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_perfect algorithm from tes
ts/BlendTest.cpp. | 145 // Color32 and its SIMD specializations use the blend_256_round_alt algorithm |
146 // An acceptable alternative is blend_256_round_alt, which is faster but not qui
te perfect. | 146 // from tests/BlendTest.cpp. It's not quite perfect, but it's never wrong in th
e |
| 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. |
147 void SkBlitRow::Color32(SkPMColor* SK_RESTRICT dst, | 150 void SkBlitRow::Color32(SkPMColor* SK_RESTRICT dst, |
148 const SkPMColor* SK_RESTRICT src, | 151 const SkPMColor* SK_RESTRICT src, |
149 int count, SkPMColor color) { | 152 int count, SkPMColor color) { |
150 switch (SkGetPackedA32(color)) { | 153 switch (SkGetPackedA32(color)) { |
151 case 0: memmove(dst, src, count * sizeof(SkPMColor)); return; | 154 case 0: memmove(dst, src, count * sizeof(SkPMColor)); return; |
152 case 255: sk_memset32(dst, color, count); return; | 155 case 255: sk_memset32(dst, color, count); return; |
153 } | 156 } |
154 | 157 |
155 unsigned invA = 255 - SkGetPackedA32(color); | 158 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 |
156 while (count --> 0) { | 166 while (count --> 0) { |
157 // Our math is 16-bit, so we can do a little bit of SIMD in 32-bit regis
ters. | 167 // Our math is 16-bit, so we can do a little bit of SIMD in 32-bit regis
ters. |
158 const uint32_t mask = 0x00FF00FF; | 168 const uint32_t mask = 0x00FF00FF; |
159 uint32_t rb = (((*src >> 0) & mask) * invA), // r_b_ | 169 uint32_t rb = (((*src >> 0) & mask) * invA + round) >> 8, // _r_b |
160 ag = (((*src >> 8) & mask) * invA); // a_g_ | 170 ag = (((*src >> 8) & mask) * invA + round) >> 0; // a_g_ |
161 #ifndef SK_SUPPORT_LEGACY_COLOR32_MATH | 171 *dst = color + ((rb & mask) | (ag & ~mask)); |
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)); | |
169 src++; | 172 src++; |
170 dst++; | 173 dst++; |
171 } | 174 } |
172 } | 175 } |
173 | 176 |
OLD | NEW |