Color pixel functions.
This commit is contained in:
228
src/textures.c
228
src/textures.c
@@ -1060,6 +1060,113 @@ int ltexturesGetTextureSize( lua_State *L ) {
|
||||
## Textures - Color/pixel
|
||||
*/
|
||||
|
||||
/*
|
||||
> 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 )
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user