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

Unified Diff: src/codec/SkCodec_libgif.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/SkCodec_libgif.cpp
diff --git a/src/codec/SkCodec_libgif.cpp b/src/codec/SkCodec_libgif.cpp
index 03980b586a1df9a6b3c2d41b213614b7e8f93465..1d2606a4f9233ae9aa22a8c660e821ee602396e4 100644
--- a/src/codec/SkCodec_libgif.cpp
+++ b/src/codec/SkCodec_libgif.cpp
@@ -96,31 +96,6 @@ static uint32_t find_trans_index(const SavedImage& image) {
return SK_MaxU32;
}
-static inline uint32_t ceil_div(uint32_t a, uint32_t b) {
- return (a + b - 1) / b;
-}
-
-/*
- * Gets the output row corresponding to the encoded row for interlaced gifs
- */
-static uint32_t get_output_row_interlaced(uint32_t encodedRow, uint32_t height) {
- SkASSERT(encodedRow < height);
- // First pass
- if (encodedRow * 8 < height) {
- return encodedRow * 8;
- }
- // Second pass
- if (encodedRow * 4 < height) {
- return 4 + 8 * (encodedRow - ceil_div(height, 8));
- }
- // Third pass
- if (encodedRow * 2 < height) {
- return 2 + 4 * (encodedRow - ceil_div(height, 4));
- }
- // Fourth pass
- return 1 + 2 * (encodedRow - ceil_div(height, 2));
-}
-
/*
* This function cleans up the gif object after the decode completes
* It is used in a SkAutoTCallIProc template
@@ -497,11 +472,11 @@ SkCodec::Result SkGifCodec::initializeSwizzler(const SkImageInfo& dstInfo,
return kUnimplemented;
}
-SkCodec::Result SkGifCodec::readRow() {
+bool SkGifCodec::readRow() {
if (GIF_ERROR == DGifGetLine(fGif, fSrcBuffer.get(), fFrameDims.width())) {
scroggo 2015/09/25 15:55:06 nit: This can be one line: return GIF_ERROR != DG
msarett 2015/10/01 12:44:52 Done.
- return kIncompleteInput;
+ return false;
}
- return kSuccess;
+ return true;
}
/*
@@ -511,7 +486,8 @@ SkCodec::Result SkGifCodec::onGetPixels(const SkImageInfo& dstInfo,
void* dst, size_t dstRowBytes,
const Options& opts,
SkPMColor* inputColorPtr,
- int* inputColorCount) {
+ int* inputColorCount,
+ int* incompleteScanlines) {
Result result = this->prepareToDecode(dstInfo, inputColorPtr, inputColorCount, opts);
if (kSuccess != result) {
return result;
@@ -530,8 +506,8 @@ SkCodec::Result SkGifCodec::onGetPixels(const SkImageInfo& dstInfo,
// Fill the background
const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
- SkSwizzler::Fill(dst, dstInfo, dstRowBytes, this->getInfo().height(),
- fFillIndex, colorPtr, opts.fZeroInitialized);
+ SkSwizzler::Fill(dst, dstInfo, dstRowBytes, this->getFillValue(dstInfo),
+ opts.fZeroInitialized);
// Modify the dst pointer
const int32_t dstBytesPerPixel = SkColorTypeBytesPerPixel(dstInfo.colorType());
@@ -551,13 +527,17 @@ SkCodec::Result SkGifCodec::onGetPixels(const SkImageInfo& dstInfo,
// the output image. We a helper function to help us
// rearrange the decoded rows.
for (uint32_t y = 0; y < height; y++) {
- if (kSuccess != this->readRow()) {
- // Recover from error by filling remainder of image
- memset(fSrcBuffer.get(), fFillIndex, width);
+ if (!this->readRow()) {
+ // Incomplete interlaced gifs are a unique case. Rather than,
+ // relying on the base class, we will fill the remaining lines
+ // here.
+ const SkImageInfo fillInfo = dstInfo.makeWH(dstInfo.width(), 1);
+ const uint32_t fillValue = this->getFillValue(fillInfo);
for (; y < height; y++) {
void* dstRow = SkTAddOffset<void>(dst,
dstRowBytes * get_output_row_interlaced(y, height));
- fSwizzler->swizzle(dstRow, fSrcBuffer.get());
+ SkSwizzler::Fill(dstRow, fillInfo, dstRowBytes, fillValue,
+ opts.fZeroInitialized);
}
return gif_error("Could not decode line.\n", kIncompleteInput);
}
@@ -569,10 +549,8 @@ SkCodec::Result SkGifCodec::onGetPixels(const SkImageInfo& dstInfo,
// Standard mode
void* dstRow = dst;
for (uint32_t y = 0; y < height; y++) {
- if (kSuccess != this->readRow()) {
- const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
- SkSwizzler::Fill(dstRow, dstInfo, dstRowBytes,
- height - y, fFillIndex, colorPtr, opts.fZeroInitialized);
+ if (!this->readRow()) {
+ *incompleteScanlines = height - y;
return gif_error("Could not decode line\n", kIncompleteInput);
}
fSwizzler->swizzle(dstRow, fSrcBuffer.get());
@@ -582,14 +560,19 @@ SkCodec::Result SkGifCodec::onGetPixels(const SkImageInfo& dstInfo,
return kSuccess;
}
+uint32_t SkGifCodec::onGetFillValue(const SkImageInfo& dstInfo) const {
+ const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
+ return get_color_table_fill_value(dstInfo.colorType(), colorPtr, fFillIndex);
+}
+
// TODO (msarett): skbug.com/3582
// Should we implement reallyHasAlpha? Or should we read extension blocks in the
// header? Or should we do both?
class SkGifScanlineDecoder : public SkScanlineDecoder {
public:
- SkGifScanlineDecoder(const SkImageInfo& srcInfo, SkGifCodec* codec)
- : INHERITED(srcInfo)
+ SkGifScanlineDecoder(SkGifCodec* codec)
+ : INHERITED(codec, codec->getInfo())
, fCodec(codec)
{}
@@ -632,12 +615,11 @@ public:
return SkCodec::kSuccess;
}
- SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) override {
+ uint32_t onGetScanlines(void* dst, int count, size_t rowBytes) override {
if (fCodec->fFrameIsSubset) {
// Fill the requested rows
- const SkPMColor* colorPtr = get_color_ptr(fCodec->fColorTable.get());
- SkSwizzler::Fill(dst, this->dstInfo(), rowBytes, count, fCodec->fFillIndex,
- colorPtr, this->options().fZeroInitialized);
+ SkSwizzler::Fill(dst, this->dstInfo().makeWH(this->dstInfo().width(), count), rowBytes,
+ fCodec->onGetFillValue(dstInfo()), this->options().fZeroInitialized);
// Do nothing for rows before the image frame
int rowsBeforeFrame = fCodec->fFrameDims.top() - INHERITED::getY();
@@ -657,18 +639,15 @@ public:
this->dstInfo().colorType()) * fCodec->fFrameDims.left());
}
+ void* dstRow = dst;
for (int i = 0; i < count; i++) {
- if (SkCodec::kSuccess != fCodec->readRow()) {
- const SkPMColor* colorPtr = get_color_ptr(fCodec->fColorTable.get());
- SkSwizzler::Fill(dst, this->dstInfo(), rowBytes,
- count - i, fCodec->fFillIndex, colorPtr,
- this->options().fZeroInitialized);
- return gif_error("Could not decode line\n", SkCodec::kIncompleteInput);
+ if (!fCodec->readRow()) {
+ return i;
}
- fCodec->fSwizzler->swizzle(dst, fCodec->fSrcBuffer.get());
- dst = SkTAddOffset<void>(dst, rowBytes);
+ fCodec->fSwizzler->swizzle(dstRow, fCodec->fSrcBuffer.get());
+ dstRow = SkTAddOffset<void>(dstRow, rowBytes);
}
- return SkCodec::kSuccess;
+ return count;
}
SkScanlineOrder onGetScanlineOrder() const override {
@@ -679,16 +658,8 @@ public:
}
}
- int onGetY() const override {
- if (fCodec->fGif->Image.Interlace) {
- return get_output_row_interlaced(INHERITED::onGetY(), this->dstInfo().height());
- } else {
- return INHERITED::onGetY();
- }
- }
-
private:
- SkAutoTDelete<SkGifCodec> fCodec;
+ SkGifCodec* fCodec; // Owned by parent class
typedef SkScanlineDecoder INHERITED;
};
@@ -699,7 +670,5 @@ SkScanlineDecoder* SkGifCodec::NewSDFromStream(SkStream* stream) {
return NULL;
}
- const SkImageInfo& srcInfo = codec->getInfo();
-
- return SkNEW_ARGS(SkGifScanlineDecoder, (srcInfo, codec.detach()));
+ return SkNEW_ARGS(SkGifScanlineDecoder, (codec.detach()));
}

Powered by Google App Engine
This is Rietveld 408576698