al_color_linear(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 3 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ al_color_linear ✨

okay bestie, welcome to the Allegro 5 API manual, section 3alleg5 πŸ’– this one's all about al_color_linear, and ngl it's a lil glow-up for your colors.


🌸 NAME 🌸

al_color_linear β€” it's giving "make me a color from linear sRGB values" and honestly? slay.


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <allegro5/allegro_color.h>

ALLEGRO_COLOR al_color_linear(float r, float g, float b)

like yes, three lil floats going in, one ALLEGRO_COLOR coming out. iconic behavior πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

so basically, this function returns an ALLEGRO_COLOR(3alleg5) structure built from linear sRGB values. periodt.

here's the tea tho: Allegro RGB values are assumed to be sRGB. and the sRGB standard? it's everywhere, fr fr β€” all kinds of display devices use it. it accounts for a standard gamma correction that gets applied to RGB colors before they ever hit your screen. 🌈

and what does gamma correction even mean? okay so imagine we have a medium gray color, like al_map_rgb_f(0.5,0.5,0.5). we do NOT want the monitor to set that pixel to exactly half the physical maximum intensity. no no. we want an intensity that appears to be half as bright as the maximum β€” to the actual human eyeballs looking at it πŸ‘€βœ¨ in that case it'd be closer to 21% of maximum intensity rather than to 50% intensity. the math is mathing, trust.

so for some applications it may be useful to specify a color in linear sRGB components β€” and that's exactly when you'd use this function 🫢 for example:

ALLEGRO_COLOR gray = al_color_linear(0.216, 0.216, 0.216);
char html[8];
al_color_rgb_to_html(gray.r, gray.g, gray.b, html); // "#808080"

the way that produces #808080... obsessed, honestly. πŸ˜­πŸ’–


⭐ SINCE ⭐

5.2.8 β€” she's been here since 5.2.8 and she's been serving ever since πŸ‘‘


πŸ”₯ SEE ALSO πŸ”₯

go read those too bestie, they're the other half of the color pipeline πŸ§šπŸ’œ


lowkey a reminder: gamma correction is not a vibe you can just skip. it's baked into how sRGB works, so don't come for it.

and that's the whole page, no cap πŸ“ this was the Allegro reference manual entry for al_color_linear, section 3alleg5 β€” tysm for reading, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from