Skip to main content

Module pixel

Module pixel 

Source
Expand description

Per-pixel reads and writes into raw byte buffers in a given PixelFormat.

These wrap raylib’s GetPixelColor / SetPixelColor C functions and are the right tools when you have a byte buffer (e.g. one you’re about to upload to a Texture2D, or a CPU framebuffer you generated yourself) and want to read or write a single pixel value while staying format-aware.

If you instead have an Image and want the pixel at coordinates (x, y), use Image::get_color — that goes through raylib’s separate GetImageColor C function and handles the row stride for you.

§BGRA limitation

raylib’s PixelFormat enum has no B8G8R8A8 variant. The rlsw software-renderer test harness stores its framebuffer as BGRA bytes while labeling them with PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, and the channel swap is expressed as a bespoke byte-swap loop in raylib::test_harness::normalize_readback. These functions cannot eliminate that loop — feeding them BGRA bytes labeled as R8G8B8A8 returns a Color with R and B swapped, which is the same problem.

Enums§

PixelColorError
Errors returned by get_pixel_color / set_pixel_color.

Functions§

bytes_per_pixel
Bytes per single pixel for an uncompressed PixelFormat.
get_pixel_color
Read a single pixel from bytes interpreted as format.
set_pixel_color
Write color into bytes encoded as format.