diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-04-19 12:08:25 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-04-19 12:08:25 +0200 |
commit | d7df65954a585e97ccee21fa9cb50cb116efddcc (patch) | |
tree | 9ed9a1f46f5d2e8373dcab553bad55b54bb8103b /image/DownscalingFilter.h | |
parent | ba71cc45fef6dfaecef8f5edf65ce1f1ff457624 (diff) | |
parent | 9135a11e8c8f0837738fd976b28d36a53fd1de27 (diff) | |
download | UXP-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/DownscalingFilter.h')
-rw-r--r-- | image/DownscalingFilter.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/image/DownscalingFilter.h b/image/DownscalingFilter.h index 6b0d3b26b..1485b85c2 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]); + } } } |