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

Side by Side Diff: src/codec/SkScaledCodec.cpp

Issue 1356923002: Use rounding when converting desiredScale to a sampleSize (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « dm/DM.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « dm/DM.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698