diff options
| author | jussi | 2024-02-17 00:49:57 +0200 |
|---|---|---|
| committer | jussi | 2024-02-17 00:49:57 +0200 |
| commit | 9de10be468c5151765a0e007d5889971c637fd24 (patch) | |
| tree | 2fb88336a8421a74883a4937d798dc58ba90c70b /src | |
| parent | b2b821929505aea2535d38382b743ad5dd5d1fa0 (diff) | |
| download | reilua-enhanced-9de10be468c5151765a0e007d5889971c637fd24.tar.gz reilua-enhanced-9de10be468c5151765a0e007d5889971c637fd24.tar.bz2 reilua-enhanced-9de10be468c5151765a0e007d5889971c637fd24.zip | |
LoadImageFromData.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lua_core.c | 1 | ||||
| -rw-r--r-- | src/textures.c | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/lua_core.c b/src/lua_core.c index 9577a0e..53059b4 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1491,6 +1491,7 @@ void luaRegister() { assingGlobalFunction( "LoadImageSvg", ltexturesLoadImageSvg ); assingGlobalFunction( "LoadImageAnim", ltexturesLoadImageAnim ); assingGlobalFunction( "LoadImageFromMemory", ltexturesLoadImageFromMemory ); + assingGlobalFunction( "LoadImageFromData", ltexturesLoadImageFromData ); assingGlobalFunction( "LoadImageFromTexture", ltexturesLoadImageFromTexture ); assingGlobalFunction( "LoadImageFromScreen", ltexturesLoadImageFromScreen ); assingGlobalFunction( "IsImageReady", ltextureIsImageReady ); diff --git a/src/textures.c b/src/textures.c index f88f9b3..48ba2cd 100644 --- a/src/textures.c +++ b/src/textures.c @@ -110,6 +110,34 @@ int ltexturesLoadImageFromMemory( lua_State *L ) { } /* +> image, frameCount = RL.LoadImageFromData( Buffer data, Vector2 size, int mipmaps, int format ) + +Load image from data + +- Success return Image +*/ +int ltexturesLoadImageFromData( lua_State *L ) { + Buffer *data = uluaGetBuffer( L, 1 ); + Vector2 size = uluaGetVector2( L, 2 ); + int mipmaps = luaL_checkinteger( L, 3 ); + int format = luaL_checkinteger( L, 4 ); + + Image image = { + .width = size.x, + .height = size.y, + .mipmaps = mipmaps, + .format = format + }; + size_t dataSize = GetPixelDataSize( size.x, size.y, format ); + image.data = malloc( dataSize * sizeof( unsigned char ) ); + memcpy( image.data, data->data, dataSize ); + + uluaPushImage( L, image ); + + return 1; +} + +/* > image = RL.LoadImageFromTexture( Texture texture ) Load image from GPU texture data |
