Index: src/codec/SkWebpCodec.cpp |
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp |
index 3c61b937622097d5e1c5be483770a6fb2336543a..5d3cb78039dc5a7a968d6e17f923398cf44eac4e 100644 |
--- a/src/codec/SkWebpCodec.cpp |
+++ b/src/codec/SkWebpCodec.cpp |
@@ -120,6 +120,13 @@ bool SkWebpCodec::onDimensionsSupported(const SkISize& dim) { |
&& dim.height() >= 1 && dim.height() <= info.height(); |
} |
+bool SkWebpCodec::onSubsetSupported(const SkIRect& subset, bool isScanlineDecode) { |
+ return !((subset.left() & 1) || (subset.top() & 1)); |
scroggo
2015/10/12 20:47:07
Could you add a comment explaining this? (Left and
|
+} |
+ |
+bool SkWebpCodec::onScaledSubsetSupported(const Options& options, bool isScanlineDecode) { |
+ return this->onSubsetSupported(*options.fSubset, isScanlineDecode); |
+} |
static WEBP_CSP_MODE webp_decode_mode(SkColorType ct, bool premultiply) { |
switch (ct) { |
@@ -139,21 +146,26 @@ static WEBP_CSP_MODE webp_decode_mode(SkColorType ct, bool premultiply) { |
// is arbitrary. |
static const size_t BUFFER_SIZE = 4096; |
-bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const { |
- if (!desiredSubset) { |
- return false; |
- } |
- |
- SkIRect dimensions = SkIRect::MakeSize(this->getInfo().dimensions()); |
- if (!dimensions.contains(*desiredSubset)) { |
- return false; |
- } |
+bool SkWebpCodec::onGetScaledSubsetDimensions(float desiredScale, const Options& options) const { |
+ options.fSubset->fLeft = (options.fSubset->fLeft >> 1) << 1; |
+ options.fSubset->fTop = (options.fSubset->fTop >> 1) << 1; |
+ |
+ // Notice that we may round the size of the subset up to 1. This means that we must |
+ // round up the scaled output dimensions to avoid suggesting a subset that is off the |
+ // edge of the image. This rounding behvaior is consistent with SkJpegCodec. |
+ *(options.fScaledDimensions) = SkISize::Make( |
+ sk_float_ceil2int(desiredScale * this->getInfo().width()), |
+ sk_float_ceil2int(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()))); |
- // 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. |
- desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1; |
- desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1; |
return true; |
} |
@@ -193,16 +205,6 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, |
return kInvalidParameters; |
} |
-#ifdef SK_DEBUG |
msarett
2015/10/12 18:33:29
I tried to keep a debug check here, but it is too
|
- { |
- // Make a copy, since getValidSubset can change its input. |
- SkIRect subset(bounds); |
- // That said, getValidSubset should *not* change its input, in this case; otherwise |
- // getValidSubset does not match the actual subsets we can do. |
- SkASSERT(this->getValidSubset(&subset) && subset == bounds); |
- } |
-#endif |
- |
config.options.use_cropping = 1; |
config.options.crop_left = bounds.fLeft; |
config.options.crop_top = bounds.fTop; |