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

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

Issue 1985903002: Prepare SkColorSpace to be a public API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
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 float toXYZD50[9]; 211 float toXYZD50[9];
212 png_fixed_point gamma; 212 png_fixed_point gamma;
213 SkColorSpace::SkGammas gammas; 213 float gammas[3];
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[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[0] = value;
230 gammas[1] = value;
231 gammas[2] = value;
230 232
231 } else { 233 } else {
232 // 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,
233 // but does not specify gamma. 235 // but does not specify gamma.
234 gammas = SkColorSpace::SkGammas(2.2f, 2.2f, 2.2f); 236 gammas[0] = 2.2f;
237 gammas[1] = 2.2f;
238 gammas[2] = 2.2f;
235 } 239 }
236 240
237 SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor); 241 SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor);
238 mat.set3x3ColMajorf(toXYZD50); 242 mat.set3x3ColMajorf(toXYZD50);
239 return SkColorSpace::NewRGB(std::move(gammas), mat); 243 return SkColorSpace::NewRGB(gammas, mat);
240 } 244 }
241 245
242 // Last, check for gamma. 246 // Last, check for gamma.
243 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)) {
244 248
245 // 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?
246 // Here we use the identity matrix as a default. 250 // Here we use the identity matrix as a default.
247 251
248 // Set the gammas. 252 // Set the gammas.
249 float value = png_inverted_fixed_point_to_float(gamma); 253 float value = png_inverted_fixed_point_to_float(gamma);
250 gammas = SkColorSpace::SkGammas(value, value, value); 254 gammas[0] = value;
255 gammas[1] = value;
256 gammas[2] = value;
251 257
252 return SkColorSpace::NewRGB(std::move(gammas), SkMatrix44::I()); 258 return SkColorSpace::NewRGB(gammas, SkMatrix44::I());
253 } 259 }
254 260
255 #endif // LIBPNG >= 1.6 261 #endif // LIBPNG >= 1.6
256 262
257 // 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?
258 // 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
259 // "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.
260 // 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.
261 return nullptr; 267 return nullptr;
262 } 268 }
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 SkCodec* outCodec; 802 SkCodec* outCodec;
797 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { 803 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) {
798 // Codec has taken ownership of the stream. 804 // Codec has taken ownership of the stream.
799 SkASSERT(outCodec); 805 SkASSERT(outCodec);
800 streamDeleter.release(); 806 streamDeleter.release();
801 return outCodec; 807 return outCodec;
802 } 808 }
803 809
804 return nullptr; 810 return nullptr;
805 } 811 }
OLDNEW
« no previous file with comments | « gm/color4f.cpp ('k') | src/core/SkColorSpace.h » ('j') | src/core/SkColorSpace.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698