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/core/SkXfermode.cpp

Issue 1710453003: some modes need clamping due to numerical imprecision (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « 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 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 float da = d.kth<SkPM4f::A>(); 313 float da = d.kth<SkPM4f::A>();
314 float dr = d.kth<SkPM4f::R>(); 314 float dr = d.kth<SkPM4f::R>();
315 float dg = d.kth<SkPM4f::G>(); 315 float dg = d.kth<SkPM4f::G>();
316 float db = d.kth<SkPM4f::B>(); 316 float db = d.kth<SkPM4f::B>();
317 317
318 float Sr = sr; 318 float Sr = sr;
319 float Sg = sg; 319 float Sg = sg;
320 float Sb = sb; 320 float Sb = sb;
321 SetLum(&Sr, &Sg, &Sb, sa * da, Lum(dr, dg, db) * sa); 321 SetLum(&Sr, &Sg, &Sb, sa * da, Lum(dr, dg, db) * sa);
322 322
323 return color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Sr, Sg, Sb), 323 Sk4f res = color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Sr, Sg, Sb),
324 sa + da - sa * da); 324 sa + da - sa * da);
325 // Can return tiny negative values ...
326 return Sk4f::Max(res, Sk4f(0));
325 } 327 }
326 328
327 static Sk4f luminosity_4f(const Sk4f& s, const Sk4f& d) { 329 static Sk4f luminosity_4f(const Sk4f& s, const Sk4f& d) {
328 float sa = s.kth<SkPM4f::A>(); 330 float sa = s.kth<SkPM4f::A>();
329 float sr = s.kth<SkPM4f::R>(); 331 float sr = s.kth<SkPM4f::R>();
330 float sg = s.kth<SkPM4f::G>(); 332 float sg = s.kth<SkPM4f::G>();
331 float sb = s.kth<SkPM4f::B>(); 333 float sb = s.kth<SkPM4f::B>();
332 334
333 float da = d.kth<SkPM4f::A>(); 335 float da = d.kth<SkPM4f::A>();
334 float dr = d.kth<SkPM4f::R>(); 336 float dr = d.kth<SkPM4f::R>();
335 float dg = d.kth<SkPM4f::G>(); 337 float dg = d.kth<SkPM4f::G>();
336 float db = d.kth<SkPM4f::B>(); 338 float db = d.kth<SkPM4f::B>();
337 339
338 float Dr = dr; 340 float Dr = dr;
339 float Dg = dg; 341 float Dg = dg;
340 float Db = db; 342 float Db = db;
341 SetLum(&Dr, &Dg, &Db, sa * da, Lum(sr, sg, sb) * da); 343 SetLum(&Dr, &Dg, &Db, sa * da, Lum(sr, sg, sb) * da);
342 344
343 return color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Dr, Dg, Db), 345 Sk4f res = color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Dr, Dg, Db),
344 sa + da - sa * da); 346 sa + da - sa * da);
347 // Can return tiny negative values ...
348 return Sk4f::Max(res, Sk4f(0));
345 } 349 }
346 350
347 /////////////////////////////////////////////////////////////////////////////// 351 ///////////////////////////////////////////////////////////////////////////////
348 352
349 // kClear_Mode, //!< [0, 0] 353 // kClear_Mode, //!< [0, 0]
350 static SkPMColor clear_modeproc(SkPMColor src, SkPMColor dst) { 354 static SkPMColor clear_modeproc(SkPMColor src, SkPMColor dst) {
351 return 0; 355 return 0;
352 } 356 }
353 357
354 // kSrc_Mode, //!< [Sa, Sc] 358 // kSrc_Mode, //!< [Sa, Sc]
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 static SkPM4f as_pm4f(const Sk4f& x) { 918 static SkPM4f as_pm4f(const Sk4f& x) {
915 SkPM4f pm4; 919 SkPM4f pm4;
916 x.store(pm4.fVec); 920 x.store(pm4.fVec);
917 return pm4; 921 return pm4;
918 } 922 }
919 923
920 static Sk4f as_4f(const SkPM4f& pm4) { 924 static Sk4f as_4f(const SkPM4f& pm4) {
921 return Sk4f::Load(pm4.fVec); 925 return Sk4f::Load(pm4.fVec);
922 } 926 }
923 927
924 template <Sk4f (blend)(const Sk4f&, const Sk4f&)> SkPM4f proc_4f(const SkPM4f& s , const SkPM4f& d) { 928 static void assert_unit(const SkPM4f& r) {
925 SkPM4f r = as_pm4f(blend(as_4f(s), as_4f(d)));
926 #ifdef SK_DEBUG 929 #ifdef SK_DEBUG
927 const float min = 0; 930 const float min = 0;
928 const float max = 1; 931 const float max = 1;
929 for (int i = 0; i < 4; ++i) { 932 for (int i = 0; i < 4; ++i) {
930 SkASSERT(r.fVec[i] >= min && r.fVec[i] <= max); 933 SkASSERT(r.fVec[i] >= min && r.fVec[i] <= max);
931 } 934 }
932 #endif 935 #endif
936 }
937
938 template <Sk4f (blend)(const Sk4f&, const Sk4f&)> SkPM4f proc_4f(const SkPM4f& s , const SkPM4f& d) {
939 assert_unit(s);
940 assert_unit(d);
941 SkPM4f r = as_pm4f(blend(as_4f(s), as_4f(d)));
942 assert_unit(r);
933 return r; 943 return r;
934 } 944 }
935 945
936 const ProcCoeff gProcCoeffs[] = { 946 const ProcCoeff gProcCoeffs[] = {
937 { clear_modeproc, proc_4f<clear_4f>, SkXfermode::kZero_Coeff, SkXfermode::kZero_Coeff }, 947 { clear_modeproc, proc_4f<clear_4f>, SkXfermode::kZero_Coeff, SkXfermode::kZero_Coeff },
938 { src_modeproc, proc_4f<src_4f>, SkXfermode::kOne_Coeff, SkXfermode::kZero_Coeff }, 948 { src_modeproc, proc_4f<src_4f>, SkXfermode::kOne_Coeff, SkXfermode::kZero_Coeff },
939 { dst_modeproc, proc_4f<dst_4f>, SkXfermode::kZero_Coeff, SkXfermode::kOne_Coeff }, 949 { dst_modeproc, proc_4f<dst_4f>, SkXfermode::kZero_Coeff, SkXfermode::kOne_Coeff },
940 { srcover_modeproc, proc_4f<srcover_4f>, SkXfermode::kOne_Coeff, SkXfermode::kISA_Coeff }, 950 { srcover_modeproc, proc_4f<srcover_4f>, SkXfermode::kOne_Coeff, SkXfermode::kISA_Coeff },
941 { dstover_modeproc, proc_4f<dstover_4f>, SkXfermode::kIDA_Coeff, SkXfermode::kOne_Coeff }, 951 { dstover_modeproc, proc_4f<dstover_4f>, SkXfermode::kIDA_Coeff, SkXfermode::kOne_Coeff },
942 { srcin_modeproc, proc_4f<srcin_4f>, SkXfermode::kDA_Coeff, SkXfermode::kZero_Coeff }, 952 { srcin_modeproc, proc_4f<srcin_4f>, SkXfermode::kDA_Coeff, SkXfermode::kZero_Coeff },
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 if (!xfer) { 1399 if (!xfer) {
1390 return SkXfermode::kOpaque_SrcColorOpacity == opacityType; 1400 return SkXfermode::kOpaque_SrcColorOpacity == opacityType;
1391 } 1401 }
1392 1402
1393 return xfer->isOpaque(opacityType); 1403 return xfer->isOpaque(opacityType);
1394 } 1404 }
1395 1405
1396 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) 1406 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode)
1397 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) 1407 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode)
1398 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1408 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
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