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

Unified Diff: src/codec/SkWebpCodec.cpp

Issue 1332053002: Fill incomplete images in SkCodec parent class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Forgot to add SkSampler.cpp Created 5 years, 2 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/SkWebpCodec.cpp
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index ccffda9276857e9549cd9fb1263577b3a9c59d68..3e6d11feda2c101504cf68b1927dee4805b7417b 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -158,7 +158,8 @@ bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const {
}
SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
- const Options& options, SkPMColor*, int*) {
+ const Options& options, SkPMColor*, int*,
+ int* rowsDecoded) {
if (!webp_conversion_possible(dstInfo, this->getInfo())) {
return kInvalidConversion;
}
@@ -216,6 +217,7 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
config.options.scaled_width = dstDimensions.width();
config.options.scaled_height = dstDimensions.height();
}
+ fDstWidth = dstDimensions.width();
config.output.colorspace = webp_decode_mode(dstInfo.colorType(),
dstInfo.alphaType() == kPremul_SkAlphaType);
@@ -234,10 +236,8 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
while (true) {
const size_t bytesRead = stream()->read(buffer, BUFFER_SIZE);
if (0 == bytesRead) {
- // FIXME: Maybe this is an incomplete image? How to decide? Based
- // on the number of rows decoded? We can know the number of rows
- // decoded using WebPIDecGetRGB.
- return kInvalidInput;
+ WebPIDecGetRGB(idec, rowsDecoded, NULL, NULL, NULL);
+ return kIncompleteInput;
}
switch (WebPIAppend(idec, buffer, bytesRead)) {
@@ -253,4 +253,38 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
}
SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream)
- : INHERITED(info, stream) {}
+ : INHERITED(info, stream)
+ , fDstWidth(info.width())
+{}
+
+class SkWebpSampler : public SkSampler {
+public:
+ SkWebpSampler(SkWebpCodec* codec)
+ : fCodec(codec)
+ {
+ SkASSERT(fCodec);
+ }
+
+private:
+ // We not support sampling of webps. Webps support arbitrary native scaling.
+ int onSetSampleX(int sampleX) {
+ SkASSERT(false);
+ return fCodec->fDstWidth;
+ }
+
+
+ int onGetScaledWidth() override {
+ return fCodec->fDstWidth;
+ }
+
+ // Unowned pointer. fCodec will delete this class in its destructor.
+ SkWebpCodec* fCodec;
+};
+
+SkSampler* SkWebpCodec::getSampler() {
+ if (!fSampler) {
+ fSampler.reset(new SkWebpSampler(this));
+ }
+
+ return fSampler;
+}
« src/codec/SkWebpCodec.h ('K') | « src/codec/SkWebpCodec.h ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698