diff --git a/src/modules/image/CompressedData.h b/src/modules/image/CompressedData.h index f1a8ca85c..35cdff95c 100644 --- a/src/modules/image/CompressedData.h +++ b/src/modules/image/CompressedData.h @@ -24,9 +24,7 @@ // LOVE #include "common/Data.h" #include "common/StringMap.h" -#include "thread/threads.h" - -using love::thread::Mutex; +#include "common/int.h" // STL #include @@ -63,7 +61,7 @@ public: { int width, height; size_t size; - char *data; + uint8 *data; }; CompressedData(); diff --git a/src/modules/image/ImageData.cpp b/src/modules/image/ImageData.cpp index 7532bbc80..8fdc585b9 100644 --- a/src/modules/image/ImageData.cpp +++ b/src/modules/image/ImageData.cpp @@ -149,14 +149,15 @@ void ImageData::paste(ImageData *src, int dx, int dy, int sx, int sy, int sw, in // If the dimensions match up, copy the entire memory stream in one go if (sw == getWidth() && getWidth() == src->getWidth() - && sh == getHeight() && getHeight() == src->getHeight()) - memcpy(d, s, sizeof(pixel) * sw * sh); - else if (sw > 0) // Otherwise, copy each row individually + && sh == getHeight() && getHeight() == src->getHeight()) { + memcpy(d, s, sizeof(pixel) * sw * sh); + } + else if (sw > 0) + { + // Otherwise, copy each row individually. for (int i = 0; i < sh; i++) - { memcpy(d + dx + (i + dy) * getWidth(), s + sx + (i + sy) * src->getWidth(), sizeof(pixel) * sw); - } } } diff --git a/src/modules/image/magpie/FormatHandler.h b/src/modules/image/magpie/FormatHandler.h index 5b4080829..e01166a49 100644 --- a/src/modules/image/magpie/FormatHandler.h +++ b/src/modules/image/magpie/FormatHandler.h @@ -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... diff --git a/src/modules/image/magpie/ImageData.cpp b/src/modules/image/magpie/ImageData.cpp index 8cc75751f..cd17700bb 100644 --- a/src/modules/image/magpie/ImageData.cpp +++ b/src/modules/image/magpie/ImageData.cpp @@ -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(); diff --git a/src/modules/image/magpie/ddsHandler.cpp b/src/modules/image/magpie/ddsHandler.cpp index 134fcf72a..6305febf9 100644 --- a/src/modules/image/magpie/ddsHandler.cpp +++ b/src/modules/image/magpie/ddsHandler.cpp @@ -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); diff --git a/src/modules/image/wrap_ImageData.cpp b/src/modules/image/wrap_ImageData.cpp index 476658060..8e7279a7a 100644 --- a/src/modules/image/wrap_ImageData.cpp +++ b/src/modules/image/wrap_ImageData.cpp @@ -202,6 +202,7 @@ int w_ImageData_mapPixel(lua_State *L) lua_pushvalue(L, 2); // Manually lock this ImageData's mutex during the entire mapPixel. + // Using the lock methods because lua_error won't trigger object destructors. mutex->lock(); int ret = lua_pcall(L, 2, 0, 0); mutex->unlock();