Bug 1146335 (Part 1) - Add assertions and fix style issues in image::Downscaler. r=tn

This commit is contained in:
Seth Fowler 2015-04-09 17:52:23 -07:00
parent 815da01ea9
commit b7b4c9d054

View File

@ -77,13 +77,15 @@ Downscaler::BeginFrame(const nsIntSize& aOriginalSize,
auto resizeMethod = skia::ImageOperations::RESIZE_LANCZOS3;
skia::resize::ComputeFilters(resizeMethod, mOriginalSize.width,
mTargetSize.width, 0,
mTargetSize.width, mXFilter.get());
skia::resize::ComputeFilters(resizeMethod,
mOriginalSize.width, mTargetSize.width,
0, mTargetSize.width,
mXFilter.get());
skia::resize::ComputeFilters(resizeMethod, mOriginalSize.height,
mTargetSize.height, 0,
mTargetSize.height, mYFilter.get());
skia::resize::ComputeFilters(resizeMethod,
mOriginalSize.height, mTargetSize.height,
0, mTargetSize.height,
mYFilter.get());
// Allocate the buffer, which contains scanlines of the original image.
mRowBuffer = MakeUnique<uint8_t[]>(mOriginalSize.width * sizeof(uint32_t));
@ -126,6 +128,18 @@ Downscaler::ResetForNextProgressivePass()
mLinesInBuffer = 0;
}
static void
GetFilterOffsetAndLength(UniquePtr<skia::ConvolutionFilter1D>& aFilter,
int32_t aOutputImagePosition,
int32_t* aFilterOffsetOut,
int32_t* aFilterLengthOut)
{
MOZ_ASSERT(aOutputImagePosition < aFilter->num_values());
aFilter->FilterForValue(aOutputImagePosition,
aFilterOffsetOut,
aFilterLengthOut);
}
void
Downscaler::CommitRow()
{
@ -135,7 +149,8 @@ Downscaler::CommitRow()
int32_t filterOffset = 0;
int32_t filterLength = 0;
mYFilter->FilterForValue(mCurrentOutLine, &filterOffset, &filterLength);
GetFilterOffsetAndLength(mYFilter, mCurrentOutLine,
&filterOffset, &filterLength);
int32_t inLineToRead = filterOffset + mLinesInBuffer;
MOZ_ASSERT(mCurrentInLine <= inLineToRead, "Reading past end of input");
@ -148,7 +163,9 @@ Downscaler::CommitRow()
while (mLinesInBuffer == filterLength &&
mCurrentOutLine < mTargetSize.height) {
DownscaleInputLine();
mYFilter->FilterForValue(mCurrentOutLine, &filterOffset, &filterLength);
GetFilterOffsetAndLength(mYFilter, mCurrentOutLine,
&filterOffset, &filterLength);
}
mCurrentInLine += 1;
@ -184,6 +201,7 @@ Downscaler::DownscaleInputLine()
int32_t filterOffset = 0;
int32_t filterLength = 0;
MOZ_ASSERT(mCurrentOutLine < mYFilter->num_values());
auto filterValues =
mYFilter->FilterForValue(mCurrentOutLine, &filterOffset, &filterLength);
@ -202,7 +220,8 @@ Downscaler::DownscaleInputLine()
int32_t newFilterOffset = 0;
int32_t newFilterLength = 0;
mYFilter->FilterForValue(mCurrentOutLine, &newFilterOffset, &newFilterLength);
GetFilterOffsetAndLength(mYFilter, mCurrentOutLine,
&newFilterOffset, &newFilterLength);
int diff = newFilterOffset - filterOffset;
MOZ_ASSERT(diff >= 0, "Moving backwards in the filter?");