Blame


1 058b0118 2005-01-03 devnull .TH COLOR 7
2 058b0118 2005-01-03 devnull .SH NAME
3 058b0118 2005-01-03 devnull color \- representation of pixels and colors
4 058b0118 2005-01-03 devnull .SH DESCRIPTION
5 058b0118 2005-01-03 devnull To address problems of consistency and portability among applications,
6 058b0118 2005-01-03 devnull Plan 9 uses a fixed color map, called
7 058b0118 2005-01-03 devnull .BR rgbv ,
8 058b0118 2005-01-03 devnull on 8-bit-per-pixel displays.
9 058b0118 2005-01-03 devnull Although this avoids problems caused by multiplexing color maps between
10 058b0118 2005-01-03 devnull applications, it requires that the color map chosen be suitable for most purposes
11 058b0118 2005-01-03 devnull and usable for all.
12 058b0118 2005-01-03 devnull Other systems that use fixed color maps tend to sample the color cube
13 058b0118 2005-01-03 devnull uniformly, which has advantages\(emmapping from a (red, green, blue) triple
14 058b0118 2005-01-03 devnull to the color map and back again is easy\(embut ignores an important property
15 058b0118 2005-01-03 devnull of the human visual system: eyes are
16 058b0118 2005-01-03 devnull much more sensitive to small changes in intensity than
17 058b0118 2005-01-03 devnull to changes in hue.
18 058b0118 2005-01-03 devnull Sampling the color cube uniformly gives a color map with many different
19 058b0118 2005-01-03 devnull hues, but only a few shades of each.
20 058b0118 2005-01-03 devnull Continuous tone images converted into such maps demonstrate conspicuous
21 058b0118 2005-01-03 devnull artifacts.
22 058b0118 2005-01-03 devnull .PP
23 058b0118 2005-01-03 devnull Rather than dice the color cube into subregions of
24 058b0118 2005-01-03 devnull size 6\(mu6\(mu6 (as in Netscape Navigator) or 8\(mu8\(mu4
25 058b0118 2005-01-03 devnull (as in previous releases of Plan 9), picking 1 color in each,
26 058b0118 2005-01-03 devnull the
27 058b0118 2005-01-03 devnull .B rgbv
28 058b0118 2005-01-03 devnull color map uses a 4\(mu4\(mu4 subdivision, with
29 058b0118 2005-01-03 devnull 4 shades in each subcube.
30 058b0118 2005-01-03 devnull The idea is to reduce the color resolution by dicing
31 058b0118 2005-01-03 devnull the color cube into fewer cells, and to use the extra space to increase the intensity
32 058b0118 2005-01-03 devnull resolution.
33 058b0118 2005-01-03 devnull This results in 16 grey shades (4 grey subcubes with
34 058b0118 2005-01-03 devnull 4 samples in each), 13 shades of each primary and secondary color (3 subcubes
35 058b0118 2005-01-03 devnull with 4 samples plus black) and a reasonable selection of colors covering the
36 058b0118 2005-01-03 devnull rest of the color cube.
37 058b0118 2005-01-03 devnull The advantage is better representation of
38 058b0118 2005-01-03 devnull continuous tones.
39 058b0118 2005-01-03 devnull .PP
40 058b0118 2005-01-03 devnull The following function computes the 256 3-byte entries in the color map:
41 058b0118 2005-01-03 devnull .IP
42 058b0118 2005-01-03 devnull .EX
43 058b0118 2005-01-03 devnull .ta 6n +6n +6n +6n
44 058b0118 2005-01-03 devnull void
45 058b0118 2005-01-03 devnull setmaprgbv(uchar cmap[256][3])
46 058b0118 2005-01-03 devnull {
47 058b0118 2005-01-03 devnull uchar *c;
48 058b0118 2005-01-03 devnull int r, g, b, v;
49 058b0118 2005-01-03 devnull int num, den;
50 058b0118 2005-01-03 devnull int i, j;
51 058b0118 2005-01-03 devnull
52 058b0118 2005-01-03 devnull for(r=0,i=0; r!=4; r++)
53 058b0118 2005-01-03 devnull for(v=0; v!=4; v++,i+=16)
54 058b0118 2005-01-03 devnull for(g=0,j=v-r; g!=4; g++)
55 058b0118 2005-01-03 devnull for(b=0; b!=4; b++,j++){
56 058b0118 2005-01-03 devnull c = cmap[i+(j&15)];
57 058b0118 2005-01-03 devnull den = r;
58 058b0118 2005-01-03 devnull if(g > den)
59 058b0118 2005-01-03 devnull den = g;
60 058b0118 2005-01-03 devnull if(b > den)
61 058b0118 2005-01-03 devnull den = b;
62 058b0118 2005-01-03 devnull if(den == 0) /* would divide check; pick grey shades */
63 058b0118 2005-01-03 devnull c[0] = c[1] = c[2] = 17*v;
64 058b0118 2005-01-03 devnull else{
65 058b0118 2005-01-03 devnull num = 17*(4*den+v);
66 058b0118 2005-01-03 devnull c[0] = r*num/den;
67 058b0118 2005-01-03 devnull c[1] = g*num/den;
68 058b0118 2005-01-03 devnull c[2] = b*num/den;
69 058b0118 2005-01-03 devnull }
70 058b0118 2005-01-03 devnull }
71 058b0118 2005-01-03 devnull }
72 058b0118 2005-01-03 devnull .EE
73 058b0118 2005-01-03 devnull .PP
74 058b0118 2005-01-03 devnull There are 4 nested loops to pick the (red,green,blue) coordinates of the subcube,
75 058b0118 2005-01-03 devnull and the value (intensity) within the subcube, indexed by
76 058b0118 2005-01-03 devnull .BR r ,
77 058b0118 2005-01-03 devnull .BR g ,
78 058b0118 2005-01-03 devnull .BR b ,
79 058b0118 2005-01-03 devnull and
80 058b0118 2005-01-03 devnull .BR v ,
81 058b0118 2005-01-03 devnull whence
82 058b0118 2005-01-03 devnull the name
83 058b0118 2005-01-03 devnull .IR rgbv .
84 058b0118 2005-01-03 devnull The peculiar order in which the color map is indexed is designed to distribute the
85 058b0118 2005-01-03 devnull grey shades uniformly through the map\(emthe
86 058b0118 2005-01-03 devnull .IR i 'th
87 058b0118 2005-01-03 devnull grey shade,
88 058b0118 2005-01-03 devnull .RI 0<= i <=15
89 058b0118 2005-01-03 devnull has index
90 058b0118 2005-01-03 devnull .IR i ×17,
91 058b0118 2005-01-03 devnull with black going to 0 and white to 255.
92 058b0118 2005-01-03 devnull Therefore, when a call to
93 058b0118 2005-01-03 devnull .B draw
94 058b0118 2005-01-03 devnull converts a 1, 2 or 4 bit-per-pixel picture to 8 bits per pixel (which it does
95 058b0118 2005-01-03 devnull by replicating the pixels' bits), the converted pixel values are the appropriate
96 058b0118 2005-01-03 devnull grey shades.
97 058b0118 2005-01-03 devnull .PP
98 058b0118 2005-01-03 devnull The
99 058b0118 2005-01-03 devnull .B rgbv
100 058b0118 2005-01-03 devnull map is not gamma-corrected, for two reasons. First, photographic
101 058b0118 2005-01-03 devnull film and television are both normally under-corrected, the former by an
102 058b0118 2005-01-03 devnull accident of physics and the latter by NTSC's design.
103 058b0118 2005-01-03 devnull Second, we require extra color resolution at low intensities because of the
104 058b0118 2005-01-03 devnull non-linear response and adaptation of the human visual system.
105 058b0118 2005-01-03 devnull Properly
106 058b0118 2005-01-03 devnull gamma-corrected displays with adequate low-intensity resolution pack the
107 058b0118 2005-01-03 devnull high-intensity parts of the color cube with colors whose differences are
108 058b0118 2005-01-03 devnull almost imperceptible.
109 058b0118 2005-01-03 devnull Either reason suggests concentrating
110 058b0118 2005-01-03 devnull the available intensities at the low end of the range.
111 058b0118 2005-01-03 devnull .PP
112 058b0118 2005-01-03 devnull On `true-color' displays with separate values for the red, green, and blue
113 058b0118 2005-01-03 devnull components of a pixel, the values are chosen so 0 represents no intensity (black) and the
114 058b0118 2005-01-03 devnull maximum value (255 for an 8-bit-per-color display) represents full intensity (e.g., full red).
115 058b0118 2005-01-03 devnull Common display depths are 24 bits per pixel, with 8 bits per color in order
116 058b0118 2005-01-03 devnull red, green, blue, and 16 bits per pixel, with 5 bits of red, 6 bits of green, and 5 bits of blue.
117 058b0118 2005-01-03 devnull .PP
118 058b0118 2005-01-03 devnull Colors may also be created with an opacity factor called
119 058b0118 2005-01-03 devnull .BR alpha ,
120 058b0118 2005-01-03 devnull which is scaled so 0 represents fully transparent and 255 represents opaque color.
121 058b0118 2005-01-03 devnull The alpha is
122 058b0118 2005-01-03 devnull .I premultiplied
123 058b0118 2005-01-03 devnull into the other channels, as described in the paper by Porter and Duff cited in
124 d32deab1 2020-08-16 rsc .MR draw (3) .
125 058b0118 2005-01-03 devnull The function
126 058b0118 2005-01-03 devnull .B setalpha
127 058b0118 2005-01-03 devnull (see
128 d32deab1 2020-08-16 rsc .MR allocimage (3) )
129 058b0118 2005-01-03 devnull aids the initialization of color values with non-trivial alpha.
130 058b0118 2005-01-03 devnull .PP
131 058b0118 2005-01-03 devnull The packing of pixels into bytes and words is odd.
132 058b0118 2005-01-03 devnull For compatibility with VGA frame buffers, the bits within a
133 058b0118 2005-01-03 devnull pixel byte are in big-endian order (leftmost pixel is most
134 058b0118 2005-01-03 devnull significant bits in byte), while bytes within a pixel are packed in little-endian
135 058b0118 2005-01-03 devnull order. Pixels are stored in contiguous bytes. This results
136 058b0118 2005-01-03 devnull in unintuitive pixel formats. For example, for the RGB24 format,
137 058b0118 2005-01-03 devnull the byte ordering is blue, green, red.
138 058b0118 2005-01-03 devnull .PP
139 058b0118 2005-01-03 devnull To maintain a constant external representation,
140 058b0118 2005-01-03 devnull the
141 d32deab1 2020-08-16 rsc .MR draw (3)
142 058b0118 2005-01-03 devnull interface
143 058b0118 2005-01-03 devnull as well as the
144 058b0118 2005-01-03 devnull various graphics libraries represent colors
145 058b0118 2005-01-03 devnull by 32-bit numbers, as described in
146 d32deab1 2020-08-16 rsc .MR color (3) .
147 058b0118 2005-01-03 devnull .SH "SEE ALSO"
148 d32deab1 2020-08-16 rsc .MR color (3) ,
149 d32deab1 2020-08-16 rsc .MR graphics (3) ,
150 d32deab1 2020-08-16 rsc .MR draw (3)