aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2015-08-18 08:03:58 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-08-18 08:03:58 -0700
commita83593b88a38765eba5f349d4e12d66b3e626af9 (patch)
treeb744b3d4ccb3d47e27ffef614cc44b49806ee5ab /src
parent0628a52b0cd11a7d5e3415f85c8b8d7cfa655151 (diff)
Prefer native scaling to sampling
In the cases we have come across so far, native scaling has better performance and correctness than sampling. If native scaling is supported we want to use it. Jpegs native scale rounds up. Ex: An 11x11 image with sampleSize=8 scales to 2x2. SkScaledCodec rounds down. Ex: An 11x11 image with sampleSize=8 scales to 1x1. Before the CL, we would choose to use SkScaledCodec because it scales closer to the "ideal" scale. I think we want to go with the native option as long as its within 1 of the ideal value. BUG=skia: Review URL: https://codereview.chromium.org/1284243004
Diffstat (limited to 'src')
-rw-r--r--src/codec/SkScaledCodec.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/codec/SkScaledCodec.cpp b/src/codec/SkScaledCodec.cpp
index e0158b6b4e..0f0d12993c 100644
--- a/src/codec/SkScaledCodec.cpp
+++ b/src/codec/SkScaledCodec.cpp
@@ -53,7 +53,7 @@ static int get_scaled_dimension(int srcDimension, int sampleSize) {
return srcDimension / sampleSize;
}
-static SkISize best_scaled_dimensions(const SkISize& origDims, const SkISize& nativeDims,
+static SkISize best_scaled_dimensions(const SkISize& origDims, const SkISize& nativeDims,
const SkISize& scaledCodecDims, float desiredScale) {
if (nativeDims == scaledCodecDims) {
// does not matter which to return if equal. Return here to skip below calculations
@@ -65,18 +65,24 @@ static SkISize best_scaled_dimensions(const SkISize& origDims, const SkISize& na
// calculate difference between native dimensions and ideal dimensions
float nativeWDiff = SkTAbs(idealWidth - nativeDims.width());
float nativeHDiff = SkTAbs(idealHeight - nativeDims.height());
- float nativeDiff = (nativeWDiff + nativeHDiff) / 2;
+ float nativeDiff = nativeWDiff + nativeHDiff;
+
+ // Native scaling is preferred to sampling. If we can scale natively to
+ // within one of the ideal value, we should choose to scale natively.
+ if (nativeWDiff < 1.0f && nativeHDiff < 1.0f) {
+ return nativeDims;
+ }
// calculate difference between scaledCodec dimensions and ideal dimensions
float scaledCodecWDiff = SkTAbs(idealWidth - scaledCodecDims.width());
float scaledCodecHDiff = SkTAbs(idealHeight - scaledCodecDims.height());
- float scaledCodecDiff = (scaledCodecWDiff + scaledCodecHDiff) / 2;
+ float scaledCodecDiff = scaledCodecWDiff + scaledCodecHDiff;
// return dimensions closest to ideal dimensions.
// If the differences are equal, return nativeDims, as native scaling is more efficient.
return nativeDiff > scaledCodecDiff ? scaledCodecDims : nativeDims;
+}
-}
/*
* Return a valid set of output dimensions for this decoder, given an input scale
*/
@@ -98,7 +104,7 @@ SkISize SkScaledCodec::onGetScaledDimensions(float desiredScale) const {
// Return the calculated output dimensions for the given scale
scaledCodecDimensions = SkISize::Make(scaledWidth, scaledHeight);
- return best_scaled_dimensions(this->getInfo().dimensions(), nativeDimensions,
+ return best_scaled_dimensions(this->getInfo().dimensions(), nativeDimensions,
scaledCodecDimensions, desiredScale);
}