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

Side by Side Diff: src/core/SkXfermode.cpp

Issue 1714363002: SkNx: kth<...>() -> [...] (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: the rest Created 4 years, 10 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/SkScan_Hairline.cpp ('k') | src/core/SkXfermode4f.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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 #include "SkXfermode.h" 8 #include "SkXfermode.h"
9 #include "SkXfermode_proccoeff.h" 9 #include "SkXfermode_proccoeff.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 } else if (prod >= 255*255) { 43 } else if (prod >= 255*255) {
44 return 255; 44 return 255;
45 } else { 45 } else {
46 return SkDiv255Round(prod); 46 return SkDiv255Round(prod);
47 } 47 }
48 } 48 }
49 49
50 /////////////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////////////
51 #include "SkNx.h" 51 #include "SkNx.h"
52 52
53 static Sk4f alpha(const Sk4f& color) { return Sk4f(color.kth<3>()); } 53 static Sk4f alpha(const Sk4f& color) { return Sk4f(color[3]); }
54 static Sk4f inv_alpha(const Sk4f& color) { return Sk4f(1 - color.kth<3>()); } 54 static Sk4f inv_alpha(const Sk4f& color) { return Sk4f(1 - color[3]); }
55 static Sk4f pin_1(const Sk4f& value) { return Sk4f::Min(value, Sk4f(1)); } 55 static Sk4f pin_1(const Sk4f& value) { return Sk4f::Min(value, Sk4f(1)); }
56 56
57 static Sk4f color_alpha(const Sk4f& color, float newAlpha) { 57 static Sk4f color_alpha(const Sk4f& color, float newAlpha) {
58 return Sk4f(color.kth<0>(), color.kth<1>(), color.kth<2>(), newAlpha); 58 return Sk4f(color[0], color[1], color[2], newAlpha);
59 } 59 }
60 static Sk4f color_alpha(const Sk4f& color, const Sk4f& newAlpha) { 60 static Sk4f color_alpha(const Sk4f& color, const Sk4f& newAlpha) {
61 return color_alpha(color, newAlpha.kth<3>()); 61 return color_alpha(color, newAlpha[3]);
62 } 62 }
63 63
64 static Sk4f set_argb(float a, float r, float g, float b) { 64 static Sk4f set_argb(float a, float r, float g, float b) {
65 if (0 == SkPM4f::R) { 65 if (0 == SkPM4f::R) {
66 return Sk4f(r, g, b, a); 66 return Sk4f(r, g, b, a);
67 } else { 67 } else {
68 return Sk4f(b, g, r, a); 68 return Sk4f(b, g, r, a);
69 } 69 }
70 } 70 }
71 71
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 257
258 static inline void SetLum(float* r, float* g, float* b, float a, float l) { 258 static inline void SetLum(float* r, float* g, float* b, float a, float l) {
259 float d = l - Lum(*r, *g, *b); 259 float d = l - Lum(*r, *g, *b);
260 *r += d; 260 *r += d;
261 *g += d; 261 *g += d;
262 *b += d; 262 *b += d;
263 clipColor(r, g, b, a); 263 clipColor(r, g, b, a);
264 } 264 }
265 265
266 static Sk4f hue_4f(const Sk4f& s, const Sk4f& d) { 266 static Sk4f hue_4f(const Sk4f& s, const Sk4f& d) {
267 float sa = s.kth<SkPM4f::A>(); 267 float sa = s[SkPM4f::A];
268 float sr = s.kth<SkPM4f::R>(); 268 float sr = s[SkPM4f::R];
269 float sg = s.kth<SkPM4f::G>(); 269 float sg = s[SkPM4f::G];
270 float sb = s.kth<SkPM4f::B>(); 270 float sb = s[SkPM4f::B];
271 271
272 float da = d.kth<SkPM4f::A>(); 272 float da = d[SkPM4f::A];
273 float dr = d.kth<SkPM4f::R>(); 273 float dr = d[SkPM4f::R];
274 float dg = d.kth<SkPM4f::G>(); 274 float dg = d[SkPM4f::G];
275 float db = d.kth<SkPM4f::B>(); 275 float db = d[SkPM4f::B];
276 276
277 float Sr = sr; 277 float Sr = sr;
278 float Sg = sg; 278 float Sg = sg;
279 float Sb = sb; 279 float Sb = sb;
280 SetSat(&Sr, &Sg, &Sb, Sat(dr, dg, db) * sa); 280 SetSat(&Sr, &Sg, &Sb, Sat(dr, dg, db) * sa);
281 SetLum(&Sr, &Sg, &Sb, sa * da, Lum(dr, dg, db) * sa); 281 SetLum(&Sr, &Sg, &Sb, sa * da, Lum(dr, dg, db) * sa);
282 282
283 return color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Sr, Sg, Sb), 283 return color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Sr, Sg, Sb),
284 sa + da - sa * da); 284 sa + da - sa * da);
285 } 285 }
286 286
287 static Sk4f saturation_4f(const Sk4f& s, const Sk4f& d) { 287 static Sk4f saturation_4f(const Sk4f& s, const Sk4f& d) {
288 float sa = s.kth<SkPM4f::A>(); 288 float sa = s[SkPM4f::A];
289 float sr = s.kth<SkPM4f::R>(); 289 float sr = s[SkPM4f::R];
290 float sg = s.kth<SkPM4f::G>(); 290 float sg = s[SkPM4f::G];
291 float sb = s.kth<SkPM4f::B>(); 291 float sb = s[SkPM4f::B];
292 292
293 float da = d.kth<SkPM4f::A>(); 293 float da = d[SkPM4f::A];
294 float dr = d.kth<SkPM4f::R>(); 294 float dr = d[SkPM4f::R];
295 float dg = d.kth<SkPM4f::G>(); 295 float dg = d[SkPM4f::G];
296 float db = d.kth<SkPM4f::B>(); 296 float db = d[SkPM4f::B];
297 297
298 float Dr = dr; 298 float Dr = dr;
299 float Dg = dg; 299 float Dg = dg;
300 float Db = db; 300 float Db = db;
301 SetSat(&Dr, &Dg, &Db, Sat(sr, sg, sb) * da); 301 SetSat(&Dr, &Dg, &Db, Sat(sr, sg, sb) * da);
302 SetLum(&Dr, &Dg, &Db, sa * da, Lum(dr, dg, db) * sa); 302 SetLum(&Dr, &Dg, &Db, sa * da, Lum(dr, dg, db) * sa);
303 303
304 return color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Dr, Dg, Db), 304 return color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Dr, Dg, Db),
305 sa + da - sa * da); 305 sa + da - sa * da);
306 } 306 }
307 307
308 static Sk4f color_4f(const Sk4f& s, const Sk4f& d) { 308 static Sk4f color_4f(const Sk4f& s, const Sk4f& d) {
309 float sa = s.kth<SkPM4f::A>(); 309 float sa = s[SkPM4f::A];
310 float sr = s.kth<SkPM4f::R>(); 310 float sr = s[SkPM4f::R];
311 float sg = s.kth<SkPM4f::G>(); 311 float sg = s[SkPM4f::G];
312 float sb = s.kth<SkPM4f::B>(); 312 float sb = s[SkPM4f::B];
313 313
314 float da = d.kth<SkPM4f::A>(); 314 float da = d[SkPM4f::A];
315 float dr = d.kth<SkPM4f::R>(); 315 float dr = d[SkPM4f::R];
316 float dg = d.kth<SkPM4f::G>(); 316 float dg = d[SkPM4f::G];
317 float db = d.kth<SkPM4f::B>(); 317 float db = d[SkPM4f::B];
318 318
319 float Sr = sr; 319 float Sr = sr;
320 float Sg = sg; 320 float Sg = sg;
321 float Sb = sb; 321 float Sb = sb;
322 SetLum(&Sr, &Sg, &Sb, sa * da, Lum(dr, dg, db) * sa); 322 SetLum(&Sr, &Sg, &Sb, sa * da, Lum(dr, dg, db) * sa);
323 323
324 Sk4f res = color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Sr, Sg, Sb), 324 Sk4f res = color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Sr, Sg, Sb),
325 sa + da - sa * da); 325 sa + da - sa * da);
326 // Can return tiny negative values ... 326 // Can return tiny negative values ...
327 return Sk4f::Max(res, Sk4f(0)); 327 return Sk4f::Max(res, Sk4f(0));
328 } 328 }
329 329
330 static Sk4f luminosity_4f(const Sk4f& s, const Sk4f& d) { 330 static Sk4f luminosity_4f(const Sk4f& s, const Sk4f& d) {
331 float sa = s.kth<SkPM4f::A>(); 331 float sa = s[SkPM4f::A];
332 float sr = s.kth<SkPM4f::R>(); 332 float sr = s[SkPM4f::R];
333 float sg = s.kth<SkPM4f::G>(); 333 float sg = s[SkPM4f::G];
334 float sb = s.kth<SkPM4f::B>(); 334 float sb = s[SkPM4f::B];
335 335
336 float da = d.kth<SkPM4f::A>(); 336 float da = d[SkPM4f::A];
337 float dr = d.kth<SkPM4f::R>(); 337 float dr = d[SkPM4f::R];
338 float dg = d.kth<SkPM4f::G>(); 338 float dg = d[SkPM4f::G];
339 float db = d.kth<SkPM4f::B>(); 339 float db = d[SkPM4f::B];
340 340
341 float Dr = dr; 341 float Dr = dr;
342 float Dg = dg; 342 float Dg = dg;
343 float Db = db; 343 float Db = db;
344 SetLum(&Dr, &Dg, &Db, sa * da, Lum(sr, sg, sb) * da); 344 SetLum(&Dr, &Dg, &Db, sa * da, Lum(sr, sg, sb) * da);
345 345
346 Sk4f res = color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Dr, Dg, Db), 346 Sk4f res = color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Dr, Dg, Db),
347 sa + da - sa * da); 347 sa + da - sa * da);
348 // Can return tiny negative values ... 348 // Can return tiny negative values ...
349 return Sk4f::Max(res, Sk4f(0)); 349 return Sk4f::Max(res, Sk4f(0));
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 if (!xfer) { 1400 if (!xfer) {
1401 return SkXfermode::kOpaque_SrcColorOpacity == opacityType; 1401 return SkXfermode::kOpaque_SrcColorOpacity == opacityType;
1402 } 1402 }
1403 1403
1404 return xfer->isOpaque(opacityType); 1404 return xfer->isOpaque(opacityType);
1405 } 1405 }
1406 1406
1407 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) 1407 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode)
1408 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) 1408 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode)
1409 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1409 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/core/SkScan_Hairline.cpp ('k') | src/core/SkXfermode4f.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698