Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: src/opts/SkColorXform_opts.h

Issue 2195523002: Revert of Add color space xform support to SkJpegCodec (includes F16!) (Closed) Base URL: https://skia.googlesource.com/skia.git@drop
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkOpts.cpp ('k') | src/opts/SkOpts_sse41.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 enum DstGamma { 34 enum DstGamma {
35 // 8888 35 // 8888
36 kSRGB_DstGamma, 36 kSRGB_DstGamma,
37 k2Dot2_DstGamma, 37 k2Dot2_DstGamma,
38 kTable_DstGamma, 38 kTable_DstGamma,
39 39
40 // F16 40 // F16
41 kLinear_DstGamma, 41 kLinear_DstGamma,
42 }; 42 };
43 43
44 template <DstGamma kDstGamma, bool kSwapRB> 44 template <DstGamma kDstGamma>
45 static void color_xform_RGB1(void* dst, const uint32_t* src, int len, 45 static void color_xform_RGB1(void* dst, const uint32_t* src, int len,
46 const float* const srcTables[3], const float matrix [16], 46 const float* const srcTables[3], const float matrix [16],
47 const uint8_t* const dstTables[3]) { 47 const uint8_t* const dstTables[3]) {
48 int kRShift = 0;
49 int kGShift = 8;
50 int kBShift = 16;
51 int kAShift = 24;
52 if (kSwapRB) {
53 kBShift = 0;
54 kRShift = 16;
55 }
56
57 Sk4f rXgXbX = Sk4f::Load(matrix + 0), 48 Sk4f rXgXbX = Sk4f::Load(matrix + 0),
58 rYgYbY = Sk4f::Load(matrix + 4), 49 rYgYbY = Sk4f::Load(matrix + 4),
59 rZgZbZ = Sk4f::Load(matrix + 8), 50 rZgZbZ = Sk4f::Load(matrix + 8),
60 rTgTbT = Sk4f::Load(matrix + 12); 51 rTgTbT = Sk4f::Load(matrix + 12);
61 52
62 if (len >= 4) { 53 if (len >= 4) {
63 Sk4f reds, greens, blues; 54 Sk4f reds, greens, blues;
64 auto load_next_4 = [&reds, &greens, &blues, &src, &len, &srcTables] { 55 auto load_next_4 = [&reds, &greens, &blues, &src, &len, &srcTables] {
65 reds = Sk4f{srcTables[0][(src[0] >> 0) & 0xFF], 56 reds = Sk4f{srcTables[0][(src[0] >> 0) & 0xFF],
66 srcTables[0][(src[1] >> 0) & 0xFF], 57 srcTables[0][(src[1] >> 0) & 0xFF],
(...skipping 12 matching lines...) Expand all
79 }; 70 };
80 71
81 Sk4f dstReds, dstGreens, dstBlues; 72 Sk4f dstReds, dstGreens, dstBlues;
82 auto transform_4 = [&reds, &greens, &blues, &dstReds, &dstGreens, &dstBl ues, &rXgXbX, 73 auto transform_4 = [&reds, &greens, &blues, &dstReds, &dstGreens, &dstBl ues, &rXgXbX,
83 &rYgYbY, &rZgZbZ, &rTgTbT] { 74 &rYgYbY, &rZgZbZ, &rTgTbT] {
84 dstReds = rXgXbX[0]*reds + rYgYbY[0]*greens + rZgZbZ[0]*blues + rT gTbT[0]; 75 dstReds = rXgXbX[0]*reds + rYgYbY[0]*greens + rZgZbZ[0]*blues + rT gTbT[0];
85 dstGreens = rXgXbX[1]*reds + rYgYbY[1]*greens + rZgZbZ[1]*blues + rT gTbT[1]; 76 dstGreens = rXgXbX[1]*reds + rYgYbY[1]*greens + rZgZbZ[1]*blues + rT gTbT[1];
86 dstBlues = rXgXbX[2]*reds + rYgYbY[2]*greens + rZgZbZ[2]*blues + rT gTbT[2]; 77 dstBlues = rXgXbX[2]*reds + rYgYbY[2]*greens + rZgZbZ[2]*blues + rT gTbT[2];
87 }; 78 };
88 79
89 auto store_4 = [&dstReds, &dstGreens, &dstBlues, &dst, &dstTables, kRShi ft, kGShift, 80 auto store_4 = [&dstReds, &dstGreens, &dstBlues, &dst, &dstTables] {
90 kBShift, kAShift] {
91 if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) { 81 if (kSRGB_DstGamma == kDstGamma || k2Dot2_DstGamma == kDstGamma) {
92 Sk4f (*linear_to_curve)(const Sk4f&) = (kSRGB_DstGamma == kDstGa mma) ? 82 Sk4f (*linear_to_curve)(const Sk4f&) = (kSRGB_DstGamma == kDstGa mma) ?
93 sk_linear_to_srgb_needs_trunc : linear_to_2dot2; 83 sk_linear_to_srgb_needs_trunc : linear_to_2dot2;
94 Sk4i (*float_to_int)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma ) ? 84 Sk4i (*float_to_int)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma ) ?
95 Sk4f_trunc : Sk4f_round; 85 Sk4f_trunc : Sk4f_round;
96 86
97 dstReds = linear_to_curve(dstReds); 87 dstReds = linear_to_curve(dstReds);
98 dstGreens = linear_to_curve(dstGreens); 88 dstGreens = linear_to_curve(dstGreens);
99 dstBlues = linear_to_curve(dstBlues); 89 dstBlues = linear_to_curve(dstBlues);
100 90
101 dstReds = sk_clamp_0_255(dstReds); 91 dstReds = sk_clamp_0_255(dstReds);
102 dstGreens = sk_clamp_0_255(dstGreens); 92 dstGreens = sk_clamp_0_255(dstGreens);
103 dstBlues = sk_clamp_0_255(dstBlues); 93 dstBlues = sk_clamp_0_255(dstBlues);
104 94
105 auto rgba = (float_to_int(dstReds) << kRShift) 95 auto rgba = (float_to_int(dstReds) << SK_R32_SHIFT)
106 | (float_to_int(dstGreens) << kGShift) 96 | (float_to_int(dstGreens) << SK_G32_SHIFT)
107 | (float_to_int(dstBlues) << kBShift) 97 | (float_to_int(dstBlues) << SK_B32_SHIFT)
108 | (Sk4i{0xFF} << kAShift); 98 | (Sk4i{0xFF} << SK_A32_SHIFT);
109 rgba.store((uint32_t*) dst); 99 rgba.store((uint32_t*) dst);
110 100
111 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t)); 101 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t));
112 } else if (kTable_DstGamma == kDstGamma) { 102 } else if (kTable_DstGamma == kDstGamma) {
113 Sk4f scaledReds = Sk4f::Min(Sk4f::Max(1023.0f * dstReds, 0.0 f), 1023.0f); 103 Sk4f scaledReds = Sk4f::Min(Sk4f::Max(1023.0f * dstReds, 0.0 f), 1023.0f);
114 Sk4f scaledGreens = Sk4f::Min(Sk4f::Max(1023.0f * dstGreens, 0.0 f), 1023.0f); 104 Sk4f scaledGreens = Sk4f::Min(Sk4f::Max(1023.0f * dstGreens, 0.0 f), 1023.0f);
115 Sk4f scaledBlues = Sk4f::Min(Sk4f::Max(1023.0f * dstBlues, 0.0 f), 1023.0f); 105 Sk4f scaledBlues = Sk4f::Min(Sk4f::Max(1023.0f * dstBlues, 0.0 f), 1023.0f);
116 106
117 Sk4i indicesReds = Sk4f_round(scaledReds); 107 Sk4i indicesReds = Sk4f_round(scaledReds);
118 Sk4i indicesGreens = Sk4f_round(scaledGreens); 108 Sk4i indicesGreens = Sk4f_round(scaledGreens);
119 Sk4i indicesBlues = Sk4f_round(scaledBlues); 109 Sk4i indicesBlues = Sk4f_round(scaledBlues);
120 110
121 uint32_t* dst32 = (uint32_t*) dst; 111 uint32_t* dst32 = (uint32_t*) dst;
122 dst32[0] = dstTables[0][indicesReds [0]] << kRShift 112 dst32[0] = dstTables[0][indicesReds [0]] << SK_R32_SHIFT
123 | dstTables[1][indicesGreens[0]] << kGShift 113 | dstTables[1][indicesGreens[0]] << SK_G32_SHIFT
124 | dstTables[2][indicesBlues [0]] << kBShift 114 | dstTables[2][indicesBlues [0]] << SK_B32_SHIFT
125 | 0xFF << kAShift; 115 | 0xFF << SK_A32_SHIFT;
126 dst32[1] = dstTables[0][indicesReds [1]] << kRShift 116 dst32[1] = dstTables[0][indicesReds [1]] << SK_R32_SHIFT
127 | dstTables[1][indicesGreens[1]] << kGShift 117 | dstTables[1][indicesGreens[1]] << SK_G32_SHIFT
128 | dstTables[2][indicesBlues [1]] << kBShift 118 | dstTables[2][indicesBlues [1]] << SK_B32_SHIFT
129 | 0xFF << kAShift; 119 | 0xFF << SK_A32_SHIFT;
130 dst32[2] = dstTables[0][indicesReds [2]] << kRShift 120 dst32[2] = dstTables[0][indicesReds [2]] << SK_R32_SHIFT
131 | dstTables[1][indicesGreens[2]] << kGShift 121 | dstTables[1][indicesGreens[2]] << SK_G32_SHIFT
132 | dstTables[2][indicesBlues [2]] << kBShift 122 | dstTables[2][indicesBlues [2]] << SK_B32_SHIFT
133 | 0xFF << kAShift; 123 | 0xFF << SK_A32_SHIFT;
134 dst32[3] = dstTables[0][indicesReds [3]] << kRShift 124 dst32[3] = dstTables[0][indicesReds [3]] << SK_R32_SHIFT
135 | dstTables[1][indicesGreens[3]] << kGShift 125 | dstTables[1][indicesGreens[3]] << SK_G32_SHIFT
136 | dstTables[2][indicesBlues [3]] << kBShift 126 | dstTables[2][indicesBlues [3]] << SK_B32_SHIFT
137 | 0xFF << kAShift; 127 | 0xFF << SK_A32_SHIFT;
138 128
139 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t)); 129 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint32_t));
140 } else { 130 } else {
141 Sk4h_store4(dst, SkFloatToHalf_finite(dstReds), 131 Sk4h_store4(dst, SkFloatToHalf_finite(dstReds),
142 SkFloatToHalf_finite(dstGreens), 132 SkFloatToHalf_finite(dstGreens),
143 SkFloatToHalf_finite(dstBlues), 133 SkFloatToHalf_finite(dstBlues),
144 SK_Half1); 134 SK_Half1);
145 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint64_t)); 135 dst = SkTAddOffset<void>(dst, 4 * sizeof(uint64_t));
146 } 136 }
147 }; 137 };
(...skipping 22 matching lines...) Expand all
170 Sk4f (*linear_to_curve)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma) ? 160 Sk4f (*linear_to_curve)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma) ?
171 sk_linear_to_srgb_needs_trunc : linear_to_2dot2; 161 sk_linear_to_srgb_needs_trunc : linear_to_2dot2;
172 Sk4i (*float_to_int)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma) ? 162 Sk4i (*float_to_int)(const Sk4f&) = (kSRGB_DstGamma == kDstGamma) ?
173 Sk4f_trunc : Sk4f_round; 163 Sk4f_trunc : Sk4f_round;
174 164
175 dstPixel = sk_clamp_0_255(linear_to_curve(dstPixel)); 165 dstPixel = sk_clamp_0_255(linear_to_curve(dstPixel));
176 166
177 uint32_t rgba; 167 uint32_t rgba;
178 SkNx_cast<uint8_t>(float_to_int(dstPixel)).store(&rgba); 168 SkNx_cast<uint8_t>(float_to_int(dstPixel)).store(&rgba);
179 rgba |= 0xFF000000; 169 rgba |= 0xFF000000;
180 if (kSwapRB) { 170 *((uint32_t*) dst) = SkSwizzle_RGBA_to_PMColor(rgba);
181 *((uint32_t*) dst) = SkSwizzle_RB(rgba);
182 } else {
183 *((uint32_t*) dst) = rgba;
184 }
185 dst = SkTAddOffset<void>(dst, sizeof(uint32_t)); 171 dst = SkTAddOffset<void>(dst, sizeof(uint32_t));
186 } else if (kTable_DstGamma == kDstGamma) { 172 } else if (kTable_DstGamma == kDstGamma) {
187 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);
188 174
189 Sk4i indices = Sk4f_round(scaledPixel); 175 Sk4i indices = Sk4f_round(scaledPixel);
190 176
191 *((uint32_t*) dst) = dstTables[0][indices[0]] << kRShift 177 *((uint32_t*) dst) = dstTables[0][indices[0]] << SK_R32_SHIFT
192 | dstTables[1][indices[1]] << kGShift 178 | dstTables[1][indices[1]] << SK_G32_SHIFT
193 | dstTables[2][indices[2]] << kBShift 179 | dstTables[2][indices[2]] << SK_B32_SHIFT
194 | 0xFF << kAShift; 180 | 0xFF << SK_A32_SHIFT;
195 181
196 dst = SkTAddOffset<void>(dst, sizeof(uint32_t)); 182 dst = SkTAddOffset<void>(dst, sizeof(uint32_t));
197 } else { 183 } else {
198 uint64_t rgba; 184 uint64_t rgba;
199 SkFloatToHalf_finite(dstPixel).store(&rgba); 185 SkFloatToHalf_finite(dstPixel).store(&rgba);
200 rgba |= static_cast<uint64_t>(SK_Half1) << 48; 186 rgba |= static_cast<uint64_t>(SK_Half1) << 48;
201 *((uint64_t*) dst) = rgba; 187 *((uint64_t*) dst) = rgba;
202 dst = SkTAddOffset<void>(dst, sizeof(uint64_t)); 188 dst = SkTAddOffset<void>(dst, sizeof(uint64_t));
203 } 189 }
204 190
205 src += 1; 191 src += 1;
206 len -= 1; 192 len -= 1;
207 } 193 }
208 } 194 }
209 195
210 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,
211 const float* const srcTables[3], const flo at matrix[16]) { 197 const float* const srcTables[3], const flo at matrix[16]) {
212 color_xform_RGB1<k2Dot2_DstGamma, false>(dst, src, len, srcTables, matrix, n ullptr); 198 color_xform_RGB1<k2Dot2_DstGamma>(dst, src, len, srcTables, matrix, nullptr) ;
213 } 199 }
214 200
215 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 ,
216 const float* const srcTables[3], const floa t matrix[16]) { 202 const float* const srcTables[3], const floa t matrix[16]) {
217 color_xform_RGB1<kSRGB_DstGamma, false>(dst, src, len, srcTables, matrix, nu llptr); 203 color_xform_RGB1<kSRGB_DstGamma>(dst, src, len, srcTables, matrix, nullptr);
218 } 204 }
219 205
220 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,
221 const float* const srcTables[3], const flo at matrix[16], 207 const float* const srcTables[3], const flo at matrix[16],
222 const uint8_t* const dstTables[3]) { 208 const uint8_t* const dstTables[3]) {
223 color_xform_RGB1<kTable_DstGamma, false>(dst, src, len, srcTables, matrix, d stTables); 209 color_xform_RGB1<kTable_DstGamma>(dst, src, len, srcTables, matrix, dstTable s);
224 } 210 }
225 211
226 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,
227 const float* const srcTables[3], const fl oat matrix[16]) { 213 const float* const srcTables[3], const fl oat matrix[16]) {
228 color_xform_RGB1<kLinear_DstGamma, false>(dst, src, len, srcTables, matrix, nullptr); 214 color_xform_RGB1<kLinear_DstGamma>(dst, src, len, srcTables, matrix, nullptr );
229 }
230
231 static void color_xform_RGB1_to_2dot2_swaprb(uint32_t* dst, const uint32_t* src, int len,
232 const float* const srcTables[3],
233 const float matrix[16]) {
234 color_xform_RGB1<k2Dot2_DstGamma, true>(dst, src, len, srcTables, matrix, nu llptr);
235 }
236
237 static void color_xform_RGB1_to_srgb_swaprb(uint32_t* dst, const uint32_t* src, int len,
238 const float* const srcTables[3],
239 const float matrix[16]) {
240 color_xform_RGB1<kSRGB_DstGamma, true>(dst, src, len, srcTables, matrix, nul lptr);
241 }
242
243 static void color_xform_RGB1_to_table_swaprb(uint32_t* dst, const uint32_t* src, int len,
244 const float* const srcTables[3],
245 const float matrix[16],
246 const uint8_t* const dstTables[3]) {
247 color_xform_RGB1<kTable_DstGamma, true>(dst, src, len, srcTables, matrix, ds tTables);
248 } 215 }
249 216
250 } // namespace SK_OPTS_NS 217 } // namespace SK_OPTS_NS
251 218
252 #endif // SkColorXform_opts_DEFINED 219 #endif // SkColorXform_opts_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkOpts.cpp ('k') | src/opts/SkOpts_sse41.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698