diff --git a/CMakeLists.txt b/CMakeLists.txt index d32c13b28..9ad8b14b1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -575,8 +575,13 @@ 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 + src/modules/image/CompressedSlice.h + src/modules/image/FormatHandler.cpp + src/modules/image/FormatHandler.h src/modules/image/Image.cpp src/modules/image/Image.h src/modules/image/ImageData.cpp @@ -594,17 +599,10 @@ set(LOVE_SRC_MODULE_IMAGE_ROOT set(LOVE_SRC_MODULE_IMAGE_MAGPIE src/modules/image/magpie/ASTCHandler.cpp src/modules/image/magpie/ASTCHandler.h - src/modules/image/magpie/CompressedImageData.cpp - src/modules/image/magpie/CompressedImageData.h - src/modules/image/magpie/CompressedFormatHandler.h src/modules/image/magpie/ddsHandler.cpp src/modules/image/magpie/ddsHandler.h src/modules/image/magpie/EXRHandler.cpp src/modules/image/magpie/EXRHandler.h - src/modules/image/magpie/FormatHandler.cpp - src/modules/image/magpie/FormatHandler.h - src/modules/image/magpie/Image.cpp - src/modules/image/magpie/Image.h src/modules/image/magpie/ImageData.cpp src/modules/image/magpie/ImageData.h src/modules/image/magpie/KTXHandler.cpp diff --git a/platform/xcode/liblove.xcodeproj/project.pbxproj b/platform/xcode/liblove.xcodeproj/project.pbxproj index 772b2ab21..908b11b0f 100644 --- a/platform/xcode/liblove.xcodeproj/project.pbxproj +++ b/platform/xcode/liblove.xcodeproj/project.pbxproj @@ -469,22 +469,9 @@ FA0B7D861A95902C000E1D17 /* ImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BC61A95902C000E1D17 /* ImageData.cpp */; }; FA0B7D871A95902C000E1D17 /* ImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BC61A95902C000E1D17 /* ImageData.cpp */; }; FA0B7D881A95902C000E1D17 /* ImageData.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BC71A95902C000E1D17 /* ImageData.h */; }; - FA0B7D891A95902C000E1D17 /* CompressedImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BC91A95902C000E1D17 /* CompressedImageData.cpp */; }; - FA0B7D8A1A95902C000E1D17 /* CompressedImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BC91A95902C000E1D17 /* CompressedImageData.cpp */; }; - FA0B7D8B1A95902C000E1D17 /* CompressedImageData.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BCA1A95902C000E1D17 /* CompressedImageData.h */; }; - FA0B7D8C1A95902C000E1D17 /* CompressedFormatHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BCB1A95902C000E1D17 /* CompressedFormatHandler.h */; }; FA0B7D8D1A95902C000E1D17 /* ddsHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BCC1A95902C000E1D17 /* ddsHandler.cpp */; }; FA0B7D8E1A95902C000E1D17 /* ddsHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BCC1A95902C000E1D17 /* ddsHandler.cpp */; }; FA0B7D8F1A95902C000E1D17 /* ddsHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BCD1A95902C000E1D17 /* ddsHandler.h */; }; - FA0B7D901A95902C000E1D17 /* FormatHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BCE1A95902C000E1D17 /* FormatHandler.cpp */; }; - FA0B7D911A95902C000E1D17 /* FormatHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BCE1A95902C000E1D17 /* FormatHandler.cpp */; }; - FA0B7D921A95902C000E1D17 /* FormatHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BCF1A95902C000E1D17 /* FormatHandler.h */; }; - FA0B7D931A95902C000E1D17 /* Image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BD01A95902C000E1D17 /* Image.cpp */; }; - FA0B7D941A95902C000E1D17 /* Image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BD01A95902C000E1D17 /* Image.cpp */; }; - FA0B7D951A95902C000E1D17 /* Image.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BD11A95902C000E1D17 /* Image.h */; }; - FA0B7D961A95902C000E1D17 /* ImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BD21A95902C000E1D17 /* ImageData.cpp */; }; - FA0B7D971A95902C000E1D17 /* ImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BD21A95902C000E1D17 /* ImageData.cpp */; }; - FA0B7D981A95902C000E1D17 /* ImageData.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BD31A95902C000E1D17 /* ImageData.h */; }; FA0B7D9F1A95902C000E1D17 /* KTXHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BD81A95902C000E1D17 /* KTXHandler.cpp */; }; FA0B7DA01A95902C000E1D17 /* KTXHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BD81A95902C000E1D17 /* KTXHandler.cpp */; }; FA0B7DA11A95902C000E1D17 /* KTXHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BD91A95902C000E1D17 /* KTXHandler.h */; }; @@ -948,6 +935,9 @@ FA91591E1CF1ED7500A7053F /* halffloat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA91591C1CF1ED7500A7053F /* halffloat.cpp */; }; FA91591F1CF1ED7500A7053F /* halffloat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA91591C1CF1ED7500A7053F /* halffloat.cpp */; }; FA9159201CF1ED7500A7053F /* halffloat.h in Headers */ = {isa = PBXBuildFile; fileRef = FA91591D1CF1ED7500A7053F /* halffloat.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 */; }; FA9D8DD11DEB56C3002CD881 /* pixelformat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA9D8DCF1DEB56C3002CD881 /* pixelformat.cpp */; }; FA9D8DD21DEB56C3002CD881 /* pixelformat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA9D8DCF1DEB56C3002CD881 /* pixelformat.cpp */; }; @@ -1036,6 +1026,10 @@ FADF543D1E3DAFF700012CC0 /* wrap_Graphics.h in Headers */ = {isa = PBXBuildFile; fileRef = FADF543A1E3DAFF700012CC0 /* wrap_Graphics.h */; }; FAE272521C05A15B00A67640 /* ParticleSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAE272501C05A15B00A67640 /* ParticleSystem.cpp */; }; FAE272531C05A15B00A67640 /* ParticleSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE272511C05A15B00A67640 /* ParticleSystem.h */; }; + FAECA1B21F3164700095D008 /* CompressedSlice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAECA1B01F3164700095D008 /* CompressedSlice.cpp */; }; + FAECA1B31F3164700095D008 /* CompressedSlice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAECA1B01F3164700095D008 /* CompressedSlice.cpp */; }; + FAECA1B41F3164700095D008 /* CompressedSlice.h in Headers */ = {isa = PBXBuildFile; fileRef = FAECA1B11F3164700095D008 /* CompressedSlice.h */; }; + FAECA1B51F31648A0095D008 /* FormatHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA93C4511F315B960087CCD4 /* FormatHandler.cpp */; }; FAF140531E20934C00F898D2 /* CodeGen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAF13FC21E20934C00F898D2 /* CodeGen.cpp */; }; FAF140541E20934C00F898D2 /* CodeGen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAF13FC21E20934C00F898D2 /* CodeGen.cpp */; }; FAF140551E20934C00F898D2 /* Link.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAF13FC31E20934C00F898D2 /* Link.cpp */; }; @@ -1482,17 +1476,8 @@ FA0B7BC51A95902C000E1D17 /* Image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Image.h; sourceTree = ""; }; FA0B7BC61A95902C000E1D17 /* ImageData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageData.cpp; sourceTree = ""; }; FA0B7BC71A95902C000E1D17 /* ImageData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageData.h; sourceTree = ""; }; - FA0B7BC91A95902C000E1D17 /* CompressedImageData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CompressedImageData.cpp; sourceTree = ""; }; - FA0B7BCA1A95902C000E1D17 /* CompressedImageData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompressedImageData.h; sourceTree = ""; }; - FA0B7BCB1A95902C000E1D17 /* CompressedFormatHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompressedFormatHandler.h; sourceTree = ""; }; FA0B7BCC1A95902C000E1D17 /* ddsHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ddsHandler.cpp; sourceTree = ""; }; FA0B7BCD1A95902C000E1D17 /* ddsHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ddsHandler.h; sourceTree = ""; }; - FA0B7BCE1A95902C000E1D17 /* FormatHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormatHandler.cpp; sourceTree = ""; }; - FA0B7BCF1A95902C000E1D17 /* FormatHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormatHandler.h; sourceTree = ""; }; - FA0B7BD01A95902C000E1D17 /* Image.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Image.cpp; sourceTree = ""; }; - FA0B7BD11A95902C000E1D17 /* Image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Image.h; sourceTree = ""; }; - FA0B7BD21A95902C000E1D17 /* ImageData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageData.cpp; sourceTree = ""; }; - FA0B7BD31A95902C000E1D17 /* ImageData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageData.h; sourceTree = ""; }; FA0B7BD81A95902C000E1D17 /* KTXHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KTXHandler.cpp; sourceTree = ""; }; FA0B7BD91A95902C000E1D17 /* KTXHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KTXHandler.h; sourceTree = ""; }; FA0B7BDA1A95902C000E1D17 /* PKMHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PKMHandler.cpp; sourceTree = ""; }; @@ -1808,6 +1793,9 @@ FA8951A11AA2EDF300EC385A /* wrap_Event.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Event.h; sourceTree = ""; }; FA91591C1CF1ED7500A7053F /* halffloat.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = halffloat.cpp; sourceTree = ""; }; FA91591D1CF1ED7500A7053F /* halffloat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = halffloat.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 = ""; }; FA9D8DCF1DEB56C3002CD881 /* pixelformat.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pixelformat.cpp; sourceTree = ""; }; FA9D8DD01DEB56C3002CD881 /* pixelformat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pixelformat.h; sourceTree = ""; }; @@ -1870,6 +1858,8 @@ FADF543A1E3DAFF700012CC0 /* wrap_Graphics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Graphics.h; sourceTree = ""; }; FAE272501C05A15B00A67640 /* ParticleSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParticleSystem.cpp; sourceTree = ""; }; FAE272511C05A15B00A67640 /* ParticleSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParticleSystem.h; sourceTree = ""; }; + FAECA1B01F3164700095D008 /* CompressedSlice.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CompressedSlice.cpp; sourceTree = ""; }; + FAECA1B11F3164700095D008 /* CompressedSlice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CompressedSlice.h; sourceTree = ""; }; FAF13FC21E20934C00F898D2 /* CodeGen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CodeGen.cpp; sourceTree = ""; }; FAF13FC31E20934C00F898D2 /* Link.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Link.cpp; sourceTree = ""; }; FAF13FC51E20934C00F898D2 /* arrays.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = arrays.h; sourceTree = ""; }; @@ -2760,8 +2750,13 @@ FA0B7BC21A95902C000E1D17 /* image */ = { isa = PBXGroup; children = ( + FA93C44F1F315B960087CCD4 /* CompressedFormatHandler.h */, FA0B7BC31A95902C000E1D17 /* CompressedImageData.cpp */, FA0B7BC41A95902C000E1D17 /* CompressedImageData.h */, + FAECA1B01F3164700095D008 /* CompressedSlice.cpp */, + FAECA1B11F3164700095D008 /* CompressedSlice.h */, + FA93C4511F315B960087CCD4 /* FormatHandler.cpp */, + FA93C4501F315B960087CCD4 /* FormatHandler.h */, FA9D8DDF1DEF843D002CD881 /* Image.cpp */, FA0B7BC51A95902C000E1D17 /* Image.h */, FA0B7BC61A95902C000E1D17 /* ImageData.cpp */, @@ -2785,19 +2780,10 @@ children = ( FA41A3C61C0A1F950084430C /* ASTCHandler.cpp */, FA41A3C71C0A1F950084430C /* ASTCHandler.h */, - FA0B7BCB1A95902C000E1D17 /* CompressedFormatHandler.h */, - FA0B7BC91A95902C000E1D17 /* CompressedImageData.cpp */, - FA0B7BCA1A95902C000E1D17 /* CompressedImageData.h */, FA0B7BCC1A95902C000E1D17 /* ddsHandler.cpp */, FA0B7BCD1A95902C000E1D17 /* ddsHandler.h */, FA1557C11CE90BD200AFF582 /* EXRHandler.cpp */, FA1557C21CE90BD200AFF582 /* EXRHandler.h */, - FA0B7BCE1A95902C000E1D17 /* FormatHandler.cpp */, - FA0B7BCF1A95902C000E1D17 /* FormatHandler.h */, - FA0B7BD01A95902C000E1D17 /* Image.cpp */, - FA0B7BD11A95902C000E1D17 /* Image.h */, - FA0B7BD21A95902C000E1D17 /* ImageData.cpp */, - FA0B7BD31A95902C000E1D17 /* ImageData.h */, FA0B7BD81A95902C000E1D17 /* KTXHandler.cpp */, FA0B7BD91A95902C000E1D17 /* KTXHandler.h */, FA0B7BDA1A95902C000E1D17 /* PKMHandler.cpp */, @@ -3550,7 +3536,6 @@ FA76344C1E28722A0066EF9E /* StreamBuffer.h in Headers */, 217DFBF31D9F6D490055D849 /* mime.h in Headers */, FA0B7B361A958EA3000E1D17 /* wuff_convert.h in Headers */, - FA0B7D981A95902C000E1D17 /* ImageData.h in Headers */, FA0B7CDE1A95902C000E1D17 /* Source.h in Headers */, FA0B7E141A95902C000E1D17 /* GearJoint.h in Headers */, FA0B7D051A95902C000E1D17 /* wrap_DroppedFile.h in Headers */, @@ -3612,6 +3597,7 @@ FA0B7CD21A95902C000E1D17 /* Audio.h in Headers */, FA0B79421A958E3B000E1D17 /* utf8.h in Headers */, FA0B7D171A95902C000E1D17 /* Font.h in Headers */, + FAECA1B41F3164700095D008 /* CompressedSlice.h in Headers */, FA0B7A6D1A958EA3000E1D17 /* b2World.h in Headers */, FA0B7EAE1A95902C000E1D17 /* wrap_SoundData.h in Headers */, FA0B7CFF1A95902C000E1D17 /* File.h in Headers */, @@ -3661,6 +3647,7 @@ 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 */, @@ -3720,6 +3707,7 @@ FA0B7ECD1A95902C000E1D17 /* wrap_Channel.h in Headers */, FAF140AF1E20934C00F898D2 /* osinclude.h in Headers */, FA0B7A431A958EA3000E1D17 /* b2CircleShape.h in Headers */, + FA93C4531F315B960087CCD4 /* FormatHandler.h in Headers */, FA0B7CD81A95902C000E1D17 /* Audio.h in Headers */, FA0B7CF61A95902C000E1D17 /* File.h in Headers */, FA0B7E961A95902C000E1D17 /* Mpg123Decoder.h in Headers */, @@ -3728,7 +3716,6 @@ FA0B7DD51A95902C000E1D17 /* BezierCurve.h in Headers */, FA0B79271A958E3B000E1D17 /* int.h in Headers */, FA27B3A21B498151008A9DCE /* VideoStream.h in Headers */, - FA0B7D8C1A95902C000E1D17 /* CompressedFormatHandler.h in Headers */, FA0B7E531A95902C000E1D17 /* wrap_FrictionJoint.h in Headers */, FA0B7EB71A95902C000E1D17 /* wrap_System.h in Headers */, FA27B3A91B498151008A9DCE /* Video.h in Headers */, @@ -3738,7 +3725,6 @@ FAB17BF21ABFB37500F9BA27 /* wrap_CompressedData.h in Headers */, FA0B7E801A95902C000E1D17 /* Joint.h in Headers */, FA0B7D2F1A95902C000E1D17 /* Drawable.h in Headers */, - FA0B7D951A95902C000E1D17 /* Image.h in Headers */, 217DFBE21D9F6D490055D849 /* ftp.lua.h in Headers */, FA0B7EC41A95902C000E1D17 /* Thread.h in Headers */, FA0B7DFF1A95902C000E1D17 /* ChainShape.h in Headers */, @@ -3794,7 +3780,6 @@ FA0B7CF91A95902C000E1D17 /* FileData.h in Headers */, FA0B7DA71A95902C000E1D17 /* PNGHandler.h in Headers */, FA0B7AC41A958EA3000E1D17 /* protocol.h in Headers */, - FA0B7D8B1A95902C000E1D17 /* CompressedImageData.h in Headers */, FAF140601E20934C00F898D2 /* revision.h in Headers */, FAF140A21E20934C00F898D2 /* RemoveTree.h in Headers */, FA0B7A8E1A958EA3000E1D17 /* b2DistanceJoint.h in Headers */, @@ -3895,7 +3880,6 @@ FADF54041E3D77B500012CC0 /* wrap_Text.h in Headers */, FA0B7ED31A95902C000E1D17 /* wrap_ThreadModule.h in Headers */, FA0B7A511A958EA3000E1D17 /* b2GrowableStack.h in Headers */, - FA0B7D921A95902C000E1D17 /* FormatHandler.h in Headers */, FAC756F61E4F99B400B91289 /* Effect.h in Headers */, FA0B7ADD1A958EA3000E1D17 /* gladfuncs.hpp in Headers */, FAF1405D1E20934C00F898D2 /* intermediate.h in Headers */, @@ -4051,7 +4035,6 @@ FA0B7ABE1A958EA3000E1D17 /* compress.c in Sources */, FA0B7CF21A95902C000E1D17 /* DroppedFile.cpp in Sources */, FA4F2C141DE936FE00CA37D7 /* usocket.c in Sources */, - FA0B7D8A1A95902C000E1D17 /* CompressedImageData.cpp in Sources */, FAF140831E20934C00F898D2 /* ParseContextBase.cpp in Sources */, FA0B7AD21A958EA3000E1D17 /* protocol.c in Sources */, FAF140A41E20934C00F898D2 /* Scan.cpp in Sources */, @@ -4190,15 +4173,14 @@ FADF54211E3DA52C00012CC0 /* wrap_ParticleSystem.cpp in Sources */, FA0B791C1A958E3B000E1D17 /* b64.cpp in Sources */, FA1E88851DF363E100E808AA /* Filter.cpp in Sources */, - FA0B7D941A95902C000E1D17 /* Image.cpp in Sources */, FA0B7DA01A95902C000E1D17 /* KTXHandler.cpp in Sources */, FA27B3A11B498151008A9DCE /* VideoStream.cpp in Sources */, FA0B7A5C1A958EA3000E1D17 /* b2Timer.cpp in Sources */, FA0B7CEC1A95902C000E1D17 /* Event.cpp in Sources */, FA27B3AB1B498151008A9DCE /* VideoStream.cpp in Sources */, FA0B7A7E1A958EA3000E1D17 /* b2ContactSolver.cpp in Sources */, - FA0B7D971A95902C000E1D17 /* ImageData.cpp in Sources */, FA0B7E581A95902C000E1D17 /* wrap_Joint.cpp in Sources */, + FAECA1B51F31648A0095D008 /* FormatHandler.cpp in Sources */, FA4F2C0A1DE936E600CA37D7 /* mime.c in Sources */, FA0B7E311A95902C000E1D17 /* Shape.cpp in Sources */, FA0B7E491A95902C000E1D17 /* wrap_DistanceJoint.cpp in Sources */, @@ -4287,13 +4269,13 @@ FA0B7DB21A95902C000E1D17 /* wrap_Image.cpp in Sources */, FA0B7E891A95902C000E1D17 /* Decoder.cpp in Sources */, FA0B7A591A958EA3000E1D17 /* b2StackAllocator.cpp in Sources */, + FAECA1B31F3164700095D008 /* CompressedSlice.cpp in Sources */, FA0B7E3D1A95902C000E1D17 /* wrap_Body.cpp in Sources */, FA0B7D7A1A95902C000E1D17 /* Quad.cpp in Sources */, FA620A3B1AA305F6005DB4C2 /* types.cpp in Sources */, FA0B7DD41A95902C000E1D17 /* BezierCurve.cpp in Sources */, FA0B7E7C1A95902C000E1D17 /* wrap_World.cpp in Sources */, FA4F2C0E1DE936FE00CA37D7 /* tcp.c in Sources */, - FA0B7D911A95902C000E1D17 /* FormatHandler.cpp in Sources */, FA0B7D431A95902C000E1D17 /* OpenGL.cpp in Sources */, FA0B7DBF1A95902C000E1D17 /* JoystickModule.cpp in Sources */, FA0B7D4F1A95902C000E1D17 /* SpriteBatch.cpp in Sources */, @@ -4410,7 +4392,6 @@ FA0B7D091A95902C000E1D17 /* wrap_FileData.cpp in Sources */, FA0B7B341A958EA3000E1D17 /* wuff_convert.c in Sources */, FA0B7CF11A95902C000E1D17 /* DroppedFile.cpp in Sources */, - FA0B7D891A95902C000E1D17 /* CompressedImageData.cpp in Sources */, FAF140821E20934C00F898D2 /* ParseContextBase.cpp in Sources */, FA0B7D1E1A95902C000E1D17 /* ImageRasterizer.cpp in Sources */, FAF140A31E20934C00F898D2 /* Scan.cpp in Sources */, @@ -4545,7 +4526,6 @@ FA0B7A4E1A958EA3000E1D17 /* b2Draw.cpp in Sources */, FAD19A171DFF8CA200D5398A /* ImageDataBase.cpp in Sources */, FA27B3C01B4985BF008A9DCE /* wrap_VideoStream.cpp in Sources */, - FA0B7D931A95902C000E1D17 /* Image.cpp in Sources */, FADF54201E3DA52C00012CC0 /* wrap_ParticleSystem.cpp in Sources */, FA0B7D9F1A95902C000E1D17 /* KTXHandler.cpp in Sources */, FA1E88831DF363DB00E808AA /* Filter.cpp in Sources */, @@ -4554,9 +4534,9 @@ FA0B7CEB1A95902C000E1D17 /* Event.cpp in Sources */, FA1557C31CE90BD200AFF582 /* EXRHandler.cpp in Sources */, FA27B3AA1B498151008A9DCE /* VideoStream.cpp in Sources */, - FA0B7D961A95902C000E1D17 /* ImageData.cpp in Sources */, FA0B7E571A95902C000E1D17 /* wrap_Joint.cpp in Sources */, FA0B7E301A95902C000E1D17 /* Shape.cpp in Sources */, + FA93C4541F315B960087CCD4 /* FormatHandler.cpp in Sources */, FA0B7E481A95902C000E1D17 /* wrap_DistanceJoint.cpp in Sources */, FA0B7A8F1A958EA3000E1D17 /* b2FrictionJoint.cpp in Sources */, FA0B792F1A958E3B000E1D17 /* Module.cpp in Sources */, @@ -4597,6 +4577,7 @@ FA0B7E8B1A95902C000E1D17 /* FLACDecoder.cpp in Sources */, FA0B7B3A1A958EA3000E1D17 /* wuff_memory.c in Sources */, FA0B7A381A958EA3000E1D17 /* b2DynamicTree.cpp in Sources */, + FAECA1B21F3164700095D008 /* CompressedSlice.cpp in Sources */, FA0B7D481A95902C000E1D17 /* Polyline.cpp in Sources */, 217DFC111D9F6D490055D849 /* usocket.c in Sources */, FAF140751E20934C00F898D2 /* IntermTraverse.cpp in Sources */, @@ -4647,7 +4628,6 @@ FA91591E1CF1ED7500A7053F /* halffloat.cpp in Sources */, FA0B7E7B1A95902C000E1D17 /* wrap_World.cpp in Sources */, FA0B7B281A958EA3000E1D17 /* simplexnoise1234.cpp in Sources */, - FA0B7D901A95902C000E1D17 /* FormatHandler.cpp in Sources */, FA0B7D421A95902C000E1D17 /* OpenGL.cpp in Sources */, FA0B7A671A958EA3000E1D17 /* b2Island.cpp in Sources */, FA0B7DBE1A95902C000E1D17 /* JoystickModule.cpp in Sources */, diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index 5ea26ee5b..074c777f2 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -447,7 +447,7 @@ static int screenshotSaveToFile(lua_State *L) const char *filename = luaL_checkstring(L, lua_upvalueindex(1)); const char *ext = luaL_checkstring(L, lua_upvalueindex(2)); - image::ImageData::EncodedFormat format; + image::FormatHandler::EncodedFormat format; if (!image::ImageData::getConstant(ext, format)) return 0; @@ -478,7 +478,7 @@ int w_captureScreenshot(lua_State *L) std::transform(ext.begin(), ext.end(), ext.begin(), tolower); - image::ImageData::EncodedFormat format; + image::FormatHandler::EncodedFormat format; if (!image::ImageData::getConstant(ext.c_str(), format)) return luaL_error(L, "Invalid encoded image format: %s", ext.c_str()); diff --git a/src/modules/image/magpie/CompressedFormatHandler.h b/src/modules/image/CompressedFormatHandler.h similarity index 78% rename from src/modules/image/magpie/CompressedFormatHandler.h rename to src/modules/image/CompressedFormatHandler.h index 81328e5be..43aa54cc9 100644 --- a/src/modules/image/magpie/CompressedFormatHandler.h +++ b/src/modules/image/CompressedFormatHandler.h @@ -18,20 +18,17 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_IMAGE_MAGPIE_COMPRESSED_HANDLER_H -#define LOVE_IMAGE_MAGPIE_COMPRESSED_HANDLER_H +#pragma once // LOVE -#include "filesystem/FileData.h" -#include "image/CompressedImageData.h" #include "common/Object.h" +#include "filesystem/FileData.h" +#include "CompressedSlice.h" namespace love { namespace image { -namespace magpie -{ /** * Base class for all CompressedImageData parser library interfaces. @@ -45,8 +42,8 @@ public: virtual ~CompressedFormatHandler() {} /** - * Determines whether a particular FileData can be parsed as CompressedImageData - * by this handler. + * Determines whether a particular FileData can be parsed as + * CompressedImageData by this handler. * @param data The data to parse. **/ virtual bool canParse(const filesystem::FileData *data) = 0; @@ -56,21 +53,18 @@ public: * 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] 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(filesystem::FileData *filedata, - std::vector> &images, + virtual StrongRef parse(filesystem::FileData *filedata, + std::vector> &images, PixelFormat &format, bool &sRGB) = 0; }; // CompressedFormatHandler -} // magpie } // image } // love - -#endif // LOVE_IMAGE_MAGPIE_COMPRESSED_HANDLER_H diff --git a/src/modules/image/CompressedImageData.cpp b/src/modules/image/CompressedImageData.cpp index 066a3b291..984c93df5 100644 --- a/src/modules/image/CompressedImageData.cpp +++ b/src/modules/image/CompressedImageData.cpp @@ -27,58 +27,54 @@ namespace image love::Type CompressedImageData::type("CompressedImageData", &Data::type); -CompressedImageData::Memory::Memory(size_t size) - : data(nullptr) - , size(size) -{ - try - { - data = new uint8[size]; - } - catch (std::exception &) - { - throw love::Exception("Out of memory."); - } -} - -CompressedImageData::Memory::~Memory() -{ - delete[] data; -} - -CompressedImageData::Slice::Slice(PixelFormat format, int width, int height, Memory *memory, size_t offset, size_t size) - : memory(memory) - , offset(offset) - , dataSize(size) -{ - this->format = format; - this->width = width; - this->height = height; -} - -CompressedImageData::Slice::Slice(const Slice &s) - : memory(s.memory) - , offset(s.offset) - , dataSize(s.dataSize) -{ - this->format = s.getFormat(); - this->width = s.getWidth(); - this->height = s.getHeight(); -} - -CompressedImageData::Slice::~Slice() -{ -} - -CompressedImageData::Slice *CompressedImageData::Slice::clone() const -{ - return new Slice(*this); -} - -CompressedImageData::CompressedImageData() +CompressedImageData::CompressedImageData(const std::list &formats, love::filesystem::FileData *filedata) : format(PIXELFORMAT_UNKNOWN) , sRGB(false) { + CompressedFormatHandler *parser = nullptr; + + for (CompressedFormatHandler *handler : formats) + { + if (handler->canParse(filedata)) + { + parser = handler; + break; + } + } + + if (parser == nullptr) + throw love::Exception("Could not parse compressed data: Unknown format."); + + memory = parser->parse(filedata, dataImages, format, sRGB); + + if (memory == nullptr) + throw love::Exception("Could not parse compressed data."); + + if (format == PIXELFORMAT_UNKNOWN) + throw love::Exception("Could not parse compressed data: Unknown format."); + + if (dataImages.size() == 0 || memory->size == 0) + throw love::Exception("Could not parse compressed data: No valid data?"); +} + +CompressedImageData::CompressedImageData(const CompressedImageData &c) + : format(c.format) + , sRGB(c.sRGB) +{ + memory.set(new CompressedMemory(c.memory->size), Acquire::NORETAIN); + memcpy(memory->data, c.memory->data, memory->size); + + for (const auto &i : c.dataImages) + { + auto slice = new CompressedSlice(i->getFormat(), i->getWidth(), i->getHeight(), memory, i->getOffset(), i->getSize()); + dataImages.push_back(slice); + slice->release(); + } +} + +CompressedImageData *CompressedImageData::clone() const +{ + return new CompressedImageData(*this); } CompressedImageData::~CompressedImageData() @@ -143,7 +139,7 @@ bool CompressedImageData::isSRGB() const return sRGB; } -CompressedImageData::Slice *CompressedImageData::getSlice(int slice, int miplevel) const +CompressedSlice *CompressedImageData::getSlice(int slice, int miplevel) const { checkSliceExists(slice, miplevel); diff --git a/src/modules/image/CompressedImageData.h b/src/modules/image/CompressedImageData.h index fef680085..5a2ecfea2 100644 --- a/src/modules/image/CompressedImageData.h +++ b/src/modules/image/CompressedImageData.h @@ -25,10 +25,13 @@ #include "common/StringMap.h" #include "common/int.h" #include "common/pixelformat.h" -#include "ImageDataBase.h" +#include "filesystem/FileData.h" +#include "CompressedSlice.h" +#include "CompressedFormatHandler.h" // STL #include +#include namespace love { @@ -44,53 +47,16 @@ class CompressedImageData : public Data { public: - class Memory : public Object - { - public: - - Memory(size_t size); - virtual ~Memory(); - - uint8 *data; - size_t size; - - }; // Memory - - // Compressed image data can have multiple mipmap levels, each represented - // by a sub-image. - class Slice : public ImageDataBase - { - public: - - Slice(PixelFormat format, int width, int height, Memory *memory, size_t offset, size_t size); - Slice(const Slice &slice); - virtual ~Slice(); - - Slice *clone() const override; - void *getData() const override { return memory->data + offset; } - size_t getSize() const override { return dataSize; } - bool isSRGB() const override { return sRGB; } - size_t getOffset() const { return offset; } - - private: - - StrongRef memory; - - size_t offset; - size_t dataSize; - bool sRGB; - - }; // Slice - static love::Type type; - CompressedImageData(); + CompressedImageData(const std::list &formats, love::filesystem::FileData *filedata); + CompressedImageData(const CompressedImageData &c); virtual ~CompressedImageData(); // Implements Data. - virtual CompressedImageData *clone() const = 0; - virtual void *getData() const; - virtual size_t getSize() const; + CompressedImageData *clone() const override; + void *getData() const override; + size_t getSize() const override; /** * Gets the number of mipmaps in this Compressed Image Data. @@ -130,19 +96,18 @@ public: bool isSRGB() const; - Slice *getSlice(int slice, int miplevel) const; + CompressedSlice *getSlice(int slice, int miplevel) const; protected: PixelFormat format; - bool sRGB; // Single block of memory containing all of the sub-images. - StrongRef memory; + StrongRef memory; // Texture info for each mipmap level. - std::vector> dataImages; + std::vector> dataImages; void checkSliceExists(int slice, int miplevel) const; diff --git a/src/modules/image/magpie/CompressedImageData.h b/src/modules/image/CompressedSlice.cpp similarity index 52% rename from src/modules/image/magpie/CompressedImageData.h rename to src/modules/image/CompressedSlice.cpp index c8fd624f5..f640c8740 100644 --- a/src/modules/image/magpie/CompressedImageData.h +++ b/src/modules/image/CompressedSlice.cpp @@ -18,37 +18,61 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_IMAGE_MAGPIE_COMPRESSED_IMAGE_DATA_H -#define LOVE_IMAGE_MAGPIE_COMPRESSED_IMAGE_DATA_H - -// LOVE -#include "CompressedFormatHandler.h" -#include "filesystem/FileData.h" -#include "image/CompressedImageData.h" - -// C++ -#include +#include "CompressedSlice.h" +#include "common/Exception.h" namespace love { namespace image { -namespace magpie + +CompressedMemory::CompressedMemory(size_t size) + : data(nullptr) + , size(size) { + try + { + data = new uint8[size]; + } + catch (std::exception &) + { + throw love::Exception("Out of memory."); + } +} -class CompressedImageData : public love::image::CompressedImageData +CompressedMemory::~CompressedMemory() { -public: + delete[] data; +} - CompressedImageData(std::list formats, love::filesystem::FileData *filedata); - CompressedImageData(const CompressedImageData &c); - virtual ~CompressedImageData(); +CompressedSlice::CompressedSlice(PixelFormat format, int width, int height, CompressedMemory *memory, size_t offset, size_t size) + : memory(memory) + , offset(offset) + , dataSize(size) +{ + this->format = format; + this->width = width; + this->height = height; +} - virtual CompressedImageData *clone() const; -}; // CompressedImageData +CompressedSlice::CompressedSlice(const CompressedSlice &s) + : memory(s.memory) + , offset(s.offset) + , dataSize(s.dataSize) +{ + this->format = s.getFormat(); + this->width = s.getWidth(); + this->height = s.getHeight(); +} + +CompressedSlice::~CompressedSlice() +{ +} + +CompressedSlice *CompressedSlice::clone() const +{ + return new CompressedSlice(*this); +} -} // magpie } // image } // love - -#endif // LOVE_IMAGE_MAGPIE_COMPRESSED_IMAGE_DATA_H diff --git a/src/modules/image/CompressedSlice.h b/src/modules/image/CompressedSlice.h new file mode 100644 index 000000000..bfe4ce946 --- /dev/null +++ b/src/modules/image/CompressedSlice.h @@ -0,0 +1,72 @@ +/** + * 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/int.h" +#include "common/pixelformat.h" +#include "common/Object.h" +#include "ImageDataBase.h" + +namespace love +{ +namespace image +{ + +class CompressedMemory : public Object +{ +public: + + CompressedMemory(size_t size); + virtual ~CompressedMemory(); + + uint8 *data; + size_t size; + +}; // CompressedMemory + +// Compressed image data can have multiple mipmap levels, each represented by a +// sub-image. +class CompressedSlice : public ImageDataBase +{ +public: + + CompressedSlice(PixelFormat format, int width, int height, CompressedMemory *memory, size_t offset, size_t size); + CompressedSlice(const CompressedSlice &slice); + virtual ~CompressedSlice(); + + CompressedSlice *clone() const override; + void *getData() const override { return memory->data + offset; } + size_t getSize() const override { return dataSize; } + bool isSRGB() const override { return sRGB; } + size_t getOffset() const { return offset; } + +private: + + StrongRef memory; + size_t offset; + size_t dataSize; + bool sRGB; + +}; // CompressedSlice + +} // image +} // love diff --git a/src/modules/image/magpie/FormatHandler.cpp b/src/modules/image/FormatHandler.cpp similarity index 89% rename from src/modules/image/magpie/FormatHandler.cpp rename to src/modules/image/FormatHandler.cpp index a50562c1e..689609f56 100644 --- a/src/modules/image/magpie/FormatHandler.cpp +++ b/src/modules/image/FormatHandler.cpp @@ -26,8 +26,6 @@ namespace love { namespace image { -namespace magpie -{ FormatHandler::FormatHandler() { @@ -42,7 +40,7 @@ bool FormatHandler::canDecode(love::filesystem::FileData* /*data*/) return false; } -bool FormatHandler::canEncode(PixelFormat /*rawFormat*/, ImageData::EncodedFormat /*encodedFormat*/) +bool FormatHandler::canEncode(PixelFormat /*rawFormat*/, EncodedFormat /*encodedFormat*/) { return false; } @@ -52,7 +50,7 @@ FormatHandler::DecodedImage FormatHandler::decode(love::filesystem::FileData* /* throw love::Exception("Image decoding is not implemented for this format backend."); } -FormatHandler::EncodedImage FormatHandler::encode(const DecodedImage& /*img*/, ImageData::EncodedFormat /*format*/) +FormatHandler::EncodedImage FormatHandler::encode(const DecodedImage& /*img*/, EncodedFormat /*format*/) { throw love::Exception("Image encoding is not implemented for this format backend."); } @@ -62,6 +60,5 @@ void FormatHandler::free(unsigned char *mem) delete[] mem; } -} // magpie } // image } // love diff --git a/src/modules/image/magpie/FormatHandler.h b/src/modules/image/FormatHandler.h similarity index 87% rename from src/modules/image/magpie/FormatHandler.h rename to src/modules/image/FormatHandler.h index 1e76819b1..a29b42d95 100644 --- a/src/modules/image/magpie/FormatHandler.h +++ b/src/modules/image/FormatHandler.h @@ -18,20 +18,17 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_IMAGE_MAGPIE_FORMAT_HANDLER_H -#define LOVE_IMAGE_MAGPIE_FORMAT_HANDLER_H +#pragma once // LOVE -#include "image/ImageData.h" -#include "filesystem/FileData.h" #include "common/Object.h" +#include "common/pixelformat.h" +#include "filesystem/FileData.h" namespace love { namespace image { -namespace magpie -{ /** * Base class for all ImageData encoder/decoder library interfaces. @@ -41,6 +38,13 @@ class FormatHandler : public love::Object { public: + enum EncodedFormat + { + ENCODED_TGA, + ENCODED_PNG, + ENCODED_MAX_ENUM + }; + // Raw RGBA pixel data. struct DecodedImage { @@ -76,7 +80,7 @@ public: /** * Whether this format handler can encode to a particular format. **/ - virtual bool canEncode(PixelFormat rawFormat, ImageData::EncodedFormat encodedFormat); + virtual bool canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat); /** * Decodes an image from its encoded form into raw pixel data. @@ -91,7 +95,7 @@ public: * @param format The format to encode to. * @return The encoded image data. **/ - virtual EncodedImage encode(const DecodedImage &img, ImageData::EncodedFormat format); + virtual EncodedImage encode(const DecodedImage &img, EncodedFormat format); /** * Frees memory allocated by the format handler. @@ -100,8 +104,5 @@ public: }; // FormatHandler -} // magpie } // image } // love - -#endif // LOVE_IMAGE_MAGPIE_FORMAT_HANDLER_H diff --git a/src/modules/image/Image.cpp b/src/modules/image/Image.cpp index d50db0d50..9d69de4b8 100644 --- a/src/modules/image/Image.cpp +++ b/src/modules/image/Image.cpp @@ -20,6 +20,17 @@ // LOVE #include "Image.h" +#include "common/config.h" + +#include "magpie/PNGHandler.h" +#include "magpie/STBHandler.h" +#include "magpie/EXRHandler.h" + +#include "magpie/ddsHandler.h" +#include "magpie/PVRHandler.h" +#include "magpie/KTXHandler.h" +#include "magpie/PKMHandler.h" +#include "magpie/ASTCHandler.h" namespace love { @@ -28,6 +39,79 @@ namespace image love::Type Image::type("image", &Module::type); +Image::Image() +{ + using namespace magpie; + + halfInit(); // Makes sure half-float conversions can be used. + + formatHandlers = { + new PNGHandler, + new STBHandler, + new EXRHandler, + }; + + compressedFormatHandlers = { + new DDSHandler, + new PVRHandler, + new KTXHandler, + new PKMHandler, + new ASTCHandler, + }; +} + +Image::~Image() +{ + // ImageData objects reference the FormatHandlers in our list, so we should + // 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 +{ + return "love.image.magpie"; +} + +love::image::ImageData *Image::newImageData(love::filesystem::FileData *data) +{ + return new ImageData(data); +} + +love::image::ImageData *Image::newImageData(int width, int height, PixelFormat format) +{ + return new ImageData(width, height, format); +} + +love::image::ImageData *Image::newImageData(int width, int height, PixelFormat format, void *data, bool own) +{ + return new ImageData(width, height, format, data, own); +} + +love::image::CompressedImageData *Image::newCompressedData(love::filesystem::FileData *data) +{ + return new CompressedImageData(compressedFormatHandlers, data); +} + +bool Image::isCompressed(love::filesystem::FileData *data) +{ + for (CompressedFormatHandler *handler : compressedFormatHandlers) + { + if (handler->canParse(data)) + return true; + } + + return false; +} + +const std::list &Image::getFormatHandlers() const +{ + return formatHandlers; +} + ImageData *Image::newPastedImageData(ImageData *src, int sx, int sy, int w, int h) { ImageData *res = newImageData(w, h, src->getFormat()); diff --git a/src/modules/image/Image.h b/src/modules/image/Image.h index 64ace18ca..a8a835439 100644 --- a/src/modules/image/Image.h +++ b/src/modules/image/Image.h @@ -28,6 +28,9 @@ #include "ImageData.h" #include "CompressedImageData.h" +// C++ +#include + namespace love { namespace image @@ -46,17 +49,19 @@ public: static love::Type type; - virtual ~Image() {} + Image(); + virtual ~Image(); // Implements Module. - virtual ModuleType getModuleType() const { return M_IMAGE; } + ModuleType getModuleType() const override { return M_IMAGE; } + const char *getName() const override; /** * Creates new ImageData from FileData. * @param data The FileData containing the encoded image data. * @return The new ImageData. **/ - virtual ImageData *newImageData(love::filesystem::FileData *data) = 0; + ImageData *newImageData(love::filesystem::FileData *data); /** * Creates empty ImageData with the given size. @@ -64,7 +69,7 @@ public: * @param height The height of the ImageData. * @return The new ImageData. **/ - virtual ImageData *newImageData(int width, int height, PixelFormat format = PIXELFORMAT_RGBA8) = 0; + ImageData *newImageData(int width, int height, PixelFormat format = PIXELFORMAT_RGBA8); /** * Creates empty ImageData with the given size. @@ -75,28 +80,36 @@ public: * copy it. * @return The new ImageData. **/ - virtual ImageData *newImageData(int width, int height, PixelFormat format, void *data, bool own = false) = 0; + ImageData *newImageData(int width, int height, PixelFormat format, void *data, bool own = false); /** * Creates new CompressedImageData from FileData. * @param data The FileData containing the compressed image data. * @return The new CompressedImageData. **/ - virtual CompressedImageData *newCompressedData(love::filesystem::FileData *data) = 0; + CompressedImageData *newCompressedData(love::filesystem::FileData *data); /** * Determines whether a FileData is Compressed image data or not. * @param data The FileData to test. **/ - virtual bool isCompressed(love::filesystem::FileData *data) = 0; + bool isCompressed(love::filesystem::FileData *data); std::vector> newCubeFaces(ImageData *src); std::vector> newVolumeLayers(ImageData *src); + const std::list &getFormatHandlers() const; + private: ImageData *newPastedImageData(ImageData *src, int sx, int sy, int w, int h); + // 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 399a08647..0313d5ae2 100644 --- a/src/modules/image/ImageData.cpp +++ b/src/modules/image/ImageData.cpp @@ -19,6 +19,8 @@ **/ #include "ImageData.h" +#include "Image.h" +#include "filesystem/Filesystem.h" using love::thread::Lock; @@ -29,13 +31,207 @@ namespace image love::Type ImageData::type("ImageData", &Data::type); -ImageData::ImageData() - : data(nullptr) +ImageData::ImageData(love::filesystem::FileData *data) { + decode(data); +} + +ImageData::ImageData(int width, int height, PixelFormat format) +{ + if (!validPixelFormat(format)) + throw love::Exception("Unsupported pixel format for ImageData"); + + this->width = width; + this->height = height; + this->format = format; + + create(width, height, format); + + // Set to black/transparency. + memset(data, 0, getSize()); +} + +ImageData::ImageData(int width, int height, PixelFormat format, void *data, bool own) +{ + if (!validPixelFormat(format)) + throw love::Exception("Unsupported pixel format for ImageData"); + + this->width = width; + this->height = height; + this->format = format; + + if (own) + this->data = (unsigned char *) data; + else + create(width, height, format, data); +} + +ImageData::ImageData(const ImageData &c) +{ + width = c.width; + height = c.height; + format = c.format; + + create(width, height, format, c.getData()); } ImageData::~ImageData() { + if (decodeHandler.get()) + decodeHandler->free(data); + else + delete[] data; +} + +love::image::ImageData *ImageData::clone() const +{ + return new ImageData(*this); +} + +void ImageData::create(int width, int height, PixelFormat format, void *data) +{ + size_t datasize = width * height * getPixelFormatSize(format); + + try + { + this->data = new unsigned char[datasize]; + } + catch(std::bad_alloc &) + { + throw love::Exception("Out of memory"); + } + + if (data) + memcpy(this->data, data, datasize); + + decodeHandler = nullptr; + this->format = format; +} + +void ImageData::decode(love::filesystem::FileData *data) +{ + FormatHandler *decoder = nullptr; + FormatHandler::DecodedImage decodedimage; + + auto module = Module::getInstance(Module::M_IMAGE); + + if (module == nullptr) + throw love::Exception("love.image must be loaded in order to decode an ImageData."); + + for (FormatHandler *handler : module->getFormatHandlers()) + { + if (handler->canDecode(data)) + { + decoder = handler; + break; + } + } + + if (decoder) + decodedimage = decoder->decode(data); + + if (decodedimage.data == nullptr) + { + const std::string &name = data->getFilename(); + throw love::Exception("Could not decode file '%s' to ImageData: unsupported file format", name.c_str()); + } + + if (decodedimage.size != decodedimage.width * decodedimage.height * getPixelFormatSize(decodedimage.format)) + { + decoder->free(decodedimage.data); + throw love::Exception("Could not convert image!"); + } + + // Clean up any old data. + if (decodeHandler) + decodeHandler->free(this->data); + else + delete[] this->data; + + this->width = decodedimage.width; + this->height = decodedimage.height; + this->data = decodedimage.data; + this->format = decodedimage.format; + + decodeHandler = decoder; +} + +love::filesystem::FileData *ImageData::encode(FormatHandler::EncodedFormat encodedFormat, const char *filename, bool writefile) const +{ + FormatHandler *encoder = nullptr; + FormatHandler::EncodedImage encodedimage; + FormatHandler::DecodedImage rawimage; + + rawimage.width = width; + rawimage.height = height; + rawimage.size = getSize(); + rawimage.data = data; + rawimage.format = format; + + auto module = Module::getInstance(Module::M_IMAGE); + + if (module == nullptr) + throw love::Exception("love.image must be loaded in order to encode an ImageData."); + + for (FormatHandler *handler : module->getFormatHandlers()) + { + if (handler->canEncode(format, encodedFormat)) + { + encoder = handler; + break; + } + } + + if (encoder != nullptr) + { + thread::Lock lock(mutex); + encodedimage = encoder->encode(rawimage, encodedFormat); + } + + if (encoder == nullptr || encodedimage.data == nullptr) + { + const char *fname = "unknown"; + love::getConstant(format, fname); + throw love::Exception("No suitable image encoder for %s format.", fname); + } + + love::filesystem::FileData *filedata = nullptr; + + try + { + filedata = new love::filesystem::FileData(encodedimage.size, filename); + } + catch (love::Exception &) + { + encoder->free(encodedimage.data); + throw; + } + + memcpy(filedata->getData(), encodedimage.data, encodedimage.size); + encoder->free(encodedimage.data); + + if (writefile) + { + auto fs = Module::getInstance(Module::M_FILESYSTEM); + + if (fs == nullptr) + { + filedata->release(); + throw love::Exception("love.filesystem must be loaded in order to write an encoded ImageData to a file."); + } + + try + { + fs->write(filename, filedata->getData(), filedata->getSize()); + } + catch (love::Exception &) + { + filedata->release(); + throw; + } + } + + return filedata; } size_t ImageData::getSize() const @@ -289,23 +485,23 @@ bool ImageData::validPixelFormat(PixelFormat format) } } -bool ImageData::getConstant(const char *in, EncodedFormat &out) +bool ImageData::getConstant(const char *in, FormatHandler::EncodedFormat &out) { return encodedFormats.find(in, out); } -bool ImageData::getConstant(EncodedFormat in, const char *&out) +bool ImageData::getConstant(FormatHandler::EncodedFormat in, const char *&out) { return encodedFormats.find(in, out); } -StringMap::Entry ImageData::encodedFormatEntries[] = +StringMap::Entry ImageData::encodedFormatEntries[] = { - {"tga", ENCODED_TGA}, - {"png", ENCODED_PNG}, + {"tga", FormatHandler::ENCODED_TGA}, + {"png", FormatHandler::ENCODED_PNG}, }; -StringMap ImageData::encodedFormats(ImageData::encodedFormatEntries, sizeof(ImageData::encodedFormatEntries)); +StringMap ImageData::encodedFormats(ImageData::encodedFormatEntries, sizeof(ImageData::encodedFormatEntries)); } // image } // love diff --git a/src/modules/image/ImageData.h b/src/modules/image/ImageData.h index c7f84bd01..21f654534 100644 --- a/src/modules/image/ImageData.h +++ b/src/modules/image/ImageData.h @@ -29,6 +29,7 @@ #include "filesystem/FileData.h" #include "thread/threads.h" #include "ImageDataBase.h" +#include "FormatHandler.h" using love::thread::Mutex; @@ -61,14 +62,10 @@ public: static love::Type type; - enum EncodedFormat - { - ENCODED_TGA, - ENCODED_PNG, - ENCODED_MAX_ENUM - }; - - ImageData(); + ImageData(love::filesystem::FileData *data); + ImageData(int width, int height, PixelFormat format = PIXELFORMAT_RGBA8); + ImageData(int width, int height, PixelFormat format, void *data, bool own); + ImageData(const ImageData &c); virtual ~ImageData(); /** @@ -111,12 +108,12 @@ public: * @param f The file to save the encoded image data to. * @param format The format of the encoded data. **/ - virtual love::filesystem::FileData *encode(EncodedFormat format, const char *filename, bool writefile) = 0; + love::filesystem::FileData *encode(FormatHandler::EncodedFormat format, const char *filename, bool writefile) const; love::thread::Mutex *getMutex() const; // Implements ImageDataBase. - virtual ImageData *clone() const override = 0; + ImageData *clone() const override; void *getData() const override; size_t getSize() const override; bool isSRGB() const override; @@ -125,18 +122,8 @@ public: static bool validPixelFormat(PixelFormat format); - static bool getConstant(const char *in, EncodedFormat &out); - static bool getConstant(EncodedFormat in, const char *&out); - -protected: - - // The actual data. - unsigned char *data; - - // We need to be thread-safe - // so we lock when we're accessing our - // data - love::thread::MutexRef mutex; + static bool getConstant(const char *in, FormatHandler::EncodedFormat &out); + static bool getConstant(FormatHandler::EncodedFormat in, const char *&out); private: @@ -148,6 +135,21 @@ private: float *f32; }; + // Create imagedata. Initialize with data if not null. + void create(int width, int height, PixelFormat format, void *data = nullptr); + + // Decode and load an encoded format. + void decode(love::filesystem::FileData *data); + + // The actual data. + unsigned char *data = nullptr; + + love::thread::MutexRef mutex; + + // The format handler that was used to decode the ImageData. We need to know + // this so we can properly delete memory allocated by the decoder. + StrongRef decodeHandler; + static void pasteRGBA8toRGBA16(Row src, Row dst, int w); static void pasteRGBA8toRGBA16F(Row src, Row dst, int w); static void pasteRGBA8toRGBA32F(Row src, Row dst, int w); @@ -164,8 +166,8 @@ private: static void pasteRGBA32FtoRGBA16(Row src, Row dst, int w); static void pasteRGBA32FtoRGBA16F(Row src, Row dst, int w); - static StringMap::Entry encodedFormatEntries[]; - static StringMap encodedFormats; + static StringMap::Entry encodedFormatEntries[]; + static StringMap encodedFormats; }; // ImageData diff --git a/src/modules/image/magpie/ASTCHandler.cpp b/src/modules/image/magpie/ASTCHandler.cpp index 63fb7fe95..05363fe24 100644 --- a/src/modules/image/magpie/ASTCHandler.cpp +++ b/src/modules/image/magpie/ASTCHandler.cpp @@ -104,7 +104,7 @@ bool ASTCHandler::canParse(const filesystem::FileData *data) return true; } -StrongRef ASTCHandler::parse(filesystem::FileData *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) +StrongRef ASTCHandler::parse(filesystem::FileData *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) { if (!canParse(filedata)) throw love::Exception("Could not decode compressed data (not an .astc file?)"); @@ -129,12 +129,12 @@ StrongRef ASTCHandler::parse(filesystem::FileData * if (totalsize + sizeof(header) > filedata->getSize()) throw love::Exception("Could not parse .astc file: file is too small."); - StrongRef memory(new CompressedImageData::Memory(totalsize), Acquire::NORETAIN); + StrongRef memory(new CompressedMemory(totalsize), Acquire::NORETAIN); // .astc files only store a single mipmap level. memcpy(memory->data, (uint8 *) filedata->getData() + sizeof(ASTCHeader), totalsize); - images.emplace_back(new CompressedImageData::Slice(cformat, sizeX, sizeY, memory, 0, totalsize), Acquire::NORETAIN); + images.emplace_back(new CompressedSlice(cformat, sizeX, sizeY, memory, 0, totalsize), Acquire::NORETAIN); format = cformat; sRGB = false; diff --git a/src/modules/image/magpie/ASTCHandler.h b/src/modules/image/magpie/ASTCHandler.h index 341782a52..d83fc4ce0 100644 --- a/src/modules/image/magpie/ASTCHandler.h +++ b/src/modules/image/magpie/ASTCHandler.h @@ -18,11 +18,10 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_IMAGE_MAGPIE_ASTC_HANDLER_H -#define LOVE_IMAGE_MAGPIE_ASTC_HANDLER_H +#pragma once #include "common/config.h" -#include "CompressedFormatHandler.h" +#include "image/CompressedFormatHandler.h" namespace love { @@ -44,8 +43,8 @@ public: // Implements CompressedFormatHandler. bool canParse(const filesystem::FileData *data) override; - StrongRef parse(filesystem::FileData *filedata, - std::vector> &images, + StrongRef parse(filesystem::FileData *filedata, + std::vector> &images, PixelFormat &format, bool &sRGB) override; }; // ASTCHandler @@ -53,5 +52,3 @@ public: } // magpie } // image } // love - -#endif // LOVE_IMAGE_MAGPIE_ASTC_HANDLER_H diff --git a/src/modules/image/magpie/CompressedImageData.cpp b/src/modules/image/magpie/CompressedImageData.cpp deleted file mode 100644 index 4d3df3e46..000000000 --- a/src/modules/image/magpie/CompressedImageData.cpp +++ /dev/null @@ -1,85 +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. - **/ - -#include "CompressedImageData.h" - -namespace love -{ -namespace image -{ -namespace magpie -{ - -CompressedImageData::CompressedImageData(std::list formats, love::filesystem::FileData *filedata) -{ - CompressedFormatHandler *parser = nullptr; - - for (CompressedFormatHandler *handler : formats) - { - if (handler->canParse(filedata)) - { - parser = handler; - break; - } - } - - if (parser == nullptr) - throw love::Exception("Could not parse compressed data: Unknown format."); - - memory = parser->parse(filedata, dataImages, format, sRGB); - - if (memory == nullptr) - throw love::Exception("Could not parse compressed data."); - - if (format == PIXELFORMAT_UNKNOWN) - throw love::Exception("Could not parse compressed data: Unknown format."); - - if (dataImages.size() == 0 || memory->size == 0) - throw love::Exception("Could not parse compressed data: No valid data?"); -} - -CompressedImageData::CompressedImageData(const CompressedImageData &c) -{ - format = c.format; - sRGB = c.sRGB; - - memory.set(new Memory(c.memory->size), Acquire::NORETAIN); - memcpy(memory->data, c.memory->data, memory->size); - - for (const auto &i : c.dataImages) - { - Slice *slice = new Slice(i->getFormat(), i->getWidth(), i->getHeight(), memory, i->getOffset(), i->getSize()); - dataImages.push_back(slice); - slice->release(); - } -} - -CompressedImageData *CompressedImageData::clone() const -{ - return new CompressedImageData(*this); -} - -CompressedImageData::~CompressedImageData() -{ -} - -} // magpie -} // image -} // love diff --git a/src/modules/image/magpie/EXRHandler.cpp b/src/modules/image/magpie/EXRHandler.cpp index 77260a78a..177ad753f 100644 --- a/src/modules/image/magpie/EXRHandler.cpp +++ b/src/modules/image/magpie/EXRHandler.cpp @@ -20,6 +20,7 @@ // LOVE #include "EXRHandler.h" +#include "common/halffloat.h" // tinyexr #define TINYEXR_IMPLEMENTATION @@ -41,7 +42,7 @@ bool EXRHandler::canDecode(love::filesystem::FileData *data) return ParseEXRVersionFromMemory(&version, (const unsigned char *) data->getData(), data->getSize()) == TINYEXR_SUCCESS; } -bool EXRHandler::canEncode(PixelFormat /*rawFormat*/, ImageData::EncodedFormat /*encodedFormat*/) +bool EXRHandler::canEncode(PixelFormat /*rawFormat*/, EncodedFormat /*encodedFormat*/) { return false; } @@ -186,7 +187,7 @@ FormatHandler::DecodedImage EXRHandler::decode(love::filesystem::FileData *data) return img; } -FormatHandler::EncodedImage EXRHandler::encode(const DecodedImage & /*img*/, ImageData::EncodedFormat /*encodedFormat*/) +FormatHandler::EncodedImage EXRHandler::encode(const DecodedImage & /*img*/, EncodedFormat /*encodedFormat*/) { throw love::Exception("Invalid format."); } diff --git a/src/modules/image/magpie/EXRHandler.h b/src/modules/image/magpie/EXRHandler.h index 187166684..ff50f2ece 100644 --- a/src/modules/image/magpie/EXRHandler.h +++ b/src/modules/image/magpie/EXRHandler.h @@ -18,10 +18,9 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_IMAGE_MAGPIE_EXR_HANDLER_H -#define LOVE_IMAGE_MAGPIE_EXR_HANDLER_H +#pragma once -#include "FormatHandler.h" +#include "image/FormatHandler.h" namespace love { @@ -40,10 +39,10 @@ public: // Implements FormatHandler. virtual bool canDecode(love::filesystem::FileData *data); - virtual bool canEncode(PixelFormat rawFormat, ImageData::EncodedFormat encodedFormat); + virtual bool canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat); virtual DecodedImage decode(love::filesystem::FileData *data); - virtual EncodedImage encode(const DecodedImage &img, ImageData::EncodedFormat format); + virtual EncodedImage encode(const DecodedImage &img, EncodedFormat format); virtual void free(unsigned char *mem); @@ -52,5 +51,3 @@ public: } // magpie } // image } // love - -#endif // LOVE_IMAGE_MAGPIE_EXR_HANDLER_H diff --git a/src/modules/image/magpie/Image.cpp b/src/modules/image/magpie/Image.cpp deleted file mode 100644 index 98b34ebfe..000000000 --- a/src/modules/image/magpie/Image.cpp +++ /dev/null @@ -1,118 +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. - **/ - -#include "common/config.h" - -#include "Image.h" - -#include "ImageData.h" -#include "CompressedImageData.h" - -#include "PNGHandler.h" -#include "STBHandler.h" -#include "EXRHandler.h" - -#include "ddsHandler.h" -#include "PVRHandler.h" -#include "KTXHandler.h" -#include "PKMHandler.h" -#include "ASTCHandler.h" - -namespace love -{ -namespace image -{ -namespace magpie -{ - -Image::Image() -{ - halfInit(); // Makes sure half-float conversions can be used. - - formatHandlers = { - new PNGHandler, - new STBHandler, - new EXRHandler, - }; - - compressedFormatHandlers = { - new DDSHandler, - new PVRHandler, - new KTXHandler, - new PKMHandler, - new ASTCHandler, - }; -} - -Image::~Image() -{ - // ImageData objects reference the FormatHandlers in our list, so we should - // 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 -{ - return "love.image.magpie"; -} - -love::image::ImageData *Image::newImageData(love::filesystem::FileData *data) -{ - return new ImageData(data); -} - -love::image::ImageData *Image::newImageData(int width, int height, PixelFormat format) -{ - return new ImageData(width, height, format); -} - -love::image::ImageData *Image::newImageData(int width, int height, PixelFormat format, void *data, bool own) -{ - return new ImageData(width, height, format, data, own); -} - -love::image::CompressedImageData *Image::newCompressedData(love::filesystem::FileData *data) -{ - return new CompressedImageData(compressedFormatHandlers, data); -} - -bool Image::isCompressed(love::filesystem::FileData *data) -{ - for (CompressedFormatHandler *handler : compressedFormatHandlers) - { - if (handler->canParse(data)) - return true; - } - - return false; -} - -const std::list &Image::getFormatHandlers() const -{ - return formatHandlers; -} - -} // magpie -} // image -} // love diff --git a/src/modules/image/magpie/Image.h b/src/modules/image/magpie/Image.h deleted file mode 100644 index b34923c01..000000000 --- a/src/modules/image/magpie/Image.h +++ /dev/null @@ -1,78 +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. - **/ - -#ifndef LOVE_IMAGE_MAGPIE_IMAGE_H -#define LOVE_IMAGE_MAGPIE_IMAGE_H - -// LOVE -#include "image/Image.h" -#include "FormatHandler.h" -#include "CompressedFormatHandler.h" - -// C++ -#include - -namespace love -{ -namespace image -{ -namespace magpie -{ - -/** - * Similar to love.sound's Lullaby module, love.image.magpie interfaces with - * multiple image libraries and determines the correct one to use on a - * per-image basis at runtime. - **/ -class Image final : public love::image::Image -{ -public: - - Image(); - ~Image(); - - // Implements Module. - const char *getName() const override; - - love::image::ImageData *newImageData(love::filesystem::FileData *data) override; - love::image::ImageData *newImageData(int width, int height, PixelFormat format = PIXELFORMAT_RGBA8) override; - love::image::ImageData *newImageData(int width, int height, PixelFormat format, void *data, bool own = false) override; - - love::image::CompressedImageData *newCompressedData(love::filesystem::FileData *data) override; - - bool isCompressed(love::filesystem::FileData *data) override; - - const std::list &getFormatHandlers() const; - -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 - -} // magpie -} // image -} // love - -#endif // LOVE_IMAGE_MAGPIE_IMAGE_H diff --git a/src/modules/image/magpie/ImageData.cpp b/src/modules/image/magpie/ImageData.cpp deleted file mode 100644 index fc2de49b3..000000000 --- a/src/modules/image/magpie/ImageData.cpp +++ /dev/null @@ -1,239 +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. - **/ - -// LOVE -#include "ImageData.h" -#include "Image.h" - -#include "filesystem/Filesystem.h" - -namespace love -{ -namespace image -{ -namespace magpie -{ - -ImageData::ImageData(love::filesystem::FileData *data) -{ - decode(data); -} - -ImageData::ImageData(int width, int height, PixelFormat format) -{ - if (!validPixelFormat(format)) - throw love::Exception("Unsupported pixel format for ImageData"); - - this->width = width; - this->height = height; - this->format = format; - - create(width, height, format); - - // Set to black/transparency. - memset(data, 0, getSize()); -} - -ImageData::ImageData(int width, int height, PixelFormat format, void *data, bool own) -{ - if (!validPixelFormat(format)) - throw love::Exception("Unsupported pixel format for ImageData"); - - this->width = width; - this->height = height; - this->format = format; - - if (own) - this->data = (unsigned char *) data; - else - create(width, height, format, data); -} - -ImageData::ImageData(const ImageData &c) -{ - width = c.width; - height = c.height; - format = c.format; - - create(width, height, format, c.getData()); -} - -ImageData::~ImageData() -{ - if (decodeHandler.get()) - decodeHandler->free(data); - else - delete[] data; -} - -love::image::ImageData *ImageData::clone() const -{ - return new ImageData(*this); -} - -void ImageData::create(int width, int height, PixelFormat format, void *data) -{ - size_t datasize = width * height * getPixelFormatSize(format); - - try - { - this->data = new unsigned char[datasize]; - } - catch(std::bad_alloc &) - { - throw love::Exception("Out of memory"); - } - - if (data) - memcpy(this->data, data, datasize); - - decodeHandler = nullptr; - this->format = format; -} - -void ImageData::decode(love::filesystem::FileData *data) -{ - FormatHandler *decoder = nullptr; - FormatHandler::DecodedImage decodedimage; - - auto module = dynamic_cast(Module::getInstance(Module::M_IMAGE)); - - if (module == nullptr) - throw love::Exception("love.image must be loaded in order to decode an ImageData."); - - for (FormatHandler *handler : module->getFormatHandlers()) - { - if (handler->canDecode(data)) - { - decoder = handler; - break; - } - } - - if (decoder) - decodedimage = decoder->decode(data); - - if (decodedimage.data == nullptr) - { - const std::string &name = data->getFilename(); - throw love::Exception("Could not decode file '%s' to ImageData: unsupported file format", name.c_str()); - } - - if (decodedimage.size != decodedimage.width * decodedimage.height * getPixelFormatSize(decodedimage.format)) - { - decoder->free(decodedimage.data); - throw love::Exception("Could not convert image!"); - } - - // Clean up any old data. - if (decodeHandler) - decodeHandler->free(this->data); - else - delete[] this->data; - - this->width = decodedimage.width; - this->height = decodedimage.height; - this->data = decodedimage.data; - this->format = decodedimage.format; - - decodeHandler = decoder; -} - -love::filesystem::FileData *ImageData::encode(EncodedFormat encodedFormat, const char *filename, bool writefile) -{ - FormatHandler *encoder = nullptr; - FormatHandler::EncodedImage encodedimage; - FormatHandler::DecodedImage rawimage; - - rawimage.width = width; - rawimage.height = height; - rawimage.size = getSize(); - rawimage.data = data; - rawimage.format = format; - - auto module = dynamic_cast(Module::getInstance(Module::M_IMAGE)); - - if (module == nullptr) - throw love::Exception("love.image must be loaded in order to encode an ImageData."); - - for (FormatHandler *handler : module->getFormatHandlers()) - { - if (handler->canEncode(format, encodedFormat)) - { - encoder = handler; - break; - } - } - - if (encoder != nullptr) - { - thread::Lock lock(mutex); - encodedimage = encoder->encode(rawimage, encodedFormat); - } - - if (encoder == nullptr || encodedimage.data == nullptr) - { - const char *fname = "unknown"; - love::getConstant(format, fname); - throw love::Exception("No suitable image encoder for %s format.", fname); - } - - love::filesystem::FileData *filedata = nullptr; - - try - { - filedata = new love::filesystem::FileData(encodedimage.size, filename); - } - catch (love::Exception &) - { - encoder->free(encodedimage.data); - throw; - } - - memcpy(filedata->getData(), encodedimage.data, encodedimage.size); - encoder->free(encodedimage.data); - - if (writefile) - { - auto fs = Module::getInstance(Module::M_FILESYSTEM); - - if (fs == nullptr) - { - filedata->release(); - throw love::Exception("love.filesystem must be loaded in order to write an encoded ImageData to a file."); - } - - try - { - fs->write(filename, filedata->getData(), filedata->getSize()); - } - catch (love::Exception &) - { - filedata->release(); - throw; - } - } - - return filedata; -} - -} // magpie -} // image -} // love diff --git a/src/modules/image/magpie/ImageData.h b/src/modules/image/magpie/ImageData.h deleted file mode 100644 index 91ec6a362..000000000 --- a/src/modules/image/magpie/ImageData.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. - **/ - -#ifndef LOVE_IMAGE_MAGPIE_IMAGE_DATA_H -#define LOVE_IMAGE_MAGPIE_IMAGE_DATA_H - -// LOVE -#include "FormatHandler.h" -#include "image/ImageData.h" - -// C++ -#include - -namespace love -{ -namespace image -{ -namespace magpie -{ - -class ImageData : public love::image::ImageData -{ -public: - - ImageData(love::filesystem::FileData *data); - ImageData(int width, int height, PixelFormat format = PIXELFORMAT_RGBA8); - ImageData(int width, int height, PixelFormat format, void *data, bool own); - ImageData(const ImageData &c); - virtual ~ImageData(); - - // Implements image::ImageData. - virtual love::image::ImageData *clone() const; - virtual love::filesystem::FileData *encode(EncodedFormat encodedFormat, const char *filename, bool writefile); - -private: - - // Create imagedata. Initialize with data if not null. - void create(int width, int height, PixelFormat format, void *data = nullptr); - - // Decode and load an encoded format. - void decode(love::filesystem::FileData *data); - - // The format handler that was used to decode the ImageData. We need to know - // this so we can properly delete memory allocated by the decoder. - StrongRef decodeHandler; - -}; // ImageData - -} // magpie -} // image -} // love - -#endif // LOVE_IMAGE_MAGPIE_IMAGE_DATA_H diff --git a/src/modules/image/magpie/KTXHandler.cpp b/src/modules/image/magpie/KTXHandler.cpp index 3d5cd7f34..da88f157e 100644 --- a/src/modules/image/magpie/KTXHandler.cpp +++ b/src/modules/image/magpie/KTXHandler.cpp @@ -297,7 +297,7 @@ bool KTXHandler::canParse(const filesystem::FileData *data) return true; } -StrongRef KTXHandler::parse(filesystem::FileData *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) +StrongRef KTXHandler::parse(filesystem::FileData *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) { if (!canParse(filedata)) throw love::Exception("Could not decode compressed data (not a KTX file?)"); @@ -353,8 +353,8 @@ StrongRef KTXHandler::parse(filesystem::FileData *f fileoffset += mipsizepadded; } - StrongRef memory; - memory.set(new CompressedImageData::Memory(totalsize), Acquire::NORETAIN); + StrongRef memory; + memory.set(new CompressedMemory(totalsize), Acquire::NORETAIN); // Reset the file offset to the start of the file's image data. fileoffset = sizeof(KTXHeader) + header.bytesOfKeyValueData; @@ -377,7 +377,7 @@ StrongRef KTXHandler::parse(filesystem::FileData *f memcpy(memory->data + dataoffset, filebytes + fileoffset, mipsize); - auto slice = new CompressedImageData::Slice(cformat, width, height, memory, dataoffset, mipsize); + auto slice = new CompressedSlice(cformat, width, height, memory, dataoffset, mipsize); images.push_back(slice); slice->release(); diff --git a/src/modules/image/magpie/KTXHandler.h b/src/modules/image/magpie/KTXHandler.h index 965c7e3c0..71d8090e7 100644 --- a/src/modules/image/magpie/KTXHandler.h +++ b/src/modules/image/magpie/KTXHandler.h @@ -18,11 +18,10 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_IMAGE_MAGPIE_KTX_HANDLER_H -#define LOVE_IMAGE_MAGPIE_KTX_HANDLER_H +#pragma once #include "common/config.h" -#include "CompressedFormatHandler.h" +#include "image/CompressedFormatHandler.h" namespace love { @@ -43,8 +42,8 @@ public: // Implements CompressedFormatHandler. bool canParse(const filesystem::FileData *data) override; - StrongRef parse(filesystem::FileData *filedata, - std::vector> &images, + StrongRef parse(filesystem::FileData *filedata, + std::vector> &images, PixelFormat &format, bool &sRGB) override; }; // KTXHandler @@ -52,5 +51,3 @@ public: } // magpie } // image } // love - -#endif // LOVE_IMAGE_MAGPIE_KTX_HANDLER_H diff --git a/src/modules/image/magpie/PKMHandler.cpp b/src/modules/image/magpie/PKMHandler.cpp index 81c799780..f78c73333 100644 --- a/src/modules/image/magpie/PKMHandler.cpp +++ b/src/modules/image/magpie/PKMHandler.cpp @@ -113,7 +113,7 @@ bool PKMHandler::canParse(const filesystem::FileData *data) return true; } -StrongRef PKMHandler::parse(filesystem::FileData *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) +StrongRef PKMHandler::parse(filesystem::FileData *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) { if (!canParse(filedata)) throw love::Exception("Could not decode compressed data (not a PKM file?)"); @@ -134,8 +134,8 @@ StrongRef PKMHandler::parse(filesystem::FileData *f // The rest of the file after the header is all texture data. size_t totalsize = filedata->getSize() - sizeof(PKMHeader); - StrongRef memory; - memory.set(new CompressedImageData::Memory(totalsize), Acquire::NORETAIN); + StrongRef memory; + memory.set(new CompressedMemory(totalsize), Acquire::NORETAIN); // PKM files only store a single mipmap level. memcpy(memory->data, (uint8 *) filedata->getData() + sizeof(PKMHeader), totalsize); @@ -145,7 +145,7 @@ StrongRef PKMHandler::parse(filesystem::FileData *f int width = header.widthBig; int height = header.heightBig; - images.emplace_back(new CompressedImageData::Slice(cformat, width, height, memory, 0, totalsize), Acquire::NORETAIN); + images.emplace_back(new CompressedSlice(cformat, width, height, memory, 0, totalsize), Acquire::NORETAIN); format = cformat; sRGB = false; diff --git a/src/modules/image/magpie/PKMHandler.h b/src/modules/image/magpie/PKMHandler.h index deb13ef1a..1da404e35 100644 --- a/src/modules/image/magpie/PKMHandler.h +++ b/src/modules/image/magpie/PKMHandler.h @@ -18,11 +18,10 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_IMAGE_MAGPIE_PKM_HANDLER_H -#define LOVE_IMAGE_MAGPIE_PKM_HANDLER_H +#pragma once #include "common/config.h" -#include "CompressedFormatHandler.h" +#include "image/CompressedFormatHandler.h" namespace love { @@ -43,8 +42,8 @@ public: // Implements CompressedFormatHandler. bool canParse(const filesystem::FileData *data) override; - StrongRef parse(filesystem::FileData *filedata, - std::vector> &images, + StrongRef parse(filesystem::FileData *filedata, + std::vector> &images, PixelFormat &format, bool &sRGB) override; }; // PKMHandler @@ -52,5 +51,3 @@ public: } // magpie } // image } // love - -#endif // LOVE_IMAGE_MAGPIE_PKM_HANDLER_H diff --git a/src/modules/image/magpie/PNGHandler.cpp b/src/modules/image/magpie/PNGHandler.cpp index fe7b9968c..b0d3265bc 100644 --- a/src/modules/image/magpie/PNGHandler.cpp +++ b/src/modules/image/magpie/PNGHandler.cpp @@ -140,9 +140,9 @@ bool PNGHandler::canDecode(love::filesystem::FileData *data) return status == 0 && width > 0 && height > 0; } -bool PNGHandler::canEncode(PixelFormat rawFormat, ImageData::EncodedFormat encodedFormat) +bool PNGHandler::canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat) { - return encodedFormat == ImageData::ENCODED_PNG + return encodedFormat == ENCODED_PNG && (rawFormat == PIXELFORMAT_RGBA8 || rawFormat == PIXELFORMAT_RGBA16); } @@ -199,7 +199,7 @@ PNGHandler::DecodedImage PNGHandler::decode(love::filesystem::FileData *fdata) return img; } -PNGHandler::EncodedImage PNGHandler::encode(const DecodedImage &img, ImageData::EncodedFormat encodedFormat) +FormatHandler::EncodedImage PNGHandler::encode(const DecodedImage &img, EncodedFormat encodedFormat) { if (!canEncode(img.format, encodedFormat)) throw love::Exception("PNG encoder cannot encode to non-PNG format."); diff --git a/src/modules/image/magpie/PNGHandler.h b/src/modules/image/magpie/PNGHandler.h index c0cee564d..071cac8ba 100644 --- a/src/modules/image/magpie/PNGHandler.h +++ b/src/modules/image/magpie/PNGHandler.h @@ -18,11 +18,10 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_IMAGE_MAGPIE_PNG_HANDLER_H -#define LOVE_IMAGE_MAGPIE_PNG_HANDLER_H +#pragma once // LOVE -#include "FormatHandler.h" +#include "image/FormatHandler.h" namespace love { @@ -41,10 +40,10 @@ public: // Implements FormatHandler. virtual bool canDecode(love::filesystem::FileData *data); - virtual bool canEncode(PixelFormat rawFormat, ImageData::EncodedFormat encodedFormat); + virtual bool canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat); virtual DecodedImage decode(love::filesystem::FileData *data); - virtual EncodedImage encode(const DecodedImage &img, ImageData::EncodedFormat format); + virtual EncodedImage encode(const DecodedImage &img, EncodedFormat format); virtual void free(unsigned char *mem); @@ -53,5 +52,3 @@ public: } // magpie } // image } // love - -#endif // LOVE_IMAGE_MAGPIE_PNG_HANDLER_H diff --git a/src/modules/image/magpie/PVRHandler.cpp b/src/modules/image/magpie/PVRHandler.cpp index ca1d74359..3afec5748 100644 --- a/src/modules/image/magpie/PVRHandler.cpp +++ b/src/modules/image/magpie/PVRHandler.cpp @@ -474,7 +474,7 @@ bool PVRHandler::canParse(const filesystem::FileData *data) return false; } -StrongRef PVRHandler::parse(filesystem::FileData *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) +StrongRef PVRHandler::parse(filesystem::FileData *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) { if (!canParse(filedata)) throw love::Exception("Could not decode compressed data (not a PVR file?)"); @@ -524,8 +524,8 @@ StrongRef PVRHandler::parse(filesystem::FileData *f if (filedata->getSize() < fileoffset + totalsize) throw love::Exception("Could not parse PVR file: invalid size calculation."); - StrongRef memory; - memory.set(new CompressedImageData::Memory(totalsize), Acquire::NORETAIN); + StrongRef memory; + memory.set(new CompressedMemory(totalsize), Acquire::NORETAIN); size_t curoffset = 0; const uint8 *filebytes = (uint8 *) filedata->getData() + fileoffset; @@ -542,7 +542,7 @@ StrongRef PVRHandler::parse(filesystem::FileData *f memcpy(memory->data + curoffset, filebytes + curoffset, mipsize); - auto slice = new CompressedImageData::Slice(cformat, width, height, memory, curoffset, mipsize); + auto slice = new CompressedSlice(cformat, width, height, memory, curoffset, mipsize); images.push_back(slice); slice->release(); diff --git a/src/modules/image/magpie/PVRHandler.h b/src/modules/image/magpie/PVRHandler.h index 7cff3c24d..de06b7f73 100644 --- a/src/modules/image/magpie/PVRHandler.h +++ b/src/modules/image/magpie/PVRHandler.h @@ -18,12 +18,11 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_IMAGE_MAGPIE_PVR_HANDLER_H -#define LOVE_IMAGE_MAGPIE_PVR_HANDLER_H +#pragma once // LOVE #include "common/config.h" -#include "CompressedFormatHandler.h" +#include "image/CompressedFormatHandler.h" namespace love { @@ -41,8 +40,8 @@ public: // Implements CompressedFormatHandler. bool canParse(const filesystem::FileData *data) override; - StrongRef parse(filesystem::FileData *filedata, - std::vector> &images, + StrongRef parse(filesystem::FileData *filedata, + std::vector> &images, PixelFormat &format, bool &sRGB) override; }; // PVRHandler @@ -50,5 +49,3 @@ public: } // magpie } // image } // love - -#endif // LOVE_IMAGE_MAGPIE_PVR_HANDLER_H diff --git a/src/modules/image/magpie/STBHandler.cpp b/src/modules/image/magpie/STBHandler.cpp index f0eac3c43..279a83ad1 100644 --- a/src/modules/image/magpie/STBHandler.cpp +++ b/src/modules/image/magpie/STBHandler.cpp @@ -20,6 +20,7 @@ // LOVE #include "STBHandler.h" +#include "image/ImageData.h" static void loveSTBIAssert(bool test, const char *teststr) { @@ -60,9 +61,9 @@ bool STBHandler::canDecode(love::filesystem::FileData *data) return status == 1 && w > 0 && h > 0; } -bool STBHandler::canEncode(PixelFormat rawFormat, ImageData::EncodedFormat encodedFormat) +bool STBHandler::canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat) { - return encodedFormat == ImageData::ENCODED_TGA && rawFormat == PIXELFORMAT_RGBA8; + return encodedFormat == ENCODED_TGA && rawFormat == PIXELFORMAT_RGBA8; } FormatHandler::DecodedImage STBHandler::decode(love::filesystem::FileData *data) @@ -97,7 +98,7 @@ FormatHandler::DecodedImage STBHandler::decode(love::filesystem::FileData *data) return img; } -FormatHandler::EncodedImage STBHandler::encode(const DecodedImage &img, ImageData::EncodedFormat encodedFormat) +FormatHandler::EncodedImage STBHandler::encode(const DecodedImage &img, EncodedFormat encodedFormat) { if (!canEncode(img.format, encodedFormat)) throw love::Exception("Invalid format."); diff --git a/src/modules/image/magpie/STBHandler.h b/src/modules/image/magpie/STBHandler.h index 3605feba6..df2740623 100644 --- a/src/modules/image/magpie/STBHandler.h +++ b/src/modules/image/magpie/STBHandler.h @@ -18,10 +18,9 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_IMAGE_MAGPIE_STB_HANDLER_H -#define LOVE_IMAGE_MAGPIE_STB_HANDLER_H +#pragma once -#include "FormatHandler.h" +#include "image/FormatHandler.h" namespace love { @@ -37,24 +36,22 @@ namespace magpie * We could use stb_image to decode PNG as well, but performance and * comprehensive format support is lacking compared to some alternatives. **/ -class STBHandler : public FormatHandler +class STBHandler final : public FormatHandler { public: // Implements FormatHandler. - virtual bool canDecode(love::filesystem::FileData *data); - virtual bool canEncode(PixelFormat rawFormat, ImageData::EncodedFormat encodedFormat); + bool canDecode(love::filesystem::FileData *data) override; + bool canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat) override; - virtual DecodedImage decode(love::filesystem::FileData *data); - virtual EncodedImage encode(const DecodedImage &img, ImageData::EncodedFormat format); + DecodedImage decode(love::filesystem::FileData *data) override; + EncodedImage encode(const DecodedImage &img, EncodedFormat format) override; - virtual void free(unsigned char *mem); + void free(unsigned char *mem) override; }; // STBHandler } // magpie } // image } // love - -#endif // LOVE_IMAGE_MAGPIE_STB_HANDLER_H diff --git a/src/modules/image/magpie/ddsHandler.cpp b/src/modules/image/magpie/ddsHandler.cpp index 400239e13..caa3896e7 100644 --- a/src/modules/image/magpie/ddsHandler.cpp +++ b/src/modules/image/magpie/ddsHandler.cpp @@ -32,7 +32,7 @@ bool DDSHandler::canParse(const filesystem::FileData *data) return dds::isCompressedDDS(data->getData(), data->getSize()); } -StrongRef DDSHandler::parse(filesystem::FileData *filedata, std::vector> &images, PixelFormat &format, bool &sRGB) +StrongRef DDSHandler::parse(filesystem::FileData *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?)"); @@ -40,7 +40,7 @@ StrongRef DDSHandler::parse(filesystem::FileData *f PixelFormat texformat = PIXELFORMAT_UNKNOWN; bool isSRGB = false; - StrongRef memory; + StrongRef memory; size_t dataSize = 0; images.clear(); @@ -63,7 +63,7 @@ StrongRef DDSHandler::parse(filesystem::FileData *f dataSize += img->dataSize; } - memory.set(new CompressedImageData::Memory(dataSize), Acquire::NORETAIN); + memory.set(new CompressedMemory(dataSize), Acquire::NORETAIN); size_t dataOffset = 0; @@ -76,7 +76,7 @@ StrongRef DDSHandler::parse(filesystem::FileData *f // Copy the mipmap image from the FileData to our block of memory. memcpy(memory->data + dataOffset, img->data, img->dataSize); - auto slice = new CompressedImageData::Slice(texformat, img->width, img->height, memory, dataOffset, img->dataSize); + auto slice = new CompressedSlice(texformat, img->width, img->height, memory, dataOffset, img->dataSize); images.emplace_back(slice, Acquire::NORETAIN); dataOffset += img->dataSize; diff --git a/src/modules/image/magpie/ddsHandler.h b/src/modules/image/magpie/ddsHandler.h index fde057729..a875e055f 100644 --- a/src/modules/image/magpie/ddsHandler.h +++ b/src/modules/image/magpie/ddsHandler.h @@ -18,11 +18,10 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_IMAGE_MAGPIE_DDS_HANDLER_H -#define LOVE_IMAGE_MAGPIE_DDS_HANDLER_H +#pragma once // LOVE -#include "CompressedFormatHandler.h" +#include "image/CompressedFormatHandler.h" // dds parser #include "ddsparse/ddsparse.h" @@ -49,8 +48,8 @@ public: // Implements CompressedFormatHandler. bool canParse(const filesystem::FileData *data) override; - StrongRef parse(filesystem::FileData *filedata, - std::vector> &images, + StrongRef parse(filesystem::FileData *filedata, + std::vector> &images, PixelFormat &format, bool &sRGB) override; private: @@ -62,5 +61,3 @@ private: } // magpie } // image } // love - -#endif // LOVE_IMAGE_MAGPIE_DDS_HANDLER_H diff --git a/src/modules/image/wrap_Image.cpp b/src/modules/image/wrap_Image.cpp index 3456fe76f..d42dea40c 100644 --- a/src/modules/image/wrap_Image.cpp +++ b/src/modules/image/wrap_Image.cpp @@ -23,7 +23,7 @@ #include "common/Data.h" #include "common/StringMap.h" -#include "magpie/Image.h" +#include "Image.h" #include "filesystem/wrap_Filesystem.h" @@ -154,7 +154,7 @@ extern "C" int luaopen_love_image(lua_State *L) Image *instance = instance(); if (instance == nullptr) { - luax_catchexcept(L, [&](){ instance = new love::image::magpie::Image(); }); + luax_catchexcept(L, [&](){ instance = new love::image::Image(); }); } else instance->retain(); diff --git a/src/modules/image/wrap_ImageData.cpp b/src/modules/image/wrap_ImageData.cpp index dd33d5faf..83785eba6 100644 --- a/src/modules/image/wrap_ImageData.cpp +++ b/src/modules/image/wrap_ImageData.cpp @@ -262,7 +262,7 @@ int w_ImageData_encode(lua_State *L) { ImageData *t = luax_checkimagedata(L, 1); - ImageData::EncodedFormat format; + FormatHandler::EncodedFormat format; const char *fmt = luaL_checkstring(L, 2); if (!ImageData::getConstant(fmt, format)) return luaL_error(L, "Invalid encoded image format '%s'.", fmt);