Index: src/codec/SkWebpCodec.cpp |
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp |
index a0fab0a153d67f0d32375ac7405d06314a7bb317..e5dc62a2162b9fdd2ece5de3da91ff44ee2b9eed 100644 |
--- a/src/codec/SkWebpCodec.cpp |
+++ b/src/codec/SkWebpCodec.cpp |
@@ -140,15 +140,6 @@ static WEBP_CSP_MODE webp_decode_mode(SkColorType ct, bool premultiply) { |
static const size_t BUFFER_SIZE = 4096; |
bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const { |
- if (!desiredSubset) { |
- return false; |
- } |
- |
- SkIRect bounds = SkIRect::MakeSize(this->getInfo().dimensions()); |
- if (!desiredSubset->intersect(bounds)) { |
- return false; |
- } |
- |
// As stated below, libwebp snaps to even left and top. Make sure top and left are even, so we |
// decode this exact subset. |
// Leave right and bottom unmodified, so we suggest a slightly larger subset than requested. |
@@ -157,6 +148,25 @@ bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const { |
return true; |
} |
+bool SkWebpCodec::onGetScaledSubsetDimensions(float desiredScale, Options* options) const { |
+ if (!this->onGetValidSubset(options->fSubset)) { |
+ return false; |
+ } |
+ options->fScaledDimensions = SkISize::Make( |
+ SkTMax(1, SkScalarRoundToInt(desiredScale * this->getInfo().width())), |
+ SkTMax(1, SkScalarRoundToInt(desiredScale * this->getInfo().height()))); |
+ // Notice that we may round the size of the subset up to 1. This means that we must |
+ // floor the left and top offsets to ensure that we do not suggest a subset that is |
+ // off the edge of the image. |
+ options->fScaledSubset = SkIRect::MakeXYWH( |
+ int (desiredScale * options->fSubset->left()), |
+ int (desiredScale * options->fSubset->top()), |
+ SkTMax(1, SkScalarRoundToInt(desiredScale * options->fSubset->width())), |
+ SkTMax(1, SkScalarRoundToInt(desiredScale * options->fSubset->height()))); |
+ |
+ return true; |
+} |
+ |
SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, |
const Options& options, SkPMColor*, int*, |
int* rowsDecoded) { |
@@ -222,7 +232,10 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, |
dstInfo.alphaType() == kPremul_SkAlphaType); |
config.output.u.RGBA.rgba = (uint8_t*) dst; |
config.output.u.RGBA.stride = (int) rowBytes; |
- config.output.u.RGBA.size = dstInfo.getSafeSize(rowBytes); |
+ // TODO: We can use dstInfo.getSafeSize(rowBytes) here because |
+ // https://code.google.com/p/webp/issues/detail?id=258 has |
+ // been resolved, but it will require an update to libwebp. |
+ config.output.u.RGBA.size = rowBytes * dstInfo.height(); |
config.output.is_external_memory = 1; |
SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &config)); |