diff --git a/src/modules/filesystem/physfs/wrap_FileData.cpp b/src/modules/filesystem/physfs/wrap_FileData.cpp index 4e8961f9f..8b9e10f22 100644 --- a/src/modules/filesystem/physfs/wrap_FileData.cpp +++ b/src/modules/filesystem/physfs/wrap_FileData.cpp @@ -52,7 +52,7 @@ static const luaL_Reg w_FileData_functions[] = { // Data - { "getPointer", w_Data_getPointer }, +// { "getPointer", w_Data_getPointer }, { "getSize", w_Data_getSize }, { "getFilename", w_FileData_getFilename }, diff --git a/src/modules/font/wrap_GlyphData.cpp b/src/modules/font/wrap_GlyphData.cpp index b09ce2c36..f28a55530 100644 --- a/src/modules/font/wrap_GlyphData.cpp +++ b/src/modules/font/wrap_GlyphData.cpp @@ -32,7 +32,7 @@ GlyphData *luax_checkglyphdata(lua_State *L, int idx) static const luaL_Reg functions[] = { - { "getPointer", w_Data_getPointer }, +// { "getPointer", w_Data_getPointer }, { "getSize", w_Data_getSize }, { 0, 0 } }; diff --git a/src/modules/graphics/opengl/Image.h b/src/modules/graphics/opengl/Image.h index 2c12bf125..1cf3c933f 100644 --- a/src/modules/graphics/opengl/Image.h +++ b/src/modules/graphics/opengl/Image.h @@ -146,10 +146,13 @@ private: { return texture; } - // The ImageData from which the texture is created. + + // The ImageData from which the texture is created. May be null if + // Compressed image data was used to create the texture. love::image::ImageData *data; - // Or the Compressed Image Data from which the texture is created. + // Or the Compressed Image Data from which the texture is created. May be + // null if raw ImageData was used to create the texture. love::image::CompressedData *cdata; // Width and height of the hardware texture. diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index b6c7c9bf1..e1fbba89b 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -418,7 +418,7 @@ int w_newImageFont(lua_State *L) int startIndex = 2; // Convert to ImageData if necessary. - if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || (luax_istype(L, 1, DATA_T) && !luax_istype(L, 1, IMAGE_IMAGE_DATA_T))) + if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T)) luax_convobj(L, 1, "image", "newImageData"); else if (luax_istype(L, 1, GRAPHICS_IMAGE_T)) { @@ -426,6 +426,8 @@ int w_newImageFont(lua_State *L) img_filter = i->getFilter(); setFilter = true; love::image::ImageData *id = i->getData(); + if (!id) + return luaL_argerror(L, 1, "image cannot be compressed"); luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)id, false); lua_replace(L, 1); } diff --git a/src/modules/image/CompressedData.h b/src/modules/image/CompressedData.h index 416202454..604e9dafd 100644 --- a/src/modules/image/CompressedData.h +++ b/src/modules/image/CompressedData.h @@ -62,8 +62,8 @@ public: // by a sub-image. struct SubImage { - size_t size; int width, height; + size_t size; std::vector data; }; diff --git a/src/modules/image/magpie/CompressedData.cpp b/src/modules/image/magpie/CompressedData.cpp index f9ac1de98..eccfb0323 100644 --- a/src/modules/image/magpie/CompressedData.cpp +++ b/src/modules/image/magpie/CompressedData.cpp @@ -40,16 +40,16 @@ CompressedData::~CompressedData() void CompressedData::load(love::filesystem::FileData *data) { - std::vector imageMipmaps; + std::vector parsedImages; TextureType textype = TYPE_UNKNOWN; if (ddsHandler::canParse(data)) - textype = ddsHandler::parse(data, imageMipmaps); + textype = ddsHandler::parse(data, parsedImages); if (textype == TYPE_UNKNOWN) throw (love::Exception("Could not parse compressed data: Unknown format.")); - dataImages = imageMipmaps; + dataImages = parsedImages; type = textype; } diff --git a/src/modules/image/magpie/DevilHandler.cpp b/src/modules/image/magpie/DevilHandler.cpp index ac85b98e2..b666e1cfa 100644 --- a/src/modules/image/magpie/DevilHandler.cpp +++ b/src/modules/image/magpie/DevilHandler.cpp @@ -145,7 +145,7 @@ DevilHandler::EncodedImage DevilHandler::encode(const DecodedImage &img, ImageDa ilBindImage(tempimage); ilxClearErrors(); - EncodedImage encodedimg; + EncodedImage encodedimage; try { @@ -194,32 +194,32 @@ DevilHandler::EncodedImage DevilHandler::encode(const DecodedImage &img, ImageDa break; } - encodedimg.size = ilSaveL(ilFormat, NULL, 0); - if (!encodedimg.size) + encodedimage.size = ilSaveL(ilFormat, NULL, 0); + if (!encodedimage.size) throw love::Exception("Could not encode image!"); try { - encodedimg.data = new ILubyte[encodedimg.size]; + encodedimage.data = new ILubyte[encodedimage.size]; } catch(std::bad_alloc &) { throw love::Exception("Out of memory"); } - ilSaveL(ilFormat, encodedimg.data, encodedimg.size); + ilSaveL(ilFormat, encodedimage.data, encodedimage.size); } catch (std::exception &e) { // catches love and std exceptions ilDeleteImage(tempimage); - delete[] encodedimg.data; + delete[] encodedimage.data; throw love::Exception("%s", e.what()); } ilDeleteImage(tempimage); - return encodedimg; + return encodedimage; } } // magpie diff --git a/src/modules/image/magpie/DevilHandler.h b/src/modules/image/magpie/DevilHandler.h index d5cd80a4a..d9da062ce 100644 --- a/src/modules/image/magpie/DevilHandler.h +++ b/src/modules/image/magpie/DevilHandler.h @@ -32,6 +32,9 @@ namespace image namespace magpie { +/** + * Interface between ImageData and DevIL. + **/ class DevilHandler : public FormatHandler { public: diff --git a/src/modules/image/magpie/ImageData.cpp b/src/modules/image/magpie/ImageData.cpp index c5127fa3e..b2e878321 100644 --- a/src/modules/image/magpie/ImageData.cpp +++ b/src/modules/image/magpie/ImageData.cpp @@ -74,26 +74,26 @@ void ImageData::create(int width, int height, void *data) void ImageData::decode(love::filesystem::FileData *data) { - FormatHandler::DecodedImage decodedimg; + FormatHandler::DecodedImage decodedimage; if (DevilHandler::canDecode(data)) - decodedimg = DevilHandler::decode(data); + decodedimage = DevilHandler::decode(data); else - throw love::Exception("Image format has no suitable decoder."); + throw love::Exception("Could not decode image: unrecognized format."); // The decoder *must* output a 32 bits-per-pixel image. - if (decodedimg.size != decodedimg.width*decodedimg.height*sizeof(pixel)) + if (decodedimage.size != decodedimage.width*decodedimage.height*sizeof(pixel)) { - delete[] decodedimg.data; + delete[] decodedimage.data; throw love::Exception("Coult not convert image!"); } if (this->data) delete[] this->data; - this->width = decodedimg.width; - this->height = decodedimg.height; - this->data = decodedimg.data; + this->width = decodedimage.width; + this->height = decodedimage.height; + this->data = decodedimage.data; } void ImageData::encode(love::filesystem::File *f, ImageData::Format format) diff --git a/src/modules/image/magpie/ddsHandler.cpp b/src/modules/image/magpie/ddsHandler.cpp index 5a149f20a..37ed662f5 100644 --- a/src/modules/image/magpie/ddsHandler.cpp +++ b/src/modules/image/magpie/ddsHandler.cpp @@ -29,28 +29,12 @@ namespace magpie bool ddsHandler::canParse(const filesystem::FileData *data) { - if (!accepts(data->getExtension())) + if (data->getExtension().compare("dds") != 0) return false; return dds::Parser::isCompressedDDS(data->getData(), data->getSize()); } -bool ddsHandler::accepts(const std::string &ext) -{ - static const std::string supported[] = - { - "dds", "" - }; - - for (int i = 0; !(supported[i].empty()); i++) - { - if (supported[i].compare(ext) == 0) - return true; - } - - return false; -} - CompressedData::TextureType ddsHandler::parse(filesystem::FileData *data, std::vector &images) { if (!dds::Parser::isDDS(data->getData(), data->getSize())) diff --git a/src/modules/image/magpie/ddsHandler.h b/src/modules/image/magpie/ddsHandler.h index d5ca057e2..3e41670fe 100644 --- a/src/modules/image/magpie/ddsHandler.h +++ b/src/modules/image/magpie/ddsHandler.h @@ -55,15 +55,14 @@ public: /** * Parses Compressed image data into a list of sub-images. * @param[in] data The data to parse. - * @param[out] images The list of sub-images (including byte data for each) - * outputted by the parser. + * @param[out] images The list of sub-images (including byte data for each), + * created by the parser. * @return The type of CompressedData. **/ static CompressedData::TextureType parse(filesystem::FileData *data, std::vector &images); private: - static bool accepts(const std::string &ext); static CompressedData::TextureType convertFormat(dds::Format ddsformat); }; // ddsHandler diff --git a/src/modules/image/wrap_CompressedData.cpp b/src/modules/image/wrap_CompressedData.cpp index 4a9c988b9..43dd3356d 100644 --- a/src/modules/image/wrap_CompressedData.cpp +++ b/src/modules/image/wrap_CompressedData.cpp @@ -109,7 +109,7 @@ int w_CompressedData_getType(lua_State *L) static const luaL_Reg functions[] = { // Data - { "getPointer", w_Data_getPointer }, +// { "getPointer", w_Data_getPointer }, { "getSize", w_Data_getSize }, { "getWidth", w_CompressedData_getWidth }, diff --git a/src/modules/image/wrap_Image.cpp b/src/modules/image/wrap_Image.cpp index c87afbf5a..8ba5d5479 100644 --- a/src/modules/image/wrap_Image.cpp +++ b/src/modules/image/wrap_Image.cpp @@ -118,7 +118,7 @@ int w_isCompressed(lua_State *L) { return luaL_error(L, "%s", e.what()); } - luax_pushboolean(L, compressed); + luax_pushboolean(L, compressed); return 1; } diff --git a/src/modules/image/wrap_ImageData.cpp b/src/modules/image/wrap_ImageData.cpp index e08500339..2dd3a8c3d 100644 --- a/src/modules/image/wrap_ImageData.cpp +++ b/src/modules/image/wrap_ImageData.cpp @@ -191,7 +191,7 @@ int w_ImageData_encode(lua_State *L) static const luaL_Reg functions[] = { // Data - { "getPointer", w_Data_getPointer }, +// { "getPointer", w_Data_getPointer }, { "getSize", w_Data_getSize }, { "getWidth", w_ImageData_getWidth }, diff --git a/src/modules/sound/wrap_SoundData.cpp b/src/modules/sound/wrap_SoundData.cpp index 19f65ed8a..720c15c97 100644 --- a/src/modules/sound/wrap_SoundData.cpp +++ b/src/modules/sound/wrap_SoundData.cpp @@ -81,7 +81,7 @@ static const luaL_Reg functions[] = { // Data - { "getPointer", w_Data_getPointer }, +// { "getPointer", w_Data_getPointer }, { "getSize", w_Data_getSize }, { "getChannels", w_SoundData_getChannels },