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