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

Side by Side Diff: src/effects/SkArithmeticMode.cpp

Issue 15917010: Fix alpha computation in SkArithmeticMode. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Add testcase to arithmode GM Created 7 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 | Annotate | Revision Log
« no previous file with comments | « gm/arithmode.cpp ('k') | 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 2013 Google Inc. 2 * Copyright 2013 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 #include "SkArithmeticMode.h" 8 #include "SkArithmeticMode.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkString.h" 10 #include "SkString.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 SkScalar k4 = fK[3] * 255; 66 SkScalar k4 = fK[3] * 255;
67 67
68 for (int i = 0; i < count; ++i) { 68 for (int i = 0; i < count; ++i) {
69 if ((NULL == aaCoverage) || aaCoverage[i]) { 69 if ((NULL == aaCoverage) || aaCoverage[i]) {
70 SkPMColor sc = src[i]; 70 SkPMColor sc = src[i];
71 SkPMColor dc = dst[i]; 71 SkPMColor dc = dst[i];
72 int sa = SkGetPackedA32(sc); 72 int sa = SkGetPackedA32(sc);
73 int da = SkGetPackedA32(dc); 73 int da = SkGetPackedA32(dc);
74 74
75 int srcNeedsUnpremul = needsUnpremul(sa); 75 int srcNeedsUnpremul = needsUnpremul(sa);
76 int dstNeedsUnpremul = needsUnpremul(sa); 76 int dstNeedsUnpremul = needsUnpremul(da);
77 77
78 int a, r, g, b; 78 int a, r, g, b;
79 79
80 if (!srcNeedsUnpremul && !dstNeedsUnpremul) { 80 if (!srcNeedsUnpremul && !dstNeedsUnpremul) {
81 a = arith(k1, k2, k3, k4, sa, sa); 81 a = arith(k1, k2, k3, k4, sa, da);
82 r = arith(k1, k2, k3, k4, SkGetPackedR32(sc), SkGetPackedR32(dc) ); 82 r = arith(k1, k2, k3, k4, SkGetPackedR32(sc), SkGetPackedR32(dc) );
83 g = arith(k1, k2, k3, k4, SkGetPackedG32(sc), SkGetPackedG32(dc) ); 83 g = arith(k1, k2, k3, k4, SkGetPackedG32(sc), SkGetPackedG32(dc) );
84 b = arith(k1, k2, k3, k4, SkGetPackedB32(sc), SkGetPackedB32(dc) ); 84 b = arith(k1, k2, k3, k4, SkGetPackedB32(sc), SkGetPackedB32(dc) );
85 } else { 85 } else {
86 int sr = SkGetPackedR32(sc); 86 int sr = SkGetPackedR32(sc);
87 int sg = SkGetPackedG32(sc); 87 int sg = SkGetPackedG32(sc);
88 int sb = SkGetPackedB32(sc); 88 int sb = SkGetPackedB32(sc);
89 if (srcNeedsUnpremul) { 89 if (srcNeedsUnpremul) {
90 SkUnPreMultiply::Scale scale = SkUnPreMultiply::GetScale(sa) ; 90 SkUnPreMultiply::Scale scale = SkUnPreMultiply::GetScale(sa) ;
91 sr = SkUnPreMultiply::ApplyScale(scale, sr); 91 sr = SkUnPreMultiply::ApplyScale(scale, sr);
92 sg = SkUnPreMultiply::ApplyScale(scale, sg); 92 sg = SkUnPreMultiply::ApplyScale(scale, sg);
93 sb = SkUnPreMultiply::ApplyScale(scale, sb); 93 sb = SkUnPreMultiply::ApplyScale(scale, sb);
94 } 94 }
95 95
96 int dr = SkGetPackedR32(dc); 96 int dr = SkGetPackedR32(dc);
97 int dg = SkGetPackedG32(dc); 97 int dg = SkGetPackedG32(dc);
98 int db = SkGetPackedB32(dc); 98 int db = SkGetPackedB32(dc);
99 if (dstNeedsUnpremul) { 99 if (dstNeedsUnpremul) {
100 SkUnPreMultiply::Scale scale = SkUnPreMultiply::GetScale(da) ; 100 SkUnPreMultiply::Scale scale = SkUnPreMultiply::GetScale(da) ;
101 dr = SkUnPreMultiply::ApplyScale(scale, dr); 101 dr = SkUnPreMultiply::ApplyScale(scale, dr);
102 dg = SkUnPreMultiply::ApplyScale(scale, dg); 102 dg = SkUnPreMultiply::ApplyScale(scale, dg);
103 db = SkUnPreMultiply::ApplyScale(scale, db); 103 db = SkUnPreMultiply::ApplyScale(scale, db);
104 } 104 }
105 105
106 a = arith(k1, k2, k3, k4, sa, sa); 106 a = arith(k1, k2, k3, k4, sa, da);
107 r = arith(k1, k2, k3, k4, sr, dr); 107 r = arith(k1, k2, k3, k4, sr, dr);
108 g = arith(k1, k2, k3, k4, sg, dg); 108 g = arith(k1, k2, k3, k4, sg, dg);
109 b = arith(k1, k2, k3, k4, sb, db); 109 b = arith(k1, k2, k3, k4, sb, db);
110 } 110 }
111 111
112 // apply antialias coverage if necessary 112 // apply antialias coverage if necessary
113 if (aaCoverage && 0xFF != aaCoverage[i]) { 113 if (aaCoverage && 0xFF != aaCoverage[i]) {
114 int scale = aaCoverage[i] + (aaCoverage[i] >> 7); 114 int scale = aaCoverage[i] + (aaCoverage[i] >> 7);
115 a = blend(a, SkGetPackedA32(sc), scale); 115 a = blend(a, SkGetPackedA32(sc), scale);
116 r = blend(r, SkGetPackedR32(sc), scale); 116 r = blend(r, SkGetPackedR32(sc), scale);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return SkNEW_ARGS(SkArithmeticMode_dst, (i3, i4)); 184 return SkNEW_ARGS(SkArithmeticMode_dst, (i3, i4));
185 } 185 }
186 if (0 == i3) { 186 if (0 == i3) {
187 return SkNEW_ARGS(SkArithmeticMode_src, (i2, i4)); 187 return SkNEW_ARGS(SkArithmeticMode_src, (i2, i4));
188 } 188 }
189 return SkNEW_ARGS(SkArithmeticMode_linear, (i2, i3, i4)); 189 return SkNEW_ARGS(SkArithmeticMode_linear, (i2, i3, i4));
190 #endif 190 #endif
191 } 191 }
192 return SkNEW_ARGS(SkArithmeticMode_scalar, (k1, k2, k3, k4)); 192 return SkNEW_ARGS(SkArithmeticMode_scalar, (k1, k2, k3, k4));
193 } 193 }
OLDNEW
« no previous file with comments | « gm/arithmode.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698