Improved performance when using ImageData methods in multiple threads when ImageData:encode is called

This commit is contained in:
Alex Szpakowski
2013-06-26 03:42:42 -03:00
parent b8efa6372b
commit b04a2fee87
6 changed files with 25 additions and 21 deletions
+13 -9
View File
@@ -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();