mirror of
https://github.com/love2d/love.git
synced 2026-08-21 21:15:09 +02:00
Removed the DevIL backend from love.image. Replaced it with PNG and JPEG encoders/decoders via LodePNG, zlib, and libjpeg-turbo.
PNG and JPEG are now the only two supported image formats, aside from compressed DDS (DXT, etc.) --HG-- branch : minor
This commit is contained in:
+17
-8
@@ -339,14 +339,16 @@ set(LOVE_SRC_MODULE_IMAGE_MAGPIE
|
||||
src/modules/image/magpie/CompressedData.h
|
||||
src/modules/image/magpie/ddsHandler.cpp
|
||||
src/modules/image/magpie/ddsHandler.h
|
||||
src/modules/image/magpie/DevilHandler.cpp
|
||||
src/modules/image/magpie/DevilHandler.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/JPEGHandler.cpp
|
||||
src/modules/image/magpie/JPEGHandler.h
|
||||
src/modules/image/magpie/PNGHandler.cpp
|
||||
src/modules/image/magpie/PNGHandler.h
|
||||
)
|
||||
|
||||
set(LOVE_SRC_MODULE_IMAGE
|
||||
@@ -928,6 +930,17 @@ add_library(love_3p_enet ${LOVE_SRC_3P_ENET})
|
||||
target_link_libraries(love_3p_enet ${MEGA_LUA})
|
||||
target_include_directories(love_3p_enet PUBLIC src/libraries/enet/libenet/include)
|
||||
|
||||
#
|
||||
# LodePNG
|
||||
#
|
||||
|
||||
set(LOVE_SRC_3P_LODEPNG
|
||||
src/libraries/lodepng/lodepng.cpp
|
||||
src/libraries/lodepng/lodepng.h
|
||||
)
|
||||
|
||||
add_library(love_3p_lodepng ${LOVE_SRC_3P_LODEPNG})
|
||||
|
||||
#
|
||||
# luasocket
|
||||
#
|
||||
@@ -1042,6 +1055,7 @@ set(LOVE_3P
|
||||
love_3p_box2d
|
||||
love_3p_ddsparse
|
||||
love_3p_enet
|
||||
love_3p_lodepng
|
||||
love_3p_luasocket
|
||||
love_3p_noise1234
|
||||
love_3p_wuff
|
||||
@@ -1086,12 +1100,9 @@ include_directories(
|
||||
link_directories(${SDL_LINK_DIR})
|
||||
|
||||
set(LOVE_MEGA_3P
|
||||
${MEGA_DEVIL}
|
||||
${MEGA_FREETYPE}
|
||||
${MEGA_JASPER}
|
||||
${MEGA_JPEG}
|
||||
${MEGA_JPEG_TURBO}
|
||||
${MEGA_LIBOGG}
|
||||
${MEGA_LIBPNG}
|
||||
${MEGA_LIBVORBISFILE}
|
||||
${MEGA_LIBVORBIS}
|
||||
${MEGA_LUA}
|
||||
@@ -1101,7 +1112,6 @@ set(LOVE_MEGA_3P
|
||||
${MEGA_PHYSFS}
|
||||
${MEGA_SDL2MAIN}
|
||||
${MEGA_SDL2}
|
||||
${MEGA_TIFF}
|
||||
${MEGA_ZLIB}
|
||||
)
|
||||
|
||||
@@ -1147,7 +1157,6 @@ target_link_libraries(love liblove)
|
||||
add_move_dll(love ${MEGA_MPEG123})
|
||||
add_move_dll(love ${MEGA_SDL2})
|
||||
add_move_dll(love ${MEGA_OPENAL})
|
||||
add_move_dll(love ${MEGA_DEVIL})
|
||||
|
||||
if(LOVE_JIT)
|
||||
add_move_file(love ${MEGA_LUAJIT_DLL})
|
||||
|
||||
@@ -133,7 +133,6 @@
|
||||
FA08F62D16C7541400F007B5 /* wrap_SpriteBatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02C16FDB537A702F4D42534E /* wrap_SpriteBatch.cpp */; };
|
||||
FA08F62E16C7542600F007B5 /* ImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 78115E763B723C0C40AD47CF /* ImageData.cpp */; };
|
||||
FA08F62F16C7542600F007B5 /* Image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 505F23A73BFE250833D650E4 /* Image.cpp */; };
|
||||
FA08F63016C7542600F007B5 /* DevilHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AA7781A230065F346E2313A /* DevilHandler.cpp */; };
|
||||
FA08F63116C7542600F007B5 /* wrap_Image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0B0728FA73B107B37A956A09 /* wrap_Image.cpp */; };
|
||||
FA08F63216C7542600F007B5 /* wrap_ImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 076840774B0B6E721D0C18D0 /* wrap_ImageData.cpp */; };
|
||||
FA08F63416C7542D00F007B5 /* JoystickModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 55B425307C0C1C4B3EFC3A5F /* JoystickModule.cpp */; };
|
||||
@@ -216,6 +215,7 @@
|
||||
FA0CDE3D1710F9A50056E8D7 /* FormatHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0CDE3B1710F9A50056E8D7 /* FormatHandler.h */; };
|
||||
FA1EF7C41799FEAC00FF380C /* wrap_System.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA34E7D4174B55AF00E04D3F /* wrap_System.cpp */; };
|
||||
FA1EF7C51799FEB200FF380C /* wrap_System.h in Headers */ = {isa = PBXBuildFile; fileRef = FA34E7D5174B55AF00E04D3F /* wrap_System.h */; };
|
||||
FA317EBA18F28B6D00B0BCD7 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = FA317EB918F28B6D00B0BCD7 /* libz.dylib */; };
|
||||
FA34E7CD174B513F00E04D3F /* System.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA34E7CB174B513F00E04D3F /* System.cpp */; };
|
||||
FA34E7CE174B513F00E04D3F /* System.h in Headers */ = {isa = PBXBuildFile; fileRef = FA34E7CC174B513F00E04D3F /* System.h */; };
|
||||
FA34E7D2174B515D00E04D3F /* System.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA34E7D0174B515D00E04D3F /* System.cpp */; };
|
||||
@@ -228,11 +228,17 @@
|
||||
FA3D9E1616E6D41100CA6630 /* wrap_Cursor.h in Headers */ = {isa = PBXBuildFile; fileRef = FA3D9E1416E6D41000CA6630 /* wrap_Cursor.h */; };
|
||||
FA435EA317B36E9C004C3F22 /* Polyline.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA435EA117B36E9C004C3F22 /* Polyline.cpp */; };
|
||||
FA435EA417B36E9C004C3F22 /* Polyline.h in Headers */ = {isa = PBXBuildFile; fileRef = FA435EA217B36E9C004C3F22 /* Polyline.h */; };
|
||||
FA48E43618F10D00007CF0BD /* JPEGHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA48E43418F10D00007CF0BD /* JPEGHandler.cpp */; };
|
||||
FA48E43718F10D00007CF0BD /* JPEGHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = FA48E43518F10D00007CF0BD /* JPEGHandler.h */; };
|
||||
FA48E43918F10D6C007CF0BD /* jpeg-turbo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA48E43818F10D6C007CF0BD /* jpeg-turbo.framework */; };
|
||||
FA4BBCDE18A5DC5D0027707D /* lodepng.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA4BBCDC18A5DC5D0027707D /* lodepng.cpp */; };
|
||||
FA4BBCDF18A5DC5D0027707D /* lodepng.h in Headers */ = {isa = PBXBuildFile; fileRef = FA4BBCDD18A5DC5D0027707D /* lodepng.h */; };
|
||||
FA4BBCE218A5DD7E0027707D /* PNGHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA4BBCE018A5DD7E0027707D /* PNGHandler.cpp */; };
|
||||
FA4BBCE318A5DD7E0027707D /* PNGHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = FA4BBCE118A5DD7E0027707D /* PNGHandler.h */; };
|
||||
FA5454C216F1310000D30303 /* MathModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA5454C016F1310000D30303 /* MathModule.cpp */; };
|
||||
FA5454C316F1310000D30303 /* MathModule.h in Headers */ = {isa = PBXBuildFile; fileRef = FA5454C116F1310000D30303 /* MathModule.h */; };
|
||||
FA577AB016C7507900860150 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA577A7916C71A1700860150 /* Cocoa.framework */; };
|
||||
FA577AC216C7512D00860150 /* FreeType.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA577A6716C719D900860150 /* FreeType.framework */; };
|
||||
FA577AC416C7513200860150 /* IL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA577A6916C719DE00860150 /* IL.framework */; };
|
||||
FA577AC516C7513400860150 /* libmodplug.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA577A8216C71A5300860150 /* libmodplug.framework */; };
|
||||
FA577AC716C7513A00860150 /* mpg123.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA577A6F16C719F000860150 /* mpg123.framework */; };
|
||||
FA577AC816C7513C00860150 /* Ogg.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA577A7116C719F400860150 /* Ogg.framework */; };
|
||||
@@ -432,7 +438,6 @@
|
||||
1A95437F513E662113AC154A /* b2Rope.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = b2Rope.h; sourceTree = "<group>"; };
|
||||
1A9810F758AC1D1E4B6431FD /* wrap_Graphics.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Graphics.cpp; sourceTree = "<group>"; };
|
||||
1AA213FC158815FA77C40330 /* ChainShape.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ChainShape.h; sourceTree = "<group>"; };
|
||||
1AA7781A230065F346E2313A /* DevilHandler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DevilHandler.cpp; sourceTree = "<group>"; };
|
||||
1B036C7C5A8832AE53BB1C06 /* b2CollideEdge.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = b2CollideEdge.cpp; sourceTree = "<group>"; };
|
||||
1B1C4E4D288A1D2F29E57B1B /* Rasterizer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Rasterizer.cpp; sourceTree = "<group>"; };
|
||||
1B4E22F1388E2B2E76E3377B /* wrap_GlyphData.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_GlyphData.cpp; sourceTree = "<group>"; };
|
||||
@@ -476,7 +481,6 @@
|
||||
27F777AB188D674F30BC1829 /* wrap_World.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wrap_World.h; sourceTree = "<group>"; };
|
||||
28016C9B51FE1A893DC35B66 /* Variant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Variant.h; sourceTree = "<group>"; };
|
||||
28024635525B077E08A73D9B /* Source.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Source.cpp; sourceTree = "<group>"; };
|
||||
283342E174613897621A43F1 /* DevilHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DevilHandler.h; sourceTree = "<group>"; };
|
||||
286660042F9654F61AB90D7A /* Body.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Body.h; sourceTree = "<group>"; };
|
||||
2912092853050AF9785F39BE /* wrap_RevoluteJoint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wrap_RevoluteJoint.h; sourceTree = "<group>"; };
|
||||
295C665B1E0B6B2D03CC4937 /* wrap_Event.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wrap_Event.h; sourceTree = "<group>"; };
|
||||
@@ -765,6 +769,7 @@
|
||||
FA0A4BF6182E260200E1E4D2 /* wrap_MotorJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_MotorJoint.cpp; sourceTree = "<group>"; };
|
||||
FA0A4BF7182E260200E1E4D2 /* wrap_MotorJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_MotorJoint.h; sourceTree = "<group>"; };
|
||||
FA0CDE3B1710F9A50056E8D7 /* FormatHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormatHandler.h; sourceTree = "<group>"; };
|
||||
FA317EB918F28B6D00B0BCD7 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
|
||||
FA34E7CB174B513F00E04D3F /* System.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = System.cpp; sourceTree = "<group>"; };
|
||||
FA34E7CC174B513F00E04D3F /* System.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = System.h; sourceTree = "<group>"; };
|
||||
FA34E7D0174B515D00E04D3F /* System.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = System.cpp; sourceTree = "<group>"; };
|
||||
@@ -779,10 +784,16 @@
|
||||
FA3D9E1416E6D41000CA6630 /* wrap_Cursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Cursor.h; sourceTree = "<group>"; };
|
||||
FA435EA117B36E9C004C3F22 /* Polyline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Polyline.cpp; sourceTree = "<group>"; };
|
||||
FA435EA217B36E9C004C3F22 /* Polyline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Polyline.h; sourceTree = "<group>"; };
|
||||
FA48E43418F10D00007CF0BD /* JPEGHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JPEGHandler.cpp; sourceTree = "<group>"; };
|
||||
FA48E43518F10D00007CF0BD /* JPEGHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JPEGHandler.h; sourceTree = "<group>"; };
|
||||
FA48E43818F10D6C007CF0BD /* jpeg-turbo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = "jpeg-turbo.framework"; path = "/Library/Frameworks/jpeg-turbo.framework"; sourceTree = "<absolute>"; };
|
||||
FA4BBCDC18A5DC5D0027707D /* lodepng.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lodepng.cpp; sourceTree = "<group>"; };
|
||||
FA4BBCDD18A5DC5D0027707D /* lodepng.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lodepng.h; sourceTree = "<group>"; };
|
||||
FA4BBCE018A5DD7E0027707D /* PNGHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PNGHandler.cpp; sourceTree = "<group>"; };
|
||||
FA4BBCE118A5DD7E0027707D /* PNGHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNGHandler.h; sourceTree = "<group>"; };
|
||||
FA5454C016F1310000D30303 /* MathModule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathModule.cpp; sourceTree = "<group>"; };
|
||||
FA5454C116F1310000D30303 /* MathModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathModule.h; sourceTree = "<group>"; };
|
||||
FA577A6716C719D900860150 /* FreeType.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FreeType.framework; path = /Library/Frameworks/FreeType.framework; sourceTree = "<absolute>"; };
|
||||
FA577A6916C719DE00860150 /* IL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IL.framework; path = /Library/Frameworks/IL.framework; sourceTree = "<absolute>"; };
|
||||
FA577A6D16C719EA00860150 /* Lua.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Lua.framework; path = /Library/Frameworks/Lua.framework; sourceTree = "<absolute>"; };
|
||||
FA577A6F16C719F000860150 /* mpg123.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = mpg123.framework; path = /Library/Frameworks/mpg123.framework; sourceTree = "<absolute>"; };
|
||||
FA577A7116C719F400860150 /* Ogg.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Ogg.framework; path = /Library/Frameworks/Ogg.framework; sourceTree = "<absolute>"; };
|
||||
@@ -897,12 +908,13 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
FA317EBA18F28B6D00B0BCD7 /* libz.dylib in Frameworks */,
|
||||
FA48E43918F10D6C007CF0BD /* jpeg-turbo.framework in Frameworks */,
|
||||
FAA627CE18E7E1560080752D /* CoreServices.framework in Frameworks */,
|
||||
FA9B4A0816E1578300074F42 /* SDL2.framework in Frameworks */,
|
||||
FAAFF04416CB11C700CCDE45 /* OpenAL-Soft.framework in Frameworks */,
|
||||
FA577AB016C7507900860150 /* Cocoa.framework in Frameworks */,
|
||||
FA577AC216C7512D00860150 /* FreeType.framework in Frameworks */,
|
||||
FA577AC416C7513200860150 /* IL.framework in Frameworks */,
|
||||
FA577AC516C7513400860150 /* libmodplug.framework in Frameworks */,
|
||||
FA577AC716C7513A00860150 /* mpg123.framework in Frameworks */,
|
||||
FA577AC816C7513C00860150 /* Ogg.framework in Frameworks */,
|
||||
@@ -1091,14 +1103,16 @@
|
||||
FAEC808D1711E76C0057279A /* CompressedData.h */,
|
||||
FAE010DE170DE25E006F29D0 /* ddsHandler.cpp */,
|
||||
FAE010DF170DE25E006F29D0 /* ddsHandler.h */,
|
||||
1AA7781A230065F346E2313A /* DevilHandler.cpp */,
|
||||
283342E174613897621A43F1 /* DevilHandler.h */,
|
||||
FADD58DC18C30367005FC3BF /* FormatHandler.cpp */,
|
||||
FA0CDE3B1710F9A50056E8D7 /* FormatHandler.h */,
|
||||
505F23A73BFE250833D650E4 /* Image.cpp */,
|
||||
68616BD516DB124312B47EB3 /* Image.h */,
|
||||
FAEC80881710FEA60057279A /* ImageData.cpp */,
|
||||
FAEC80891710FEA60057279A /* ImageData.h */,
|
||||
FA48E43418F10D00007CF0BD /* JPEGHandler.cpp */,
|
||||
FA48E43518F10D00007CF0BD /* JPEGHandler.h */,
|
||||
FA4BBCE018A5DD7E0027707D /* PNGHandler.cpp */,
|
||||
FA4BBCE118A5DD7E0027707D /* PNGHandler.h */,
|
||||
);
|
||||
path = magpie;
|
||||
sourceTree = "<group>";
|
||||
@@ -1391,6 +1405,7 @@
|
||||
63287ED84D0F2EEB65D249A3 /* Box2D */,
|
||||
FAE010D7170DDE99006F29D0 /* ddsparse */,
|
||||
FA5FDC5E1788D548002F0ED2 /* enet */,
|
||||
FA4BBCDB18A5DC5D0027707D /* lodepng */,
|
||||
3AED1DE005A53DDB07902760 /* luasocket */,
|
||||
FA0354691731F3A700284828 /* noise1234 */,
|
||||
36C14C81334735EC54E33637 /* utf8 */,
|
||||
@@ -1830,13 +1845,23 @@
|
||||
path = sdl;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
FA4BBCDB18A5DC5D0027707D /* lodepng */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
FA4BBCDC18A5DC5D0027707D /* lodepng.cpp */,
|
||||
FA4BBCDD18A5DC5D0027707D /* lodepng.h */,
|
||||
);
|
||||
path = lodepng;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
FA577A6616C7199700860150 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
FA317EB918F28B6D00B0BCD7 /* libz.dylib */,
|
||||
FA577A7916C71A1700860150 /* Cocoa.framework */,
|
||||
FAA627CD18E7E1560080752D /* CoreServices.framework */,
|
||||
FA577A6716C719D900860150 /* FreeType.framework */,
|
||||
FA577A6916C719DE00860150 /* IL.framework */,
|
||||
FA48E43818F10D6C007CF0BD /* jpeg-turbo.framework */,
|
||||
FA577A8216C71A5300860150 /* libmodplug.framework */,
|
||||
FA577A6D16C719EA00860150 /* Lua.framework */,
|
||||
FA577A6F16C719F000860150 /* mpg123.framework */,
|
||||
@@ -1967,7 +1992,9 @@
|
||||
FAF272A516E3D44400CC193A /* Channel.h in Headers */,
|
||||
FAF272A716E3D44400CC193A /* LuaThread.h in Headers */,
|
||||
FAF4377017F4AC530074F9E2 /* Mesh.h in Headers */,
|
||||
FA4BBCDF18A5DC5D0027707D /* lodepng.h in Headers */,
|
||||
FAF272A916E3D44400CC193A /* ThreadModule.h in Headers */,
|
||||
FA4BBCE318A5DD7E0027707D /* PNGHandler.h in Headers */,
|
||||
FAF6705018184FF800DBDEEA /* wuff_convert.h in Headers */,
|
||||
FAF272AB16E3D44400CC193A /* wrap_Channel.h in Headers */,
|
||||
FA0A4BF9182E260200E1E4D2 /* wrap_MotorJoint.h in Headers */,
|
||||
@@ -2014,6 +2041,7 @@
|
||||
FA0A4BF1182E0C2800E1E4D2 /* b2MotorJoint.h in Headers */,
|
||||
FA5FDC851788D548002F0ED2 /* utility.h in Headers */,
|
||||
FAF6704D18184FF800DBDEEA /* wuff.h in Headers */,
|
||||
FA48E43718F10D00007CF0BD /* JPEGHandler.h in Headers */,
|
||||
FA5FDC861788D548002F0ED2 /* win32.h in Headers */,
|
||||
FA5FDC8F1788D548002F0ED2 /* lua-enet.h in Headers */,
|
||||
FA7175AA178E8418001FE7FE /* lua.h in Headers */,
|
||||
@@ -2096,6 +2124,7 @@
|
||||
FA08F5B716C7530A00F007B5 /* Pool.cpp in Sources */,
|
||||
FA08F5B816C7530A00F007B5 /* Source.cpp in Sources */,
|
||||
FA08F5B916C7532A00F007B5 /* b64.cpp in Sources */,
|
||||
FA4BBCE218A5DD7E0027707D /* PNGHandler.cpp in Sources */,
|
||||
FA08F5BA16C7532A00F007B5 /* delay.cpp in Sources */,
|
||||
FA08F5BB16C7532A00F007B5 /* Exception.cpp in Sources */,
|
||||
FA08F5BD16C7532A00F007B5 /* Matrix.cpp in Sources */,
|
||||
@@ -2154,6 +2183,7 @@
|
||||
FA08F5EF16C7538F00F007B5 /* b2RevoluteJoint.cpp in Sources */,
|
||||
FA08F5F016C7538F00F007B5 /* b2RopeJoint.cpp in Sources */,
|
||||
FA08F5F116C7538F00F007B5 /* b2WeldJoint.cpp in Sources */,
|
||||
FA4BBCDE18A5DC5D0027707D /* lodepng.cpp in Sources */,
|
||||
FA08F5F216C7538F00F007B5 /* b2WheelJoint.cpp in Sources */,
|
||||
FA08F5F316C7539B00F007B5 /* b2Rope.cpp in Sources */,
|
||||
FA08F5F416C753A400F007B5 /* luasocket.cpp in Sources */,
|
||||
@@ -2214,7 +2244,6 @@
|
||||
FA08F62D16C7541400F007B5 /* wrap_SpriteBatch.cpp in Sources */,
|
||||
FA08F62E16C7542600F007B5 /* ImageData.cpp in Sources */,
|
||||
FA08F62F16C7542600F007B5 /* Image.cpp in Sources */,
|
||||
FA08F63016C7542600F007B5 /* DevilHandler.cpp in Sources */,
|
||||
FA08F63116C7542600F007B5 /* wrap_Image.cpp in Sources */,
|
||||
FA08F63216C7542600F007B5 /* wrap_ImageData.cpp in Sources */,
|
||||
FA08F63416C7542D00F007B5 /* JoystickModule.cpp in Sources */,
|
||||
@@ -2258,6 +2287,7 @@
|
||||
FA08F65816C7547300F007B5 /* wrap_Contact.cpp in Sources */,
|
||||
FA08F65916C7547300F007B5 /* wrap_DistanceJoint.cpp in Sources */,
|
||||
FA08F65A16C7547300F007B5 /* wrap_EdgeShape.cpp in Sources */,
|
||||
FA48E43618F10D00007CF0BD /* JPEGHandler.cpp in Sources */,
|
||||
FA08F65B16C7547300F007B5 /* wrap_Fixture.cpp in Sources */,
|
||||
FA08F65C16C7547300F007B5 /* wrap_FrictionJoint.cpp in Sources */,
|
||||
FA08F65D16C7548200F007B5 /* wrap_GearJoint.cpp in Sources */,
|
||||
@@ -2476,6 +2506,10 @@
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
DYLIB_COMPATIBILITY_VERSION = 9.0;
|
||||
DYLIB_CURRENT_VERSION = 9.0;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(LOCAL_LIBRARY_DIR)/Frameworks",
|
||||
);
|
||||
FRAMEWORK_VERSION = A;
|
||||
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
|
||||
INFOPLIST_FILE = "Info-Framework.plist";
|
||||
@@ -2498,6 +2532,10 @@
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 9.0;
|
||||
DYLIB_CURRENT_VERSION = 9.0;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(LOCAL_LIBRARY_DIR)/Frameworks",
|
||||
);
|
||||
FRAMEWORK_VERSION = A;
|
||||
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
@@ -2525,6 +2563,10 @@
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
DYLIB_COMPATIBILITY_VERSION = 9.0;
|
||||
DYLIB_CURRENT_VERSION = 9.0;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(LOCAL_LIBRARY_DIR)/Frameworks",
|
||||
);
|
||||
FRAMEWORK_VERSION = A;
|
||||
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
|
||||
INFOPLIST_FILE = "Info-Framework.plist";
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
A9255DD11043183600BA1496 /* FreeType.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E4810420B4A007D418B /* FreeType.framework */; };
|
||||
A9255DD31043183600BA1496 /* Lua.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E5310420B57007D418B /* Lua.framework */; };
|
||||
A9255E031043195A00BA1496 /* Vorbis.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9255E021043195A00BA1496 /* Vorbis.framework */; };
|
||||
A9255F431043240F00BA1496 /* IL.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9255F421043240F00BA1496 /* IL.framework */; };
|
||||
A9255F58104324E100BA1496 /* Ogg.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9255F51104324D700BA1496 /* Ogg.framework */; };
|
||||
A93E6E5510420B57007D418B /* Lua.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E5310420B57007D418B /* Lua.framework */; };
|
||||
A93E6EED10420BA8007D418B /* love.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A3410420AC0007D418B /* love.cpp */; };
|
||||
@@ -22,6 +21,7 @@
|
||||
A9F169AD109E825000FC83D1 /* libmodplug.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9F16926109E7BAD00FC83D1 /* libmodplug.framework */; };
|
||||
FA08F69616C766E000F007B5 /* love.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA08F69116C765A200F007B5 /* love.framework */; };
|
||||
FA08F69716C766E700F007B5 /* love.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = FA08F69116C765A200F007B5 /* love.framework */; };
|
||||
FA77A36518F1172600D23AE9 /* jpeg-turbo.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = FA77A36418F1172600D23AE9 /* jpeg-turbo.framework */; };
|
||||
FA9B4A0A16E1579F00074F42 /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA9B4A0916E1579F00074F42 /* SDL2.framework */; };
|
||||
FA9B4A0B16E157B500074F42 /* SDL2.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = FA9B4A0916E1579F00074F42 /* SDL2.framework */; };
|
||||
FAAFF04716CB120000CCDE45 /* OpenAL-Soft.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = FAAFF04616CB120000CCDE45 /* OpenAL-Soft.framework */; };
|
||||
@@ -45,6 +45,7 @@
|
||||
dstPath = "";
|
||||
dstSubfolderSpec = 10;
|
||||
files = (
|
||||
FA77A36518F1172600D23AE9 /* jpeg-turbo.framework in Copy Frameworks */,
|
||||
FA08F69716C766E700F007B5 /* love.framework in Copy Frameworks */,
|
||||
FA9B4A0B16E157B500074F42 /* SDL2.framework in Copy Frameworks */,
|
||||
FAAFF04716CB120000CCDE45 /* OpenAL-Soft.framework in Copy Frameworks */,
|
||||
@@ -52,7 +53,6 @@
|
||||
A9F169AD109E825000FC83D1 /* libmodplug.framework in Copy Frameworks */,
|
||||
A9D307F2106635D3004FEDF8 /* physfs.framework in Copy Frameworks */,
|
||||
A9255F58104324E100BA1496 /* Ogg.framework in Copy Frameworks */,
|
||||
A9255F431043240F00BA1496 /* IL.framework in Copy Frameworks */,
|
||||
A9255E031043195A00BA1496 /* Vorbis.framework in Copy Frameworks */,
|
||||
A9255DD11043183600BA1496 /* FreeType.framework in Copy Frameworks */,
|
||||
A9255DD31043183600BA1496 /* Lua.framework in Copy Frameworks */,
|
||||
@@ -66,7 +66,6 @@
|
||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
|
||||
8D1107320486CEB800E47090 /* love.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = love.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
A9255E021043195A00BA1496 /* Vorbis.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Vorbis.framework; path = /Library/Frameworks/Vorbis.framework; sourceTree = "<absolute>"; };
|
||||
A9255F421043240F00BA1496 /* IL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IL.framework; path = /Library/Frameworks/IL.framework; sourceTree = "<absolute>"; };
|
||||
A9255F51104324D700BA1496 /* Ogg.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Ogg.framework; path = /Library/Frameworks/Ogg.framework; sourceTree = "<absolute>"; };
|
||||
A93E6A3410420AC0007D418B /* love.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = love.cpp; path = ../../src/love.cpp; sourceTree = "<group>"; };
|
||||
A93E6E4710420B4A007D418B /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = "<absolute>"; };
|
||||
@@ -80,6 +79,7 @@
|
||||
A9F169A6109E824900FC83D1 /* mpg123.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = mpg123.framework; path = /Library/Frameworks/mpg123.framework; sourceTree = "<absolute>"; };
|
||||
FA08F69116C765A200F007B5 /* love.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = love.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
FA577A9316C7217800860150 /* love-framework.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = "love-framework.xcodeproj"; sourceTree = "<group>"; };
|
||||
FA77A36418F1172600D23AE9 /* jpeg-turbo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = "jpeg-turbo.framework"; path = "/Library/Frameworks/jpeg-turbo.framework"; sourceTree = "<absolute>"; };
|
||||
FA9B4A0916E1579F00074F42 /* SDL2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2.framework; path = /Library/Frameworks/SDL2.framework; sourceTree = "<absolute>"; };
|
||||
FAAFF04616CB120000CCDE45 /* OpenAL-Soft.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = "OpenAL-Soft.framework"; path = "/Library/Frameworks/OpenAL-Soft.framework"; sourceTree = "<absolute>"; };
|
||||
FAC8E8D316F3C468004DADF3 /* OSX.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OSX.mm; sourceTree = "<group>"; };
|
||||
@@ -107,7 +107,7 @@
|
||||
FA9B4A0916E1579F00074F42 /* SDL2.framework */,
|
||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
|
||||
A93E6E4810420B4A007D418B /* FreeType.framework */,
|
||||
A9255F421043240F00BA1496 /* IL.framework */,
|
||||
FA77A36418F1172600D23AE9 /* jpeg-turbo.framework */,
|
||||
A9F16926109E7BAD00FC83D1 /* libmodplug.framework */,
|
||||
FA08F69116C765A200F007B5 /* love.framework */,
|
||||
A93E6E5310420B57007D418B /* Lua.framework */,
|
||||
|
||||
@@ -56,14 +56,15 @@ PKG_CHECK_MODULES([lua], [${with_lua}${with_luaversion}], [lua_found=yes],
|
||||
[PKG_CHECK_MODULES([lua], [${with_lua}], [lua_found=yes], [lua_found=no])])
|
||||
PKG_CHECK_MODULES([freetype2], [freetype2], [], [LOVE_MSG_ERROR([FreeType2])])
|
||||
PKG_CHECK_MODULES([openal], [openal], [], [LOVE_MSG_ERROR([OpenAL])])
|
||||
PKG_CHECK_MODULES([devil], [IL], [], [LOVE_MSG_ERROR([DevIL])])
|
||||
PKG_CHECK_MODULES([libmodplug], [libmodplug], [], [LOVE_MSG_ERROR([libmodplug])])
|
||||
PKG_CHECK_MODULES([vorbisfile], [vorbisfile], [], [LOVE_MSG_ERROR([libvorbis and libvorbisfile])])
|
||||
PKG_CHECK_MODULES([zlib], [zlib], [], [LOVE_MSG_ERROR([zlib])])
|
||||
|
||||
# Other libraries
|
||||
AC_SEARCH_LIBS([sqrt], [m], [], [LOVE_MSG_ERROR([the C math library])])
|
||||
AC_SEARCH_LIBS([PHYSFS_init], [physfs], [], [LOVE_MSG_ERROR([PhysicsFS])])
|
||||
AC_SEARCH_LIBS([glLoadIdentity], [GL], [], [LOVE_MSG_ERROR([OpenGL])])
|
||||
AC_SEARCH_LIBS([tjInitCompress], [turbojpeg], [], [LOVE_MSG_ERROR([TurboJPEG])])
|
||||
|
||||
# Lua, treated seperately because of --with-lua
|
||||
AS_VAR_IF([with_luaversion], [5.2], [luatest=lua_version], [luatest=lua_pcall]) # use lua_version for 5.2
|
||||
|
||||
@@ -5,7 +5,6 @@ Maintainer: Bart van Strien <bart.bes@gmail.com>
|
||||
Build-Depends: debhelper (>= 9),
|
||||
autotools-dev,
|
||||
pkg-config,
|
||||
libdevil-dev,
|
||||
libfreetype6-dev,
|
||||
libluajit-5.1-dev,
|
||||
libphysfs-dev,
|
||||
@@ -13,11 +12,10 @@ Build-Depends: debhelper (>= 9),
|
||||
libopenal-dev,
|
||||
libogg-dev,
|
||||
libvorbis-dev,
|
||||
libflac-dev,
|
||||
libflac++-dev,
|
||||
libmodplug-dev,
|
||||
libmpg123-dev,
|
||||
libmng-dev
|
||||
zlib1g-dev,
|
||||
libjpeg-turbo8-dev
|
||||
Standards-Version: 3.9.3
|
||||
Homepage: http://love2d.org
|
||||
|
||||
@@ -27,8 +25,6 @@ Multi-Arch: same
|
||||
Pre-Depends: ${misc:Pre-Depends}
|
||||
Depends: ${misc:Depends},
|
||||
${shlibs:Depends},
|
||||
libdevil1c2,
|
||||
libmng1,
|
||||
libfreetype6,
|
||||
libgl1-mesa-glx,
|
||||
libluajit-5.1-2,
|
||||
@@ -39,7 +35,9 @@ Depends: ${misc:Depends},
|
||||
libvorbis0a,
|
||||
libvorbisfile3,
|
||||
libmodplug1,
|
||||
libmpg123-0
|
||||
libmpg123-0,
|
||||
zlib1g,
|
||||
libjpeg-turbo8
|
||||
Description: LOVE is a free 2D game engine which enables easy game creation in Lua.
|
||||
|
||||
Package: love@LOVE_SUFFIX@
|
||||
|
||||
@@ -111,7 +111,7 @@ inc_libraries="$inc_current/libraries"
|
||||
cat > src/Makefile.am << EOF
|
||||
AM_CPPFLAGS = -I$inc_current -I$inc_modules -I$inc_libraries -I$inc_libraries/enet/libenet/include \$(LOVE_INCLUDES) \$(FILE_OFFSET)\
|
||||
\$(SDL_CFLAGS) \$(lua_CFLAGS) \$(freetype2_CFLAGS)\
|
||||
\$(openal_CFLAGS) \$(devil_CFLAGS) \$(libmodplug_CFLAGS)\
|
||||
\$(openal_CFLAGS) \$(zlib_CFLAGS) \$(libmodplug_CFLAGS)\
|
||||
\$(vorbisfile_CFLAGS)
|
||||
AUTOMAKE_OPTIONS = subdir-objects
|
||||
SUBDIRS =
|
||||
@@ -144,7 +144,7 @@ lib_LTLIBRARIES = liblove${love_suffix}.la
|
||||
liblove${love_amsuffix}_la_LDFLAGS = -module -export-dynamic \$(LDFLAGS)
|
||||
liblove${love_amsuffix}_la_LIBADD = \
|
||||
\$(SDL_LIBS) \$(freetype2_LIBS) \$(lua_LIBS)\
|
||||
\$(openal_LIBS) \$(devil_LIBS) \$(libmodplug_LIBS)\
|
||||
\$(openal_LIBS) \$(zlib_LIBS) \$(libmodplug_LIBS)\
|
||||
\$(vorbisfile_LIBS)
|
||||
EOF
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,228 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 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 "DevilHandler.h"
|
||||
|
||||
// LOVE
|
||||
#include "common/Exception.h"
|
||||
#include "common/math.h"
|
||||
|
||||
// DevIL
|
||||
#include <IL/il.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace image
|
||||
{
|
||||
namespace magpie
|
||||
{
|
||||
|
||||
static inline void ilxClearErrors()
|
||||
{
|
||||
while (ilGetError() != IL_NO_ERROR);
|
||||
}
|
||||
|
||||
DevilHandler::DevilHandler()
|
||||
: mutex(nullptr)
|
||||
{
|
||||
// There should only ever be one DevilHandler object (owned by the Image
|
||||
// module), so we can use the global initialization function here.
|
||||
ilInit();
|
||||
ilEnable(IL_ORIGIN_SET);
|
||||
ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
|
||||
}
|
||||
|
||||
DevilHandler::~DevilHandler()
|
||||
{
|
||||
ilShutDown();
|
||||
|
||||
if (mutex)
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
bool DevilHandler::canDecode(love::filesystem::FileData * /*data*/)
|
||||
{
|
||||
// DevIL can decode a lot of formats...
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DevilHandler::canEncode(ImageData::Format format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case ImageData::FORMAT_BMP:
|
||||
case ImageData::FORMAT_TGA:
|
||||
case ImageData::FORMAT_JPG:
|
||||
case ImageData::FORMAT_PNG:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
DevilHandler::DecodedImage DevilHandler::decode(love::filesystem::FileData *data)
|
||||
{
|
||||
if (!mutex)
|
||||
mutex = love::thread::newMutex();
|
||||
|
||||
love::thread::Lock lock(mutex);
|
||||
|
||||
ILuint image = ilGenImage();
|
||||
ilBindImage(image);
|
||||
|
||||
DecodedImage img;
|
||||
|
||||
try
|
||||
{
|
||||
bool success = ilLoadL(IL_TYPE_UNKNOWN, (void *)data->getData(), (ILuint) data->getSize()) == IL_TRUE;
|
||||
|
||||
if (!success)
|
||||
throw love::Exception("Could not decode image!");
|
||||
|
||||
img.width = ilGetInteger(IL_IMAGE_WIDTH);
|
||||
img.height = ilGetInteger(IL_IMAGE_HEIGHT);
|
||||
|
||||
// Make sure the image is in RGBA format.
|
||||
ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
|
||||
|
||||
// This should always be four.
|
||||
int bpp = ilGetInteger(IL_IMAGE_BPP);
|
||||
if (bpp != sizeof(pixel))
|
||||
throw love::Exception("Could not convert image!");
|
||||
|
||||
img.size = (size_t) ilGetInteger(IL_IMAGE_SIZE_OF_DATA);
|
||||
|
||||
try
|
||||
{
|
||||
img.data = new ILubyte[img.size];
|
||||
}
|
||||
catch (std::bad_alloc &)
|
||||
{
|
||||
throw love::Exception("Out of memory.");
|
||||
}
|
||||
|
||||
memcpy(img.data, ilGetData(), img.size);
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
// catches love and std exceptions
|
||||
ilDeleteImage(image);
|
||||
throw love::Exception("%s", e.what());
|
||||
}
|
||||
|
||||
ilDeleteImage(image);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
DevilHandler::EncodedImage DevilHandler::encode(const DecodedImage &img, ImageData::Format format)
|
||||
{
|
||||
if (!mutex)
|
||||
mutex = love::thread::newMutex();
|
||||
|
||||
love::thread::Lock lock(mutex);
|
||||
|
||||
ILuint tempimage = ilGenImage();
|
||||
ilBindImage(tempimage);
|
||||
ilxClearErrors();
|
||||
|
||||
EncodedImage encodedimage;
|
||||
|
||||
try
|
||||
{
|
||||
bool success = ilTexImage(img.width, img.height, 1, sizeof(pixel), IL_RGBA, IL_UNSIGNED_BYTE, img.data) == IL_TRUE;
|
||||
|
||||
ILenum err = ilGetError();
|
||||
ilxClearErrors();
|
||||
|
||||
if (!success)
|
||||
{
|
||||
if (err != IL_NO_ERROR)
|
||||
{
|
||||
switch (err)
|
||||
{
|
||||
case IL_ILLEGAL_OPERATION:
|
||||
throw love::Exception("Illegal operation");
|
||||
case IL_INVALID_PARAM:
|
||||
throw love::Exception("Invalid parameters");
|
||||
case IL_OUT_OF_MEMORY:
|
||||
throw love::Exception("Out of memory");
|
||||
default:
|
||||
throw love::Exception("Unknown error (%d)", (int) err);
|
||||
}
|
||||
}
|
||||
|
||||
throw love::Exception("Could not create image for the encoding!");
|
||||
}
|
||||
|
||||
ilRegisterOrigin(IL_ORIGIN_UPPER_LEFT);
|
||||
|
||||
ILuint ilFormat;
|
||||
switch (format)
|
||||
{
|
||||
case ImageData::FORMAT_BMP:
|
||||
ilFormat = IL_BMP;
|
||||
break;
|
||||
case ImageData::FORMAT_TGA:
|
||||
ilFormat = IL_TGA;
|
||||
break;
|
||||
case ImageData::FORMAT_JPG:
|
||||
ilFormat = IL_JPG;
|
||||
break;
|
||||
case ImageData::FORMAT_PNG:
|
||||
default: // PNG is the default format
|
||||
ilFormat = IL_PNG;
|
||||
break;
|
||||
}
|
||||
|
||||
encodedimage.size = ilSaveL(ilFormat, NULL, 0);
|
||||
if (!encodedimage.size)
|
||||
throw love::Exception("Could not encode image!");
|
||||
|
||||
try
|
||||
{
|
||||
encodedimage.data = new ILubyte[encodedimage.size];
|
||||
}
|
||||
catch(std::bad_alloc &)
|
||||
{
|
||||
throw love::Exception("Out of memory");
|
||||
}
|
||||
|
||||
ilSaveL(ilFormat, encodedimage.data, encodedimage.size);
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
// Catches love and std exceptions.
|
||||
ilDeleteImage(tempimage);
|
||||
delete[] encodedimage.data;
|
||||
encodedimage.data = 0;
|
||||
throw love::Exception("%s", e.what());
|
||||
}
|
||||
|
||||
ilDeleteImage(tempimage);
|
||||
|
||||
return encodedimage;
|
||||
}
|
||||
|
||||
} // magpie
|
||||
} // image
|
||||
} // love
|
||||
@@ -57,6 +57,11 @@ FormatHandler::EncodedImage FormatHandler::encode(const DecodedImage& /*img*/, I
|
||||
throw love::Exception("Image encoding is not implemented for this format backend.");
|
||||
}
|
||||
|
||||
void FormatHandler::free(unsigned char *mem)
|
||||
{
|
||||
delete[] mem;
|
||||
}
|
||||
|
||||
} // magpie
|
||||
} // image
|
||||
} // love
|
||||
|
||||
@@ -93,6 +93,11 @@ public:
|
||||
**/
|
||||
virtual EncodedImage encode(const DecodedImage &img, ImageData::Format format);
|
||||
|
||||
/**
|
||||
* Frees memory allocated by the format handler.
|
||||
**/
|
||||
virtual void free(unsigned char *mem);
|
||||
|
||||
}; // FormatHandler
|
||||
|
||||
} // magpie
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
#include "ImageData.h"
|
||||
#include "CompressedData.h"
|
||||
|
||||
#include "DevilHandler.h"
|
||||
#include "JPEGHandler.h"
|
||||
#include "PNGHandler.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -34,7 +35,8 @@ namespace magpie
|
||||
|
||||
Image::Image()
|
||||
{
|
||||
formatHandlers.push_back(new DevilHandler);
|
||||
formatHandlers.push_back(new PNGHandler);
|
||||
formatHandlers.push_back(new JPEGHandler);
|
||||
}
|
||||
|
||||
Image::~Image()
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace magpie
|
||||
|
||||
ImageData::ImageData(std::list<FormatHandler *> formats, love::filesystem::FileData *data)
|
||||
: formatHandlers(formats)
|
||||
, decodeHandler(nullptr)
|
||||
{
|
||||
for (auto it = formatHandlers.begin(); it != formatHandlers.end(); ++it)
|
||||
(*it)->retain();
|
||||
@@ -39,6 +40,7 @@ ImageData::ImageData(std::list<FormatHandler *> formats, love::filesystem::FileD
|
||||
|
||||
ImageData::ImageData(std::list<FormatHandler *> formats, int width, int height)
|
||||
: formatHandlers(formats)
|
||||
, decodeHandler(nullptr)
|
||||
{
|
||||
for (auto it = formatHandlers.begin(); it != formatHandlers.end(); ++it)
|
||||
(*it)->retain();
|
||||
@@ -54,6 +56,7 @@ ImageData::ImageData(std::list<FormatHandler *> formats, int width, int height)
|
||||
|
||||
ImageData::ImageData(std::list<FormatHandler *> formats, int width, int height, void *data, bool own)
|
||||
: formatHandlers(formats)
|
||||
, decodeHandler(nullptr)
|
||||
{
|
||||
for (auto it = formatHandlers.begin(); it != formatHandlers.end(); ++it)
|
||||
(*it)->retain();
|
||||
@@ -69,6 +72,9 @@ ImageData::ImageData(std::list<FormatHandler *> formats, int width, int height,
|
||||
|
||||
ImageData::~ImageData()
|
||||
{
|
||||
if (decodeHandler)
|
||||
decodeHandler->free(data);
|
||||
else
|
||||
delete[] data;
|
||||
|
||||
for (auto it = formatHandlers.begin(); it != formatHandlers.end(); ++it)
|
||||
@@ -88,23 +94,32 @@ void ImageData::create(int width, int height, void *data)
|
||||
|
||||
if (data)
|
||||
memcpy(this->data, data, width*height*sizeof(pixel));
|
||||
|
||||
decodeHandler = nullptr;
|
||||
}
|
||||
|
||||
void ImageData::decode(love::filesystem::FileData *data)
|
||||
{
|
||||
FormatHandler *handler = nullptr;
|
||||
FormatHandler::DecodedImage decodedimage;
|
||||
|
||||
for (auto it = formatHandlers.begin(); it != formatHandlers.end(); ++it)
|
||||
{
|
||||
if ((*it)->canDecode(data))
|
||||
{
|
||||
decodedimage = (*it)->decode(data);
|
||||
handler = *it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (handler)
|
||||
decodedimage = handler->decode(data);
|
||||
|
||||
if (decodedimage.data == nullptr)
|
||||
throw love::Exception("Could not decode image: unrecognized format.");
|
||||
{
|
||||
const char *ext = data->getExtension().c_str();
|
||||
throw love::Exception("Could not decode to ImageData: unrecognized format (%s)", ext);
|
||||
}
|
||||
|
||||
// The decoder *must* output a 32 bits-per-pixel image.
|
||||
if (decodedimage.size != decodedimage.width*decodedimage.height*sizeof(pixel))
|
||||
@@ -113,16 +128,22 @@ void ImageData::decode(love::filesystem::FileData *data)
|
||||
throw love::Exception("Could not convert image!");
|
||||
}
|
||||
|
||||
if (this->data)
|
||||
// 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;
|
||||
|
||||
decodeHandler = handler;
|
||||
}
|
||||
|
||||
void ImageData::encode(love::filesystem::File *f, ImageData::Format format)
|
||||
{
|
||||
FormatHandler *handler = nullptr;
|
||||
FormatHandler::EncodedImage encodedimage;
|
||||
|
||||
{
|
||||
@@ -139,11 +160,14 @@ void ImageData::encode(love::filesystem::File *f, ImageData::Format format)
|
||||
{
|
||||
if ((*it)->canEncode(format))
|
||||
{
|
||||
encodedimage = (*it)->encode(rawimage, format);
|
||||
handler = *it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (handler)
|
||||
handler->encode(rawimage, format);
|
||||
|
||||
if (encodedimage.data == nullptr)
|
||||
throw love::Exception("Image format has no suitable encoder.");
|
||||
}
|
||||
@@ -156,10 +180,17 @@ void ImageData::encode(love::filesystem::File *f, ImageData::Format format)
|
||||
}
|
||||
catch (love::Exception &)
|
||||
{
|
||||
if (handler)
|
||||
handler->free(encodedimage.data);
|
||||
else
|
||||
delete[] encodedimage.data;
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
if (handler)
|
||||
handler->free(encodedimage.data);
|
||||
else
|
||||
delete[] encodedimage.data;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,10 @@ private:
|
||||
// Image format handlers we can use for decoding and encoding.
|
||||
std::list<FormatHandler *> formatHandlers;
|
||||
|
||||
// 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.
|
||||
FormatHandler *decodeHandler;
|
||||
|
||||
}; // ImageData
|
||||
|
||||
} // magpie
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 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 "JPEGHandler.h"
|
||||
#include "common/Exception.h"
|
||||
#include "common/math.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace image
|
||||
{
|
||||
namespace magpie
|
||||
{
|
||||
|
||||
JPEGHandler::JPEGHandler()
|
||||
{
|
||||
mutex = love::thread::newMutex();
|
||||
|
||||
decompressor = tjInitDecompress();
|
||||
compressor = tjInitCompress();
|
||||
}
|
||||
|
||||
JPEGHandler::~JPEGHandler()
|
||||
{
|
||||
delete mutex;
|
||||
|
||||
if (decompressor)
|
||||
tjDestroy(decompressor);
|
||||
|
||||
if (compressor)
|
||||
tjDestroy(compressor);
|
||||
}
|
||||
|
||||
bool JPEGHandler::canDecode(love::filesystem::FileData *data)
|
||||
{
|
||||
if (!decompressor)
|
||||
return false;
|
||||
|
||||
int w, h, subsamp;
|
||||
int status = tjDecompressHeader2(decompressor,
|
||||
(unsigned char *) data->getData(),
|
||||
data->getSize(),
|
||||
&w, &h, &subsamp);
|
||||
|
||||
return (status == 0);
|
||||
}
|
||||
|
||||
bool JPEGHandler::canEncode(ImageData::Format format)
|
||||
{
|
||||
if (!compressor)
|
||||
return false;
|
||||
|
||||
return format == ImageData::FORMAT_JPG;
|
||||
}
|
||||
|
||||
FormatHandler::DecodedImage JPEGHandler::decode(love::filesystem::FileData *data)
|
||||
{
|
||||
if (!decompressor)
|
||||
throw love::Exception("Could not decode jpeg image: %s", tjGetErrorStr());
|
||||
|
||||
DecodedImage img;
|
||||
unsigned char *jpegdata = (unsigned char *) data->getData();
|
||||
|
||||
love::thread::Lock lock(mutex);
|
||||
|
||||
int unused;
|
||||
int status = tjDecompressHeader2(decompressor,
|
||||
jpegdata, data->getSize(),
|
||||
&img.width, &img.height,
|
||||
&unused);
|
||||
|
||||
if (status < 0)
|
||||
throw love::Exception("Could not decode jpeg image: %s", tjGetErrorStr());
|
||||
|
||||
img.size = img.width * img.height * sizeof(pixel);
|
||||
|
||||
try
|
||||
{
|
||||
img.data = new unsigned char[img.size];
|
||||
}
|
||||
catch (std::bad_alloc &)
|
||||
{
|
||||
throw love::Exception("Out of memory.");
|
||||
}
|
||||
|
||||
status = tjDecompress2(decompressor,
|
||||
jpegdata, data->getSize(),
|
||||
img.data, 0, 0, 0, TJPF_RGBA, 0);
|
||||
|
||||
if (status < 0)
|
||||
{
|
||||
delete[] img.data;
|
||||
throw love::Exception("Could not decode jpeg image: %s", tjGetErrorStr());
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
FormatHandler::EncodedImage JPEGHandler::encode(const DecodedImage &img, ImageData::Format format)
|
||||
{
|
||||
if (!canEncode(format))
|
||||
throw love::Exception("JPEG encoder cannot encode specified format.");
|
||||
|
||||
EncodedImage encodedimage;
|
||||
|
||||
love::thread::Lock lock(mutex);
|
||||
|
||||
unsigned long tjsize = tjBufSize(img.width, img.height, TJSAMP_444);
|
||||
|
||||
try
|
||||
{
|
||||
// We want to allocate the memory ourselves instead of letting
|
||||
// TurboJPEG do it, so we can safely use delete[] in ImageData.cpp.
|
||||
encodedimage.data = new unsigned char[tjsize];
|
||||
}
|
||||
catch (std::bad_alloc &)
|
||||
{
|
||||
throw love::Exception("Out of memory.");
|
||||
}
|
||||
|
||||
int status = tjCompress2(compressor,
|
||||
img.data,
|
||||
img.width, 0, img.height,
|
||||
TJPF_RGBA,
|
||||
&encodedimage.data, &encodedimage.size,
|
||||
TJSAMP_444, COMPRESS_QUALITY, TJFLAG_NOREALLOC);
|
||||
|
||||
if (status < 0)
|
||||
{
|
||||
delete[] encodedimage.data;
|
||||
throw love::Exception("Could not encode jpeg image: %s", tjGetErrorStr());
|
||||
}
|
||||
|
||||
return encodedimage;
|
||||
}
|
||||
|
||||
} // magpie
|
||||
} // image
|
||||
} // love
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 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_JPEG_HANDLER_H
|
||||
#define LOVE_IMAGE_MAGPIE_JPEG_HANDLER_H
|
||||
|
||||
// LOVE
|
||||
#include "filesystem/FileData.h"
|
||||
#include "FormatHandler.h"
|
||||
#include "thread/threads.h"
|
||||
|
||||
// libjpeg-turbo
|
||||
#ifdef LOVE_MACOSX_USE_FRAMEWORKS
|
||||
#include <jpeg-turbo/turbojpeg.h>
|
||||
#else
|
||||
#include <turbojpeg.h>
|
||||
#endif
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace image
|
||||
{
|
||||
namespace magpie
|
||||
{
|
||||
|
||||
/**
|
||||
* Interface between ImageData and TurboJPEG.
|
||||
**/
|
||||
class JPEGHandler : public FormatHandler
|
||||
{
|
||||
public:
|
||||
|
||||
// Implements FormatHandler.
|
||||
|
||||
JPEGHandler();
|
||||
virtual ~JPEGHandler();
|
||||
|
||||
virtual bool canDecode(love::filesystem::FileData *data);
|
||||
virtual bool canEncode(ImageData::Format format);
|
||||
|
||||
virtual DecodedImage decode(love::filesystem::FileData *data);
|
||||
virtual EncodedImage encode(const DecodedImage &img, ImageData::Format format);
|
||||
|
||||
private:
|
||||
|
||||
Mutex *mutex;
|
||||
|
||||
tjhandle decompressor;
|
||||
tjhandle compressor;
|
||||
|
||||
static const int COMPRESS_QUALITY = 90;
|
||||
|
||||
}; // JPEGHandler
|
||||
|
||||
} // magpie
|
||||
} // image
|
||||
} // love
|
||||
|
||||
#endif // LOVE_IMAGE_MAGPIE_JPEG_HANDLER_H
|
||||
@@ -0,0 +1,218 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 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 "PNGHandler.h"
|
||||
|
||||
// LOVE
|
||||
#include "common/Exception.h"
|
||||
#include "common/math.h"
|
||||
|
||||
// LodePNG
|
||||
#include "lodepng/lodepng.h"
|
||||
|
||||
// zlib
|
||||
#include <zlib.h>
|
||||
|
||||
// C++
|
||||
#include <algorithm>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace image
|
||||
{
|
||||
namespace magpie
|
||||
{
|
||||
|
||||
// Custom PNG decompression function for LodePNG, using zlib.
|
||||
static unsigned zlibDecompress(unsigned char **out, size_t *outsize, const unsigned char *in,
|
||||
size_t insize, const LodePNGDecompressSettings* /*settings*/)
|
||||
{
|
||||
int status = Z_OK;
|
||||
|
||||
size_t outdataSize = insize;
|
||||
size_t sizeMultiplier = 0;
|
||||
unsigned char *outdata = nullptr;
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Enough size to hold the decompressed data, hopefully.
|
||||
outdataSize = insize << (++sizeMultiplier);
|
||||
|
||||
try
|
||||
{
|
||||
outdata = new unsigned char[outdataSize];
|
||||
}
|
||||
catch (std::bad_alloc &)
|
||||
{
|
||||
return 83; // "Memory allocation failed" error code for LodePNG.
|
||||
}
|
||||
|
||||
// Use zlib to decompress the PNG data.
|
||||
status = uncompress(outdata, &outdataSize, in, insize);
|
||||
|
||||
// If the out buffer was big enough, break out of the loop.
|
||||
if (status != Z_BUF_ERROR)
|
||||
break;
|
||||
|
||||
// Otherwise delete the out buffer and try again with a larger size...
|
||||
delete[] outdata;
|
||||
outdata = nullptr;
|
||||
}
|
||||
|
||||
if (status != Z_OK)
|
||||
{
|
||||
delete[] outdata;
|
||||
return 10000; // "Unknown error code" for LodePNG.
|
||||
}
|
||||
|
||||
if (out != nullptr)
|
||||
*out = outdata;
|
||||
|
||||
if (outsize != nullptr)
|
||||
*outsize = outdataSize;
|
||||
|
||||
return 0; // Success.
|
||||
}
|
||||
|
||||
// Custom PNG compression function for LodePNG, using zlib.
|
||||
static unsigned zlibCompress(unsigned char **out, size_t *outsize, const unsigned char *in,
|
||||
size_t insize, const LodePNGCompressSettings* /*settings*/)
|
||||
{
|
||||
// Get the maximum compressed size of the data.
|
||||
uLongf outdataSize = compressBound(insize);
|
||||
unsigned char *outdata = nullptr;
|
||||
|
||||
try
|
||||
{
|
||||
outdata = new unsigned char[outdataSize];
|
||||
}
|
||||
catch (std::bad_alloc &)
|
||||
{
|
||||
return 83; // "Memory allocation failed" error code for LodePNG.
|
||||
}
|
||||
|
||||
// Use zlib to compress the PNG data.
|
||||
int status = compress(outdata, &outdataSize, in, insize);
|
||||
|
||||
if (status != Z_OK)
|
||||
{
|
||||
delete[] outdata;
|
||||
return 10000; // "Unknown error code" for LodePNG.
|
||||
}
|
||||
|
||||
if (out != nullptr)
|
||||
*out = outdata;
|
||||
|
||||
if (outsize != nullptr)
|
||||
*outsize = (size_t) outdataSize;
|
||||
|
||||
return 0; // Success.
|
||||
}
|
||||
|
||||
bool PNGHandler::canDecode(love::filesystem::FileData *data)
|
||||
{
|
||||
std::string ext = data->getExtension();
|
||||
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
|
||||
|
||||
return ext.compare("png") == 0;
|
||||
}
|
||||
|
||||
bool PNGHandler::canEncode(ImageData::Format format)
|
||||
{
|
||||
return format == ImageData::FORMAT_PNG;
|
||||
}
|
||||
|
||||
PNGHandler::DecodedImage PNGHandler::decode(love::filesystem::FileData *fdata)
|
||||
{
|
||||
unsigned int width = 0, height = 0;
|
||||
unsigned char *indata = (unsigned char *) fdata->getData();
|
||||
size_t insize = fdata->getSize();
|
||||
|
||||
DecodedImage img;
|
||||
|
||||
LodePNGState state;
|
||||
lodepng_state_init(&state);
|
||||
|
||||
state.info_raw.colortype = LCT_RGBA;
|
||||
state.info_raw.bitdepth = 8;
|
||||
|
||||
state.decoder.zlibsettings.custom_zlib = zlibDecompress;
|
||||
|
||||
unsigned status = lodepng_decode(&img.data, &width, &height,
|
||||
&state, indata, insize);
|
||||
|
||||
lodepng_state_cleanup(&state);
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
const char *err = lodepng_error_text(status);
|
||||
throw love::Exception("Could not decode PNG image (%s)", err);
|
||||
}
|
||||
|
||||
img.width = (int) width;
|
||||
img.height = (int) height;
|
||||
img.size = width * height * 4;
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
PNGHandler::EncodedImage PNGHandler::encode(const DecodedImage &img, ImageData::Format format)
|
||||
{
|
||||
if (format != ImageData::FORMAT_PNG)
|
||||
throw love::Exception("PNG encoder cannot encode to non-PNG format.");
|
||||
|
||||
EncodedImage encimg;
|
||||
|
||||
LodePNGState state;
|
||||
lodepng_state_init(&state);
|
||||
|
||||
state.info_raw.colortype = LCT_RGBA;
|
||||
state.info_raw.bitdepth = 8;
|
||||
|
||||
// TODO: support plain RGB (24-bit) encoding in the future?
|
||||
state.info_png.color.colortype = LCT_RGBA;
|
||||
state.info_png.color.bitdepth = 8;
|
||||
|
||||
state.encoder.zlibsettings.custom_zlib = zlibCompress;
|
||||
|
||||
unsigned status = lodepng_encode(&encimg.data, &encimg.size,
|
||||
img.data, img.width, img.height, &state);
|
||||
|
||||
lodepng_state_cleanup(&state);
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
const char *err = lodepng_error_text(status);
|
||||
throw love::Exception("Could not encode PNG image (%s)", err);
|
||||
}
|
||||
|
||||
return encimg;
|
||||
}
|
||||
|
||||
void PNGHandler::free(unsigned char *mem)
|
||||
{
|
||||
// LodePNG uses malloc, realloc, and free.
|
||||
if (mem)
|
||||
::free(mem);
|
||||
}
|
||||
|
||||
} // magpie
|
||||
} // image
|
||||
} // love
|
||||
@@ -18,13 +18,12 @@
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_IMAGE_MAGPIE_DEVIL_HANDLER_H
|
||||
#define LOVE_IMAGE_MAGPIE_DEVIL_HANDLER_H
|
||||
#ifndef LOVE_IMAGE_MAGPIE_PNG_HANDLER_H
|
||||
#define LOVE_IMAGE_MAGPIE_PNG_HANDLER_H
|
||||
|
||||
// LOVE
|
||||
#include "filesystem/FileData.h"
|
||||
#include "FormatHandler.h"
|
||||
#include "thread/threads.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -34,31 +33,26 @@ namespace magpie
|
||||
{
|
||||
|
||||
/**
|
||||
* Interface between ImageData and DevIL.
|
||||
* Interface between ImageData and LodePNG.
|
||||
**/
|
||||
class DevilHandler : public FormatHandler
|
||||
class PNGHandler : public FormatHandler
|
||||
{
|
||||
public:
|
||||
|
||||
// Implements FormatHandler.
|
||||
|
||||
DevilHandler();
|
||||
virtual ~DevilHandler();
|
||||
|
||||
virtual bool canDecode(love::filesystem::FileData *data);
|
||||
virtual bool canEncode(ImageData::Format format);
|
||||
|
||||
virtual DecodedImage decode(love::filesystem::FileData *data);
|
||||
virtual EncodedImage encode(const DecodedImage &img, ImageData::Format format);
|
||||
|
||||
private:
|
||||
virtual void free(unsigned char *mem);
|
||||
|
||||
Mutex *mutex;
|
||||
|
||||
}; // DevilHandler
|
||||
}; // PNGHandler
|
||||
|
||||
} // magpie
|
||||
} // image
|
||||
} // love
|
||||
|
||||
#endif // LOVE_IMAGE_MAGPIE_DEVIL_HANDLER_H
|
||||
#endif // LOVE_IMAGE_MAGPIE_PNG_HANDLER_H
|
||||
Reference in New Issue
Block a user