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

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

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

Powered by Google App Engine
This is Rietveld 408576698