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

Unified Diff: src/codec/SkWebpCodec.cpp

Issue 1321433002: Add subsetting to SkScaledCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@gif-scan
Patch Set: 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 062123033c0a7e41dcbc29835f16d8ddf3c69124..32321835495fd9ad11194808ea12cf5e7c2c235c 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -133,15 +133,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.
@@ -150,6 +141,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) {
@@ -215,7 +225,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();
msarett 2015/10/02 14:49:15 I need to check if I can change this back now that
config.output.is_external_memory = 1;
SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &config));

Powered by Google App Engine
This is Rietveld 408576698