# rgbv - color map

## Description

To solve problems of consistency and portability among Inferno applications, Inferno uses a fixed color map, called rgbv, on 8-bit-per-pixel displays. Although this avoids problems caused by multiplexing color maps between applications, it requires that the color map chosen be suitable for most purposes and usable for all.

```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[255-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 order in which the color map is indexed distributes the grey shades uniformly through map-the i'th grey shade, has index with white going to 0 and black to 255. When a call to draw converts a 1, 2 or 4 bit-per-pixel picture to 8 bits per pixel by replicating the pixels' bits, the converted pixel values are the appropriate grey shades.