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

Unified Diff: src/codec/SkWebpCodec.cpp

Issue 1240143002: Add the ability to decode a subset to SkCodec. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix line endings 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
« dm/DMSrcSink.cpp ('K') | « include/codec/SkCodec.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkWebpCodec.cpp
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index 32a8b78b14f2487e69305c6d90c89533319435bb..bbfd153ecba85bea8b7735f2d563539afc2f3325 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -126,7 +126,7 @@ static WEBP_CSP_MODE webp_decode_mode(SkColorType ct, bool premultiply) {
static const size_t BUFFER_SIZE = 4096;
SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
- const Options&, SkPMColor*, int*) {
+ const Options& options, SkPMColor*, int*) {
switch (this->rewindIfNeeded()) {
case kCouldNotRewind_RewindState:
return kCouldNotRewind;
@@ -153,12 +153,34 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
// Free any memory associated with the buffer. Must be called last, so we declare it first.
SkAutoTCallVProc<WebPDecBuffer, WebPFreeDecBuffer> autoFree(&(config.output));
- SkISize dimensions = dstInfo.dimensions();
- if (this->getInfo().dimensions() != dimensions) {
+ SkIRect bounds = SkIRect::MakeSize(this->getInfo().dimensions());
+ if (!options.fSubset.isEmpty()) {
+ // Caller is requesting a subset.
+ if (!bounds.intersect(options.fSubset)) {
+ // The subset is out of bounds.
+ return kInvalidParameters;
+ }
+
+ // This is tricky. libwebp snaps the top and left to even values. Rather than claim we
+ // supported this, when we really did something different, report that we cannot
emmaleer 2015/07/17 22:31:05 What is the different thing we did, instead of cro
scroggo 2015/07/20 14:25:42 Done. Please take a look and let me know if you th
+ // handle it.
+ if (!SkIsAlign2(bounds.fLeft) || !SkIsAlign2(bounds.fTop)) {
+ return kInvalidParameters;
+ }
+
+ config.options.use_cropping = 1;
+ config.options.crop_left = bounds.fLeft;
+ config.options.crop_top = bounds.fTop;
+ config.options.crop_width = bounds.width();
+ config.options.crop_height = bounds.height();
+ }
+
+ SkISize dstDimensions = dstInfo.dimensions();
+ if (bounds.size() != dstDimensions) {
// Caller is requesting scaling.
config.options.use_scaling = 1;
- config.options.scaled_width = dimensions.width();
- config.options.scaled_height = dimensions.height();
+ config.options.scaled_width = dstDimensions.width();
+ config.options.scaled_height = dstDimensions.height();
emmaleer 2015/07/17 22:31:05 Should we check that the width and height are bein
scroggo 2015/07/20 14:25:42 Not sure. As I understand it, libwebp allows scali
}
config.output.colorspace = webp_decode_mode(dstInfo.colorType(),
« dm/DMSrcSink.cpp ('K') | « include/codec/SkCodec.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698