diff options
author | Leon Scroggins III <scroggo@google.com> | 2018-01-16 15:01:17 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-16 21:23:08 +0000 |
commit | 07a722cdcf064fca22213dc06a433dd82f080c23 (patch) | |
tree | 8d8e7de91637af359b9ff8649c8bed317019cbf7 /include/codec/SkAndroidCodec.h | |
parent | 539c6f5c92c2a4f04816d562c3d23556a35a2e98 (diff) |
Add SkAndroidCodec::computeSampledSize
Bug: b/63909536
Android's ImageDecoder API takes as input an arbitrary width and height
to scale the image to. Internally, this uses SkAndroidCodec to sample,
and then (if not a perfect match) scales to the desired size with
drawing.
computeSampledSize is a modified version of what ImageDecoder currently
does to convert from arbitrary dimensions to a sampleSize. Moving it
here allows it to be shared by SkAnimatedImage. The modified version
also corrects two bugs:
- a client using the dimensions returned by getSampledDimensions
previously may have resulted in ImageDecoder decoding to a larger
size and then scaling it. (example found in tests: dog.jpg is
180 x 180. getSampledDimensions(8) returns 23 x 23, but the old
method resulted in using sampleSize of 7 and downscaling the resulting
25 x 25 image.)
- recompute the sampleSize based on the size returned by
getSampledDimensions.
Change-Id: I022040e8bac31c20988903a0452257f7ae902bc7
Reviewed-on: https://skia-review.googlesource.com/94620
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'include/codec/SkAndroidCodec.h')
-rw-r--r-- | include/codec/SkAndroidCodec.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/codec/SkAndroidCodec.h b/include/codec/SkAndroidCodec.h index 2bf38025bf..0746f066c8 100644 --- a/include/codec/SkAndroidCodec.h +++ b/include/codec/SkAndroidCodec.h @@ -91,6 +91,17 @@ public: sk_sp<SkColorSpace> prefColorSpace = nullptr); /** + * Compute the appropriate sample size to get to |size|. + * + * @param size As an input parameter, the desired output size of + * the decode. As an output parameter, the smallest sampled size + * larger than the input. + * @return the sample size to set AndroidOptions::fSampleSize to decode + * to the output |size|. + */ + int computeSampleSize(SkISize* size) const; + + /** * Returns the dimensions of the scaled output image, for an input * sampleSize. * |