colourpicker

Simple Colour Picker written in C
git clone anongit@rnpnr.xyz:colourpicker.git
Log | Files | Refs | Feed | Submodules | README | LICENSE

Commit: acb7f1e748158f833cfbf89f76d72f54d0e969fc
Parent: bdbaa835692c37f6222ecadf7e3ebfb3d79c76f4
Author: Randy Palamar
Date:   Fri, 26 Jul 2024 22:52:42 -0600

move colour packing to a function

Diffstat:
Mcolourpicker.c | 3+--
Mmain.c | 4+---
Mutil.c | 6++++++
3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/colourpicker.c b/colourpicker.c @@ -496,8 +496,7 @@ do_colour_selector(ColourPickerCtx *ctx, Rect r) DrawRectangleRec(cs[0].rr, pcolour); DrawRectangleRec(cs[1].rr, colour); - u32 fg_packed_rgba = ctx->fg.r << 24 | ctx->fg.g << 16 | ctx->fg.b << 8 | ctx->fg.a << 0; - v4 fg = normalize_colour(fg_packed_rgba); + v4 fg = normalize_colour(pack_rl_colour(ctx->fg)); f32 scale = 5; v4 delta = scaled_sub_v4(fg, ctx->hover_colour, scale * ctx->dt); char *labels[2] = {"Revert", "Apply"}; diff --git a/main.c b/main.c @@ -200,9 +200,7 @@ main(i32 argc, char *argv[]) default: ASSERT(0); break; } - Color rl = colour_from_normalized(rgba); - u32 packed_rgba = rl.r << 24 | rl.g << 16 | rl.b << 8 | rl.a << 0; - + u32 packed_rgba = pack_rl_colour(colour_from_normalized(rgba)); printf("0x%08X|{.r = %0.03f, .g = %0.03f, .b = %0.03f, .a = %0.03f}\n", packed_rgba, rgba.r, rgba.g, rgba.b, rgba.a); diff --git a/util.c b/util.c @@ -195,4 +195,10 @@ normalize_colour(u32 rgba) }; } +static u32 +pack_rl_colour(Color colour) +{ + return colour.r << 24 | colour.g << 16 | colour.b << 8 | colour.a << 0; +} + #endif /* _UTIL_C_ */