From a41f78dfe4ac896b308a9862b411bdefce8c6bcc Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 30 Aug 2017 22:25:26 -0300 Subject: [PATCH] Simplified some compressed image parsing code. --HG-- branch : minor --- CMakeLists.txt | 1 - .../xcode/liblove.xcodeproj/project.pbxproj | 4 -- src/modules/image/CompressedFormatHandler.h | 70 ------------------- src/modules/image/CompressedImageData.cpp | 10 +-- src/modules/image/CompressedImageData.h | 4 +- src/modules/image/FormatHandler.cpp | 12 +++- src/modules/image/FormatHandler.h | 46 +++++++----- src/modules/image/Image.cpp | 12 +--- src/modules/image/Image.h | 3 - src/modules/image/ImageData.cpp | 10 +-- src/modules/image/magpie/ASTCHandler.cpp | 6 +- src/modules/image/magpie/ASTCHandler.h | 10 +-- src/modules/image/magpie/EXRHandler.cpp | 2 +- src/modules/image/magpie/EXRHandler.h | 2 +- src/modules/image/magpie/KTXHandler.cpp | 6 +- src/modules/image/magpie/KTXHandler.h | 10 +-- src/modules/image/magpie/PKMHandler.cpp | 6 +- src/modules/image/magpie/PKMHandler.h | 10 +-- src/modules/image/magpie/PNGHandler.cpp | 2 +- src/modules/image/magpie/PNGHandler.h | 2 +- src/modules/image/magpie/PVRHandler.cpp | 6 +- src/modules/image/magpie/PVRHandler.h | 10 +-- src/modules/image/magpie/STBHandler.cpp | 2 +- src/modules/image/magpie/STBHandler.h | 2 +- src/modules/image/magpie/ddsHandler.cpp | 4 +- src/modules/image/magpie/ddsHandler.h | 10 +-- 26 files changed, 101 insertions(+), 161 deletions(-) delete mode 100644 src/modules/image/CompressedFormatHandler.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b3909077c..fbfd3b905 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -579,7 +579,6 @@ source_group("modules\\graphics\\opengl" FILES ${LOVE_SRC_MODULE_GRAPHICS_OPENGL # set(LOVE_SRC_MODULE_IMAGE_ROOT - src/modules/image/CompressedFormatHandler.h src/modules/image/CompressedImageData.cpp src/modules/image/CompressedImageData.h src/modules/image/CompressedSlice.cpp diff --git a/platform/xcode/liblove.xcodeproj/project.pbxproj b/platform/xcode/liblove.xcodeproj/project.pbxproj index bf20dd1d7..7b175fdb9 100644 --- a/platform/xcode/liblove.xcodeproj/project.pbxproj +++ b/platform/xcode/liblove.xcodeproj/project.pbxproj @@ -938,7 +938,6 @@ FA91DA8B1F377C3900C80E33 /* deprecation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA91DA891F377C3900C80E33 /* deprecation.cpp */; }; FA91DA8C1F377C3900C80E33 /* deprecation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA91DA891F377C3900C80E33 /* deprecation.cpp */; }; FA91DA8D1F377C3900C80E33 /* deprecation.h in Headers */ = {isa = PBXBuildFile; fileRef = FA91DA8A1F377C3900C80E33 /* deprecation.h */; }; - FA93C4521F315B960087CCD4 /* CompressedFormatHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = FA93C44F1F315B960087CCD4 /* CompressedFormatHandler.h */; }; FA93C4531F315B960087CCD4 /* FormatHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = FA93C4501F315B960087CCD4 /* FormatHandler.h */; }; FA93C4541F315B960087CCD4 /* FormatHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA93C4511F315B960087CCD4 /* FormatHandler.cpp */; }; FA9B4A0816E1578300074F42 /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA9B4A0716E1578300074F42 /* SDL2.framework */; }; @@ -1801,7 +1800,6 @@ FA91591D1CF1ED7500A7053F /* halffloat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = halffloat.h; sourceTree = ""; }; FA91DA891F377C3900C80E33 /* deprecation.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = deprecation.cpp; sourceTree = ""; }; FA91DA8A1F377C3900C80E33 /* deprecation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = deprecation.h; sourceTree = ""; }; - FA93C44F1F315B960087CCD4 /* CompressedFormatHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompressedFormatHandler.h; sourceTree = ""; }; FA93C4501F315B960087CCD4 /* FormatHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormatHandler.h; sourceTree = ""; }; FA93C4511F315B960087CCD4 /* FormatHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormatHandler.cpp; sourceTree = ""; }; FA9B4A0716E1578300074F42 /* SDL2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2.framework; path = /Library/Frameworks/SDL2.framework; sourceTree = ""; }; @@ -2764,7 +2762,6 @@ FA0B7BC21A95902C000E1D17 /* image */ = { isa = PBXGroup; children = ( - FA93C44F1F315B960087CCD4 /* CompressedFormatHandler.h */, FA0B7BC31A95902C000E1D17 /* CompressedImageData.cpp */, FA0B7BC41A95902C000E1D17 /* CompressedImageData.h */, FAECA1B01F3164700095D008 /* CompressedSlice.cpp */, @@ -3661,7 +3658,6 @@ FA0B7E351A95902C000E1D17 /* WeldJoint.h in Headers */, FA0B7E2F1A95902C000E1D17 /* RopeJoint.h in Headers */, FA0B7D141A95902C000E1D17 /* Font.h in Headers */, - FA93C4521F315B960087CCD4 /* CompressedFormatHandler.h in Headers */, FA0B7D411A95902C000E1D17 /* Mesh.h in Headers */, FA0B7E591A95902C000E1D17 /* wrap_Joint.h in Headers */, FA0B79351A958E3B000E1D17 /* macosx.h in Headers */, diff --git a/src/modules/image/CompressedFormatHandler.h b/src/modules/image/CompressedFormatHandler.h deleted file mode 100644 index 99bdc5030..000000000 --- a/src/modules/image/CompressedFormatHandler.h +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2006-2017 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#pragma once - -// LOVE -#include "common/Object.h" -#include "common/Data.h" -#include "CompressedSlice.h" - -namespace love -{ -namespace image -{ - -/** - * Base class for all CompressedImageData parser library interfaces. - * We inherit from love::Object to take advantage of reference counting... - **/ -class CompressedFormatHandler : public love::Object -{ -public: - - CompressedFormatHandler() {} - virtual ~CompressedFormatHandler() {} - - /** - * Determines whether a particular FileData can be parsed as - * CompressedImageData by this handler. - * @param data The data to parse. - **/ - virtual bool canParse(const Data *data) = 0; - - /** - * Parses compressed image filedata into a list of sub-images and returns - * a single block of memory containing all the images. - * - * @param[in] filedata The data to parse. - * @param[out] images The list of sub-images generated. Byte data is a - * pointer to the returned data. - * @param[out] format The format of the Compressed Data. - * @param[out] sRGB Whether the texture is sRGB-encoded. - * - * @return The single block of memory containing the parsed images. - **/ - virtual StrongRef parse(Data *filedata, - std::vector> &images, - PixelFormat &format, bool &sRGB) = 0; - -}; // CompressedFormatHandler - -} // image -} // love diff --git a/src/modules/image/CompressedImageData.cpp b/src/modules/image/CompressedImageData.cpp index 715a382a1..0214eb1e9 100644 --- a/src/modules/image/CompressedImageData.cpp +++ b/src/modules/image/CompressedImageData.cpp @@ -27,15 +27,15 @@ namespace image love::Type CompressedImageData::type("CompressedImageData", &Data::type); -CompressedImageData::CompressedImageData(const std::list &formats, Data *filedata) +CompressedImageData::CompressedImageData(const std::list &formats, Data *filedata) : format(PIXELFORMAT_UNKNOWN) , sRGB(false) { - CompressedFormatHandler *parser = nullptr; + FormatHandler *parser = nullptr; - for (CompressedFormatHandler *handler : formats) + for (FormatHandler *handler : formats) { - if (handler->canParse(filedata)) + if (handler->canParseCompressed(filedata)) { parser = handler; break; @@ -45,7 +45,7 @@ CompressedImageData::CompressedImageData(const std::listparse(filedata, dataImages, format, sRGB); + memory = parser->parseCompressed(filedata, dataImages, format, sRGB); if (memory == nullptr) throw love::Exception("Could not parse compressed data."); diff --git a/src/modules/image/CompressedImageData.h b/src/modules/image/CompressedImageData.h index f74ae2cef..99a0a10e8 100644 --- a/src/modules/image/CompressedImageData.h +++ b/src/modules/image/CompressedImageData.h @@ -26,7 +26,7 @@ #include "common/int.h" #include "common/pixelformat.h" #include "CompressedSlice.h" -#include "CompressedFormatHandler.h" +#include "FormatHandler.h" // STL #include @@ -48,7 +48,7 @@ public: static love::Type type; - CompressedImageData(const std::list &formats, Data *filedata); + CompressedImageData(const std::list &formats, Data *filedata); CompressedImageData(const CompressedImageData &c); virtual ~CompressedImageData(); diff --git a/src/modules/image/FormatHandler.cpp b/src/modules/image/FormatHandler.cpp index 951ab70d3..1afe02914 100644 --- a/src/modules/image/FormatHandler.cpp +++ b/src/modules/image/FormatHandler.cpp @@ -55,7 +55,17 @@ FormatHandler::EncodedImage FormatHandler::encode(const DecodedImage& /*img*/, E throw love::Exception("Image encoding is not implemented for this format backend."); } -void FormatHandler::free(unsigned char *mem) +bool FormatHandler::canParseCompressed(Data* /*data*/) +{ + return false; +} + +StrongRef FormatHandler::parseCompressed(Data* /*filedata*/, std::vector>& /*images*/, PixelFormat& /*format*/, bool& /*sRGB*/) +{ + throw love::Exception("Compressed image parsing is not implemented for this format backend."); +} + +void FormatHandler::freeRawPixels(unsigned char *mem) { delete[] mem; } diff --git a/src/modules/image/FormatHandler.h b/src/modules/image/FormatHandler.h index 994e0dc77..b4996a7aa 100644 --- a/src/modules/image/FormatHandler.h +++ b/src/modules/image/FormatHandler.h @@ -22,8 +22,9 @@ // LOVE #include "common/Object.h" -#include "common/pixelformat.h" #include "common/Data.h" +#include "common/pixelformat.h" +#include "CompressedSlice.h" namespace love { @@ -31,8 +32,8 @@ namespace image { /** - * Base class for all ImageData encoder/decoder library interfaces. - * We inherit from love::Object to take advantage of reference counting... + * Base class for all ImageData and CompressedImageData encoder/decoder library + * interfaces. We inherit from love::Object to take advantage of ref coounting. **/ class FormatHandler : public love::Object { @@ -66,41 +67,54 @@ public: * The default constructor is called when the Image module is initialized. **/ FormatHandler(); - - /** - * The destructor is called when the Image module is uninitialized. - **/ virtual ~FormatHandler(); /** - * Whether this format handler can decode a particular FileData. + * Whether this format handler can decode the given Data into raw pixels. **/ virtual bool canDecode(Data *data); /** - * Whether this format handler can encode to a particular format. + * Whether this format handler can encode raw pixels to a particular format. **/ virtual bool canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat); /** * Decodes an image from its encoded form into raw pixel data. - * @param data The encoded data to decode. - * @return The decoded pixel data. **/ virtual DecodedImage decode(Data *data); /** * Encodes an image from raw pixel data into a particular format. - * @param img The raw image data to encode. - * @param format The format to encode to. - * @return The encoded image data. **/ virtual EncodedImage encode(const DecodedImage &img, EncodedFormat format); /** - * Frees memory allocated by the format handler. + * Whether this format handler can parse the given Data into a + * CompressedImageData object. **/ - virtual void free(unsigned char *mem); + virtual bool canParseCompressed(Data *data); + + /** + * Parses compressed image data into a list of sub-images and returns a + * single block of memory containing all the images. + * + * @param[in] filedata The data to parse. + * @param[out] images The list of sub-images generated. Byte data is a + * pointer to the returned data. + * @param[out] format The format of the Compressed Data. + * @param[out] sRGB Whether the texture is sRGB-encoded. + * + * @return The single block of memory containing the parsed images. + **/ + virtual StrongRef parseCompressed(Data *filedata, + std::vector> &images, + PixelFormat &format, bool &sRGB); + + /** + * Frees raw pixel memory allocated by the format handler. + **/ + virtual void freeRawPixels(unsigned char *mem); }; // FormatHandler diff --git a/src/modules/image/Image.cpp b/src/modules/image/Image.cpp index 2839eec6e..3ab95a27b 100644 --- a/src/modules/image/Image.cpp +++ b/src/modules/image/Image.cpp @@ -49,9 +49,6 @@ Image::Image() new PNGHandler, new STBHandler, new EXRHandler, - }; - - compressedFormatHandlers = { new DDSHandler, new PVRHandler, new KTXHandler, @@ -66,9 +63,6 @@ Image::~Image() // release them instead of deleting them completely here. for (FormatHandler *handler : formatHandlers) handler->release(); - - for (CompressedFormatHandler *handler : compressedFormatHandlers) - handler->release(); } const char *Image::getName() const @@ -93,14 +87,14 @@ love::image::ImageData *Image::newImageData(int width, int height, PixelFormat f love::image::CompressedImageData *Image::newCompressedData(Data *data) { - return new CompressedImageData(compressedFormatHandlers, data); + return new CompressedImageData(formatHandlers, data); } bool Image::isCompressed(Data *data) { - for (CompressedFormatHandler *handler : compressedFormatHandlers) + for (FormatHandler *handler : formatHandlers) { - if (handler->canParse(data)) + if (handler->canParseCompressed(data)) return true; } diff --git a/src/modules/image/Image.h b/src/modules/image/Image.h index 6283c286c..1f305c8e0 100644 --- a/src/modules/image/Image.h +++ b/src/modules/image/Image.h @@ -107,9 +107,6 @@ private: // Image format handlers we can use for decoding and encoding ImageData. std::list formatHandlers; - // Compressed image format handers we can use for parsing CompressedImageData. - std::list compressedFormatHandlers; - }; // Image } // image diff --git a/src/modules/image/ImageData.cpp b/src/modules/image/ImageData.cpp index 863e8de37..5533634de 100644 --- a/src/modules/image/ImageData.cpp +++ b/src/modules/image/ImageData.cpp @@ -78,7 +78,7 @@ ImageData::ImageData(const ImageData &c) ImageData::~ImageData() { if (decodeHandler.get()) - decodeHandler->free(data); + decodeHandler->freeRawPixels(data); else delete[] data; } @@ -145,13 +145,13 @@ void ImageData::decode(Data *data) if (decodedimage.size != decodedimage.width * decodedimage.height * getPixelFormatSize(decodedimage.format)) { - decoder->free(decodedimage.data); + decoder->freeRawPixels(decodedimage.data); throw love::Exception("Could not convert image!"); } // Clean up any old data. if (decodeHandler) - decodeHandler->free(this->data); + decodeHandler->freeRawPixels(this->data); else delete[] this->data; @@ -210,12 +210,12 @@ love::filesystem::FileData *ImageData::encode(FormatHandler::EncodedFormat encod } catch (love::Exception &) { - encoder->free(encodedimage.data); + encoder->freeRawPixels(encodedimage.data); throw; } memcpy(filedata->getData(), encodedimage.data, encodedimage.size); - encoder->free(encodedimage.data); + encoder->freeRawPixels(encodedimage.data); if (writefile) { diff --git a/src/modules/image/magpie/ASTCHandler.cpp b/src/modules/image/magpie/ASTCHandler.cpp index fc938348f..75249c966 100644 --- a/src/modules/image/magpie/ASTCHandler.cpp +++ b/src/modules/image/magpie/ASTCHandler.cpp @@ -87,7 +87,7 @@ static PixelFormat convertFormat(uint32 blockX, uint32 blockY, uint32 blockZ) } // Anonymous namespace. -bool ASTCHandler::canParse(const Data *data) +bool ASTCHandler::canParseCompressed(Data *data) { if (data->getSize() <= sizeof(ASTCHeader)) return false; @@ -105,9 +105,9 @@ bool ASTCHandler::canParse(const Data *data) return true; } -StrongRef ASTCHandler::parse(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) +StrongRef ASTCHandler::parseCompressed(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) { - if (!canParse(filedata)) + if (!canParseCompressed(filedata)) throw love::Exception("Could not decode compressed data (not an .astc file?)"); ASTCHeader header = *(const ASTCHeader *) filedata->getData(); diff --git a/src/modules/image/magpie/ASTCHandler.h b/src/modules/image/magpie/ASTCHandler.h index 9d876b4f3..e3121d5a1 100644 --- a/src/modules/image/magpie/ASTCHandler.h +++ b/src/modules/image/magpie/ASTCHandler.h @@ -21,7 +21,7 @@ #pragma once #include "common/config.h" -#include "image/CompressedFormatHandler.h" +#include "image/FormatHandler.h" namespace love { @@ -34,16 +34,16 @@ namespace magpie * Handles simple .astc files (generated by ARM's astcenc tool) with compressed * ASTC data inside. **/ -class ASTCHandler : public CompressedFormatHandler +class ASTCHandler : public FormatHandler { public: virtual ~ASTCHandler() {} - // Implements CompressedFormatHandler. - bool canParse(const Data *data) override; + // Implements FormatHandler. + bool canParseCompressed(Data *data) override; - StrongRef parse(Data *filedata, + StrongRef parseCompressed(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) override; diff --git a/src/modules/image/magpie/EXRHandler.cpp b/src/modules/image/magpie/EXRHandler.cpp index 1180eee5d..602c9cd88 100644 --- a/src/modules/image/magpie/EXRHandler.cpp +++ b/src/modules/image/magpie/EXRHandler.cpp @@ -193,7 +193,7 @@ FormatHandler::EncodedImage EXRHandler::encode(const DecodedImage & /*img*/, Enc throw love::Exception("Invalid format."); } -void EXRHandler::free(unsigned char *mem) +void EXRHandler::freeRawPixels(unsigned char *mem) { delete[] mem; } diff --git a/src/modules/image/magpie/EXRHandler.h b/src/modules/image/magpie/EXRHandler.h index bb7e2559b..3c7d7a0c4 100644 --- a/src/modules/image/magpie/EXRHandler.h +++ b/src/modules/image/magpie/EXRHandler.h @@ -44,7 +44,7 @@ public: virtual DecodedImage decode(Data *data); virtual EncodedImage encode(const DecodedImage &img, EncodedFormat format); - virtual void free(unsigned char *mem); + virtual void freeRawPixels(unsigned char *mem); }; // EXRHandler diff --git a/src/modules/image/magpie/KTXHandler.cpp b/src/modules/image/magpie/KTXHandler.cpp index 78cde9477..f0ef8853f 100644 --- a/src/modules/image/magpie/KTXHandler.cpp +++ b/src/modules/image/magpie/KTXHandler.cpp @@ -281,7 +281,7 @@ PixelFormat convertFormat(uint32 glformat, bool &sRGB) } // Anonymous namespace. -bool KTXHandler::canParse(const Data *data) +bool KTXHandler::canParseCompressed(Data *data) { if (data->getSize() < sizeof(KTXHeader)) return false; @@ -298,9 +298,9 @@ bool KTXHandler::canParse(const Data *data) return true; } -StrongRef KTXHandler::parse(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) +StrongRef KTXHandler::parseCompressed(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) { - if (!canParse(filedata)) + if (!canParseCompressed(filedata)) throw love::Exception("Could not decode compressed data (not a KTX file?)"); KTXHeader header = *(KTXHeader *) filedata->getData(); diff --git a/src/modules/image/magpie/KTXHandler.h b/src/modules/image/magpie/KTXHandler.h index 5716a7d64..896e9b965 100644 --- a/src/modules/image/magpie/KTXHandler.h +++ b/src/modules/image/magpie/KTXHandler.h @@ -21,7 +21,7 @@ #pragma once #include "common/config.h" -#include "image/CompressedFormatHandler.h" +#include "image/FormatHandler.h" namespace love { @@ -33,16 +33,16 @@ namespace magpie /** * Handles KTX files with compressed image data inside. **/ -class KTXHandler : public CompressedFormatHandler +class KTXHandler : public FormatHandler { public: virtual ~KTXHandler() {} - // Implements CompressedFormatHandler. - bool canParse(const Data *data) override; + // Implements FormatHandler. + bool canParseCompressed(Data *data) override; - StrongRef parse(Data *filedata, + StrongRef parseCompressed(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) override; diff --git a/src/modules/image/magpie/PKMHandler.cpp b/src/modules/image/magpie/PKMHandler.cpp index df522c2b5..b13c29baa 100644 --- a/src/modules/image/magpie/PKMHandler.cpp +++ b/src/modules/image/magpie/PKMHandler.cpp @@ -97,7 +97,7 @@ static PixelFormat convertFormat(uint16 texformat) } // Anonymous namespace. -bool PKMHandler::canParse(const Data *data) +bool PKMHandler::canParseCompressed(Data *data) { if (data->getSize() <= sizeof(PKMHeader)) return false; @@ -114,9 +114,9 @@ bool PKMHandler::canParse(const Data *data) return true; } -StrongRef PKMHandler::parse(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) +StrongRef PKMHandler::parseCompressed(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) { - if (!canParse(filedata)) + if (!canParseCompressed(filedata)) throw love::Exception("Could not decode compressed data (not a PKM file?)"); PKMHeader header = *(const PKMHeader *) filedata->getData(); diff --git a/src/modules/image/magpie/PKMHandler.h b/src/modules/image/magpie/PKMHandler.h index ff6a93896..8a66b4fba 100644 --- a/src/modules/image/magpie/PKMHandler.h +++ b/src/modules/image/magpie/PKMHandler.h @@ -21,7 +21,7 @@ #pragma once #include "common/config.h" -#include "image/CompressedFormatHandler.h" +#include "image/FormatHandler.h" namespace love { @@ -33,16 +33,16 @@ namespace magpie /** * Handles PKM files with compressed ETC data inside. **/ -class PKMHandler : public CompressedFormatHandler +class PKMHandler : public FormatHandler { public: virtual ~PKMHandler() {} - // Implements CompressedFormatHandler. - bool canParse(const Data *data) override; + // Implements FormatHandler. + bool canParseCompressed(Data *data) override; - StrongRef parse(Data *filedata, + StrongRef parseCompressed(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) override; diff --git a/src/modules/image/magpie/PNGHandler.cpp b/src/modules/image/magpie/PNGHandler.cpp index 814e58bee..5451609f5 100644 --- a/src/modules/image/magpie/PNGHandler.cpp +++ b/src/modules/image/magpie/PNGHandler.cpp @@ -257,7 +257,7 @@ FormatHandler::EncodedImage PNGHandler::encode(const DecodedImage &img, EncodedF return encimg; } -void PNGHandler::free(unsigned char *mem) +void PNGHandler::freeRawPixels(unsigned char *mem) { // LodePNG uses malloc, realloc, and free. if (mem) diff --git a/src/modules/image/magpie/PNGHandler.h b/src/modules/image/magpie/PNGHandler.h index f969f5630..d075f3c85 100644 --- a/src/modules/image/magpie/PNGHandler.h +++ b/src/modules/image/magpie/PNGHandler.h @@ -45,7 +45,7 @@ public: virtual DecodedImage decode(Data *data); virtual EncodedImage encode(const DecodedImage &img, EncodedFormat format); - virtual void free(unsigned char *mem); + virtual void freeRawPixels(unsigned char *mem); }; // PNGHandler diff --git a/src/modules/image/magpie/PVRHandler.cpp b/src/modules/image/magpie/PVRHandler.cpp index 6b076a780..e234b91e0 100644 --- a/src/modules/image/magpie/PVRHandler.cpp +++ b/src/modules/image/magpie/PVRHandler.cpp @@ -454,7 +454,7 @@ size_t getMipLevelSize(const PVRTexHeaderV3 &header, int miplevel) } // Anonymous namespace. -bool PVRHandler::canParse(const Data *data) +bool PVRHandler::canParseCompressed(Data *data) { if (data->getSize() < sizeof(PVRTexHeaderV2) || data->getSize() < sizeof(PVRTexHeaderV3)) return false; @@ -475,9 +475,9 @@ bool PVRHandler::canParse(const Data *data) return false; } -StrongRef PVRHandler::parse(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) +StrongRef PVRHandler::parseCompressed(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) { - if (!canParse(filedata)) + if (!canParseCompressed(filedata)) throw love::Exception("Could not decode compressed data (not a PVR file?)"); PVRTexHeaderV3 header3 = *(PVRTexHeaderV3 *) filedata->getData(); diff --git a/src/modules/image/magpie/PVRHandler.h b/src/modules/image/magpie/PVRHandler.h index 33d0b76f3..ae8e2f1e3 100644 --- a/src/modules/image/magpie/PVRHandler.h +++ b/src/modules/image/magpie/PVRHandler.h @@ -22,7 +22,7 @@ // LOVE #include "common/config.h" -#include "image/CompressedFormatHandler.h" +#include "image/FormatHandler.h" namespace love { @@ -31,16 +31,16 @@ namespace image namespace magpie { -class PVRHandler : public CompressedFormatHandler +class PVRHandler : public FormatHandler { public: virtual ~PVRHandler() {} - // Implements CompressedFormatHandler. - bool canParse(const Data *data) override; + // Implements FormatHandler. + bool canParseCompressed(Data *data) override; - StrongRef parse(Data *filedata, + StrongRef parseCompressed(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) override; diff --git a/src/modules/image/magpie/STBHandler.cpp b/src/modules/image/magpie/STBHandler.cpp index 48a50c601..82f888982 100644 --- a/src/modules/image/magpie/STBHandler.cpp +++ b/src/modules/image/magpie/STBHandler.cpp @@ -162,7 +162,7 @@ FormatHandler::EncodedImage STBHandler::encode(const DecodedImage &img, EncodedF return encimg; } -void STBHandler::free(unsigned char *mem) +void STBHandler::freeRawPixels(unsigned char *mem) { // The STB decoder gave memory allocated directly by stb_image to the // ImageData, so we use stb_image_free to delete it. diff --git a/src/modules/image/magpie/STBHandler.h b/src/modules/image/magpie/STBHandler.h index 09cee4a65..b6a7932dd 100644 --- a/src/modules/image/magpie/STBHandler.h +++ b/src/modules/image/magpie/STBHandler.h @@ -48,7 +48,7 @@ public: DecodedImage decode(Data *data) override; EncodedImage encode(const DecodedImage &img, EncodedFormat format) override; - void free(unsigned char *mem) override; + void freeRawPixels(unsigned char *mem) override; }; // STBHandler diff --git a/src/modules/image/magpie/ddsHandler.cpp b/src/modules/image/magpie/ddsHandler.cpp index 1330efe03..b9baba616 100644 --- a/src/modules/image/magpie/ddsHandler.cpp +++ b/src/modules/image/magpie/ddsHandler.cpp @@ -28,12 +28,12 @@ namespace image namespace magpie { -bool DDSHandler::canParse(const Data *data) +bool DDSHandler::canParseCompressed(Data *data) { return dds::isCompressedDDS(data->getData(), data->getSize()); } -StrongRef DDSHandler::parse(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) +StrongRef DDSHandler::parseCompressed(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) { if (!dds::isDDS(filedata->getData(), filedata->getSize())) throw love::Exception("Could not decode compressed data (not a DDS file?)"); diff --git a/src/modules/image/magpie/ddsHandler.h b/src/modules/image/magpie/ddsHandler.h index 138e19f49..b4ecf8269 100644 --- a/src/modules/image/magpie/ddsHandler.h +++ b/src/modules/image/magpie/ddsHandler.h @@ -21,7 +21,7 @@ #pragma once // LOVE -#include "image/CompressedFormatHandler.h" +#include "image/FormatHandler.h" // dds parser #include "ddsparse/ddsparse.h" @@ -39,16 +39,16 @@ namespace magpie /** * Interface between CompressedImageData and the ddsparse library. **/ -class DDSHandler : public CompressedFormatHandler +class DDSHandler : public FormatHandler { public: virtual ~DDSHandler() {} - // Implements CompressedFormatHandler. - bool canParse(const Data *data) override; + // Implements FormatHandler. + bool canParseCompressed(Data *data) override; - StrongRef parse(Data *filedata, + StrongRef parseCompressed(Data *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) override;