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

Unified Diff: src/codec/SkCodec_libpng.cpp

Issue 1260673002: SkScaledCodec class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add helper functions to calculate sampleSize and scaledDimensions 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..f0f01e56902756994ab1a1018121961b11d0df8b 100644
--- a/src/codec/SkCodec_libpng.cpp
+++ b/src/codec/SkCodec_libpng.cpp
@@ -474,7 +474,7 @@ SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo,
// 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, this->getInfo()));
if (!fSwizzler) {
// FIXME: CreateSwizzler could fail for another reason.
return kUnimplemented;
@@ -597,7 +597,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 +634,10 @@ public:
bool onReallyHasAlpha() const override { return fHasAlpha; }
+ bool onIsHardToSample() override {
+ return false;
+ }
+
private:
SkAutoTDelete<SkPngCodec> fCodec;
bool fHasAlpha;
@@ -653,7 +657,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 +712,10 @@ public:
bool onReallyHasAlpha() const override { return fHasAlpha; }
+ bool onIsHardToSample() override {
+ return true;
+ }
+
private:
SkAutoTDelete<SkPngCodec> fCodec;
bool fHasAlpha;
@@ -727,9 +735,14 @@ SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo,
SkCodecPrintf("no conversion possible\n");
return NULL;
}
+ Options scaledOptions = options;
// 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
+ 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 +757,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;
« no previous file with comments | « src/codec/SkCodec_libpng.h ('k') | src/codec/SkJpegCodec.h » ('j') | src/codec/SkJpegCodec.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698