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

27
API.md
View File

@@ -5271,6 +5271,33 @@ Get collision rectangle for two rectangles collision
Load image from file into CPU memory (RAM)
- Failure return nil
- Success return Image
---
> image = RL.LoadImageRaw( string fileName, Vector2 size, int format, int headerSize )
Load image from RAW file data
- Failure return nil
- Success return Image
---
> 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
---
> image, frameCount = RL.LoadImageFromMemory( string fileType, Buffer data )
Load image from memory buffer, fileType refers to extension: i.e. '.png'
- Success return Image
---

View File

@@ -2678,11 +2678,38 @@ function RL.GetCollisionRec( rec1, rec2 ) end
-- Textures - Image loading functions
---Load image from file into CPU memory (RAM)
---- Failure return nil
---- Success return Image
---@param fileName string
---@return any image
function RL.LoadImage( fileName ) end
---Load image from RAW file data
---- Failure return nil
---- Success return Image
---@param fileName string
---@param size table
---@param format integer
---@param headerSize integer
---@return any image
function RL.LoadImageRaw( fileName, size, format, headerSize ) end
---Load image sequence from file (frames appended to image.data). All frames are returned in RGBA format
---- Failure return nil
---- Success return Image, int
---@param fileName string
---@return any image
---@return any frameCount
function RL.LoadImageAnim( fileName ) end
---Load image from memory buffer, fileType refers to extension: i.e. '.png'
---- Success return Image
---@param fileType string
---@param data any
---@return any image
---@return any frameCount
function RL.LoadImageFromMemory( fileType, data ) end
---Load image from GPU texture data
---- Success return Image
---@param texture any

View File

@@ -57,6 +57,7 @@ DETAILED CHANGES:
- CHANGED: Organized shapes, textures, audio, text, lights and gui functions.
- ADDED: More color and rectangle lib functionality.
- CHANGED: rlLoadTexture to take Buffer data.
- ADDED: LoadImageRaw, LoadImageAnim and LoadImageFromMemory.
------------------------------------------------------------------------
Release: ReiLua version 0.5.0 Using Raylib 4.5

View File

@@ -1,10 +1,9 @@
Current {
* Review image functions if sould use Buffer instead of color arrays.
}
Backlog {
* Text
* Text codepoints management functions (unicode characters)?
* Text codepoints management functions (unicode characters)? Could be usefull for luajit.
* Some of the Text strings management functions could be easier to use than the Lua ones.
* Audio
* AudioStream.

View File

@@ -5,7 +5,7 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 6
#define VERSION_PATCH 0
#define VERSION_DEV 1
#define VERSION_DEV 0
#include "glad.h"
#include <stdio.h>

View File

@@ -2,6 +2,9 @@
/* Image loading functions. */
int ltexturesLoadImage( lua_State *L );
int ltexturesLoadImageRaw( lua_State *L );
int ltexturesLoadImageAnim( lua_State *L );
int ltexturesLoadImageFromMemory( lua_State *L );
int ltexturesLoadImageFromTexture( lua_State *L );
int ltexturesLoadImageFromScreen( lua_State *L );
int ltextureIsImageReady( lua_State *L );

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 )