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

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

Issue 1256373002: Pass the destination pointer to next (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Thanks windows bot! 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 "SkSwizzler.h" 10 #include "SkSwizzler.h"
11 #include "SkTemplates.h" 11 #include "SkTemplates.h"
12 #include "SkUtils.h" 12 #include "SkUtils.h"
13 13
14 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, 14 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha,
15 uint8_t maxAlpha) { 15 uint8_t maxAlpha) {
16 // In the transparent case, this returns 0x0000 16 // In the transparent case, this returns 0x0000
17 // In the opaque case, this returns 0xFFFF 17 // In the opaque case, this returns 0xFFFF
18 // If the row is neither transparent nor opaque, returns something else 18 // If the row is neither transparent nor opaque, returns something else
19 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; 19 return (((uint16_t) maxAlpha) << 8) | zeroAlpha;
20 } 20 }
21 21
22 // kIndex1, kIndex2, kIndex4 22 // kIndex1, kIndex2, kIndex4
23 23
24 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( 24 static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
25 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 25 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
26 int bitsPerPixel, int y, const SkPMColor ctable[]) { 26 int bitsPerPixel, const SkPMColor ctable[]) {
27 27
28 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 28 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
29 INIT_RESULT_ALPHA; 29 INIT_RESULT_ALPHA;
30 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 30 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
31 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); 31 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
32 const uint8_t mask = (1 << bitsPerPixel) - 1; 32 const uint8_t mask = (1 << bitsPerPixel) - 1;
33 int x = 0; 33 int x = 0;
34 for (uint32_t byte = 0; byte < rowBytes; byte++) { 34 for (uint32_t byte = 0; byte < rowBytes; byte++) {
35 uint8_t pixelData = src[byte]; 35 uint8_t pixelData = src[byte];
36 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { 36 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) {
37 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; 37 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
38 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); 38 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
39 dst[x] = index; 39 dst[x] = index;
40 pixelData <<= bitsPerPixel; 40 pixelData <<= bitsPerPixel;
41 x++; 41 x++;
42 } 42 }
43 } 43 }
44 return COMPUTE_RESULT_ALPHA; 44 return COMPUTE_RESULT_ALPHA;
45 } 45 }
46 46
47 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( 47 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
48 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 48 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
49 int bitsPerPixel, int y, const SkPMColor ctable[]) { 49 int bitsPerPixel, const SkPMColor ctable[]) {
50 50
51 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; 51 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
52 INIT_RESULT_ALPHA; 52 INIT_RESULT_ALPHA;
53 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 53 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
54 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); 54 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
55 const uint8_t mask = (1 << bitsPerPixel) - 1; 55 const uint8_t mask = (1 << bitsPerPixel) - 1;
56 int x = 0; 56 int x = 0;
57 for (uint32_t byte = 0; byte < rowBytes; byte++) { 57 for (uint32_t byte = 0; byte < rowBytes; byte++) {
58 uint8_t pixelData = src[byte]; 58 uint8_t pixelData = src[byte];
59 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { 59 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) {
60 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; 60 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
61 SkPMColor c = ctable[index]; 61 SkPMColor c = ctable[index];
62 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 62 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
63 dst[x] = c; 63 dst[x] = c;
64 pixelData <<= bitsPerPixel; 64 pixelData <<= bitsPerPixel;
65 x++; 65 x++;
66 } 66 }
67 } 67 }
68 return COMPUTE_RESULT_ALPHA; 68 return COMPUTE_RESULT_ALPHA;
69 } 69 }
70 70
71 // kIndex 71 // kIndex
72 72
73 static SkSwizzler::ResultAlpha swizzle_index_to_index( 73 static SkSwizzler::ResultAlpha swizzle_index_to_index(
74 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 74 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
75 int bytesPerPixel, int y, const SkPMColor ctable[]) { 75 int bytesPerPixel, const SkPMColor ctable[]) {
76 76
77 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 77 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
78 memcpy(dst, src, width); 78 memcpy(dst, src, width);
79 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? 79 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque?
80 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous 80 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous
81 // and probably wrong since gif and bmp (rarely) may have al pha. 81 // and probably wrong since gif and bmp (rarely) may have al pha.
82 INIT_RESULT_ALPHA; 82 INIT_RESULT_ALPHA;
83 for (int x = 0; x < width; x++) { 83 for (int x = 0; x < width; x++) {
84 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); 84 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT);
85 } 85 }
86 return COMPUTE_RESULT_ALPHA; 86 return COMPUTE_RESULT_ALPHA;
87 } 87 }
88 88
89 static SkSwizzler::ResultAlpha swizzle_index_to_n32( 89 static SkSwizzler::ResultAlpha swizzle_index_to_n32(
90 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 90 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
91 int bytesPerPixel, int y, const SkPMColor ctable[]) { 91 int bytesPerPixel, const SkPMColor ctable[]) {
92 92
93 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 93 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
94 INIT_RESULT_ALPHA; 94 INIT_RESULT_ALPHA;
95 for (int x = 0; x < width; x++) { 95 for (int x = 0; x < width; x++) {
96 SkPMColor c = ctable[src[x]]; 96 SkPMColor c = ctable[src[x]];
97 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 97 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
98 dst[x] = c; 98 dst[x] = c;
99 } 99 }
100 return COMPUTE_RESULT_ALPHA; 100 return COMPUTE_RESULT_ALPHA;
101 } 101 }
102 102
103 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( 103 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ(
104 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 104 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
105 int bytesPerPixel, int y, const SkPMColor ctable[]) { 105 int bytesPerPixel, const SkPMColor ctable[]) {
106 106
107 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 107 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
108 INIT_RESULT_ALPHA; 108 INIT_RESULT_ALPHA;
109 for (int x = 0; x < width; x++) { 109 for (int x = 0; x < width; x++) {
110 SkPMColor c = ctable[src[x]]; 110 SkPMColor c = ctable[src[x]];
111 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 111 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
112 if (c != 0) { 112 if (c != 0) {
113 dst[x] = c; 113 dst[x] = c;
114 } 114 }
115 } 115 }
116 return COMPUTE_RESULT_ALPHA; 116 return COMPUTE_RESULT_ALPHA;
117 } 117 }
118 118
119 #undef A32_MASK_IN_PLACE 119 #undef A32_MASK_IN_PLACE
120 120
121 // kGray 121 // kGray
122 122
123 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( 123 static SkSwizzler::ResultAlpha swizzle_gray_to_n32(
124 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 124 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
125 int bytesPerPixel, int y, const SkPMColor ctable[]) { 125 int bytesPerPixel, const SkPMColor ctable[]) {
126 126
127 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 127 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
128 for (int x = 0; x < width; x++) { 128 for (int x = 0; x < width; x++) {
129 dst[x] = SkPackARGB32NoCheck(0xFF, src[x], src[x], src[x]); 129 dst[x] = SkPackARGB32NoCheck(0xFF, src[x], src[x], src[x]);
130 } 130 }
131 return SkSwizzler::kOpaque_ResultAlpha; 131 return SkSwizzler::kOpaque_ResultAlpha;
132 } 132 }
133 133
134 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( 134 static SkSwizzler::ResultAlpha swizzle_gray_to_gray(
135 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 135 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
136 int bytesPerPixel, int y, const SkPMColor ctable[]) { 136 int bytesPerPixel, const SkPMColor ctable[]) {
137 memcpy(dstRow, src, width); 137 memcpy(dstRow, src, width);
138 return SkSwizzler::kOpaque_ResultAlpha; 138 return SkSwizzler::kOpaque_ResultAlpha;
139 } 139 }
140 140
141 // kBGRX 141 // kBGRX
142 142
143 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( 143 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32(
144 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 144 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
145 int bytesPerPixel, int y, const SkPMColor ctable[]) { 145 int bytesPerPixel, const SkPMColor ctable[]) {
146 146
147 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 147 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
148 for (int x = 0; x < width; x++) { 148 for (int x = 0; x < width; x++) {
149 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); 149 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]);
150 src += bytesPerPixel; 150 src += bytesPerPixel;
151 } 151 }
152 return SkSwizzler::kOpaque_ResultAlpha; 152 return SkSwizzler::kOpaque_ResultAlpha;
153 } 153 }
154 154
155 // kBGRA 155 // kBGRA
156 156
157 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( 157 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul(
158 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 158 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
159 int bytesPerPixel, int y, const SkPMColor ctable[]) { 159 int bytesPerPixel, const SkPMColor ctable[]) {
160 160
161 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 161 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
162 INIT_RESULT_ALPHA; 162 INIT_RESULT_ALPHA;
163 for (int x = 0; x < width; x++) { 163 for (int x = 0; x < width; x++) {
164 uint8_t alpha = src[3]; 164 uint8_t alpha = src[3];
165 UPDATE_RESULT_ALPHA(alpha); 165 UPDATE_RESULT_ALPHA(alpha);
166 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); 166 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]);
167 src += bytesPerPixel; 167 src += bytesPerPixel;
168 } 168 }
169 return COMPUTE_RESULT_ALPHA; 169 return COMPUTE_RESULT_ALPHA;
170 } 170 }
171 171
172 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( 172 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul(
173 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 173 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
174 int bytesPerPixel, int y, const SkPMColor ctable[]) { 174 int bytesPerPixel, const SkPMColor ctable[]) {
175 175
176 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 176 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
177 INIT_RESULT_ALPHA; 177 INIT_RESULT_ALPHA;
178 for (int x = 0; x < width; x++) { 178 for (int x = 0; x < width; x++) {
179 uint8_t alpha = src[3]; 179 uint8_t alpha = src[3];
180 UPDATE_RESULT_ALPHA(alpha); 180 UPDATE_RESULT_ALPHA(alpha);
181 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); 181 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]);
182 src += bytesPerPixel; 182 src += bytesPerPixel;
183 } 183 }
184 return COMPUTE_RESULT_ALPHA; 184 return COMPUTE_RESULT_ALPHA;
185 } 185 }
186 186
187 // n32 187 // n32
188 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( 188 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32(
189 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 189 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
190 int bytesPerPixel, int y, const SkPMColor ctable[]) { 190 int bytesPerPixel, const SkPMColor ctable[]) {
191 191
192 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 192 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
193 for (int x = 0; x < width; x++) { 193 for (int x = 0; x < width; x++) {
194 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); 194 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]);
195 src += bytesPerPixel; 195 src += bytesPerPixel;
196 } 196 }
197 return SkSwizzler::kOpaque_ResultAlpha; 197 return SkSwizzler::kOpaque_ResultAlpha;
198 } 198 }
199 199
200 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( 200 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul(
201 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 201 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
202 int bytesPerPixel, int y, const SkPMColor ctable[]) { 202 int bytesPerPixel, const SkPMColor ctable[]) {
203 203
204 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 204 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
205 INIT_RESULT_ALPHA; 205 INIT_RESULT_ALPHA;
206 for (int x = 0; x < width; x++) { 206 for (int x = 0; x < width; x++) {
207 unsigned alpha = src[3]; 207 unsigned alpha = src[3];
208 UPDATE_RESULT_ALPHA(alpha); 208 UPDATE_RESULT_ALPHA(alpha);
209 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); 209 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]);
210 src += bytesPerPixel; 210 src += bytesPerPixel;
211 } 211 }
212 return COMPUTE_RESULT_ALPHA; 212 return COMPUTE_RESULT_ALPHA;
213 } 213 }
214 214
215 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( 215 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul(
216 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 216 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
217 int bytesPerPixel, int y, const SkPMColor ctable[]) { 217 int bytesPerPixel, const SkPMColor ctable[]) {
218 218
219 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); 219 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
220 INIT_RESULT_ALPHA; 220 INIT_RESULT_ALPHA;
221 for (int x = 0; x < width; x++) { 221 for (int x = 0; x < width; x++) {
222 unsigned alpha = src[3]; 222 unsigned alpha = src[3];
223 UPDATE_RESULT_ALPHA(alpha); 223 UPDATE_RESULT_ALPHA(alpha);
224 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); 224 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]);
225 src += bytesPerPixel; 225 src += bytesPerPixel;
226 } 226 }
227 return COMPUTE_RESULT_ALPHA; 227 return COMPUTE_RESULT_ALPHA;
228 } 228 }
229 229
230 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( 230 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ(
231 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 231 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
232 int bytesPerPixel, int y, const SkPMColor ctable[]) { 232 int bytesPerPixel, const SkPMColor ctable[]) {
233 233
234 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 234 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
235 INIT_RESULT_ALPHA; 235 INIT_RESULT_ALPHA;
236 for (int x = 0; x < width; x++) { 236 for (int x = 0; x < width; x++) {
237 unsigned alpha = src[3]; 237 unsigned alpha = src[3];
238 UPDATE_RESULT_ALPHA(alpha); 238 UPDATE_RESULT_ALPHA(alpha);
239 if (0 != alpha) { 239 if (0 != alpha) {
240 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); 240 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]);
241 } 241 }
242 src += bytesPerPixel; 242 src += bytesPerPixel;
(...skipping 23 matching lines...) Expand all
266 } 266 }
267 src += deltaSrc; 267 src += deltaSrc;
268 alphaMask &= alpha; 268 alphaMask &= alpha;
269 } 269 }
270 return alphaMask != 0xFF; 270 return alphaMask != 0xFF;
271 } 271 }
272 */ 272 */
273 273
274 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, 274 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
275 const SkPMColor* ctable, 275 const SkPMColor* ctable,
276 const SkImageInfo& info, void* dst, 276 const SkImageInfo& info,
277 size_t dstRowBytes,
278 SkCodec::ZeroInitialized zeroInit) { 277 SkCodec::ZeroInitialized zeroInit) {
279 if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) { 278 if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) {
280 return NULL; 279 return NULL;
281 } 280 }
282 if (info.minRowBytes() > dstRowBytes) {
283 return NULL;
284 }
285 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) 281 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc)
286 && NULL == ctable) { 282 && NULL == ctable) {
287 return NULL; 283 return NULL;
288 } 284 }
289 RowProc proc = NULL; 285 RowProc proc = NULL;
290 switch (sc) { 286 switch (sc) {
291 case kIndex1: 287 case kIndex1:
292 case kIndex2: 288 case kIndex2:
293 case kIndex4: 289 case kIndex4:
294 switch (info.colorType()) { 290 switch (info.colorType()) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 default: 396 default:
401 break; 397 break;
402 } 398 }
403 if (NULL == proc) { 399 if (NULL == proc) {
404 return NULL; 400 return NULL;
405 } 401 }
406 402
407 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits 403 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits
408 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : 404 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) :
409 BitsPerPixel(sc); 405 BitsPerPixel(sc);
410 return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, info, dst, 406 return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, info));
411 dstRowBytes));
412 } 407 }
413 408
414 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, 409 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable,
415 int deltaSrc, const SkImageInfo& info, void* dst, 410 int deltaSrc, const SkImageInfo& info)
416 size_t rowBytes)
417 : fRowProc(proc) 411 : fRowProc(proc)
418 , fColorTable(ctable) 412 , fColorTable(ctable)
419 , fDeltaSrc(deltaSrc) 413 , fDeltaSrc(deltaSrc)
420 , fDstInfo(info) 414 , fDstInfo(info)
421 , fDstRow(dst) 415 {}
422 , fDstRowBytes(rowBytes)
423 , fCurrY(0)
424 {
425 SkDEBUGCODE(fNextMode = kUninitialized_NextMode);
426 }
427 416
428 SkSwizzler::ResultAlpha SkSwizzler::next(const uint8_t* SK_RESTRICT src) { 417 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) {
429 SkASSERT(0 <= fCurrY && fCurrY < fDstInfo.height()); 418 SkASSERT(NULL != dst && NULL != src);
430 SkASSERT(fDstRow != NULL); 419 return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fColorTable);
431 SkASSERT(kDesignateRow_NextMode != fNextMode);
432 SkDEBUGCODE(fNextMode = kConsecutive_NextMode);
433
434 // Decode a row
435 const ResultAlpha result = fRowProc(fDstRow, src, fDstInfo.width(),
436 fDeltaSrc, fCurrY, fColorTable);
437
438 // Move to the next row and return the result
439 fCurrY++;
440 fDstRow = SkTAddOffset<void>(fDstRow, fDstRowBytes);
441 return result;
442 }
443
444 SkSwizzler::ResultAlpha SkSwizzler::next(const uint8_t* SK_RESTRICT src,
445 int y) {
446 SkASSERT(0 <= y && y < fDstInfo.height());
447 SkASSERT(kConsecutive_NextMode != fNextMode);
448 SkDEBUGCODE(fNextMode = kDesignateRow_NextMode);
449
450 // Choose the row
451 void* row = SkTAddOffset<void>(fDstRow, y*fDstRowBytes);
452
453 // Decode the row
454 return fRowProc(row, src, fDstInfo.width(), fDeltaSrc, fCurrY,
455 fColorTable);
456 } 420 }
457 421
458 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes, 422 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes,
459 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { 423 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) {
460 SkASSERT(dstStartRow != NULL); 424 SkASSERT(dstStartRow != NULL);
461 SkASSERT(numRows <= (uint32_t) dstInfo.height()); 425 SkASSERT(numRows <= (uint32_t) dstInfo.height());
462 426
463 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. 427 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded.
464 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes); 428 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes);
465 429
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 // bits of SK_ColorBLACK are identical to the grayscale representati on 469 // bits of SK_ColorBLACK are identical to the grayscale representati on
506 // for black. 470 // for black.
507 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill); 471 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill);
508 break; 472 break;
509 default: 473 default:
510 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); 474 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
511 SkASSERT(false); 475 SkASSERT(false);
512 break; 476 break;
513 } 477 }
514 } 478 }
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