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 114173002: Preventing division by 0 (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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 | Annotate | Revision Log
« 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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkXfermode.h" 10 #include "SkXfermode.h"
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 setSaturationComponents(g, b, r, s); 461 setSaturationComponents(g, b, r, s);
462 } else { 462 } else {
463 setSaturationComponents(b, g, r, s); 463 setSaturationComponents(b, g, r, s);
464 } 464 }
465 } 465 }
466 466
467 static inline void clipColor(int* r, int* g, int* b, int a) { 467 static inline void clipColor(int* r, int* g, int* b, int a) {
468 int L = Lum(*r, *g, *b); 468 int L = Lum(*r, *g, *b);
469 int n = minimum(*r, *g, *b); 469 int n = minimum(*r, *g, *b);
470 int x = maximum(*r, *g, *b); 470 int x = maximum(*r, *g, *b);
471 if(n < 0) { 471 int denom;
472 *r = L + SkMulDiv(*r - L, L, L - n); 472 if ((n < 0) && (denom = L - n)) { // Compute denom and make sure it's non ze ro
473 *g = L + SkMulDiv(*g - L, L, L - n); 473 *r = L + SkMulDiv(*r - L, L, denom);
474 *b = L + SkMulDiv(*b - L, L, L - n); 474 *g = L + SkMulDiv(*g - L, L, denom);
475 *b = L + SkMulDiv(*b - L, L, denom);
475 } 476 }
476 477
477 if (x > a) { 478 if ((x > a) && (denom = x - L)) { // Compute denom and make sure it's non ze ro
478 *r = L + SkMulDiv(*r - L, a - L, x - L); 479 int numer = a - L;
479 *g = L + SkMulDiv(*g - L, a - L, x - L); 480 *r = L + SkMulDiv(*r - L, numer, denom);
480 *b = L + SkMulDiv(*b - L, a - L, x - L); 481 *g = L + SkMulDiv(*g - L, numer, denom);
482 *b = L + SkMulDiv(*b - L, numer, denom);
481 } 483 }
482 } 484 }
483 485
484 static inline void SetLum(int* r, int* g, int* b, int a, int l) { 486 static inline void SetLum(int* r, int* g, int* b, int a, int l) {
485 int d = l - Lum(*r, *g, *b); 487 int d = l - Lum(*r, *g, *b);
486 *r += d; 488 *r += d;
487 *g += d; 489 *g += d;
488 *b += d; 490 *b += d;
489 491
490 clipColor(r, g, b, a); 492 clipColor(r, g, b, a);
(...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) 1970 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode)
1969 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) 1971 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode)
1970 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkClearXfermode) 1972 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkClearXfermode)
1971 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSrcXfermode) 1973 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSrcXfermode)
1972 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstInXfermode) 1974 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstInXfermode)
1973 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstOutXfermode) 1975 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstOutXfermode)
1974 #if !SK_ARM_NEON_IS_NONE 1976 #if !SK_ARM_NEON_IS_NONE
1975 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkNEONProcCoeffXfermode) 1977 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkNEONProcCoeffXfermode)
1976 #endif 1978 #endif
1977 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1979 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