getr_depth(3alleg4)

πŸ’– getr_depth β€” okay bestie, let's talk color components πŸ’–

So this is getr_depth(3alleg4) from the Allegro manual, and it's honestly such a helpful little squad of functions. Allegro game programming library, if you didn't know. πŸŽ€


✨ NAME ✨

getr_depth, getg_depth, getb_depth, geta_depth β€” extract a color component from a color in a specified pixel format. Allegro game programming library. πŸ¦‹


🌸 SYNOPSIS 🌸

#include <allegro.h>

int getr_depth(int color_depth, int c);

int getg_depth(int color_depth, int c);

int getb_depth(int color_depth, int c);

int geta_depth(int color_depth, int c);

πŸ‘‘ DESCRIPTION πŸ‘‘

Okay so here's the vibe: you hand these functions a color that's in the format being used by the color depth you specify, and they pull out one of the components β€” red, green, blue, or alpha β€” ranging 0-255. That's it, that's the whole job, and they do it flawlessly. πŸ’…

Heads up bestie: the alpha part is only meaningful for 32-bit pixels. For anything less, don't come for alpha, she's not there. 😭

And here's an example, because of course there's an example, we love a demo: ✨

int r, g, b, color_value, bpp;

bpp = bitmap_color_depth(bitmap);
color_value = getpixel(bitmap, 100, 100);
r = getr_depth(bpp, color_value);
g = getg_depth(bpp, color_value);
b = getb_depth(bpp, color_value);

Look at that. Grab the depth, grab the pixel, split it into her components. Main character energy fr fr. 🌈


🫢 SEE ALSO 🫢


Allegro, version 4.4.3 β€” that's the whole page, bestie, you ate it up. Go forth and extract those components. Not me being obsessed with a manpage. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«ΆπŸ˜­πŸ”₯πŸ‘‘πŸŒˆβ­πŸ’€πŸ™ˆπŸ“πŸ§šπŸ’œ