LoadImageRaw, LoadImageAnim and LoadImageFromMemory. Version 0.6.

This commit is contained in:
jussi
2023-11-20 16:20:11 +02:00
parent 50d0e15ff4
commit 7765a23a2c
8 changed files with 129 additions and 3 deletions

View File

@@ -1774,6 +1774,9 @@ void luaRegister() {
/* Textures. */
/* Image loading functions. */
assingGlobalFunction( "LoadImage", ltexturesLoadImage );
assingGlobalFunction( "LoadImageRaw", ltexturesLoadImageRaw );
assingGlobalFunction( "LoadImageAnim", ltexturesLoadImageAnim );
assingGlobalFunction( "LoadImageFromMemory", ltexturesLoadImageFromMemory );
assingGlobalFunction( "LoadImageFromTexture", ltexturesLoadImageFromTexture );
assingGlobalFunction( "LoadImageFromScreen", ltexturesLoadImageFromScreen );
assingGlobalFunction( "IsImageReady", ltextureIsImageReady );

View File

@@ -13,6 +13,7 @@
Load image from file into CPU memory (RAM)
- Failure return nil
- Success return Image
*/
int ltexturesLoadImage( lua_State *L ) {
@@ -27,6 +28,71 @@ int ltexturesLoadImage( lua_State *L ) {
return 1;
}
/*
> image = RL.LoadImageRaw( string fileName, Vector2 size, int format, int headerSize )
Load image from RAW file data
- Failure return nil
- Success return Image
*/
int ltexturesLoadImageRaw( lua_State *L ) {
const char *fileName = luaL_checkstring( L, 1 );
Vector2 size = uluaGetVector2( L, 2 );
int format = luaL_checkinteger( L, 3 );
int headerSize = luaL_checkinteger( L, 4 );
if ( FileExists( fileName ) ) {
uluaPushImage( L, LoadImageRaw( fileName, (int)size.x, (int)size.y, format, headerSize ) );
return 1;
}
TraceLog( state->logLevelInvalid, "Invalid file '%s'", fileName );
lua_pushnil( L );
return 1;
}
/*
> image, frameCount = RL.LoadImageAnim( string fileName )
Load image sequence from file (frames appended to image.data). All frames are returned in RGBA format
- Failure return nil
- Success return Image, int
*/
int ltexturesLoadImageAnim( lua_State *L ) {
const char *fileName = luaL_checkstring( L, 1 );
if ( FileExists( fileName ) ) {
int frameCount = 0;
uluaPushImage( L, LoadImageAnim( fileName, &frameCount ) );
lua_pushinteger( L, frameCount );
return 2;
}
TraceLog( state->logLevelInvalid, "Invalid file '%s'", fileName );
lua_pushnil( L );
return 1;
}
/*
> image, frameCount = RL.LoadImageFromMemory( string fileType, Buffer data )
Load image from memory buffer, fileType refers to extension: i.e. '.png'
- Success return Image
*/
int ltexturesLoadImageFromMemory( lua_State *L ) {
const char *fileType = luaL_checkstring( L, 1 );
Buffer *data = uluaGetBuffer( L, 2 );
uluaPushImage( L, LoadImageFromMemory( fileType, data->data, data->size ) );
return 1;
}
/*
> image = RL.LoadImageFromTexture( Texture texture )