al_color_linear(3)

πŸ“¦
version 5.2.11.3 Β· 2 versions
, in arch rolling

πŸ’œ al_color_linear β€” the Allegro 5 API glow-up

okay bestie, so this one lives in the Allegro 5 API and it's genuinely such a slay little function. It's the one that lets you hand over linear sRGB values and get a real ALLEGRO_COLOR(3) back. ✨


🌈 SYNOPSIS

#include <allegro5/allegro_color.h>

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

πŸŽ€ DESCRIPTION

So al_color_linear returns an ALLEGRO_COLOR(3) structure built from linear sRGB values. πŸ’…

Here's the lore: Allegro RGB values are assumed to be sRGB, and sRGB is literally everywhere β€” it's in wide use by all kinds of display devices. What makes sRGB special is that it accounts for a standard gamma correction that gets applied to RGB colors before they ever show up on your screen. no cap. πŸ¦‹

And gamma correction means... okay imagine this: say you've got a medium gray color specified with al_map_rgb_f(0.5,0.5,0.5). You do not want your monitor to set that pixel to exactly half the physical maximum intensity. That would be lowkey a lie to your eyes 😭 β€” instead you want an intensity that appears half as bright as the maximum to the person looking at it. In this case, that's closer to 21% of maximum intensity rather than to 50% intensity. The way math is humbling us fr fr.

For some applications it may be useful to specify a color in linear sRGB components β€” and that's exactly when you reach for 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"

iconic. it ate. πŸ‘‘


⭐ SINCE

5.2.8 β€” a vintage, your honor. πŸŽ€


🌸 SEE ALSO

the little conversion besties, go say hi πŸ’–


Allegro reference manual β€” that's the whole vibe check for this page, and it's brought to you by the Allegro reference manual itself. mwah πŸ’‹βœ¨πŸ§š

πŸ“¦ where this page comes from
  • arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms