Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: src/codec/SkPngCodec.cpp

Issue 1928123002: Introduce SkGammas type to represent ICC gamma curves (Closed) Base URL: https://skia.googlesource.com/skia.git@delcolorspace
Patch Set: Fix Mac clang again Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkColorSpace.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 SkFloat3 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.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 gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = 228 float value = png_inverted_fixed_point_to_float(gamma);
229 png_inverted_fixed_point_to_float(gamma); 229 gammas = SkColorSpace::SkGammas(value, value, value);
230
230 } else { 231 } else {
231 // If the image does not specify gamma, let's choose linear. Should we default 232 // Default to sRGB (gamma = 2.2f) if the image has color space infor mation,
232 // to sRGB? Most images are intended to be sRGB (gamma = 2.2f). 233 // but does not specify gamma.
233 gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = 1.0f; 234 gammas = SkColorSpace::SkGammas(2.2f, 2.2f, 2.2f);
234 } 235 }
235 236
236 237
237 return SkColorSpace::NewRGB(toXYZD50, gammas); 238 return SkColorSpace::NewRGB(toXYZD50, std::move(gammas));
238 } 239 }
239 240
240 // Last, check for gamma. 241 // Last, check for gamma.
241 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { 242 if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) {
242 243
243 // Guess a default value for cHRM? Or should we just give up? 244 // Guess a default value for cHRM? Or should we just give up?
244 // Here we use the identity matrix as a default. 245 // Here we use the identity matrix as a default.
245 // FIXME (msarett): Should SkFloat3x3 have a method to set the identity matrix? 246 // FIXME (msarett): Should SkFloat3x3 have a method to set the identity matrix?
246 memset(toXYZD50.fMat, 0, 9 * sizeof(float)); 247 memset(toXYZD50.fMat, 0, 9 * sizeof(float));
247 toXYZD50.fMat[0] = toXYZD50.fMat[4] = toXYZD50.fMat[8] = 1.0f; 248 toXYZD50.fMat[0] = toXYZD50.fMat[4] = toXYZD50.fMat[8] = 1.0f;
248 249
249 // Set the gammas. 250 // Set the gammas.
250 gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = png_inverted_fixed_po int_to_float(gamma); 251 float value = png_inverted_fixed_point_to_float(gamma);
252 gammas = SkColorSpace::SkGammas(value, value, value);
251 253
252 return SkColorSpace::NewRGB(toXYZD50, gammas); 254 return SkColorSpace::NewRGB(toXYZD50, std::move(gammas));
253 } 255 }
254 256
255 #endif // LIBPNG >= 1.6 257 #endif // LIBPNG >= 1.6
256 258
257 // Finally, what should we do if there is no color space information in the PNG? 259 // Finally, what should we do if there is no color space information in the PNG?
258 // The specification says that this indicates "gamma is unknown" and that th e 260 // The specification says that this indicates "gamma is unknown" and that th e
259 // "color is device dependent". I'm assuming we can represent this with NUL L. 261 // "color is device dependent". I'm assuming we can represent this with NUL L.
260 // But should we guess sRGB? Most images are sRGB, even if they don't speci fy. 262 // But should we guess sRGB? Most images are sRGB, even if they don't speci fy.
261 return nullptr; 263 return nullptr;
262 } 264 }
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 SkCodec* outCodec; 798 SkCodec* outCodec;
797 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { 799 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) {
798 // Codec has taken ownership of the stream. 800 // Codec has taken ownership of the stream.
799 SkASSERT(outCodec); 801 SkASSERT(outCodec);
800 streamDeleter.release(); 802 streamDeleter.release();
801 return outCodec; 803 return outCodec;
802 } 804 }
803 805
804 return nullptr; 806 return nullptr;
805 } 807 }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkColorSpace.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698