Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: tools/picture_utils.cpp

Issue 2072813002: Revert of Lots of progress switching to SkColorSpace rather than SkColorProfileType (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/flags/SkCommonFlagsConfig.cpp ('k') | tools/skiaserve/Request.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "picture_utils.h" 8 #include "picture_utils.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 sk_sp<SkData> encode_bitmap_for_png(SkBitmap bitmap) { 74 sk_sp<SkData> encode_bitmap_for_png(SkBitmap bitmap) {
75 const int w = bitmap.width(), 75 const int w = bitmap.width(),
76 h = bitmap.height(); 76 h = bitmap.height();
77 // PNG wants unpremultiplied 8-bit RGBA pixels (16-bit could work fine t oo). 77 // PNG wants unpremultiplied 8-bit RGBA pixels (16-bit could work fine t oo).
78 // We leave the gamma of these bytes unspecified, to continue the status quo, 78 // We leave the gamma of these bytes unspecified, to continue the status quo,
79 // which we think generally is to interpret them as sRGB. 79 // which we think generally is to interpret them as sRGB.
80 80
81 SkAutoTMalloc<uint32_t> rgba(w*h); 81 SkAutoTMalloc<uint32_t> rgba(w*h);
82 82
83 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); 83 if (bitmap. colorType() == kN32_SkColorType &&
84 if (bitmap. colorType() == kN32_SkColorType && 84 bitmap.profileType() == kSRGB_SkColorProfileType) {
85 bitmap.colorSpace() == srgbColorSpace.get()) {
86 // These are premul sRGB 8-bit pixels in SkPMColor order. 85 // These are premul sRGB 8-bit pixels in SkPMColor order.
87 // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get ther e via floats. 86 // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get ther e via floats.
88 bitmap.lockPixels(); 87 bitmap.lockPixels();
89 auto px = (const uint32_t*)bitmap.getPixels(); 88 auto px = (const uint32_t*)bitmap.getPixels();
90 if (!px) { 89 if (!px) {
91 return nullptr; 90 return nullptr;
92 } 91 }
93 for (int i = 0; i < w*h; i++) { 92 for (int i = 0; i < w*h; i++) {
94 Sk4f fs = Sk4f_fromS32(px[i]); // Convert up to linear f loats. 93 Sk4f fs = Sk4f_fromS32(px[i]); // Convert up to linear f loats.
95 #if defined(SK_PMCOLOR_IS_BGRA) 94 #if defined(SK_PMCOLOR_IS_BGRA)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 kUnpremul_SkAlphaType), 137 kUnpremul_SkAlphaType),
139 rgba, 4*w, 0,0)) { 138 rgba, 4*w, 0,0)) {
140 return nullptr; 139 return nullptr;
141 } 140 }
142 } 141 }
143 142
144 return SkData::MakeFromMalloc(rgba.release(), w*h*sizeof(uint32_t)); 143 return SkData::MakeFromMalloc(rgba.release(), w*h*sizeof(uint32_t));
145 } 144 }
146 145
147 } // namespace sk_tools 146 } // namespace sk_tools
OLDNEW
« no previous file with comments | « tools/flags/SkCommonFlagsConfig.cpp ('k') | tools/skiaserve/Request.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698