diff options
author | reed <reed@google.com> | 2016-05-03 12:13:21 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-03 12:13:21 -0700 |
commit | 50d3b57c8aaa0f026b981101c45ea30361382940 (patch) | |
tree | ca3b1319d55b7fc495406bd13fd238171b48c2d8 /src | |
parent | 676ab68b04597c997e3152f31c08090c0d2ccbe4 (diff) |
return 4x4 matrix from SkColorSpace
move SkMatrix44 into core (with alias in utils to transition chrome)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1943833002
Review-Url: https://codereview.chromium.org/1943833002
Diffstat (limited to 'src')
-rw-r--r-- | src/codec/SkPngCodec.cpp | 14 | ||||
-rw-r--r-- | src/core/SkColorSpace.cpp | 83 | ||||
-rw-r--r-- | src/core/SkColorSpace.h | 25 | ||||
-rw-r--r-- | src/core/SkMatrix44.cpp (renamed from src/utils/SkMatrix44.cpp) | 8 |
4 files changed, 65 insertions, 65 deletions
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp index b34c80c6ed..1ca3586c6c 100644 --- a/src/codec/SkPngCodec.cpp +++ b/src/codec/SkPngCodec.cpp @@ -208,7 +208,7 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) { // Next, check for chromaticities. png_fixed_point XYZ[9]; - SkFloat3x3 toXYZD50; + float toXYZD50[9]; png_fixed_point gamma; SkColorSpace::SkGammas gammas; if (png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &XYZ[0], &XYZ[1], &XYZ[2], &XYZ[3], &XYZ[4], @@ -221,7 +221,7 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) { // we should add a new constructor to SkColorSpace that accepts // XYZ with D-Unkown? for (int i = 0; i < 9; i++) { - toXYZD50.fMat[i] = png_fixed_point_to_float(XYZ[i]); + toXYZD50[i] = png_fixed_point_to_float(XYZ[i]); } if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) { @@ -234,8 +234,9 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) { gammas = SkColorSpace::SkGammas(2.2f, 2.2f, 2.2f); } - - return SkColorSpace::NewRGB(toXYZD50, std::move(gammas)); + SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor); + mat.set3x3ColMajorf(toXYZD50); + return SkColorSpace::NewRGB(mat, std::move(gammas)); } // Last, check for gamma. @@ -243,15 +244,12 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) { // Guess a default value for cHRM? Or should we just give up? // Here we use the identity matrix as a default. - // FIXME (msarett): Should SkFloat3x3 have a method to set the identity matrix? - memset(toXYZD50.fMat, 0, 9 * sizeof(float)); - toXYZD50.fMat[0] = toXYZD50.fMat[4] = toXYZD50.fMat[8] = 1.0f; // Set the gammas. float value = png_inverted_fixed_point_to_float(gamma); gammas = SkColorSpace::SkGammas(value, value, value); - return SkColorSpace::NewRGB(toXYZD50, std::move(gammas)); + return SkColorSpace::NewRGB(SkMatrix44::I(), std::move(gammas)); } #endif // LIBPNG >= 1.6 diff --git a/src/core/SkColorSpace.cpp b/src/core/SkColorSpace.cpp index 54495de940..f7e1ddb88f 100644 --- a/src/core/SkColorSpace.cpp +++ b/src/core/SkColorSpace.cpp @@ -12,50 +12,44 @@ void SkFloat3::dump() const { SkDebugf("[%7.4f %7.4f %7.4f]\n", fVec[0], fVec[1], fVec[2]); } -void SkFloat3x3::dump() const { - SkDebugf("[%7.4f %7.4f %7.4f] [%7.4f %7.4f %7.4f] [%7.4f %7.4f %7.4f]\n", - fMat[0], fMat[1], fMat[2], - fMat[3], fMat[4], fMat[5], - fMat[6], fMat[7], fMat[8]); -} - ////////////////////////////////////////////////////////////////////////////////////////////////// static int32_t gUniqueColorSpaceID; -SkColorSpace::SkColorSpace(SkGammas gammas, const SkFloat3x3& toXYZD50, Named named) +SkColorSpace::SkColorSpace(SkGammas gammas, const SkMatrix44& toXYZD50, Named named) : fGammas(std::move(gammas)) , fToXYZD50(toXYZD50) - , fToXYZOffset({{ 0.0f, 0.0f, 0.0f }}) , fUniqueID(sk_atomic_inc(&gUniqueColorSpaceID)) , fNamed(named) {} SkColorSpace::SkColorSpace(SkColorLookUpTable colorLUT, SkGammas gammas, - const SkFloat3x3& toXYZD50, const SkFloat3& toXYZOffset) + const SkMatrix44& toXYZD50) : fColorLUT(std::move(colorLUT)) , fGammas(std::move(gammas)) , fToXYZD50(toXYZD50) - , fToXYZOffset(toXYZOffset) , fUniqueID(sk_atomic_inc(&gUniqueColorSpaceID)) , fNamed(kUnknown_Named) {} -sk_sp<SkColorSpace> SkColorSpace::NewRGB(const SkFloat3x3& toXYZD50, SkGammas gammas) { +sk_sp<SkColorSpace> SkColorSpace::NewRGB(const SkMatrix44& toXYZD50, SkGammas gammas) { return sk_sp<SkColorSpace>(new SkColorSpace(std::move(gammas), toXYZD50, kUnknown_Named)); } -const SkFloat3x3 gSRGB_toXYZD50 {{ +const float gSRGB_toXYZD50[] { 0.4358f, 0.2224f, 0.0139f, // * R 0.3853f, 0.7170f, 0.0971f, // * G 0.1430f, 0.0606f, 0.7139f, // * B -}}; +}; sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) { switch (named) { - case kSRGB_Named: - return sk_sp<SkColorSpace>(new SkColorSpace(SkGammas(2.2f, 2.2f, 2.2f), gSRGB_toXYZD50, + case kSRGB_Named: { + SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); + srgbToxyzD50.set3x3ColMajorf(gSRGB_toXYZD50); + return sk_sp<SkColorSpace>(new SkColorSpace(SkGammas(2.2f, 2.2f, 2.2f), srgbToxyzD50, kSRGB_Named)); + } default: break; } @@ -414,29 +408,35 @@ bool SkColorSpace::LoadColorLUT(SkColorLookUpTable* colorLUT, uint32_t inputChan return true; } -bool load_matrix(SkFloat3x3* toXYZ, SkFloat3* toXYZOffset, const uint8_t* src, size_t len) { +bool load_matrix(SkMatrix44* toXYZ, const uint8_t* src, size_t len) { if (len < 48) { SkColorSpacePrintf("Matrix tag is too small (%d bytes).", len); return false; } - toXYZ->fMat[0] = SkFixedToFloat(read_big_endian_int(src)); - toXYZ->fMat[3] = SkFixedToFloat(read_big_endian_int(src + 4)); - toXYZ->fMat[6] = SkFixedToFloat(read_big_endian_int(src + 8)); - toXYZ->fMat[1] = SkFixedToFloat(read_big_endian_int(src + 12)); - toXYZ->fMat[4] = SkFixedToFloat(read_big_endian_int(src + 16)); - toXYZ->fMat[7] = SkFixedToFloat(read_big_endian_int(src + 20)); - toXYZ->fMat[2] = SkFixedToFloat(read_big_endian_int(src + 24)); - toXYZ->fMat[5] = SkFixedToFloat(read_big_endian_int(src + 28)); - toXYZ->fMat[8] = SkFixedToFloat(read_big_endian_int(src + 32)); - toXYZOffset->fVec[0] = SkFixedToFloat(read_big_endian_int(src + 36)); - toXYZOffset->fVec[1] = SkFixedToFloat(read_big_endian_int(src + 40)); - toXYZOffset->fVec[2] = SkFixedToFloat(read_big_endian_int(src + 44)); + float array[16]; + array[ 0] = SkFixedToFloat(read_big_endian_int(src)); + array[ 1] = SkFixedToFloat(read_big_endian_int(src + 4)); + array[ 2] = SkFixedToFloat(read_big_endian_int(src + 8)); + array[ 3] = 0; + array[ 4] = SkFixedToFloat(read_big_endian_int(src + 12)); + array[ 5] = SkFixedToFloat(read_big_endian_int(src + 16)); + array[ 6] = SkFixedToFloat(read_big_endian_int(src + 20)); + array[ 7] = 0; + array[ 8] = SkFixedToFloat(read_big_endian_int(src + 24)); + array[ 9] = SkFixedToFloat(read_big_endian_int(src + 28)); + array[10] = SkFixedToFloat(read_big_endian_int(src + 32)); + array[11] = 0; + array[12] = SkFixedToFloat(read_big_endian_int(src + 36)); // translate R + array[13] = SkFixedToFloat(read_big_endian_int(src + 40)); // translate G + array[14] = SkFixedToFloat(read_big_endian_int(src + 44)); + array[15] = 1; + toXYZ->setColMajorf(array); return true; } -bool SkColorSpace::LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkFloat3x3* toXYZ, - SkFloat3* toXYZOffset, const uint8_t* src, size_t len) { +bool SkColorSpace::LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkMatrix44* toXYZ, + const uint8_t* src, size_t len) { if (len < 32) { SkColorSpacePrintf("A to B tag is too small (%d bytes).", len); return false; @@ -493,7 +493,7 @@ bool SkColorSpace::LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkFl uint32_t offsetToMatrix = read_big_endian_int(src + 16); if (0 != offsetToMatrix && offsetToMatrix < len) { - if (!load_matrix(toXYZ, toXYZOffset, src + offsetToMatrix, len - offsetToMatrix)) { + if (!load_matrix(toXYZ, src + offsetToMatrix, len - offsetToMatrix)) { SkColorSpacePrintf("Failed to read matrix from A to B tag.\n"); } } @@ -551,10 +551,10 @@ sk_sp<SkColorSpace> SkColorSpace::NewICC(const void* base, size_t len) { const ICCTag* g = ICCTag::Find(tags.get(), tagCount, kTAG_gXYZ); const ICCTag* b = ICCTag::Find(tags.get(), tagCount, kTAG_bXYZ); if (r && g && b) { - SkFloat3x3 toXYZ; - if (!load_xyz(&toXYZ.fMat[0], r->addr((const uint8_t*) base), r->fLength) || - !load_xyz(&toXYZ.fMat[3], g->addr((const uint8_t*) base), g->fLength) || - !load_xyz(&toXYZ.fMat[6], b->addr((const uint8_t*) base), b->fLength)) + float toXYZ[9]; + if (!load_xyz(&toXYZ[0], r->addr((const uint8_t*) base), r->fLength) || + !load_xyz(&toXYZ[3], g->addr((const uint8_t*) base), g->fLength) || + !load_xyz(&toXYZ[6], b->addr((const uint8_t*) base), b->fLength)) { return_null("Need valid rgb tags for XYZ space"); } @@ -577,7 +577,9 @@ sk_sp<SkColorSpace> SkColorSpace::NewICC(const void* base, size_t len) { b->addr((const uint8_t*) base), b->fLength)) { SkColorSpacePrintf("Failed to read B gamma tag.\n"); } - return SkColorSpace::NewRGB(toXYZ, std::move(gammas)); + SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor); + mat.set3x3ColMajorf(toXYZ); + return SkColorSpace::NewRGB(mat, std::move(gammas)); } // Recognize color profile specified by A2B0 tag. @@ -585,15 +587,14 @@ sk_sp<SkColorSpace> SkColorSpace::NewICC(const void* base, size_t len) { if (a2b0) { SkColorLookUpTable colorLUT; SkGammas gammas; - SkFloat3x3 toXYZ; - SkFloat3 toXYZOffset; - if (!SkColorSpace::LoadA2B0(&colorLUT, &gammas, &toXYZ, &toXYZOffset, + SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); + if (!SkColorSpace::LoadA2B0(&colorLUT, &gammas, &toXYZ, a2b0->addr((const uint8_t*) base), a2b0->fLength)) { return_null("Failed to parse A2B0 tag"); } return sk_sp<SkColorSpace>(new SkColorSpace(std::move(colorLUT), std::move(gammas), - toXYZ, toXYZOffset)); + toXYZ)); } } diff --git a/src/core/SkColorSpace.h b/src/core/SkColorSpace.h index a1ccf13fe0..6498941d7d 100644 --- a/src/core/SkColorSpace.h +++ b/src/core/SkColorSpace.h @@ -22,6 +22,7 @@ // #include "SkRefCnt.h" +#include "SkMatrix44.h" struct SkFloat3 { float fVec[3]; @@ -29,12 +30,6 @@ struct SkFloat3 { void dump() const; }; -struct SkFloat3x3 { - float fMat[9]; - - void dump() const; -}; - class SkColorSpace : public SkRefCnt { private: struct SkGammaCurve { @@ -117,17 +112,16 @@ public: }; /** - * Return a colorspace instance, given a 3x3 transform from linear_RGB to D50_XYZ + * Return a colorspace instance, given a transform from linear_RGB to D50_XYZ * and the src-gamma, return a ColorSpace */ - static sk_sp<SkColorSpace> NewRGB(const SkFloat3x3& toXYZD50, SkGammas gammas); + static sk_sp<SkColorSpace> NewRGB(const SkMatrix44& toXYZD50, SkGammas gammas); static sk_sp<SkColorSpace> NewNamed(Named); static sk_sp<SkColorSpace> NewICC(const void*, size_t); const SkGammas& gammas() const { return fGammas; } - SkFloat3x3 xyz() const { return fToXYZD50; } - SkFloat3 xyzOffset() const { return fToXYZOffset; } + SkMatrix44 xyz() const { return fToXYZD50; } Named named() const { return fNamed; } uint32_t uniqueID() const { return fUniqueID; } @@ -140,18 +134,17 @@ private: uint32_t outputChannels, const uint8_t* src, size_t len); - static bool LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkFloat3x3* toXYZ, - SkFloat3* toXYZOffset, const uint8_t* src, size_t len); + static bool LoadA2B0(SkColorLookUpTable* colorLUT, SkGammas* gammas, SkMatrix44* toXYZ, + const uint8_t* src, size_t len); - SkColorSpace(SkGammas gammas, const SkFloat3x3& toXYZ, Named); + SkColorSpace(SkGammas gammas, const SkMatrix44& toXYZ, Named); SkColorSpace(SkColorLookUpTable colorLUT, SkGammas gammas, - const SkFloat3x3& toXYZ, const SkFloat3& toXYZOffset); + const SkMatrix44& toXYZ); const SkColorLookUpTable fColorLUT; const SkGammas fGammas; - const SkFloat3x3 fToXYZD50; - const SkFloat3 fToXYZOffset; + const SkMatrix44 fToXYZD50; const uint32_t fUniqueID; const Named fNamed; diff --git a/src/utils/SkMatrix44.cpp b/src/core/SkMatrix44.cpp index 71cd74002b..34b5327519 100644 --- a/src/utils/SkMatrix44.cpp +++ b/src/core/SkMatrix44.cpp @@ -209,6 +209,14 @@ void SkMatrix44::set3x3(SkMScalar m00, SkMScalar m01, SkMScalar m02, this->dirtyTypeMask(); } +void SkMatrix44::set3x3ColMajorf(const float src[]) { + fMat[0][0] = src[0]; fMat[0][1] = src[3]; fMat[0][2] = src[6]; fMat[0][3] = 0; + fMat[1][0] = src[1]; fMat[1][1] = src[4]; fMat[1][2] = src[7]; fMat[1][3] = 0; + fMat[2][0] = src[2]; fMat[2][1] = src[5]; fMat[2][2] = src[8]; fMat[2][3] = 0; + fMat[3][0] = 0; fMat[3][1] = 0; fMat[3][2] = 0; fMat[3][3] = 1; + this->dirtyTypeMask(); +} + /////////////////////////////////////////////////////////////////////////////// void SkMatrix44::setTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz) { |