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

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

Issue 1294593002: Revert of SkScaledCodec class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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/SkSwizzler.h ('k') | no next file » | 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 "SkScaledCodec.h"
11 #include "SkSwizzler.h" 10 #include "SkSwizzler.h"
12 #include "SkTemplates.h" 11 #include "SkTemplates.h"
13 #include "SkUtils.h" 12 #include "SkUtils.h"
14 13
15 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, 14 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha,
16 uint8_t maxAlpha) { 15 uint8_t maxAlpha) {
17 // In the transparent case, this returns 0x0000 16 // In the transparent case, this returns 0x0000
18 // In the opaque case, this returns 0xFFFF 17 // In the opaque case, this returns 0xFFFF
19 // If the row is neither transparent nor opaque, returns something else 18 // If the row is neither transparent nor opaque, returns something else
20 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; 19 return (((uint16_t) maxAlpha) << 8) | zeroAlpha;
21 } 20 }
22 21
23 // samples the row. Does not do anything else but sampling
24 static SkSwizzler::ResultAlpha sample565(void* SK_RESTRICT dstRow, const uint8_t * SK_RESTRICT src,
25 int width, int deltaSrc, int offset, const SkPMColor ctable[]){
26
27 src += offset;
28 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
29 for (int x = 0; x < width; x++) {
30 dst[x] = src[1] << 8 | src[0];
31 src += deltaSrc;
32 }
33 // 565 is always opaque
34 return SkSwizzler::kOpaque_ResultAlpha;
35 }
36
37 // kBit 22 // kBit
38 // These routines exclusively choose between white and black 23 // These routines exclusively choose between white and black
39 24
40 #define GRAYSCALE_BLACK 0 25 #define GRAYSCALE_BLACK 0
41 #define GRAYSCALE_WHITE 0xFF 26 #define GRAYSCALE_WHITE 0xFF
42 27
43
44 // same as swizzle_bit_to_index and swizzle_bit_to_n32 except for value assigned to dst[x]
45 static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale( 28 static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale(
46 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 29 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
47 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { 30 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) {
48
49 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 31 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
50 32
51 // increment src by byte offset and bitIndex by bit offset 33 // Determine how many full bytes are in the row
52 src += offset / 8; 34 int bytesInRow = width >> 3;
53 int bitIndex = offset % 8; 35 int i;
54 uint8_t currByte = *src; 36 for (i = 0; i < bytesInRow; i++) {
55 for (int x = 0; x < dstWidth; x++) { 37 U8CPU currByte = src[i];
56 dst[x] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_ BLACK; 38 for (int j = 0; j < 8; j++) {
57 int bitOffset = bitIndex + deltaSrc; 39 dst[j] = ((currByte >> (7 - j)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_B LACK;
58 bitIndex = bitOffset % 8; 40 }
59 currByte = *(src += bitOffset / 8); 41 dst += 8;
60 } 42 }
61 43
44 // Finish the remaining bits
45 width &= 7;
46 if (width > 0) {
47 U8CPU currByte = src[i];
48 for (int j = 0; j < width; j++) {
49 dst[j] = ((currByte >> 7) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK;
50 currByte <<= 1;
51 }
52 }
62 return SkSwizzler::kOpaque_ResultAlpha; 53 return SkSwizzler::kOpaque_ResultAlpha;
63 } 54 }
64 55
65 #undef GRAYSCALE_BLACK 56 #undef GRAYSCALE_BLACK
66 #undef GRAYSCALE_WHITE 57 #undef GRAYSCALE_WHITE
67 58
68 // same as swizzle_bit_to_grayscale and swizzle_bit_to_n32 except for value assi gned to dst[x]
69 static SkSwizzler::ResultAlpha swizzle_bit_to_index( 59 static SkSwizzler::ResultAlpha swizzle_bit_to_index(
70 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 60 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
71 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { 61 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) {
72 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 62 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
73 63
74 // increment src by byte offset and bitIndex by bit offset 64 // Determine how many full bytes are in the row
75 src += offset / 8; 65 int bytesInRow = width >> 3;
76 int bitIndex = offset % 8; 66 int i;
77 uint8_t currByte = *src; 67 for (i = 0; i < bytesInRow; i++) {
78 for (int x = 0; x < dstWidth; x++) { 68 U8CPU currByte = src[i];
79 dst[x] = ((currByte >> (7-bitIndex)) & 1); 69 for (int j = 0; j < 8; j++) {
80 int bitOffset = bitIndex + deltaSrc; 70 dst[j] = (currByte >> (7 - j)) & 1;
81 bitIndex = bitOffset % 8; 71 }
82 currByte = *(src += bitOffset / 8); 72 dst += 8;
83 } 73 }
84 74
75 // Finish the remaining bits
76 width &= 7;
77 if (width > 0) {
78 U8CPU currByte = src[i];
79 for (int j = 0; j < width; j++) {
80 dst[j] = ((currByte >> 7) & 1);
81 currByte <<= 1;
82 }
83 }
85 return SkSwizzler::kOpaque_ResultAlpha; 84 return SkSwizzler::kOpaque_ResultAlpha;
86 } 85 }
87 86
88 // same as swizzle_bit_to_grayscale and swizzle_bit_to_index except for value as signed to dst[x]
89 static SkSwizzler::ResultAlpha swizzle_bit_to_n32( 87 static SkSwizzler::ResultAlpha swizzle_bit_to_n32(
90 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 88 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
91 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { 89 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) {
92 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; 90 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
93 91
94 // increment src by byte offset and bitIndex by bit offset 92 // Determine how many full bytes are in the row
95 src += offset / 8; 93 int bytesInRow = width >> 3;
96 int bitIndex = offset % 8; 94 int i;
97 uint8_t currByte = *src; 95 for (i = 0; i < bytesInRow; i++) {
98 for (int x = 0; x < dstWidth; x++) { 96 U8CPU currByte = src[i];
99 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBL ACK; 97 for (int j = 0; j < 8; j++) {
100 int bitOffset = bitIndex + deltaSrc; 98 dst[j] = ((currByte >> (7 - j)) & 1) ? SK_ColorWHITE : SK_ColorBLACK ;
101 bitIndex = bitOffset % 8; 99 }
102 currByte = *(src += bitOffset / 8); 100 dst += 8;
103 } 101 }
104 102
103 // Finish the remaining bits
104 width &= 7;
105 if (width > 0) {
106 U8CPU currByte = src[i];
107 for (int j = 0; j < width; j++) {
108 dst[j] = ((currByte >> 7) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
109 currByte <<= 1;
110 }
111 }
105 return SkSwizzler::kOpaque_ResultAlpha; 112 return SkSwizzler::kOpaque_ResultAlpha;
106 } 113 }
107 114
108 // kIndex1, kIndex2, kIndex4 115 // kIndex1, kIndex2, kIndex4
109 116
110 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( 117 static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
111 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 118 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
112 int bitsPerPixel, int offset, const SkPMColor ctable[]) { 119 int bitsPerPixel, const SkPMColor ctable[]) {
113 120
114 src += offset;
115 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 121 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
116 INIT_RESULT_ALPHA; 122 INIT_RESULT_ALPHA;
117 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 123 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
118 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); 124 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
119 const uint8_t mask = (1 << bitsPerPixel) - 1; 125 const uint8_t mask = (1 << bitsPerPixel) - 1;
120 int x = 0; 126 int x = 0;
121 for (uint32_t byte = 0; byte < rowBytes; byte++) { 127 for (uint32_t byte = 0; byte < rowBytes; byte++) {
122 uint8_t pixelData = src[byte]; 128 uint8_t pixelData = src[byte];
123 for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) { 129 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) {
124 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; 130 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
125 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); 131 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
126 dst[x] = index; 132 dst[x] = index;
127 pixelData <<= bitsPerPixel; 133 pixelData <<= bitsPerPixel;
128 x++; 134 x++;
129 } 135 }
130 } 136 }
131 return COMPUTE_RESULT_ALPHA; 137 return COMPUTE_RESULT_ALPHA;
132 } 138 }
133 139
134 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( 140 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
135 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 141 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
136 int bitsPerPixel, int offset, const SkPMColor ctable[]) { 142 int bitsPerPixel, const SkPMColor ctable[]) {
137 143
138 src += offset;
139 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; 144 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
140 INIT_RESULT_ALPHA; 145 INIT_RESULT_ALPHA;
141 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 146 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
142 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); 147 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
143 const uint8_t mask = (1 << bitsPerPixel) - 1; 148 const uint8_t mask = (1 << bitsPerPixel) - 1;
144 int x = 0; 149 int x = 0;
145 for (uint32_t byte = 0; byte < rowBytes; byte++) { 150 for (uint32_t byte = 0; byte < rowBytes; byte++) {
146 uint8_t pixelData = src[byte]; 151 uint8_t pixelData = src[byte];
147 for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) { 152 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) {
148 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; 153 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
149 SkPMColor c = ctable[index]; 154 SkPMColor c = ctable[index];
150 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 155 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
151 dst[x] = c; 156 dst[x] = c;
152 pixelData <<= bitsPerPixel; 157 pixelData <<= bitsPerPixel;
153 x++; 158 x++;
154 } 159 }
155 } 160 }
156 return COMPUTE_RESULT_ALPHA; 161 return COMPUTE_RESULT_ALPHA;
157 } 162 }
158 163
159 // kIndex 164 // kIndex
160 165
161 static SkSwizzler::ResultAlpha swizzle_index_to_index( 166 static SkSwizzler::ResultAlpha swizzle_index_to_index(
162 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 167 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
163 int deltaSrc, int offset, const SkPMColor ctable[]) { 168 int bytesPerPixel, const SkPMColor ctable[]) {
164 169
165 src += offset;
166 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 170 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
167 if (1 == deltaSrc) { 171 memcpy(dst, src, width);
168 memcpy(dst, src, dstWidth);
169 } else {
170 for (int x = 0; x < dstWidth; x++) {
171 dst[x] = src[0];
172 src += deltaSrc;
173 }
174 }
175 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? 172 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque?
176 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous 173 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous
177 // and probably wrong since gif and bmp (rarely) may have al pha. 174 // and probably wrong since gif and bmp (rarely) may have al pha.
178 INIT_RESULT_ALPHA; 175 INIT_RESULT_ALPHA;
179 for (int x = 0; x < dstWidth; x++) { 176 for (int x = 0; x < width; x++) {
180 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); 177 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT);
181 } 178 }
182 return COMPUTE_RESULT_ALPHA; 179 return COMPUTE_RESULT_ALPHA;
183 } 180 }
184 181
185 static SkSwizzler::ResultAlpha swizzle_index_to_n32( 182 static SkSwizzler::ResultAlpha swizzle_index_to_n32(
186 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 183 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
187 int deltaSrc, int offset, const SkPMColor ctable[]) { 184 int bytesPerPixel, const SkPMColor ctable[]) {
188 185
189 src += offset;
190 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 186 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
191 INIT_RESULT_ALPHA; 187 INIT_RESULT_ALPHA;
192 for (int x = 0; x < dstWidth; x++) { 188 for (int x = 0; x < width; x++) {
193 SkPMColor c = ctable[*src]; 189 SkPMColor c = ctable[src[x]];
194 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 190 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
195 dst[x] = c; 191 dst[x] = c;
196 src += deltaSrc;
197 } 192 }
198 return COMPUTE_RESULT_ALPHA; 193 return COMPUTE_RESULT_ALPHA;
199 } 194 }
200 195
201 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( 196 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ(
202 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 197 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
203 int deltaSrc, int offset, const SkPMColor ctable[]) { 198 int bytesPerPixel, const SkPMColor ctable[]) {
204 199
205 src += offset;
206 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 200 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
207 INIT_RESULT_ALPHA; 201 INIT_RESULT_ALPHA;
208 for (int x = 0; x < dstWidth; x++) { 202 for (int x = 0; x < width; x++) {
209 SkPMColor c = ctable[*src]; 203 SkPMColor c = ctable[src[x]];
210 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 204 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
211 if (c != 0) { 205 if (c != 0) {
212 dst[x] = c; 206 dst[x] = c;
213 } 207 }
214 src += deltaSrc;
215 } 208 }
216 return COMPUTE_RESULT_ALPHA; 209 return COMPUTE_RESULT_ALPHA;
217 } 210 }
218 211
219 static SkSwizzler::ResultAlpha swizzle_index_to_565( 212 static SkSwizzler::ResultAlpha swizzle_index_to_565(
220 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 213 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
221 int bytesPerPixel, int offset, const SkPMColor ctable[]) { 214 int bytesPerPixel, const SkPMColor ctable[]) {
222 // FIXME: Support dithering? Requires knowing y, which I think is a bigger 215 // FIXME: Support dithering? Requires knowing y, which I think is a bigger
223 // change. 216 // change.
224 src += offset;
225 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 217 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
226 for (int x = 0; x < dstWidth; x++) { 218 for (int x = 0; x < width; x++) {
227 dst[x] = SkPixel32ToPixel16(ctable[*src]); 219 dst[x] = SkPixel32ToPixel16(ctable[*src]);
228 src += bytesPerPixel; 220 src += bytesPerPixel;
229 } 221 }
230 return SkSwizzler::kOpaque_ResultAlpha; 222 return SkSwizzler::kOpaque_ResultAlpha;
231 } 223 }
232 224
233 225
234 #undef A32_MASK_IN_PLACE 226 #undef A32_MASK_IN_PLACE
235 227
236 // kGray 228 // kGray
237 229
238 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( 230 static SkSwizzler::ResultAlpha swizzle_gray_to_n32(
239 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 231 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
240 int deltaSrc, int offset, const SkPMColor ctable[]) { 232 int bytesPerPixel, const SkPMColor ctable[]) {
241 233
242 src += offset;
243 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 234 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
244 for (int x = 0; x < dstWidth; x++) { 235 for (int x = 0; x < width; x++) {
245 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); 236 dst[x] = SkPackARGB32NoCheck(0xFF, src[x], src[x], src[x]);
246 src += deltaSrc;
247 } 237 }
248 return SkSwizzler::kOpaque_ResultAlpha; 238 return SkSwizzler::kOpaque_ResultAlpha;
249 } 239 }
250 240
251 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( 241 static SkSwizzler::ResultAlpha swizzle_gray_to_gray(
252 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 242 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
253 int deltaSrc, int offset, const SkPMColor ctable[]) { 243 int bytesPerPixel, const SkPMColor ctable[]) {
254 244 memcpy(dstRow, src, width);
255 src += offset;
256 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
257 if (1 == deltaSrc) {
258 memcpy(dstRow, src, dstWidth);
259 } else {
260 for (int x = 0; x < dstWidth; x++) {
261 dst[x] = src[0];
262 src += deltaSrc;
263 }
264 }
265 return SkSwizzler::kOpaque_ResultAlpha; 245 return SkSwizzler::kOpaque_ResultAlpha;
266 } 246 }
267 247
268 static SkSwizzler::ResultAlpha swizzle_gray_to_565( 248 static SkSwizzler::ResultAlpha swizzle_gray_to_565(
269 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 249 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
270 int bytesPerPixel, int offset, const SkPMColor ctable[]) { 250 int bytesPerPixel, const SkPMColor ctable[]) {
271 // FIXME: Support dithering? 251 // FIXME: Support dithering?
272 src += offset;
273 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 252 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
274 for (int x = 0; x < dstWidth; x++) { 253 for (int x = 0; x < width; x++) {
275 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); 254 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]);
276 src += bytesPerPixel; 255 src += bytesPerPixel;
277 } 256 }
278 return SkSwizzler::kOpaque_ResultAlpha; 257 return SkSwizzler::kOpaque_ResultAlpha;
279 } 258 }
280 259
281 // kBGRX 260 // kBGRX
282 261
283 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( 262 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32(
284 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 263 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
285 int deltaSrc, int offset, const SkPMColor ctable[]) { 264 int bytesPerPixel, const SkPMColor ctable[]) {
286 265
287 src += offset;
288 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 266 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
289 for (int x = 0; x < dstWidth; x++) { 267 for (int x = 0; x < width; x++) {
290 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); 268 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]);
291 src += deltaSrc; 269 src += bytesPerPixel;
292 } 270 }
293 return SkSwizzler::kOpaque_ResultAlpha; 271 return SkSwizzler::kOpaque_ResultAlpha;
294 } 272 }
295 273
296 // kBGRA 274 // kBGRA
297 275
298 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( 276 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul(
299 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 277 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
300 int deltaSrc, int offset, const SkPMColor ctable[]) { 278 int bytesPerPixel, const SkPMColor ctable[]) {
301 279
302 src += offset;
303 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 280 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
304 INIT_RESULT_ALPHA; 281 INIT_RESULT_ALPHA;
305 for (int x = 0; x < dstWidth; x++) { 282 for (int x = 0; x < width; x++) {
306 uint8_t alpha = src[3]; 283 uint8_t alpha = src[3];
307 UPDATE_RESULT_ALPHA(alpha); 284 UPDATE_RESULT_ALPHA(alpha);
308 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); 285 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]);
309 src += deltaSrc; 286 src += bytesPerPixel;
310 } 287 }
311 return COMPUTE_RESULT_ALPHA; 288 return COMPUTE_RESULT_ALPHA;
312 } 289 }
313 290
314 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( 291 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul(
315 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 292 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
316 int deltaSrc, int offset, const SkPMColor ctable[]) { 293 int bytesPerPixel, const SkPMColor ctable[]) {
317 294
318 src += offset;
319 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 295 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
320 INIT_RESULT_ALPHA; 296 INIT_RESULT_ALPHA;
321 for (int x = 0; x < dstWidth; x++) { 297 for (int x = 0; x < width; x++) {
322 uint8_t alpha = src[3]; 298 uint8_t alpha = src[3];
323 UPDATE_RESULT_ALPHA(alpha); 299 UPDATE_RESULT_ALPHA(alpha);
324 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); 300 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]);
325 src += deltaSrc; 301 src += bytesPerPixel;
326 } 302 }
327 return COMPUTE_RESULT_ALPHA; 303 return COMPUTE_RESULT_ALPHA;
328 } 304 }
329 305
330 // kRGBX 306 // kRGBX
331 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( 307 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32(
332 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 308 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
333 int deltaSrc, int offset, const SkPMColor ctable[]) { 309 int bytesPerPixel, const SkPMColor ctable[]) {
334 310
335 src += offset;
336 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 311 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
337 for (int x = 0; x < dstWidth; x++) { 312 for (int x = 0; x < width; x++) {
338 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); 313 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]);
339 src += deltaSrc; 314 src += bytesPerPixel;
340 } 315 }
341 return SkSwizzler::kOpaque_ResultAlpha; 316 return SkSwizzler::kOpaque_ResultAlpha;
342 } 317 }
343 318
344 static SkSwizzler::ResultAlpha swizzle_rgbx_to_565( 319 static SkSwizzler::ResultAlpha swizzle_rgbx_to_565(
345 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 320 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
346 int bytesPerPixel, int offset, const SkPMColor ctable[]) { 321 int bytesPerPixel, const SkPMColor ctable[]) {
347 // FIXME: Support dithering? 322 // FIXME: Support dithering?
348 src += offset;
349 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 323 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
350 for (int x = 0; x < dstWidth; x++) { 324 for (int x = 0; x < width; x++) {
351 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); 325 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]);
352 src += bytesPerPixel; 326 src += bytesPerPixel;
353 } 327 }
354 return SkSwizzler::kOpaque_ResultAlpha; 328 return SkSwizzler::kOpaque_ResultAlpha;
355 } 329 }
356 330
357 331
358 // kRGBA 332 // kRGBA
359 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( 333 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul(
360 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 334 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
361 int deltaSrc, int offset, const SkPMColor ctable[]) { 335 int bytesPerPixel, const SkPMColor ctable[]) {
362 336
363 src += offset;
364 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 337 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
365 INIT_RESULT_ALPHA; 338 INIT_RESULT_ALPHA;
366 for (int x = 0; x < dstWidth; x++) { 339 for (int x = 0; x < width; x++) {
367 unsigned alpha = src[3]; 340 unsigned alpha = src[3];
368 UPDATE_RESULT_ALPHA(alpha); 341 UPDATE_RESULT_ALPHA(alpha);
369 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); 342 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]);
370 src += deltaSrc; 343 src += bytesPerPixel;
371 } 344 }
372 return COMPUTE_RESULT_ALPHA; 345 return COMPUTE_RESULT_ALPHA;
373 } 346 }
374 347
375 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( 348 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul(
376 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 349 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
377 int deltaSrc, int offset, const SkPMColor ctable[]) { 350 int bytesPerPixel, const SkPMColor ctable[]) {
378 351
379 src += offset;
380 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); 352 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
381 INIT_RESULT_ALPHA; 353 INIT_RESULT_ALPHA;
382 for (int x = 0; x < dstWidth; x++) { 354 for (int x = 0; x < width; x++) {
383 unsigned alpha = src[3]; 355 unsigned alpha = src[3];
384 UPDATE_RESULT_ALPHA(alpha); 356 UPDATE_RESULT_ALPHA(alpha);
385 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); 357 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]);
386 src += deltaSrc; 358 src += bytesPerPixel;
387 } 359 }
388 return COMPUTE_RESULT_ALPHA; 360 return COMPUTE_RESULT_ALPHA;
389 } 361 }
390 362
391 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( 363 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ(
392 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 364 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
393 int deltaSrc, int offset, const SkPMColor ctable[]) { 365 int bytesPerPixel, const SkPMColor ctable[]) {
394 366
395 src += offset;
396 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 367 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
397 INIT_RESULT_ALPHA; 368 INIT_RESULT_ALPHA;
398 for (int x = 0; x < dstWidth; x++) { 369 for (int x = 0; x < width; x++) {
399 unsigned alpha = src[3]; 370 unsigned alpha = src[3];
400 UPDATE_RESULT_ALPHA(alpha); 371 UPDATE_RESULT_ALPHA(alpha);
401 if (0 != alpha) { 372 if (0 != alpha) {
402 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); 373 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]);
403 } 374 }
404 src += deltaSrc; 375 src += bytesPerPixel;
405 } 376 }
406 return COMPUTE_RESULT_ALPHA; 377 return COMPUTE_RESULT_ALPHA;
407 } 378 }
408 379
409 /** 380 /**
410 FIXME: This was my idea to cheat in order to continue taking advantage of sk ipping zeroes. 381 FIXME: This was my idea to cheat in order to continue taking advantage of sk ipping zeroes.
411 This would be fine for drawing normally, but not for drawing with transfer m odes. Being 382 This would be fine for drawing normally, but not for drawing with transfer m odes. Being
412 honest means we can draw correctly with transfer modes, with the cost of not being able 383 honest means we can draw correctly with transfer modes, with the cost of not being able
413 to take advantage of Android's free unwritten pages. Something to keep in mi nd when we 384 to take advantage of Android's free unwritten pages. Something to keep in mi nd when we
414 decide whether to switch to unpremul default. 385 decide whether to switch to unpremul default.
415 static bool swizzle_rgba_to_n32_unpremul_skipZ(void* SK_RESTRICT dstRow, 386 static bool swizzle_rgba_to_n32_unpremul_skipZ(void* SK_RESTRICT dstRow,
416 const uint8_t* SK_RESTRICT src, 387 const uint8_t* SK_RESTRICT src,
417 int dstWidth, int bitsPerPixel, i nt offset, 388 int width, int bitsPerPixel,
418 const SkPMColor[]) { 389 const SkPMColor[]) {
419 src += offset;
420 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 390 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
421 unsigned alphaMask = 0xFF; 391 unsigned alphaMask = 0xFF;
422 for (int x = 0; x < dstWidth; x++) { 392 for (int x = 0; x < width; x++) {
423 unsigned alpha = src[3]; 393 unsigned alpha = src[3];
424 // NOTE: We cheat here. The caller requested unpremul and skip zeroes. I t's possible 394 // NOTE: We cheat here. The caller requested unpremul and skip zeroes. I t's possible
425 // the color components are not zero, but we skip them anyway, meaning t hey'll remain 395 // the color components are not zero, but we skip them anyway, meaning t hey'll remain
426 // zero (implied by the request to skip zeroes). 396 // zero (implied by the request to skip zeroes).
427 if (0 != alpha) { 397 if (0 != alpha) {
428 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); 398 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]);
429 } 399 }
430 src += deltaSrc; 400 src += deltaSrc;
431 alphaMask &= alpha; 401 alphaMask &= alpha;
432 } 402 }
433 return alphaMask != 0xFF; 403 return alphaMask != 0xFF;
434 } 404 }
435 */ 405 */
436 406
437 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, 407 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
438 const SkPMColor* ctable, 408 const SkPMColor* ctable,
439 const SkImageInfo& dstInfo, 409 const SkImageInfo& info,
440 SkCodec::ZeroInitialized zeroInit, 410 SkCodec::ZeroInitialized zeroInit) {
441 const SkImageInfo& srcInfo) { 411 if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) {
442 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) {
443 return NULL; 412 return NULL;
444 } 413 }
445 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) 414 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc)
446 && NULL == ctable) { 415 && NULL == ctable) {
447 return NULL; 416 return NULL;
448 } 417 }
449 RowProc proc = NULL; 418 RowProc proc = NULL;
450
451 switch (sc) { 419 switch (sc) {
452 case kBit: 420 case kBit:
453 switch (dstInfo.colorType()) { 421 switch (info.colorType()) {
454 case kN32_SkColorType: 422 case kN32_SkColorType:
455 proc = &swizzle_bit_to_n32; 423 proc = &swizzle_bit_to_n32;
456 break; 424 break;
457 case kIndex_8_SkColorType: 425 case kIndex_8_SkColorType:
458 proc = &swizzle_bit_to_index; 426 proc = &swizzle_bit_to_index;
459 break; 427 break;
460 case kGray_8_SkColorType: 428 case kGray_8_SkColorType:
461 proc = &swizzle_bit_to_grayscale; 429 proc = &swizzle_bit_to_grayscale;
462 break; 430 break;
463 default: 431 default:
464 break; 432 break;
465 } 433 }
466 break; 434 break;
467 case kIndex1: 435 case kIndex1:
468 case kIndex2: 436 case kIndex2:
469 case kIndex4: 437 case kIndex4:
470 switch (dstInfo.colorType()) { 438 switch (info.colorType()) {
471 case kN32_SkColorType: 439 case kN32_SkColorType:
472 proc = &swizzle_small_index_to_n32; 440 proc = &swizzle_small_index_to_n32;
473 break; 441 break;
474 case kIndex_8_SkColorType: 442 case kIndex_8_SkColorType:
475 proc = &swizzle_small_index_to_index; 443 proc = &swizzle_small_index_to_index;
476 break; 444 break;
477 default: 445 default:
478 break; 446 break;
479 } 447 }
480 break; 448 break;
481 case kIndex: 449 case kIndex:
482 switch (dstInfo.colorType()) { 450 switch (info.colorType()) {
483 case kN32_SkColorType: 451 case kN32_SkColorType:
484 // We assume the color premultiplied ctable (or not) as desi red. 452 // We assume the color premultiplied ctable (or not) as desi red.
485 if (SkCodec::kYes_ZeroInitialized == zeroInit) { 453 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
486 proc = &swizzle_index_to_n32_skipZ; 454 proc = &swizzle_index_to_n32_skipZ;
487 break; 455 break;
488 } else { 456 } else {
489 proc = &swizzle_index_to_n32; 457 proc = &swizzle_index_to_n32;
490 break; 458 break;
491 } 459 }
492 break; 460 break;
493 case kRGB_565_SkColorType: 461 case kRGB_565_SkColorType:
494 proc = &swizzle_index_to_565; 462 proc = &swizzle_index_to_565;
495 break; 463 break;
496 case kIndex_8_SkColorType: 464 case kIndex_8_SkColorType:
497 proc = &swizzle_index_to_index; 465 proc = &swizzle_index_to_index;
498 break; 466 break;
499 default: 467 default:
500 break; 468 break;
501 } 469 }
502 break; 470 break;
503 case kGray: 471 case kGray:
504 switch (dstInfo.colorType()) { 472 switch (info.colorType()) {
505 case kN32_SkColorType: 473 case kN32_SkColorType:
506 proc = &swizzle_gray_to_n32; 474 proc = &swizzle_gray_to_n32;
507 break; 475 break;
508 case kGray_8_SkColorType: 476 case kGray_8_SkColorType:
509 proc = &swizzle_gray_to_gray; 477 proc = &swizzle_gray_to_gray;
510 break; 478 break;
511 case kRGB_565_SkColorType: 479 case kRGB_565_SkColorType:
512 proc = &swizzle_gray_to_565; 480 proc = &swizzle_gray_to_565;
513 break; 481 break;
514 default: 482 default:
515 break; 483 break;
516 } 484 }
517 break; 485 break;
518 case kBGR: 486 case kBGR:
519 case kBGRX: 487 case kBGRX:
520 switch (dstInfo.colorType()) { 488 switch (info.colorType()) {
521 case kN32_SkColorType: 489 case kN32_SkColorType:
522 proc = &swizzle_bgrx_to_n32; 490 proc = &swizzle_bgrx_to_n32;
523 break; 491 break;
524 default: 492 default:
525 break; 493 break;
526 } 494 }
527 break; 495 break;
528 case kBGRA: 496 case kBGRA:
529 switch (dstInfo.colorType()) { 497 switch (info.colorType()) {
530 case kN32_SkColorType: 498 case kN32_SkColorType:
531 switch (dstInfo.alphaType()) { 499 switch (info.alphaType()) {
532 case kUnpremul_SkAlphaType: 500 case kUnpremul_SkAlphaType:
533 proc = &swizzle_bgra_to_n32_unpremul; 501 proc = &swizzle_bgra_to_n32_unpremul;
534 break; 502 break;
535 case kPremul_SkAlphaType: 503 case kPremul_SkAlphaType:
536 proc = &swizzle_bgra_to_n32_premul; 504 proc = &swizzle_bgra_to_n32_premul;
537 break; 505 break;
538 default: 506 default:
539 break; 507 break;
540 } 508 }
541 break; 509 break;
542 default: 510 default:
543 break; 511 break;
544 } 512 }
545 break; 513 break;
546 case kRGBX: 514 case kRGBX:
547 // TODO: Support other swizzles. 515 // TODO: Support other swizzles.
548 switch (dstInfo.colorType()) { 516 switch (info.colorType()) {
549 case kN32_SkColorType: 517 case kN32_SkColorType:
550 proc = &swizzle_rgbx_to_n32; 518 proc = &swizzle_rgbx_to_n32;
551 break; 519 break;
552 case kRGB_565_SkColorType: 520 case kRGB_565_SkColorType:
553 proc = &swizzle_rgbx_to_565; 521 proc = &swizzle_rgbx_to_565;
554 default: 522 default:
555 break; 523 break;
556 } 524 }
557 break; 525 break;
558 case kRGBA: 526 case kRGBA:
559 switch (dstInfo.colorType()) { 527 switch (info.colorType()) {
560 case kN32_SkColorType: 528 case kN32_SkColorType:
561 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { 529 if (info.alphaType() == kUnpremul_SkAlphaType) {
562 // Respect zeroInit? 530 // Respect zeroInit?
563 proc = &swizzle_rgba_to_n32_unpremul; 531 proc = &swizzle_rgba_to_n32_unpremul;
564 } else { 532 } else {
565 if (SkCodec::kYes_ZeroInitialized == zeroInit) { 533 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
566 proc = &swizzle_rgba_to_n32_premul_skipZ; 534 proc = &swizzle_rgba_to_n32_premul_skipZ;
567 } else { 535 } else {
568 proc = &swizzle_rgba_to_n32_premul; 536 proc = &swizzle_rgba_to_n32_premul;
569 } 537 }
570 } 538 }
571 break; 539 break;
572 default: 540 default:
573 break; 541 break;
574 } 542 }
575 break; 543 break;
576 case kRGB: 544 case kRGB:
577 switch (dstInfo.colorType()) { 545 switch (info.colorType()) {
578 case kN32_SkColorType: 546 case kN32_SkColorType:
579 proc = &swizzle_rgbx_to_n32; 547 proc = &swizzle_rgbx_to_n32;
580 break; 548 break;
581 default: 549 default:
582 break; 550 break;
583 } 551 }
584 break; 552 break;
585 case kRGB_565:
586 switch (dstInfo.colorType()) {
587 case kRGB_565_SkColorType:
588 proc = &sample565;
589 break;
590 default:
591 break;
592 }
593 default: 553 default:
594 break; 554 break;
595 } 555 }
596 if (NULL == proc) { 556 if (NULL == proc) {
597 return NULL; 557 return NULL;
598 } 558 }
599 559
600 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits 560 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits
601 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPix el(sc); 561 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) :
602 562 BitsPerPixel(sc);
603 // get sampleX based on srcInfo and dstInfo dimensions 563 return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, info));
604 int sampleX;
605 SkScaledCodec::ComputeSampleSize(dstInfo, srcInfo, &sampleX, NULL);
606
607 return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, dstInfo, sampleX));
608 } 564 }
609 565
610 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, 566 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable,
611 int deltaSrc, const SkImageInfo& info, int sampleX) 567 int deltaSrc, const SkImageInfo& info)
612 : fRowProc(proc) 568 : fRowProc(proc)
613 , fColorTable(ctable) 569 , fColorTable(ctable)
614 , fDeltaSrc(deltaSrc) 570 , fDeltaSrc(deltaSrc)
615 , fDstInfo(info) 571 , fDstInfo(info)
616 , fSampleX(sampleX) 572 {}
617 , fX0(sampleX == 1 ? 0 : sampleX >> 1)
618 {
619 // check that fX0 is less than original width
620 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX);
621 }
622 573
623 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { 574 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) {
624 SkASSERT(NULL != dst && NULL != src); 575 SkASSERT(NULL != dst && NULL != src);
625 return fRowProc(dst, src, fDstInfo.width(), fSampleX * fDeltaSrc, fX0 * fDel taSrc, fColorTable); 576 return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fColorTable);
626 } 577 }
627 578
628 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes, 579 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes,
629 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { 580 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) {
630 SkASSERT(dstStartRow != NULL); 581 SkASSERT(dstStartRow != NULL);
631 SkASSERT(numRows <= (uint32_t) dstInfo.height()); 582 SkASSERT(numRows <= (uint32_t) dstInfo.height());
632 583
633 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. 584 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded.
634 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes); 585 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes);
635 586
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 // bits of SK_ColorBLACK are identical to the 565 representation 635 // bits of SK_ColorBLACK are identical to the 565 representation
685 // for black. 636 // for black.
686 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); 637 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill);
687 break; 638 break;
688 default: 639 default:
689 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); 640 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
690 SkASSERT(false); 641 SkASSERT(false);
691 break; 642 break;
692 } 643 }
693 } 644 }
OLDNEW
« no previous file with comments | « src/codec/SkSwizzler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698