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

Unified Diff: src/codec/SkCodec_libpng.cpp

Issue 1260673002: SkScaledCodec class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Works for jpeg images Created 5 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 side-by-side diff with in-line comments
Download patch
Index: src/codec/SkCodec_libpng.cpp
diff --git a/src/codec/SkCodec_libpng.cpp b/src/codec/SkCodec_libpng.cpp
index 553233de12117ea8ccebcdfd261a720b8e721412..79b2c0ea35d18ad27d7db73a600d8c973faac9e0 100644
--- a/src/codec/SkCodec_libpng.cpp
+++ b/src/codec/SkCodec_libpng.cpp
@@ -471,10 +471,12 @@ SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo,
// Copy the color table to the client if they request kIndex8 mode
copy_color_table(requestedInfo, fColorTable, ctable, ctableCount);
+ int sampleX = this->getInfo().width() / requestedInfo.width();
scroggo 2015/07/30 17:53:01 This should also be in some central place, to be s
+
// Create the swizzler. SkPngCodec retains ownership of the color table.
const SkPMColor* colors = fColorTable ? fColorTable->readColors() : NULL;
fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo,
- dst, rowBytes, options.fZeroInitialized));
+ dst, rowBytes, options.fZeroInitialized, sampleX));
if (!fSwizzler) {
// FIXME: CreateSwizzler could fail for another reason.
return kUnimplemented;
@@ -597,7 +599,7 @@ public:
, fCodec(codec)
, fHasAlpha(false)
{
- fStorage.reset(dstInfo.width() * SkSwizzler::BytesPerPixel(fCodec->fSrcConfig));
+ fStorage.reset(fCodec->getInfo().width() * SkSwizzler::BytesPerPixel(fCodec->fSrcConfig));
fSrcRow = static_cast<uint8_t*>(fStorage.get());
}
@@ -634,6 +636,10 @@ public:
bool onReallyHasAlpha() const override { return fHasAlpha; }
+ bool onIsHardToSample() override {
+ return false;
+ }
+
private:
SkAutoTDelete<SkPngCodec> fCodec;
bool fHasAlpha;
@@ -653,7 +659,7 @@ public:
, fCurrentRow(0)
, fHeight(dstInfo.height())
{
- fSrcRowBytes = dstInfo.width() * SkSwizzler::BytesPerPixel(fCodec->fSrcConfig);
+ fSrcRowBytes = codec->getInfo().width() * SkSwizzler::BytesPerPixel(fCodec->fSrcConfig);
fGarbageRow.reset(fSrcRowBytes);
fGarbageRowPtr = static_cast<uint8_t*>(fGarbageRow.get());
}
@@ -708,6 +714,10 @@ public:
bool onReallyHasAlpha() const override { return fHasAlpha; }
+ bool onIsHardToSample() override {
+ return true;
+ }
+
private:
SkAutoTDelete<SkPngCodec> fCodec;
bool fHasAlpha;
@@ -727,9 +737,14 @@ SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo,
SkCodecPrintf("no conversion possible\n");
return NULL;
}
+ Options scaledOptions = options;
scroggo 2015/07/30 17:53:01 It looks like we do not modify scaledOptions, so w
emmaleer 2015/07/30 22:27:55 Acknowledged.
// Check to see if scaling was requested.
- if (dstInfo.dimensions() != this->getInfo().dimensions()) {
- return NULL;
+ if(dstInfo.dimensions() != this->getInfo().dimensions()) {
+ // the caller is sampling
+ // heights must be equal as SkCodec_libpng has no native y sampling
scroggo 2015/07/30 17:53:01 What about widths? We don't want them to request a
emmaleer 2015/07/30 22:27:55 Good point. I've added a check to only allow small
+ if (dstInfo.height() != this->getInfo().height()) {
+ return NULL;
+ }
}
// Create a new SkPngCodec, to be owned by the scanline decoder.
SkStream* stream = this->stream()->duplicate();
@@ -744,7 +759,7 @@ SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo,
// Note: We set dst to NULL since we do not know it yet. rowBytes is not needed,
// since we'll be manually updating the dstRow, but the SkSwizzler requires it to
// be at least dstInfo.minRowBytes.
- if (codec->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), options, ctable,
+ if (codec->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), scaledOptions, ctable,
ctableCount) != kSuccess) {
SkCodecPrintf("failed to initialize the swizzler.\n");
return NULL;

Powered by Google App Engine
This is Rietveld 408576698