COLOR(7)
π NAME π
okay bestie, welcome to the COLOR(7) page from the Miscellaneous Information Manual β¨ this one is all about how pixels and colors get represented, and it's honestly giving fixed-color-map main character energy.
color β representation of pixels and colors
π¨ DESCRIPTION π¨
so to address problems of consistency and portability among applications, Plan 9 uses a fixed color map, called rgbv, on 8-bit-per-pixel displays. this avoids the problems caused by multiplexing color maps between applications, but it requires that the color map chosen be suitable for most purposes and usable for all. other systems that use fixed color maps tend to sample the color cube uniformly, which has advantagesβmapping from a (red, green, blue) triple to the color map and back again is easyβbut it ignores an important property of the human visual system: eyes are much more sensitive to small changes in intensity than to changes in hue π sampling the color cube uniformly gives a color map with many different hues, but only a few shades of each. continuous tone images converted into such maps demonstrate conspicuous artifacts.
rather than dice the color cube into subregions of size 6Γ6Γ6 (as in Netscape Navigator) or 8Γ8Γ4 (as in previous releases of Plan 9), picking 1 color in each, the rgbv color map uses a 4Γ4Γ4 subdivision, with 4 shades in each subcube. the idea is to reduce the color resolution by dicing the color cube into fewer cells, and to use the extra space to increase the intensity resolution. this results in 16 grey shades (4 grey subcubes with 4 samples in each), 13 shades of each primary and secondary color (3 subcubes with 4 samples plus black) and a reasonable selection of colors covering the rest of the color cube. the advantage is better representation of continuous tones π
the following function computes the 256 3-byte entries in the color map:
void
setmaprgbv(uchar cmap[256][3])
{
uchar *c;
int r, g, b, v;
int num, den;
int i, j;
for(r=0,i=0; r!=4; r++)
for(v=0; v!=4; v++,i+=16)
for(g=0,j=v-r; g!=4; g++)
for(b=0; b!=4; b++,j++){
c = cmap[i+(j&15)];
den = r;
if(g > den)
den = g;
if(b > den)
den = b;
if(den == 0) /* would divide check; pick grey shades */
c[0] = c[1] = c[2] = 17*v;
else{
num = 17*(4*den+v);
c[0] = r*num/den;
c[1] = g*num/den;
c[2] = b*num/den;
}
}
}
there are 4 nested loops to pick the (red,green,blue) coordinates of the subcube, and the value (intensity) within the subcube, indexed by r, g, b, and v, whence the name rgbv. the peculiar order in which the color map is indexed is designed to distribute the grey shades uniformly through the mapβthe i'th grey shade, 0<=i<=15, has index iΓ17, with black going to 0 and white to 255. therefore, when a call to draw converts a 1, 2 or 4 bit-per-pixel picture to 8 bits per pixel (which it does by replicating the pixels' bits), the converted pixel values are the appropriate grey shades.
the rgbv map is not gamma-corrected, for two reasons. first, photographic film and television are both normally under-corrected, the former by an accident of physics and the latter by NTSC's design. second, we require extra color resolution at low intensities because of the non-linear response and adaptation of the human visual system. properly gamma-corrected displays with adequate low-intensity resolution pack the high-intensity parts of the color cube with colors whose differences are almost imperceptible. either reason suggests concentrating the available intensities at the low end of the range.
on true-color displays with separate values for the red, green, and blue components of a pixel, the values are chosen so 0 represents no intensity (black) and the maximum value (255 for an 8-bit-per-color display) represents full intensity (e.g., full red). common display depths are 24 bits per pixel, with 8 bits per color in order red, green, blue, and 16 bits per pixel, with 5 bits of red, 6 bits of green, and 5 bits of blue.
colors may also be created with an opacity factor called alpha, which is scaled so 0 represents fully transparent and 255 represents opaque color. the alpha is premultiplied into the other channels, as described in the paper by Porter and Duff cited in draw(3). the function setalpha (see allocimage(3)) aids the initialization of color values with non-trivial alpha.
the packing of pixels into bytes and words is odd. for compatibility with VGA frame buffers, the bits within a pixel byte are in big-endian order (leftmost pixel is most significant bits in byte), while bytes within a pixel are packed in little-endian order. pixels are stored in contiguous bytes. this results in unintuitive pixel formats. for example, for the RGB24 format, the byte ordering is blue, green, red.
to maintain a constant external representation, the draw(3) interface as well as the various graphics libraries represent colors by 32-bit numbers, as described in color(3).
π SEE ALSO π
that's the whole COLOR(7) page from the Miscellaneous Information Manual, bestie π«Ά the footer just repeats COLOR(7) againβno extra version/date teaβso go forth and make those pixels iconic π
β¨
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms