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/effects/SkAvoidXfermode.cpp

Issue 17335008: remove dst/rendertarget support for kARGB_4444_Config (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: 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
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 "SkAvoidXfermode.h" 8 #include "SkAvoidXfermode.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkFlattenableBuffers.h" 10 #include "SkFlattenableBuffers.h"
(...skipping 30 matching lines...) Expand all
41 SkASSERT(g <= SK_G16_MASK); 41 SkASSERT(g <= SK_G16_MASK);
42 SkASSERT(b <= SK_B16_MASK); 42 SkASSERT(b <= SK_B16_MASK);
43 43
44 unsigned dr = SkAbs32(SkGetPackedR16(c) - r); 44 unsigned dr = SkAbs32(SkGetPackedR16(c) - r);
45 unsigned dg = SkAbs32(SkGetPackedG16(c) - g) >> (SK_G16_BITS - SK_R16_BITS); 45 unsigned dg = SkAbs32(SkGetPackedG16(c) - g) >> (SK_G16_BITS - SK_R16_BITS);
46 unsigned db = SkAbs32(SkGetPackedB16(c) - b); 46 unsigned db = SkAbs32(SkGetPackedB16(c) - b);
47 47
48 return SkMax32(dr, SkMax32(dg, db)); 48 return SkMax32(dr, SkMax32(dg, db));
49 } 49 }
50 50
51 // returns 0..15
52 static unsigned color_dist4444(uint16_t c, unsigned r, unsigned g, unsigned b) {
53 SkASSERT(r <= 0xF);
54 SkASSERT(g <= 0xF);
55 SkASSERT(b <= 0xF);
56
57 unsigned dr = SkAbs32(SkGetPackedR4444(c) - r);
58 unsigned dg = SkAbs32(SkGetPackedG4444(c) - g);
59 unsigned db = SkAbs32(SkGetPackedB4444(c) - b);
60
61 return SkMax32(dr, SkMax32(dg, db));
62 }
63
64 // returns 0..255 51 // returns 0..255
65 static unsigned color_dist32(SkPMColor c, U8CPU r, U8CPU g, U8CPU b) { 52 static unsigned color_dist32(SkPMColor c, U8CPU r, U8CPU g, U8CPU b) {
66 SkASSERT(r <= 0xFF); 53 SkASSERT(r <= 0xFF);
67 SkASSERT(g <= 0xFF); 54 SkASSERT(g <= 0xFF);
68 SkASSERT(b <= 0xFF); 55 SkASSERT(b <= 0xFF);
69 56
70 unsigned dr = SkAbs32(SkGetPackedR32(c) - r); 57 unsigned dr = SkAbs32(SkGetPackedR32(c) - r);
71 unsigned dg = SkAbs32(SkGetPackedG32(c) - g); 58 unsigned dg = SkAbs32(SkGetPackedG32(c) - g);
72 unsigned db = SkAbs32(SkGetPackedB32(c) - b); 59 unsigned db = SkAbs32(SkGetPackedB32(c) - b);
73 60
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 d = SkAlphaMul(d, Accurate255To256(*aa++)); 154 d = SkAlphaMul(d, Accurate255To256(*aa++));
168 if (0 == d) { 155 if (0 == d) {
169 continue; 156 continue;
170 } 157 }
171 } 158 }
172 dst[i] = SkBlend3216(src[i], dst[i], d); 159 dst[i] = SkBlend3216(src[i], dst[i], d);
173 } 160 }
174 } 161 }
175 } 162 }
176 163
177 void SkAvoidXfermode::xfer4444(uint16_t dst[], const SkPMColor src[], int count,
178 const SkAlpha aa[]) const {
179 unsigned opR = SkColorGetR(fOpColor) >> 4;
180 unsigned opG = SkColorGetG(fOpColor) >> 4;
181 unsigned opB = SkColorGetB(fOpColor) >> 4;
182 uint32_t mul = fDistMul;
183 uint32_t sub = (fDistMul - (1 << 14)) << 4;
184
185 int MAX, mask;
186
187 if (kTargetColor_Mode == fMode) {
188 mask = -1;
189 MAX = 15;
190 } else {
191 mask = 0;
192 MAX = 0;
193 }
194
195 for (int i = 0; i < count; i++) {
196 int d = color_dist4444(dst[i], opR, opG, opB);
197 // now reverse d if we need to
198 d = MAX + (d ^ mask) - mask;
199 SkASSERT((unsigned)d <= 15);
200 // convert from 0..15 to 0..16
201 d += d >> 3;
202 d = scale_dist_14(d, mul, sub);
203 SkASSERT(d <= 16);
204
205 if (d > 0) {
206 if (NULL != aa) {
207 d = SkAlphaMul(d, Accurate255To256(*aa++));
208 if (0 == d) {
209 continue;
210 }
211 }
212 dst[i] = SkBlend4444(SkPixel32ToPixel4444(src[i]), dst[i], d);
213 }
214 }
215 }
216
217 void SkAvoidXfermode::xferA8(SkAlpha dst[], const SkPMColor src[], int count, 164 void SkAvoidXfermode::xferA8(SkAlpha dst[], const SkPMColor src[], int count,
218 const SkAlpha aa[]) const { 165 const SkAlpha aa[]) const {
219 // override in subclass 166 // override in subclass
220 } 167 }
221 168
222 #ifdef SK_DEVELOPER 169 #ifdef SK_DEVELOPER
223 void SkAvoidXfermode::toString(SkString* str) const { 170 void SkAvoidXfermode::toString(SkString* str) const {
224 str->append("SkAvoidXfermode: opColor: "); 171 str->append("SkAvoidXfermode: opColor: ");
225 str->appendHex(fOpColor); 172 str->appendHex(fOpColor);
226 str->appendf("distMul: %d ", fDistMul); 173 str->appendf("distMul: %d ", fDistMul);
227 174
228 static const char* gModeStrings[] = { "Avoid", "Target" }; 175 static const char* gModeStrings[] = { "Avoid", "Target" };
229 176
230 str->appendf("mode: %s", gModeStrings[fMode]); 177 str->appendf("mode: %s", gModeStrings[fMode]);
231 } 178 }
232 #endif 179 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698