summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--API.md8
-rw-r--r--ReiLua_API.lua10
-rw-r--r--changelog1
-rw-r--r--examples/resources/lib/bitlib.lua4
-rw-r--r--include/textures.h1
-rw-r--r--src/lua_core.c1
-rw-r--r--src/textures.c28
7 files changed, 51 insertions, 2 deletions
diff --git a/API.md b/API.md
index 3b1d817..4934bc4 100644
--- a/API.md
+++ b/API.md
@@ -5547,6 +5547,14 @@ Load image from memory buffer, fileType refers to extension: i.e. '.png'
---
+> image, frameCount = RL.LoadImageFromData( Buffer data, Vector2 size, int mipmaps, int format )
+
+Load image from data
+
+- Success return Image
+
+---
+
> image = RL.LoadImageFromTexture( Texture texture )
Load image from GPU texture data
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 8da57ed..c5be720 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -2964,6 +2964,16 @@ function RL.LoadImageAnim( fileName ) end
---@return any frameCount
function RL.LoadImageFromMemory( fileType, data ) end
+---Load image from data
+---- Success return Image
+---@param data any
+---@param size table
+---@param mipmaps integer
+---@param format integer
+---@return any image
+---@return any frameCount
+function RL.LoadImageFromData( data, size, mipmaps, format ) end
+
---Load image from GPU texture data
---- Success return Image
---@param texture any
diff --git a/changelog b/changelog
index 5030d3b..83825df 100644
--- a/changelog
+++ b/changelog
@@ -3,6 +3,7 @@ Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0
------------------------------------------------------------------------
KEY CHANGES:
- CHANGE: GetBufferData takes also position and length arguments.
+ - ADDED: LoadImageFromData.
DETAILED CHANGES:
- ADDED: GetBufferElementSize and GetBufferLength.
diff --git a/examples/resources/lib/bitlib.lua b/examples/resources/lib/bitlib.lua
index e794d32..0cdea4e 100644
--- a/examples/resources/lib/bitlib.lua
+++ b/examples/resources/lib/bitlib.lua
@@ -3,7 +3,7 @@ local bitlib = {}
function bitlib.setBit( v, i, b )
if b then
return v | 1 << i
- else
+ else
return v & ~( 1 << i )
end
end
@@ -20,4 +20,4 @@ function bitlib.getBit( v, i )
return v & ( 1 << i ) > 0
end
-return bitlib \ No newline at end of file
+return bitlib
diff --git a/include/textures.h b/include/textures.h
index b1d9b8f..a3218a0 100644
--- a/include/textures.h
+++ b/include/textures.h
@@ -6,6 +6,7 @@ int ltexturesLoadImageRaw( lua_State *L );
int ltexturesLoadImageSvg( lua_State *L );
int ltexturesLoadImageAnim( lua_State *L );
int ltexturesLoadImageFromMemory( lua_State *L );
+int ltexturesLoadImageFromData( lua_State *L );
int ltexturesLoadImageFromTexture( lua_State *L );
int ltexturesLoadImageFromScreen( lua_State *L );
int ltextureIsImageReady( lua_State *L );
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