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

Unified Diff: src/codec/SkJpegCodec.cpp

Issue 1332053002: Fill incomplete images in SkCodec parent class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase on merged SkCodec and SkScanlineDecoder Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: src/codec/SkJpegCodec.cpp
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index b4c794c90623111d3835b0673d5ec88eb5c42d32..aff54bbd4d6e49f19d3041ef8f4f81ca7610928b 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -302,7 +302,8 @@ bool SkJpegCodec::nativelyScaleToDimensions(uint32_t dstWidth, uint32_t dstHeigh
*/
SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo,
void* dst, size_t dstRowBytes,
- const Options& options, SkPMColor*, int*) {
+ const Options& options, SkPMColor*, int*,
+ int* rowsDecoded) {
if (options.fSubset) {
// Subsets are not supported.
return kUnimplemented;
@@ -340,20 +341,11 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo,
JSAMPLE* dstRow = (JSAMPLE*) dst;
for (uint32_t y = 0; y < dstHeight; y++) {
// Read rows of the image
- uint32_t rowsDecoded = jpeg_read_scanlines(dinfo, &dstRow, 1);
+ uint32_t lines = jpeg_read_scanlines(dinfo, &dstRow, 1);
// If we cannot read enough rows, assume the input is incomplete
- if (rowsDecoded != 1) {
- // Fill the remainder of the image with black. This error handling
- // behavior is unspecified but SkCodec consistently uses black as
- // the fill color for opaque images. If the destination is kGray,
- // the low 8 bits of SK_ColorBLACK will be used. Conveniently,
- // these are zeros, which is the representation for black in kGray.
- // If the destination is kRGB_565, the low 16 bits of SK_ColorBLACK
- // will be used. Conveniently, these are zeros, which is the
- // representation for black in kRGB_565.
- SkSwizzler::Fill(dstRow, dstInfo, dstRowBytes, dstHeight - y,
- SK_ColorBLACK, nullptr, options.fZeroInitialized);
+ if (lines != 1) {
+ *rowsDecoded = y;
// Prevent libjpeg from failing on incomplete decode
dinfo->output_scanline = dstHeight;
@@ -461,7 +453,7 @@ SkJpegCodec::~SkJpegCodec() {
jpeg_finish_decompress(fDecoderMgr->dinfo());
}
-SkCodec::Result SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowBytes) {
+uint32_t SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowBytes) {
// Set the jump location for libjpeg errors
if (setjmp(fDecoderMgr->getJmpBuf())) {
return fDecoderMgr->returnFailure("setjmp", kInvalidInput);
@@ -480,10 +472,8 @@ SkCodec::Result SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowByte
// Read row of the image
uint32_t rowsDecoded = jpeg_read_scanlines(fDecoderMgr->dinfo(), &dstRow, 1);
if (rowsDecoded != 1) {
- SkSwizzler::Fill(dstRow, this->dstInfo(), rowBytes, count - y,
- SK_ColorBLACK, nullptr, this->options().fZeroInitialized);
fDecoderMgr->dinfo()->output_scanline = this->dstInfo().height();
- return kIncompleteInput;
+ return y;
}
// Convert to RGBA if necessary
@@ -499,7 +489,7 @@ SkCodec::Result SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowByte
dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes);
}
}
- return kSuccess;
+ return count;
}
#ifndef TURBO_HAS_SKIP
@@ -513,14 +503,11 @@ SkCodec::Result SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowByte
}
#endif
-SkCodec::Result SkJpegCodec::onSkipScanlines(int count) {
+bool SkJpegCodec::onSkipScanlines(int count) {
// Set the jump location for libjpeg errors
if (setjmp(fDecoderMgr->getJmpBuf())) {
return fDecoderMgr->returnFailure("setjmp", kInvalidInput);
}
- jpeg_skip_scanlines(fDecoderMgr->dinfo(), count);
-
- return kSuccess;
+ return count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count);
}
-

Powered by Google App Engine
This is Rietveld 408576698