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 22 matching lines...) Expand all Loading... |
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> |
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 Sk4f rXgXbX = Sk4f::Load(matrix + 0), | 43 Sk4f rXgXbX = Sk4f::Load(matrix + 0), |
44 rYgYbY = Sk4f::Load(matrix + 4), | 44 rYgYbY = Sk4f::Load(matrix + 4), |
45 rZgZbZ = Sk4f::Load(matrix + 8); | 45 rZgZbZ = Sk4f::Load(matrix + 8), |
| 46 rTgTbT = Sk4f::Load(matrix + 12); |
46 | 47 |
47 if (len >= 4) { | 48 if (len >= 4) { |
48 Sk4f reds, greens, blues; | 49 Sk4f reds, greens, blues; |
49 auto load_next_4 = [&reds, &greens, &blues, &src, &len, &srcTables] { | 50 auto load_next_4 = [&reds, &greens, &blues, &src, &len, &srcTables] { |
50 reds = Sk4f{srcTables[0][(src[0] >> 0) & 0xFF], | 51 reds = Sk4f{srcTables[0][(src[0] >> 0) & 0xFF], |
51 srcTables[0][(src[1] >> 0) & 0xFF], | 52 srcTables[0][(src[1] >> 0) & 0xFF], |
52 srcTables[0][(src[2] >> 0) & 0xFF], | 53 srcTables[0][(src[2] >> 0) & 0xFF], |
53 srcTables[0][(src[3] >> 0) & 0xFF]}; | 54 srcTables[0][(src[3] >> 0) & 0xFF]}; |
54 greens = Sk4f{srcTables[1][(src[0] >> 8) & 0xFF], | 55 greens = Sk4f{srcTables[1][(src[0] >> 8) & 0xFF], |
55 srcTables[1][(src[1] >> 8) & 0xFF], | 56 srcTables[1][(src[1] >> 8) & 0xFF], |
56 srcTables[1][(src[2] >> 8) & 0xFF], | 57 srcTables[1][(src[2] >> 8) & 0xFF], |
57 srcTables[1][(src[3] >> 8) & 0xFF]}; | 58 srcTables[1][(src[3] >> 8) & 0xFF]}; |
58 blues = Sk4f{srcTables[2][(src[0] >> 16) & 0xFF], | 59 blues = Sk4f{srcTables[2][(src[0] >> 16) & 0xFF], |
59 srcTables[2][(src[1] >> 16) & 0xFF], | 60 srcTables[2][(src[1] >> 16) & 0xFF], |
60 srcTables[2][(src[2] >> 16) & 0xFF], | 61 srcTables[2][(src[2] >> 16) & 0xFF], |
61 srcTables[2][(src[3] >> 16) & 0xFF]}; | 62 srcTables[2][(src[3] >> 16) & 0xFF]}; |
62 src += 4; | 63 src += 4; |
63 len -= 4; | 64 len -= 4; |
64 }; | 65 }; |
65 | 66 |
66 Sk4f dstReds, dstGreens, dstBlues; | 67 Sk4f dstReds, dstGreens, dstBlues; |
67 auto transform_4 = [&reds, &greens, &blues, &dstReds, &dstGreens, &dstBl
ues, &rXgXbX, | 68 auto transform_4 = [&reds, &greens, &blues, &dstReds, &dstGreens, &dstBl
ues, &rXgXbX, |
68 &rYgYbY, &rZgZbZ] { | 69 &rYgYbY, &rZgZbZ, &rTgTbT] { |
69 dstReds = rXgXbX[0]*reds + rYgYbY[0]*greens + rZgZbZ[0]*blues; | 70 dstReds = rXgXbX[0]*reds + rYgYbY[0]*greens + rZgZbZ[0]*blues + rT
gTbT[0]; |
70 dstGreens = rXgXbX[1]*reds + rYgYbY[1]*greens + rZgZbZ[1]*blues; | 71 dstGreens = rXgXbX[1]*reds + rYgYbY[1]*greens + rZgZbZ[1]*blues + rT
gTbT[1]; |
71 dstBlues = rXgXbX[2]*reds + rYgYbY[2]*greens + rZgZbZ[2]*blues; | 72 dstBlues = rXgXbX[2]*reds + rYgYbY[2]*greens + rZgZbZ[2]*blues + rT
gTbT[2]; |
72 }; | 73 }; |
73 | 74 |
74 auto store_4 = [&dstReds, &dstGreens, &dstBlues, &dst, &dstTables] { | 75 auto store_4 = [&dstReds, &dstGreens, &dstBlues, &dst, &dstTables] { |
75 if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) { | 76 if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) { |
76 Sk4i (*linear_to_curve)(const Sk4f&) = | 77 Sk4i (*linear_to_curve)(const Sk4f&) = |
77 (kSRGB_DstGamma == kDstGamma) ? sk_linear_to_srgb : line
ar_to_2dot2; | 78 (kSRGB_DstGamma == kDstGamma) ? sk_linear_to_srgb : line
ar_to_2dot2; |
78 | 79 |
79 auto reds = linear_to_curve(dstReds); | 80 auto reds = linear_to_curve(dstReds); |
80 auto greens = linear_to_curve(dstGreens); | 81 auto greens = linear_to_curve(dstGreens); |
81 auto blues = linear_to_curve(dstBlues); | 82 auto blues = linear_to_curve(dstBlues); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 transform_4(); | 136 transform_4(); |
136 store_4(); | 137 store_4(); |
137 } | 138 } |
138 | 139 |
139 while (len > 0) { | 140 while (len > 0) { |
140 // Splat r,g,b across a register each. | 141 // Splat r,g,b across a register each. |
141 auto r = Sk4f{srcTables[0][(*src >> 0) & 0xFF]}, | 142 auto r = Sk4f{srcTables[0][(*src >> 0) & 0xFF]}, |
142 g = Sk4f{srcTables[1][(*src >> 8) & 0xFF]}, | 143 g = Sk4f{srcTables[1][(*src >> 8) & 0xFF]}, |
143 b = Sk4f{srcTables[2][(*src >> 16) & 0xFF]}; | 144 b = Sk4f{srcTables[2][(*src >> 16) & 0xFF]}; |
144 | 145 |
145 auto dstPixel = rXgXbX*r + rYgYbY*g + rZgZbZ*b; | 146 auto dstPixel = rXgXbX*r + rYgYbY*g + rZgZbZ*b + rTgTbT; |
146 | 147 |
147 if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) { | 148 if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) { |
148 Sk4i (*linear_to_curve)(const Sk4f&) = | 149 Sk4i (*linear_to_curve)(const Sk4f&) = |
149 (kSRGB_DstGamma == kDstGamma) ? sk_linear_to_srgb : linear_t
o_2dot2; | 150 (kSRGB_DstGamma == kDstGamma) ? sk_linear_to_srgb : linear_t
o_2dot2; |
150 | 151 |
151 auto pixel = linear_to_curve(dstPixel); | 152 auto pixel = linear_to_curve(dstPixel); |
152 | 153 |
153 uint32_t rgba; | 154 uint32_t rgba; |
154 SkNx_cast<uint8_t>(pixel).store(&rgba); | 155 SkNx_cast<uint8_t>(pixel).store(&rgba); |
155 rgba |= 0xFF000000; | 156 rgba |= 0xFF000000; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 197 } |
197 | 198 |
198 static void color_xform_RGB1_to_linear(uint64_t* dst, const uint32_t* src, int l
en, | 199 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]) { | 200 const float* const srcTables[3], const fl
oat matrix[16]) { |
200 color_xform_RGB1<kLinear_DstGamma>(dst, src, len, srcTables, matrix, nullptr
); | 201 color_xform_RGB1<kLinear_DstGamma>(dst, src, len, srcTables, matrix, nullptr
); |
201 } | 202 } |
202 | 203 |
203 } // namespace SK_OPTS_NS | 204 } // namespace SK_OPTS_NS |
204 | 205 |
205 #endif // SkColorXform_opts_DEFINED | 206 #endif // SkColorXform_opts_DEFINED |
OLD | NEW |