Mercurial > love-experiments
changeset 1423:5b9ebe6a9a7e image-CompressedData
Cosmetic code improvements
| author | Alex Szpakowski <slime73@gmail.com> |
|---|---|
| date | Sun, 07 Apr 2013 22:58:08 -0300 |
| parents | 377f9dad7a2d |
| children | 4d201f99aed3 |
| files | src/modules/filesystem/physfs/wrap_FileData.cpp src/modules/font/wrap_GlyphData.cpp src/modules/graphics/opengl/Image.h src/modules/graphics/opengl/wrap_Graphics.cpp src/modules/image/CompressedData.h src/modules/image/magpie/CompressedData.cpp src/modules/image/magpie/DevilHandler.cpp src/modules/image/magpie/DevilHandler.h src/modules/image/magpie/ImageData.cpp src/modules/image/magpie/ddsHandler.cpp src/modules/image/magpie/ddsHandler.h src/modules/image/wrap_CompressedData.cpp src/modules/image/wrap_Image.cpp src/modules/image/wrap_ImageData.cpp src/modules/sound/wrap_SoundData.cpp |
| diffstat | 15 files changed, 39 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/src/modules/filesystem/physfs/wrap_FileData.cpp Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/filesystem/physfs/wrap_FileData.cpp Sun Apr 07 22:58:08 2013 -0300 @@ -52,7 +52,7 @@ { // Data - { "getPointer", w_Data_getPointer }, +// { "getPointer", w_Data_getPointer }, { "getSize", w_Data_getSize }, { "getFilename", w_FileData_getFilename },
--- a/src/modules/font/wrap_GlyphData.cpp Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/font/wrap_GlyphData.cpp Sun Apr 07 22:58:08 2013 -0300 @@ -32,7 +32,7 @@ static const luaL_Reg functions[] = { - { "getPointer", w_Data_getPointer }, +// { "getPointer", w_Data_getPointer }, { "getSize", w_Data_getSize }, { 0, 0 } };
--- a/src/modules/graphics/opengl/Image.h Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/graphics/opengl/Image.h Sun Apr 07 22:58:08 2013 -0300 @@ -146,10 +146,13 @@ { 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.
--- a/src/modules/graphics/opengl/wrap_Graphics.cpp Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp Sun Apr 07 22:58:08 2013 -0300 @@ -418,7 +418,7 @@ 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 @@ 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); }
--- a/src/modules/image/CompressedData.h Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/image/CompressedData.h Sun Apr 07 22:58:08 2013 -0300 @@ -62,8 +62,8 @@ // by a sub-image. struct SubImage { + int width, height; size_t size; - int width, height; std::vector<unsigned char> data; };
--- a/src/modules/image/magpie/CompressedData.cpp Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/image/magpie/CompressedData.cpp Sun Apr 07 22:58:08 2013 -0300 @@ -40,16 +40,16 @@ void CompressedData::load(love::filesystem::FileData *data) { - std::vector<SubImage> imageMipmaps; + std::vector<SubImage> 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; }
--- a/src/modules/image/magpie/DevilHandler.cpp Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/image/magpie/DevilHandler.cpp Sun Apr 07 22:58:08 2013 -0300 @@ -145,7 +145,7 @@ ilBindImage(tempimage); ilxClearErrors(); - EncodedImage encodedimg; + EncodedImage encodedimage; try { @@ -194,32 +194,32 @@ 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
--- a/src/modules/image/magpie/DevilHandler.h Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/image/magpie/DevilHandler.h Sun Apr 07 22:58:08 2013 -0300 @@ -32,6 +32,9 @@ namespace magpie { +/** + * Interface between ImageData and DevIL. + **/ class DevilHandler : public FormatHandler { public:
--- a/src/modules/image/magpie/ImageData.cpp Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/image/magpie/ImageData.cpp Sun Apr 07 22:58:08 2013 -0300 @@ -74,26 +74,26 @@ 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)
--- a/src/modules/image/magpie/ddsHandler.cpp Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/image/magpie/ddsHandler.cpp Sun Apr 07 22:58:08 2013 -0300 @@ -29,28 +29,12 @@ 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<CompressedData::SubImage> &images) { if (!dds::Parser::isDDS(data->getData(), data->getSize()))
--- a/src/modules/image/magpie/ddsHandler.h Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/image/magpie/ddsHandler.h Sun Apr 07 22:58:08 2013 -0300 @@ -55,15 +55,14 @@ /** * 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<CompressedData::SubImage> &images); private: - static bool accepts(const std::string &ext); static CompressedData::TextureType convertFormat(dds::Format ddsformat); }; // ddsHandler
--- a/src/modules/image/wrap_CompressedData.cpp Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/image/wrap_CompressedData.cpp Sun Apr 07 22:58:08 2013 -0300 @@ -109,7 +109,7 @@ static const luaL_Reg functions[] = { // Data - { "getPointer", w_Data_getPointer }, +// { "getPointer", w_Data_getPointer }, { "getSize", w_Data_getSize }, { "getWidth", w_CompressedData_getWidth },
--- a/src/modules/image/wrap_Image.cpp Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/image/wrap_Image.cpp Sun Apr 07 22:58:08 2013 -0300 @@ -118,7 +118,7 @@ { return luaL_error(L, "%s", e.what()); } - luax_pushboolean(L, compressed); + luax_pushboolean(L, compressed); return 1; }
--- a/src/modules/image/wrap_ImageData.cpp Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/image/wrap_ImageData.cpp Sun Apr 07 22:58:08 2013 -0300 @@ -191,7 +191,7 @@ static const luaL_Reg functions[] = { // Data - { "getPointer", w_Data_getPointer }, +// { "getPointer", w_Data_getPointer }, { "getSize", w_Data_getSize }, { "getWidth", w_ImageData_getWidth },
--- a/src/modules/sound/wrap_SoundData.cpp Sun Apr 07 17:18:34 2013 -0300 +++ b/src/modules/sound/wrap_SoundData.cpp Sun Apr 07 22:58:08 2013 -0300 @@ -81,7 +81,7 @@ { // Data - { "getPointer", w_Data_getPointer }, +// { "getPointer", w_Data_getPointer }, { "getSize", w_Data_getSize }, { "getChannels", w_SoundData_getChannels },
