mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Improved performance when using ImageData methods in multiple threads when ImageData:encode is called
This commit is contained in:
@@ -45,7 +45,7 @@ public:
|
||||
int width, height;
|
||||
size_t size;
|
||||
unsigned char *data;
|
||||
DecodedImage() : width(0), height(0), size(0), data(0) {};
|
||||
DecodedImage() : width(0), height(0), size(0), data(0) {}
|
||||
};
|
||||
|
||||
// Pixel data encoded in a particular format.
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
{
|
||||
size_t size;
|
||||
unsigned char *data;
|
||||
EncodedImage() : size(0), data(0) {};
|
||||
EncodedImage() : size(0), data(0) {}
|
||||
};
|
||||
|
||||
// Lets pretend we have virtual static methods...
|
||||
|
||||
@@ -102,23 +102,27 @@ void ImageData::decode(love::filesystem::FileData *data)
|
||||
|
||||
void ImageData::encode(love::filesystem::File *f, ImageData::Format format)
|
||||
{
|
||||
thread::Lock lock(mutex);
|
||||
|
||||
FormatHandler::DecodedImage rawimage;
|
||||
rawimage.width = width;
|
||||
rawimage.height = height;
|
||||
rawimage.size = width*height*sizeof(pixel);
|
||||
rawimage.data = data;
|
||||
|
||||
FormatHandler::EncodedImage encodedimage;
|
||||
|
||||
try
|
||||
{
|
||||
// We only need to lock this mutex when actually encoding the ImageData.
|
||||
thread::Lock lock(mutex);
|
||||
|
||||
FormatHandler::DecodedImage rawimage;
|
||||
rawimage.width = width;
|
||||
rawimage.height = height;
|
||||
rawimage.size = width*height*sizeof(pixel);
|
||||
rawimage.data = data;
|
||||
|
||||
if (DevilHandler::canEncode(format))
|
||||
encodedimage = DevilHandler::encode(rawimage, format);
|
||||
else
|
||||
throw love::Exception("Image format has no suitable encoder.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
f->open(love::filesystem::File::WRITE);
|
||||
f->write(encodedimage.data, encodedimage.size);
|
||||
f->close();
|
||||
|
||||
@@ -68,7 +68,7 @@ CompressedData::TextureType ddsHandler::parse(filesystem::FileData *data, std::v
|
||||
mip.size = img->dataSize;
|
||||
|
||||
// Copy the mipmap image from the FileData.
|
||||
mip.data = new char[mip.size];
|
||||
mip.data = new uint8[mip.size];
|
||||
memcpy(mip.data, img->data, mip.size);
|
||||
|
||||
images.push_back(mip);
|
||||
|
||||
Reference in New Issue
Block a user