diff --git a/platform/macosx/love.xcodeproj/project.pbxproj b/platform/macosx/love.xcodeproj/project.pbxproj index 951be913f..722c43db1 100644 --- a/platform/macosx/love.xcodeproj/project.pbxproj +++ b/platform/macosx/love.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ A93E6E5410420B57007D418B /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E5210420B57007D418B /* SDL.framework */; }; A93E6E5510420B57007D418B /* Lua.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E5310420B57007D418B /* Lua.framework */; }; A93E6EED10420BA8007D418B /* love.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A3410420AC0007D418B /* love.cpp */; }; + A946CE821172BCD7005E1462 /* wrap_EncodedImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A946CE811172BCD7005E1462 /* wrap_EncodedImageData.cpp */; }; A946D67F104248DA002BF36C /* Reference.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E69EA10420ABF007D418B /* Reference.cpp */; }; A946D680104248DA002BF36C /* Matrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E69E310420ABF007D418B /* Matrix.cpp */; }; A946D681104248DA002BF36C /* Object.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E69E810420ABF007D418B /* Object.cpp */; }; @@ -573,6 +574,8 @@ A93E6E4810420B4A007D418B /* FreeType.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FreeType.framework; path = /Library/Frameworks/FreeType.framework; sourceTree = ""; }; A93E6E5210420B57007D418B /* SDL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL.framework; path = /Library/Frameworks/SDL.framework; sourceTree = ""; }; A93E6E5310420B57007D418B /* Lua.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Lua.framework; path = /Library/Frameworks/Lua.framework; sourceTree = ""; }; + A946CE801172BCD6005E1462 /* wrap_EncodedImageData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_EncodedImageData.h; sourceTree = ""; }; + A946CE811172BCD7005E1462 /* wrap_EncodedImageData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_EncodedImageData.cpp; sourceTree = ""; }; A968F0C61083A07B00A895AA /* EnumMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EnumMap.h; sourceTree = ""; }; A968F0C71083A07C00A895AA /* StringMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringMap.h; sourceTree = ""; }; A968F0CE1083A9A900A895AA /* Event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Event.cpp; sourceTree = ""; }; @@ -1019,6 +1022,8 @@ A93E6AAD10420AC3007D418B /* Image.h */, A93E6AAE10420AC3007D418B /* ImageData.cpp */, A93E6AAF10420AC3007D418B /* ImageData.h */, + A946CE811172BCD7005E1462 /* wrap_EncodedImageData.cpp */, + A946CE801172BCD6005E1462 /* wrap_EncodedImageData.h */, A93E6AB010420AC3007D418B /* wrap_Image.cpp */, A93E6AB110420AC3007D418B /* wrap_Image.h */, A93E6AB210420AC3007D418B /* wrap_ImageData.cpp */, @@ -1650,6 +1655,7 @@ A93A3AB51121E86E003B04A4 /* Image.cpp in Sources */, A986DEB5113249A800810279 /* Thread.cpp in Sources */, A986DEB6113249A800810279 /* wrap_Thread.cpp in Sources */, + A946CE821172BCD7005E1462 /* wrap_EncodedImageData.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/common/runtime.cpp b/src/common/runtime.cpp index c85b3ae06..d7115ecca 100644 --- a/src/common/runtime.cpp +++ b/src/common/runtime.cpp @@ -205,21 +205,21 @@ namespace love int luax_register_searcher(lua_State * L, lua_CFunction f) { - // Add the package loader to the package.loaders table. - lua_getglobal(L, "package"); - - if(lua_isnil(L, -1)) - return luaL_error(L, "Can't register searcher: package table does not exist."); - - lua_getfield(L, -1, "loaders"); - - if(lua_isnil(L, -1)) - return luaL_error(L, "Can't register searcher: package.loaders table does not exist."); - - int len = lua_objlen(L, -1); - lua_pushinteger(L, len+1); - lua_pushcfunction(L, f); - lua_settable(L, -3); + // Add the package loader to the package.loaders table. + lua_getglobal(L, "package"); + + if(lua_isnil(L, -1)) + return luaL_error(L, "Can't register searcher: package table does not exist."); + + lua_getfield(L, -1, "loaders"); + + if(lua_isnil(L, -1)) + return luaL_error(L, "Can't register searcher: package.loaders table does not exist."); + + int len = lua_objlen(L, -1); + lua_pushinteger(L, len+1); + lua_pushcfunction(L, f); + lua_settable(L, -3); lua_pop(L, 2); return 0; } @@ -362,6 +362,7 @@ namespace love // Image {"ImageData", IMAGE_IMAGE_DATA_ID}, + {"EncodedImageData", IMAGE_ENCODED_IMAGE_DATA_ID}, // Audio {"Source", AUDIO_SOURCE_ID}, diff --git a/src/common/types.h b/src/common/types.h index 6d6ed3590..249c92d03 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -54,6 +54,7 @@ namespace love // Image IMAGE_IMAGE_DATA_ID, + IMAGE_ENCODED_IMAGE_DATA_ID, // Audio AUDIO_SOURCE_ID, @@ -116,6 +117,7 @@ namespace love // Image. const bits IMAGE_IMAGE_DATA_T = (bits(1) << IMAGE_IMAGE_DATA_ID) | DATA_T; + const bits IMAGE_ENCODED_IMAGE_DATA_T = (bits(1) << IMAGE_ENCODED_IMAGE_DATA_ID) | DATA_T; // Audio. const bits AUDIO_SOURCE_T = (bits(1) << AUDIO_SOURCE_ID) | OBJECT_T; diff --git a/src/modules/image/EncodedImageData.h b/src/modules/image/EncodedImageData.h index 49b711fad..7a1d60edc 100644 --- a/src/modules/image/EncodedImageData.h +++ b/src/modules/image/EncodedImageData.h @@ -25,8 +25,6 @@ #include #include -#include "Image.h" - namespace love { namespace image diff --git a/src/modules/image/ImageData.h b/src/modules/image/ImageData.h index 3a24decd2..5cc5385d0 100644 --- a/src/modules/image/ImageData.h +++ b/src/modules/image/ImageData.h @@ -24,6 +24,8 @@ // LOVE #include +#include "EncodedImageData.h" + namespace love { namespace image @@ -94,6 +96,13 @@ namespace image * @return The color for the given location. **/ virtual pixel getPixel(int x, int y) const = 0; + + /** + * Encodes raw pixel data into a given format. + * @param f The format to convert to. + * @return A pointer to the encoded image data. + **/ + virtual EncodedImageData * encode(EncodedImageData::Format f) = 0; }; // ImageData diff --git a/src/modules/image/devil/ImageData.cpp b/src/modules/image/devil/ImageData.cpp index 6b66db54a..eedc97954 100644 --- a/src/modules/image/devil/ImageData.cpp +++ b/src/modules/image/devil/ImageData.cpp @@ -168,10 +168,10 @@ namespace devil return pixels[y*width+x]; } - love::image::EncodedImageData * ImageData::encodeImageData(love::image::ImageData * d, EncodedImageData::Format f) { + EncodedImageData * ImageData::encode(EncodedImageData::Format f) { ILubyte * data; - ILuint w = d->getWidth(); - int h = d->getHeight(); // has to be a signed int so we can make it negative for BMPs + ILuint w = getWidth(); + int h = getHeight(); // has to be a signed int so we can make it negative for BMPs int headerLen, bpp, row, size, padding, filesize; switch (f) { case EncodedImageData::FORMAT_BMP: @@ -227,7 +227,6 @@ namespace devil data[50] = data[51] = data[52] = data[53] = 0; // all colors are important! // Okay, header's done! Now for the pixel data... data += headerLen; - d->getData(); // bind the imagedata's image for (int i = 0; i < h; i++) { // we've got to loop through the rows, adding the pixel data plus padding ilCopyPixels(0,i,0,w,1,1,IL_BGR,IL_UNSIGNED_BYTE,data); data += row; @@ -258,7 +257,6 @@ namespace devil data[17] = 0; // descriptor bits // header done. write the pixel data to TGA: data += headerLen; - d->getData(); // bind the imagedata's image ilCopyPixels(0,0,0,w,h,1,IL_BGR,IL_UNSIGNED_BYTE,data); // convert the pixels to BGR (remember, little-endian) and copy them to data // It's Targa, so we have to flip the image. @@ -274,7 +272,7 @@ namespace devil data -= headerLen; delete [] temp; } - return new love::image::EncodedImageData(data, f, size + headerLen); + return new EncodedImageData(data, f, size + headerLen); } } // devil diff --git a/src/modules/image/devil/ImageData.h b/src/modules/image/devil/ImageData.h index 8bb18b91a..e2c9ccc80 100644 --- a/src/modules/image/devil/ImageData.h +++ b/src/modules/image/devil/ImageData.h @@ -77,14 +77,8 @@ namespace devil int getHeight() const ; void setPixel(int x, int y, pixel c); pixel getPixel(int x, int y) const; + EncodedImageData * encode(EncodedImageData::Format f); - /** - * Encodes raw pixel data into a given format. - * @param d The pixel data to be converted. - * @param f The format to convert to. - * @return A pointer to the encoded image data. - **/ - static love::image::EncodedImageData * encodeImageData(love::image::ImageData * d, EncodedImageData::Format f); }; // ImageData diff --git a/src/modules/image/wrap_EncodedImageData.cpp b/src/modules/image/wrap_EncodedImageData.cpp new file mode 100644 index 000000000..fd3b34c33 --- /dev/null +++ b/src/modules/image/wrap_EncodedImageData.cpp @@ -0,0 +1,59 @@ +/** +* Copyright (c) 2006-2010 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 "wrap_ImageData.h" + +#include + +namespace love +{ +namespace image +{ + EncodedImageData * luax_checkencodedimagedata(lua_State * L, int idx) + { + return luax_checktype(L, idx, "EncodedImageData", IMAGE_ENCODED_IMAGE_DATA_T); + } + + int w_EncodedImageData_getFormat(lua_State * L) { + EncodedImageData * e = luax_checkencodedimagedata(L, 1); + EncodedImageData::Format f = e->getFormat(); + const char * fmt; + EncodedImageData::getConstant(f, fmt); + lua_pushstring(L, fmt); + return 1; + } + + static const luaL_Reg functions[] = { + + // Data + { "getPointer", w_Data_getPointer }, + { "getSize", w_Data_getSize }, + + { "getFormat", w_EncodedImageData_getFormat }, + { 0, 0 } + }; + + int luaopen_encodedimagedata(lua_State * L) + { + return luax_register_type(L, "EncodedImageData", functions); + } + +} // image +} // love \ No newline at end of file diff --git a/src/modules/image/wrap_EncodedImageData.h b/src/modules/image/wrap_EncodedImageData.h new file mode 100644 index 000000000..4f7b1944f --- /dev/null +++ b/src/modules/image/wrap_EncodedImageData.h @@ -0,0 +1,40 @@ +/** +* Copyright (c) 2006-2010 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_WRAP_ENCODED_IMAGE_DATA_H +#define LOVE_IMAGE_WRAP_ENCODED_IMAGE_DATA_H + +// LOVE +#include +#include "ImageData.h" + +namespace love +{ +namespace image +{ + EncodedImageData * luax_checkencodedimagedata(lua_State * L, int idx); + + int w_EncodedImageData_getFormat(lua_State * L); + int luaopen_encodedimagedata(lua_State * L); + +} // image +} // love + +#endif // LOVE_IMAGE_WRAP_ENCODED_IMAGE_DATA_H diff --git a/src/modules/image/wrap_Image.cpp b/src/modules/image/wrap_Image.cpp index 46b82a526..492122a0d 100644 --- a/src/modules/image/wrap_Image.cpp +++ b/src/modules/image/wrap_Image.cpp @@ -20,6 +20,9 @@ #include "wrap_Image.h" +#include "EncodedImageData.h" +#include "wrap_EncodedImageData.h" + #include #include @@ -79,13 +82,14 @@ namespace image int w_newEncodedImageData(lua_State * L) { ImageData * t = luax_checkimagedata(L, 1); - EncodedImageData::Format format; - EncodedImageData::getConstant(luaL_checkstring(L, 2), format); - EncodedImageData * e = love::image::devil::ImageData::encodeImageData(t, format); - luax_newtype(L, "Data", DATA_T, (void*)e); // since we don't need any of EncodedImageData's features + const char * fmt = luaL_checkstring(L, 2); + EncodedImageData::Format f; + EncodedImageData::getConstant(fmt, f); + EncodedImageData * eid = t->encode(f); + luax_newtype(L, "EncodedImageData", IMAGE_ENCODED_IMAGE_DATA_T, (void*)eid); return 1; } - + // List of functions to wrap. static const luaL_Reg functions[] = { { "newImageData", w_newImageData }, @@ -95,6 +99,7 @@ namespace image static const lua_CFunction types[] = { luaopen_imagedata, + luaopen_encodedimagedata, 0 }; diff --git a/src/modules/image/wrap_Image.h b/src/modules/image/wrap_Image.h index f69e80007..72f66df9b 100644 --- a/src/modules/image/wrap_Image.h +++ b/src/modules/image/wrap_Image.h @@ -23,7 +23,6 @@ // LOVE #include "Image.h" -#include "EncodedImageData.h" #include "wrap_ImageData.h" namespace love diff --git a/src/modules/image/wrap_ImageData.cpp b/src/modules/image/wrap_ImageData.cpp index f0faa785d..98555d46c 100644 --- a/src/modules/image/wrap_ImageData.cpp +++ b/src/modules/image/wrap_ImageData.cpp @@ -126,6 +126,17 @@ namespace image t->paste((love::image::ImageData *)src, dx, dy, sx, sy, sw, sh); return 0; } + + int w_ImageData_encode(lua_State * L) + { + ImageData * t = luax_checkimagedata(L, 1); + const char * fmt = luaL_checkstring(L, 2); + EncodedImageData::Format f; + EncodedImageData::getConstant(fmt, f); + EncodedImageData * eid = t->encode(f); + luax_newtype(L, "EncodedImageData", IMAGE_ENCODED_IMAGE_DATA_T, (void*)eid); + return 1; + } static const luaL_Reg functions[] = { @@ -140,6 +151,7 @@ namespace image { "mapPixel", w_ImageData_mapPixel }, { "getString", w_ImageData_getString }, { "paste", w_ImageData_paste }, + { "encode", w_ImageData_encode }, { 0, 0 } }; diff --git a/src/modules/image/wrap_ImageData.h b/src/modules/image/wrap_ImageData.h index 936b7005e..81ae3687b 100644 --- a/src/modules/image/wrap_ImageData.h +++ b/src/modules/image/wrap_ImageData.h @@ -37,6 +37,7 @@ namespace image int w_ImageData_mapPixel(lua_State * L); int w_ImageData_getString(lua_State * L); int w_ImageData_paste(lua_State * L); + int w_ImageData_encode(lua_State * L); int luaopen_imagedata(lua_State * L); } // image