OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCodecPriv.h" | 8 #include "SkCodecPriv.h" |
9 #include "SkScaledCodec.h" | 9 #include "SkScaledCodec.h" |
10 #include "SkStream.h" | 10 #include "SkStream.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 SkISize SkScaledCodec::onGetScaledDimensions(float desiredScale) const { | 80 SkISize SkScaledCodec::onGetScaledDimensions(float desiredScale) const { |
81 SkISize nativeDimensions = fScanlineDecoder->getScaledDimensions(desiredScal
e); | 81 SkISize nativeDimensions = fScanlineDecoder->getScaledDimensions(desiredScal
e); |
82 // support scaling down by integer numbers. Ex: 1/2, 1/3, 1/4 ... | 82 // support scaling down by integer numbers. Ex: 1/2, 1/3, 1/4 ... |
83 SkISize scaledCodecDimensions; | 83 SkISize scaledCodecDimensions; |
84 if (desiredScale > 0.5f) { | 84 if (desiredScale > 0.5f) { |
85 // sampleSize = 1 | 85 // sampleSize = 1 |
86 scaledCodecDimensions = fScanlineDecoder->getInfo().dimensions(); | 86 scaledCodecDimensions = fScanlineDecoder->getInfo().dimensions(); |
87 } | 87 } |
88 // sampleSize determines the step size between samples | 88 // sampleSize determines the step size between samples |
89 // Ex: sampleSize = 2, sample every second pixel in x and y directions | 89 // Ex: sampleSize = 2, sample every second pixel in x and y directions |
90 int sampleSize = int(1 / desiredScale); | 90 int sampleSize = int ((1.0f / desiredScale) + 0.5f); |
91 | 91 |
92 int scaledWidth = get_scaled_dimension(this->getInfo().width(), sampleSize); | 92 int scaledWidth = get_scaled_dimension(this->getInfo().width(), sampleSize); |
93 int scaledHeight = get_scaled_dimension(this->getInfo().height(), sampleSize
); | 93 int scaledHeight = get_scaled_dimension(this->getInfo().height(), sampleSize
); |
94 | 94 |
95 // Return the calculated output dimensions for the given scale | 95 // Return the calculated output dimensions for the given scale |
96 scaledCodecDimensions = SkISize::Make(scaledWidth, scaledHeight); | 96 scaledCodecDimensions = SkISize::Make(scaledWidth, scaledHeight); |
97 | 97 |
98 return best_scaled_dimensions(this->getInfo().dimensions(), nativeDimensions
, | 98 return best_scaled_dimensions(this->getInfo().dimensions(), nativeDimensions
, |
99 scaledCodecDimensions, desiredScale); | 99 scaledCodecDimensions, desiredScale); |
100 } | 100 } |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 storagePtr += sampleY * rowBytes; | 289 storagePtr += sampleY * rowBytes; |
290 dst = SkTAddOffset<void>(dst, rowBytes); | 290 dst = SkTAddOffset<void>(dst, rowBytes); |
291 } | 291 } |
292 return result; | 292 return result; |
293 } | 293 } |
294 default: | 294 default: |
295 SkASSERT(false); | 295 SkASSERT(false); |
296 return kUnimplemented; | 296 return kUnimplemented; |
297 } | 297 } |
298 } | 298 } |
OLD | NEW |