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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 SkBlitRow::Proc32 SkBlitRow::ColorProcFactory() { | 134 SkBlitRow::Proc32 SkBlitRow::ColorProcFactory() { |
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 |
| 144 |
| 145 // Color32 and its SIMD specializations use the blend_256_round_alt algorithm |
| 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. |
143 void SkBlitRow::Color32(SkPMColor* SK_RESTRICT dst, | 150 void SkBlitRow::Color32(SkPMColor* SK_RESTRICT dst, |
144 const SkPMColor* SK_RESTRICT src, | 151 const SkPMColor* SK_RESTRICT src, |
145 int count, SkPMColor color) { | 152 int count, SkPMColor color) { |
146 if (count > 0) { | 153 switch (SkGetPackedA32(color)) { |
147 if (0 == color) { | 154 case 0: memmove(dst, src, count * sizeof(SkPMColor)); return; |
148 if (src != dst) { | 155 case 255: sk_memset32(dst, color, count); return; |
149 memcpy(dst, src, count * sizeof(SkPMColor)); | 156 } |
150 } | 157 |
151 return; | 158 unsigned invA = 255 - SkGetPackedA32(color); |
152 } | 159 #ifdef SK_SUPPORT_LEGACY_COLOR32_MATH // blend_256_plus1_trunc, busted |
153 unsigned colorA = SkGetPackedA32(color); | 160 unsigned round = 0; |
154 if (255 == colorA) { | 161 #else // blend_256_round_alt, good |
155 sk_memset32(dst, color, count); | 162 invA += invA >> 7; |
156 } else { | 163 unsigned round = (128 << 16) + (128 << 0); |
157 unsigned scale = 256 - SkAlpha255To256(colorA); | 164 #endif |
158 do { | 165 |
159 *dst = color + SkAlphaMulQ(*src, scale); | 166 while (count --> 0) { |
160 src += 1; | 167 // Our math is 16-bit, so we can do a little bit of SIMD in 32-bit regis
ters. |
161 dst += 1; | 168 const uint32_t mask = 0x00FF00FF; |
162 } while (--count); | 169 uint32_t rb = (((*src >> 0) & mask) * invA + round) >> 8, // _r_b |
163 } | 170 ag = (((*src >> 8) & mask) * invA + round) >> 0; // a_g_ |
| 171 *dst = color + ((rb & mask) | (ag & ~mask)); |
| 172 src++; |
| 173 dst++; |
164 } | 174 } |
165 } | 175 } |
166 | 176 |
OLD | NEW |