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

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

Issue 1260673002: SkScaledCodec class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Works for jpeg images 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 "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 static SkSwizzler::ResultAlpha sample(void* SK_RESTRICT dstRow, const uint8_t* S K_RESTRICT src,
scroggo 2015/07/30 17:53:01 Could you add a description?
emmaleer 2015/07/30 22:27:56 Yes. Also, we can use the sample function for all
23 int width, int deltaSrc, int y, const SkPM Color ctable[]){
24 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
scroggo 2015/07/30 17:53:01 Does this do what we want it to? It looks like it
emmaleer 2015/07/30 22:27:56 I think this is working somehow.. When I test it,
scroggo 2015/07/31 13:35:33 That is correct. For the "small index" versions (a
emmaleer 2015/07/31 18:41:56 I've fixed this to work with 565
25 for (int x = 0; x < width; x++) {
26 dst[x] = src[0];
27 src += deltaSrc;
28 }
scroggo 2015/07/30 17:53:01 This method should return a value. For 565, we do
emmaleer 2015/07/30 22:27:56 Acknowledged.
29 }
22 // kIndex1, kIndex2, kIndex4 30 // kIndex1, kIndex2, kIndex4
23 31
24 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( 32 static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
25 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 33 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
26 int bitsPerPixel, int y, const SkPMColor ctable[]) { 34 int bitsPerPixel, int y, const SkPMColor ctable[]) {
27 35
28 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 36 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
29 INIT_RESULT_ALPHA; 37 INIT_RESULT_ALPHA;
30 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 38 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
31 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); 39 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 x++; 73 x++;
66 } 74 }
67 } 75 }
68 return COMPUTE_RESULT_ALPHA; 76 return COMPUTE_RESULT_ALPHA;
69 } 77 }
70 78
71 // kIndex 79 // kIndex
72 80
73 static SkSwizzler::ResultAlpha swizzle_index_to_index( 81 static SkSwizzler::ResultAlpha swizzle_index_to_index(
74 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 82 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
75 int bytesPerPixel, int y, const SkPMColor ctable[]) { 83 int deltaSrc, int y, const SkPMColor ctable[]) {
76 84
77 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 85 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
78 memcpy(dst, src, width); 86 if (1 == deltaSrc) {
87 memcpy(dst, src, width);
88 } else {
89 for (int x = 0; x < width; x++) {
90 dst[x] = src[0];
91 src += deltaSrc;
92 }
93 }
79 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? 94 // 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 95 // 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. 96 // and probably wrong since gif and bmp (rarely) may have al pha.
82 INIT_RESULT_ALPHA; 97 INIT_RESULT_ALPHA;
83 for (int x = 0; x < width; x++) { 98 for (int x = 0; x < width; x++) {
84 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); 99 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT);
85 } 100 }
86 return COMPUTE_RESULT_ALPHA; 101 return COMPUTE_RESULT_ALPHA;
87 } 102 }
88 103
89 static SkSwizzler::ResultAlpha swizzle_index_to_n32( 104 static SkSwizzler::ResultAlpha swizzle_index_to_n32(
90 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 105 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
91 int bytesPerPixel, int y, const SkPMColor ctable[]) { 106 int deltaSrc, int y, const SkPMColor ctable[]) {
92 107
93 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 108 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
94 INIT_RESULT_ALPHA; 109 INIT_RESULT_ALPHA;
95 for (int x = 0; x < width; x++) { 110 for (int x = 0; x < width; x++) {
96 SkPMColor c = ctable[src[x]]; 111 SkPMColor c = ctable[*src];
97 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 112 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
98 dst[x] = c; 113 dst[x] = c;
114 src += deltaSrc;
99 } 115 }
100 return COMPUTE_RESULT_ALPHA; 116 return COMPUTE_RESULT_ALPHA;
101 } 117 }
102 118
103 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( 119 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ(
104 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 120 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
105 int bytesPerPixel, int y, const SkPMColor ctable[]) { 121 int deltaSrc, int y, const SkPMColor ctable[]) {
106 122
107 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 123 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
108 INIT_RESULT_ALPHA; 124 INIT_RESULT_ALPHA;
109 for (int x = 0; x < width; x++) { 125 for (int x = 0; x < width; x++) {
110 SkPMColor c = ctable[src[x]]; 126 SkPMColor c = ctable[*src];
111 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 127 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
112 if (c != 0) { 128 if (c != 0) {
113 dst[x] = c; 129 dst[x] = c;
114 } 130 }
131 src += deltaSrc;
115 } 132 }
116 return COMPUTE_RESULT_ALPHA; 133 return COMPUTE_RESULT_ALPHA;
117 } 134 }
118 135
119 #undef A32_MASK_IN_PLACE 136 #undef A32_MASK_IN_PLACE
120 137
121 // kGray 138 // kGray
122 139
123 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( 140 static SkSwizzler::ResultAlpha swizzle_gray_to_n32(
124 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 141 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
125 int bytesPerPixel, int y, const SkPMColor ctable[]) { 142 int deltaSrc, int y, const SkPMColor ctable[]) {
126 143
127 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 144 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
128 for (int x = 0; x < width; x++) { 145 for (int x = 0; x < width; x++) {
129 dst[x] = SkPackARGB32NoCheck(0xFF, src[x], src[x], src[x]); 146 dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src);
147 src += deltaSrc;
130 } 148 }
131 return SkSwizzler::kOpaque_ResultAlpha; 149 return SkSwizzler::kOpaque_ResultAlpha;
132 } 150 }
133 151
134 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( 152 static SkSwizzler::ResultAlpha swizzle_gray_to_gray(
135 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 153 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
136 int bytesPerPixel, int y, const SkPMColor ctable[]) { 154 int deltaSrc, int y, const SkPMColor ctable[]) {
137 memcpy(dstRow, src, width); 155
156 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
157 if (1 == deltaSrc) {
158 memcpy(dstRow, src, width);
159 } else {
160 for (int x = 0; x < width; x++) {
161 dst[x] = src[0];
162 src += deltaSrc;
163 }
164 }
138 return SkSwizzler::kOpaque_ResultAlpha; 165 return SkSwizzler::kOpaque_ResultAlpha;
139 } 166 }
140 167
141 // kBGRX 168 // kBGRX
142 169
143 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( 170 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32(
144 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 171 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
145 int bytesPerPixel, int y, const SkPMColor ctable[]) { 172 int deltaSrc, int y, const SkPMColor ctable[]) {
146 173
147 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 174 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
148 for (int x = 0; x < width; x++) { 175 for (int x = 0; x < width; x++) {
149 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); 176 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]);
150 src += bytesPerPixel; 177 src += deltaSrc;
151 } 178 }
152 return SkSwizzler::kOpaque_ResultAlpha; 179 return SkSwizzler::kOpaque_ResultAlpha;
153 } 180 }
154 181
155 // kBGRA 182 // kBGRA
156 183
157 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( 184 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul(
158 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 185 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
159 int bytesPerPixel, int y, const SkPMColor ctable[]) { 186 int deltaSrc, int y, const SkPMColor ctable[]) {
160 187
161 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 188 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
162 INIT_RESULT_ALPHA; 189 INIT_RESULT_ALPHA;
163 for (int x = 0; x < width; x++) { 190 for (int x = 0; x < width; x++) {
164 uint8_t alpha = src[3]; 191 uint8_t alpha = src[3];
165 UPDATE_RESULT_ALPHA(alpha); 192 UPDATE_RESULT_ALPHA(alpha);
166 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); 193 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]);
167 src += bytesPerPixel; 194 src += deltaSrc;
168 } 195 }
169 return COMPUTE_RESULT_ALPHA; 196 return COMPUTE_RESULT_ALPHA;
170 } 197 }
171 198
172 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( 199 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul(
173 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 200 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
174 int bytesPerPixel, int y, const SkPMColor ctable[]) { 201 int deltaSrc, int y, const SkPMColor ctable[]) {
175 202
176 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 203 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
177 INIT_RESULT_ALPHA; 204 INIT_RESULT_ALPHA;
178 for (int x = 0; x < width; x++) { 205 for (int x = 0; x < width; x++) {
179 uint8_t alpha = src[3]; 206 uint8_t alpha = src[3];
180 UPDATE_RESULT_ALPHA(alpha); 207 UPDATE_RESULT_ALPHA(alpha);
181 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); 208 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]);
182 src += bytesPerPixel; 209 src += deltaSrc;
183 } 210 }
184 return COMPUTE_RESULT_ALPHA; 211 return COMPUTE_RESULT_ALPHA;
185 } 212 }
186 213
187 // n32 214 // n32
188 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( 215 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32(
189 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,
190 int bytesPerPixel, int y, const SkPMColor ctable[]) { 217 int deltaSrc, int y, const SkPMColor ctable[]) {
191 218
192 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 219 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
193 for (int x = 0; x < width; x++) { 220 for (int x = 0; x < width; x++) {
194 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); 221 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]);
195 src += bytesPerPixel; 222 src += deltaSrc;
196 } 223 }
197 return SkSwizzler::kOpaque_ResultAlpha; 224 return SkSwizzler::kOpaque_ResultAlpha;
198 } 225 }
199 226
200 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( 227 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul(
201 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 228 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
202 int bytesPerPixel, int y, const SkPMColor ctable[]) { 229 int deltaSrc, int y, const SkPMColor ctable[]) {
203 230
204 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 231 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
205 INIT_RESULT_ALPHA; 232 INIT_RESULT_ALPHA;
206 for (int x = 0; x < width; x++) { 233 for (int x = 0; x < width; x++) {
207 unsigned alpha = src[3]; 234 unsigned alpha = src[3];
208 UPDATE_RESULT_ALPHA(alpha); 235 UPDATE_RESULT_ALPHA(alpha);
209 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); 236 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]);
210 src += bytesPerPixel; 237 src += deltaSrc;
211 } 238 }
212 return COMPUTE_RESULT_ALPHA; 239 return COMPUTE_RESULT_ALPHA;
213 } 240 }
214 241
215 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( 242 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul(
216 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 243 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
217 int bytesPerPixel, int y, const SkPMColor ctable[]) { 244 int deltaSrc, int y, const SkPMColor ctable[]) {
218 245
219 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); 246 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
220 INIT_RESULT_ALPHA; 247 INIT_RESULT_ALPHA;
221 for (int x = 0; x < width; x++) { 248 for (int x = 0; x < width; x++) {
222 unsigned alpha = src[3]; 249 unsigned alpha = src[3];
223 UPDATE_RESULT_ALPHA(alpha); 250 UPDATE_RESULT_ALPHA(alpha);
224 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); 251 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]);
225 src += bytesPerPixel; 252 src += deltaSrc;
226 } 253 }
227 return COMPUTE_RESULT_ALPHA; 254 return COMPUTE_RESULT_ALPHA;
228 } 255 }
229 256
230 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( 257 static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ(
231 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 258 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
232 int bytesPerPixel, int y, const SkPMColor ctable[]) { 259 int deltaSrc, int y, const SkPMColor ctable[]) {
233 260
234 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 261 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
235 INIT_RESULT_ALPHA; 262 INIT_RESULT_ALPHA;
236 for (int x = 0; x < width; x++) { 263 for (int x = 0; x < width; x++) {
237 unsigned alpha = src[3]; 264 unsigned alpha = src[3];
238 UPDATE_RESULT_ALPHA(alpha); 265 UPDATE_RESULT_ALPHA(alpha);
239 if (0 != alpha) { 266 if (0 != alpha) {
240 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); 267 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]);
241 } 268 }
242 src += bytesPerPixel; 269 src += deltaSrc;
243 } 270 }
244 return COMPUTE_RESULT_ALPHA; 271 return COMPUTE_RESULT_ALPHA;
245 } 272 }
246 273
247 /** 274 /**
248 FIXME: This was my idea to cheat in order to continue taking advantage of sk ipping zeroes. 275 FIXME: This was my idea to cheat in order to continue taking advantage of sk ipping zeroes.
249 This would be fine for drawing normally, but not for drawing with transfer m odes. Being 276 This would be fine for drawing normally, but not for drawing with transfer m odes. Being
250 honest means we can draw correctly with transfer modes, with the cost of not being able 277 honest means we can draw correctly with transfer modes, with the cost of not being able
251 to take advantage of Android's free unwritten pages. Something to keep in mi nd when we 278 to take advantage of Android's free unwritten pages. Something to keep in mi nd when we
252 decide whether to switch to unpremul default. 279 decide whether to switch to unpremul default.
(...skipping 15 matching lines...) Expand all
268 alphaMask &= alpha; 295 alphaMask &= alpha;
269 } 296 }
270 return alphaMask != 0xFF; 297 return alphaMask != 0xFF;
271 } 298 }
272 */ 299 */
273 300
274 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, 301 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
275 const SkPMColor* ctable, 302 const SkPMColor* ctable,
276 const SkImageInfo& info, void* dst, 303 const SkImageInfo& info, void* dst,
277 size_t dstRowBytes, 304 size_t dstRowBytes,
278 SkCodec::ZeroInitialized zeroInit) { 305 SkCodec::ZeroInitialized zeroInit, int sa mpleX) {
279 if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) { 306 if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) {
280 return NULL; 307 return NULL;
281 } 308 }
282 if (info.minRowBytes() > dstRowBytes) { 309 if (info.minRowBytes() > dstRowBytes) {
283 return NULL; 310 return NULL;
284 } 311 }
285 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) 312 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc)
286 && NULL == ctable) { 313 && NULL == ctable) {
287 return NULL; 314 return NULL;
288 } 315 }
316
289 RowProc proc = NULL; 317 RowProc proc = NULL;
318
290 switch (sc) { 319 switch (sc) {
291 case kIndex1: 320 case kIndex1:
292 case kIndex2: 321 case kIndex2:
293 case kIndex4: 322 case kIndex4:
294 switch (info.colorType()) { 323 switch (info.colorType()) {
295 case kN32_SkColorType: 324 case kN32_SkColorType:
296 proc = &swizzle_small_index_to_n32; 325 proc = &swizzle_small_index_to_n32;
297 break; 326 break;
298 case kIndex_8_SkColorType: 327 case kIndex_8_SkColorType:
299 proc = &swizzle_small_index_to_index; 328 proc = &swizzle_small_index_to_index;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 break; 419 break;
391 case kRGB: 420 case kRGB:
392 switch (info.colorType()) { 421 switch (info.colorType()) {
393 case kN32_SkColorType: 422 case kN32_SkColorType:
394 proc = &swizzle_rgbx_to_n32; 423 proc = &swizzle_rgbx_to_n32;
395 break; 424 break;
396 default: 425 default:
397 break; 426 break;
398 } 427 }
399 break; 428 break;
429 case kRGB_565:
430 switch (info.colorType()) {
431 case kRGB_565_SkColorType:
432 proc = &sample;
433 break;
434 default:
435 break;
436 }
400 default: 437 default:
401 break; 438 break;
402 } 439 }
403 if (NULL == proc) { 440 if (NULL == proc) {
404 return NULL; 441 return NULL;
405 } 442 }
406 443
407 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits 444 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits
408 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : 445 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) :
409 BitsPerPixel(sc); 446 BitsPerPixel(sc);
410 return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, info, dst, 447 return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, info, dst,
411 dstRowBytes)); 448 dstRowBytes, sampleX));
412 } 449 }
413 450
414 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, 451 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable,
415 int deltaSrc, const SkImageInfo& info, void* dst, 452 int deltaSrc, const SkImageInfo& info, void* dst,
416 size_t rowBytes) 453 size_t rowBytes, int sampleX)
417 : fRowProc(proc) 454 : fRowProc(proc)
418 , fColorTable(ctable) 455 , fColorTable(ctable)
419 , fDeltaSrc(deltaSrc) 456 , fDeltaSrc(deltaSrc)
420 , fDstInfo(info) 457 , fDstInfo(info)
421 , fDstRow(dst) 458 , fDstRow(dst)
422 , fDstRowBytes(rowBytes) 459 , fDstRowBytes(rowBytes)
423 , fCurrY(0) 460 , fCurrY(0)
461 , fSampleX(sampleX)
462 , fX0(sampleX == 1 ? 0 : sampleX >> 1)
424 { 463 {
464 // check that fX0 is less than original width
465 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX);
425 SkDEBUGCODE(fNextMode = kUninitialized_NextMode); 466 SkDEBUGCODE(fNextMode = kUninitialized_NextMode);
426 } 467 }
427 468
428 SkSwizzler::ResultAlpha SkSwizzler::next(const uint8_t* SK_RESTRICT src) { 469 SkSwizzler::ResultAlpha SkSwizzler::next(const uint8_t* SK_RESTRICT src) {
429 SkASSERT(0 <= fCurrY && fCurrY < fDstInfo.height()); 470 SkASSERT(0 <= fCurrY && fCurrY < fDstInfo.height());
430 SkASSERT(fDstRow != NULL); 471 SkASSERT(fDstRow != NULL);
431 SkASSERT(kDesignateRow_NextMode != fNextMode); 472 SkASSERT(kDesignateRow_NextMode != fNextMode);
432 SkDEBUGCODE(fNextMode = kConsecutive_NextMode); 473 SkDEBUGCODE(fNextMode = kConsecutive_NextMode);
433 474
434 // Decode a row 475 // Decode a row
435 const ResultAlpha result = fRowProc(fDstRow, src, fDstInfo.width(), 476 const ResultAlpha result = fRowProc(fDstRow, src + fX0 * fDeltaSrc, fDstInf o.width(),
msarett 2015/07/30 13:55:38 nit: extra space before src
emmaleer 2015/07/30 17:50:39 Acknowledged.
436 fDeltaSrc, fCurrY, fColorTable); 477 fSampleX * fDeltaSrc, fCurrY, fColorTable);
437 478
438 // Move to the next row and return the result 479 // Move to the next row and return the result
439 fCurrY++; 480 fCurrY++;
440 fDstRow = SkTAddOffset<void>(fDstRow, fDstRowBytes); 481 fDstRow = SkTAddOffset<void>(fDstRow, fDstRowBytes);
441 return result; 482 return result;
442 } 483 }
443 484
444 SkSwizzler::ResultAlpha SkSwizzler::next(const uint8_t* SK_RESTRICT src, 485 SkSwizzler::ResultAlpha SkSwizzler::next(const uint8_t* SK_RESTRICT src,
445 int y) { 486 int y) {
446 SkASSERT(0 <= y && y < fDstInfo.height()); 487 SkASSERT(0 <= y && y < fDstInfo.height());
447 SkASSERT(kConsecutive_NextMode != fNextMode); 488 SkASSERT(kConsecutive_NextMode != fNextMode);
448 SkDEBUGCODE(fNextMode = kDesignateRow_NextMode); 489 SkDEBUGCODE(fNextMode = kDesignateRow_NextMode);
449 490
450 // Choose the row 491 // Choose the row
451 void* row = SkTAddOffset<void>(fDstRow, y*fDstRowBytes); 492 void* row = SkTAddOffset<void>(fDstRow, y*fDstRowBytes);
452 493
453 // Decode the row 494 // Decode the row
454 return fRowProc(row, src, fDstInfo.width(), fDeltaSrc, fCurrY, 495 return fRowProc(row, src + fX0 * fDeltaSrc, fDstInfo.width(), fSampleX * fDe ltaSrc, fCurrY,
455 fColorTable); 496 fColorTable);
456 } 497 }
457 498
458 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes, 499 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes,
459 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { 500 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) {
460 SkASSERT(dstStartRow != NULL); 501 SkASSERT(dstStartRow != NULL);
461 SkASSERT(numRows <= (uint32_t) dstInfo.height()); 502 SkASSERT(numRows <= (uint32_t) dstInfo.height());
462 503
463 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. 504 // 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); 505 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 break; 540 break;
500 case kGray_8_SkColorType: 541 case kGray_8_SkColorType:
501 // If the destination is kGray, the caller passes in an 8-bit color. 542 // If the destination is kGray, the caller passes in an 8-bit color.
502 // We will not assert that the high bits of colorOrIndex must be zer oed. 543 // We will not assert that the high bits of colorOrIndex must be zer oed.
503 // This allows us to take advantage of the fact that the low 8 bits of an 544 // This allows us to take advantage of the fact that the low 8 bits of an
504 // SKPMColor may be a valid a grayscale color. For example, the low 8 545 // SKPMColor may be a valid a grayscale color. For example, the low 8
505 // bits of SK_ColorBLACK are identical to the grayscale representati on 546 // bits of SK_ColorBLACK are identical to the grayscale representati on
506 // for black. 547 // for black.
507 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill); 548 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill);
508 break; 549 break;
550
msarett 2015/07/30 13:55:38 nit: extra new line Also, you might want to try r
emmaleer 2015/07/30 17:50:39 Acknowledged.
scroggo 2015/07/30 17:53:01 Just as a general piece of advice, I find it usefu
509 default: 551 default:
510 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); 552 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
511 SkASSERT(false); 553 SkASSERT(false);
512 break; 554 break;
513 } 555 }
514 } 556 }
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