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

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: Rename and fix test 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') | src/core/SkColorSpace.h » ('J')
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 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 gammas.fRed.fValue = gammas.fGreen.fValue = gammas.fBlue.fValue =
229 png_inverted_fixed_point_to_float(gamma); 229 png_inverted_fixed_point_to_float(gamma);
230 } else { 230 } else {
231 // If the image does not specify gamma, let's choose linear. Should we default 231 // If the image does not specify gamma, let's choose linear. Should we default
232 // to sRGB? Most images are intended to be sRGB (gamma = 2.2f). 232 // to sRGB? Most images are intended to be sRGB (gamma = 2.2f).
233 gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = 1.0f; 233 gammas.fRed.fValue = gammas.fGreen.fValue = gammas.fBlue.fValue = 1. 0f;
234 } 234 }
235 235
236 236
237 return SkColorSpace::NewRGB(toXYZD50, gammas); 237 return SkColorSpace::NewRGB(toXYZD50, std::move(gammas));
238 } 238 }
239 239
240 // Last, check for gamma. 240 // Last, check for gamma.
241 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)) {
242 242
243 // 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?
244 // Here we use the identity matrix as a default. 244 // Here we use the identity matrix as a default.
245 // 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?
246 memset(toXYZD50.fMat, 0, 9 * sizeof(float)); 246 memset(toXYZD50.fMat, 0, 9 * sizeof(float));
247 toXYZD50.fMat[0] = toXYZD50.fMat[4] = toXYZD50.fMat[8] = 1.0f; 247 toXYZD50.fMat[0] = toXYZD50.fMat[4] = toXYZD50.fMat[8] = 1.0f;
248 248
249 // Set the gammas. 249 // Set the gammas.
250 gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = png_inverted_fixed_po int_to_float(gamma); 250 gammas.fRed.fValue = gammas.fGreen.fValue = gammas.fBlue.fValue =
251 png_inverted_fixed_point_to_float(gamma);
251 252
252 return SkColorSpace::NewRGB(toXYZD50, gammas); 253 return SkColorSpace::NewRGB(toXYZD50, std::move(gammas));
253 } 254 }
254 255
255 #endif // LIBPNG >= 1.6 256 #endif // LIBPNG >= 1.6
256 257
257 // Finally, what should we do if there is no color space information in the PNG? 258 // 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 259 // 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. 260 // "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. 261 // But should we guess sRGB? Most images are sRGB, even if they don't speci fy.
261 return nullptr; 262 return nullptr;
262 } 263 }
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 SkCodec* outCodec; 797 SkCodec* outCodec;
797 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { 798 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) {
798 // Codec has taken ownership of the stream. 799 // Codec has taken ownership of the stream.
799 SkASSERT(outCodec); 800 SkASSERT(outCodec);
800 streamDeleter.release(); 801 streamDeleter.release();
801 return outCodec; 802 return outCodec;
802 } 803 }
803 804
804 return nullptr; 805 return nullptr;
805 } 806 }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkColorSpace.h » ('j') | src/core/SkColorSpace.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698