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

Unified Diff: src/codec/SkPngCodec.cpp

Issue 1829433002: Correct png inverse gAMA when parsing color space (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkPngCodec.cpp
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index 326b9c23c6a188b0545ba6caf11f041f34dc3ccc..8ae2360f2570f5addb6cfb37fc4bea8e6b0483f7 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -174,6 +174,11 @@ static float png_fixed_point_to_float(png_fixed_point x) {
return ((float) x) * 0.00001f;
}
+static float png_inverted_fixed_point_to_float(png_fixed_point x) {
+ // This is necessary because the gAMA chunk actually stores 1/gamma.
+ return 1.0f / png_fixed_point_to_float(x);
+}
+
// Returns a colorSpace object that represents any color space information in
// the encoded data. If the encoded data contains no color space, this will
// return NULL.
@@ -226,13 +231,15 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) {
toXYZD50.fMat[i] = png_fixed_point_to_float(XYZ[i]);
}
- if (PNG_INFO_gAMA != png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) {
-
+ if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) {
+ gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] =
+ png_inverted_fixed_point_to_float(gamma);
+ } else {
// If the image does not specify gamma, let's choose linear. Should we default
// to sRGB? Most images are intended to be sRGB (gamma = 2.2f).
- gamma = PNG_GAMMA_LINEAR;
+ gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = 1.0f;
}
- gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = png_fixed_point_to_float(gamma);
+
return SkColorSpace::NewRGB(toXYZD50, gammas);
}
@@ -247,7 +254,7 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) {
toXYZD50.fMat[0] = toXYZD50.fMat[4] = toXYZD50.fMat[8] = 1.0f;
// Set the gammas.
- gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = png_fixed_point_to_float(gamma);
+ gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = png_inverted_fixed_point_to_float(gamma);
return SkColorSpace::NewRGB(toXYZD50, gammas);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698