OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 #ifndef SkSwizzler_opts_DEFINED | 8 #ifndef SkSwizzler_opts_DEFINED |
9 #define SkSwizzler_opts_DEFINED | 9 #define SkSwizzler_opts_DEFINED |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 r = (r*a+127)/255; | 40 r = (r*a+127)/255; |
41 g = (g*a+127)/255; | 41 g = (g*a+127)/255; |
42 b = (b*a+127)/255; | 42 b = (b*a+127)/255; |
43 dst[i] = (uint32_t)a << 24 | 43 dst[i] = (uint32_t)a << 24 |
44 | (uint32_t)b << 16 | 44 | (uint32_t)b << 16 |
45 | (uint32_t)g << 8 | 45 | (uint32_t)g << 8 |
46 | (uint32_t)r << 0; | 46 | (uint32_t)r << 0; |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
| 50 static void swaprb_xxxa_portable(uint32_t dst[], const uint32_t src[], int count
) { |
| 51 for (int i = 0; i < count; i++) { |
| 52 uint8_t a = src[i] >> 24, |
| 53 r = src[i] >> 16, |
| 54 g = src[i] >> 8, |
| 55 b = src[i] >> 0; |
| 56 dst[i] = (uint32_t)a << 24 |
| 57 | (uint32_t)b << 16 |
| 58 | (uint32_t)g << 8 |
| 59 | (uint32_t)r << 0; |
| 60 } |
| 61 } |
| 62 |
50 #if defined(SK_ARM_HAS_NEON) | 63 #if defined(SK_ARM_HAS_NEON) |
51 | 64 |
52 // Rounded divide by 255, (x + 127) / 255 | 65 // Rounded divide by 255, (x + 127) / 255 |
53 static uint8x8_t div255_round(uint16x8_t x) { | 66 static uint8x8_t div255_round(uint16x8_t x) { |
54 // result = (x + 127) / 255 | 67 // result = (x + 127) / 255 |
55 // result = (x + 127) / 256 + error1 | 68 // result = (x + 127) / 256 + error1 |
56 // | 69 // |
57 // error1 = (x + 127) / (255 * 256) | 70 // error1 = (x + 127) / (255 * 256) |
58 // error1 = (x + 127) / (256 * 256) + error2 | 71 // error1 = (x + 127) / (256 * 256) + error2 |
59 // | 72 // |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 129 } |
117 | 130 |
118 static void premul_xxxa(uint32_t dst[], const uint32_t src[], int count) { | 131 static void premul_xxxa(uint32_t dst[], const uint32_t src[], int count) { |
119 premul_xxxa_should_swaprb<false>(dst, src, count); | 132 premul_xxxa_should_swaprb<false>(dst, src, count); |
120 } | 133 } |
121 | 134 |
122 static void premul_swaprb_xxxa(uint32_t dst[], const uint32_t src[], int count)
{ | 135 static void premul_swaprb_xxxa(uint32_t dst[], const uint32_t src[], int count)
{ |
123 premul_xxxa_should_swaprb<true>(dst, src, count); | 136 premul_xxxa_should_swaprb<true>(dst, src, count); |
124 } | 137 } |
125 | 138 |
| 139 static void swaprb_xxxa(uint32_t dst[], const uint32_t src[], int count) { |
| 140 while (count >= 16) { |
| 141 // Load 16 pixels. |
| 142 uint8x16x4_t bgra = vld4q_u8((const uint8_t*) src); |
| 143 |
| 144 // Swap r and b. |
| 145 SkTSwap(bgra.val[0], bgra.val[2]); |
| 146 |
| 147 // Store 16 pixels. |
| 148 vst4q_u8((uint8_t*) dst, bgra); |
| 149 src += 16; |
| 150 dst += 16; |
| 151 count -= 16; |
| 152 } |
| 153 |
| 154 if (count >= 8) { |
| 155 // Load 8 pixels. |
| 156 uint8x8x4_t bgra = vld4_u8((const uint8_t*) src); |
| 157 |
| 158 // Swap r and b. |
| 159 SkTSwap(bgra.val[0], bgra.val[2]); |
| 160 |
| 161 // Store 8 pixels. |
| 162 vst4_u8((uint8_t*) dst, bgra); |
| 163 src += 8; |
| 164 dst += 8; |
| 165 count -= 8; |
| 166 } |
| 167 |
| 168 swaprb_xxxa_portable(dst, src, count); |
| 169 } |
| 170 |
126 #else | 171 #else |
127 | 172 |
128 static void premul_xxxa(uint32_t dst[], const uint32_t src[], int count) { | 173 static void premul_xxxa(uint32_t dst[], const uint32_t src[], int count) { |
129 premul_xxxa_portable(dst, src, count); | 174 premul_xxxa_portable(dst, src, count); |
130 } | 175 } |
131 | 176 |
132 static void premul_swaprb_xxxa(uint32_t dst[], const uint32_t src[], int count)
{ | 177 static void premul_swaprb_xxxa(uint32_t dst[], const uint32_t src[], int count)
{ |
133 premul_swaprb_xxxa_portable(dst, src, count); | 178 premul_swaprb_xxxa_portable(dst, src, count); |
134 } | 179 } |
135 | 180 |
| 181 static void swaprb_xxxa(uint32_t dst[], const uint32_t src[], int count) { |
| 182 swaprb_xxxa_portable(dst, src, count); |
| 183 } |
| 184 |
136 #endif | 185 #endif |
137 | 186 |
138 static void swaprb_xxxa(uint32_t dst[], const uint32_t src[], int count) { | |
139 for (int i = 0; i < count; i++) { | |
140 uint8_t a = src[i] >> 24, | |
141 r = src[i] >> 16, | |
142 g = src[i] >> 8, | |
143 b = src[i] >> 0; | |
144 dst[i] = (uint32_t)a << 24 | |
145 | (uint32_t)b << 16 | |
146 | (uint32_t)g << 8 | |
147 | (uint32_t)r << 0; | |
148 } | |
149 } | |
150 | |
151 } | 187 } |
152 | 188 |
153 #endif // SkSwizzler_opts_DEFINED | 189 #endif // SkSwizzler_opts_DEFINED |
OLD | NEW |