getr(3alleg4)

πŸ’– getr, getg, getb, geta β€” the Allegro color-splitting girlies πŸ’–

okay bestie, so this is getr(3alleg4), straight out of the Allegro manual, and it's literally the four functions you need when you've got a packed color and you wanna know what's inside it. let's go ✨


✨ NAME ✨

getr, getg, getb, geta β€” pull one single color component out of whatever pixel format you're currently rocking. part of the Allegro game programming library, obviously πŸ’…


✨ SYNOPSIS ✨

#include <allegro.h>

int getr(int c);

int getg(int c);

int getb(int c);

int geta(int c);

✨ DESCRIPTION ✨

so here's the vibe: you hand these functions a color c that's already in the format your current video mode is using, and they hand you back one of the red, green, blue, or alpha components. the components range 0-255, bestie, so you get a nice full byte of range πŸŽ€

the way that works is that these are the smart ones β€” they peek at your current setup and call the preceding 8, 15, 16, 24, or 32-bit get functions as appropriate. so you don't gotta remember which depth you're in. iconic, honestly πŸ‘‘

⚠️ heads up: the alpha part is only meaningful for 32-bit pixels. don't come crying to me when geta gives you nonsense at other depths, i warned you πŸ’€

here's the example, verbatim, no notes:

int r, g, b, color_value;

color_value = getpixel(screen, 100, 100);
r = getr(color_value);
g = getg(color_value);
b = getb(color_value);

look at that. grab a pixel, crack it open, get your channels. main character energy fr fr 🌸


✨ SEE ALSO ✨


okay that's the whole page, you're welcome 🫢 this was Allegro, version 4.4.3 β€” go forth and extract your color components, bestie, you're gonna slay πŸ’–βœ¨πŸ¦‹