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

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

Issue 2081933005: Do loads and math in parallel in SkColorXform_opts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Don't close over rgba Created 4 years, 6 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 | « no previous file | no next file » | 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 static Sk4f clamp_0_to_255(const Sk4f& x) { 180 static Sk4f clamp_0_to_255(const Sk4f& x) {
181 // The order of the arguments is important here. We want to make sure that NaN 181 // The order of the arguments is important here. We want to make sure that NaN
182 // clamps to zero. Note that max(NaN, 0) = 0, while max(0, NaN) = NaN. 182 // clamps to zero. Note that max(NaN, 0) = 0, while max(0, NaN) = NaN.
183 return Sk4f::Min(Sk4f::Max(x, 0.0f), 255.0f); 183 return Sk4f::Min(Sk4f::Max(x, 0.0f), 255.0f);
184 } 184 }
185 185
186 template <const float (&linear_from_curve)[256], Sk4f (*linear_to_curve)(const S k4f&)> 186 template <const float (&linear_from_curve)[256], Sk4f (*linear_to_curve)(const S k4f&)>
187 static void color_xform_RGB1(uint32_t* dst, const uint32_t* src, int len, 187 static void color_xform_RGB1(uint32_t* dst, const uint32_t* src, int len,
188 const float matrix[16]) { 188 const float matrix[16]) {
189 // Load transformation matrix. 189 Sk4f rXgXbX = Sk4f::Load(matrix + 0),
190 auto rXgXbX = Sk4f::Load(matrix + 0),
191 rYgYbY = Sk4f::Load(matrix + 4), 190 rYgYbY = Sk4f::Load(matrix + 4),
192 rZgZbZ = Sk4f::Load(matrix + 8); 191 rZgZbZ = Sk4f::Load(matrix + 8);
193 192
194 while (len >= 4) { 193 if (len >= 4) {
195 // Convert to linear. The look-up table has perfect accuracy. 194 Sk4f reds, greens, blues;
196 auto reds = Sk4f{linear_from_curve[(src[0] >> 0) & 0xFF], 195 auto load_next_4 = [&reds, &greens, &blues, &src, &len] {
197 linear_from_curve[(src[1] >> 0) & 0xFF], 196 reds = Sk4f{linear_from_curve[(src[0] >> 0) & 0xFF],
198 linear_from_curve[(src[2] >> 0) & 0xFF], 197 linear_from_curve[(src[1] >> 0) & 0xFF],
199 linear_from_curve[(src[3] >> 0) & 0xFF]}; 198 linear_from_curve[(src[2] >> 0) & 0xFF],
200 auto greens = Sk4f{linear_from_curve[(src[0] >> 8) & 0xFF], 199 linear_from_curve[(src[3] >> 0) & 0xFF]};
201 linear_from_curve[(src[1] >> 8) & 0xFF], 200 greens = Sk4f{linear_from_curve[(src[0] >> 8) & 0xFF],
202 linear_from_curve[(src[2] >> 8) & 0xFF], 201 linear_from_curve[(src[1] >> 8) & 0xFF],
203 linear_from_curve[(src[3] >> 8) & 0xFF]}; 202 linear_from_curve[(src[2] >> 8) & 0xFF],
204 auto blues = Sk4f{linear_from_curve[(src[0] >> 16) & 0xFF], 203 linear_from_curve[(src[3] >> 8) & 0xFF]};
205 linear_from_curve[(src[1] >> 16) & 0xFF], 204 blues = Sk4f{linear_from_curve[(src[0] >> 16) & 0xFF],
206 linear_from_curve[(src[2] >> 16) & 0xFF], 205 linear_from_curve[(src[1] >> 16) & 0xFF],
207 linear_from_curve[(src[3] >> 16) & 0xFF]}; 206 linear_from_curve[(src[2] >> 16) & 0xFF],
207 linear_from_curve[(src[3] >> 16) & 0xFF]};
208 src += 4;
209 len -= 4;
210 };
208 211
209 // Apply the transformation matrix to dst gamut. 212 Sk4f dstReds, dstGreens, dstBlues;
210 auto dstReds = rXgXbX[0]*reds + rYgYbY[0]*greens + rZgZbZ[0]*blues, 213 auto transform_4 = [&reds, &greens, &blues, &dstReds, &dstGreens, &dstBl ues, &rXgXbX,
211 dstGreens = rXgXbX[1]*reds + rYgYbY[1]*greens + rZgZbZ[1]*blues, 214 &rYgYbY, &rZgZbZ] {
212 dstBlues = rXgXbX[2]*reds + rYgYbY[2]*greens + rZgZbZ[2]*blues; 215 dstReds = rXgXbX[0]*reds + rYgYbY[0]*greens + rZgZbZ[0]*blues;
216 dstGreens = rXgXbX[1]*reds + rYgYbY[1]*greens + rZgZbZ[1]*blues;
217 dstBlues = rXgXbX[2]*reds + rYgYbY[2]*greens + rZgZbZ[2]*blues;
218 };
213 219
214 // Convert to dst gamma. 220 auto store_4 = [&dstReds, &dstGreens, &dstBlues, &dst] {
215 dstReds = linear_to_curve(dstReds); 221 dstReds = linear_to_curve(dstReds);
216 dstGreens = linear_to_curve(dstGreens); 222 dstGreens = linear_to_curve(dstGreens);
217 dstBlues = linear_to_curve(dstBlues); 223 dstBlues = linear_to_curve(dstBlues);
218 224
219 // Clamp floats to byte range. 225 dstReds = clamp_0_to_255(dstReds);
220 dstReds = clamp_0_to_255(dstReds); 226 dstGreens = clamp_0_to_255(dstGreens);
221 dstGreens = clamp_0_to_255(dstGreens); 227 dstBlues = clamp_0_to_255(dstBlues);
222 dstBlues = clamp_0_to_255(dstBlues);
223 228
224 // Convert to bytes and store to memory. 229 auto rgba = (Sk4i{(int)0xFF000000} )
225 auto rgba = (Sk4i{(int)0xFF000000} ) 230 | (SkNx_cast<int>(dstReds) )
226 | (SkNx_cast<int>(dstReds) ) 231 | (SkNx_cast<int>(dstGreens) << 8)
227 | (SkNx_cast<int>(dstGreens) << 8) 232 | (SkNx_cast<int>(dstBlues) << 16);
228 | (SkNx_cast<int>(dstBlues) << 16); 233 rgba.store(dst);
229 rgba.store(dst); 234 dst += 4;
235 };
230 236
231 dst += 4; 237 load_next_4();
232 src += 4; 238
233 len -= 4; 239 while (len >= 4) {
240 transform_4();
241 load_next_4();
242 store_4();
243 }
244
245 transform_4();
246 store_4();
234 } 247 }
235 248
236 while (len > 0) { 249 while (len > 0) {
237 // Splat r,g,b across a register each. 250 // Splat r,g,b across a register each.
238 auto r = Sk4f{linear_from_curve[(*src >> 0) & 0xFF]}, 251 auto r = Sk4f{linear_from_curve[(*src >> 0) & 0xFF]},
239 g = Sk4f{linear_from_curve[(*src >> 8) & 0xFF]}, 252 g = Sk4f{linear_from_curve[(*src >> 8) & 0xFF]},
240 b = Sk4f{linear_from_curve[(*src >> 16) & 0xFF]}; 253 b = Sk4f{linear_from_curve[(*src >> 16) & 0xFF]};
241 254
242 // Apply transformation matrix to dst gamut. 255 // Apply transformation matrix to dst gamut.
243 auto dstPixel = rXgXbX*r + rYgYbY*g + rZgZbZ*b; 256 auto dstPixel = rXgXbX*r + rYgYbY*g + rZgZbZ*b;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 289 }
277 290
278 static void color_xform_RGB1_2dot2_to_srgb(uint32_t* dst, const uint32_t* src, i nt len, 291 static void color_xform_RGB1_2dot2_to_srgb(uint32_t* dst, const uint32_t* src, i nt len,
279 const float matrix[16]) { 292 const float matrix[16]) {
280 color_xform_RGB1<linear_from_2dot2, linear_to_srgb>(dst, src, len, matrix); 293 color_xform_RGB1<linear_from_2dot2, linear_to_srgb>(dst, src, len, matrix);
281 } 294 }
282 295
283 } // namespace SK_OPTS_NS 296 } // namespace SK_OPTS_NS
284 297
285 #endif // SkColorXform_opts_DEFINED 298 #endif // SkColorXform_opts_DEFINED
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698