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

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

Issue 18083026: Allow decoding JPEG into A8. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Naming improvements, remove obsolete, add a test. Created 7 years, 5 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
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"
(...skipping 271 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 // A8
293 static bool Sample_Gray_DA8(void* SK_RESTRICT dstRow,
294 const uint8_t* SK_RESTRICT src,
295 int width, int deltaSrc, int,
296 const SkPMColor[]) {
297 memcpy(dstRow, src, width);
298 return true;
299 }
300
292 // 8888 Unpremul 301 // 8888 Unpremul
293 302
294 static bool Sample_Gray_D8888_Unpremul(void* SK_RESTRICT dstRow, 303 static bool Sample_Gray_D8888_Unpremul(void* SK_RESTRICT dstRow,
295 const uint8_t* SK_RESTRICT src, 304 const uint8_t* SK_RESTRICT src,
296 int width, int deltaSrc, int, 305 int width, int deltaSrc, int,
297 const SkPMColor[]) { 306 const SkPMColor[]) {
298 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); 307 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
299 for (int x = 0; x < width; x++) { 308 for (int x = 0; x < width; x++) {
300 dst[x] = SkPackARGB32NoCheck(0xFF, src[0], src[0], src[0]); 309 dst[x] = SkPackARGB32NoCheck(0xFF, src[0], src[0], src[0]);
301 src += deltaSrc; 310 src += deltaSrc;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 Sample_RGBx_D4444, Sample_RGBx_D4444_D, 398 Sample_RGBx_D4444, Sample_RGBx_D4444_D,
390 Sample_RGBA_D4444, Sample_RGBA_D4444_D, 399 Sample_RGBA_D4444, Sample_RGBA_D4444_D,
391 Sample_Index_D4444, Sample_Index_D4444_D, 400 Sample_Index_D4444, Sample_Index_D4444_D,
392 NULL, NULL, 401 NULL, NULL,
393 // Index8 402 // Index8
394 NULL, NULL, 403 NULL, NULL,
395 NULL, NULL, 404 NULL, NULL,
396 NULL, NULL, 405 NULL, NULL,
397 Sample_Index_DI, Sample_Index_DI, 406 Sample_Index_DI, Sample_Index_DI,
398 NULL, NULL, 407 NULL, NULL,
408 // A8
409 Sample_Gray_DA8, Sample_Gray_DA8,
410 NULL, NULL,
411 NULL, NULL,
412 NULL, NULL,
413 NULL, NULL,
399 // 8888 Unpremul (no dither distinction) 414 // 8888 Unpremul (no dither distinction)
400 Sample_Gray_D8888_Unpremul, Sample_Gray_D8888_Unpremul, 415 Sample_Gray_D8888_Unpremul, Sample_Gray_D8888_Unpremul,
401 Sample_RGBx_D8888, Sample_RGBx_D8888, 416 Sample_RGBx_D8888, Sample_RGBx_D8888,
402 Sample_RGBA_D8888_Unpremul, Sample_RGBA_D8888_Unpremul, 417 Sample_RGBA_D8888_Unpremul, Sample_RGBA_D8888_Unpremul,
403 Sample_Index_D8888, Sample_Index_D8888, 418 Sample_Index_D8888, Sample_Index_D8888,
404 NULL, NULL, 419 NULL, NULL,
405 }; 420 };
406 // The jump between dst configs in the table 421 // The jump between dst configs in the table
407 static const int gProcDstConfigSpan = 10; 422 static const int gProcDstConfigSpan = 10;
408 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gProcs) == 5 * gProcDstConfigSpan, 423 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gProcs) == 6 * gProcDstConfigSpan,
409 gProcs_has_the_wrong_number_of_entries); 424 gProcs_has_the_wrong_number_of_entries);
410 425
411 fCTable = ctable; 426 fCTable = ctable;
412 427
413 int index = 0; 428 int index = 0;
414 if (dither) { 429 if (dither) {
415 index += 1; 430 index += 1;
416 } 431 }
417 switch (sc) { 432 switch (sc) {
418 case SkScaledBitmapSampler::kGray: 433 case SkScaledBitmapSampler::kGray:
(...skipping 30 matching lines...) Expand all
449 break; 464 break;
450 case SkBitmap::kRGB_565_Config: 465 case SkBitmap::kRGB_565_Config:
451 index += 1 * gProcDstConfigSpan; 466 index += 1 * gProcDstConfigSpan;
452 break; 467 break;
453 case SkBitmap::kARGB_4444_Config: 468 case SkBitmap::kARGB_4444_Config:
454 index += 2 * gProcDstConfigSpan; 469 index += 2 * gProcDstConfigSpan;
455 break; 470 break;
456 case SkBitmap::kIndex8_Config: 471 case SkBitmap::kIndex8_Config:
457 index += 3 * gProcDstConfigSpan; 472 index += 3 * gProcDstConfigSpan;
458 break; 473 break;
474 case SkBitmap::kA8_Config:
475 index += 4 * gProcDstConfigSpan;
476 break;
459 default: 477 default:
460 return false; 478 return false;
461 } 479 }
462 480
463 if (requireUnpremul) { 481 if (requireUnpremul) {
464 if (dst->config() != SkBitmap::kARGB_8888_Config) { 482 if (dst->config() != SkBitmap::kARGB_8888_Config) {
465 return false; 483 return false;
466 } 484 }
467 index += 4 * gProcDstConfigSpan; 485 index += 5 * gProcDstConfigSpan;
468 } 486 }
469 487
470 fRowProc = gProcs[index]; 488 fRowProc = gProcs[index];
471 fDstRow = (char*)dst->getPixels(); 489 fDstRow = (char*)dst->getPixels();
472 fDstRowBytes = dst->rowBytes(); 490 fDstRowBytes = dst->rowBytes();
473 fCurrY = 0; 491 fCurrY = 0;
474 return fRowProc != NULL; 492 return fRowProc != NULL;
475 } 493 }
476 494
477 bool SkScaledBitmapSampler::next(const uint8_t* SK_RESTRICT src) { 495 bool SkScaledBitmapSampler::next(const uint8_t* SK_RESTRICT src) {
478 SkASSERT((unsigned)fCurrY < (unsigned)fScaledHeight); 496 SkASSERT((unsigned)fCurrY < (unsigned)fScaledHeight);
479 497
480 bool hadAlpha = fRowProc(fDstRow, src + fX0 * fSrcPixelSize, fScaledWidth, 498 bool hadAlpha = fRowProc(fDstRow, src + fX0 * fSrcPixelSize, fScaledWidth,
481 fDX * fSrcPixelSize, fCurrY, fCTable); 499 fDX * fSrcPixelSize, fCurrY, fCTable);
482 fDstRow += fDstRowBytes; 500 fDstRow += fDstRowBytes;
483 fCurrY += 1; 501 fCurrY += 1;
484 return hadAlpha; 502 return hadAlpha;
485 } 503 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698