| Index: src/core/SkColorSpaceXform.cpp
|
| diff --git a/src/core/SkColorSpaceXform.cpp b/src/core/SkColorSpaceXform.cpp
|
| index c92c37f75b9ac73532e3a94ba3c9c7227f5c9cf3..321828952285a3aac72a3548c0bc4c1c001e4ce8 100644
|
| --- a/src/core/SkColorSpaceXform.cpp
|
| +++ b/src/core/SkColorSpaceXform.cpp
|
| @@ -10,7 +10,9 @@
|
| #include "SkColorSpace_Base.h"
|
| #include "SkColorSpace_XYZ.h"
|
| #include "SkColorSpacePriv.h"
|
| +#include "SkColorSpaceXform_A2B.h"
|
| #include "SkColorSpaceXform_Base.h"
|
| +#include "SkColorSpaceXformPriv.h"
|
| #include "SkHalf.h"
|
| #include "SkOpts.h"
|
| #include "SkSRGB.h"
|
| @@ -90,14 +92,6 @@ static void build_table_linear_from_gamma(float* outTable, float exponent) {
|
| }
|
| }
|
|
|
| -// Interpolating lookup in a variably sized table.
|
| -static float interp_lut(float input, const float* table, int tableSize) {
|
| - float index = input * (tableSize - 1);
|
| - float diff = index - sk_float_floor2int(index);
|
| - return table[(int) sk_float_floor2int(index)] * (1.0f - diff) +
|
| - table[(int) sk_float_ceil2int(index)] * diff;
|
| -}
|
| -
|
| // outTable is always 256 entries, inTable may be larger or smaller.
|
| static void build_table_linear_from_gamma(float* outTable, const float* inTable,
|
| int inTableSize) {
|
| @@ -345,18 +339,14 @@ std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(SkColorSpace* srcSpace
|
| }
|
|
|
| if (SkColorSpace_Base::Type::kA2B == as_CSB(dstSpace)->type()) {
|
| - SkColorSpacePrintf("A2B destinations not supported\n");
|
| + SkCSXformPrintf("A2B destinations not supported\n");
|
| return nullptr;
|
| }
|
|
|
| if (SkColorSpace_Base::Type::kA2B == as_CSB(srcSpace)->type()) {
|
| - // TODO (raftias): return an A2B-supporting SkColorSpaceXform here once the xform.
|
| - // is implemented. SkColorSpaceXform_Base only supports XYZ+TRC based SkColorSpaces
|
| - //SkColorSpace_A2B* src = static_cast<SkColorSpace_A2B*>(srcSpace);
|
| - //SkColorSpace_XYZ* dst = static_cast<SkColorSpace_XYZ*>(dstSpace);
|
| - //return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_A2B(src, dst));
|
| - SkColorSpacePrintf("A2B sources not supported (yet)\n");
|
| - return nullptr;
|
| + SkColorSpace_A2B* src = static_cast<SkColorSpace_A2B*>(srcSpace);
|
| + SkColorSpace_XYZ* dst = static_cast<SkColorSpace_XYZ*>(dstSpace);
|
| + return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_A2B(src, dst));
|
| }
|
| SkColorSpace_XYZ* srcSpaceXYZ = static_cast<SkColorSpace_XYZ*>(srcSpace);
|
| SkColorSpace_XYZ* dstSpaceXYZ = static_cast<SkColorSpace_XYZ*>(dstSpace);
|
| @@ -492,29 +482,6 @@ std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(SkColorSpace* srcSpace
|
|
|
| #define AI SK_ALWAYS_INLINE
|
|
|
| -static AI void load_matrix(const float matrix[16],
|
| - Sk4f& rXgXbX, Sk4f& rYgYbY, Sk4f& rZgZbZ, Sk4f& rTgTbT) {
|
| - rXgXbX = Sk4f::Load(matrix + 0);
|
| - rYgYbY = Sk4f::Load(matrix + 4);
|
| - rZgZbZ = Sk4f::Load(matrix + 8);
|
| - rTgTbT = Sk4f::Load(matrix + 12);
|
| -}
|
| -
|
| -enum Order {
|
| - kRGBA_Order,
|
| - kBGRA_Order,
|
| -};
|
| -
|
| -static AI void set_rb_shifts(Order kOrder, int* kRShift, int* kBShift) {
|
| - if (kRGBA_Order == kOrder) {
|
| - *kRShift = 0;
|
| - *kBShift = 16;
|
| - } else {
|
| - *kRShift = 16;
|
| - *kBShift = 0;
|
| - }
|
| -}
|
| -
|
| template <Order kOrder>
|
| static AI void load_rgb_from_tables(const uint32_t* src,
|
| Sk4f& r, Sk4f& g, Sk4f& b, Sk4f& a,
|
| @@ -558,30 +525,6 @@ static AI void load_rgba_from_tables(const uint32_t* src,
|
| }
|
|
|
| template <Order kOrder>
|
| -static AI void load_rgb_linear(const uint32_t* src,
|
| - Sk4f& r, Sk4f& g, Sk4f& b, Sk4f& a,
|
| - const float* const[3]) {
|
| - int kRShift, kGShift = 8, kBShift;
|
| - set_rb_shifts(kOrder, &kRShift, &kBShift);
|
| - r = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) >> kRShift) & 0xFF);
|
| - g = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) >> kGShift) & 0xFF);
|
| - b = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) >> kBShift) & 0xFF);
|
| - a = 0.0f; // Don't let the compiler complain that |a| is uninitialized.
|
| -}
|
| -
|
| -template <Order kOrder>
|
| -static AI void load_rgba_linear(const uint32_t* src,
|
| - Sk4f& r, Sk4f& g, Sk4f& b, Sk4f& a,
|
| - const float* const[3]) {
|
| - int kRShift, kGShift = 8, kBShift;
|
| - set_rb_shifts(kOrder, &kRShift, &kBShift);
|
| - r = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) >> kRShift) & 0xFF);
|
| - g = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) >> kGShift) & 0xFF);
|
| - b = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) >> kBShift) & 0xFF);
|
| - a = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) >> 24));
|
| -}
|
| -
|
| -template <Order kOrder>
|
| static AI void load_rgb_from_tables_1(const uint32_t* src,
|
| Sk4f& r, Sk4f& g, Sk4f& b, Sk4f& a,
|
| const float* const srcTables[3]) {
|
| @@ -629,65 +572,21 @@ static AI void load_rgba_linear_1(const uint32_t* src,
|
| a = Sk4f((1.0f / 255.0f) * ((*src >> 24)));
|
| }
|
|
|
| -static AI void transform_gamut(const Sk4f& r, const Sk4f& g, const Sk4f& b, const Sk4f& a,
|
| - const Sk4f& rXgXbX, const Sk4f& rYgYbY, const Sk4f& rZgZbZ,
|
| - Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f& da) {
|
| - dr = rXgXbX[0]*r + rYgYbY[0]*g + rZgZbZ[0]*b;
|
| - dg = rXgXbX[1]*r + rYgYbY[1]*g + rZgZbZ[1]*b;
|
| - db = rXgXbX[2]*r + rYgYbY[2]*g + rZgZbZ[2]*b;
|
| - da = a;
|
| -}
|
| -
|
| static AI void transform_gamut_1(const Sk4f& r, const Sk4f& g, const Sk4f& b,
|
| const Sk4f& rXgXbX, const Sk4f& rYgYbY, const Sk4f& rZgZbZ,
|
| Sk4f& rgba) {
|
| rgba = rXgXbX*r + rYgYbY*g + rZgZbZ*b;
|
| }
|
|
|
| -static AI void translate_gamut(const Sk4f& rTgTbT, Sk4f& dr, Sk4f& dg, Sk4f& db) {
|
| - dr = dr + rTgTbT[0];
|
| - dg = dg + rTgTbT[1];
|
| - db = db + rTgTbT[2];
|
| -}
|
| -
|
| static AI void translate_gamut_1(const Sk4f& rTgTbT, Sk4f& rgba) {
|
| rgba = rgba + rTgTbT;
|
| }
|
|
|
| -static AI void premultiply(Sk4f& dr, Sk4f& dg, Sk4f& db, const Sk4f& da) {
|
| - dr = da * dr;
|
| - dg = da * dg;
|
| - db = da * db;
|
| -}
|
| -
|
| static AI void premultiply_1(const Sk4f& a, Sk4f& rgba) {
|
| rgba = a * rgba;
|
| }
|
|
|
| template <Order kOrder>
|
| -static AI void store_srgb(void* dst, const uint32_t* src,
|
| - Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f&,
|
| - const uint8_t* const[3]) {
|
| - int kRShift, kGShift = 8, kBShift;
|
| - set_rb_shifts(kOrder, &kRShift, &kBShift);
|
| - dr = sk_linear_to_srgb_needs_trunc(dr);
|
| - dg = sk_linear_to_srgb_needs_trunc(dg);
|
| - db = sk_linear_to_srgb_needs_trunc(db);
|
| -
|
| - dr = sk_clamp_0_255(dr);
|
| - dg = sk_clamp_0_255(dg);
|
| - db = sk_clamp_0_255(db);
|
| -
|
| - Sk4i da = Sk4i::Load(src) & 0xFF000000;
|
| -
|
| - Sk4i rgba = (SkNx_cast<int>(dr) << kRShift)
|
| - | (SkNx_cast<int>(dg) << kGShift)
|
| - | (SkNx_cast<int>(db) << kBShift)
|
| - | (da );
|
| - rgba.store(dst);
|
| -}
|
| -
|
| -template <Order kOrder>
|
| static AI void store_srgb_1(void* dst, const uint32_t* src,
|
| Sk4f& rgba, const Sk4f&,
|
| const uint8_t* const[3]) {
|
| @@ -703,39 +602,6 @@ static AI void store_srgb_1(void* dst, const uint32_t* src,
|
| *(uint32_t*)dst = tmp;
|
| }
|
|
|
| -static AI Sk4f linear_to_2dot2(const Sk4f& x) {
|
| - // x^(29/64) is a very good approximation of the true value, x^(1/2.2).
|
| - auto x2 = x.rsqrt(), // x^(-1/2)
|
| - x32 = x2.rsqrt().rsqrt().rsqrt().rsqrt(), // x^(-1/32)
|
| - x64 = x32.rsqrt(); // x^(+1/64)
|
| -
|
| - // 29 = 32 - 2 - 1
|
| - return 255.0f * x2.invert() * x32 * x64.invert();
|
| -}
|
| -
|
| -template <Order kOrder>
|
| -static AI void store_2dot2(void* dst, const uint32_t* src,
|
| - Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f&,
|
| - const uint8_t* const[3]) {
|
| - int kRShift, kGShift = 8, kBShift;
|
| - set_rb_shifts(kOrder, &kRShift, &kBShift);
|
| - dr = linear_to_2dot2(dr);
|
| - dg = linear_to_2dot2(dg);
|
| - db = linear_to_2dot2(db);
|
| -
|
| - dr = sk_clamp_0_255(dr);
|
| - dg = sk_clamp_0_255(dg);
|
| - db = sk_clamp_0_255(db);
|
| -
|
| - Sk4i da = Sk4i::Load(src) & 0xFF000000;
|
| -
|
| - Sk4i rgba = (Sk4f_round(dr) << kRShift)
|
| - | (Sk4f_round(dg) << kGShift)
|
| - | (Sk4f_round(db) << kBShift)
|
| - | (da );
|
| - rgba.store(dst);
|
| -}
|
| -
|
| template <Order kOrder>
|
| static AI void store_2dot2_1(void* dst, const uint32_t* src,
|
| Sk4f& rgba, const Sk4f&,
|
| @@ -753,25 +619,6 @@ static AI void store_2dot2_1(void* dst, const uint32_t* src,
|
| }
|
|
|
| template <Order kOrder>
|
| -static AI void store_linear(void* dst, const uint32_t* src,
|
| - Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f&,
|
| - const uint8_t* const[3]) {
|
| - int kRShift, kGShift = 8, kBShift;
|
| - set_rb_shifts(kOrder, &kRShift, &kBShift);
|
| - dr = sk_clamp_0_255(255.0f * dr);
|
| - dg = sk_clamp_0_255(255.0f * dg);
|
| - db = sk_clamp_0_255(255.0f * db);
|
| -
|
| - Sk4i da = Sk4i::Load(src) & 0xFF000000;
|
| -
|
| - Sk4i rgba = (Sk4f_round(dr) << kRShift)
|
| - | (Sk4f_round(dg) << kGShift)
|
| - | (Sk4f_round(db) << kBShift)
|
| - | (da );
|
| - rgba.store(dst);
|
| -}
|
| -
|
| -template <Order kOrder>
|
| static AI void store_linear_1(void* dst, const uint32_t* src,
|
| Sk4f& rgba, const Sk4f&,
|
| const uint8_t* const[3]) {
|
| @@ -787,15 +634,6 @@ static AI void store_linear_1(void* dst, const uint32_t* src,
|
| *(uint32_t*)dst = tmp;
|
| }
|
|
|
| -template <Order kOrder>
|
| -static AI void store_f16(void* dst, const uint32_t* src,
|
| - Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f& da,
|
| - const uint8_t* const[3]) {
|
| - Sk4h::Store4(dst, SkFloatToHalf_finite_ftz(dr),
|
| - SkFloatToHalf_finite_ftz(dg),
|
| - SkFloatToHalf_finite_ftz(db),
|
| - SkFloatToHalf_finite_ftz(da));
|
| -}
|
|
|
| template <Order kOrder>
|
| static AI void store_f16_1(void* dst, const uint32_t* src,
|
| @@ -806,13 +644,6 @@ static AI void store_f16_1(void* dst, const uint32_t* src,
|
| }
|
|
|
| template <Order kOrder>
|
| -static AI void store_f32(void* dst, const uint32_t* src,
|
| - Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f& da,
|
| - const uint8_t* const[3]) {
|
| - Sk4f::Store4(dst, dr, dg, db, da);
|
| -}
|
| -
|
| -template <Order kOrder>
|
| static AI void store_f32_1(void* dst, const uint32_t* src,
|
| Sk4f& rgba, const Sk4f& a,
|
| const uint8_t* const[3]) {
|
| @@ -821,16 +652,6 @@ static AI void store_f32_1(void* dst, const uint32_t* src,
|
| }
|
|
|
| template <Order kOrder>
|
| -static AI void store_f16_opaque(void* dst, const uint32_t* src,
|
| - Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f&,
|
| - const uint8_t* const[3]) {
|
| - Sk4h::Store4(dst, SkFloatToHalf_finite_ftz(dr),
|
| - SkFloatToHalf_finite_ftz(dg),
|
| - SkFloatToHalf_finite_ftz(db),
|
| - SK_Half1);
|
| -}
|
| -
|
| -template <Order kOrder>
|
| static AI void store_f16_1_opaque(void* dst, const uint32_t* src,
|
| Sk4f& rgba, const Sk4f&,
|
| const uint8_t* const[3]) {
|
| @@ -841,41 +662,6 @@ static AI void store_f16_1_opaque(void* dst, const uint32_t* src,
|
| }
|
|
|
| template <Order kOrder>
|
| -static AI void store_generic(void* dst, const uint32_t* src,
|
| - Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f&,
|
| - const uint8_t* const dstTables[3]) {
|
| - int kRShift, kGShift = 8, kBShift;
|
| - set_rb_shifts(kOrder, &kRShift, &kBShift);
|
| - dr = Sk4f::Min(Sk4f::Max(1023.0f * dr, 0.0f), 1023.0f);
|
| - dg = Sk4f::Min(Sk4f::Max(1023.0f * dg, 0.0f), 1023.0f);
|
| - db = Sk4f::Min(Sk4f::Max(1023.0f * db, 0.0f), 1023.0f);
|
| -
|
| - Sk4i ir = Sk4f_round(dr);
|
| - Sk4i ig = Sk4f_round(dg);
|
| - Sk4i ib = Sk4f_round(db);
|
| -
|
| - Sk4i da = Sk4i::Load(src) & 0xFF000000;
|
| -
|
| - uint32_t* dst32 = (uint32_t*) dst;
|
| - dst32[0] = dstTables[0][ir[0]] << kRShift
|
| - | dstTables[1][ig[0]] << kGShift
|
| - | dstTables[2][ib[0]] << kBShift
|
| - | da[0];
|
| - dst32[1] = dstTables[0][ir[1]] << kRShift
|
| - | dstTables[1][ig[1]] << kGShift
|
| - | dstTables[2][ib[1]] << kBShift
|
| - | da[1];
|
| - dst32[2] = dstTables[0][ir[2]] << kRShift
|
| - | dstTables[1][ig[2]] << kGShift
|
| - | dstTables[2][ib[2]] << kBShift
|
| - | da[2];
|
| - dst32[3] = dstTables[0][ir[3]] << kRShift
|
| - | dstTables[1][ig[3]] << kGShift
|
| - | dstTables[2][ib[3]] << kBShift
|
| - | da[3];
|
| -}
|
| -
|
| -template <Order kOrder>
|
| static AI void store_generic_1(void* dst, const uint32_t* src,
|
| Sk4f& rgba, const Sk4f&,
|
| const uint8_t* const dstTables[3]) {
|
| @@ -891,9 +677,7 @@ static AI void store_generic_1(void* dst, const uint32_t* src,
|
| | (*src & 0xFF000000);
|
| }
|
|
|
| -typedef decltype(load_rgb_from_tables<kRGBA_Order> )* LoadFn;
|
| typedef decltype(load_rgb_from_tables_1<kRGBA_Order>)* Load1Fn;
|
| -typedef decltype(store_generic<kRGBA_Order> )* StoreFn;
|
| typedef decltype(store_generic_1<kRGBA_Order> )* Store1Fn;
|
|
|
| enum SrcFormat {
|
| @@ -1105,28 +889,6 @@ static void color_xform_RGBA(void* dst, const void* vsrc, int len,
|
|
|
| ///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
| -static inline int num_tables(SkColorSpace_XYZ* space) {
|
| - switch (space->gammaNamed()) {
|
| - case kSRGB_SkGammaNamed:
|
| - case k2Dot2Curve_SkGammaNamed:
|
| - case kLinear_SkGammaNamed:
|
| - return 0;
|
| - default: {
|
| - const SkGammas* gammas = space->gammas();
|
| - SkASSERT(gammas);
|
| -
|
| - bool gammasAreMatching = (gammas->type(0) == gammas->type(1)) &&
|
| - (gammas->data(0) == gammas->data(1)) &&
|
| - (gammas->type(0) == gammas->type(2)) &&
|
| - (gammas->data(0) == gammas->data(2));
|
| -
|
| - // It's likely that each component will have the same gamma. In this case,
|
| - // we only need to build one table.
|
| - return gammasAreMatching ? 1 : 3;
|
| - }
|
| - }
|
| -}
|
| -
|
| template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM>
|
| SkColorSpaceXform_XYZ<kSrc, kDst, kCSM>
|
| ::SkColorSpaceXform_XYZ(SkColorSpace_XYZ* srcSpace, const SkMatrix44& srcToDst,
|
|
|