| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright 2016 Google Inc. |    2  * Copyright 2016 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 "SkColorSpace.h" |    8 #include "SkColorSpace.h" | 
|    9 #include "SkColorSpace_Base.h" |    9 #include "SkColorSpace_Base.h" | 
|   10 #include "SkColorSpacePriv.h" |   10 #include "SkColorSpacePriv.h" | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|   27                                      sk_sp<SkData> profileData) |   27                                      sk_sp<SkData> profileData) | 
|   28     : INHERITED(toXYZD50) |   28     : INHERITED(toXYZD50) | 
|   29     , fColorLUT(std::move(colorLUT)) |   29     , fColorLUT(std::move(colorLUT)) | 
|   30     , fGammaNamed(gammaNamed) |   30     , fGammaNamed(gammaNamed) | 
|   31     , fGammas(std::move(gammas)) |   31     , fGammas(std::move(gammas)) | 
|   32     , fProfileData(std::move(profileData)) |   32     , fProfileData(std::move(profileData)) | 
|   33     , fFromXYZD50(SkMatrix44::kUninitialized_Constructor) |   33     , fFromXYZD50(SkMatrix44::kUninitialized_Constructor) | 
|   34 {} |   34 {} | 
|   35  |   35  | 
|   36 static constexpr float gSRGB_toXYZD50[] { |   36 static constexpr float gSRGB_toXYZD50[] { | 
|   37     0.4358f, 0.2224f, 0.0139f,    // * R |   37     0.4358f, 0.3853f, 0.1430f,    // Rx, Gx, Bx | 
|   38     0.3853f, 0.7170f, 0.0971f,    // * G |   38     0.2224f, 0.7170f, 0.0606f,    // Ry, Gy, Gz | 
|   39     0.1430f, 0.0606f, 0.7139f,    // * B |   39     0.0139f, 0.0971f, 0.7139f,    // Rz, Gz, Bz | 
|   40 }; |   40 }; | 
|   41  |   41  | 
|   42 static constexpr float gAdobeRGB_toXYZD50[] { |   42 static constexpr float gAdobeRGB_toXYZD50[] { | 
|   43     0.6098f, 0.3111f, 0.0195f,    // * R |   43     0.6098f, 0.2052f, 0.1492f,    // Rx, Gx, Bx | 
|   44     0.2052f, 0.6257f, 0.0609f,    // * G |   44     0.3111f, 0.6257f, 0.0632f,    // Ry, Gy, By | 
|   45     0.1492f, 0.0632f, 0.7448f,    // * B |   45     0.0195f, 0.0609f, 0.7448f,    // Rz, Gz, Bz | 
|   46 }; |   46 }; | 
|   47  |   47  | 
|   48 /** |   48 /** | 
|   49  *  Checks if our toXYZ matrix is a close match to a known color gamut. |   49  *  Checks if our toXYZ matrix is a close match to a known color gamut. | 
|   50  * |   50  * | 
|   51  *  @param toXYZD50 transformation matrix deduced from profile data |   51  *  @param toXYZD50 transformation matrix deduced from profile data | 
|   52  *  @param standard 3x3 canonical transformation matrix |   52  *  @param standard 3x3 canonical transformation matrix | 
|   53  */ |   53  */ | 
|   54 static bool xyz_almost_equal(const SkMatrix44& toXYZD50, const float* standard) 
     { |   54 static bool xyz_almost_equal(const SkMatrix44& toXYZD50, const float* standard) 
     { | 
|   55     return color_space_almost_equal(toXYZD50.getFloat(0, 0), standard[0]) && |   55     return color_space_almost_equal(toXYZD50.getFloat(0, 0), standard[0]) && | 
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  274         // If we have a named gamma, write the enum and the matrix. |  274         // If we have a named gamma, write the enum and the matrix. | 
|  275         switch (as_CSB(this)->fGammaNamed) { |  275         switch (as_CSB(this)->fGammaNamed) { | 
|  276             case kSRGB_SkGammaNamed: |  276             case kSRGB_SkGammaNamed: | 
|  277             case k2Dot2Curve_SkGammaNamed: |  277             case k2Dot2Curve_SkGammaNamed: | 
|  278             case kLinear_SkGammaNamed: { |  278             case kLinear_SkGammaNamed: { | 
|  279                 if (memory) { |  279                 if (memory) { | 
|  280                     *((ColorSpaceHeader*) memory) = |  280                     *((ColorSpaceHeader*) memory) = | 
|  281                             ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)->
     fGammaNamed, |  281                             ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)->
     fGammaNamed, | 
|  282                                                    ColorSpaceHeader::kMatrix_Fla
     g); |  282                                                    ColorSpaceHeader::kMatrix_Fla
     g); | 
|  283                     memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
     ); |  283                     memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
     ); | 
|  284                     fToXYZD50.as4x3ColMajorf((float*) memory); |  284                     fToXYZD50.as3x4RowMajorf((float*) memory); | 
|  285                 } |  285                 } | 
|  286                 return sizeof(ColorSpaceHeader) + 12 * sizeof(float); |  286                 return sizeof(ColorSpaceHeader) + 12 * sizeof(float); | 
|  287             } |  287             } | 
|  288             default: |  288             default: | 
|  289                 // Otherwise, write the gamma values and the matrix. |  289                 // Otherwise, write the gamma values and the matrix. | 
|  290                 if (memory) { |  290                 if (memory) { | 
|  291                     *((ColorSpaceHeader*) memory) = |  291                     *((ColorSpaceHeader*) memory) = | 
|  292                             ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)->
     fGammaNamed, |  292                             ColorSpaceHeader::Pack(k0_Version, 0, as_CSB(this)->
     fGammaNamed, | 
|  293                                                    ColorSpaceHeader::kFloatGamma
     _Flag); |  293                                                    ColorSpaceHeader::kFloatGamma
     _Flag); | 
|  294                     memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
     ); |  294                     memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader)
     ); | 
|  295  |  295  | 
|  296                     const SkGammas* gammas = as_CSB(this)->gammas(); |  296                     const SkGammas* gammas = as_CSB(this)->gammas(); | 
|  297                     SkASSERT(gammas); |  297                     SkASSERT(gammas); | 
|  298                     SkASSERT(SkGammas::Type::kValue_Type == gammas->fRedType && |  298                     SkASSERT(SkGammas::Type::kValue_Type == gammas->fRedType && | 
|  299                              SkGammas::Type::kValue_Type == gammas->fGreenType &
     & |  299                              SkGammas::Type::kValue_Type == gammas->fGreenType &
     & | 
|  300                              SkGammas::Type::kValue_Type == gammas->fBlueType); |  300                              SkGammas::Type::kValue_Type == gammas->fBlueType); | 
|  301                     *(((float*) memory) + 0) = gammas->fRedData.fValue; |  301                     *(((float*) memory) + 0) = gammas->fRedData.fValue; | 
|  302                     *(((float*) memory) + 1) = gammas->fGreenData.fValue; |  302                     *(((float*) memory) + 1) = gammas->fGreenData.fValue; | 
|  303                     *(((float*) memory) + 2) = gammas->fBlueData.fValue; |  303                     *(((float*) memory) + 2) = gammas->fBlueData.fValue; | 
|  304                     memory = SkTAddOffset<void>(memory, 3 * sizeof(float)); |  304                     memory = SkTAddOffset<void>(memory, 3 * sizeof(float)); | 
|  305  |  305  | 
|  306                     fToXYZD50.as4x3ColMajorf((float*) memory); |  306                     fToXYZD50.as3x4RowMajorf((float*) memory); | 
|  307                 } |  307                 } | 
|  308                 return sizeof(ColorSpaceHeader) + 15 * sizeof(float); |  308                 return sizeof(ColorSpaceHeader) + 15 * sizeof(float); | 
|  309         } |  309         } | 
|  310     } |  310     } | 
|  311  |  311  | 
|  312     // Otherwise, serialize the ICC data. |  312     // Otherwise, serialize the ICC data. | 
|  313     size_t profileSize = as_CSB(this)->fProfileData->size(); |  313     size_t profileSize = as_CSB(this)->fProfileData->size(); | 
|  314     if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) { |  314     if (SkAlign4(profileSize) != (uint32_t) SkAlign4(profileSize)) { | 
|  315         return 0; |  315         return 0; | 
|  316     } |  316     } | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  355  |  355  | 
|  356     switch ((SkGammaNamed) header.fGammaNamed) { |  356     switch ((SkGammaNamed) header.fGammaNamed) { | 
|  357         case kSRGB_SkGammaNamed: |  357         case kSRGB_SkGammaNamed: | 
|  358         case k2Dot2Curve_SkGammaNamed: |  358         case k2Dot2Curve_SkGammaNamed: | 
|  359         case kLinear_SkGammaNamed: { |  359         case kLinear_SkGammaNamed: { | 
|  360             if (ColorSpaceHeader::kMatrix_Flag != header.fFlags || length < 12 *
      sizeof(float)) { |  360             if (ColorSpaceHeader::kMatrix_Flag != header.fFlags || length < 12 *
      sizeof(float)) { | 
|  361                 return nullptr; |  361                 return nullptr; | 
|  362             } |  362             } | 
|  363  |  363  | 
|  364             SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); |  364             SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); | 
|  365             toXYZ.set4x3ColMajorf((const float*) data); |  365             toXYZ.set3x4RowMajorf((const float*) data); | 
|  366             return SkColorSpace_Base::NewRGB((SkGammaNamed) header.fGammaNamed, 
     toXYZ); |  366             return SkColorSpace_Base::NewRGB((SkGammaNamed) header.fGammaNamed, 
     toXYZ); | 
|  367         } |  367         } | 
|  368         default: |  368         default: | 
|  369             break; |  369             break; | 
|  370     } |  370     } | 
|  371  |  371  | 
|  372     switch (header.fFlags) { |  372     switch (header.fFlags) { | 
|  373         case ColorSpaceHeader::kICC_Flag: { |  373         case ColorSpaceHeader::kICC_Flag: { | 
|  374             if (length < sizeof(uint32_t)) { |  374             if (length < sizeof(uint32_t)) { | 
|  375                 return nullptr; |  375                 return nullptr; | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|  389                 return nullptr; |  389                 return nullptr; | 
|  390             } |  390             } | 
|  391  |  391  | 
|  392             float gammas[3]; |  392             float gammas[3]; | 
|  393             gammas[0] = *(((const float*) data) + 0); |  393             gammas[0] = *(((const float*) data) + 0); | 
|  394             gammas[1] = *(((const float*) data) + 1); |  394             gammas[1] = *(((const float*) data) + 1); | 
|  395             gammas[2] = *(((const float*) data) + 2); |  395             gammas[2] = *(((const float*) data) + 2); | 
|  396             data = SkTAddOffset<const void>(data, 3 * sizeof(float)); |  396             data = SkTAddOffset<const void>(data, 3 * sizeof(float)); | 
|  397  |  397  | 
|  398             SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); |  398             SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); | 
|  399             toXYZ.set4x3ColMajorf((const float*) data); |  399             toXYZ.set3x4RowMajorf((const float*) data); | 
|  400             return SkColorSpace_Base::NewRGB(gammas, toXYZ); |  400             return SkColorSpace_Base::NewRGB(gammas, toXYZ); | 
|  401         } |  401         } | 
|  402         default: |  402         default: | 
|  403             return nullptr; |  403             return nullptr; | 
|  404     } |  404     } | 
|  405 } |  405 } | 
|  406  |  406  | 
|  407 bool SkColorSpace::Equals(const SkColorSpace* src, const SkColorSpace* dst) { |  407 bool SkColorSpace::Equals(const SkColorSpace* src, const SkColorSpace* dst) { | 
|  408     if (src == dst) { |  408     if (src == dst) { | 
|  409         return true; |  409         return true; | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
|  437                 return false; |  437                 return false; | 
|  438             } |  438             } | 
|  439  |  439  | 
|  440             // It is unlikely that we will reach this case. |  440             // It is unlikely that we will reach this case. | 
|  441             sk_sp<SkData> srcData = src->serialize(); |  441             sk_sp<SkData> srcData = src->serialize(); | 
|  442             sk_sp<SkData> dstData = dst->serialize(); |  442             sk_sp<SkData> dstData = dst->serialize(); | 
|  443             return srcData->size() == dstData->size() && |  443             return srcData->size() == dstData->size() && | 
|  444                    0 == memcmp(srcData->data(), dstData->data(), srcData->size()
     ); |  444                    0 == memcmp(srcData->data(), dstData->data(), srcData->size()
     ); | 
|  445     } |  445     } | 
|  446 } |  446 } | 
| OLD | NEW |