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/images/SkScaledBitmapSampler.cpp

Issue 321873003: Add sampler options to SkScaledBitmapSampler (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Simply SamplerOptions -> Options Created 6 years, 6 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/images/SkScaledBitmapSampler.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 2007 The Android Open Source Project 2 * Copyright 2007 The Android Open Source Project
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 8
9 #include "SkScaledBitmapSampler.h" 9 #include "SkScaledBitmapSampler.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkDither.h" 12 #include "SkDither.h"
13 #include "SkTypes.h" 13 #include "SkTypes.h"
14 14
15 // 8888 15 // 8888
16 16
17 static bool Sample_Gray_D8888(void* SK_RESTRICT dstRow, 17 static bool Sample_Gray_D8888(void* SK_RESTRICT dstRow,
18 const uint8_t* SK_RESTRICT src, 18 const uint8_t* SK_RESTRICT src,
19 int width, int deltaSrc, int, const SkPMColor[]) { 19 int width, int deltaSrc, int, const SkPMColor[]) {
20 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 20 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
21 for (int x = 0; x < width; x++) { 21 for (int x = 0; x < width; x++) {
22 dst[x] = SkPackARGB32(0xFF, src[0], src[0], src[0]); 22 dst[x] = SkPackARGB32(0xFF, src[0], src[0], src[0]);
23 src += deltaSrc; 23 src += deltaSrc;
24 } 24 }
25 return false; 25 return false;
26 } 26 }
27 27
28 static SkScaledBitmapSampler::RowProc get_gray_to_8888_proc(const SkImageDecoder & decoder) { 28 static SkScaledBitmapSampler::RowProc
29 get_gray_to_8888_proc(const SkScaledBitmapSampler::Options& opts) {
29 // Dither, unpremul, and skipZeroes have no effect 30 // Dither, unpremul, and skipZeroes have no effect
30 return Sample_Gray_D8888; 31 return Sample_Gray_D8888;
31 } 32 }
32 33
33 static bool Sample_RGBx_D8888(void* SK_RESTRICT dstRow, 34 static bool Sample_RGBx_D8888(void* SK_RESTRICT dstRow,
34 const uint8_t* SK_RESTRICT src, 35 const uint8_t* SK_RESTRICT src,
35 int width, int deltaSrc, int, const SkPMColor[]) { 36 int width, int deltaSrc, int, const SkPMColor[]) {
36 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 37 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
37 for (int x = 0; x < width; x++) { 38 for (int x = 0; x < width; x++) {
38 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); 39 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]);
39 src += deltaSrc; 40 src += deltaSrc;
40 } 41 }
41 return false; 42 return false;
42 } 43 }
43 44
44 static SkScaledBitmapSampler::RowProc get_RGBx_to_8888_proc(const SkImageDecoder & decoder) { 45 static SkScaledBitmapSampler::RowProc
46 get_RGBx_to_8888_proc(const SkScaledBitmapSampler::Options& opts) {
45 // Dither, unpremul, and skipZeroes have no effect 47 // Dither, unpremul, and skipZeroes have no effect
46 return Sample_RGBx_D8888; 48 return Sample_RGBx_D8888;
47 } 49 }
48 50
49 static bool Sample_RGBA_D8888(void* SK_RESTRICT dstRow, 51 static bool Sample_RGBA_D8888(void* SK_RESTRICT dstRow,
50 const uint8_t* SK_RESTRICT src, 52 const uint8_t* SK_RESTRICT src,
51 int width, int deltaSrc, int, const SkPMColor[]) { 53 int width, int deltaSrc, int, const SkPMColor[]) {
52 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 54 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
53 unsigned alphaMask = 0xFF; 55 unsigned alphaMask = 0xFF;
54 for (int x = 0; x < width; x++) { 56 for (int x = 0; x < width; x++) {
(...skipping 30 matching lines...) Expand all
85 unsigned alpha = src[3]; 87 unsigned alpha = src[3];
86 if (0 != alpha) { 88 if (0 != alpha) {
87 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); 89 dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]);
88 } 90 }
89 src += deltaSrc; 91 src += deltaSrc;
90 alphaMask &= alpha; 92 alphaMask &= alpha;
91 } 93 }
92 return alphaMask != 0xFF; 94 return alphaMask != 0xFF;
93 } 95 }
94 96
95 static SkScaledBitmapSampler::RowProc get_RGBA_to_8888_proc(const SkImageDecoder & decoder) { 97 static SkScaledBitmapSampler::RowProc
98 get_RGBA_to_8888_proc(const SkScaledBitmapSampler::Options& opts) {
96 // Dither has no effect. 99 // Dither has no effect.
97 if (decoder.getRequireUnpremultipliedColors()) { 100 if (!opts.fPremultiplyAlpha) {
98 // We could check each component for a zero, at the expense of extra che cks. 101 // We could check each component for a zero, at the expense of extra che cks.
99 // For now, just return unpremul. 102 // For now, just return unpremul.
100 return Sample_RGBA_D8888_Unpremul; 103 return Sample_RGBA_D8888_Unpremul;
101 } 104 }
102 // Supply the versions that premultiply the colors 105 // Supply the versions that premultiply the colors
103 if (decoder.getSkipWritingZeroes()) { 106 if (opts.fSkipZeros) {
104 return Sample_RGBA_D8888_SkipZ; 107 return Sample_RGBA_D8888_SkipZ;
105 } 108 }
106 return Sample_RGBA_D8888; 109 return Sample_RGBA_D8888;
107 } 110 }
108 111
109 // 565 112 // 565
110 113
111 static bool Sample_Gray_D565(void* SK_RESTRICT dstRow, 114 static bool Sample_Gray_D565(void* SK_RESTRICT dstRow,
112 const uint8_t* SK_RESTRICT src, 115 const uint8_t* SK_RESTRICT src,
113 int width, int deltaSrc, int, const SkPMColor[]) { 116 int width, int deltaSrc, int, const SkPMColor[]) {
(...skipping 10 matching lines...) Expand all
124 int width, int deltaSrc, int y, const SkPMColor[]) { 127 int width, int deltaSrc, int y, const SkPMColor[]) {
125 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 128 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
126 DITHER_565_SCAN(y); 129 DITHER_565_SCAN(y);
127 for (int x = 0; x < width; x++) { 130 for (int x = 0; x < width; x++) {
128 dst[x] = SkDitherRGBTo565(src[0], src[0], src[0], DITHER_VALUE(x)); 131 dst[x] = SkDitherRGBTo565(src[0], src[0], src[0], DITHER_VALUE(x));
129 src += deltaSrc; 132 src += deltaSrc;
130 } 133 }
131 return false; 134 return false;
132 } 135 }
133 136
134 static SkScaledBitmapSampler::RowProc get_gray_to_565_proc(const SkImageDecoder& decoder) { 137 static SkScaledBitmapSampler::RowProc
138 get_gray_to_565_proc(const SkScaledBitmapSampler::Options& opts) {
135 // Unpremul and skip zeroes make no difference 139 // Unpremul and skip zeroes make no difference
136 if (decoder.getDitherImage()) { 140 if (opts.fDither) {
137 return Sample_Gray_D565_D; 141 return Sample_Gray_D565_D;
138 } 142 }
139 return Sample_Gray_D565; 143 return Sample_Gray_D565;
140 } 144 }
141 145
142 static bool Sample_RGBx_D565(void* SK_RESTRICT dstRow, 146 static bool Sample_RGBx_D565(void* SK_RESTRICT dstRow,
143 const uint8_t* SK_RESTRICT src, 147 const uint8_t* SK_RESTRICT src,
144 int width, int deltaSrc, int, const SkPMColor[]) { 148 int width, int deltaSrc, int, const SkPMColor[]) {
145 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 149 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
146 for (int x = 0; x < width; x++) { 150 for (int x = 0; x < width; x++) {
147 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); 151 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]);
148 src += deltaSrc; 152 src += deltaSrc;
149 } 153 }
150 return false; 154 return false;
151 } 155 }
152 156
153 static bool Sample_RGBx_D565_D(void* SK_RESTRICT dstRow, 157 static bool Sample_RGBx_D565_D(void* SK_RESTRICT dstRow,
154 const uint8_t* SK_RESTRICT src, 158 const uint8_t* SK_RESTRICT src,
155 int width, int deltaSrc, int y, 159 int width, int deltaSrc, int y,
156 const SkPMColor[]) { 160 const SkPMColor[]) {
157 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 161 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
158 DITHER_565_SCAN(y); 162 DITHER_565_SCAN(y);
159 for (int x = 0; x < width; x++) { 163 for (int x = 0; x < width; x++) {
160 dst[x] = SkDitherRGBTo565(src[0], src[1], src[2], DITHER_VALUE(x)); 164 dst[x] = SkDitherRGBTo565(src[0], src[1], src[2], DITHER_VALUE(x));
161 src += deltaSrc; 165 src += deltaSrc;
162 } 166 }
163 return false; 167 return false;
164 } 168 }
165 169
166 static SkScaledBitmapSampler::RowProc get_RGBx_to_565_proc(const SkImageDecoder& decoder) { 170 static SkScaledBitmapSampler::RowProc
171 get_RGBx_to_565_proc(const SkScaledBitmapSampler::Options& opts) {
167 // Unpremul and skip zeroes make no difference 172 // Unpremul and skip zeroes make no difference
168 if (decoder.getDitherImage()) { 173 if (opts.fDither) {
169 return Sample_RGBx_D565_D; 174 return Sample_RGBx_D565_D;
170 } 175 }
171 return Sample_RGBx_D565; 176 return Sample_RGBx_D565;
172 } 177 }
173 178
174 179
175 static bool Sample_D565_D565(void* SK_RESTRICT dstRow, 180 static bool Sample_D565_D565(void* SK_RESTRICT dstRow,
176 const uint8_t* SK_RESTRICT src, 181 const uint8_t* SK_RESTRICT src,
177 int width, int deltaSrc, int, const SkPMColor[]) { 182 int width, int deltaSrc, int, const SkPMColor[]) {
178 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 183 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
179 uint16_t* SK_RESTRICT castedSrc = (uint16_t*) src; 184 uint16_t* SK_RESTRICT castedSrc = (uint16_t*) src;
180 for (int x = 0; x < width; x++) { 185 for (int x = 0; x < width; x++) {
181 dst[x] = castedSrc[0]; 186 dst[x] = castedSrc[0];
182 castedSrc += deltaSrc >> 1; 187 castedSrc += deltaSrc >> 1;
183 } 188 }
184 return false; 189 return false;
185 } 190 }
186 191
187 static SkScaledBitmapSampler::RowProc get_565_to_565_proc(const SkImageDecoder& decoder) { 192 static SkScaledBitmapSampler::RowProc
193 get_565_to_565_proc(const SkScaledBitmapSampler::Options& opts) {
188 // Unpremul, dither, and skip zeroes have no effect 194 // Unpremul, dither, and skip zeroes have no effect
189 return Sample_D565_D565; 195 return Sample_D565_D565;
190 } 196 }
191 197
192 // 4444 198 // 4444
193 199
194 static bool Sample_Gray_D4444(void* SK_RESTRICT dstRow, 200 static bool Sample_Gray_D4444(void* SK_RESTRICT dstRow,
195 const uint8_t* SK_RESTRICT src, 201 const uint8_t* SK_RESTRICT src,
196 int width, int deltaSrc, int, const SkPMColor[]) { 202 int width, int deltaSrc, int, const SkPMColor[]) {
197 SkPMColor16* SK_RESTRICT dst = (SkPMColor16*)dstRow; 203 SkPMColor16* SK_RESTRICT dst = (SkPMColor16*)dstRow;
(...skipping 11 matching lines...) Expand all
209 SkPMColor16* SK_RESTRICT dst = (SkPMColor16*)dstRow; 215 SkPMColor16* SK_RESTRICT dst = (SkPMColor16*)dstRow;
210 DITHER_4444_SCAN(y); 216 DITHER_4444_SCAN(y);
211 for (int x = 0; x < width; x++) { 217 for (int x = 0; x < width; x++) {
212 dst[x] = SkDitherARGB32To4444(0xFF, src[0], src[0], src[0], 218 dst[x] = SkDitherARGB32To4444(0xFF, src[0], src[0], src[0],
213 DITHER_VALUE(x)); 219 DITHER_VALUE(x));
214 src += deltaSrc; 220 src += deltaSrc;
215 } 221 }
216 return false; 222 return false;
217 } 223 }
218 224
219 static SkScaledBitmapSampler::RowProc get_gray_to_4444_proc(const SkImageDecoder & decoder) { 225 static SkScaledBitmapSampler::RowProc
226 get_gray_to_4444_proc(const SkScaledBitmapSampler::Options& opts) {
220 // Skip zeroes and unpremul make no difference 227 // Skip zeroes and unpremul make no difference
221 if (decoder.getDitherImage()) { 228 if (opts.fDither) {
222 return Sample_Gray_D4444_D; 229 return Sample_Gray_D4444_D;
223 } 230 }
224 return Sample_Gray_D4444; 231 return Sample_Gray_D4444;
225 } 232 }
226 233
227 static bool Sample_RGBx_D4444(void* SK_RESTRICT dstRow, 234 static bool Sample_RGBx_D4444(void* SK_RESTRICT dstRow,
228 const uint8_t* SK_RESTRICT src, 235 const uint8_t* SK_RESTRICT src,
229 int width, int deltaSrc, int, const SkPMColor[]) { 236 int width, int deltaSrc, int, const SkPMColor[]) {
230 SkPMColor16* SK_RESTRICT dst = (SkPMColor16*)dstRow; 237 SkPMColor16* SK_RESTRICT dst = (SkPMColor16*)dstRow;
231 for (int x = 0; x < width; x++) { 238 for (int x = 0; x < width; x++) {
(...skipping 10 matching lines...) Expand all
242 DITHER_4444_SCAN(y); 249 DITHER_4444_SCAN(y);
243 250
244 for (int x = 0; x < width; x++) { 251 for (int x = 0; x < width; x++) {
245 dst[x] = SkDitherARGB32To4444(0xFF, src[0], src[1], src[2], 252 dst[x] = SkDitherARGB32To4444(0xFF, src[0], src[1], src[2],
246 DITHER_VALUE(x)); 253 DITHER_VALUE(x));
247 src += deltaSrc; 254 src += deltaSrc;
248 } 255 }
249 return false; 256 return false;
250 } 257 }
251 258
252 static SkScaledBitmapSampler::RowProc get_RGBx_to_4444_proc(const SkImageDecoder & decoder) { 259 static SkScaledBitmapSampler::RowProc
260 get_RGBx_to_4444_proc(const SkScaledBitmapSampler::Options& opts) {
253 // Skip zeroes and unpremul make no difference 261 // Skip zeroes and unpremul make no difference
254 if (decoder.getDitherImage()) { 262 if (opts.fDither) {
255 return Sample_RGBx_D4444_D; 263 return Sample_RGBx_D4444_D;
256 } 264 }
257 return Sample_RGBx_D4444; 265 return Sample_RGBx_D4444;
258 } 266 }
259 267
260 static bool Sample_RGBA_D4444(void* SK_RESTRICT dstRow, 268 static bool Sample_RGBA_D4444(void* SK_RESTRICT dstRow,
261 const uint8_t* SK_RESTRICT src, 269 const uint8_t* SK_RESTRICT src,
262 int width, int deltaSrc, int, const SkPMColor[]) { 270 int width, int deltaSrc, int, const SkPMColor[]) {
263 SkPMColor16* SK_RESTRICT dst = (SkPMColor16*)dstRow; 271 SkPMColor16* SK_RESTRICT dst = (SkPMColor16*)dstRow;
264 unsigned alphaMask = 0xFF; 272 unsigned alphaMask = 0xFF;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 if (alpha != 0) { 332 if (alpha != 0) {
325 SkPMColor c = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); 333 SkPMColor c = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]);
326 dst[x] = SkDitherARGB32To4444(c, DITHER_VALUE(x)); 334 dst[x] = SkDitherARGB32To4444(c, DITHER_VALUE(x));
327 } 335 }
328 src += deltaSrc; 336 src += deltaSrc;
329 alphaMask &= alpha; 337 alphaMask &= alpha;
330 } 338 }
331 return alphaMask != 0xFF; 339 return alphaMask != 0xFF;
332 } 340 }
333 341
334 static SkScaledBitmapSampler::RowProc get_RGBA_to_4444_proc(const SkImageDecoder & decoder) { 342 static SkScaledBitmapSampler::RowProc
335 if (decoder.getRequireUnpremultipliedColors()) { 343 get_RGBA_to_4444_proc(const SkScaledBitmapSampler::Options& opts) {
344 if (!opts.fPremultiplyAlpha) {
336 // Unpremultiplied is not supported for 4444 345 // Unpremultiplied is not supported for 4444
337 return NULL; 346 return NULL;
338 } 347 }
339 const bool dither = decoder.getDitherImage(); 348 if (opts.fSkipZeros) {
340 if (decoder.getSkipWritingZeroes()) { 349 if (opts.fDither) {
341 if (dither) {
342 return Sample_RGBA_D4444_D_SkipZ; 350 return Sample_RGBA_D4444_D_SkipZ;
343 } 351 }
344 return Sample_RGBA_D4444_SkipZ; 352 return Sample_RGBA_D4444_SkipZ;
345 } 353 }
346 if (dither) { 354 if (opts.fDither) {
347 return Sample_RGBA_D4444_D; 355 return Sample_RGBA_D4444_D;
348 } 356 }
349 return Sample_RGBA_D4444; 357 return Sample_RGBA_D4444;
350 } 358 }
351 359
352 // Index 360 // Index
353 361
354 #define A32_MASK_IN_PLACE (SkPMColor)(SK_A32_MASK << SK_A32_SHIFT) 362 #define A32_MASK_IN_PLACE (SkPMColor)(SK_A32_MASK << SK_A32_SHIFT)
355 363
356 static bool Sample_Index_D8888(void* SK_RESTRICT dstRow, 364 static bool Sample_Index_D8888(void* SK_RESTRICT dstRow,
(...skipping 22 matching lines...) Expand all
379 SkPMColor c = ctable[*src]; 387 SkPMColor c = ctable[*src];
380 cc &= c; 388 cc &= c;
381 if (c != 0) { 389 if (c != 0) {
382 dst[x] = c; 390 dst[x] = c;
383 } 391 }
384 src += deltaSrc; 392 src += deltaSrc;
385 } 393 }
386 return cc != A32_MASK_IN_PLACE; 394 return cc != A32_MASK_IN_PLACE;
387 } 395 }
388 396
389 static SkScaledBitmapSampler::RowProc get_index_to_8888_proc(const SkImageDecode r& decoder) { 397 static SkScaledBitmapSampler::RowProc
390 if (decoder.getRequireUnpremultipliedColors()) { 398 get_index_to_8888_proc(const SkScaledBitmapSampler::Options& opts) {
399 if (!opts.fPremultiplyAlpha) {
391 // Unpremultiplied is not supported for an index source. 400 // Unpremultiplied is not supported for an index source.
392 return NULL; 401 return NULL;
393 } 402 }
394 // Dither makes no difference 403 // Dither makes no difference
395 if (decoder.getSkipWritingZeroes()) { 404 if (opts.fSkipZeros) {
396 return Sample_Index_D8888_SkipZ; 405 return Sample_Index_D8888_SkipZ;
397 } 406 }
398 return Sample_Index_D8888; 407 return Sample_Index_D8888;
399 } 408 }
400 409
401 static bool Sample_Index_D565(void* SK_RESTRICT dstRow, 410 static bool Sample_Index_D565(void* SK_RESTRICT dstRow,
402 const uint8_t* SK_RESTRICT src, 411 const uint8_t* SK_RESTRICT src,
403 int width, int deltaSrc, int, const SkPMColor ctable[]) { 412 int width, int deltaSrc, int, const SkPMColor ctable[]) {
404 413
405 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 414 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
(...skipping 13 matching lines...) Expand all
419 428
420 for (int x = 0; x < width; x++) { 429 for (int x = 0; x < width; x++) {
421 SkPMColor c = ctable[*src]; 430 SkPMColor c = ctable[*src];
422 dst[x] = SkDitherRGBTo565(SkGetPackedR32(c), SkGetPackedG32(c), 431 dst[x] = SkDitherRGBTo565(SkGetPackedR32(c), SkGetPackedG32(c),
423 SkGetPackedB32(c), DITHER_VALUE(x)); 432 SkGetPackedB32(c), DITHER_VALUE(x));
424 src += deltaSrc; 433 src += deltaSrc;
425 } 434 }
426 return false; 435 return false;
427 } 436 }
428 437
429 static SkScaledBitmapSampler::RowProc get_index_to_565_proc(const SkImageDecoder & decoder) { 438 static SkScaledBitmapSampler::RowProc
439 get_index_to_565_proc(const SkScaledBitmapSampler::Options& opts) {
430 // Unpremultiplied and skip zeroes make no difference 440 // Unpremultiplied and skip zeroes make no difference
431 if (decoder.getDitherImage()) { 441 if (opts.fDither) {
432 return Sample_Index_D565_D; 442 return Sample_Index_D565_D;
433 } 443 }
434 return Sample_Index_D565; 444 return Sample_Index_D565;
435 } 445 }
436 446
437 static bool Sample_Index_D4444(void* SK_RESTRICT dstRow, 447 static bool Sample_Index_D4444(void* SK_RESTRICT dstRow,
438 const uint8_t* SK_RESTRICT src, int width, 448 const uint8_t* SK_RESTRICT src, int width,
439 int deltaSrc, int y, const SkPMColor ctable[]) { 449 int deltaSrc, int y, const SkPMColor ctable[]) {
440 450
441 SkPMColor16* SK_RESTRICT dst = (SkPMColor16*)dstRow; 451 SkPMColor16* SK_RESTRICT dst = (SkPMColor16*)dstRow;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 SkPMColor c = ctable[*src]; 505 SkPMColor c = ctable[*src];
496 cc &= c; 506 cc &= c;
497 if (c != 0) { 507 if (c != 0) {
498 dst[x] = SkDitherARGB32To4444(c, DITHER_VALUE(x)); 508 dst[x] = SkDitherARGB32To4444(c, DITHER_VALUE(x));
499 } 509 }
500 src += deltaSrc; 510 src += deltaSrc;
501 } 511 }
502 return cc != A32_MASK_IN_PLACE; 512 return cc != A32_MASK_IN_PLACE;
503 } 513 }
504 514
505 static SkScaledBitmapSampler::RowProc get_index_to_4444_proc(const SkImageDecode r& decoder) { 515 static SkScaledBitmapSampler::RowProc
516 get_index_to_4444_proc(const SkScaledBitmapSampler::Options& opts) {
506 // Unpremul not allowed 517 // Unpremul not allowed
507 if (decoder.getRequireUnpremultipliedColors()) { 518 if (!opts.fPremultiplyAlpha) {
508 return NULL; 519 return NULL;
509 } 520 }
510 const bool dither = decoder.getDitherImage(); 521 if (opts.fSkipZeros) {
511 if (decoder.getSkipWritingZeroes()) { 522 if (opts.fDither) {
512 if (dither) {
513 return Sample_Index_D4444_D_SkipZ; 523 return Sample_Index_D4444_D_SkipZ;
514 } 524 }
515 return Sample_Index_D4444_SkipZ; 525 return Sample_Index_D4444_SkipZ;
516 } 526 }
517 if (dither) { 527 if (opts.fDither) {
518 return Sample_Index_D4444_D; 528 return Sample_Index_D4444_D;
519 } 529 }
520 return Sample_Index_D4444; 530 return Sample_Index_D4444;
521 } 531 }
522 532
523 static bool Sample_Index_DI(void* SK_RESTRICT dstRow, 533 static bool Sample_Index_DI(void* SK_RESTRICT dstRow,
524 const uint8_t* SK_RESTRICT src, 534 const uint8_t* SK_RESTRICT src,
525 int width, int deltaSrc, int, const SkPMColor[]) { 535 int width, int deltaSrc, int, const SkPMColor[]) {
526 if (1 == deltaSrc) { 536 if (1 == deltaSrc) {
527 memcpy(dstRow, src, width); 537 memcpy(dstRow, src, width);
528 } else { 538 } else {
529 uint8_t* SK_RESTRICT dst = (uint8_t*)dstRow; 539 uint8_t* SK_RESTRICT dst = (uint8_t*)dstRow;
530 for (int x = 0; x < width; x++) { 540 for (int x = 0; x < width; x++) {
531 dst[x] = src[0]; 541 dst[x] = src[0];
532 src += deltaSrc; 542 src += deltaSrc;
533 } 543 }
534 } 544 }
535 return false; 545 return false;
536 } 546 }
537 547
538 static SkScaledBitmapSampler::RowProc get_index_to_index_proc(const SkImageDecod er& decoder) { 548 static SkScaledBitmapSampler::RowProc
549 get_index_to_index_proc(const SkScaledBitmapSampler::Options& opts) {
539 // Unpremul not allowed 550 // Unpremul not allowed
540 if (decoder.getRequireUnpremultipliedColors()) { 551 if (!opts.fPremultiplyAlpha) {
541 return NULL; 552 return NULL;
542 } 553 }
543 // Ignore dither and skip zeroes 554 // Ignore dither and skip zeroes
544 return Sample_Index_DI; 555 return Sample_Index_DI;
545 } 556 }
546 557
547 // A8 558 // A8
548 static bool Sample_Gray_DA8(void* SK_RESTRICT dstRow, 559 static bool Sample_Gray_DA8(void* SK_RESTRICT dstRow,
549 const uint8_t* SK_RESTRICT src, 560 const uint8_t* SK_RESTRICT src,
550 int width, int deltaSrc, int, 561 int width, int deltaSrc, int,
551 const SkPMColor[]) { 562 const SkPMColor[]) {
552 // Sampling Gray to A8 uses the same function as Index to Index8, 563 // Sampling Gray to A8 uses the same function as Index to Index8,
553 // except we assume that there is alpha for speed, since an A8 564 // except we assume that there is alpha for speed, since an A8
554 // bitmap with no alpha is not interesting. 565 // bitmap with no alpha is not interesting.
555 (void) Sample_Index_DI(dstRow, src, width, deltaSrc, /* y unused */ 0, 566 (void) Sample_Index_DI(dstRow, src, width, deltaSrc, /* y unused */ 0,
556 /* ctable unused */ NULL); 567 /* ctable unused */ NULL);
557 return true; 568 return true;
558 } 569 }
559 570
560 static SkScaledBitmapSampler::RowProc get_gray_to_A8_proc(const SkImageDecoder& decoder) { 571 static SkScaledBitmapSampler::RowProc
561 if (decoder.getRequireUnpremultipliedColors()) { 572 get_gray_to_A8_proc(const SkScaledBitmapSampler::Options& opts) {
573 if (!opts.fPremultiplyAlpha) {
562 return NULL; 574 return NULL;
563 } 575 }
564 // Ignore skip and dither. 576 // Ignore skip and dither.
565 return Sample_Gray_DA8; 577 return Sample_Gray_DA8;
566 } 578 }
567 579
568 typedef SkScaledBitmapSampler::RowProc (*RowProcChooser)(const SkImageDecoder& d ecoder); 580 typedef SkScaledBitmapSampler::RowProc (*RowProcChooser)(const SkScaledBitmapSam pler::Options&);
569 /////////////////////////////////////////////////////////////////////////////// 581 ///////////////////////////////////////////////////////////////////////////////
570 582
571 #include "SkScaledBitmapSampler.h" 583 #include "SkScaledBitmapSampler.h"
572 584
573 SkScaledBitmapSampler::SkScaledBitmapSampler(int width, int height, 585 SkScaledBitmapSampler::SkScaledBitmapSampler(int width, int height,
574 int sampleSize) { 586 int sampleSize) {
575 fCTable = NULL; 587 fCTable = NULL;
576 fDstRow = NULL; 588 fDstRow = NULL;
577 fRowProc = NULL; 589 fRowProc = NULL;
578 590
(...skipping 27 matching lines...) Expand all
606 SkASSERT(fY0 >= 0 && fY0 < height); 618 SkASSERT(fY0 >= 0 && fY0 < height);
607 619
608 fDX = dx; 620 fDX = dx;
609 fDY = dy; 621 fDY = dy;
610 622
611 SkASSERT(fDX > 0 && (fX0 + fDX * (fScaledWidth - 1)) < width); 623 SkASSERT(fDX > 0 && (fX0 + fDX * (fScaledWidth - 1)) < width);
612 SkASSERT(fDY > 0 && (fY0 + fDY * (fScaledHeight - 1)) < height); 624 SkASSERT(fDY > 0 && (fY0 + fDY * (fScaledHeight - 1)) < height);
613 } 625 }
614 626
615 bool SkScaledBitmapSampler::begin(SkBitmap* dst, SrcConfig sc, 627 bool SkScaledBitmapSampler::begin(SkBitmap* dst, SrcConfig sc,
616 const SkImageDecoder& decoder, 628 const Options& opts,
617 const SkPMColor ctable[]) { 629 const SkPMColor ctable[]) {
618 static const RowProcChooser gProcChoosers[] = { 630 static const RowProcChooser gProcChoosers[] = {
619 get_gray_to_8888_proc, 631 get_gray_to_8888_proc,
620 get_RGBx_to_8888_proc, 632 get_RGBx_to_8888_proc,
621 get_RGBA_to_8888_proc, 633 get_RGBA_to_8888_proc,
622 get_index_to_8888_proc, 634 get_index_to_8888_proc,
623 NULL, // 565 to 8888 635 NULL, // 565 to 8888
624 636
625 get_gray_to_565_proc, 637 get_gray_to_565_proc,
626 get_RGBx_to_565_proc, 638 get_RGBx_to_565_proc,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 index += 4 * gProcDstConfigSpan; 713 index += 4 * gProcDstConfigSpan;
702 break; 714 break;
703 default: 715 default:
704 return false; 716 return false;
705 } 717 }
706 718
707 RowProcChooser chooser = gProcChoosers[index]; 719 RowProcChooser chooser = gProcChoosers[index];
708 if (NULL == chooser) { 720 if (NULL == chooser) {
709 fRowProc = NULL; 721 fRowProc = NULL;
710 } else { 722 } else {
711 fRowProc = chooser(decoder); 723 fRowProc = chooser(opts);
712 } 724 }
713 fDstRow = (char*)dst->getPixels(); 725 fDstRow = (char*)dst->getPixels();
714 fDstRowBytes = dst->rowBytes(); 726 fDstRowBytes = dst->rowBytes();
715 fCurrY = 0; 727 fCurrY = 0;
716 return fRowProc != NULL; 728 return fRowProc != NULL;
717 } 729 }
718 730
731 bool SkScaledBitmapSampler::begin(SkBitmap* dst, SrcConfig sc,
732 const SkImageDecoder& decoder,
733 const SkPMColor ctable[]) {
734 return this->begin(dst, sc, Options(decoder), ctable);
735 }
736
719 bool SkScaledBitmapSampler::next(const uint8_t* SK_RESTRICT src) { 737 bool SkScaledBitmapSampler::next(const uint8_t* SK_RESTRICT src) {
720 SkASSERT(kInterlaced_SampleMode != fSampleMode); 738 SkASSERT(kInterlaced_SampleMode != fSampleMode);
721 SkDEBUGCODE(fSampleMode = kConsecutive_SampleMode); 739 SkDEBUGCODE(fSampleMode = kConsecutive_SampleMode);
722 SkASSERT((unsigned)fCurrY < (unsigned)fScaledHeight); 740 SkASSERT((unsigned)fCurrY < (unsigned)fScaledHeight);
723 741
724 bool hadAlpha = fRowProc(fDstRow, src + fX0 * fSrcPixelSize, fScaledWidth, 742 bool hadAlpha = fRowProc(fDstRow, src + fX0 * fSrcPixelSize, fScaledWidth,
725 fDX * fSrcPixelSize, fCurrY, fCTable); 743 fDX * fSrcPixelSize, fCurrY, fCTable);
726 fDstRow += fDstRowBytes; 744 fDstRow += fDstRowBytes;
727 fCurrY += 1; 745 fCurrY += 1;
728 return hadAlpha; 746 return hadAlpha;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 SkScaledBitmapSampler::RowProc actual = RowProcTester::getRo wProc(sampler); 861 SkScaledBitmapSampler::RowProc actual = RowProcTester::getRo wProc(sampler);
844 SkASSERT(expected == actual); 862 SkASSERT(expected == actual);
845 procCounter++; 863 procCounter++;
846 } 864 }
847 } 865 }
848 } 866 }
849 } 867 }
850 SkASSERT(SK_ARRAY_COUNT(gTestProcs) == procCounter); 868 SkASSERT(SK_ARRAY_COUNT(gTestProcs) == procCounter);
851 } 869 }
852 #endif // SK_DEBUG 870 #endif // SK_DEBUG
OLDNEW
« no previous file with comments | « src/images/SkScaledBitmapSampler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698