summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2023-11-20 16:20:11 +0200
committerjussi2023-11-20 16:20:11 +0200
commit7765a23a2c90e6d02f6278eed1b1b9b9375bc941 (patch)
treefaa7dee80e49a327bf04fbb086822b25cf019f88
parent50d0e15ff494291779710b120d8f53202aa2ef1f (diff)
downloadreilua-enhanced-7765a23a2c90e6d02f6278eed1b1b9b9375bc941.tar.gz
reilua-enhanced-7765a23a2c90e6d02f6278eed1b1b9b9375bc941.tar.bz2
reilua-enhanced-7765a23a2c90e6d02f6278eed1b1b9b9375bc941.zip
LoadImageRaw, LoadImageAnim and LoadImageFromMemory. Version 0.6.
-rw-r--r--API.md27
-rw-r--r--ReiLua_API.lua27
-rw-r--r--changelog1
-rw-r--r--devnotes3
-rw-r--r--include/main.h2
-rw-r--r--include/textures.h3
-rw-r--r--src/lua_core.c3
-rw-r--r--src/textures.c66
8 files changed, 129 insertions, 3 deletions
diff --git a/API.md b/API.md
index ad5eb3b..f8086af 100644
--- a/API.md
+++ b/API.md
@@ -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
---
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index f607ffe..de40894 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -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
diff --git a/changelog b/changelog
index be3b68c..6e0125b 100644
--- a/changelog
+++ b/changelog
@@ -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
diff --git a/devnotes b/devnotes
index fe5b150..6b28dfc 100644
--- a/devnotes
+++ b/devnotes
@@ -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.
diff --git a/include/main.h b/include/main.h
index 3279bcc..e8759bb 100644
--- a/include/main.h
+++ b/include/main.h
@@ -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>
diff --git a/include/textures.h b/include/textures.h
index e755576..82cb1b9 100644
--- a/include/textures.h
+++ b/include/textures.h
@@ -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 );
diff --git a/src/lua_core.c b/src/lua_core.c
index 2389463..fe9d8c7 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -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 );
diff --git a/src/textures.c b/src/textures.c
index c5b07e4..008aa14 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -13,6 +13,7 @@
Load image from file into CPU memory (RAM)
+- Failure return nil
- Success return Image
*/
int ltexturesLoadImage( lua_State *L ) {
@@ -28,6 +29,71 @@ int ltexturesLoadImage( lua_State *L ) {
}
/*
+> 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 )
Load image from GPU texture data