mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1218823 - use UniquePtr<> in preference to delete[] in image/; r=seth
This commit is contained in:
parent
f5a7d91c7c
commit
edc9df0468
@ -273,15 +273,13 @@ private:
|
|||||||
, mLength(0)
|
, mLength(0)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(aCapacity > 0, "Creating zero-capacity chunk");
|
MOZ_ASSERT(aCapacity > 0, "Creating zero-capacity chunk");
|
||||||
mData = new (fallible) char[mCapacity];
|
mData.reset(new (fallible) char[mCapacity]);
|
||||||
}
|
}
|
||||||
|
|
||||||
~Chunk() { delete[] mData; }
|
|
||||||
|
|
||||||
Chunk(Chunk&& aOther)
|
Chunk(Chunk&& aOther)
|
||||||
: mCapacity(aOther.mCapacity)
|
: mCapacity(aOther.mCapacity)
|
||||||
, mLength(aOther.mLength)
|
, mLength(aOther.mLength)
|
||||||
, mData(aOther.mData)
|
, mData(Move(aOther.mData))
|
||||||
{
|
{
|
||||||
aOther.mCapacity = aOther.mLength = 0;
|
aOther.mCapacity = aOther.mLength = 0;
|
||||||
aOther.mData = nullptr;
|
aOther.mData = nullptr;
|
||||||
@ -291,7 +289,7 @@ private:
|
|||||||
{
|
{
|
||||||
mCapacity = aOther.mCapacity;
|
mCapacity = aOther.mCapacity;
|
||||||
mLength = aOther.mLength;
|
mLength = aOther.mLength;
|
||||||
mData = aOther.mData;
|
mData = Move(aOther.mData);
|
||||||
aOther.mCapacity = aOther.mLength = 0;
|
aOther.mCapacity = aOther.mLength = 0;
|
||||||
aOther.mData = nullptr;
|
aOther.mData = nullptr;
|
||||||
return *this;
|
return *this;
|
||||||
@ -304,7 +302,7 @@ private:
|
|||||||
char* Data() const
|
char* Data() const
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mData, "Allocation failed but nobody checked for it");
|
MOZ_ASSERT(mData, "Allocation failed but nobody checked for it");
|
||||||
return mData;
|
return mData.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddLength(size_t aAdditionalLength)
|
void AddLength(size_t aAdditionalLength)
|
||||||
@ -319,7 +317,7 @@ private:
|
|||||||
|
|
||||||
size_t mCapacity;
|
size_t mCapacity;
|
||||||
size_t mLength;
|
size_t mLength;
|
||||||
char* mData;
|
UniquePtr<char[]> mData;
|
||||||
};
|
};
|
||||||
|
|
||||||
nsresult AppendChunk(Maybe<Chunk>&& aChunk);
|
nsresult AppendChunk(Maybe<Chunk>&& aChunk);
|
||||||
|
@ -575,11 +575,11 @@ nsIconChannel::MakeInputStream(nsIInputStream** _retval, bool aNonBlocking)
|
|||||||
colorHeader.biSizeImage +
|
colorHeader.biSizeImage +
|
||||||
maskHeader.biSizeImage;
|
maskHeader.biSizeImage;
|
||||||
|
|
||||||
char* buffer = new char[iconSize];
|
UniquePtr<char[]> buffer = MakeUnique<char[]>(iconSize);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
} else {
|
} else {
|
||||||
char* whereTo = buffer;
|
char* whereTo = buffer.get();
|
||||||
int howMuch;
|
int howMuch;
|
||||||
|
|
||||||
// the data starts with an icon file header
|
// the data starts with an icon file header
|
||||||
@ -640,7 +640,7 @@ nsIconChannel::MakeInputStream(nsIInputStream** _retval, bool aNonBlocking)
|
|||||||
iconSize, iconSize, aNonBlocking);
|
iconSize, iconSize, aNonBlocking);
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
uint32_t written;
|
uint32_t written;
|
||||||
rv = outStream->Write(buffer, iconSize, &written);
|
rv = outStream->Write(buffer.get(), iconSize, &written);
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
NS_ADDREF(*_retval = inStream);
|
NS_ADDREF(*_retval = inStream);
|
||||||
}
|
}
|
||||||
@ -650,7 +650,6 @@ nsIconChannel::MakeInputStream(nsIInputStream** _retval, bool aNonBlocking)
|
|||||||
delete maskInfo;
|
delete maskInfo;
|
||||||
} // if we got mask bits
|
} // if we got mask bits
|
||||||
delete colorInfo;
|
delete colorInfo;
|
||||||
delete [] buffer;
|
|
||||||
} // if we allocated the buffer
|
} // if we allocated the buffer
|
||||||
} // if we got mask size
|
} // if we got mask size
|
||||||
|
|
||||||
|
@ -137,7 +137,8 @@ SetPixel(uint32_t*& aDecoded, uint8_t aRed, uint8_t aGreen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
SetPixel(uint32_t*& aDecoded, uint8_t idx, bmp::ColorTableEntry* aColors)
|
SetPixel(uint32_t*& aDecoded, uint8_t idx,
|
||||||
|
const UniquePtr<ColorTableEntry[]>& aColors)
|
||||||
{
|
{
|
||||||
SetPixel(aDecoded,
|
SetPixel(aDecoded,
|
||||||
aColors[idx].mRed, aColors[idx].mGreen, aColors[idx].mBlue);
|
aColors[idx].mRed, aColors[idx].mGreen, aColors[idx].mBlue);
|
||||||
@ -150,7 +151,7 @@ SetPixel(uint32_t*& aDecoded, uint8_t idx, bmp::ColorTableEntry* aColors)
|
|||||||
/// @param aCount Current count. Is decremented by one or two.
|
/// @param aCount Current count. Is decremented by one or two.
|
||||||
static void
|
static void
|
||||||
Set4BitPixel(uint32_t*& aDecoded, uint8_t aData, uint32_t& aCount,
|
Set4BitPixel(uint32_t*& aDecoded, uint8_t aData, uint32_t& aCount,
|
||||||
bmp::ColorTableEntry* aColors)
|
const UniquePtr<ColorTableEntry[]>& aColors)
|
||||||
{
|
{
|
||||||
uint8_t idx = aData >> 4;
|
uint8_t idx = aData >> 4;
|
||||||
SetPixel(aDecoded, idx, aColors);
|
SetPixel(aDecoded, idx, aColors);
|
||||||
@ -191,7 +192,6 @@ nsBMPDecoder::nsBMPDecoder(RasterImage* aImage)
|
|||||||
|
|
||||||
nsBMPDecoder::~nsBMPDecoder()
|
nsBMPDecoder::~nsBMPDecoder()
|
||||||
{
|
{
|
||||||
delete[] mColors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtains the bits per pixel from the internal BIH header.
|
// Obtains the bits per pixel from the internal BIH header.
|
||||||
@ -671,8 +671,8 @@ nsBMPDecoder::ReadBitfields(const char* aData, size_t aLength)
|
|||||||
|
|
||||||
// Always allocate and zero 256 entries, even though mNumColors might be
|
// Always allocate and zero 256 entries, even though mNumColors might be
|
||||||
// smaller, because the file might erroneously index past mNumColors.
|
// smaller, because the file might erroneously index past mNumColors.
|
||||||
mColors = new ColorTableEntry[256];
|
mColors = MakeUnique<ColorTableEntry[]>(256);
|
||||||
memset(mColors, 0, 256 * sizeof(ColorTableEntry));
|
memset(mColors.get(), 0, 256 * sizeof(ColorTableEntry));
|
||||||
|
|
||||||
// OS/2 Bitmaps have no padding byte.
|
// OS/2 Bitmaps have no padding byte.
|
||||||
mBytesPerColor = (mBIH.bihsize == InfoHeaderLength::WIN_V2) ? 3 : 4;
|
mBytesPerColor = (mBIH.bihsize == InfoHeaderLength::WIN_V2) ? 3 : 4;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "Decoder.h"
|
#include "Decoder.h"
|
||||||
#include "gfxColor.h"
|
#include "gfxColor.h"
|
||||||
#include "StreamingLexer.h"
|
#include "StreamingLexer.h"
|
||||||
|
#include "mozilla/UniquePtr.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace image {
|
namespace image {
|
||||||
@ -190,7 +191,7 @@ private:
|
|||||||
|
|
||||||
uint32_t mNumColors; // The number of used colors, i.e. the number of
|
uint32_t mNumColors; // The number of used colors, i.e. the number of
|
||||||
// entries in mColors, if it's present.
|
// entries in mColors, if it's present.
|
||||||
bmp::ColorTableEntry* mColors; // The color table, if it's present.
|
UniquePtr<bmp::ColorTableEntry[]> mColors; // The color table, if it's present.
|
||||||
uint32_t mBytesPerColor; // 3 or 4, depending on the format
|
uint32_t mBytesPerColor; // 3 or 4, depending on the format
|
||||||
|
|
||||||
// The number of bytes prior to the optional gap that have been read. This
|
// The number of bytes prior to the optional gap that have been read. This
|
||||||
|
@ -162,19 +162,19 @@ nsJPEGEncoder::InitFromData(const uint8_t* aData,
|
|||||||
jpeg_write_scanlines(&cinfo, const_cast<uint8_t**>(&row), 1);
|
jpeg_write_scanlines(&cinfo, const_cast<uint8_t**>(&row), 1);
|
||||||
}
|
}
|
||||||
} else if (aInputFormat == INPUT_FORMAT_RGBA) {
|
} else if (aInputFormat == INPUT_FORMAT_RGBA) {
|
||||||
uint8_t* row = new uint8_t[aWidth * 3];
|
UniquePtr<uint8_t[]> rowptr = MakeUnique<uint8_t[]>(aWidth * 3);
|
||||||
|
uint8_t* row = rowptr.get();
|
||||||
while (cinfo.next_scanline < cinfo.image_height) {
|
while (cinfo.next_scanline < cinfo.image_height) {
|
||||||
ConvertRGBARow(&aData[cinfo.next_scanline * aStride], row, aWidth);
|
ConvertRGBARow(&aData[cinfo.next_scanline * aStride], row, aWidth);
|
||||||
jpeg_write_scanlines(&cinfo, &row, 1);
|
jpeg_write_scanlines(&cinfo, &row, 1);
|
||||||
}
|
}
|
||||||
delete[] row;
|
|
||||||
} else if (aInputFormat == INPUT_FORMAT_HOSTARGB) {
|
} else if (aInputFormat == INPUT_FORMAT_HOSTARGB) {
|
||||||
uint8_t* row = new uint8_t[aWidth * 3];
|
UniquePtr<uint8_t[]> rowptr = MakeUnique<uint8_t[]>(aWidth * 3);
|
||||||
|
uint8_t* row = rowptr.get();
|
||||||
while (cinfo.next_scanline < cinfo.image_height) {
|
while (cinfo.next_scanline < cinfo.image_height) {
|
||||||
ConvertHostARGBRow(&aData[cinfo.next_scanline * aStride], row, aWidth);
|
ConvertHostARGBRow(&aData[cinfo.next_scanline * aStride], row, aWidth);
|
||||||
jpeg_write_scanlines(&cinfo, &row, 1);
|
jpeg_write_scanlines(&cinfo, &row, 1);
|
||||||
}
|
}
|
||||||
delete[] row;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg_finish_compress(&cinfo);
|
jpeg_finish_compress(&cinfo);
|
||||||
|
@ -287,22 +287,18 @@ nsPNGEncoder::AddImageFrame(const uint8_t* aData,
|
|||||||
if (aInputFormat == INPUT_FORMAT_HOSTARGB) {
|
if (aInputFormat == INPUT_FORMAT_HOSTARGB) {
|
||||||
// PNG requires RGBA with post-multiplied alpha, so we need to
|
// PNG requires RGBA with post-multiplied alpha, so we need to
|
||||||
// convert
|
// convert
|
||||||
uint8_t* row = new uint8_t[aWidth * 4];
|
UniquePtr<uint8_t[]> row = MakeUnique<uint8_t[]>(aWidth * 4);
|
||||||
for (uint32_t y = 0; y < aHeight; y++) {
|
for (uint32_t y = 0; y < aHeight; y++) {
|
||||||
ConvertHostARGBRow(&aData[y * aStride], row, aWidth, useTransparency);
|
ConvertHostARGBRow(&aData[y * aStride], row.get(), aWidth, useTransparency);
|
||||||
png_write_row(mPNG, row);
|
png_write_row(mPNG, row.get());
|
||||||
}
|
}
|
||||||
delete[] row;
|
|
||||||
|
|
||||||
} else if (aInputFormat == INPUT_FORMAT_RGBA && !useTransparency) {
|
} else if (aInputFormat == INPUT_FORMAT_RGBA && !useTransparency) {
|
||||||
// RBGA, but we need to strip the alpha
|
// RBGA, but we need to strip the alpha
|
||||||
uint8_t* row = new uint8_t[aWidth * 4];
|
UniquePtr<uint8_t[]> row = MakeUnique<uint8_t[]>(aWidth * 4);
|
||||||
for (uint32_t y = 0; y < aHeight; y++) {
|
for (uint32_t y = 0; y < aHeight; y++) {
|
||||||
StripAlpha(&aData[y * aStride], row, aWidth);
|
StripAlpha(&aData[y * aStride], row.get(), aWidth);
|
||||||
png_write_row(mPNG, row);
|
png_write_row(mPNG, row.get());
|
||||||
}
|
}
|
||||||
delete[] row;
|
|
||||||
|
|
||||||
} else if (aInputFormat == INPUT_FORMAT_RGB ||
|
} else if (aInputFormat == INPUT_FORMAT_RGB ||
|
||||||
aInputFormat == INPUT_FORMAT_RGBA) {
|
aInputFormat == INPUT_FORMAT_RGBA) {
|
||||||
// simple RBG(A), no conversion needed
|
// simple RBG(A), no conversion needed
|
||||||
|
Loading…
Reference in New Issue
Block a user