| 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" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // sRGB chunks also store a rendering intent: Absolute, Relative, | 201 // sRGB chunks also store a rendering intent: Absolute, Relative, |
| 202 // Perceptual, and Saturation. | 202 // Perceptual, and Saturation. |
| 203 // FIXME (msarett): Extract this information from the sRGB chunk once | 203 // FIXME (msarett): Extract this information from the sRGB chunk once |
| 204 // we are able to handle this information in | 204 // we are able to handle this information in |
| 205 // SkColorSpace. | 205 // SkColorSpace. |
| 206 return SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | 206 return SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Next, check for chromaticities. | 209 // Next, check for chromaticities. |
| 210 png_fixed_point XYZ[9]; | 210 png_fixed_point XYZ[9]; |
| 211 SkFloat3x3 toXYZD50; | 211 float toXYZD50[9]; |
| 212 png_fixed_point gamma; | 212 png_fixed_point gamma; |
| 213 SkColorSpace::SkGammas gammas; | 213 SkColorSpace::SkGammas gammas; |
| 214 if (png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &XYZ[0], &XYZ[1], &XYZ[2], &XY
Z[3], &XYZ[4], | 214 if (png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &XYZ[0], &XYZ[1], &XYZ[2], &XY
Z[3], &XYZ[4], |
| 215 &XYZ[5], &XYZ[6], &XYZ[7], &XYZ[8])) { | 215 &XYZ[5], &XYZ[6], &XYZ[7], &XYZ[8])) { |
| 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.fMat[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 = SkColorSpace::SkGammas(value, value, value); | 229 gammas = SkColorSpace::SkGammas(value, value, value); |
| 230 | 230 |
| 231 } else { | 231 } else { |
| 232 // Default to sRGB (gamma = 2.2f) if the image has color space infor
mation, | 232 // Default to sRGB (gamma = 2.2f) if the image has color space infor
mation, |
| 233 // but does not specify gamma. | 233 // but does not specify gamma. |
| 234 gammas = SkColorSpace::SkGammas(2.2f, 2.2f, 2.2f); | 234 gammas = SkColorSpace::SkGammas(2.2f, 2.2f, 2.2f); |
| 235 } | 235 } |
| 236 | 236 |
| 237 | 237 SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor); |
| 238 return SkColorSpace::NewRGB(toXYZD50, std::move(gammas)); | 238 mat.set3x3ColMajorf(toXYZD50); |
| 239 return SkColorSpace::NewRGB(mat, std::move(gammas)); |
| 239 } | 240 } |
| 240 | 241 |
| 241 // Last, check for gamma. | 242 // Last, check for gamma. |
| 242 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { | 243 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { |
| 243 | 244 |
| 244 // Guess a default value for cHRM? Or should we just give up? | 245 // Guess a default value for cHRM? Or should we just give up? |
| 245 // Here we use the identity matrix as a default. | 246 // Here we use the identity matrix as a default. |
| 246 // FIXME (msarett): Should SkFloat3x3 have a method to set the identity
matrix? | |
| 247 memset(toXYZD50.fMat, 0, 9 * sizeof(float)); | |
| 248 toXYZD50.fMat[0] = toXYZD50.fMat[4] = toXYZD50.fMat[8] = 1.0f; | |
| 249 | 247 |
| 250 // Set the gammas. | 248 // Set the gammas. |
| 251 float value = png_inverted_fixed_point_to_float(gamma); | 249 float value = png_inverted_fixed_point_to_float(gamma); |
| 252 gammas = SkColorSpace::SkGammas(value, value, value); | 250 gammas = SkColorSpace::SkGammas(value, value, value); |
| 253 | 251 |
| 254 return SkColorSpace::NewRGB(toXYZD50, std::move(gammas)); | 252 return SkColorSpace::NewRGB(SkMatrix44::I(), std::move(gammas)); |
| 255 } | 253 } |
| 256 | 254 |
| 257 #endif // LIBPNG >= 1.6 | 255 #endif // LIBPNG >= 1.6 |
| 258 | 256 |
| 259 // Finally, what should we do if there is no color space information in the
PNG? | 257 // Finally, what should we do if there is no color space information in the
PNG? |
| 260 // The specification says that this indicates "gamma is unknown" and that th
e | 258 // The specification says that this indicates "gamma is unknown" and that th
e |
| 261 // "color is device dependent". I'm assuming we can represent this with NUL
L. | 259 // "color is device dependent". I'm assuming we can represent this with NUL
L. |
| 262 // But should we guess sRGB? Most images are sRGB, even if they don't speci
fy. | 260 // But should we guess sRGB? Most images are sRGB, even if they don't speci
fy. |
| 263 return nullptr; | 261 return nullptr; |
| 264 } | 262 } |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 SkCodec* outCodec; | 796 SkCodec* outCodec; |
| 799 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { | 797 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { |
| 800 // Codec has taken ownership of the stream. | 798 // Codec has taken ownership of the stream. |
| 801 SkASSERT(outCodec); | 799 SkASSERT(outCodec); |
| 802 streamDeleter.release(); | 800 streamDeleter.release(); |
| 803 return outCodec; | 801 return outCodec; |
| 804 } | 802 } |
| 805 | 803 |
| 806 return nullptr; | 804 return nullptr; |
| 807 } | 805 } |
| OLD | NEW |