Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 #include "SkColorSpace.h" | 11 #include "SkColorSpace_Base.h" |
| 12 #include "SkColorTable.h" | 12 #include "SkColorTable.h" |
| 13 #include "SkMath.h" | 13 #include "SkMath.h" |
| 14 #include "SkOpts.h" | 14 #include "SkOpts.h" |
| 15 #include "SkPngCodec.h" | 15 #include "SkPngCodec.h" |
| 16 #include "SkSize.h" | 16 #include "SkSize.h" |
| 17 #include "SkStream.h" | 17 #include "SkStream.h" |
| 18 #include "SkSwizzler.h" | 18 #include "SkSwizzler.h" |
| 19 #include "SkTemplates.h" | 19 #include "SkTemplates.h" |
| 20 #include "SkUtils.h" | 20 #include "SkUtils.h" |
| 21 | 21 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 | 216 |
| 217 // FIXME (msarett): Here we are treating XYZ values as D50 even though t he color | 217 // FIXME (msarett): Here we are treating XYZ values as D50 even though t he color |
| 218 // temperature is unspecified. I suspect that this ass umption | 218 // temperature is unspecified. I suspect that this ass umption |
| 219 // is most often ok, but we could also calculate the co lor | 219 // is most often ok, but we could also calculate the co lor |
| 220 // temperature (D value) and then convert the XYZ to D5 0. Maybe | 220 // temperature (D value) and then convert the XYZ to D5 0. Maybe |
| 221 // we should add a new constructor to SkColorSpace that accepts | 221 // we should add a new constructor to SkColorSpace that accepts |
| 222 // XYZ with D-Unkown? | 222 // XYZ with D-Unkown? |
| 223 for (int i = 0; i < 9; i++) { | 223 for (int i = 0; i < 9; i++) { |
| 224 toXYZD50[i] = png_fixed_point_to_float(XYZ[i]); | 224 toXYZD50[i] = png_fixed_point_to_float(XYZ[i]); |
| 225 } | 225 } |
| 226 SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor); | |
| 227 mat.set3x3ColMajorf(toXYZD50); | |
| 226 | 228 |
| 227 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { | 229 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { |
| 228 float value = png_inverted_fixed_point_to_float(gamma); | 230 float value = png_inverted_fixed_point_to_float(gamma); |
| 229 gammas[0] = value; | 231 gammas[0] = value; |
| 230 gammas[1] = value; | 232 gammas[1] = value; |
| 231 gammas[2] = value; | 233 gammas[2] = value; |
| 232 | 234 |
| 233 } else { | 235 } else { |
| 234 // Default to sRGB (gamma = 2.2f) if the image has color space infor mation, | 236 // Default to sRGB gamma if the image has color space information, |
| 235 // but does not specify gamma. | 237 // but does not specify gamma. |
| 236 gammas[0] = 2.2f; | 238 return SkColorSpace::NewRGB(SkColorSpace::kSRGB_GammaNamed, mat); |
| 237 gammas[1] = 2.2f; | |
| 238 gammas[2] = 2.2f; | |
| 239 } | 239 } |
| 240 | 240 |
| 241 SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor); | 241 return SkColorSpace_Base::NewRGB(gammas, mat); |
|
Brian Osman
2016/06/15 13:26:59
Nit: Now that we're returning sRGB in the else cas
msarett
2016/06/15 14:33:48
Yup that makes a lot more sense. Done.
| |
| 242 mat.set3x3ColMajorf(toXYZD50); | |
| 243 return SkColorSpace::NewRGB(gammas, mat); | |
| 244 } | 242 } |
| 245 | 243 |
| 246 // Last, check for gamma. | 244 // Last, check for gamma. |
| 247 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { | 245 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { |
| 248 | 246 |
| 249 // Guess a default value for cHRM? Or should we just give up? | 247 // Guess a default value for cHRM? Or should we just give up? |
|
Brian Osman
2016/06/15 13:26:59
As I read this code and think about it more, I get
msarett
2016/06/15 14:33:48
Yeah I'd agree we should guess sRGB here. Nobody
| |
| 250 // Here we use the identity matrix as a default. | 248 // Here we use the identity matrix as a default. |
| 251 | 249 |
| 252 // Set the gammas. | 250 // Set the gammas. |
| 253 float value = png_inverted_fixed_point_to_float(gamma); | 251 float value = png_inverted_fixed_point_to_float(gamma); |
| 254 gammas[0] = value; | 252 gammas[0] = value; |
| 255 gammas[1] = value; | 253 gammas[1] = value; |
| 256 gammas[2] = value; | 254 gammas[2] = value; |
| 257 | 255 |
| 258 return SkColorSpace::NewRGB(gammas, SkMatrix44::I()); | 256 return SkColorSpace_Base::NewRGB(gammas, SkMatrix44::I()); |
| 259 } | 257 } |
| 260 | 258 |
| 261 #endif // LIBPNG >= 1.6 | 259 #endif // LIBPNG >= 1.6 |
| 262 | 260 |
| 263 // Finally, what should we do if there is no color space information in the PNG? | 261 // Finally, what should we do if there is no color space information in the PNG? |
| 264 // The specification says that this indicates "gamma is unknown" and that th e | 262 // The specification says that this indicates "gamma is unknown" and that th e |
| 265 // "color is device dependent". I'm assuming we can represent this with NUL L. | 263 // "color is device dependent". I'm assuming we can represent this with NUL L. |
| 266 // But should we guess sRGB? Most images are sRGB, even if they don't speci fy. | 264 // But should we guess sRGB? Most images are sRGB, even if they don't speci fy. |
| 267 return nullptr; | 265 return nullptr; |
| 268 } | 266 } |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 807 SkCodec* outCodec; | 805 SkCodec* outCodec; |
| 808 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { | 806 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { |
| 809 // Codec has taken ownership of the stream. | 807 // Codec has taken ownership of the stream. |
| 810 SkASSERT(outCodec); | 808 SkASSERT(outCodec); |
| 811 streamDeleter.release(); | 809 streamDeleter.release(); |
| 812 return outCodec; | 810 return outCodec; |
| 813 } | 811 } |
| 814 | 812 |
| 815 return nullptr; | 813 return nullptr; |
| 816 } | 814 } |
| OLD | NEW |