aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2016-04-29 10:01:26 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-29 10:01:26 -0700
commit7b2c6dd8c918209cb92e1338905d511c68da3eb2 (patch)
tree2fa6d22ca22aac34c49944d7c3355b73f8e6d945 /src/codec
parentb138fdc65f91d20e423d447e458cee2cdbf3ca3a (diff)
Introduce SkGammas type to represent ICC gamma curves
Diffstat (limited to 'src/codec')
-rw-r--r--src/codec/SkPngCodec.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index 1ad7f8006e..b34c80c6ed 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -210,7 +210,7 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) {
png_fixed_point XYZ[9];
SkFloat3x3 toXYZD50;
png_fixed_point gamma;
- SkFloat3 gammas;
+ SkColorSpace::SkGammas gammas;
if (png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &XYZ[0], &XYZ[1], &XYZ[2], &XYZ[3], &XYZ[4],
&XYZ[5], &XYZ[6], &XYZ[7], &XYZ[8])) {
@@ -225,16 +225,17 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) {
}
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);
+ float value = png_inverted_fixed_point_to_float(gamma);
+ gammas = SkColorSpace::SkGammas(value, value, value);
+
} 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).
- gammas.fVec[0] = gammas.fVec[1] = gammas.fVec[2] = 1.0f;
+ // Default to sRGB (gamma = 2.2f) if the image has color space information,
+ // but does not specify gamma.
+ gammas = SkColorSpace::SkGammas(2.2f, 2.2f, 2.2f);
}
- return SkColorSpace::NewRGB(toXYZD50, gammas);
+ return SkColorSpace::NewRGB(toXYZD50, std::move(gammas));
}
// Last, check for gamma.
@@ -247,9 +248,10 @@ 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_inverted_fixed_point_to_float(gamma);
+ float value = png_inverted_fixed_point_to_float(gamma);
+ gammas = SkColorSpace::SkGammas(value, value, value);
- return SkColorSpace::NewRGB(toXYZD50, gammas);
+ return SkColorSpace::NewRGB(toXYZD50, std::move(gammas));
}
#endif // LIBPNG >= 1.6