READCOLMAP(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

πŸ’… READCOLMAP(3) β€” the one where we access the display color map

okay bestie, so this is a page from the Library Functions Manual and it's all about RGB, readcolmap, and writecolmap β€” aka how you get your hands on a display's color map. it's giving very old-school graphics energy and honestly? iconic. ✨

🌈 SYNOPSIS

#include <u.h>
#include <libc.h>
#include <draw.h>

int  readcolmap(Display *d, RGB *map)

int  writecolmap(Display *d, RGB *map)

πŸ’– DESCRIPTION

so first things first, bestie: colors get described by their red, green, and blue light intensities, all cozy inside an RGB datum. it looks like this:

typedef
struct RGB {
      ulong red;
      ulong green;
      ulong blue;
} RGB;

now the vibe check: black is literally zero in all three positions πŸ–€, and white is the maximum unsigned long value in all three positions 🀍. no in-between drama, just full send.

a color map is an array of RGBs, of length 2^depth, and it gives you the colors for pixels 0, 1, 2, etc. πŸ“‹ so on displays with color mapped pixels (typically 8-bit displays β€” yes, the vintage ones 🧚), you retrieve RGB color information by treating the pixel data as an offset into the color map. that's it, that's the whole trick, iykyk. πŸŽ€

  • readcolmap β€” reads the color map for the given display into the provided map, which must have enough space to hold it. don't be out here handing it a tiny buffer, it will not slay. πŸ™ˆ
  • writecolmap β€” associates the given color map with the given display, if possible. (the hardware might not allow this β€” lowkey rude of it, but okay. πŸ’€)

both of them return 0 on success, or -1 on error, setting errstr. so check your return values, bestie, fr fr. 🫢

⚠️ the big caveat, do not skip this one: changing the hardware color map does not change the color map used by the draw(3) operator to convert between mapped and true color or greyscale images. that one is described in color(7). two different color maps, two different vibes, keep them straight. 🌸 ⭐

πŸ”₯ SOURCE

/src/libdraw


πŸ‘€ SEE ALSO


and that's the page!! πŸ¦‹ mwah πŸ’‹

signing off from the Library Functions Manual β€” this one's READCOLMAP(3), straight outta /src/libdraw πŸ‘‘πŸ’œ