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

Side by Side Diff: tools/picture_utils.cpp

Issue 2069173002: Lots of progress switching to SkColorSpace rather than SkColorProfileType (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix bad assert 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 if (bitmap. colorType() == kN32_SkColorType && 83 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
84 bitmap.profileType() == kSRGB_SkColorProfileType) { 84 if (bitmap. colorType() == kN32_SkColorType &&
85 bitmap.colorSpace() == srgbColorSpace.get()) {
85 // These are premul sRGB 8-bit pixels in SkPMColor order. 86 // These are premul sRGB 8-bit pixels in SkPMColor order.
86 // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get ther e via floats. 87 // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get ther e via floats.
87 bitmap.lockPixels(); 88 bitmap.lockPixels();
88 auto px = (const uint32_t*)bitmap.getPixels(); 89 auto px = (const uint32_t*)bitmap.getPixels();
89 if (!px) { 90 if (!px) {
90 return nullptr; 91 return nullptr;
91 } 92 }
92 for (int i = 0; i < w*h; i++) { 93 for (int i = 0; i < w*h; i++) {
93 Sk4f fs = Sk4f_fromS32(px[i]); // Convert up to linear f loats. 94 Sk4f fs = Sk4f_fromS32(px[i]); // Convert up to linear f loats.
94 #if defined(SK_PMCOLOR_IS_BGRA) 95 #if defined(SK_PMCOLOR_IS_BGRA)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 kUnpremul_SkAlphaType), 138 kUnpremul_SkAlphaType),
138 rgba, 4*w, 0,0)) { 139 rgba, 4*w, 0,0)) {
139 return nullptr; 140 return nullptr;
140 } 141 }
141 } 142 }
142 143
143 return SkData::MakeFromMalloc(rgba.release(), w*h*sizeof(uint32_t)); 144 return SkData::MakeFromMalloc(rgba.release(), w*h*sizeof(uint32_t));
144 } 145 }
145 146
146 } // namespace sk_tools 147 } // 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