summaryrefslogtreecommitdiff
path: root/src/textures.c
diff options
context:
space:
mode:
authorjussi2022-02-27 19:31:28 +0200
committerjussi2022-02-27 19:31:28 +0200
commitc3ae0a6c28316174891f8361ee0226d699a24013 (patch)
tree5e6ece761d9fda650ceef7e2dd2b164ce6e6ce57 /src/textures.c
parentda446b40b6923a08ce1f12f01bb93522c97683fe (diff)
downloadreilua-enhanced-c3ae0a6c28316174891f8361ee0226d699a24013.tar.gz
reilua-enhanced-c3ae0a6c28316174891f8361ee0226d699a24013.tar.bz2
reilua-enhanced-c3ae0a6c28316174891f8361ee0226d699a24013.zip
Color pixel functions.
Diffstat (limited to 'src/textures.c')
-rw-r--r--src/textures.c228
1 files changed, 228 insertions, 0 deletions
diff --git a/src/textures.c b/src/textures.c
index f28bd0f..72d6c28 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -1061,6 +1061,113 @@ int ltexturesGetTextureSize( lua_State *L ) {
*/
/*
+> color = RL_Fade( Color color, float alpha )
+
+Returns color with alpha applied, alpha goes from 0.0f to 1.0f
+
+- Failure return false
+- Success return Color
+*/
+int ltexturesFade( lua_State *L ) {
+ if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Fade( Color color, float alpha )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ float alpha = lua_tonumber( L, -1 );
+ lua_pop( L, 1 );
+ Color color = uluaGetColor( L );
+
+ uluaPushColor( L, Fade( color, alpha ) );
+
+ return 1;
+}
+
+/*
+> value = RL_ColorToInt( Color color )
+
+Returns hexadecimal value for a Color
+
+- Failure return false
+- Success return int
+*/
+int ltexturesColorToInt( lua_State *L ) {
+ if ( !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorToInt( Color color )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Color color = uluaGetColor( L );
+
+ lua_pushinteger( L, ColorToInt( color ) );
+
+ return 1;
+}
+
+/*
+> color = RL_ColorNormalize( Color color )
+
+Returns Color normalized as float [0..1]
+
+- Failure return false
+- Success return Vector4
+*/
+int ltexturesColorNormalize( lua_State *L ) {
+ if ( !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorNormalize( Color color )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Color color = uluaGetColor( L );
+
+ uluaPushVector4( L, ColorNormalize( color ) );
+
+ return 1;
+}
+
+/*
+> color = RL_ColorFromNormalized( Vector4 normalized )
+
+Color from normalized values [0..1]
+
+- Failure return false
+- Success return Color
+*/
+int ltexturesColorFromNormalized( lua_State *L ) {
+ if ( !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorFromNormalized( Vector4 normalized )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Vector4 normalized = uluaGetVector4( L );
+
+ uluaPushColor( L, ColorFromNormalized( normalized ) );
+
+ return 1;
+}
+
+/*
+> HSV = RL_ColorToHSV( Color color )
+
+Returns HSV values for a Color, hue [0..360], saturation/value [0..1]
+
+- Failure return false
+- Success return Vector3
+*/
+int ltexturesColorToHSV( lua_State *L ) {
+ if ( !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorToHSV( Color color )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Color color = uluaGetColor( L );
+
+ uluaPushVector3( L, ColorToHSV( color ) );
+
+ return 1;
+}
+
+/*
> color = RL_ColorFromHSV( float hue, float saturation, float value )
Returns a Color from HSV values, hue [0..360], saturation/value [0..1]
@@ -1078,3 +1185,124 @@ int ltexturesColorFromHSV( lua_State *L ) {
return 1;
}
+
+/*
+> color = RL_ColorAlpha( Color color, float alpha )
+
+Returns color with alpha applied, alpha goes from 0.0f to 1.0f
+
+- Failure return false
+- Success return Color
+*/
+int ltexturesColorAlpha( lua_State *L ) {
+ if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorAlpha( Color color, float alpha )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ float alpha = lua_tonumber( L, -1 );
+ lua_pop( L, 1 );
+ Color color = uluaGetColor( L );
+
+ uluaPushColor( L, ColorAlpha( color, alpha ) );
+
+ return 1;
+}
+
+/*
+> color = RL_ColorAlphaBlend( Color dst, Color src, Color tint )
+
+Returns src alpha-blended into dst color with tint
+
+- Failure return false
+- Success return Color
+*/
+int ltexturesColorAlphaBlend( lua_State *L ) {
+ if ( !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorAlphaBlend( Color dst, Color src, Color tint )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Color tint = uluaGetColor( L );
+ lua_pop( L, 1 );
+ Color src = uluaGetColor( L );
+ lua_pop( L, 1 );
+ Color dst = uluaGetColor( L );
+
+ uluaPushColor( L, ColorAlphaBlend( dst, src, tint ) );
+
+ return 1;
+}
+
+/*
+> Color = RL_GetColor( unsigned int hexValue )
+
+Get Color structure from hexadecimal value
+
+- Failure return false
+- Success return Color
+*/
+int ltexturesGetColor( lua_State *L ) {
+ if ( !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetColor( unsigned int hexValue )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ uluaPushColor( L, GetColor( (unsigned int)lua_tointeger( L, -1 ) ) );
+
+ return 1;
+}
+
+/*
+> Color = RL_GetPixelColor( Texture2D texture, Vector2 position )
+
+Get pixel color from source texture
+
+- Failure return false
+- Success return Color
+*/
+int ltexturesGetPixelColor( lua_State *L ) {
+ if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetPixelColor( Texture2D texture, Vector2 position )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Vector2 pos = uluaGetVector2( L );
+ lua_pop( L, 1 );
+ size_t texId = lua_tointeger( L, -2 );
+
+ if ( !validTexture( texId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ Texture2D *texture = texturesGetSourceTexture( texId );
+ Image srcImage = LoadImageFromTexture( *texture );
+
+ uluaPushColor( L, GetImageColor( srcImage, pos.x, pos.y ) );
+ UnloadImage( srcImage );
+
+ return 1;
+}
+
+
+
+Color GetPixelColor(void *srcPtr, int format);
+
+/*
+> size = RL_GetPixelDataSize( int width, int height, int format )
+
+Get pixel data size in bytes for certain format
+
+- Failure return false
+- Success return int
+*/
+int ltexturesGetPixelDataSize( lua_State *L ) {
+ if ( !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetPixelDataSize( int width, int height, int format )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ lua_pushinteger( L, GetPixelDataSize( lua_tointeger( L, -3 ), lua_tointeger( L, -2 ), lua_tointeger( L, -1 ) ) );
+
+ return 1;
+}