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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 toXYZD50[i] = png_fixed_point_to_float(XYZ[i]); | 224 toXYZD50[i] = png_fixed_point_to_float(XYZ[i]); |
| 225 } | 225 } |
| 226 | 226 |
| 227 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { | 227 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { |
| 228 float value = png_inverted_fixed_point_to_float(gamma); | 228 float value = png_inverted_fixed_point_to_float(gamma); |
| 229 gammas[0] = value; | 229 gammas[0] = value; |
| 230 gammas[1] = value; | 230 gammas[1] = value; |
| 231 gammas[2] = value; | 231 gammas[2] = value; |
| 232 | 232 |
| 233 } else { | 233 } else { |
| 234 // Default to sRGB (gamma = 2.2f) if the image has color space infor mation, | 234 // Default to sRGB (gamma = 2.2f) if the image has color space infor mation, |
|
Brian Osman
2016/06/14 21:55:38
Now that we're distinguishing between 2.2 and sRGB
msarett
2016/06/14 22:59:11
Yes I think so! Done.
Might make sense to defaul
| |
| 235 // but does not specify gamma. | 235 // but does not specify gamma. |
| 236 gammas[0] = 2.2f; | 236 gammas[0] = 2.2f; |
| 237 gammas[1] = 2.2f; | 237 gammas[1] = 2.2f; |
| 238 gammas[2] = 2.2f; | 238 gammas[2] = 2.2f; |
| 239 } | 239 } |
| 240 | 240 |
| 241 SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor); | 241 SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor); |
| 242 mat.set3x3ColMajorf(toXYZD50); | 242 mat.set3x3ColMajorf(toXYZD50); |
| 243 return SkColorSpace::NewRGB(gammas, mat); | 243 return SkColorSpace_Base::NewRGB(gammas, mat); |
| 244 } | 244 } |
| 245 | 245 |
| 246 // Last, check for gamma. | 246 // Last, check for gamma. |
| 247 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { | 247 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { |
| 248 | 248 |
| 249 // Guess a default value for cHRM? Or should we just give up? | 249 // Guess a default value for cHRM? Or should we just give up? |
| 250 // Here we use the identity matrix as a default. | 250 // Here we use the identity matrix as a default. |
| 251 | 251 |
| 252 // Set the gammas. | 252 // Set the gammas. |
| 253 float value = png_inverted_fixed_point_to_float(gamma); | 253 float value = png_inverted_fixed_point_to_float(gamma); |
| 254 gammas[0] = value; | 254 gammas[0] = value; |
| 255 gammas[1] = value; | 255 gammas[1] = value; |
| 256 gammas[2] = value; | 256 gammas[2] = value; |
| 257 | 257 |
| 258 return SkColorSpace::NewRGB(gammas, SkMatrix44::I()); | 258 return SkColorSpace_Base::NewRGB(gammas, SkMatrix44::I()); |
| 259 } | 259 } |
| 260 | 260 |
| 261 #endif // LIBPNG >= 1.6 | 261 #endif // LIBPNG >= 1.6 |
| 262 | 262 |
| 263 // Finally, what should we do if there is no color space information in the PNG? | 263 // 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 | 264 // 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. | 265 // "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. | 266 // But should we guess sRGB? Most images are sRGB, even if they don't speci fy. |
| 267 return nullptr; | 267 return nullptr; |
| 268 } | 268 } |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 807 SkCodec* outCodec; | 807 SkCodec* outCodec; |
| 808 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { | 808 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { |
| 809 // Codec has taken ownership of the stream. | 809 // Codec has taken ownership of the stream. |
| 810 SkASSERT(outCodec); | 810 SkASSERT(outCodec); |
| 811 streamDeleter.release(); | 811 streamDeleter.release(); |
| 812 return outCodec; | 812 return outCodec; |
| 813 } | 813 } |
| 814 | 814 |
| 815 return nullptr; | 815 return nullptr; |
| 816 } | 816 } |
| OLD | NEW |