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

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

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