summaryrefslogtreecommitdiffstats
path: root/image/Downscaler.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-04-19 12:08:25 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-04-19 12:08:25 +0200
commitd7df65954a585e97ccee21fa9cb50cb116efddcc (patch)
tree9ed9a1f46f5d2e8373dcab553bad55b54bb8103b /image/Downscaler.cpp
parentba71cc45fef6dfaecef8f5edf65ce1f1ff457624 (diff)
parent9135a11e8c8f0837738fd976b28d36a53fd1de27 (diff)
downloadUXP-d7df65954a585e97ccee21fa9cb50cb116efddcc.tar
UXP-d7df65954a585e97ccee21fa9cb50cb116efddcc.tar.gz
UXP-d7df65954a585e97ccee21fa9cb50cb116efddcc.tar.lz
UXP-d7df65954a585e97ccee21fa9cb50cb116efddcc.tar.xz
UXP-d7df65954a585e97ccee21fa9cb50cb116efddcc.zip
Merge branch 'ported-upstream'
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 18f09c596..2ded487a5 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]);
+ }
}
}