зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1463244 - cleanup of swizzle stride calculations. r=rhunt
MozReview-Commit-ID: GMXRKnu8zHB
This commit is contained in:
Родитель
bf36928a04
Коммит
2f14d46de8
|
@ -157,9 +157,16 @@ SurfaceToPackedBGRA(DataSourceSurface *aSurface)
|
||||||
}
|
}
|
||||||
|
|
||||||
IntSize size = aSurface->GetSize();
|
IntSize size = aSurface->GetSize();
|
||||||
|
if (size.width < 0 || size.width >= INT32_MAX / 4) {
|
||||||
UniquePtr<uint8_t[]> imageBuffer(
|
return nullptr;
|
||||||
new (std::nothrow) uint8_t[size.width * size.height * sizeof(uint32_t)]);
|
}
|
||||||
|
int32_t stride = size.width * 4;
|
||||||
|
CheckedInt<size_t> bufferSize =
|
||||||
|
CheckedInt<size_t>(stride) * CheckedInt<size_t>(size.height);
|
||||||
|
if (!bufferSize.isValid()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
UniquePtr<uint8_t[]> imageBuffer(new (std::nothrow) uint8_t[bufferSize.value()]);
|
||||||
if (!imageBuffer) {
|
if (!imageBuffer) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -170,14 +177,14 @@ SurfaceToPackedBGRA(DataSourceSurface *aSurface)
|
||||||
}
|
}
|
||||||
|
|
||||||
CopySurfaceDataToPackedArray(map.mData, imageBuffer.get(), size,
|
CopySurfaceDataToPackedArray(map.mData, imageBuffer.get(), size,
|
||||||
map.mStride, 4 * sizeof(uint8_t));
|
map.mStride, 4);
|
||||||
|
|
||||||
aSurface->Unmap();
|
aSurface->Unmap();
|
||||||
|
|
||||||
if (format == SurfaceFormat::B8G8R8X8) {
|
if (format == SurfaceFormat::B8G8R8X8) {
|
||||||
// Convert BGRX to BGRA by setting a to 255.
|
// Convert BGRX to BGRA by setting a to 255.
|
||||||
SwizzleData(imageBuffer.get(), size.width * sizeof(uint32_t), SurfaceFormat::X8R8G8B8_UINT32,
|
SwizzleData(imageBuffer.get(), stride, SurfaceFormat::X8R8G8B8_UINT32,
|
||||||
imageBuffer.get(), size.width * sizeof(uint32_t), SurfaceFormat::A8R8G8B8_UINT32,
|
imageBuffer.get(), stride, SurfaceFormat::A8R8G8B8_UINT32,
|
||||||
size);
|
size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,8 +203,16 @@ SurfaceToPackedBGR(DataSourceSurface *aSurface)
|
||||||
}
|
}
|
||||||
|
|
||||||
IntSize size = aSurface->GetSize();
|
IntSize size = aSurface->GetSize();
|
||||||
|
if (size.width < 0 || size.width >= INT32_MAX / 3) {
|
||||||
uint8_t* imageBuffer = new (std::nothrow) uint8_t[size.width * size.height * 3 * sizeof(uint8_t)];
|
return nullptr;
|
||||||
|
}
|
||||||
|
int32_t stride = size.width * 3;
|
||||||
|
CheckedInt<size_t> bufferSize =
|
||||||
|
CheckedInt<size_t>(stride) * CheckedInt<size_t>(size.height);
|
||||||
|
if (!bufferSize.isValid()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
uint8_t* imageBuffer = new (std::nothrow) uint8_t[bufferSize.value()];
|
||||||
if (!imageBuffer) {
|
if (!imageBuffer) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -209,7 +224,7 @@ SurfaceToPackedBGR(DataSourceSurface *aSurface)
|
||||||
}
|
}
|
||||||
|
|
||||||
SwizzleData(map.mData, map.mStride, SurfaceFormat::B8G8R8X8,
|
SwizzleData(map.mData, map.mStride, SurfaceFormat::B8G8R8X8,
|
||||||
imageBuffer, size.width * 3, SurfaceFormat::B8G8R8,
|
imageBuffer, stride, SurfaceFormat::B8G8R8,
|
||||||
size);
|
size);
|
||||||
|
|
||||||
aSurface->Unmap();
|
aSurface->Unmap();
|
||||||
|
|
|
@ -259,7 +259,8 @@ static inline IntSize
|
||||||
CollapseSize(const IntSize& aSize, int32_t aSrcStride, int32_t aDstStride)
|
CollapseSize(const IntSize& aSize, int32_t aSrcStride, int32_t aDstStride)
|
||||||
{
|
{
|
||||||
if (aSrcStride == aDstStride &&
|
if (aSrcStride == aDstStride &&
|
||||||
aSrcStride == 4 * aSize.width) {
|
(aSrcStride & 3) == 0 &&
|
||||||
|
aSrcStride / 4 == aSize.width) {
|
||||||
CheckedInt32 area = CheckedInt32(aSize.width) * CheckedInt32(aSize.height);
|
CheckedInt32 area = CheckedInt32(aSize.width) * CheckedInt32(aSize.height);
|
||||||
if (area.isValid()) {
|
if (area.isValid()) {
|
||||||
return IntSize(area.value(), 1);
|
return IntSize(area.value(), 1);
|
||||||
|
@ -268,6 +269,16 @@ CollapseSize(const IntSize& aSize, int32_t aSrcStride, int32_t aDstStride)
|
||||||
return aSize;
|
return aSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int32_t
|
||||||
|
GetStrideGap(int32_t aWidth, SurfaceFormat aFormat, int32_t aStride)
|
||||||
|
{
|
||||||
|
CheckedInt32 used = CheckedInt32(aWidth) * BytesPerPixel(aFormat);
|
||||||
|
if (!used.isValid() || used.value() < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return aStride - used.value();
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PremultiplyData(const uint8_t* aSrc, int32_t aSrcStride, SurfaceFormat aSrcFormat,
|
PremultiplyData(const uint8_t* aSrc, int32_t aSrcStride, SurfaceFormat aSrcFormat,
|
||||||
uint8_t* aDst, int32_t aDstStride, SurfaceFormat aDstFormat,
|
uint8_t* aDst, int32_t aDstStride, SurfaceFormat aDstFormat,
|
||||||
|
@ -278,9 +289,12 @@ PremultiplyData(const uint8_t* aSrc, int32_t aSrcStride, SurfaceFormat aSrcForma
|
||||||
}
|
}
|
||||||
IntSize size = CollapseSize(aSize, aSrcStride, aDstStride);
|
IntSize size = CollapseSize(aSize, aSrcStride, aDstStride);
|
||||||
// Find gap from end of row to the start of the next row.
|
// Find gap from end of row to the start of the next row.
|
||||||
int32_t srcGap = aSrcStride - BytesPerPixel(aSrcFormat) * aSize.width;
|
int32_t srcGap = GetStrideGap(aSize.width, aSrcFormat, aSrcStride);
|
||||||
int32_t dstGap = aDstStride - BytesPerPixel(aDstFormat) * aSize.width;
|
int32_t dstGap = GetStrideGap(aSize.width, aDstFormat, aDstStride);
|
||||||
MOZ_ASSERT(srcGap >= 0 && dstGap >= 0);
|
MOZ_ASSERT(srcGap >= 0 && dstGap >= 0);
|
||||||
|
if (srcGap < 0 || dstGap < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#define FORMAT_CASE_CALL(...) __VA_ARGS__(aSrc, srcGap, aDst, dstGap, size)
|
#define FORMAT_CASE_CALL(...) __VA_ARGS__(aSrc, srcGap, aDst, dstGap, size)
|
||||||
|
|
||||||
|
@ -404,9 +418,12 @@ UnpremultiplyData(const uint8_t* aSrc, int32_t aSrcStride, SurfaceFormat aSrcFor
|
||||||
}
|
}
|
||||||
IntSize size = CollapseSize(aSize, aSrcStride, aDstStride);
|
IntSize size = CollapseSize(aSize, aSrcStride, aDstStride);
|
||||||
// Find gap from end of row to the start of the next row.
|
// Find gap from end of row to the start of the next row.
|
||||||
int32_t srcGap = aSrcStride - BytesPerPixel(aSrcFormat) * aSize.width;
|
int32_t srcGap = GetStrideGap(aSize.width, aSrcFormat, aSrcStride);
|
||||||
int32_t dstGap = aDstStride - BytesPerPixel(aDstFormat) * aSize.width;
|
int32_t dstGap = GetStrideGap(aSize.width, aDstFormat, aDstStride);
|
||||||
MOZ_ASSERT(srcGap >= 0 && dstGap >= 0);
|
MOZ_ASSERT(srcGap >= 0 && dstGap >= 0);
|
||||||
|
if (srcGap < 0 || dstGap < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#define FORMAT_CASE_CALL(...) __VA_ARGS__(aSrc, srcGap, aDst, dstGap, size)
|
#define FORMAT_CASE_CALL(...) __VA_ARGS__(aSrc, srcGap, aDst, dstGap, size)
|
||||||
|
|
||||||
|
@ -702,9 +719,12 @@ SwizzleData(const uint8_t* aSrc, int32_t aSrcStride, SurfaceFormat aSrcFormat,
|
||||||
}
|
}
|
||||||
IntSize size = CollapseSize(aSize, aSrcStride, aDstStride);
|
IntSize size = CollapseSize(aSize, aSrcStride, aDstStride);
|
||||||
// Find gap from end of row to the start of the next row.
|
// Find gap from end of row to the start of the next row.
|
||||||
int32_t srcGap = aSrcStride - BytesPerPixel(aSrcFormat) * aSize.width;
|
int32_t srcGap = GetStrideGap(aSize.width, aSrcFormat, aSrcStride);
|
||||||
int32_t dstGap = aDstStride - BytesPerPixel(aDstFormat) * aSize.width;
|
int32_t dstGap = GetStrideGap(aSize.width, aDstFormat, aDstStride);
|
||||||
MOZ_ASSERT(srcGap >= 0 && dstGap >= 0);
|
MOZ_ASSERT(srcGap >= 0 && dstGap >= 0);
|
||||||
|
if (srcGap < 0 || dstGap < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#define FORMAT_CASE_CALL(...) __VA_ARGS__(aSrc, srcGap, aDst, dstGap, size)
|
#define FORMAT_CASE_CALL(...) __VA_ARGS__(aSrc, srcGap, aDst, dstGap, size)
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче