Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/codec/SkMaskSwizzler.cpp

Issue 1907593004: Support the non-native (RGBA/BGRA) swizzle (Closed) Base URL: https://skia.googlesource.com/skia.git@tryagain
Patch Set: Multiple bug fixes Created 4 years, 8 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
« no previous file with comments | « src/codec/SkJpegCodec.cpp ('k') | src/codec/SkPngCodec.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkMaskSwizzler.h" 10 #include "SkMaskSwizzler.h"
11 11
12 static void swizzle_mask16_to_n32_opaque( 12 static void swizzle_mask16_to_rgba_opaque(
13 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 13 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
14 uint32_t startX, uint32_t sampleX) { 14 uint32_t startX, uint32_t sampleX) {
15 15
16 // Use the masks to decode to the destination 16 // Use the masks to decode to the destination
17 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; 17 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
18 SkPMColor* dstPtr = (SkPMColor*) dstRow; 18 SkPMColor* dstPtr = (SkPMColor*) dstRow;
19 for (int i = 0; i < width; i++) { 19 for (int i = 0; i < width; i++) {
20 uint16_t p = srcPtr[0]; 20 uint16_t p = srcPtr[0];
21 uint8_t red = masks->getRed(p); 21 uint8_t red = masks->getRed(p);
22 uint8_t green = masks->getGreen(p); 22 uint8_t green = masks->getGreen(p);
23 uint8_t blue = masks->getBlue(p); 23 uint8_t blue = masks->getBlue(p);
24 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); 24 dstPtr[i] = SkPackARGB_as_RGBA(0xFF, red, green, blue);
25 srcPtr += sampleX; 25 srcPtr += sampleX;
26 } 26 }
27 } 27 }
28 28
29 static void swizzle_mask16_to_n32_unpremul( 29 static void swizzle_mask16_to_bgra_opaque(
30 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 30 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
31 uint32_t startX, uint32_t sampleX) { 31 uint32_t startX, uint32_t sampleX) {
32 32
33 // Use the masks to decode to the destination
34 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
35 SkPMColor* dstPtr = (SkPMColor*) dstRow;
36 for (int i = 0; i < width; i++) {
37 uint16_t p = srcPtr[0];
38 uint8_t red = masks->getRed(p);
39 uint8_t green = masks->getGreen(p);
40 uint8_t blue = masks->getBlue(p);
41 dstPtr[i] = SkPackARGB_as_BGRA(0xFF, red, green, blue);
42 srcPtr += sampleX;
43 }
44 }
45
46 static void swizzle_mask16_to_rgba_unpremul(
47 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
48 uint32_t startX, uint32_t sampleX) {
49
33 // Use the masks to decode to the destination 50 // Use the masks to decode to the destination
34 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; 51 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
35 SkPMColor* dstPtr = (SkPMColor*) dstRow; 52 SkPMColor* dstPtr = (SkPMColor*) dstRow;
36 for (int i = 0; i < width; i++) { 53 for (int i = 0; i < width; i++) {
37 uint16_t p = srcPtr[0]; 54 uint16_t p = srcPtr[0];
38 uint8_t red = masks->getRed(p); 55 uint8_t red = masks->getRed(p);
39 uint8_t green = masks->getGreen(p); 56 uint8_t green = masks->getGreen(p);
40 uint8_t blue = masks->getBlue(p); 57 uint8_t blue = masks->getBlue(p);
41 uint8_t alpha = masks->getAlpha(p); 58 uint8_t alpha = masks->getAlpha(p);
42 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); 59 dstPtr[i] = SkPackARGB_as_RGBA(alpha, red, green, blue);
43 srcPtr += sampleX; 60 srcPtr += sampleX;
44 } 61 }
45 } 62 }
46 63
47 static void swizzle_mask16_to_n32_premul( 64 static void swizzle_mask16_to_bgra_unpremul(
48 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 65 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
49 uint32_t startX, uint32_t sampleX) { 66 uint32_t startX, uint32_t sampleX) {
50 67
51 // Use the masks to decode to the destination 68 // Use the masks to decode to the destination
52 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; 69 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
53 SkPMColor* dstPtr = (SkPMColor*) dstRow; 70 SkPMColor* dstPtr = (SkPMColor*) dstRow;
54 for (int i = 0; i < width; i++) { 71 for (int i = 0; i < width; i++) {
55 uint16_t p = srcPtr[0]; 72 uint16_t p = srcPtr[0];
56 uint8_t red = masks->getRed(p); 73 uint8_t red = masks->getRed(p);
57 uint8_t green = masks->getGreen(p); 74 uint8_t green = masks->getGreen(p);
58 uint8_t blue = masks->getBlue(p); 75 uint8_t blue = masks->getBlue(p);
59 uint8_t alpha = masks->getAlpha(p); 76 uint8_t alpha = masks->getAlpha(p);
60 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); 77 dstPtr[i] = SkPackARGB_as_BGRA(alpha, red, green, blue);
61 srcPtr += sampleX; 78 srcPtr += sampleX;
62 } 79 }
63 } 80 }
81
82 static void swizzle_mask16_to_rgba_premul(
83 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
84 uint32_t startX, uint32_t sampleX) {
85
86 // Use the masks to decode to the destination
87 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
88 SkPMColor* dstPtr = (SkPMColor*) dstRow;
89 for (int i = 0; i < width; i++) {
90 uint16_t p = srcPtr[0];
91 uint8_t red = masks->getRed(p);
92 uint8_t green = masks->getGreen(p);
93 uint8_t blue = masks->getBlue(p);
94 uint8_t alpha = masks->getAlpha(p);
95 dstPtr[i] = premultiply_argb_as_rgba(alpha, red, green, blue);
96 srcPtr += sampleX;
97 }
98 }
99
100 static void swizzle_mask16_to_bgra_premul(
101 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
102 uint32_t startX, uint32_t sampleX) {
103
104 // Use the masks to decode to the destination
105 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
106 SkPMColor* dstPtr = (SkPMColor*) dstRow;
107 for (int i = 0; i < width; i++) {
108 uint16_t p = srcPtr[0];
109 uint8_t red = masks->getRed(p);
110 uint8_t green = masks->getGreen(p);
111 uint8_t blue = masks->getBlue(p);
112 uint8_t alpha = masks->getAlpha(p);
113 dstPtr[i] = premultiply_argb_as_bgra(alpha, red, green, blue);
114 srcPtr += sampleX;
115 }
116 }
64 117
65 // TODO (msarett): We have promoted a two byte per pixel image to 8888, only to 118 // TODO (msarett): We have promoted a two byte per pixel image to 8888, only to
66 // convert it back to 565. Instead, we should swizzle to 565 directly. 119 // convert it back to 565. Instead, we should swizzle to 565 directly.
67 static void swizzle_mask16_to_565( 120 static void swizzle_mask16_to_565(
68 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 121 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
69 uint32_t startX, uint32_t sampleX) { 122 uint32_t startX, uint32_t sampleX) {
70 123
71 // Use the masks to decode to the destination 124 // Use the masks to decode to the destination
72 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX; 125 uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
73 uint16_t* dstPtr = (uint16_t*) dstRow; 126 uint16_t* dstPtr = (uint16_t*) dstRow;
74 for (int i = 0; i < width; i++) { 127 for (int i = 0; i < width; i++) {
75 uint16_t p = srcPtr[0]; 128 uint16_t p = srcPtr[0];
76 uint8_t red = masks->getRed(p); 129 uint8_t red = masks->getRed(p);
77 uint8_t green = masks->getGreen(p); 130 uint8_t green = masks->getGreen(p);
78 uint8_t blue = masks->getBlue(p); 131 uint8_t blue = masks->getBlue(p);
79 dstPtr[i] = SkPack888ToRGB16(red, green, blue); 132 dstPtr[i] = SkPack888ToRGB16(red, green, blue);
80 srcPtr += sampleX; 133 srcPtr += sampleX;
81 } 134 }
82 } 135 }
83 136
84 static void swizzle_mask24_to_n32_opaque( 137 static void swizzle_mask24_to_rgba_opaque(
85 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 138 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
86 uint32_t startX, uint32_t sampleX) { 139 uint32_t startX, uint32_t sampleX) {
87 140
141 // Use the masks to decode to the destination
142 srcRow += 3 * startX;
143 SkPMColor* dstPtr = (SkPMColor*) dstRow;
144 for (int i = 0; i < width; i++) {
145 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
146 uint8_t red = masks->getRed(p);
147 uint8_t green = masks->getGreen(p);
148 uint8_t blue = masks->getBlue(p);
149 dstPtr[i] = SkPackARGB_as_RGBA(0xFF, red, green, blue);
150 srcRow += 3 * sampleX;
151 }
152 }
153
154 static void swizzle_mask24_to_bgra_opaque(
155 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
156 uint32_t startX, uint32_t sampleX) {
157
158 // Use the masks to decode to the destination
159 srcRow += 3 * startX;
160 SkPMColor* dstPtr = (SkPMColor*) dstRow;
161 for (int i = 0; i < width; i++) {
162 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
163 uint8_t red = masks->getRed(p);
164 uint8_t green = masks->getGreen(p);
165 uint8_t blue = masks->getBlue(p);
166 dstPtr[i] = SkPackARGB_as_BGRA(0xFF, red, green, blue);
167 srcRow += 3 * sampleX;
168 }
169 }
170
171 static void swizzle_mask24_to_rgba_unpremul(
172 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
173 uint32_t startX, uint32_t sampleX) {
174
88 // Use the masks to decode to the destination 175 // Use the masks to decode to the destination
89 srcRow += 3 * startX; 176 srcRow += 3 * startX;
90 SkPMColor* dstPtr = (SkPMColor*) dstRow; 177 SkPMColor* dstPtr = (SkPMColor*) dstRow;
91 for (int i = 0; i < width; i++) { 178 for (int i = 0; i < width; i++) {
92 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; 179 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
93 uint8_t red = masks->getRed(p); 180 uint8_t red = masks->getRed(p);
94 uint8_t green = masks->getGreen(p); 181 uint8_t green = masks->getGreen(p);
95 uint8_t blue = masks->getBlue(p); 182 uint8_t blue = masks->getBlue(p);
96 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); 183 uint8_t alpha = masks->getAlpha(p);
184 dstPtr[i] = SkPackARGB_as_RGBA(alpha, red, green, blue);
97 srcRow += 3 * sampleX; 185 srcRow += 3 * sampleX;
98 } 186 }
99 } 187 }
100 188
101 static void swizzle_mask24_to_n32_unpremul( 189 static void swizzle_mask24_to_bgra_unpremul(
102 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 190 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
103 uint32_t startX, uint32_t sampleX) { 191 uint32_t startX, uint32_t sampleX) {
104 192
105 // Use the masks to decode to the destination 193 // Use the masks to decode to the destination
106 srcRow += 3 * startX; 194 srcRow += 3 * startX;
107 SkPMColor* dstPtr = (SkPMColor*) dstRow; 195 SkPMColor* dstPtr = (SkPMColor*) dstRow;
108 for (int i = 0; i < width; i++) { 196 for (int i = 0; i < width; i++) {
109 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; 197 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
110 uint8_t red = masks->getRed(p); 198 uint8_t red = masks->getRed(p);
111 uint8_t green = masks->getGreen(p); 199 uint8_t green = masks->getGreen(p);
112 uint8_t blue = masks->getBlue(p); 200 uint8_t blue = masks->getBlue(p);
113 uint8_t alpha = masks->getAlpha(p); 201 uint8_t alpha = masks->getAlpha(p);
114 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); 202 dstPtr[i] = SkPackARGB_as_BGRA(alpha, red, green, blue);
115 srcRow += 3 * sampleX; 203 srcRow += 3 * sampleX;
116 } 204 }
117 } 205 }
118 206
119 static void swizzle_mask24_to_n32_premul( 207 static void swizzle_mask24_to_rgba_premul(
120 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 208 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
121 uint32_t startX, uint32_t sampleX) { 209 uint32_t startX, uint32_t sampleX) {
122 210
123 // Use the masks to decode to the destination 211 // Use the masks to decode to the destination
124 srcRow += 3 * startX; 212 srcRow += 3 * startX;
125 SkPMColor* dstPtr = (SkPMColor*) dstRow; 213 SkPMColor* dstPtr = (SkPMColor*) dstRow;
126 for (int i = 0; i < width; i++) { 214 for (int i = 0; i < width; i++) {
127 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; 215 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
128 uint8_t red = masks->getRed(p); 216 uint8_t red = masks->getRed(p);
129 uint8_t green = masks->getGreen(p); 217 uint8_t green = masks->getGreen(p);
130 uint8_t blue = masks->getBlue(p); 218 uint8_t blue = masks->getBlue(p);
131 uint8_t alpha = masks->getAlpha(p); 219 uint8_t alpha = masks->getAlpha(p);
132 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); 220 dstPtr[i] = premultiply_argb_as_rgba(alpha, red, green, blue);
133 srcRow += 3 * sampleX; 221 srcRow += 3 * sampleX;
134 } 222 }
135 } 223 }
224
225 static void swizzle_mask24_to_bgra_premul(
226 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
227 uint32_t startX, uint32_t sampleX) {
228
229 // Use the masks to decode to the destination
230 srcRow += 3 * startX;
231 SkPMColor* dstPtr = (SkPMColor*) dstRow;
232 for (int i = 0; i < width; i++) {
233 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
234 uint8_t red = masks->getRed(p);
235 uint8_t green = masks->getGreen(p);
236 uint8_t blue = masks->getBlue(p);
237 uint8_t alpha = masks->getAlpha(p);
238 dstPtr[i] = premultiply_argb_as_bgra(alpha, red, green, blue);
239 srcRow += 3 * sampleX;
240 }
241 }
136 242
137 static void swizzle_mask24_to_565( 243 static void swizzle_mask24_to_565(
138 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 244 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
139 uint32_t startX, uint32_t sampleX) { 245 uint32_t startX, uint32_t sampleX) {
140 246
141 // Use the masks to decode to the destination 247 // Use the masks to decode to the destination
142 srcRow += 3 * startX; 248 srcRow += 3 * startX;
143 uint16_t* dstPtr = (uint16_t*) dstRow; 249 uint16_t* dstPtr = (uint16_t*) dstRow;
144 for (int i = 0; i < width; i++) { 250 for (int i = 0; i < width; i++) {
145 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16; 251 uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
146 uint8_t red = masks->getRed(p); 252 uint8_t red = masks->getRed(p);
147 uint8_t green = masks->getGreen(p); 253 uint8_t green = masks->getGreen(p);
148 uint8_t blue = masks->getBlue(p); 254 uint8_t blue = masks->getBlue(p);
149 dstPtr[i] = SkPack888ToRGB16(red, green, blue); 255 dstPtr[i] = SkPack888ToRGB16(red, green, blue);
150 srcRow += 3 * sampleX; 256 srcRow += 3 * sampleX;
151 } 257 }
152 } 258 }
153 259
154 static void swizzle_mask32_to_n32_opaque( 260 static void swizzle_mask32_to_rgba_opaque(
155 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 261 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
156 uint32_t startX, uint32_t sampleX) { 262 uint32_t startX, uint32_t sampleX) {
157 263
264 // Use the masks to decode to the destination
265 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
266 SkPMColor* dstPtr = (SkPMColor*) dstRow;
267 for (int i = 0; i < width; i++) {
268 uint32_t p = srcPtr[0];
269 uint8_t red = masks->getRed(p);
270 uint8_t green = masks->getGreen(p);
271 uint8_t blue = masks->getBlue(p);
272 dstPtr[i] = SkPackARGB_as_RGBA(0xFF, red, green, blue);
273 srcPtr += sampleX;
274 }
275 }
276
277 static void swizzle_mask32_to_bgra_opaque(
278 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
279 uint32_t startX, uint32_t sampleX) {
280
281 // Use the masks to decode to the destination
282 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
283 SkPMColor* dstPtr = (SkPMColor*) dstRow;
284 for (int i = 0; i < width; i++) {
285 uint32_t p = srcPtr[0];
286 uint8_t red = masks->getRed(p);
287 uint8_t green = masks->getGreen(p);
288 uint8_t blue = masks->getBlue(p);
289 dstPtr[i] = SkPackARGB_as_BGRA(0xFF, red, green, blue);
290 srcPtr += sampleX;
291 }
292 }
293
294 static void swizzle_mask32_to_rgba_unpremul(
295 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
296 uint32_t startX, uint32_t sampleX) {
297
298 // Use the masks to decode to the destination
299 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
300 SkPMColor* dstPtr = (SkPMColor*) dstRow;
301 for (int i = 0; i < width; i++) {
302 uint32_t p = srcPtr[0];
303 uint8_t red = masks->getRed(p);
304 uint8_t green = masks->getGreen(p);
305 uint8_t blue = masks->getBlue(p);
306 uint8_t alpha = masks->getAlpha(p);
307 dstPtr[i] = SkPackARGB_as_RGBA(alpha, red, green, blue);
308 srcPtr += sampleX;
309 }
310 }
311
312 static void swizzle_mask32_to_bgra_unpremul(
313 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
314 uint32_t startX, uint32_t sampleX) {
315
158 // Use the masks to decode to the destination 316 // Use the masks to decode to the destination
159 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; 317 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
160 SkPMColor* dstPtr = (SkPMColor*) dstRow; 318 SkPMColor* dstPtr = (SkPMColor*) dstRow;
161 for (int i = 0; i < width; i++) { 319 for (int i = 0; i < width; i++) {
162 uint32_t p = srcPtr[0]; 320 uint32_t p = srcPtr[0];
163 uint8_t red = masks->getRed(p); 321 uint8_t red = masks->getRed(p);
164 uint8_t green = masks->getGreen(p); 322 uint8_t green = masks->getGreen(p);
165 uint8_t blue = masks->getBlue(p); 323 uint8_t blue = masks->getBlue(p);
166 dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); 324 uint8_t alpha = masks->getAlpha(p);
325 dstPtr[i] = SkPackARGB_as_BGRA(alpha, red, green, blue);
167 srcPtr += sampleX; 326 srcPtr += sampleX;
168 } 327 }
169 } 328 }
170 329
171 static void swizzle_mask32_to_n32_unpremul( 330 static void swizzle_mask32_to_rgba_premul(
172 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 331 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
173 uint32_t startX, uint32_t sampleX) { 332 uint32_t startX, uint32_t sampleX) {
174 333
175 // Use the masks to decode to the destination 334 // Use the masks to decode to the destination
176 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; 335 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
177 SkPMColor* dstPtr = (SkPMColor*) dstRow; 336 SkPMColor* dstPtr = (SkPMColor*) dstRow;
178 for (int i = 0; i < width; i++) { 337 for (int i = 0; i < width; i++) {
179 uint32_t p = srcPtr[0]; 338 uint32_t p = srcPtr[0];
180 uint8_t red = masks->getRed(p); 339 uint8_t red = masks->getRed(p);
181 uint8_t green = masks->getGreen(p); 340 uint8_t green = masks->getGreen(p);
182 uint8_t blue = masks->getBlue(p); 341 uint8_t blue = masks->getBlue(p);
183 uint8_t alpha = masks->getAlpha(p); 342 uint8_t alpha = masks->getAlpha(p);
184 dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue); 343 dstPtr[i] = premultiply_argb_as_rgba(alpha, red, green, blue);
185 srcPtr += sampleX; 344 srcPtr += sampleX;
186 } 345 }
187 } 346 }
188 347
189 static void swizzle_mask32_to_n32_premul( 348 static void swizzle_mask32_to_bgra_premul(
190 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 349 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
191 uint32_t startX, uint32_t sampleX) { 350 uint32_t startX, uint32_t sampleX) {
192 351
193 // Use the masks to decode to the destination 352 // Use the masks to decode to the destination
194 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; 353 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
195 SkPMColor* dstPtr = (SkPMColor*) dstRow; 354 SkPMColor* dstPtr = (SkPMColor*) dstRow;
196 for (int i = 0; i < width; i++) { 355 for (int i = 0; i < width; i++) {
197 uint32_t p = srcPtr[0]; 356 uint32_t p = srcPtr[0];
198 uint8_t red = masks->getRed(p); 357 uint8_t red = masks->getRed(p);
199 uint8_t green = masks->getGreen(p); 358 uint8_t green = masks->getGreen(p);
200 uint8_t blue = masks->getBlue(p); 359 uint8_t blue = masks->getBlue(p);
201 uint8_t alpha = masks->getAlpha(p); 360 uint8_t alpha = masks->getAlpha(p);
202 dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue); 361 dstPtr[i] = premultiply_argb_as_bgra(alpha, red, green, blue);
203 srcPtr += sampleX; 362 srcPtr += sampleX;
204 } 363 }
205 } 364 }
206 365
207 static void swizzle_mask32_to_565( 366 static void swizzle_mask32_to_565(
208 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks, 367 void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
209 uint32_t startX, uint32_t sampleX) { 368 uint32_t startX, uint32_t sampleX) {
210 // Use the masks to decode to the destination 369 // Use the masks to decode to the destination
211 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX; 370 uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
212 uint16_t* dstPtr = (uint16_t*) dstRow; 371 uint16_t* dstPtr = (uint16_t*) dstRow;
(...skipping 14 matching lines...) Expand all
227 */ 386 */
228 SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo, 387 SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo,
229 const SkImageInfo& srcInfo, SkMasks* masks, uint32_t bitsPerPixel, 388 const SkImageInfo& srcInfo, SkMasks* masks, uint32_t bitsPerPixel,
230 const SkCodec::Options& options) { 389 const SkCodec::Options& options) {
231 390
232 // Choose the appropriate row procedure 391 // Choose the appropriate row procedure
233 RowProc proc = nullptr; 392 RowProc proc = nullptr;
234 switch (bitsPerPixel) { 393 switch (bitsPerPixel) {
235 case 16: 394 case 16:
236 switch (dstInfo.colorType()) { 395 switch (dstInfo.colorType()) {
237 case kN32_SkColorType: 396 case kRGBA_8888_SkColorType:
238 if (kOpaque_SkAlphaType == srcInfo.alphaType()) { 397 if (kOpaque_SkAlphaType == srcInfo.alphaType()) {
239 proc = &swizzle_mask16_to_n32_opaque; 398 proc = &swizzle_mask16_to_rgba_opaque;
240 } else { 399 } else {
241 switch (dstInfo.alphaType()) { 400 switch (dstInfo.alphaType()) {
242 case kUnpremul_SkAlphaType: 401 case kUnpremul_SkAlphaType:
243 proc = &swizzle_mask16_to_n32_unpremul; 402 proc = &swizzle_mask16_to_rgba_unpremul;
244 break; 403 break;
245 case kPremul_SkAlphaType: 404 case kPremul_SkAlphaType:
246 proc = &swizzle_mask16_to_n32_premul; 405 proc = &swizzle_mask16_to_rgba_premul;
247 break; 406 break;
248 default: 407 default:
249 break; 408 break;
409 }
410 }
411 break;
412 case kBGRA_8888_SkColorType:
413 if (kOpaque_SkAlphaType == srcInfo.alphaType()) {
414 proc = &swizzle_mask16_to_bgra_opaque;
415 } else {
416 switch (dstInfo.alphaType()) {
417 case kUnpremul_SkAlphaType:
418 proc = &swizzle_mask16_to_bgra_unpremul;
419 break;
420 case kPremul_SkAlphaType:
421 proc = &swizzle_mask16_to_bgra_premul;
422 break;
423 default:
424 break;
250 } 425 }
251 } 426 }
252 break; 427 break;
253 case kRGB_565_SkColorType: 428 case kRGB_565_SkColorType:
254 proc = &swizzle_mask16_to_565; 429 proc = &swizzle_mask16_to_565;
255 break; 430 break;
256 default: 431 default:
257 break; 432 break;
258 } 433 }
259 break; 434 break;
260 case 24: 435 case 24:
261 switch (dstInfo.colorType()) { 436 switch (dstInfo.colorType()) {
262 case kN32_SkColorType: 437 case kRGBA_8888_SkColorType:
263 if (kOpaque_SkAlphaType == srcInfo.alphaType()) { 438 if (kOpaque_SkAlphaType == srcInfo.alphaType()) {
264 proc = &swizzle_mask24_to_n32_opaque; 439 proc = &swizzle_mask24_to_rgba_opaque;
265 } else { 440 } else {
266 switch (dstInfo.alphaType()) { 441 switch (dstInfo.alphaType()) {
267 case kUnpremul_SkAlphaType: 442 case kUnpremul_SkAlphaType:
268 proc = &swizzle_mask24_to_n32_unpremul; 443 proc = &swizzle_mask24_to_rgba_unpremul;
269 break; 444 break;
270 case kPremul_SkAlphaType: 445 case kPremul_SkAlphaType:
271 proc = &swizzle_mask24_to_n32_premul; 446 proc = &swizzle_mask24_to_rgba_premul;
272 break; 447 break;
273 default: 448 default:
274 break; 449 break;
450 }
451 }
452 break;
453 case kBGRA_8888_SkColorType:
454 if (kOpaque_SkAlphaType == srcInfo.alphaType()) {
455 proc = &swizzle_mask24_to_bgra_opaque;
456 } else {
457 switch (dstInfo.alphaType()) {
458 case kUnpremul_SkAlphaType:
459 proc = &swizzle_mask24_to_bgra_unpremul;
460 break;
461 case kPremul_SkAlphaType:
462 proc = &swizzle_mask24_to_bgra_premul;
463 break;
464 default:
465 break;
275 } 466 }
276 } 467 }
277 break; 468 break;
278 case kRGB_565_SkColorType: 469 case kRGB_565_SkColorType:
279 proc = &swizzle_mask24_to_565; 470 proc = &swizzle_mask24_to_565;
280 break; 471 break;
281 default: 472 default:
282 break; 473 break;
283 } 474 }
284 break; 475 break;
285 case 32: 476 case 32:
286 switch (dstInfo.colorType()) { 477 switch (dstInfo.colorType()) {
287 case kN32_SkColorType: 478 case kRGBA_8888_SkColorType:
288 if (kOpaque_SkAlphaType == srcInfo.alphaType()) { 479 if (kOpaque_SkAlphaType == srcInfo.alphaType()) {
289 proc = &swizzle_mask32_to_n32_opaque; 480 proc = &swizzle_mask32_to_rgba_opaque;
290 } else { 481 } else {
291 switch (dstInfo.alphaType()) { 482 switch (dstInfo.alphaType()) {
292 case kUnpremul_SkAlphaType: 483 case kUnpremul_SkAlphaType:
293 proc = &swizzle_mask32_to_n32_unpremul; 484 proc = &swizzle_mask32_to_rgba_unpremul;
294 break; 485 break;
295 case kPremul_SkAlphaType: 486 case kPremul_SkAlphaType:
296 proc = &swizzle_mask32_to_n32_premul; 487 proc = &swizzle_mask32_to_rgba_premul;
297 break; 488 break;
298 default: 489 default:
299 break; 490 break;
491 }
492 }
493 break;
494 case kBGRA_8888_SkColorType:
495 if (kOpaque_SkAlphaType == srcInfo.alphaType()) {
496 proc = &swizzle_mask32_to_bgra_opaque;
497 } else {
498 switch (dstInfo.alphaType()) {
499 case kUnpremul_SkAlphaType:
500 proc = &swizzle_mask32_to_bgra_unpremul;
501 break;
502 case kPremul_SkAlphaType:
503 proc = &swizzle_mask32_to_bgra_premul;
504 break;
505 default:
506 break;
300 } 507 }
301 } 508 }
302 break; 509 break;
303 case kRGB_565_SkColorType: 510 case kRGB_565_SkColorType:
304 proc = &swizzle_mask32_to_565; 511 proc = &swizzle_mask32_to_565;
305 break; 512 break;
306 default: 513 default:
307 break; 514 break;
308 } 515 }
309 break; 516 break;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 559
353 /* 560 /*
354 * 561 *
355 * Swizzle the specified row 562 * Swizzle the specified row
356 * 563 *
357 */ 564 */
358 void SkMaskSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { 565 void SkMaskSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) {
359 SkASSERT(nullptr != dst && nullptr != src); 566 SkASSERT(nullptr != dst && nullptr != src);
360 fRowProc(dst, src, fDstWidth, fMasks, fX0, fSampleX); 567 fRowProc(dst, src, fDstWidth, fMasks, fX0, fSampleX);
361 } 568 }
OLDNEW
« no previous file with comments | « src/codec/SkJpegCodec.cpp ('k') | src/codec/SkPngCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698