Index: src/opts/SkColorXform_opts.h |
diff --git a/src/opts/SkColorXform_opts.h b/src/opts/SkColorXform_opts.h |
index b3da55c1fdd758d2b3b7d74ea41b050b5918eb18..3160c4c81b0f41348f6dbca0aa17b0890ec16294 100644 |
--- a/src/opts/SkColorXform_opts.h |
+++ b/src/opts/SkColorXform_opts.h |
@@ -16,25 +16,9 @@ |
namespace SK_OPTS_NS { |
-// Strange that we need a wrapper on SkNx_cast to use as a function ptr. |
-static Sk4i Sk4f_trunc(const Sk4f& x) { |
- return SkNx_cast<int>(x); |
-} |
- |
-static 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(); |
-} |
- |
enum DstGamma { |
// 8888 |
kSRGB_DstGamma, |
- k2Dot2_DstGamma, |
kTable_DstGamma, |
// F16 |
@@ -88,24 +72,19 @@ static void color_xform_RGB1(void* dst, const uint32_t* src, int len, |
auto store_4 = [&dstReds, &dstGreens, &dstBlues, &dst, &dstTables, kRShift, kGShift, |
kBShift, kAShift] { |
- if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) { |
- Sk4f (*linear_to_curve)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma) ? |
- sk_linear_to_srgb_needs_trunc : linear_to_2dot2; |
- Sk4i (*float_to_int)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma) ? |
- Sk4f_trunc : Sk4f_round; |
- |
- dstReds = linear_to_curve(dstReds); |
- dstGreens = linear_to_curve(dstGreens); |
- dstBlues = linear_to_curve(dstBlues); |
+ if (kSRGB_DstGamma == kDstGamma) { |
+ dstReds = sk_linear_to_srgb_needs_trunc(dstReds); |
+ dstGreens = sk_linear_to_srgb_needs_trunc(dstGreens); |
+ dstBlues = sk_linear_to_srgb_needs_trunc(dstBlues); |
dstReds = sk_clamp_0_255(dstReds); |
dstGreens = sk_clamp_0_255(dstGreens); |
dstBlues = sk_clamp_0_255(dstBlues); |
- auto rgba = (float_to_int(dstReds) << kRShift) |
- | (float_to_int(dstGreens) << kGShift) |
- | (float_to_int(dstBlues) << kBShift) |
- | (Sk4i{0xFF} << kAShift); |
+ auto rgba = (SkNx_cast<int>(dstReds) << kRShift) |
+ | (SkNx_cast<int>(dstGreens) << kGShift) |
+ | (SkNx_cast<int>(dstBlues) << kBShift) |
+ | (Sk4i{0xFF} << kAShift); |
rgba.store((uint32_t*) dst); |
dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t)); |
@@ -166,16 +145,11 @@ static void color_xform_RGB1(void* dst, const uint32_t* src, int len, |
auto dstPixel = rXgXbX*r + rYgYbY*g + rZgZbZ*b + rTgTbT; |
- if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) { |
- Sk4f (*linear_to_curve)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma) ? |
- sk_linear_to_srgb_needs_trunc : linear_to_2dot2; |
- Sk4i (*float_to_int)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma) ? |
- Sk4f_trunc : Sk4f_round; |
- |
- dstPixel = sk_clamp_0_255(linear_to_curve(dstPixel)); |
+ if (kSRGB_DstGamma == kDstGamma) { |
+ dstPixel = sk_clamp_0_255(sk_linear_to_srgb_needs_trunc(dstPixel)); |
uint32_t rgba; |
- SkNx_cast<uint8_t>(float_to_int(dstPixel)).store(&rgba); |
+ SkNx_cast<uint8_t>(SkNx_cast<int>(dstPixel)).store(&rgba); |
rgba |= 0xFF000000; |
if (kSwapRB) { |
*((uint32_t*) dst) = SkSwizzle_RB(rgba); |
@@ -207,11 +181,6 @@ static void color_xform_RGB1(void* dst, const uint32_t* src, int len, |
} |
} |
-static void color_xform_RGB1_to_2dot2(uint32_t* dst, const uint32_t* src, int len, |
- const float* const srcTables[3], const float matrix[16]) { |
- color_xform_RGB1<k2Dot2_DstGamma, false>(dst, src, len, srcTables, matrix, nullptr); |
-} |
- |
static void color_xform_RGB1_to_srgb(uint32_t* dst, const uint32_t* src, int len, |
const float* const srcTables[3], const float matrix[16]) { |
color_xform_RGB1<kSRGB_DstGamma, false>(dst, src, len, srcTables, matrix, nullptr); |
@@ -228,12 +197,6 @@ static void color_xform_RGB1_to_linear(uint64_t* dst, const uint32_t* src, int l |
color_xform_RGB1<kLinear_DstGamma, false>(dst, src, len, srcTables, matrix, nullptr); |
} |
-static void color_xform_RGB1_to_2dot2_swaprb(uint32_t* dst, const uint32_t* src, int len, |
- const float* const srcTables[3], |
- const float matrix[16]) { |
- color_xform_RGB1<k2Dot2_DstGamma, true>(dst, src, len, srcTables, matrix, nullptr); |
-} |
- |
static void color_xform_RGB1_to_srgb_swaprb(uint32_t* dst, const uint32_t* src, int len, |
const float* const srcTables[3], |
const float matrix[16]) { |