Browse Source

Added Image:getData, returns the original ImageData (or CompressedData) used to create the image

Alex Szpakowski 12 years ago
parent
commit
cd97e9ec05

+ 6 - 1
src/modules/graphics/opengl/Image.cpp

@@ -88,11 +88,16 @@ const vertex *Image::getVertices() const
 	return vertices;
 }
 
-love::image::ImageData *Image::getData() const
+love::image::ImageData *Image::getImageData() const
 {
 	return data;
 }
 
+love::image::CompressedData *Image::getCompressedData() const
+{
+	return cdata;
+}
+
 void Image::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
 {
 	static Matrix t;

+ 2 - 1
src/modules/graphics/opengl/Image.h

@@ -74,7 +74,8 @@ public:
 
 	const vertex *getVertices() const;
 
-	love::image::ImageData *getData() const;
+	love::image::ImageData *getImageData() const;
+	love::image::CompressedData *getCompressedData() const;
 
 	/**
 	 * @copydoc Drawable::draw()

+ 1 - 1
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -354,7 +354,7 @@ int w_newImageFont(lua_State *L)
 	{
 		Image *i = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
 		filter = i->getFilter();
-		love::image::ImageData *id = i->getData();
+		love::image::ImageData *id = i->getImageData();
 		if (!id)
 			return luaL_argerror(L, 1, "Image cannot be compressed.");
 		luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)id, false);

+ 31 - 0
src/modules/graphics/opengl/wrap_Image.cpp

@@ -196,6 +196,36 @@ int w_Image_refresh(lua_State *L)
 	return 0;
 }
 
+int w_Image_getData(lua_State *L)
+{
+	Image *i = luax_checkimage(L, 1);
+
+	if (i->isCompressed())
+	{
+		love::image::CompressedData *t = i->getCompressedData();
+		if (t)
+		{
+			t->retain();
+			luax_newtype(L, "CompressedData", IMAGE_COMPRESSED_DATA_T, (void *) t);
+		}
+		else
+			lua_pushnil(L);
+	}
+	else
+	{
+		love::image::ImageData *t = i->getImageData();
+		if (t)
+		{
+			t->retain();
+			luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *) t);
+		}
+		else
+			lua_pushnil(L);
+	}
+
+	return 1;
+}
+
 static const luaL_Reg functions[] =
 {
 	{ "getWidth", w_Image_getWidth },
@@ -209,6 +239,7 @@ static const luaL_Reg functions[] =
 	{ "getMipmapFilter", w_Image_getMipmapFilter },
 	{ "isCompressed", w_Image_isCompressed },
 	{ "refresh", w_Image_refresh },
+	{ "getData", w_Image_getData },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/graphics/opengl/wrap_Image.h

@@ -44,6 +44,7 @@ int w_Image_setWrap(lua_State *L);
 int w_Image_getWrap(lua_State *L);
 int w_Image_isCompressed(lua_State *L);
 int w_Image_refresh(lua_State *L);
+int w_Image_getData(lua_State *L);
 extern "C" int luaopen_image(lua_State *L);
 
 } // opengl