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

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

Issue 658343003: Fixes for partial images. (Closed) Base URL: https://skia.googlesource.com/skia.git/+/master
Patch Set: Created 6 years, 2 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/SkImageDecoder_libgif.cpp ('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 "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkImageEncoder.h" 10 #include "SkImageEncoder.h"
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 cinfo->dither_mode = JDITHER_ORDERED; 485 cinfo->dither_mode = JDITHER_ORDERED;
486 } 486 }
487 break; 487 break;
488 default: 488 default:
489 break; 489 break;
490 } 490 }
491 #endif 491 #endif
492 } 492 }
493 493
494 494
495 #ifdef SK_DECODE_PARTIAL_IMAGES
495 /** 496 /**
496 Sets all pixels in given bitmap to SK_ColorWHITE for all rows >= y. 497 Sets all pixels in given bitmap to SK_ColorWHITE for all rows >= y.
497 Used when decoding fails partway through reading scanlines to fill 498 Used when decoding fails partway through reading scanlines to fill
498 remaining lines. */ 499 remaining lines. */
499 static void fill_below_level(int y, SkBitmap* bitmap) { 500 static void fill_below_level(int y, SkBitmap* bitmap) {
500 SkIRect rect = SkIRect::MakeLTRB(0, y, bitmap->width(), bitmap->height()); 501 SkIRect rect = SkIRect::MakeLTRB(0, y, bitmap->width(), bitmap->height());
501 SkCanvas canvas(*bitmap); 502 SkCanvas canvas(*bitmap);
502 canvas.clipRect(SkRect::Make(rect)); 503 canvas.clipRect(SkRect::Make(rect));
503 canvas.drawColor(SK_ColorWHITE); 504 canvas.drawColor(SK_ColorWHITE);
504 } 505 }
506 #endif
505 507
506 /** 508 /**
507 * Get the config and bytes per pixel of the source data. Return 509 * Get the config and bytes per pixel of the source data. Return
508 * whether the data is supported. 510 * whether the data is supported.
509 */ 511 */
510 static bool get_src_config(const jpeg_decompress_struct& cinfo, 512 static bool get_src_config(const jpeg_decompress_struct& cinfo,
511 SkScaledBitmapSampler::SrcConfig* sc, 513 SkScaledBitmapSampler::SrcConfig* sc,
512 int* srcBytesPerPixel) { 514 int* srcBytesPerPixel) {
513 SkASSERT(sc != NULL && srcBytesPerPixel != NULL); 515 SkASSERT(sc != NULL && srcBytesPerPixel != NULL);
514 if (JCS_CMYK == cinfo.out_color_space) { 516 if (JCS_CMYK == cinfo.out_color_space) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 if (sampleSize == 1 && 653 if (sampleSize == 1 &&
652 ((kN32_SkColorType == colorType && cinfo.out_color_space == JCS_RGBA_888 8) || 654 ((kN32_SkColorType == colorType && cinfo.out_color_space == JCS_RGBA_888 8) ||
653 (kRGB_565_SkColorType == colorType && cinfo.out_color_space == JCS_RGB_ 565))) 655 (kRGB_565_SkColorType == colorType && cinfo.out_color_space == JCS_RGB_ 565)))
654 { 656 {
655 JSAMPLE* rowptr = (JSAMPLE*)bm->getPixels(); 657 JSAMPLE* rowptr = (JSAMPLE*)bm->getPixels();
656 INT32 const bpr = bm->rowBytes(); 658 INT32 const bpr = bm->rowBytes();
657 659
658 while (cinfo.output_scanline < cinfo.output_height) { 660 while (cinfo.output_scanline < cinfo.output_height) {
659 int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1); 661 int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1);
660 if (0 == row_count) { 662 if (0 == row_count) {
663 #ifdef SK_DECODE_PARTIAL_IMAGES
661 // if row_count == 0, then we didn't get a scanline, 664 // if row_count == 0, then we didn't get a scanline,
662 // so return early. We will return a partial image. 665 // so return early. We will return a partial image.
663 fill_below_level(cinfo.output_scanline, bm); 666 fill_below_level(cinfo.output_scanline, bm);
664 cinfo.output_scanline = cinfo.output_height; 667 cinfo.output_scanline = cinfo.output_height;
665 break; // Skip to jpeg_finish_decompress() 668 break; // Skip to jpeg_finish_decompress()
669 #else
670 return return_false(cinfo, *bm, "read_scanlines");
671 #endif
666 } 672 }
667 if (this->shouldCancelDecode()) { 673 if (this->shouldCancelDecode()) {
668 return return_false(cinfo, *bm, "shouldCancelDecode"); 674 return return_false(cinfo, *bm, "shouldCancelDecode");
669 } 675 }
670 rowptr += bpr; 676 rowptr += bpr;
671 } 677 }
672 jpeg_finish_decompress(&cinfo); 678 jpeg_finish_decompress(&cinfo);
673 return true; 679 return true;
674 } 680 }
675 #endif 681 #endif
(...skipping 16 matching lines...) Expand all
692 // Possibly skip initial rows [sampler.srcY0] 698 // Possibly skip initial rows [sampler.srcY0]
693 if (!skip_src_rows(&cinfo, srcRow, sampler.srcY0())) { 699 if (!skip_src_rows(&cinfo, srcRow, sampler.srcY0())) {
694 return return_false(cinfo, *bm, "skip rows"); 700 return return_false(cinfo, *bm, "skip rows");
695 } 701 }
696 702
697 // now loop through scanlines until y == bm->height() - 1 703 // now loop through scanlines until y == bm->height() - 1
698 for (int y = 0;; y++) { 704 for (int y = 0;; y++) {
699 JSAMPLE* rowptr = (JSAMPLE*)srcRow; 705 JSAMPLE* rowptr = (JSAMPLE*)srcRow;
700 int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1); 706 int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1);
701 if (0 == row_count) { 707 if (0 == row_count) {
708 #ifdef SK_DECODE_PARTIAL_IMAGES
702 // if row_count == 0, then we didn't get a scanline, 709 // if row_count == 0, then we didn't get a scanline,
703 // so return early. We will return a partial image. 710 // so return early. We will return a partial image.
704 fill_below_level(y, bm); 711 fill_below_level(y, bm);
705 cinfo.output_scanline = cinfo.output_height; 712 cinfo.output_scanline = cinfo.output_height;
706 break; // Skip to jpeg_finish_decompress() 713 break; // Skip to jpeg_finish_decompress()
714 #else
715 return return_false(cinfo, *bm, "read_scanlines");
716 #endif
707 } 717 }
708 if (this->shouldCancelDecode()) { 718 if (this->shouldCancelDecode()) {
709 return return_false(cinfo, *bm, "shouldCancelDecode"); 719 return return_false(cinfo, *bm, "shouldCancelDecode");
710 } 720 }
711 721
712 if (JCS_CMYK == cinfo.out_color_space) { 722 if (JCS_CMYK == cinfo.out_color_space) {
713 convert_CMYK_to_RGB(srcRow, cinfo.output_width); 723 convert_CMYK_to_RGB(srcRow, cinfo.output_width);
714 } 724 }
715 725
716 sampler.next(srcRow); 726 sampler.next(srcRow);
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 return SkImageDecoder::kUnknown_Format; 1491 return SkImageDecoder::kUnknown_Format;
1482 } 1492 }
1483 1493
1484 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { 1494 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) {
1485 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; 1495 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL;
1486 } 1496 }
1487 1497
1488 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); 1498 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory);
1489 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); 1499 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg);
1490 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); 1500 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory);
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libgif.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698