2015-09-28 11:40:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
|
|
#include "Downscaler.h"
|
2015-12-30 14:03:24 -08:00
|
|
|
#include "mozilla/UniquePtrExtensions.h"
|
2015-09-28 11:40:00 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace image {
|
|
|
|
|
|
|
|
Deinterlacer::Deinterlacer(const nsIntSize& aImageSize)
|
|
|
|
: mImageSize(aImageSize)
|
2015-12-30 14:03:24 -08:00
|
|
|
{
|
|
|
|
CheckedInt<size_t> bufferSize = mImageSize.width;
|
|
|
|
bufferSize *= mImageSize.height;
|
|
|
|
bufferSize *= sizeof(uint32_t);
|
|
|
|
|
|
|
|
if (!bufferSize.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBuffer = MakeUniqueFallible<uint8_t[]>(bufferSize.value());
|
|
|
|
}
|
2015-09-28 11:40:00 -07:00
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Deinterlacer::RowSize() const
|
|
|
|
{
|
|
|
|
return mImageSize.width * sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t*
|
|
|
|
Deinterlacer::RowBuffer(uint32_t aRow)
|
|
|
|
{
|
|
|
|
uint32_t offset = aRow * RowSize();
|
2015-12-30 14:03:24 -08:00
|
|
|
MOZ_ASSERT(IsValid(), "Deinterlacer in invalid state");
|
2015-09-28 11:40:00 -07:00
|
|
|
MOZ_ASSERT(offset < mImageSize.width * mImageSize.height * sizeof(uint32_t),
|
|
|
|
"Row is outside of image");
|
|
|
|
return mBuffer.get() + offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Deinterlacer::PropagatePassToDownscaler(Downscaler& aDownscaler)
|
|
|
|
{
|
2015-12-30 14:03:24 -08:00
|
|
|
MOZ_ASSERT(IsValid(), "Deinterlacer in invalid state");
|
2015-09-28 11:40:00 -07:00
|
|
|
for (int32_t row = 0 ; row < mImageSize.height ; ++row) {
|
|
|
|
memcpy(aDownscaler.RowBuffer(), RowBuffer(row), RowSize());
|
|
|
|
aDownscaler.CommitRow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|