summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/launch.json2
-rw-r--r--API.md316
-rw-r--r--CMakeLists.txt2
-rw-r--r--README.md1
-rw-r--r--examples/image_draw/main.lua13
-rw-r--r--include/textures.h38
-rw-r--r--src/lua_core.c38
-rw-r--r--src/textures.c1129
8 files changed, 1417 insertions, 122 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 6927ffe..fd73ad6 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -9,7 +9,7 @@
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/ReiLua",
- "args": ["/examples/heightmap/"],
+ "args": ["/examples/image_draw/"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
diff --git a/API.md b/API.md
index 5dac6f3..b4e23f4 100644
--- a/API.md
+++ b/API.md
@@ -2250,6 +2250,271 @@ Generate image: cellular algorithm. Bigger tileSize means bigger cells
---
+## Textures - Image Manipulation Functions
+
+---
+
+> image = RL_ImageCopy( Image image )
+
+Create an image duplicate ( useful for transformations )
+
+- Failure return -1
+- Success return int
+
+---
+
+> image = RL_ImageFromImage( Image image, Rectangle rec )
+
+Create an image from another image piece
+
+- Failure return -1
+- Success return int
+
+---
+
+> image = RL_ImageText( Font font, string text, float fontSize, float spacing, Color tint )
+
+Create an image from text ( custom sprite font )
+
+- Failure return -1
+- Success return int
+
+---
+
+> success = RL_ImageFormat( Image image, int newFormat )
+
+Convert image data to desired format
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageToPOT( Image image, Color fill )
+
+Convert image to POT ( power-of-two )
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageCrop( Image image, Rectangle crop )
+
+Crop an image to a defined rectangle
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageAlphaCrop( Image image, float threshold )
+
+Crop image depending on alpha value
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageAlphaClear( Image image, Color color, float threshold )
+
+Clear alpha channel to desired color
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageAlphaMask( Image image, Image alphaMask )
+
+Apply alpha mask to image
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageAlphaPremultiply( Image image )
+
+Premultiply alpha channel
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageResize( Image image, Vector2 size )
+
+Resize image ( Bicubic scaling algorithm )
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageResizeNN( Image image, Vector2 size )
+
+Resize image ( Nearest-Neighbor scaling algorithm )
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageResizeCanvas( Image image, Vector2 size, Vector2 offset, Color fill )
+
+Resize canvas and fill with color
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageMipmaps( Image image )
+
+Generate all mipmap levels for a provided image
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageDither( Image image, Color bpp )
+
+Dither image data to 16bpp or lower ( Floyd-Steinberg dithering )
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageFlipVertical( Image image )
+
+Flip image vertically
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageFlipHorizontal( Image image )
+
+Flip image horizontally
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageRotateCW( Image image )
+
+Rotate image clockwise 90deg
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageRotateCCW( Image image )
+
+Rotate image counter-clockwise 90deg
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageColorTint( Image image, Color color )
+
+Modify image color: tint
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageColorInvert( Image image )
+
+Modify image color: invert
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageColorGrayscale( Image image )
+
+Modify image color: grayscale
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageColorContrast( Image image, float contrast )
+
+Modify image color: contrast ( -100 to 100 )
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageColorBrightness( Image image, int brightness )
+
+Modify image color: brightness ( -255 to 255 )
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL_ImageColorReplace( Image image, Color color, Color replace )
+
+Modify image color: replace color
+
+- Failure return false
+- Success return true
+
+---
+
+> colors = RL_LoadImageColors( Image image )
+
+Load color data from image as a Color array ( RGBA - 32bit )
+
+- Failure return false
+- Success return Color{}
+
+---
+
+> colors = RL_LoadImagePalette( Image image, int maxPaletteSize )
+
+Load colors palette from image as a Color array ( RGBA - 32bit )
+
+- Failure return false
+- Success return Color{}
+
+---
+
+> rectangle = RL_GetImageAlphaBorder( Image image, float threshold )
+
+Get image alpha border rectangle
+
+- Failure return false
+- Success return Rectangle
+
+---
+
+> color = RL_GetImageColor( Image image, Vector2 pixelPos )
+
+Get image pixel color at ( x, y ) position
+
+- Failure return false
+- Success return Color
+
+---
+
## Textures - Image Drawing
---
@@ -2326,6 +2591,37 @@ Draw text ( Custom sprite font ) within an image ( Destination )
---
+## Textures - Image Configuration
+
+---
+
+> size = RL_GetImageSize( Image image )
+
+Get image size
+
+- Failure return nil
+- Success return Vector2
+
+---
+
+> mipmaps = RL_GetImageMipmaps( Image image )
+
+Get image mipmaps. Mipmap levels, 1 by default
+
+- Failure return false
+- Success return int
+
+---
+
+> format = RL_GetImageFormat( Image image )
+
+Get image data format ( PixelFormat type )
+
+- Failure return false
+- Success return int
+
+---
+
## Textures - Texture Drawing
---
@@ -2416,7 +2712,7 @@ Get current texture source type ( TEXTURE_SOURCE_TEXTURE or TEXTURE_SOURCE_RENDE
---
-## Textures - Configure
+## Textures - Texture Configuration
---
@@ -2456,6 +2752,24 @@ Get texture size
---
+> mipmaps = RL_GetTextureMipmaps( Texture2D texture )
+
+Get texture mipmaps. Mipmap levels, 1 by default
+
+- Failure return false
+- Success return int
+
+---
+
+> format = RL_GetTextureFormat( Texture2D texture )
+
+Get texture mipmaps. Mipmap levels, 1 by default
+
+- Failure return false
+- Success return int
+
+---
+
## Textures - Color/pixel
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index be2d7f2..09a73ab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,8 +7,10 @@ project( ReiLua )
set( CMAKE_C_STANDARD 99 ) # Requires C99 standard
if( DEBUG )
+ message( Debug )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb -std=c99 -Wall -pedantic -fno-common" )
else()
+ message( Release )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -std=c99 -Wall -pedantic -fno-common" )
endif()
diff --git a/README.md b/README.md
index da97268..b36f80d 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,6 @@ List of some MISSING features that are planned to be included. For specific func
* Files drop
* VR stereo config functions for VR simulator
* Textures
- * Image manipulation functions
* Texture update functions
* Text
* Some font loading/unloading functions
diff --git a/examples/image_draw/main.lua b/examples/image_draw/main.lua
index 8855fce..5490c94 100644
--- a/examples/image_draw/main.lua
+++ b/examples/image_draw/main.lua
@@ -2,6 +2,8 @@ local monitor = 0
local texture = -1
local image = -1
local catImage = -1
+local catCopy = -1
+local textImage = -1
function init()
local mPos = RL_GetMonitorPosition( monitor )
@@ -21,6 +23,17 @@ function init()
RL_ImageDraw( image, catImage, { 143, 25, 230, 250 }, { 200, 200, 230, 250 }, WHITE )
RL_ImageDrawTextEx( image, 0, "Hello", { 300, 32 }, 48.0, 1.0, WHITE )
+ -- catCopy = RL_ImageCopy( catImage )
+ local src = { 80, 70, 96, 96 }
+ catCopy = RL_ImageFromImage( catImage, src )
+
+ RL_ImageDraw( image, catCopy, src, { 600, 200, src[3], src[4] }, WHITE )
+ -- RL_ImageDraw( image, catCopy, src, src, WHITE )
+
+ textImage = RL_ImageText( 0, "Cat", 10, 4, WHITE )
+ local imageSize = RL_GetImageSize( textImage )
+ RL_ImageDraw( image, textImage, { 0, 0, imageSize[1], imageSize[2] }, { 250, 40, imageSize[1], imageSize[2] }, WHITE )
+
texture = RL_LoadTextureFromImage( image )
end
diff --git a/include/textures.h b/include/textures.h
index 6da17e2..06947f6 100644
--- a/include/textures.h
+++ b/include/textures.h
@@ -28,6 +28,36 @@ int ltexturesGenImageGradientRadial( lua_State *L );
int ltexturesGenImageChecked( lua_State *L );
int ltexturesGenImageWhiteNoise( lua_State *L );
int ltexturesGenImageCellular( lua_State *L );
+/* Image Manipulation Functions. */
+int ltexturesImageCopy( lua_State *L );
+int ltexturesImageFromImage( lua_State *L );
+int ltexturesImageText( lua_State *L );
+int ltexturesImageFormat( lua_State *L );
+int ltexturesImageToPOT( lua_State *L );
+int ltexturesImageCrop( lua_State *L );
+int ltexturesImageAlphaCrop( lua_State *L );
+int ltexturesImageAlphaClear( lua_State *L );
+int ltexturesImageAlphaMask( lua_State *L );
+int ltexturesImageAlphaPremultiply( lua_State *L );
+int ltexturesImageResize( lua_State *L );
+int ltexturesImageResizeNN( lua_State *L );
+int ltexturesImageResizeCanvas( lua_State *L );
+int ltexturesImageMipmaps( lua_State *L );
+int ltexturesImageDither( lua_State *L );
+int ltexturesImageFlipVertical( lua_State *L );
+int ltexturesImageFlipHorizontal( lua_State *L );
+int ltexturesImageRotateCW( lua_State *L );
+int ltexturesImageRotateCCW( lua_State *L );
+int ltexturesImageColorTint( lua_State *L );
+int ltexturesImageColorInvert( lua_State *L );
+int ltexturesImageColorGrayscale( lua_State *L );
+int ltexturesImageColorContrast( lua_State *L );
+int ltexturesImageColorBrightness( lua_State *L );
+int ltexturesImageColorReplace( lua_State *L );
+int ltexturesLoadImageColors( lua_State *L );
+int ltexturesLoadImagePalette( lua_State *L );
+int ltexturesGetImageAlphaBorder( lua_State *L );
+int ltexturesGetImageColor( lua_State *L );
/* Image Drawing. */
int ltexturesImageClearBackground( lua_State *L );
int ltexturesImageDrawPixel( lua_State *L );
@@ -37,6 +67,10 @@ int ltexturesImageDrawRectangle( lua_State *L );
int ltexturesImageDrawRectangleLines( lua_State *L );
int ltexturesImageDraw( lua_State *L );
int ltexturesImageDrawTextEx( lua_State *L );
+/* Image Configuration. */
+int ltexturesGetImageSize( lua_State *L );
+int ltexturesGetImageMipmaps( lua_State *L );
+int ltexturesGetImageFormat( lua_State *L );
/* Texture Drawing. */
int ltexturesDrawTexture( lua_State *L );
int ltexturesDrawTextureRec( lua_State *L );
@@ -48,11 +82,13 @@ int ltexturesBeginTextureMode( lua_State *L );
int ltexturesEndTextureMode( lua_State *L );
int ltexturesSetTextureSource( lua_State *L );
int ltexturesGetTextureSource( lua_State *L );
-/* Conf. */
+/* Texture Configuration. */
int ltexturesGenTextureMipmaps( lua_State *L );
int ltexturesSetTextureFilter( lua_State *L );
int ltexturesSetTextureWrap( lua_State *L );
int ltexturesGetTextureSize( lua_State *L );
+int ltexturesGetTextureMipmaps( lua_State *L );
+int ltexturesGetTextureFormat( lua_State *L );
/* Color/pixel */
int ltexturesFade( lua_State *L );
int ltexturesColorToInt( lua_State *L );
diff --git a/src/lua_core.c b/src/lua_core.c
index 26bb1cf..da385da 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -666,6 +666,36 @@ void luaRegister() {
lua_register( L, "RL_GenImageChecked", ltexturesGenImageChecked );
lua_register( L, "RL_GenImageWhiteNoise", ltexturesGenImageWhiteNoise );
lua_register( L, "RL_GenImageCellular", ltexturesGenImageCellular );
+ /* Image Manipulation Functions. */
+ lua_register( L, "RL_ImageCopy", ltexturesImageCopy );
+ lua_register( L, "RL_ImageFromImage", ltexturesImageFromImage );
+ lua_register( L, "RL_ImageText", ltexturesImageText );
+ lua_register( L, "RL_ImageFormat", ltexturesImageFormat );
+ lua_register( L, "RL_ImageToPOT", ltexturesImageToPOT );
+ lua_register( L, "RL_ImageCrop", ltexturesImageCrop );
+ lua_register( L, "RL_ImageAlphaCrop", ltexturesImageAlphaCrop );
+ lua_register( L, "RL_ImageAlphaClear", ltexturesImageAlphaClear );
+ lua_register( L, "RL_ImageAlphaMask", ltexturesImageAlphaMask );
+ lua_register( L, "RL_ImageAlphaPremultiply", ltexturesImageAlphaPremultiply );
+ lua_register( L, "RL_ImageResize", ltexturesImageResize );
+ lua_register( L, "RL_ImageResizeNN", ltexturesImageResizeNN );
+ lua_register( L, "RL_ImageResizeCanvas", ltexturesImageResizeCanvas );
+ lua_register( L, "RL_ImageMipmaps", ltexturesImageMipmaps );
+ lua_register( L, "RL_ImageDither", ltexturesImageDither );
+ lua_register( L, "RL_ImageFlipVertical", ltexturesImageFlipVertical );
+ lua_register( L, "RL_ImageFlipHorizontal", ltexturesImageFlipHorizontal );
+ lua_register( L, "RL_ImageRotateCW", ltexturesImageRotateCW );
+ lua_register( L, "RL_ImageRotateCCW", ltexturesImageRotateCCW );
+ lua_register( L, "RL_ImageColorTint", ltexturesImageColorTint );
+ lua_register( L, "RL_ImageColorInvert", ltexturesImageColorInvert );
+ lua_register( L, "RL_ImageColorGrayscale", ltexturesImageColorGrayscale );
+ lua_register( L, "RL_ImageColorContrast", ltexturesImageColorContrast );
+ lua_register( L, "RL_ImageColorBrightness", ltexturesImageColorBrightness );
+ lua_register( L, "RL_ImageColorReplace", ltexturesImageColorReplace );
+ lua_register( L, "RL_LoadImageColors", ltexturesLoadImageColors );
+ lua_register( L, "RL_LoadImagePalette", ltexturesLoadImagePalette );
+ lua_register( L, "RL_GetImageAlphaBorder", ltexturesGetImageAlphaBorder );
+ lua_register( L, "RL_GetImageColor", ltexturesGetImageColor );
/* Image Drawing. */
lua_register( L, "RL_ImageClearBackground", ltexturesImageClearBackground );
lua_register( L, "RL_ImageDrawPixel", ltexturesImageDrawPixel );
@@ -675,6 +705,10 @@ void luaRegister() {
lua_register( L, "RL_ImageDrawRectangleLines", ltexturesImageDrawRectangleLines );
lua_register( L, "RL_ImageDraw", ltexturesImageDraw );
lua_register( L, "RL_ImageDrawTextEx", ltexturesImageDrawTextEx );
+ /* Image Configuration. */
+ lua_register( L, "RL_GetImageSize", ltexturesGetImageSize );
+ lua_register( L, "RL_GetImageMipmaps", ltexturesGetImageMipmaps );
+ lua_register( L, "RL_GetImageFormat", ltexturesGetImageFormat );
/* Texture Drawing. */
lua_register( L, "RL_DrawTexture", ltexturesDrawTexture );
lua_register( L, "RL_DrawTextureRec", ltexturesDrawTextureRec );
@@ -686,11 +720,13 @@ void luaRegister() {
lua_register( L, "RL_EndTextureMode", ltexturesEndTextureMode );
lua_register( L, "RL_SetTextureSource", ltexturesSetTextureSource );
lua_register( L, "RL_GetTextureSource", ltexturesGetTextureSource );
- /* Conf. */
+ /* Texture Configuration. */
lua_register( L, "RL_GenTextureMipmaps", ltexturesGenTextureMipmaps );
lua_register( L, "RL_SetTextureFilter", ltexturesSetTextureFilter );
lua_register( L, "RL_SetTextureWrap", ltexturesSetTextureWrap );
lua_register( L, "RL_GetTextureSize", ltexturesGetTextureSize );
+ lua_register( L, "RL_GetTextureMipmaps", ltexturesGetTextureMipmaps );
+ lua_register( L, "RL_GetTextureFormat", ltexturesGetTextureFormat );
/* Color/pixel */
lua_register( L, "RL_Fade", ltexturesFade );
lua_register( L, "RL_ColorToInt", ltexturesColorToInt );
diff --git a/src/textures.c b/src/textures.c
index f65b4c5..afc20c4 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -91,6 +91,34 @@ bool validSourceTexture( size_t id ) {
}
}
+static int newImage() {
+ int i = 0;
+
+ for ( i = 0; i < state->imageCount; i++ ) {
+ if ( state->images[i] == NULL ) {
+ break;
+ }
+ }
+ state->images[i] = malloc( sizeof( Image ) );
+ checkImageRealloc( i );
+
+ return i;
+}
+
+static int newTexture() {
+ int i = 0;
+
+ for ( i = 0; i < state->textureCount; i++ ) {
+ if ( state->textures[i] == NULL ) {
+ break;
+ }
+ }
+ state->textures[i] = malloc( sizeof( Texture2D ) );
+ checkTextureRealloc( i );
+
+ return i;
+}
+
Texture2D* texturesGetSourceTexture( size_t index ) {
switch ( state->textureSource ) {
case TEXTURE_SOURCE_TEXTURE:
@@ -123,17 +151,10 @@ int ltexturesLoadImage( lua_State *L ) {
}
if ( FileExists( lua_tostring( L, -1 ) ) ) {
- int i = 0;
-
- for ( i = 0; i < state->imageCount; i++ ) {
- if ( state->images[i] == NULL ) {
- break;
- }
- }
- state->images[i] = malloc( sizeof( Image ) );
+ int i = newImage();
*state->images[i] = LoadImage( lua_tostring( L, -1 ) );
lua_pushinteger( L, i );
- checkImageRealloc( i );
+
return 1;
}
else {
@@ -156,25 +177,15 @@ int ltexturesLoadImageFromTexture( lua_State *L ) {
lua_pushinteger( L, -1 );
return 1;
}
-
size_t texId = lua_tointeger( L, -1 );
if ( !validSourceTexture( texId ) ) {
lua_pushinteger( L, -1 );
return 1;
}
-
- int i = 0;
-
- for ( i = 0; i < state->imageCount; i++ ) {
- if ( state->images[i] == NULL ) {
- break;
- }
- }
- state->images[i] = malloc( sizeof( Image ) );
+ int i = newImage();
*state->images[i] = LoadImageFromTexture( *texturesGetSourceTexture( texId ) );
lua_pushinteger( L, i );
- checkImageRealloc( i );
return 1;
}
@@ -187,17 +198,9 @@ Load image from screen buffer and ( screenshot )
- Success return int
*/
int ltexturesLoadImageFromScreen( lua_State *L ) {
- int i = 0;
-
- for ( i = 0; i < state->imageCount; i++ ) {
- if ( state->images[i] == NULL ) {
- break;
- }
- }
- state->images[i] = malloc( sizeof( Image ) );
+ int i = newImage();
*state->images[i] = LoadImageFromScreen();
lua_pushinteger( L, i );
- checkImageRealloc( i );
return 1;
}
@@ -295,17 +298,9 @@ int ltexturesLoadTexture( lua_State *L ) {
}
if ( FileExists( lua_tostring( L, -1 ) ) ) {
- int i = 0;
-
- for ( i = 0; i < state->textureCount; i++ ) {
- if ( state->textures[i] == NULL ) {
- break;
- }
- }
- state->textures[i] = malloc( sizeof( Texture2D ) );
+ int i = newTexture();
*state->textures[i] = LoadTexture( lua_tostring( L, -1 ) );
lua_pushinteger( L, i );
- checkTextureRealloc( i );
return 1;
}
else {
@@ -334,18 +329,9 @@ int ltexturesLoadTextureFromImage( lua_State *L ) {
lua_pushboolean( L, false );
return 1;
}
-
- int i = 0;
-
- for ( i = 0; i < state->textureCount; i++ ) {
- if ( state->textures[i] == NULL ) {
- break;
- }
- }
- state->textures[i] = malloc( sizeof( Texture2D ) );
+ int i = newTexture();
*state->textures[i] = LoadTextureFromImage( *state->images[ imageId ] );
lua_pushinteger( L, i );
- checkTextureRealloc( i );
return 1;
}
@@ -458,17 +444,9 @@ int ltexturesGenImageColor( lua_State *L ) {
lua_pop( L, 1 );
int width = lua_tointeger( L, -1 );
- int i = 0;
-
- for ( i = 0; i < state->imageCount; i++ ) {
- if ( state->images[i] == NULL ) {
- break;
- }
- }
- state->images[i] = malloc( sizeof( Image ) );
+ int i = newImage();
*state->images[i] = GenImageColor( width, height, color );
lua_pushinteger( L, i );
- checkImageRealloc( i );
return 1;
}
@@ -493,17 +471,9 @@ int ltexturesGenImageGradientV( lua_State *L ) {
lua_pop( L, 1 );
Vector2 size = uluaGetVector2( L );
- int i = 0;
-
- for ( i = 0; i < state->imageCount; i++ ) {
- if ( state->images[i] == NULL ) {
- break;
- }
- }
- state->images[i] = malloc( sizeof( Image ) );
+ int i = newImage();
*state->images[i] = GenImageGradientV( (int)size.x, (int)size.y, top, bottom );
lua_pushinteger( L, i );
- checkImageRealloc( i );
return 1;
}
@@ -528,17 +498,9 @@ int ltexturesGenImageGradientH( lua_State *L ) {
lua_pop( L, 1 );
Vector2 size = uluaGetVector2( L );
- int i = 0;
-
- for ( i = 0; i < state->imageCount; i++ ) {
- if ( state->images[i] == NULL ) {
- break;
- }
- }
- state->images[i] = malloc( sizeof( Image ) );
+ int i = newImage();
*state->images[i] = GenImageGradientH( (int)size.x, (int)size.y, left, right );
lua_pushinteger( L, i );
- checkImageRealloc( i );
return 1;
}
@@ -565,17 +527,9 @@ int ltexturesGenImageGradientRadial( lua_State *L ) {
lua_pop( L, 1 );
Vector2 size = uluaGetVector2( L );
- int i = 0;
-
- for ( i = 0; i < state->imageCount; i++ ) {
- if ( state->images[i] == NULL ) {
- break;
- }
- }
- state->images[i] = malloc( sizeof( Image ) );
+ int i = newImage();
*state->images[i] = GenImageGradientRadial( (int)size.x, (int)size.y, density, inner, outer );
lua_pushinteger( L, i );
- checkImageRealloc( i );
return 1;
}
@@ -602,17 +556,9 @@ int ltexturesGenImageChecked( lua_State *L ) {
lua_pop( L, 1 );
Vector2 size = uluaGetVector2( L );
- int i = 0;
-
- for ( i = 0; i < state->imageCount; i++ ) {
- if ( state->images[i] == NULL ) {
- break;
- }
- }
- state->images[i] = malloc( sizeof( Image ) );
+ int i = newImage();
*state->images[i] = GenImageChecked( (int)size.x, (int)size.y, (int)checks.x, (int)checks.y, col1, col2 );
lua_pushinteger( L, i );
- checkImageRealloc( i );
return 1;
}
@@ -635,17 +581,9 @@ int ltexturesGenImageWhiteNoise( lua_State *L ) {
lua_pop( L, 1 );
Vector2 size = uluaGetVector2( L );
- int i = 0;
-
- for ( i = 0; i < state->imageCount; i++ ) {
- if ( state->images[i] == NULL ) {
- break;
- }
- }
- state->images[i] = malloc( sizeof( Image ) );
+ int i = newImage();
*state->images[i] = GenImageWhiteNoise( (int)size.x, (int)size.y, factor );
lua_pushinteger( L, i );
- checkImageRealloc( i );
return 1;
}
@@ -668,17 +606,837 @@ int ltexturesGenImageCellular( lua_State *L ) {
lua_pop( L, 1 );
Vector2 size = uluaGetVector2( L );
- int i = 0;
+ int i = newImage();
+ *state->images[i] = GenImageCellular( (int)size.x, (int)size.y, tileSize );
+ lua_pushinteger( L, i );
- for ( i = 0; i < state->imageCount; i++ ) {
- if ( state->images[i] == NULL ) {
- break;
- }
+ return 1;
+}
+
+/*
+## Textures - Image Manipulation Functions
+*/
+
+/*
+> image = RL_ImageCopy( Image image )
+
+Create an image duplicate ( useful for transformations )
+
+- Failure return -1
+- Success return int
+*/
+int ltexturesImageCopy( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageCopy( Image image )" );
+ lua_pushinteger( L, -1 );
+ return 1;
}
- state->images[i] = malloc( sizeof( Image ) );
- *state->images[i] = GenImageCellular( (int)size.x, (int)size.y, tileSize );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushinteger( L, -1 );
+ return 1;
+ }
+ int i = newImage();
+ *state->images[i] = ImageCopy( *state->images[ imageId ] );
lua_pushinteger( L, i );
- checkImageRealloc( i );
+
+ return 1;
+}
+
+/*
+> image = RL_ImageFromImage( Image image, Rectangle rec )
+
+Create an image from another image piece
+
+- Failure return -1
+- Success return int
+*/
+int ltexturesImageFromImage( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageFromImage( Image image, Rectangle rec )" );
+ lua_pushinteger( L, -1 );
+ return 1;
+ }
+ Rectangle rec = uluaGetRectangle( L );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushinteger( L, -1 );
+ return 1;
+ }
+ int i = newImage();
+ *state->images[i] = ImageFromImage( *state->images[ imageId ], rec );
+ lua_pushinteger( L, i );
+
+ return 1;
+}
+
+/*
+> image = RL_ImageText( Font font, string text, float fontSize, float spacing, Color tint )
+
+Create an image from text ( custom sprite font )
+
+- Failure return -1
+- Success return int
+*/
+int ltexturesImageText( lua_State *L ) {
+ if ( !lua_isnumber( L, -5 ) || !lua_isstring( L, -4 ) || !lua_isnumber( L, -3 )
+ || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageText( Font font, string text, float fontSize, float spacing, Color tint )" );
+ lua_pushinteger( L, -1 );
+ return 1;
+ }
+ Color tint = uluaGetColor( L );
+ lua_pop( L, 1 );
+ float spacing = lua_tonumber( L, -1 );
+ lua_pop( L, 1 );
+ float fontSize = lua_tonumber( L, -1 );
+ lua_pop( L, 1 );
+ size_t fontId = lua_tointeger( L, -2 );
+
+ if ( !validFont( fontId ) ) {
+ lua_pushinteger( L, -1 );
+ return 1;
+ }
+ int i = newImage();
+ *state->images[i] = ImageTextEx( *state->fonts[ fontId ], lua_tostring( L, -1 ), fontSize, spacing, tint );
+ lua_pushinteger( L, i );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageFormat( Image image, int newFormat )
+
+Convert image data to desired format
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageFormat( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageFormat( Image image, int newFormat )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int newFormat = lua_tointeger( L, -1 );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageFormat( state->images[ imageId ], newFormat );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageToPOT( Image image, Color fill )
+
+Convert image to POT ( power-of-two )
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageToPOT( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageToPOT( Image image, Color fill )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Color fill = uluaGetColor( L );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageToPOT( state->images[ imageId ], fill );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageCrop( Image image, Rectangle crop )
+
+Crop an image to a defined rectangle
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageCrop( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageCrop( Image image, Rectangle crop )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Rectangle crop = uluaGetRectangle( L );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageCrop( state->images[ imageId ], crop );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageAlphaCrop( Image image, float threshold )
+
+Crop image depending on alpha value
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageAlphaCrop( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageAlphaCrop( Image image, float threshold )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ float threshold = lua_tonumber( L, -1 );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageAlphaCrop( state->images[ imageId ], threshold );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageAlphaClear( Image image, Color color, float threshold )
+
+Clear alpha channel to desired color
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageAlphaClear( lua_State *L ) {
+ if ( !lua_isnumber( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageAlphaClear( Image image, Color color, float threshold )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Color color = uluaGetColor( L );
+ lua_pop( L, 1 );
+ float threshold = lua_tonumber( L, -1 );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageAlphaClear( state->images[ imageId ], color, threshold );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageAlphaMask( Image image, Image alphaMask )
+
+Apply alpha mask to image
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageAlphaMask( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageAlphaMask( Image image, Image alphaMask )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t alphaMaskId = lua_tonumber( L, -1 );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) || !validImage( alphaMaskId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageAlphaMask( state->images[ imageId ], *state->images[ alphaMaskId ] );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageAlphaPremultiply( Image image )
+
+Premultiply alpha channel
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageAlphaPremultiply( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageAlphaPremultiply( Image image )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageAlphaPremultiply( state->images[ imageId ] );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageResize( Image image, Vector2 size )
+
+Resize image ( Bicubic scaling algorithm )
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageResize( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageResize( Image image, Vector2 size )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Vector2 size = uluaGetVector2( L );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageResize( state->images[ imageId ], size.x, size.y );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageResizeNN( Image image, Vector2 size )
+
+Resize image ( Nearest-Neighbor scaling algorithm )
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageResizeNN( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageResizeNN( Image image, Vector2 size )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Vector2 size = uluaGetVector2( L );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageResizeNN( state->images[ imageId ], size.x, size.y );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageResizeCanvas( Image image, Vector2 size, Vector2 offset, Color fill )
+
+Resize canvas and fill with color
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageResizeCanvas( lua_State *L ) {
+ if ( !lua_isnumber( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageResizeCanvas( Image image, Vector2 size, Vector2 offset, Color fill )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Color fill = uluaGetColor( L );
+ lua_pop( L, 1 );
+ Vector2 offset = uluaGetVector2( L );
+ lua_pop( L, 1 );
+ Vector2 size = uluaGetVector2( L );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageResizeCanvas( state->images[ imageId ], size.x, size.y, offset.x, offset.y, fill );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageMipmaps( Image image )
+
+Generate all mipmap levels for a provided image
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageMipmaps( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageMipmaps( Image image )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageMipmaps( state->images[ imageId ] );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageDither( Image image, Color bpp )
+
+Dither image data to 16bpp or lower ( Floyd-Steinberg dithering )
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageDither( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageDither( Image image, Color bpp )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Color bpp = uluaGetColor( L );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageDither( state->images[ imageId ], bpp.r, bpp.g, bpp.b, bpp.a );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageFlipVertical( Image image )
+
+Flip image vertically
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageFlipVertical( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageFlipVertical( Image image )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageFlipVertical( state->images[ imageId ] );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageFlipHorizontal( Image image )
+
+Flip image horizontally
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageFlipHorizontal( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageFlipHorizontal( Image image )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageFlipHorizontal( state->images[ imageId ] );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageRotateCW( Image image )
+
+Rotate image clockwise 90deg
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageRotateCW( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageRotateCW( Image image )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageRotateCW( state->images[ imageId ] );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageRotateCCW( Image image )
+
+Rotate image counter-clockwise 90deg
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageRotateCCW( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageRotateCCW( Image image )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageRotateCCW( state->images[ imageId ] );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageColorTint( Image image, Color color )
+
+Modify image color: tint
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageColorTint( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageColorTint( Image image, Color color )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Color color = uluaGetColor( L );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageColorTint( state->images[ imageId ], color );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageColorInvert( Image image )
+
+Modify image color: invert
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageColorInvert( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageColorInvert( Image image )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageColorInvert( state->images[ imageId ] );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageColorGrayscale( Image image )
+
+Modify image color: grayscale
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageColorGrayscale( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageColorGrayscale( Image image )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageColorGrayscale( state->images[ imageId ] );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageColorContrast( Image image, float contrast )
+
+Modify image color: contrast ( -100 to 100 )
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageColorContrast( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageColorContrast( Image image, float contrast )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ float contrast = lua_tonumber( L, -1 );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageColorContrast( state->images[ imageId ], contrast );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageColorBrightness( Image image, int brightness )
+
+Modify image color: brightness ( -255 to 255 )
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageColorBrightness( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageColorBrightness( Image image, int brightness )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int brightness = lua_tointeger( L, -1 );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageColorBrightness( state->images[ imageId ], brightness );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL_ImageColorReplace( Image image, Color color, Color replace )
+
+Modify image color: replace color
+
+- Failure return false
+- Success return true
+*/
+int ltexturesImageColorReplace( lua_State *L ) {
+ if ( !lua_isnumber( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageColorReplace( Image image, Color color, Color replace )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Color replace = uluaGetColor( L );
+ lua_pop( L, 1 );
+ Color color = uluaGetColor( L );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ ImageColorReplace( state->images[ imageId ], color, replace );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> colors = RL_LoadImageColors( Image image )
+
+Load color data from image as a Color array ( RGBA - 32bit )
+
+- Failure return false
+- Success return Color{}
+*/
+int ltexturesLoadImageColors( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadImageColors( Image image )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int colorCount = state->images[ imageId ]->width * state->images[ imageId ]->height;
+
+ Color *colors = LoadImageColors( *state->images[ imageId ] );
+
+ lua_createtable( L, colorCount, 0 );
+
+ for ( int i = 0; i < colorCount; ++i ) {
+ uluaPushColor( L, colors[i] );
+ lua_rawseti( L, -2, i + 1 );
+ }
+ UnloadImageColors( colors );
+
+ return 1;
+}
+
+/*
+> colors = RL_LoadImagePalette( Image image, int maxPaletteSize )
+
+Load colors palette from image as a Color array ( RGBA - 32bit )
+
+- Failure return false
+- Success return Color{}
+*/
+int ltexturesLoadImagePalette( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadImagePalette( Image image, int maxPaletteSize )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int maxPaletteSize = lua_tointeger( L, -1 );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int colorCount = 0;
+
+ Color *colors = LoadImagePalette( *state->images[ imageId ], maxPaletteSize, &colorCount );
+
+ lua_createtable( L, colorCount, 0 );
+
+ for ( int i = 0; i < colorCount; ++i ) {
+ uluaPushColor( L, colors[i] );
+ lua_rawseti( L, -2, i + 1 );
+ }
+ UnloadImagePalette( colors );
+
+ return 1;
+}
+
+/*
+> rectangle = RL_GetImageAlphaBorder( Image image, float threshold )
+
+Get image alpha border rectangle
+
+- Failure return false
+- Success return Rectangle
+*/
+int ltexturesGetImageAlphaBorder( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetImageAlphaBorder( Image image, float threshold )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ float threshold = lua_tonumber( L, -1 );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ uluaPushRectangle( L, GetImageAlphaBorder( *state->images[ imageId ], threshold ) );
+
+ return 1;
+}
+
+/*
+> color = RL_GetImageColor( Image image, Vector2 pixelPos )
+
+Get image pixel color at ( x, y ) position
+
+- Failure return false
+- Success return Color
+*/
+int ltexturesGetImageColor( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetImageColor( Image image, Vector2 pixelPos )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Vector2 pixelPos = uluaGetVector2( L );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ uluaPushColor( L, GetImageColor( *state->images[ imageId ], pixelPos.x, pixelPos.y ) );
return 1;
}
@@ -950,6 +1708,87 @@ int ltexturesImageDrawTextEx( lua_State *L ) {
}
/*
+## Textures - Image Configuration
+*/
+
+/*
+> size = RL_GetImageSize( Image image )
+
+Get image size
+
+- Failure return nil
+- Success return Vector2
+*/
+int ltexturesGetImageSize( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetImageSize( Image image )" );
+ lua_pushnil( L );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushnil( L );
+ return 1;
+ }
+
+ Image *image = state->images[ imageId ];
+ uluaPushVector2( L, (Vector2){ image->width, image->height } );
+
+ return 1;
+}
+
+/*
+> mipmaps = RL_GetImageMipmaps( Image image )
+
+Get image mipmaps. Mipmap levels, 1 by default
+
+- Failure return false
+- Success return int
+*/
+int ltexturesGetImageMipmaps( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetImageMipmaps( Image image )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ lua_pushinteger( L, state->images[ imageId ]->mipmaps );
+
+ return 1;
+}
+
+/*
+> format = RL_GetImageFormat( Image image )
+
+Get image data format ( PixelFormat type )
+
+- Failure return false
+- Success return int
+*/
+int ltexturesGetImageFormat( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetImageFormat( Image image )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ lua_pushinteger( L, state->images[ imageId ]->format );
+
+ return 1;
+}
+
+/*
## Textures - Texture Drawing
*/
@@ -1270,7 +2109,7 @@ int ltexturesGetTextureSource( lua_State *L ) {
}
/*
-## Textures - Configure
+## Textures - Texture Configuration
*/
/*
@@ -1289,7 +2128,8 @@ int ltexturesGenTextureMipmaps( lua_State *L ) {
}
size_t texId = lua_tointeger( L, -1 );
- if ( !validTexture( texId ) ) {
+ // if ( !validTexture( texId ) ) {
+ if ( !validSourceTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -1316,7 +2156,8 @@ int ltexturesSetTextureFilter( lua_State *L ) {
}
size_t texId = lua_tointeger( L, -2 );
- if ( !validTexture( texId ) ) {
+ // if ( !validTexture( texId ) ) {
+ if ( !validSourceTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
@@ -1343,12 +2184,14 @@ int ltexturesSetTextureWrap( lua_State *L ) {
}
size_t texId = lua_tointeger( L, -2 );
- if ( !validTexture( texId ) ) {
+ // if ( !validTexture( texId ) ) {
+ if ( !validSourceTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
- SetTextureWrap( *state->textures[ texId ], lua_tointeger( L, -1 ) );
+ SetTextureWrap( *texturesGetSourceTexture( texId ), lua_tointeger( L, -1 ) );
+ // SetTextureWrap( *state->textures[ texId ], lua_tointeger( L, -1 ) );
lua_pushboolean( L, true );
return 1;
@@ -1371,12 +2214,63 @@ int ltexturesGetTextureSize( lua_State *L ) {
size_t texId = lua_tointeger( L, -1 );
if ( !validSourceTexture( texId ) ) {
+ lua_pushnil( L );
+ return 1;
+ }
+ Texture2D texture = *texturesGetSourceTexture( texId );
+ uluaPushVector2( L, (Vector2){ texture.width, texture.height } );
+
+ return 1;
+}
+
+/*
+> mipmaps = RL_GetTextureMipmaps( Texture2D texture )
+
+Get texture mipmaps. Mipmap levels, 1 by default
+
+- Failure return false
+- Success return int
+*/
+int ltexturesGetTextureMipmaps( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetTextureMipmaps( Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
}
+ size_t texId = lua_tointeger( L, -1 );
+ if ( !validImage( texId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
Texture2D texture = *texturesGetSourceTexture( texId );
- uluaPushVector2( L, (Vector2){ texture.width, texture.height } );
+ lua_pushinteger( L, texture.mipmaps );
+
+ return 1;
+}
+
+/*
+> format = RL_GetTextureFormat( Texture2D texture )
+
+Get texture mipmaps. Mipmap levels, 1 by default
+
+- Failure return false
+- Success return int
+*/
+int ltexturesGetTextureFormat( lua_State *L ) {
+ if ( !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetTextureFormat( Texture2D texture )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ size_t texId = lua_tointeger( L, -1 );
+
+ if ( !validImage( texId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Texture2D texture = *texturesGetSourceTexture( texId );
+ lua_pushinteger( L, texture.format );
return 1;
}
@@ -1596,7 +2490,8 @@ int ltexturesGetPixelColor( lua_State *L ) {
lua_pop( L, 1 );
size_t texId = lua_tointeger( L, -2 );
- if ( !validTexture( texId ) ) {
+ // if ( !validTexture( texId ) ) {
+ if ( !validSourceTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}