From f3b1eb4ea262e48c93db8f0975e16341596cd8ec Mon Sep 17 00:00:00 2001 From: "epoger@google.com" Date: Tue, 27 May 2014 21:12:42 +0000 Subject: Manual SVN revert of https://code.google.com/p/skia/source/detail?r=14905 git-svn-id: http://skia.googlecode.com/svn/trunk@14907 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkBitmapProcState.cpp | 11 ++------- src/core/SkBitmapScaler.cpp | 51 ++++++++++++++++++++++++++---------------- src/core/SkBitmapScaler.h | 20 ++++++++++++++++- 3 files changed, 53 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/core/SkBitmapProcState.cpp b/src/core/SkBitmapProcState.cpp index 220eb56316..eecfbbcc48 100644 --- a/src/core/SkBitmapProcState.cpp +++ b/src/core/SkBitmapProcState.cpp @@ -15,7 +15,6 @@ #include "SkMipMap.h" #include "SkPixelRef.h" #include "SkScaledImageCache.h" -#include "SkImageEncoder.h" #if !SK_ARM_NEON_IS_NONE // These are defined in src/opts/SkBitmapProcState_arm_neon.cpp @@ -167,13 +166,8 @@ bool SkBitmapProcState::possiblyScaleImage() { } if (NULL == fScaledCacheID) { - float dest_width = fOrigBitmap.width() / invScaleX; - float dest_height = fOrigBitmap.height() / invScaleY; - -#ifdef SK_IGNORE_CORRECT_HIGH_QUALITY_IMAGE_SCALE - dest_width = SkScalarCeilToScalar(dest_width); - dest_height = SkScalarCeilToScalar(dest_height); -#endif + int dest_width = SkScalarCeilToInt(fOrigBitmap.width() / invScaleX); + int dest_height = SkScalarCeilToInt(fOrigBitmap.height() / invScaleY); // All the criteria are met; let's make a new bitmap. @@ -193,7 +187,6 @@ bool SkBitmapProcState::possiblyScaleImage() { return false; } - SkASSERT(NULL != fScaledBitmap.getPixels()); fScaledCacheID = SkScaledImageCache::AddAndLock(fOrigBitmap, invScaleX, diff --git a/src/core/SkBitmapScaler.cpp b/src/core/SkBitmapScaler.cpp index ebcccf2fe0..599e9d8eb5 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, - float destWidth, float destHeight, - const SkRect& destSubset, + int destWidth, int destHeight, + const SkIRect& destSubset, const SkConvolutionProcs& convolveProcs); ~SkResizeFilter() { SkDELETE( fBitmapFilter ); @@ -40,7 +40,7 @@ private: // for the transform is also specified. void computeFilters(int srcSize, - float destSubsetLo, float destSubsetSize, + int destSubsetLo, int destSubsetSize, float scale, SkConvolutionFilter1D* output, const SkConvolutionProcs& convolveProcs); @@ -51,8 +51,8 @@ private: SkResizeFilter::SkResizeFilter(SkBitmapScaler::ResizeMethod method, int srcFullWidth, int srcFullHeight, - float destWidth, float destHeight, - const SkRect& destSubset, + int destWidth, int destHeight, + const SkIRect& destSubset, const SkConvolutionProcs& convolveProcs) { // method will only ever refer to an "algorithm method". @@ -82,8 +82,10 @@ SkResizeFilter::SkResizeFilter(SkBitmapScaler::ResizeMethod method, } - float scaleX = destWidth / srcFullWidth; - float scaleY = destHeight / srcFullHeight; + float scaleX = static_cast(destWidth) / + static_cast(srcFullWidth); + float scaleY = static_cast(destHeight) / + static_cast(srcFullHeight); this->computeFilters(srcFullWidth, destSubset.fLeft, destSubset.width(), scaleX, &fXFilter, convolveProcs); @@ -110,11 +112,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, - float destSubsetLo, float destSubsetSize, + int destSubsetLo, int destSubsetSize, float scale, SkConvolutionFilter1D* output, const SkConvolutionProcs& convolveProcs) { - float destSubsetHi = destSubsetLo + destSubsetSize; // [lo, hi) + int 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 @@ -136,7 +138,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 = SkScalarFloorToInt(destSubsetLo); destSubsetI < SkScalarCeilToInt(destSubsetHi); + for (int destSubsetI = destSubsetLo; destSubsetI < destSubsetHi; destSubsetI++) { // Reset the arrays. We don't declare them inside so they can re-use the // same malloc-ed buffer. @@ -245,23 +247,22 @@ static SkBitmapScaler::ResizeMethod ResizeMethodToAlgorithmMethod( bool SkBitmapScaler::Resize(SkBitmap* resultPtr, const SkBitmap& source, ResizeMethod method, - float destWidth, float destHeight, + int destWidth, int destHeight, + const SkIRect& destSubset, 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))); - SkRect dest = { 0, 0, destWidth, destHeight }; + SkIRect dest = { 0, 0, destWidth, destHeight }; if (!dest.contains(destSubset)) { SkErrorInternals::SetError( kInvalidArgument_SkError, - "Sorry, the destination bitmap scale subset " - "falls outside the full destination bitmap." ); + "Sorry, you passed me a bitmap resize " + " method I have never heard of: %d", + method ); } // If the size of source or destination is 0, i.e. 0x0, 0xN or Nx0, just @@ -296,8 +297,8 @@ bool SkBitmapScaler::Resize(SkBitmap* resultPtr, // Convolve into the result. SkBitmap result; - result.setConfig(SkImageInfo::MakeN32(SkScalarCeilToInt(destSubset.width()), - SkScalarCeilToInt(destSubset.height()), + result.setConfig(SkImageInfo::MakeN32(destSubset.width(), + destSubset.height(), source.alphaType())); result.allocPixels(allocator, NULL); if (!result.readyToDraw()) { @@ -315,3 +316,15 @@ 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); +} diff --git a/src/core/SkBitmapScaler.h b/src/core/SkBitmapScaler.h index d6636cf34e..c8d8a84185 100644 --- a/src/core/SkBitmapScaler.h +++ b/src/core/SkBitmapScaler.h @@ -79,10 +79,28 @@ public: RESIZE_LAST_ALGORITHM_METHOD = RESIZE_MITCHELL, }; + // Resizes the given source bitmap using the specified resize method, so that + // the entire image is (dest_size) big. The dest_subset is the rectangle in + // this destination image that should actually be returned. + // + // The output image will be (dest_subset.width(), dest_subset.height()). This + // will save work if you do not need the entire bitmap. + // + // The destination subset must be smaller than the destination image. static bool Resize(SkBitmap* result, const SkBitmap& source, ResizeMethod method, - float dest_width, float dest_height, + int dest_width, int dest_height, + const SkIRect& dest_subset, + const SkConvolutionProcs&, + SkBitmap::Allocator* allocator = NULL); + + // Alternate version for resizing and returning the entire bitmap rather than + // a subset. + static bool Resize(SkBitmap* result, + const SkBitmap& source, + ResizeMethod method, + int dest_width, int dest_height, const SkConvolutionProcs&, SkBitmap::Allocator* allocator = NULL); }; -- cgit v1.2.3