diff options
author | Andrew Osmond <aosmond@mozilla.com> | 2018-03-28 14:47:32 -0400 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-04-19 11:37:13 +0200 |
commit | 49969faa9189022ce67572f83b1ec9d13c8bd93c (patch) | |
tree | 54a4abdb29b03b10396d9b292a238b893ee64693 /image | |
parent | 2b020e9bbbc54f9c1bb44ef94a8e4382ca0a6558 (diff) | |
download | uxp-49969faa9189022ce67572f83b1ec9d13c8bd93c.tar.gz |
Bug 1409440. r=tnikkel, a=RyanVM
Diffstat (limited to 'image')
-rw-r--r-- | image/Downscaler.cpp | 14 | ||||
-rw-r--r-- | image/DownscalingFilter.h | 14 |
2 files changed, 20 insertions, 8 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]); + } } } diff --git a/image/DownscalingFilter.h b/image/DownscalingFilter.h index 6b0d3b26bd..1485b85c20 100644 --- a/image/DownscalingFilter.h +++ b/image/DownscalingFilter.h @@ -246,6 +246,7 @@ protected: int32_t inputRowToRead = filterOffset + mRowsInWindow; MOZ_ASSERT(mInputRow <= inputRowToRead, "Reading past end of input"); if (mInputRow == inputRowToRead) { + MOZ_RELEASE_ASSERT(mRowsInWindow < mWindowCapacity, "Need more rows than capacity!"); skia::ConvolveHorizontally(mRowBuffer.get(), *mXFilter, mWindow[mRowsInWindow++], mHasAlpha, supports_sse2() || supports_mmi()); @@ -254,7 +255,7 @@ protected: MOZ_ASSERT(mOutputRow < mNext.InputSize().height, "Writing past end of output"); - while (mRowsInWindow == filterLength) { + while (mRowsInWindow >= filterLength) { DownscaleInputRow(); if (mOutputRow == mNext.InputSize().height) { @@ -330,9 +331,14 @@ private: // Shift the buffer. We're just moving pointers here, so this is cheap. mRowsInWindow -= diff; - mRowsInWindow = std::max(mRowsInWindow, 0); - for (int32_t i = 0; i < mRowsInWindow; ++i) { - std::swap(mWindow[i], mWindow[filterLength - mRowsInWindow + i]); + mRowsInWindow = std::min(std::max(mRowsInWindow, 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 > mRowsInWindow) { + for (int32_t i = 0; i < mRowsInWindow; ++i) { + std::swap(mWindow[i], mWindow[filterLength - mRowsInWindow + i]); + } } } |