LoadImageFromData.

This commit is contained in:
jussi
2024-02-17 00:49:57 +02:00
parent b2b8219295
commit 9de10be468
7 changed files with 51 additions and 2 deletions

8
API.md
View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -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
return bitlib

View File

@@ -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 );

View File

@@ -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 );

View File

@@ -109,6 +109,34 @@ int ltexturesLoadImageFromMemory( lua_State *L ) {
return 1;
}
/*
> 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 )