mirror of
https://github.com/love2d/love.git
synced 2026-08-14 01:20:56 +02:00
Added Image:getData, returns the original ImageData (or CompressedData) used to create the image
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 }
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user