cColor
Overview
Types and Definitions
cColor
struct cColor
{
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
};
typedef struct cColor cColor;
Structs that represents a color value with a alpha channel. The color value is stored in the RGB color space.
Generated
cColorSlice
struct cColorSlice
{
int64_t s;
cColor const* v;
};
typedef struct cColorSlice cColorSlice;
Via the macro SLICES_C_ generated struct.
cVarColorSlice
struct cVarColorSlice
{
int64_t s;
cColor* v;
};
typedef struct cVarColorSlice cVarColorSlice;
Via the macro SLICES_C_ generated struct.
Functions
init
color_c_
#define color_c_( Red, Green, Blue, Alpha )
Creates a transparent color object from decimal red, green, blue and alpha (RGBA) values.
rgb_color_c
cColor rgb_color_c( uint32_t raw );
Creates a cColor instance from a hex value in the following format RRGGBB.
rgba_color_c
cColor rgba_color_c( uint32_t raw );
Creates a cColor instance from a hex value in the following format RRGGBBAA.
argb_color_c
cColor argb_color_c( uint32_t raw );
Creates a cColor instance from a hex value in the following format AARRGGBB.
alpha_color_c
cColor alpha_color_c( uint8_t red, uint32_t green, uint32_t blue, float alpha );
Creats a cColor instance where the alpha value can be set as float (0.0 - 1.0).
from
from_cmyk_c
#define from_cmyk_c_( Cyan, Magenta, Yellow, Key ) \
from_cmyk_c( cmyk_c_( (Cyan), (Magenta), (Yellow), (Key) ) )
cColor from_cmyk_c( cCmyk cmyk );
Creates a cColor value from a cCmyk value.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cColor c = from_cmyk_c_( 0.58f, 0.36f, 0.0f, 0.35f );
expect_c_( eq_color_c( c, rgb_color_c( 0x466aa6 ) ) );
return finish_tap_c_();
}
from_cmyk32_c
#define from_cmyk32_c_( Cyan, Magenta, Yellow, Key ) \
from_cmyk32_c( cmyk32_c_( (Cyan), (Magenta), (Yellow), (Key) ) )
cColor from_cmyk32_c( cCmyk32 cmyk );
Creates a cColor value from a cCmyk32 value.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cColor c = from_cmyk32_c_( 148, 92, 0, 89 );
expect_c_( eq_color_c( c, rgb_color_c( 0x466aa6 ) ) );
return finish_tap_c_();
}
from_hsl_c
#define from_hsl_c_( Hue, Saturation, Lightness ) \
from_hsl_c( hsl_c_( (Hue), (Saturation), (Lightness) ) )
cColor from_hsl_c( cHsl hsl );
Creates a cColor value from a cHsl value.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cColor c = from_hsl_c_( 90.0f, 1.0f, 0.5f );
expect_c_( eq_color_c( c, rgb_color_c( 0x80ff00 ) ) );
return finish_tap_c_();
}
from_hsv_c
#define from_hsv_c_( Hue, Saturation, Value ) \
from_hsv_c( hsv_c_( (Hue), (Saturation), (Value) ) )
cColor from_hsv_c( cHsv hsv );
Creates a cColor value from a cHsv value.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cColor c = from_hsv_c_( 90.0f, 1.0f, 0.5f );
expect_c_( eq_color_c( c, rgb_color_c( 0x408000 ) ) );
return finish_tap_c_();
}
from_rgb_c
#define from_rgb_c_( Red, Green, Blue ) \
from_rgb_c( rgb_c_( (Red), (Green), (Blue) ) )
cColor from_rgb_c( cRgb rgb );
Creates a cColor value from a cRgb value.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cColor c = from_rgb_c_( 0.271f, 0.416f, 0.651f );
expect_c_( eq_color_c( c, rgb_color_c( 0x456aa6 ) ) );
return finish_tap_c_();
}
from_rgb24_c
#define from_rgb24_c_( Red, Green, Blue ) \
from_rgb24_c( rgb24_c_( (Red), (Green), (Blue) ) )
cColor from_rgb24_c( cRgb24 rgb );
Creates a cColor value from a cRgb24 value.
as
as_cmyk_c
cCmyk as_cmyk_c( cColor color );
Coverts a cColor value to a cCmyk value.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cCmyk cmyk = as_cmyk_c( rgb_color_c( 0x466aa6 ) );
cCmyk exp = cmyk_c_( 0.578f, 0.361f, 0.0f, 0.349f );
expect_c_( eq_cmyk_c( cmyk, exp, 0.0005f ) );
return finish_tap_c_();
}
as_cmyk32_c
cCmyk32 as_cmyk32_c( cColor color );
Coverts a cColor value to a cCmyk32 value.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cCmyk32 cmyk = as_cmyk32_c( rgb_color_c( 0x466aa6 ) );
cCmyk32 exp = cmyk32_c_( 147, 92, 0, 89 );
expect_c_( eq_cmyk32_c( cmyk, exp ) );
return finish_tap_c_();
}
as_hsl_c
cHsl as_hsl_c( cColor color );
Coverts a cColor value to a cHsl value.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cHsl hsl = as_hsl_c( color_c_( 128, 255, 0, 255 ) );
cHsl exp = hsl_c_( 89.9f, 1.0f, 0.5f );
expect_c_( eq_hsl_c( hsl, exp, 0.05f ) );
return finish_tap_c_();
}
as_hsv_c
cHsv as_hsv_c( cColor color );
Coverts a cColor value to a cHsv value.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cHsv hsv = as_hsv_c( rgb_color_c( 0xabcdef ) );
cHsv exp = hsv_c_( 210.0f, 0.285f, 0.937f );
expect_c_( eq_hsv_c( hsv, exp, 0.0005f ) );
return finish_tap_c_();
}
as_rgb_c
cRgb as_rgb_c( cColor color );
Coverts a cColor value to a cRgb value.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cRgb rgb = as_rgb_c( rgb_color_c( 0x456aa6 ) );
cRgb exp = rgb_c_( 0.271f, 0.416f, 0.651f );
expect_c_( eq_rgb_c( rgb, exp, 0.0005f ) );
return finish_tap_c_();
}
as_rgb24_c
cRgb24 as_rgb24_c( cColor color );
Coverts a cColor value to a cRgb24 value.
cmp
eq_color_c
bool eq_color_c( cColor a, cColor b );
Returns true if both cColor values are equal, otherwise false.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cColor black = rgb_color_c( 0x000000 );
cColor white = rgb_color_c( 0xffffff );
expect_c_( eq_color_c( black, black ) );
expect_c_( !eq_color_c( black, white ) );
return finish_tap_c_();
}
eq_rgb_color_c
bool eq_rgb_color_c( cColor a, cColor b );
Returns true if the RGB values of both cColor values are equal, otherwise false.
alpha
color_alpha_c
float color_alpha_c( cColor color );
Returns the alpha value as float (0.0 - 1.0).
set_color_alpha_c
cColor set_color_alpha_c( cColor color, float alpha );
Sets the alpha value via float (0.0 - 1.0).
color_luma_c
float color_luma_c( cColor color );
Calculates the luma (perceptual brightness) of a color object.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor color;
float exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
testSlice tests = slice_c_( test,
t_( from_rgb24_c_( 100, 200, 30 ), 0.65f ),
t_( cCONTRAST_COLOR_DARK_, 0.0f ),
t_( cCONTRAST_COLOR_LIGHT_, 1.0f ),
t_( from_hsl_c_( 90.0f, 1.0f, 0.5f ), 0.82f )
);
for_each_c_( test const*, t, tests )
{
float luma = color_luma_c( t->color );
bool res = eq_float_c( luma, t->exp, 0.005 );
expect_c_( res );
}
return finish_tap_c_();
}
operations
saturate_color_c
cColor saturate_color_c( cColor color, float amount );
Increase the saturation of a color in the HSL color space by an absolute amount.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor color;
float amount;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
testSlice tests = slice_c_( test,
t_( from_hsl_c_( 90.0f, 0.9f, 0.5f ), 0.1f, rgb_color_c( 0x80ff00 ) )
);
for_each_c_( test const*, t, tests )
{
cColor saturated = saturate_color_c( t->color, t->amount );
bool res = eq_color_c( saturated, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
desaturate_color_c
cColor desaturate_color_c( cColor color, float amount );
Decrease the saturation of a color in the HSL color space by an absolute amount.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cColor base = from_hsl_c_( 90.0f, 0.9f, 0.5f );
cColor desaturated = desaturate_color_c( base, 0.1f );
expect_c_( eq_color_c( desaturated, rgb_color_c( 0x80e51a ) ) );
return finish_tap_c_();
}
lighten_color_c
cColor lighten_color_c( cColor color, float amount );
Increase the lightness of a color in the HSL color space by an absolute amount.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cColor base = from_hsl_c_( 90.0f, 0.9f, 0.5f );
cColor light = lighten_color_c( base, 0.1f );
expect_c_( eq_color_c( light, rgb_color_c( 0x99f53d ) ) );
return finish_tap_c_();
}
darken_color_c
cColor darken_color_c( cColor color, float amount );
Decrease the lightness of a color in the HSL color space by an absolute amount.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cColor base = from_hsl_c_( 90.0f, 0.9f, 0.5f );
cColor dark = darken_color_c( base, 0.1f );
expect_c_( eq_color_c( dark, rgb_color_c( 0x66c20a ) ) );
return finish_tap_c_();
}
fade_color_c
cColor fade_color_c( cColor color, float amount );
Set the absolute opacity of a color. Can be applied to colors whether they already have an opacity value or not.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
float alpha;
float fade;
float exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
testSlice tests = slice_c_( test,
t_( 0.5f, 0.1f, 0.6f ),
t_( 0.5f, -0.1f, 0.4f )
);
cColor base = rgb_color_c( 0xaabbcc );
for_each_c_( test const*, t, tests )
{
cColor c = set_color_alpha_c( base, t->alpha );
c = fade_color_c( c, t->fade );
float res = color_alpha_c( c );
expect_c_( eq_float_c( res, t->exp, 0.005f ) );
}
return finish_tap_c_();
}
spin_color_c
cColor spin_color_c( cColor color, float angle );
While the angle range is 0-360, it applies a mod 360 operation, so you can pass in much larger (or negative) values and they will wrap around e.g. angles of 360 and 720 will produce the same result.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor color;
float angle;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
testSlice tests = slice_c_( test,
t_( from_hsl_c_( 10.0f, 0.9f, 0.5f ), 20.0f, rgb_color_c( 0xf27f0d ) ),
t_( from_hsl_c_( 10.0f, 0.9f, 0.5f ), -20.0f, rgb_color_c( 0xf20d33 ) )
);
for_each_c_( test const*, t, tests )
{
cColor spinned = spin_color_c( t->color, t->angle );
bool res = eq_color_c( spinned, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
mix_color_c
#define mix_color_c_( Color, Extra ) \
mix_color_c( Color, Extra, cMIX_COLOR_WEIGHT_ )
cColor mix_color_c( cColor color, cColor extra, float weight );
Mix two colors together in variable proportion. Opacity is included in the calculations.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor color;
cColor extra;
float weight;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
testSlice tests = slice_c_( test,
t_(
rgb_color_c( 0xff0000 ), rgb_color_c( 0x0000ff ), 0.5f,
rgb_color_c( 0x800080 )
),
t_(
rgba_color_c( 0x640000ff ), rgba_color_c( 0x00640080 ), 0.5f,
rgba_color_c( 0x4b1900c0 )
),
t_(
rgba_color_c( 0x640000ff ), rgba_color_c( 0x00640080 ), 0.25f,
rgba_color_c( 0x323200a0 )
)
);
for_each_c_( test const*, t, tests )
{
cColor mixed = mix_color_c( t->color, t->extra, t->weight );
bool res = eq_color_c( mixed, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
greyscale_color_c
cColor greyscale_color_c( cColor color );
Remove all saturation from a color in the HSL color space.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cColor color = greyscale_color_c( from_hsl_c_( 90.0, 0.9, 0.5 ) );
expect_c_( eq_color_c( color, rgb_color_c( 0x808080 ) ) );
return finish_tap_c_();
}
contrast_color_c
#define contrast_color_c_( Color ) \
contrast_color_c( (Color), \
cCONTRAST_COLOR_DARK_, \
cCONTRAST_COLOR_LIGHT_, \
cCONTRAST_COLOR_THRESHOLD_ )
cColor contrast_color_c( cColor color,
cColor dark,
cColor light,
float threshold );
Choose which of two colors provides the greatest contrast with another.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor base;
cColor dark;
cColor light;
float threshold;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
testSlice tests = slice_c_( test,
t_(
rgb_color_c( 0x222222 ), rgb_color_c( 0x101010 ),
cCONTRAST_COLOR_LIGHT_, cCONTRAST_COLOR_THRESHOLD_,
cCONTRAST_COLOR_LIGHT_
),
t_(
rgb_color_c( 0x222222 ), rgb_color_c( 0x101010 ),
rgb_color_c( 0xdddddd ), cCONTRAST_COLOR_THRESHOLD_,
rgb_color_c( 0xdddddd )
),
t_(
from_hsl_c_( 90.0f, 1.0f, 0.5f ), cCONTRAST_COLOR_DARK_,
cCONTRAST_COLOR_LIGHT_, 0.4f,
cCONTRAST_COLOR_DARK_
),
t_(
from_hsl_c_( 90.0f, 1.0f, 0.5f ), cCONTRAST_COLOR_DARK_,
cCONTRAST_COLOR_LIGHT_, 0.6f,
cCONTRAST_COLOR_LIGHT_
)
);
for_each_c_( test const*, t, tests )
{
cColor c = contrast_color_c( t->base, t->dark, t->light, t->threshold );
bool res = eq_color_c( c, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
blending
multiply_color_c
cColor multiply_color_c( cColor a, cColor b );
Multiply two colors. Corresponding RGB channels from each of the two colors are multiplied together then divided by 255. The result is a darker color.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor a;
cColor b;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
cColor base = rgb_color_c( 0xff6600 );
testSlice tests = slice_c_( test,
t_( base, rgb_color_c( 0x000000 ), rgb_color_c( 0x000000 ) ),
t_( base, rgb_color_c( 0x333333 ), rgb_color_c( 0x331400 ) ),
t_( base, rgb_color_c( 0x666666 ), rgb_color_c( 0x662900 ) ),
t_( base, rgb_color_c( 0x999999 ), rgb_color_c( 0x993d00 ) ),
t_( base, rgb_color_c( 0xcccccc ), rgb_color_c( 0xcc5200 ) ),
t_( base, rgb_color_c( 0xffffff ), rgb_color_c( 0xff6600 ) ),
t_( base, rgb_color_c( 0xff0000 ), rgb_color_c( 0xff0000 ) ),
t_( base, rgb_color_c( 0x00ff00 ), rgb_color_c( 0x006600 ) ),
t_( base, rgb_color_c( 0x0000ff ), rgb_color_c( 0x000000 ) )
);
for_each_c_( test const*, t, tests )
{
cColor mult = multiply_color_c( t->a, t->b );
bool res = eq_color_c( mult, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
screen_color_c
cColor screen_color_c( cColor a, cColor b );
Do the opposite of multiply. The result is a brighter color.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor a;
cColor b;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
cColor base = rgb_color_c( 0xff6600 );
testSlice tests = slice_c_( test,
t_( base, rgb_color_c( 0x000000 ), rgb_color_c( 0xff6600 ) ),
t_( base, rgb_color_c( 0x333333 ), rgb_color_c( 0xff8533 ) ),
t_( base, rgb_color_c( 0x666666 ), rgb_color_c( 0xffa366 ) ),
t_( base, rgb_color_c( 0x999999 ), rgb_color_c( 0xffc299 ) ),
t_( base, rgb_color_c( 0xcccccc ), rgb_color_c( 0xffe0cc ) ),
t_( base, rgb_color_c( 0xffffff ), rgb_color_c( 0xffffff ) ),
t_( base, rgb_color_c( 0xff0000 ), rgb_color_c( 0xff6600 ) ),
t_( base, rgb_color_c( 0x00ff00 ), rgb_color_c( 0xffff00 ) ),
t_( base, rgb_color_c( 0x0000ff ), rgb_color_c( 0xff66ff ) )
);
for_each_c_( test const*, t, tests )
{
cColor screen = screen_color_c( t->a, t->b );
bool res = eq_color_c( screen, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
overlay_color_c
cColor overlay_color_c( cColor a, cColor b );
Combines the effects of both multiply and screen. Conditionally make light channels lighter and dark channels darker.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor a;
cColor b;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
cColor base = rgb_color_c( 0xff6600 );
testSlice tests = slice_c_( test,
t_( base, rgb_color_c( 0x000000 ), rgb_color_c( 0xff0000 ) ),
t_( base, rgb_color_c( 0x333333 ), rgb_color_c( 0xff2900 ) ),
t_( base, rgb_color_c( 0x666666 ), rgb_color_c( 0xff5200 ) ),
t_( base, rgb_color_c( 0x999999 ), rgb_color_c( 0xff7a00 ) ),
t_( base, rgb_color_c( 0xcccccc ), rgb_color_c( 0xffa300 ) ),
t_( base, rgb_color_c( 0xffffff ), rgb_color_c( 0xffcc00 ) ),
t_( base, rgb_color_c( 0xff0000 ), rgb_color_c( 0xff0000 ) ),
t_( base, rgb_color_c( 0x00ff00 ), rgb_color_c( 0xffcc00 ) ),
t_( base, rgb_color_c( 0x0000ff ), rgb_color_c( 0xff0000 ) )
);
for_each_c_( test const*, t, tests )
{
cColor over = overlay_color_c( t->a, t->b );
bool res = eq_color_c( over, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
softlight_color_c
cColor softlight_color_c( cColor color, cColor extra );
Similar to overlay but avoids pure black resulting in pure black, and pure white resulting in pure white.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor color;
cColor extra;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
cColor base = rgb_color_c( 0xff6600 );
testSlice tests = slice_c_( test,
t_( base, rgb_color_c( 0x000000 ), rgb_color_c( 0xff2900 ) ),
t_( base, rgb_color_c( 0x333333 ), rgb_color_c( 0xff4100 ) ),
t_( base, rgb_color_c( 0x666666 ), rgb_color_c( 0xff5a00 ) ),
t_( base, rgb_color_c( 0x999999 ), rgb_color_c( 0xff7200 ) ),
t_( base, rgb_color_c( 0xcccccc ), rgb_color_c( 0xff8b00 ) ),
t_( base, rgb_color_c( 0xffffff ), rgb_color_c( 0xffa300 ) ),
t_( base, rgb_color_c( 0xff0000 ), rgb_color_c( 0xff2900 ) ),
t_( base, rgb_color_c( 0x00ff00 ), rgb_color_c( 0xffa300 ) ),
t_( base, rgb_color_c( 0x0000ff ), rgb_color_c( 0xff2900 ) )
);
for_each_c_( test const*, t, tests )
{
cColor spot = softlight_color_c( t->color, t->extra );
bool res = eq_color_c( spot, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
hardlight_color_c
cColor hardlight_color_c( cColor color, cColor extra );
The same as overlay but with the color roles reversed.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor a;
cColor b;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
cColor base = rgb_color_c( 0xff6600 );
testSlice tests = slice_c_( test,
t_( base, rgb_color_c( 0x000000 ), rgb_color_c( 0x000000 ) ),
t_( base, rgb_color_c( 0x333333 ), rgb_color_c( 0x662900 ) ),
t_( base, rgb_color_c( 0x666666 ), rgb_color_c( 0xcc5200 ) ),
t_( base, rgb_color_c( 0x999999 ), rgb_color_c( 0xff8533 ) ),
t_( base, rgb_color_c( 0xcccccc ), rgb_color_c( 0xffc299 ) ),
t_( base, rgb_color_c( 0xffffff ), rgb_color_c( 0xffffff ) ),
t_( base, rgb_color_c( 0xff0000 ), rgb_color_c( 0xff0000 ) ),
t_( base, rgb_color_c( 0x00ff00 ), rgb_color_c( 0x00ff00 ) ),
t_( base, rgb_color_c( 0x0000ff ), rgb_color_c( 0x0000ff ) )
);
for_each_c_( test const*, t, tests )
{
cColor hard = hardlight_color_c( t->a, t->b );
bool res = eq_color_c( hard, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
difference_color_c
cColor difference_color_c( cColor color, cColor other );
Subtracts the second color from the first color on a channel-by-channel basis. Negative values are inverted. Subtracting black results in no change; subtracting white results in color inversion.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor a;
cColor b;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
cColor base = rgb_color_c( 0xff6600 );
testSlice tests = slice_c_( test,
t_( base, rgb_color_c( 0x000000 ), rgb_color_c( 0xff6600 ) ),
t_( base, rgb_color_c( 0x333333 ), rgb_color_c( 0xcc3333 ) ),
t_( base, rgb_color_c( 0x666666 ), rgb_color_c( 0x990066 ) ),
t_( base, rgb_color_c( 0x999999 ), rgb_color_c( 0x663399 ) ),
t_( base, rgb_color_c( 0xcccccc ), rgb_color_c( 0x3366cc ) ),
t_( base, rgb_color_c( 0xffffff ), rgb_color_c( 0x0099ff ) ),
t_( base, rgb_color_c( 0xff0000 ), rgb_color_c( 0x006600 ) ),
t_( base, rgb_color_c( 0x00ff00 ), rgb_color_c( 0xff9900 ) ),
t_( base, rgb_color_c( 0x0000ff ), rgb_color_c( 0xff66ff ) )
);
for_each_c_( test const*, t, tests )
{
cColor diff = difference_color_c( t->a, t->b );
bool res = eq_color_c( diff, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
exclusion_color_c
cColor exclusion_color_c( cColor color, cColor other );
A similar effect to difference with lower contrast.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor a;
cColor b;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
cColor base = rgb_color_c( 0xff6600 );
testSlice tests = slice_c_( test,
t_( base, rgb_color_c( 0x000000 ), rgb_color_c( 0xff6600 ) ),
t_( base, rgb_color_c( 0x333333 ), rgb_color_c( 0xcc7033 ) ),
t_( base, rgb_color_c( 0x666666 ), rgb_color_c( 0x997a66 ) ),
t_( base, rgb_color_c( 0x999999 ), rgb_color_c( 0x668599 ) ),
t_( base, rgb_color_c( 0xcccccc ), rgb_color_c( 0x338fcc ) ),
t_( base, rgb_color_c( 0xffffff ), rgb_color_c( 0x0099ff ) ),
t_( base, rgb_color_c( 0xff0000 ), rgb_color_c( 0x006600 ) ),
t_( base, rgb_color_c( 0x00ff00 ), rgb_color_c( 0xff9900 ) ),
t_( base, rgb_color_c( 0x0000ff ), rgb_color_c( 0xff66ff ) )
);
for_each_c_( test const*, t, tests )
{
cColor excl = exclusion_color_c( t->a, t->b );
bool res = eq_color_c( excl, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
average_color_c
cColor average_color_c( cColor color, cColor other );
Compute the average of two colors on a per-channel (RGB) basis.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor a;
cColor b;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
cColor base = rgb_color_c( 0xff6600 );
testSlice tests = slice_c_( test,
t_( base, rgb_color_c( 0x000000 ), rgb_color_c( 0x803300 ) ),
t_( base, rgb_color_c( 0x333333 ), rgb_color_c( 0x994d1a ) ),
t_( base, rgb_color_c( 0x666666 ), rgb_color_c( 0xb36633 ) ),
t_( base, rgb_color_c( 0x999999 ), rgb_color_c( 0xcc804d ) ),
t_( base, rgb_color_c( 0xcccccc ), rgb_color_c( 0xe69966 ) ),
t_( base, rgb_color_c( 0xffffff ), rgb_color_c( 0xffb380 ) ),
t_( base, rgb_color_c( 0xff0000 ), rgb_color_c( 0xff3300 ) ),
t_( base, rgb_color_c( 0x00ff00 ), rgb_color_c( 0x80b300 ) ),
t_( base, rgb_color_c( 0x0000ff ), rgb_color_c( 0x803380 ) )
);
for_each_c_( test const*, t, tests )
{
cColor avg = average_color_c( t->a, t->b );
bool res = eq_color_c( avg, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
negation_color_c
cColor negation_color_c( cColor color, cColor other );
Do the opposite effect to difference.
#include "clingo/color/cColor.h"
#include "clingo/lang/expect.h"
TEMP_SLICE_C_(
test,
{
cColor color;
cColor other;
cColor exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
cColor base = rgb_color_c( 0xff6600 );
testSlice tests = slice_c_( test,
t_( base, rgb_color_c( 0x000000 ), rgb_color_c( 0xff6600 ) ),
t_( base, rgb_color_c( 0x333333 ), rgb_color_c( 0xcc9933 ) ),
t_( base, rgb_color_c( 0x666666 ), rgb_color_c( 0x99cc66 ) ),
t_( base, rgb_color_c( 0x999999 ), rgb_color_c( 0x66ff99 ) ),
t_( base, rgb_color_c( 0xcccccc ), rgb_color_c( 0x33cccc ) ),
t_( base, rgb_color_c( 0xffffff ), rgb_color_c( 0x0099ff ) ),
t_( base, rgb_color_c( 0xff0000 ), rgb_color_c( 0x006600 ) ),
t_( base, rgb_color_c( 0x00ff00 ), rgb_color_c( 0xff9900 ) ),
t_( base, rgb_color_c( 0x0000ff ), rgb_color_c( 0xff66ff ) )
);
for_each_c_( test const*, t, tests )
{
cColor neg = negation_color_c( t->color, t->other );
bool res = eq_color_c( neg, t->exp );
expect_c_( res );
}
return finish_tap_c_();
}
image
heap_var_color_image_c_
#define heap_var_color_image_c_( W, H )
Allocates the image data at the heap and assigns the memory to a new created color image.
get_color_pixel_c
cColor get_color_pixel_c( cColorImage image, cPixel pixel );
Gets the color of a pixel in a color image.
set_color_pixel_c
void set_color_pixel_c( cVarColorImage image, cPixel pixel, cColor color );
Sets the pixel in a color image.