colourpicker

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

Commit: 1f2b48877b7accb8b4eb015c036e57a451b691b2
Parent: 6aaf10c79a900549065125f4044cd07bed9f8549
Author: Randy Palamar
Date:   Mon, 29 Jul 2024 22:28:03 -0600

drop last sscanf usage

Diffstat:
Mcolourpicker.c | 3+--
Mmain.c | 17+++++------------
Mutil.c | 6++++++
3 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/colourpicker.c b/colourpicker.c @@ -249,8 +249,7 @@ parse_and_store_text_input(ColourPickerCtx *ctx) } else { new_mode = ctx->colour_mode; new_colour = ctx->colour; - f32 fv; - sscanf(ctx->is.buf, "%f", &fv); + f32 fv = parse_f32(ctx->is.buf); CLAMP01(fv); switch(ctx->is.idx) { case INPUT_R: new_colour.r = fv; break; diff --git a/main.c b/main.c @@ -76,13 +76,6 @@ usage(char *argv0) exit(1); } -static f32 -parse_f32(char *s) -{ - f32 res = atof(s); - return CLAMP01(res); -} - int main(i32 argc, char *argv[]) { @@ -136,11 +129,11 @@ main(i32 argc, char *argv[]) rgb = normalize_colour(parse_hex_u32(argv[i + 1])); ctx.colour = rgb_to_hsv(rgb); break; - case 'r': rgb.r = parse_f32(argv[i + 1]); break; - case 'g': rgb.g = parse_f32(argv[i + 1]); break; - case 'b': rgb.b = parse_f32(argv[i + 1]); break; - case 'a': rgb.a = parse_f32(argv[i + 1]); break; - default: usage(argv[0]); break; + case 'r': rgb.r = parse_f32(argv[i + 1]); CLAMP01(rgb.r); break; + case 'g': rgb.g = parse_f32(argv[i + 1]); CLAMP01(rgb.g); break; + case 'b': rgb.b = parse_f32(argv[i + 1]); CLAMP01(rgb.b); break; + case 'a': rgb.a = parse_f32(argv[i + 1]); CLAMP01(rgb.a); break; + default: usage(argv[0]); break; } i++; } else { diff --git a/util.c b/util.c @@ -307,4 +307,10 @@ parse_hex_u32(char *s) return res; } +static f32 +parse_f32(char *s) +{ + return atof(s); +} + #endif /* _UTIL_C_ */