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

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: Response to comments 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 4557e45673eb124a4ae346467b77a21cc955f8fa..5d5acc02e6efc238873a72a0af0730ca8005af8b 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -303,7 +303,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* incompleteScanlines) {
// Rewind the stream if needed
if (!this->rewindIfNeeded()) {
return fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRewind);
@@ -350,16 +351,7 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo,
// 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);
+ *incompleteScanlines = dstHeight - y;
// Prevent libjpeg from failing on incomplete decode
dinfo->output_scanline = dstHeight;
@@ -387,8 +379,8 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo,
*/
class SkJpegScanlineDecoder : public SkScanlineDecoder {
public:
- SkJpegScanlineDecoder(const SkImageInfo& srcInfo, SkJpegCodec* codec)
- : INHERITED(srcInfo)
+ SkJpegScanlineDecoder(SkJpegCodec* codec)
+ : INHERITED(codec, codec->getInfo())
, fCodec(codec)
, fOpts()
{}
@@ -425,8 +417,8 @@ public:
SkASSERT(false);
}
- fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, info, options.fZeroInitialized,
- this->getInfo()));
+ fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, info,
+ options.fZeroInitialized, this->getInfo()));
if (!fSwizzler) {
// FIXME: CreateSwizzler could fail for another reason.
return SkCodec::kUnimplemented;
@@ -496,7 +488,7 @@ public:
jpeg_finish_decompress(fCodec->fDecoderMgr->dinfo());
}
- SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) override {
+ uint32_t onGetScanlines(void* dst, int count, size_t rowBytes) override {
// Set the jump location for libjpeg errors
if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) {
return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvalidInput);
@@ -515,10 +507,8 @@ public:
// Read row of the image
uint32_t rowsDecoded = jpeg_read_scanlines(fCodec->fDecoderMgr->dinfo(), &dstRow, 1);
if (rowsDecoded != 1) {
- SkSwizzler::Fill(dstRow, this->dstInfo(), rowBytes, count - y,
- SK_ColorBLACK, nullptr, fOpts.fZeroInitialized);
fCodec->fDecoderMgr->dinfo()->output_scanline = this->dstInfo().height();
- return SkCodec::kIncompleteInput;
+ return y;
}
// Convert to RGBA if necessary
@@ -534,7 +524,7 @@ public:
dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes);
}
}
- return SkCodec::kSuccess;
+ return count;
}
#ifndef TURBO_HAS_SKIP
@@ -548,15 +538,13 @@ public:
}
#endif
- SkCodec::Result onSkipScanlines(int count) override {
+ uint32_t onSkipScanlines(int count) override {
// Set the jump location for libjpeg errors
if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) {
return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvalidInput);
}
- jpeg_skip_scanlines(fCodec->fDecoderMgr->dinfo(), count);
-
- return SkCodec::kSuccess;
+ return jpeg_skip_scanlines(fCodec->fDecoderMgr->dinfo(), count);
}
SkEncodedFormat onGetEncodedFormat() const override {
@@ -564,7 +552,7 @@ public:
}
private:
- SkAutoTDelete<SkJpegCodec> fCodec;
+ SkJpegCodec* fCodec; // Owned by parent class
SkAutoMalloc fStorage; // Only used if sampling is needed
uint8_t* fSrcRow; // Only used if sampling is needed
SkCodec::Options fOpts;
@@ -579,8 +567,6 @@ SkScanlineDecoder* SkJpegCodec::NewSDFromStream(SkStream* stream) {
return nullptr;
}
- const SkImageInfo& srcInfo = codec->getInfo();
-
// Return the new scanline decoder
- return new SkJpegScanlineDecoder(srcInfo, codec.detach());
+ return new SkJpegScanlineDecoder(codec.detach());
}

Powered by Google App Engine
This is Rietveld 408576698