OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBlitRow.h" | 8 #include "SkBlitRow.h" |
9 #include "SkBlitMask.h" | 9 #include "SkBlitMask.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 SkBlitRow::ColorProc proc = PlatformColorProc(); | 135 SkBlitRow::ColorProc proc = PlatformColorProc(); |
136 if (NULL == proc) { | 136 if (NULL == proc) { |
137 proc = Color32; | 137 proc = Color32; |
138 } | 138 } |
139 SkASSERT(proc); | 139 SkASSERT(proc); |
140 return proc; | 140 return proc; |
141 } | 141 } |
142 | 142 |
143 #define SK_SUPPORT_LEGACY_COLOR32_MATHx | 143 #define SK_SUPPORT_LEGACY_COLOR32_MATHx |
144 | 144 |
145 // Color32 and its SIMD specializations use the blend_256_round_alt algorithm | 145 // Color32 and its SIMD specializations use the blend_perfect algorithm from tes
ts/BlendTest.cpp. |
146 // from tests/BlendTest.cpp. It's not quite perfect, but it's never wrong in th
e | 146 // An acceptable alternative is blend_256_round_alt, which is faster but not qui
te perfect. |
147 // interesting edge cases, and it's quite a bit faster than blend_perfect. | |
148 // | |
149 // blend_256_round_alt is our currently blessed algorithm. Please use it or an
analogous one. | |
150 void SkBlitRow::Color32(SkPMColor* SK_RESTRICT dst, | 147 void SkBlitRow::Color32(SkPMColor* SK_RESTRICT dst, |
151 const SkPMColor* SK_RESTRICT src, | 148 const SkPMColor* SK_RESTRICT src, |
152 int count, SkPMColor color) { | 149 int count, SkPMColor color) { |
153 switch (SkGetPackedA32(color)) { | 150 switch (SkGetPackedA32(color)) { |
154 case 0: memmove(dst, src, count * sizeof(SkPMColor)); return; | 151 case 0: memmove(dst, src, count * sizeof(SkPMColor)); return; |
155 case 255: sk_memset32(dst, color, count); return; | 152 case 255: sk_memset32(dst, color, count); return; |
156 } | 153 } |
157 | 154 |
158 unsigned invA = 255 - SkGetPackedA32(color); | 155 unsigned invA = 255 - SkGetPackedA32(color); |
159 #ifdef SK_SUPPORT_LEGACY_COLOR32_MATH // blend_256_plus1_trunc, busted | |
160 unsigned round = 0; | |
161 #else // blend_256_round_alt, good | |
162 invA += invA >> 7; | |
163 unsigned round = (128 << 16) + (128 << 0); | |
164 #endif | |
165 | |
166 while (count --> 0) { | 156 while (count --> 0) { |
167 // Our math is 16-bit, so we can do a little bit of SIMD in 32-bit regis
ters. | 157 // Our math is 16-bit, so we can do a little bit of SIMD in 32-bit regis
ters. |
168 const uint32_t mask = 0x00FF00FF; | 158 const uint32_t mask = 0x00FF00FF; |
169 uint32_t rb = (((*src >> 0) & mask) * invA + round) >> 8, // _r_b | 159 uint32_t rb = (((*src >> 0) & mask) * invA), // r_b_ |
170 ag = (((*src >> 8) & mask) * invA + round) >> 0; // a_g_ | 160 ag = (((*src >> 8) & mask) * invA); // a_g_ |
171 *dst = color + ((rb & mask) | (ag & ~mask)); | 161 #ifndef SK_SUPPORT_LEGACY_COLOR32_MATH |
| 162 uint32_t round = (128 << 16) + (128 << 0); |
| 163 rb += round; |
| 164 ag += round; |
| 165 rb += (rb & ~mask) >> 8; |
| 166 ag += (ag & ~mask) >> 8; |
| 167 #endif |
| 168 *dst = color + (((rb>>8) & mask) | ((ag>>0) & ~mask)); |
172 src++; | 169 src++; |
173 dst++; | 170 dst++; |
174 } | 171 } |
175 } | 172 } |
176 | 173 |
OLD | NEW |