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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkFloat3x3 toXYZD50; |
212 png_fixed_point gamma; | 212 png_fixed_point gamma; |
213 SkColorSpace::SkGammas gammas; | 213 SkFloat3 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.fMat[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 gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = |
229 gammas = SkColorSpace::SkGammas(value, value, value); | 229 png_inverted_fixed_point_to_float(gamma); |
230 | |
231 } else { | 230 } else { |
232 // Default to sRGB (gamma = 2.2f) if the image has color space infor
mation, | 231 // If the image does not specify gamma, let's choose linear. Should
we default |
233 // but does not specify gamma. | 232 // to sRGB? Most images are intended to be sRGB (gamma = 2.2f). |
234 gammas = SkColorSpace::SkGammas(2.2f, 2.2f, 2.2f); | 233 gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = 1.0f; |
235 } | 234 } |
236 | 235 |
237 | 236 |
238 return SkColorSpace::NewRGB(toXYZD50, std::move(gammas)); | 237 return SkColorSpace::NewRGB(toXYZD50, gammas); |
239 } | 238 } |
240 | 239 |
241 // Last, check for gamma. | 240 // Last, check for gamma. |
242 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { | 241 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { |
243 | 242 |
244 // Guess a default value for cHRM? Or should we just give up? | 243 // Guess a default value for cHRM? Or should we just give up? |
245 // Here we use the identity matrix as a default. | 244 // Here we use the identity matrix as a default. |
246 // FIXME (msarett): Should SkFloat3x3 have a method to set the identity
matrix? | 245 // FIXME (msarett): Should SkFloat3x3 have a method to set the identity
matrix? |
247 memset(toXYZD50.fMat, 0, 9 * sizeof(float)); | 246 memset(toXYZD50.fMat, 0, 9 * sizeof(float)); |
248 toXYZD50.fMat[0] = toXYZD50.fMat[4] = toXYZD50.fMat[8] = 1.0f; | 247 toXYZD50.fMat[0] = toXYZD50.fMat[4] = toXYZD50.fMat[8] = 1.0f; |
249 | 248 |
250 // Set the gammas. | 249 // Set the gammas. |
251 float value = png_inverted_fixed_point_to_float(gamma); | 250 gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = png_inverted_fixed_po
int_to_float(gamma); |
252 gammas = SkColorSpace::SkGammas(value, value, value); | |
253 | 251 |
254 return SkColorSpace::NewRGB(toXYZD50, std::move(gammas)); | 252 return SkColorSpace::NewRGB(toXYZD50, 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 |