getpixel(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸ’– getpixel(3) πŸ’–

okay bestie, welcome to the Allegro manual β€” yes, the game programming library, we're being ✨productive✨ today. this one's a lil function called getpixel and she is so simple it's almost suspicious. let's go πŸ¦‹


🌸 NAME 🌸

getpixel β€” reads a pixel from a bitmap. that's it. that's the whole job. Allegro game programming library behavior, no cap πŸ’…


✨ SYNOPSIS ✨

#include <allegro.h>

int getpixel(BITMAP *bmp, int x, int y);

πŸŽ€ DESCRIPTION πŸŽ€

so you give her a point (x, y) and she reads the pixel right there in the bitmap. that's the vibe. one point, one pixel, done. 🌈


πŸ‘‘ RETURN VALUE πŸ‘‘

she hands you back the value of that pixel β€” in the color format of the bitmap, so like, whatever format that bitmap speaks, that's what you get back. 🫢

but if the point lies outside the bitmap (and heads up, she's ignoring the clipping rectangle here, so it's about the actual bitmap bounds), you get -1. periodt.

⚠️ WARNING, and this one's important bestie, don't skip it: -1 is also a totally valid pixel value for pixels in 32-bit bitmaps with an alpha channel β€” specifically when R,G,B,A are all equal to 255. so you literally cannot use "is it -1?" as a test for whether you're inside the bitmap when you're dealing with those. it will lie to you. it will betray you. πŸ’€
the only reliable predicate in those cases is is_inside_bitmap(). use her. trust her. she's the main character here. πŸ‘‘

and if you wanna pull the individual color components out of that pixel value, that's the getr() / getg() / getb() / geta() family of functions. they're the girlies for that job. 🧚


πŸ’œ SEE ALSO πŸ’œ


and that's the whole page, bestie!! πŸ“ this lil gem came to you courtesy of Allegro, version 4.4.3 β€” go read a pixel, or don't, either way you understood the assignment. mwah πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from