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

Side by Side Diff: src/images/SkScaledBitmapSampler.cpp

Issue 16410009: Add an option to create unpremultiplied bitmaps. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix for andriod only code. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/images/SkScaledBitmapSampler.h ('k') | src/ports/SkImageDecoder_WIC.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1
2 /* 1 /*
3 * Copyright 2007 The Android Open Source Project 2 * Copyright 2007 The Android Open Source Project
4 * 3 *
5 * 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
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 7
9 8
10 #include "SkScaledBitmapSampler.h" 9 #include "SkScaledBitmapSampler.h"
11 #include "SkBitmap.h" 10 #include "SkBitmap.h"
12 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
13 #include "SkDither.h" 12 #include "SkDither.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;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } else { 282 } else {
283 uint8_t* SK_RESTRICT dst = (uint8_t*)dstRow; 283 uint8_t* SK_RESTRICT dst = (uint8_t*)dstRow;
284 for (int x = 0; x < width; x++) { 284 for (int x = 0; x < width; x++) {
285 dst[x] = src[0]; 285 dst[x] = src[0];
286 src += deltaSrc; 286 src += deltaSrc;
287 } 287 }
288 } 288 }
289 return false; 289 return false;
290 } 290 }
291 291
292 // 8888 Unpremul
293
294 static bool Sample_Gray_D8888_Unpremul(void* SK_RESTRICT dstRow,
295 const uint8_t* SK_RESTRICT src,
296 int width, int deltaSrc, int,
297 const SkPMColor[]) {
298 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
299 for (int x = 0; x < width; x++) {
300 dst[x] = SkPackARGB32NoCheck(0xFF, src[0], src[0], src[0]);
301 src += deltaSrc;
302 }
303 return false;
304 }
305
306 // Sample_RGBx_D8888_Unpremul is no different from Sample_RGBx_D8888, since alph a
307 // is 0xFF
308
309 static bool Sample_RGBA_D8888_Unpremul(void* SK_RESTRICT dstRow,
310 const uint8_t* SK_RESTRICT src,
311 int width, int deltaSrc, int,
312 const SkPMColor[]) {
313 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
314 unsigned alphaMask = 0xFF;
315 for (int x = 0; x < width; x++) {
316 unsigned alpha = src[3];
317 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]);
318 src += deltaSrc;
319 alphaMask &= alpha;
320 }
321 return alphaMask != 0xFF;
322 }
323
324 // Sample_Index_D8888_Unpremul is the same as Sample_Index_D8888, since the
325 // color table has its colors inserted unpremultiplied.
326
292 /////////////////////////////////////////////////////////////////////////////// 327 ///////////////////////////////////////////////////////////////////////////////
293 328
294 #include "SkScaledBitmapSampler.h" 329 #include "SkScaledBitmapSampler.h"
295 330
296 SkScaledBitmapSampler::SkScaledBitmapSampler(int width, int height, 331 SkScaledBitmapSampler::SkScaledBitmapSampler(int width, int height,
297 int sampleSize) { 332 int sampleSize) {
298 fCTable = NULL; 333 fCTable = NULL;
299 fDstRow = NULL; 334 fDstRow = NULL;
300 fRowProc = NULL; 335 fRowProc = NULL;
301 336
(...skipping 25 matching lines...) Expand all
327 SkASSERT(fY0 >= 0 && fY0 < height); 362 SkASSERT(fY0 >= 0 && fY0 < height);
328 363
329 fDX = dx; 364 fDX = dx;
330 fDY = dy; 365 fDY = dy;
331 366
332 SkASSERT(fDX > 0 && (fX0 + fDX * (fScaledWidth - 1)) < width); 367 SkASSERT(fDX > 0 && (fX0 + fDX * (fScaledWidth - 1)) < width);
333 SkASSERT(fDY > 0 && (fY0 + fDY * (fScaledHeight - 1)) < height); 368 SkASSERT(fDY > 0 && (fY0 + fDY * (fScaledHeight - 1)) < height);
334 } 369 }
335 370
336 bool SkScaledBitmapSampler::begin(SkBitmap* dst, SrcConfig sc, bool dither, 371 bool SkScaledBitmapSampler::begin(SkBitmap* dst, SrcConfig sc, bool dither,
337 const SkPMColor ctable[]) { 372 const SkPMColor ctable[],
373 bool requireUnpremul) {
338 static const RowProc gProcs[] = { 374 static const RowProc gProcs[] = {
339 // 8888 (no dither distinction) 375 // 8888 (no dither distinction)
340 Sample_Gray_D8888, Sample_Gray_D8888, 376 Sample_Gray_D8888, Sample_Gray_D8888,
341 Sample_RGBx_D8888, Sample_RGBx_D8888, 377 Sample_RGBx_D8888, Sample_RGBx_D8888,
342 Sample_RGBA_D8888, Sample_RGBA_D8888, 378 Sample_RGBA_D8888, Sample_RGBA_D8888,
343 Sample_Index_D8888, Sample_Index_D8888, 379 Sample_Index_D8888, Sample_Index_D8888,
344 NULL, NULL, 380 NULL, NULL,
345 // 565 (no alpha distinction) 381 // 565 (no alpha distinction)
346 Sample_Gray_D565, Sample_Gray_D565_D, 382 Sample_Gray_D565, Sample_Gray_D565_D,
347 Sample_RGBx_D565, Sample_RGBx_D565_D, 383 Sample_RGBx_D565, Sample_RGBx_D565_D,
348 Sample_RGBx_D565, Sample_RGBx_D565_D, 384 Sample_RGBx_D565, Sample_RGBx_D565_D,
349 Sample_Index_D565, Sample_Index_D565_D, 385 Sample_Index_D565, Sample_Index_D565_D,
350 Sample_D565_D565, Sample_D565_D565, 386 Sample_D565_D565, Sample_D565_D565,
351 // 4444 387 // 4444
352 Sample_Gray_D4444, Sample_Gray_D4444_D, 388 Sample_Gray_D4444, Sample_Gray_D4444_D,
353 Sample_RGBx_D4444, Sample_RGBx_D4444_D, 389 Sample_RGBx_D4444, Sample_RGBx_D4444_D,
354 Sample_RGBA_D4444, Sample_RGBA_D4444_D, 390 Sample_RGBA_D4444, Sample_RGBA_D4444_D,
355 Sample_Index_D4444, Sample_Index_D4444_D, 391 Sample_Index_D4444, Sample_Index_D4444_D,
356 NULL, NULL, 392 NULL, NULL,
357 // Index8 393 // Index8
358 NULL, NULL, 394 NULL, NULL,
359 NULL, NULL, 395 NULL, NULL,
360 NULL, NULL, 396 NULL, NULL,
361 Sample_Index_DI, Sample_Index_DI, 397 Sample_Index_DI, Sample_Index_DI,
362 NULL, NULL, 398 NULL, NULL,
399 // 8888 Unpremul (no dither distinction)
400 Sample_Gray_D8888_Unpremul, Sample_Gray_D8888_Unpremul,
401 Sample_RGBx_D8888, Sample_RGBx_D8888,
402 Sample_RGBA_D8888_Unpremul, Sample_RGBA_D8888_Unpremul,
403 Sample_Index_D8888, Sample_Index_D8888,
404 NULL, NULL,
363 }; 405 };
406 // The jump between dst configs in the table
407 static const int gProcDstConfigSpan = 10;
408 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gProcs) == 5 * gProcDstConfigSpan,
409 gProcs_has_the_wrong_number_of_entries);
364 410
365 fCTable = ctable; 411 fCTable = ctable;
366 412
367 int index = 0; 413 int index = 0;
368 if (dither) { 414 if (dither) {
369 index += 1; 415 index += 1;
370 } 416 }
371 switch (sc) { 417 switch (sc) {
372 case SkScaledBitmapSampler::kGray: 418 case SkScaledBitmapSampler::kGray:
373 fSrcPixelSize = 1; 419 fSrcPixelSize = 1;
(...skipping 18 matching lines...) Expand all
392 case SkScaledBitmapSampler::kRGB_565: 438 case SkScaledBitmapSampler::kRGB_565:
393 fSrcPixelSize = 2; 439 fSrcPixelSize = 2;
394 index += 8; 440 index += 8;
395 break; 441 break;
396 default: 442 default:
397 return false; 443 return false;
398 } 444 }
399 445
400 switch (dst->config()) { 446 switch (dst->config()) {
401 case SkBitmap::kARGB_8888_Config: 447 case SkBitmap::kARGB_8888_Config:
402 index += 0; 448 index += 0 * gProcDstConfigSpan;
403 break; 449 break;
404 case SkBitmap::kRGB_565_Config: 450 case SkBitmap::kRGB_565_Config:
405 index += 10; 451 index += 1 * gProcDstConfigSpan;
406 break; 452 break;
407 case SkBitmap::kARGB_4444_Config: 453 case SkBitmap::kARGB_4444_Config:
408 index += 20; 454 index += 2 * gProcDstConfigSpan;
409 break; 455 break;
410 case SkBitmap::kIndex8_Config: 456 case SkBitmap::kIndex8_Config:
411 index += 30; 457 index += 3 * gProcDstConfigSpan;
412 break; 458 break;
413 default: 459 default:
414 return false; 460 return false;
415 } 461 }
416 462
463 if (requireUnpremul) {
464 if (dst->config() != SkBitmap::kARGB_8888_Config) {
465 return false;
466 }
467 index += 4 * gProcDstConfigSpan;
468 }
469
417 fRowProc = gProcs[index]; 470 fRowProc = gProcs[index];
418 fDstRow = (char*)dst->getPixels(); 471 fDstRow = (char*)dst->getPixels();
419 fDstRowBytes = dst->rowBytes(); 472 fDstRowBytes = dst->rowBytes();
420 fCurrY = 0; 473 fCurrY = 0;
421 return fRowProc != NULL; 474 return fRowProc != NULL;
422 } 475 }
423 476
424 bool SkScaledBitmapSampler::next(const uint8_t* SK_RESTRICT src) { 477 bool SkScaledBitmapSampler::next(const uint8_t* SK_RESTRICT src) {
425 SkASSERT((unsigned)fCurrY < (unsigned)fScaledHeight); 478 SkASSERT((unsigned)fCurrY < (unsigned)fScaledHeight);
426 479
427 bool hadAlpha = fRowProc(fDstRow, src + fX0 * fSrcPixelSize, fScaledWidth, 480 bool hadAlpha = fRowProc(fDstRow, src + fX0 * fSrcPixelSize, fScaledWidth,
428 fDX * fSrcPixelSize, fCurrY, fCTable); 481 fDX * fSrcPixelSize, fCurrY, fCTable);
429 fDstRow += fDstRowBytes; 482 fDstRow += fDstRowBytes;
430 fCurrY += 1; 483 fCurrY += 1;
431 return hadAlpha; 484 return hadAlpha;
432 } 485 }
OLDNEW
« no previous file with comments | « src/images/SkScaledBitmapSampler.h ('k') | src/ports/SkImageDecoder_WIC.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698