| 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 #ifndef SkColorXform_opts_DEFINED | 8 #ifndef SkColorXform_opts_DEFINED |
| 9 #define SkColorXform_opts_DEFINED | 9 #define SkColorXform_opts_DEFINED |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 enum DstGamma { | 29 enum DstGamma { |
| 30 // 8888 | 30 // 8888 |
| 31 kSRGB_DstGamma, | 31 kSRGB_DstGamma, |
| 32 k2Dot2_DstGamma, | 32 k2Dot2_DstGamma, |
| 33 kTable_DstGamma, | 33 kTable_DstGamma, |
| 34 | 34 |
| 35 // F16 | 35 // F16 |
| 36 kLinear_DstGamma, | 36 kLinear_DstGamma, |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 template <DstGamma kDstGamma> | 39 template <DstGamma kDstGamma, bool kSwapRB> |
| 40 static void color_xform_RGB1(void* dst, const uint32_t* src, int len, | 40 static void color_xform_RGB1(void* dst, const uint32_t* src, int len, |
| 41 const float* const srcTables[3], const float matrix
[16], | 41 const float* const srcTables[3], const float matrix
[16], |
| 42 const uint8_t* const dstTables[3]) { | 42 const uint8_t* const dstTables[3]) { |
| 43 int kRShift = 0; |
| 44 int kGShift = 8; |
| 45 int kBShift = 16; |
| 46 int kAShift = 24; |
| 47 if (kSwapRB) { |
| 48 kBShift = 0; |
| 49 kRShift = 16; |
| 50 } |
| 51 |
| 43 Sk4f rXgXbX = Sk4f::Load(matrix + 0), | 52 Sk4f rXgXbX = Sk4f::Load(matrix + 0), |
| 44 rYgYbY = Sk4f::Load(matrix + 4), | 53 rYgYbY = Sk4f::Load(matrix + 4), |
| 45 rZgZbZ = Sk4f::Load(matrix + 8); | 54 rZgZbZ = Sk4f::Load(matrix + 8); |
| 46 | 55 |
| 47 if (len >= 4) { | 56 if (len >= 4) { |
| 48 Sk4f reds, greens, blues; | 57 Sk4f reds, greens, blues; |
| 49 auto load_next_4 = [&reds, &greens, &blues, &src, &len, &srcTables] { | 58 auto load_next_4 = [&reds, &greens, &blues, &src, &len, &srcTables] { |
| 50 reds = Sk4f{srcTables[0][(src[0] >> 0) & 0xFF], | 59 reds = Sk4f{srcTables[0][(src[0] >> 0) & 0xFF], |
| 51 srcTables[0][(src[1] >> 0) & 0xFF], | 60 srcTables[0][(src[1] >> 0) & 0xFF], |
| 52 srcTables[0][(src[2] >> 0) & 0xFF], | 61 srcTables[0][(src[2] >> 0) & 0xFF], |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 }; | 73 }; |
| 65 | 74 |
| 66 Sk4f dstReds, dstGreens, dstBlues; | 75 Sk4f dstReds, dstGreens, dstBlues; |
| 67 auto transform_4 = [&reds, &greens, &blues, &dstReds, &dstGreens, &dstBl
ues, &rXgXbX, | 76 auto transform_4 = [&reds, &greens, &blues, &dstReds, &dstGreens, &dstBl
ues, &rXgXbX, |
| 68 &rYgYbY, &rZgZbZ] { | 77 &rYgYbY, &rZgZbZ] { |
| 69 dstReds = rXgXbX[0]*reds + rYgYbY[0]*greens + rZgZbZ[0]*blues; | 78 dstReds = rXgXbX[0]*reds + rYgYbY[0]*greens + rZgZbZ[0]*blues; |
| 70 dstGreens = rXgXbX[1]*reds + rYgYbY[1]*greens + rZgZbZ[1]*blues; | 79 dstGreens = rXgXbX[1]*reds + rYgYbY[1]*greens + rZgZbZ[1]*blues; |
| 71 dstBlues = rXgXbX[2]*reds + rYgYbY[2]*greens + rZgZbZ[2]*blues; | 80 dstBlues = rXgXbX[2]*reds + rYgYbY[2]*greens + rZgZbZ[2]*blues; |
| 72 }; | 81 }; |
| 73 | 82 |
| 74 auto store_4 = [&dstReds, &dstGreens, &dstBlues, &dst, &dstTables] { | 83 auto store_4 = [&dstReds, &dstGreens, &dstBlues, &dst, &dstTables, &kRSh
ift, &kGShift, |
| 84 &kBShift, &kAShift] { |
| 75 if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) { | 85 if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) { |
| 76 Sk4i (*linear_to_curve)(const Sk4f&) = | 86 Sk4i (*linear_to_curve)(const Sk4f&) = |
| 77 (kSRGB_DstGamma == kDstGamma) ? sk_linear_to_srgb : line
ar_to_2dot2; | 87 (kSRGB_DstGamma == kDstGamma) ? sk_linear_to_srgb : line
ar_to_2dot2; |
| 78 | 88 |
| 79 auto reds = linear_to_curve(dstReds); | 89 auto reds = linear_to_curve(dstReds); |
| 80 auto greens = linear_to_curve(dstGreens); | 90 auto greens = linear_to_curve(dstGreens); |
| 81 auto blues = linear_to_curve(dstBlues); | 91 auto blues = linear_to_curve(dstBlues); |
| 82 | 92 |
| 83 auto rgba = (reds << SK_R32_SHIFT) | 93 auto rgba = (reds << kRShift) |
| 84 | (greens << SK_G32_SHIFT) | 94 | (greens << kGShift) |
| 85 | (blues << SK_B32_SHIFT) | 95 | (blues << kBShift) |
| 86 | (Sk4i{0xFF} << SK_A32_SHIFT); | 96 | (Sk4i{0xFF} << kAShift); |
| 87 rgba.store((uint32_t*) dst); | 97 rgba.store((uint32_t*) dst); |
| 88 | 98 |
| 89 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t)); | 99 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t)); |
| 90 } else if (kTable_DstGamma == kDstGamma) { | 100 } else if (kTable_DstGamma == kDstGamma) { |
| 91 Sk4f scaledReds = Sk4f::Min(Sk4f::Max(1023.0f * dstReds, 0.0
f), 1023.0f); | 101 Sk4f scaledReds = Sk4f::Min(Sk4f::Max(1023.0f * dstReds, 0.0
f), 1023.0f); |
| 92 Sk4f scaledGreens = Sk4f::Min(Sk4f::Max(1023.0f * dstGreens, 0.0
f), 1023.0f); | 102 Sk4f scaledGreens = Sk4f::Min(Sk4f::Max(1023.0f * dstGreens, 0.0
f), 1023.0f); |
| 93 Sk4f scaledBlues = Sk4f::Min(Sk4f::Max(1023.0f * dstBlues, 0.0
f), 1023.0f); | 103 Sk4f scaledBlues = Sk4f::Min(Sk4f::Max(1023.0f * dstBlues, 0.0
f), 1023.0f); |
| 94 | 104 |
| 95 Sk4i indicesReds = Sk4f_round(scaledReds); | 105 Sk4i indicesReds = Sk4f_round(scaledReds); |
| 96 Sk4i indicesGreens = Sk4f_round(scaledGreens); | 106 Sk4i indicesGreens = Sk4f_round(scaledGreens); |
| 97 Sk4i indicesBlues = Sk4f_round(scaledBlues); | 107 Sk4i indicesBlues = Sk4f_round(scaledBlues); |
| 98 | 108 |
| 99 uint32_t* dst32 = (uint32_t*) dst; | 109 uint32_t* dst32 = (uint32_t*) dst; |
| 100 dst32[0] = dstTables[0][indicesReds [0]] << SK_R32_SHIFT | 110 dst32[0] = dstTables[0][indicesReds [0]] << kRShift |
| 101 | dstTables[1][indicesGreens[0]] << SK_G32_SHIFT | 111 | dstTables[1][indicesGreens[0]] << kGShift |
| 102 | dstTables[2][indicesBlues [0]] << SK_B32_SHIFT | 112 | dstTables[2][indicesBlues [0]] << kBShift |
| 103 | 0xFF << SK_A32_SHIFT; | 113 | 0xFF << kAShift; |
| 104 dst32[1] = dstTables[0][indicesReds [1]] << SK_R32_SHIFT | 114 dst32[1] = dstTables[0][indicesReds [1]] << kRShift |
| 105 | dstTables[1][indicesGreens[1]] << SK_G32_SHIFT | 115 | dstTables[1][indicesGreens[1]] << kGShift |
| 106 | dstTables[2][indicesBlues [1]] << SK_B32_SHIFT | 116 | dstTables[2][indicesBlues [1]] << kBShift |
| 107 | 0xFF << SK_A32_SHIFT; | 117 | 0xFF << kAShift; |
| 108 dst32[2] = dstTables[0][indicesReds [2]] << SK_R32_SHIFT | 118 dst32[2] = dstTables[0][indicesReds [2]] << kRShift |
| 109 | dstTables[1][indicesGreens[2]] << SK_G32_SHIFT | 119 | dstTables[1][indicesGreens[2]] << kGShift |
| 110 | dstTables[2][indicesBlues [2]] << SK_B32_SHIFT | 120 | dstTables[2][indicesBlues [2]] << kBShift |
| 111 | 0xFF << SK_A32_SHIFT; | 121 | 0xFF << kAShift; |
| 112 dst32[3] = dstTables[0][indicesReds [3]] << SK_R32_SHIFT | 122 dst32[3] = dstTables[0][indicesReds [3]] << kRShift |
| 113 | dstTables[1][indicesGreens[3]] << SK_G32_SHIFT | 123 | dstTables[1][indicesGreens[3]] << kGShift |
| 114 | dstTables[2][indicesBlues [3]] << SK_B32_SHIFT | 124 | dstTables[2][indicesBlues [3]] << kBShift |
| 115 | 0xFF << SK_A32_SHIFT; | 125 | 0xFF << kAShift; |
| 116 | 126 |
| 117 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t)); | 127 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t)); |
| 118 } else { | 128 } else { |
| 119 Sk4h_store4(dst, SkFloatToHalf_finite(dstReds), | 129 Sk4h_store4(dst, SkFloatToHalf_finite(dstReds), |
| 120 SkFloatToHalf_finite(dstGreens), | 130 SkFloatToHalf_finite(dstGreens), |
| 121 SkFloatToHalf_finite(dstBlues), | 131 SkFloatToHalf_finite(dstBlues), |
| 122 SK_Half1); | 132 SK_Half1); |
| 123 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint64_t)); | 133 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint64_t)); |
| 124 } | 134 } |
| 125 }; | 135 }; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 146 | 156 |
| 147 if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) { | 157 if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) { |
| 148 Sk4i (*linear_to_curve)(const Sk4f&) = | 158 Sk4i (*linear_to_curve)(const Sk4f&) = |
| 149 (kSRGB_DstGamma == kDstGamma) ? sk_linear_to_srgb : linear_t
o_2dot2; | 159 (kSRGB_DstGamma == kDstGamma) ? sk_linear_to_srgb : linear_t
o_2dot2; |
| 150 | 160 |
| 151 auto pixel = linear_to_curve(dstPixel); | 161 auto pixel = linear_to_curve(dstPixel); |
| 152 | 162 |
| 153 uint32_t rgba; | 163 uint32_t rgba; |
| 154 SkNx_cast<uint8_t>(pixel).store(&rgba); | 164 SkNx_cast<uint8_t>(pixel).store(&rgba); |
| 155 rgba |= 0xFF000000; | 165 rgba |= 0xFF000000; |
| 156 *((uint32_t*) dst) = SkSwizzle_RGBA_to_PMColor(rgba); | 166 if (kSwapRB) { |
| 167 *((uint32_t*) dst) = SkSwizzle_RB(rgba); |
| 168 } else { |
| 169 *((uint32_t*) dst) = rgba; |
| 170 } |
| 157 dst = SkTAddOffset<void>(dst, sizeof(uint32_t)); | 171 dst = SkTAddOffset<void>(dst, sizeof(uint32_t)); |
| 158 } else if (kTable_DstGamma == kDstGamma) { | 172 } else if (kTable_DstGamma == kDstGamma) { |
| 159 Sk4f scaledPixel = Sk4f::Min(Sk4f::Max(1023.0f * dstPixel, 0.0f), 10
23.0f); | 173 Sk4f scaledPixel = Sk4f::Min(Sk4f::Max(1023.0f * dstPixel, 0.0f), 10
23.0f); |
| 160 | 174 |
| 161 Sk4i indices = Sk4f_round(scaledPixel); | 175 Sk4i indices = Sk4f_round(scaledPixel); |
| 162 | 176 |
| 163 *((uint32_t*) dst) = dstTables[0][indices[0]] << SK_R32_SHIFT | 177 *((uint32_t*) dst) = dstTables[0][indices[0]] << kRShift |
| 164 | dstTables[1][indices[1]] << SK_G32_SHIFT | 178 | dstTables[1][indices[1]] << kGShift |
| 165 | dstTables[2][indices[2]] << SK_B32_SHIFT | 179 | dstTables[2][indices[2]] << kBShift |
| 166 | 0xFF << SK_A32_SHIFT; | 180 | 0xFF << kAShift; |
| 167 | 181 |
| 168 dst = SkTAddOffset<void>(dst, sizeof(uint32_t)); | 182 dst = SkTAddOffset<void>(dst, sizeof(uint32_t)); |
| 169 } else { | 183 } else { |
| 170 uint64_t rgba; | 184 uint64_t rgba; |
| 171 SkFloatToHalf_finite(dstPixel).store(&rgba); | 185 SkFloatToHalf_finite(dstPixel).store(&rgba); |
| 172 rgba |= static_cast<uint64_t>(SK_Half1) << 48; | 186 rgba |= static_cast<uint64_t>(SK_Half1) << 48; |
| 173 *((uint64_t*) dst) = rgba; | 187 *((uint64_t*) dst) = rgba; |
| 174 dst = SkTAddOffset<void>(dst, sizeof(uint64_t)); | 188 dst = SkTAddOffset<void>(dst, sizeof(uint64_t)); |
| 175 } | 189 } |
| 176 | 190 |
| 177 src += 1; | 191 src += 1; |
| 178 len -= 1; | 192 len -= 1; |
| 179 } | 193 } |
| 180 } | 194 } |
| 181 | 195 |
| 182 static void color_xform_RGB1_to_2dot2(uint32_t* dst, const uint32_t* src, int le
n, | 196 static void color_xform_RGB1_to_2dot2(uint32_t* dst, const uint32_t* src, int le
n, |
| 183 const float* const srcTables[3], const flo
at matrix[16]) { | 197 const float* const srcTables[3], const flo
at matrix[16]) { |
| 184 color_xform_RGB1<k2Dot2_DstGamma>(dst, src, len, srcTables, matrix, nullptr)
; | 198 color_xform_RGB1<k2Dot2_DstGamma, false>(dst, src, len, srcTables, matrix, n
ullptr); |
| 185 } | 199 } |
| 186 | 200 |
| 187 static void color_xform_RGB1_to_srgb(uint32_t* dst, const uint32_t* src, int len
, | 201 static void color_xform_RGB1_to_srgb(uint32_t* dst, const uint32_t* src, int len
, |
| 188 const float* const srcTables[3], const floa
t matrix[16]) { | 202 const float* const srcTables[3], const floa
t matrix[16]) { |
| 189 color_xform_RGB1<kSRGB_DstGamma>(dst, src, len, srcTables, matrix, nullptr); | 203 color_xform_RGB1<kSRGB_DstGamma, false>(dst, src, len, srcTables, matrix, nu
llptr); |
| 190 } | 204 } |
| 191 | 205 |
| 192 static void color_xform_RGB1_to_table(uint32_t* dst, const uint32_t* src, int le
n, | 206 static void color_xform_RGB1_to_table(uint32_t* dst, const uint32_t* src, int le
n, |
| 193 const float* const srcTables[3], const flo
at matrix[16], | 207 const float* const srcTables[3], const flo
at matrix[16], |
| 194 const uint8_t* const dstTables[3]) { | 208 const uint8_t* const dstTables[3]) { |
| 195 color_xform_RGB1<kTable_DstGamma>(dst, src, len, srcTables, matrix, dstTable
s); | 209 color_xform_RGB1<kTable_DstGamma, false>(dst, src, len, srcTables, matrix, d
stTables); |
| 196 } | 210 } |
| 197 | 211 |
| 198 static void color_xform_RGB1_to_linear(uint64_t* dst, const uint32_t* src, int l
en, | 212 static void color_xform_RGB1_to_linear(uint64_t* dst, const uint32_t* src, int l
en, |
| 199 const float* const srcTables[3], const fl
oat matrix[16]) { | 213 const float* const srcTables[3], const fl
oat matrix[16]) { |
| 200 color_xform_RGB1<kLinear_DstGamma>(dst, src, len, srcTables, matrix, nullptr
); | 214 color_xform_RGB1<kLinear_DstGamma, false>(dst, src, len, srcTables, matrix,
nullptr); |
| 215 } |
| 216 |
| 217 static void color_xform_RGB1_to_2dot2_swaprb(uint32_t* dst, const uint32_t* src,
int len, |
| 218 const float* const srcTables[3], |
| 219 const float matrix[16]) { |
| 220 color_xform_RGB1<k2Dot2_DstGamma, true>(dst, src, len, srcTables, matrix, nu
llptr); |
| 221 } |
| 222 |
| 223 static void color_xform_RGB1_to_srgb_swaprb(uint32_t* dst, const uint32_t* src,
int len, |
| 224 const float* const srcTables[3], |
| 225 const float matrix[16]) { |
| 226 color_xform_RGB1<kSRGB_DstGamma, true>(dst, src, len, srcTables, matrix, nul
lptr); |
| 227 } |
| 228 |
| 229 static void color_xform_RGB1_to_table_swaprb(uint32_t* dst, const uint32_t* src,
int len, |
| 230 const float* const srcTables[3], |
| 231 const float matrix[16], |
| 232 const uint8_t* const dstTables[3])
{ |
| 233 color_xform_RGB1<kTable_DstGamma, true>(dst, src, len, srcTables, matrix, ds
tTables); |
| 201 } | 234 } |
| 202 | 235 |
| 203 } // namespace SK_OPTS_NS | 236 } // namespace SK_OPTS_NS |
| 204 | 237 |
| 205 #endif // SkColorXform_opts_DEFINED | 238 #endif // SkColorXform_opts_DEFINED |
| OLD | NEW |