aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2015-06-12 07:09:59 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-12 07:09:59 -0700
commit3c834324d9a53659999ea496124a3e41001c5f1b (patch)
treecc6a6a8fce3812cb36d2d49a8204049ae07e4a24 /src
parent74d614a0448f916963468afa756d922f651c9d30 (diff)
change Resize to take pixmap for src
Diffstat (limited to 'src')
-rw-r--r--src/core/SkBitmapController.cpp11
-rw-r--r--src/core/SkBitmapScaler.cpp80
-rw-r--r--src/core/SkBitmapScaler.h7
3 files changed, 44 insertions, 54 deletions
diff --git a/src/core/SkBitmapController.cpp b/src/core/SkBitmapController.cpp
index dd7eb6f36f..c8164a35c7 100644
--- a/src/core/SkBitmapController.cpp
+++ b/src/core/SkBitmapController.cpp
@@ -122,11 +122,12 @@ bool SkDefaultBitmapControllerState::processHQRequest(const SkBitmap& origBitmap
SkScalar roundedDestHeight = SkScalarRoundToScalar(trueDestHeight);
if (!SkBitmapCache::Find(origBitmap, roundedDestWidth, roundedDestHeight, &fResultBitmap)) {
- if (!SkBitmapScaler::Resize(&fResultBitmap,
- origBitmap,
- SkBitmapScaler::RESIZE_BEST,
- roundedDestWidth,
- roundedDestHeight,
+ SkAutoPixmapUnlock src;
+ if (!origBitmap.requestLock(&src)) {
+ return false;
+ }
+ if (!SkBitmapScaler::Resize(&fResultBitmap, src.pixmap(), SkBitmapScaler::RESIZE_BEST,
+ roundedDestWidth, roundedDestHeight,
SkResourceCache::GetAllocator())) {
return false; // we failed to create fScaledBitmap
}
diff --git a/src/core/SkBitmapScaler.cpp b/src/core/SkBitmapScaler.cpp
index 57b6b93e4e..84b926ec34 100644
--- a/src/core/SkBitmapScaler.cpp
+++ b/src/core/SkBitmapScaler.cpp
@@ -248,73 +248,65 @@ static SkBitmapScaler::ResizeMethod ResizeMethodToAlgorithmMethod(
}
}
-// static
-bool SkBitmapScaler::Resize(SkBitmap* resultPtr,
- const SkBitmap& source,
- ResizeMethod method,
+bool SkBitmapScaler::Resize(SkBitmap* resultPtr, const SkPixmap& source, ResizeMethod method,
float destWidth, float destHeight,
SkBitmap::Allocator* allocator) {
+ if (NULL == source.addr() || source.colorType() != kN32_SkColorType ||
+ source.width() < 1 || source.height() < 1)
+ {
+ return false;
+ }
+
+ if (destWidth < 1 || destHeight < 1) {
+ // todo: seems like we could handle negative dstWidth/Height, since that
+ // is just a negative scale (flip)
+ return false;
+ }
- SkConvolutionProcs convolveProcs= { 0, NULL, NULL, NULL, NULL };
- PlatformConvolutionProcs(&convolveProcs);
+ SkConvolutionProcs convolveProcs= { 0, NULL, NULL, NULL, NULL };
+ PlatformConvolutionProcs(&convolveProcs);
- SkRect destSubset = { 0, 0, destWidth, destHeight };
+ SkRect destSubset = { 0, 0, destWidth, destHeight };
- // Ensure that the ResizeMethod enumeration is sound.
- SkASSERT(((RESIZE_FIRST_QUALITY_METHOD <= method) &&
+ // 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)));
- // If the size of source or destination is 0, i.e. 0x0, 0xN or Nx0, just
- // return empty.
- if (source.width() < 1 || source.height() < 1 ||
- destWidth < 1 || destHeight < 1) {
- // todo: seems like we could handle negative dstWidth/Height, since that
- // is just a negative scale (flip)
- return false;
- }
-
- method = ResizeMethodToAlgorithmMethod(method);
+ method = ResizeMethodToAlgorithmMethod(method);
- // Check that we deal with an "algorithm methods" from this point onward.
- SkASSERT((SkBitmapScaler::RESIZE_FIRST_ALGORITHM_METHOD <= method) &&
+ // Check that we deal with an "algorithm methods" from this point onward.
+ SkASSERT((SkBitmapScaler::RESIZE_FIRST_ALGORITHM_METHOD <= method) &&
(method <= SkBitmapScaler::RESIZE_LAST_ALGORITHM_METHOD));
- SkAutoLockPixels locker(source);
- if (!source.readyToDraw() ||
- source.colorType() != kN32_SkColorType) {
- return false;
- }
-
- SkResizeFilter filter(method, source.width(), source.height(),
+ SkResizeFilter filter(method, source.width(), source.height(),
destWidth, destHeight, destSubset, convolveProcs);
- // Get a source bitmap encompassing this touched area. We construct the
- // offsets and row strides such that it looks like a new bitmap, while
- // referring to the old data.
- const unsigned char* sourceSubset =
- reinterpret_cast<const unsigned char*>(source.getPixels());
+ // Get a subset encompassing this touched area. We construct the
+ // offsets and row strides such that it looks like a new bitmap, while
+ // referring to the old data.
+ const uint8_t* sourceSubset = reinterpret_cast<const uint8_t*>(source.addr());
- // Convolve into the result.
- SkBitmap result;
- result.setInfo(SkImageInfo::MakeN32(SkScalarCeilToInt(destSubset.width()),
+ // Convolve into the result.
+ SkBitmap result;
+ result.setInfo(SkImageInfo::MakeN32(SkScalarCeilToInt(destSubset.width()),
SkScalarCeilToInt(destSubset.height()),
source.alphaType()));
- result.allocPixels(allocator, NULL);
- if (!result.readyToDraw()) {
+ result.allocPixels(allocator, NULL);
+ if (!result.readyToDraw()) {
return false;
- }
+ }
- BGRAConvolve2D(sourceSubset, static_cast<int>(source.rowBytes()),
+ BGRAConvolve2D(sourceSubset, static_cast<int>(source.rowBytes()),
!source.isOpaque(), filter.xFilter(), filter.yFilter(),
static_cast<int>(result.rowBytes()),
static_cast<unsigned char*>(result.getPixels()),
convolveProcs, true);
- *resultPtr = result;
- resultPtr->lockPixels();
- SkASSERT(resultPtr->getPixels());
- return true;
+ *resultPtr = result;
+ resultPtr->lockPixels();
+ SkASSERT(resultPtr->getPixels());
+ return true;
}
diff --git a/src/core/SkBitmapScaler.h b/src/core/SkBitmapScaler.h
index ef559df606..c4c7f0ad0b 100644
--- a/src/core/SkBitmapScaler.h
+++ b/src/core/SkBitmapScaler.h
@@ -79,11 +79,8 @@ public:
RESIZE_LAST_ALGORITHM_METHOD = RESIZE_MITCHELL,
};
- static bool Resize(SkBitmap* result,
- const SkBitmap& source,
- ResizeMethod method,
- float dest_width, float dest_height,
- SkBitmap::Allocator* allocator = NULL);
+ static bool Resize(SkBitmap* result, const SkPixmap& src, ResizeMethod method,
+ float dest_width, float dest_height, SkBitmap::Allocator* = NULL);
/** Platforms can also optionally overwrite the convolution functions
if we have SIMD versions of them.