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

Unified Diff: src/codec/SkCodec_libpng.cpp

Issue 1260673002: SkScaledCodec class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use SkWebpCodec native scaling, update comments and spacing 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..a03deb435f41d625327eebf75bf21c2c13fb0f52 100644
--- a/src/codec/SkCodec_libpng.cpp
+++ b/src/codec/SkCodec_libpng.cpp
@@ -424,6 +424,11 @@ static bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src)
}
}
+bool SkPngCodec::onIsInterlaced() {
+ // we cannot depend on fNumberPasses, since it may not have been set yet
scroggo 2015/07/27 19:29:57 If we moved this onto the scanline decoder, we wou
emmaleer 2015/07/28 14:19:16 Acknowledged.
+ return 1 != png_set_interlace_handling(fPng_ptr);
+}
+
SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo,
void* dst, size_t rowBytes,
const Options& options,
@@ -593,14 +598,19 @@ SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void*
class SkPngScanlineDecoder : public SkScanlineDecoder {
public:
SkPngScanlineDecoder(const SkImageInfo& dstInfo, SkPngCodec* codec)
- : INHERITED(dstInfo)
+ : INHERITED(dstInfo, codec->getInfo())
, 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());
}
+ bool onSetSampleX(int sampleX) override {
+ fCodec->fSwizzler->setSampleX(sampleX);
+ return true;
+ }
+
SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) override {
if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) {
SkCodecPrintf("setjmp long jump!\n");
@@ -647,17 +657,22 @@ private:
class SkPngInterlacedScanlineDecoder : public SkScanlineDecoder {
public:
SkPngInterlacedScanlineDecoder(const SkImageInfo& dstInfo, SkPngCodec* codec)
- : INHERITED(dstInfo)
+ : INHERITED(dstInfo, codec->getInfo())
, fCodec(codec)
, fHasAlpha(false)
, 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());
}
+ bool onSetSampleX(int sampleX) override {
+ fCodec->fSwizzler->setSampleX(sampleX);
+ return true;
+ }
+
SkCodec::Result onGetScanlines(void* dst, int count, size_t dstRowBytes) override {
//rewind stream if have previously called onGetScanlines,
//since we need entire progressive image to get scanlines
@@ -728,8 +743,11 @@ SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo,
return NULL;
}
// Check to see if scaling was requested.
- if (dstInfo.dimensions() != this->getInfo().dimensions()) {
- return NULL;
+ if(options.fSampled == false) {
msarett 2015/07/27 20:42:18 I think we should still be able to check for inval
emmaleer 2015/07/28 14:19:16 Yes, I now check to make sure dstHeight == srcHeig
+ // If the caller is sampling, it is okay for the dimensions to not match
+ if (dstInfo.dimensions() != this->getInfo().dimensions()) {
+ return NULL;
+ }
}
// Create a new SkPngCodec, to be owned by the scanline decoder.
SkStream* stream = this->stream()->duplicate();

Powered by Google App Engine
This is Rietveld 408576698