OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |