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

Unified Diff: src/core/SkBitmapScaler.cpp

Issue 307553005: floating point scale factors for images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove the box; it landed separately Created 6 years, 7 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
« no previous file with comments | « src/core/SkBitmapScaler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkBitmapScaler.cpp
diff --git a/src/core/SkBitmapScaler.cpp b/src/core/SkBitmapScaler.cpp
index 599e9d8eb54eba79645da0d353d651d2a3b58c93..ebcccf2fe0eabc6bfd38d53974d347d9cc6695da 100644
--- a/src/core/SkBitmapScaler.cpp
+++ b/src/core/SkBitmapScaler.cpp
@@ -13,8 +13,8 @@ class SkResizeFilter {
public:
SkResizeFilter(SkBitmapScaler::ResizeMethod method,
int srcFullWidth, int srcFullHeight,
- int destWidth, int destHeight,
- const SkIRect& destSubset,
+ float destWidth, float destHeight,
+ const SkRect& destSubset,
const SkConvolutionProcs& convolveProcs);
~SkResizeFilter() {
SkDELETE( fBitmapFilter );
@@ -40,7 +40,7 @@ private:
// for the transform is also specified.
void computeFilters(int srcSize,
- int destSubsetLo, int destSubsetSize,
+ float destSubsetLo, float destSubsetSize,
float scale,
SkConvolutionFilter1D* output,
const SkConvolutionProcs& convolveProcs);
@@ -51,8 +51,8 @@ private:
SkResizeFilter::SkResizeFilter(SkBitmapScaler::ResizeMethod method,
int srcFullWidth, int srcFullHeight,
- int destWidth, int destHeight,
- const SkIRect& destSubset,
+ float destWidth, float destHeight,
+ const SkRect& destSubset,
const SkConvolutionProcs& convolveProcs) {
// method will only ever refer to an "algorithm method".
@@ -82,10 +82,8 @@ SkResizeFilter::SkResizeFilter(SkBitmapScaler::ResizeMethod method,
}
- float scaleX = static_cast<float>(destWidth) /
- static_cast<float>(srcFullWidth);
- float scaleY = static_cast<float>(destHeight) /
- static_cast<float>(srcFullHeight);
+ float scaleX = destWidth / srcFullWidth;
+ float scaleY = destHeight / srcFullHeight;
this->computeFilters(srcFullWidth, destSubset.fLeft, destSubset.width(),
scaleX, &fXFilter, convolveProcs);
@@ -112,11 +110,11 @@ SkResizeFilter::SkResizeFilter(SkBitmapScaler::ResizeMethod method,
// the coefficients can be shared. For periods of 1 we can consider
// loading the factors only once outside the borders.
void SkResizeFilter::computeFilters(int srcSize,
- int destSubsetLo, int destSubsetSize,
+ float destSubsetLo, float destSubsetSize,
float scale,
SkConvolutionFilter1D* output,
const SkConvolutionProcs& convolveProcs) {
- int destSubsetHi = destSubsetLo + destSubsetSize; // [lo, hi)
+ float destSubsetHi = destSubsetLo + destSubsetSize; // [lo, hi)
// When we're doing a magnification, the scale will be larger than one. This
// means the destination pixels are much smaller than the source pixels, and
@@ -138,7 +136,7 @@ void SkResizeFilter::computeFilters(int srcSize,
// Loop over all pixels in the output range. We will generate one set of
// filter values for each one. Those values will tell us how to blend the
// source pixels to compute the destination pixel.
- for (int destSubsetI = destSubsetLo; destSubsetI < destSubsetHi;
+ for (int destSubsetI = SkScalarFloorToInt(destSubsetLo); destSubsetI < SkScalarCeilToInt(destSubsetHi);
destSubsetI++) {
// Reset the arrays. We don't declare them inside so they can re-use the
// same malloc-ed buffer.
@@ -247,22 +245,23 @@ static SkBitmapScaler::ResizeMethod ResizeMethodToAlgorithmMethod(
bool SkBitmapScaler::Resize(SkBitmap* resultPtr,
const SkBitmap& source,
ResizeMethod method,
- int destWidth, int destHeight,
- const SkIRect& destSubset,
+ float destWidth, float destHeight,
const SkConvolutionProcs& convolveProcs,
SkBitmap::Allocator* allocator) {
+
+ SkRect destSubset = { 0, 0, destWidth, destHeight };
+
// Ensure that the ResizeMethod enumeration is sound.
SkASSERT(((RESIZE_FIRST_QUALITY_METHOD <= method) &&
(method <= RESIZE_LAST_QUALITY_METHOD)) ||
((RESIZE_FIRST_ALGORITHM_METHOD <= method) &&
(method <= RESIZE_LAST_ALGORITHM_METHOD)));
- SkIRect dest = { 0, 0, destWidth, destHeight };
+ SkRect dest = { 0, 0, destWidth, destHeight };
if (!dest.contains(destSubset)) {
SkErrorInternals::SetError( kInvalidArgument_SkError,
- "Sorry, you passed me a bitmap resize "
- " method I have never heard of: %d",
- method );
+ "Sorry, the destination bitmap scale subset "
+ "falls outside the full destination bitmap." );
}
// If the size of source or destination is 0, i.e. 0x0, 0xN or Nx0, just
@@ -297,8 +296,8 @@ bool SkBitmapScaler::Resize(SkBitmap* resultPtr,
// Convolve into the result.
SkBitmap result;
- result.setConfig(SkImageInfo::MakeN32(destSubset.width(),
- destSubset.height(),
+ result.setConfig(SkImageInfo::MakeN32(SkScalarCeilToInt(destSubset.width()),
+ SkScalarCeilToInt(destSubset.height()),
source.alphaType()));
result.allocPixels(allocator, NULL);
if (!result.readyToDraw()) {
@@ -316,15 +315,3 @@ bool SkBitmapScaler::Resize(SkBitmap* resultPtr,
SkASSERT(NULL != resultPtr->getPixels());
return true;
}
-
-// static
-bool SkBitmapScaler::Resize(SkBitmap* resultPtr,
- const SkBitmap& source,
- ResizeMethod method,
- int destWidth, int destHeight,
- const SkConvolutionProcs& convolveProcs,
- SkBitmap::Allocator* allocator) {
- SkIRect destSubset = { 0, 0, destWidth, destHeight };
- return Resize(resultPtr, source, method, destWidth, destHeight, destSubset,
- convolveProcs, allocator);
-}
« no previous file with comments | « src/core/SkBitmapScaler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698