summaryrefslogtreecommitdiff
path: root/image/Downscaler.cpp
diff options
context:
space:
mode:
authorAndrew Osmond <aosmond@mozilla.com>2018-03-28 14:47:32 -0400
committerwolfbeast <mcwerewolf@gmail.com>2018-04-19 11:37:13 +0200
commit7dcb5b7cd5357b9e4fb76cdd7c7f9447b747c3a9 (patch)
tree54a4abdb29b03b10396d9b292a238b893ee64693 /image/Downscaler.cpp
parent84839cdaed6718ab7f7ca2c9c1ac206bddc95fff (diff)
downloaduxp-7dcb5b7cd5357b9e4fb76cdd7c7f9447b747c3a9.tar.gz
Bug 1409440. r=tnikkel, a=RyanVM
Diffstat (limited to 'image/Downscaler.cpp')
-rw-r--r--image/Downscaler.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/image/Downscaler.cpp b/image/Downscaler.cpp
index 18f09c5961..2ded487a54 100644
--- a/image/Downscaler.cpp
+++ b/image/Downscaler.cpp
@@ -231,6 +231,7 @@ Downscaler::CommitRow()
int32_t inLineToRead = filterOffset + mLinesInBuffer;
MOZ_ASSERT(mCurrentInLine <= inLineToRead, "Reading past end of input");
if (mCurrentInLine == inLineToRead) {
+ MOZ_RELEASE_ASSERT(mLinesInBuffer < mWindowCapacity, "Need more rows than capacity!");
skia::ConvolveHorizontally(mRowBuffer.get(), *mXFilter,
mWindow[mLinesInBuffer++], mHasAlpha,
supports_sse2() || supports_mmi());
@@ -239,7 +240,7 @@ Downscaler::CommitRow()
MOZ_ASSERT(mCurrentOutLine < mTargetSize.height,
"Writing past end of output");
- while (mLinesInBuffer == filterLength) {
+ while (mLinesInBuffer >= filterLength) {
DownscaleInputLine();
if (mCurrentOutLine == mTargetSize.height) {
@@ -340,9 +341,14 @@ Downscaler::DownscaleInputLine()
// Shift the buffer. We're just moving pointers here, so this is cheap.
mLinesInBuffer -= diff;
- mLinesInBuffer = max(mLinesInBuffer, 0);
- for (int32_t i = 0; i < mLinesInBuffer; ++i) {
- swap(mWindow[i], mWindow[filterLength - mLinesInBuffer + i]);
+ mLinesInBuffer = min(max(mLinesInBuffer, 0), mWindowCapacity);
+
+ // If we already have enough rows to satisfy the filter, there is no need
+ // to swap as we won't be writing more before the next convolution.
+ if (filterLength > mLinesInBuffer) {
+ for (int32_t i = 0; i < mLinesInBuffer; ++i) {
+ swap(mWindow[i], mWindow[filterLength - mLinesInBuffer + i]);
+ }
}
}