chapter1_color
Download
Report
Transcript chapter1_color
Color
• Color is one of the most interesting aspects of both
human perception and computer graphics.
• In principle, a display needs only three primary colors to
produce any color needed for a human observer.
• We vary the intensity of each primary to produce a color.
• We can look at how color is handled in a graphics system
from the programmer’s perspective-that is, through the
API.
• There are two different approaches.
1
RGB and Indexed color models
• We will stress the RGB-color model because
an understanding of it will be crucial for our
later discussion of shading.
• Historically, the indexed-color model was
easier to support in hardware because of its
lower memory requirements and the limited
colors available on displays, but in modern
systems RGB color has become the norm.
2
RGB color
• Each color component is stored separately in the frame
buffer
• Usually 8 bits per component in buffer
• Note in glColor3f the color values range from 0. 0 (none)
to 1. 0 (all), whereas in glColor3ub the values range
from0 to 255
3
Indexed Color
• Colors are indices into tables of RGB values
• Requires less memory
– indices usually 8 bits
– not as important now
• Memory inexpensive
• Need more colors for shading
4
RGB color
• Any color can be constructed by "adding" certain amounts of 3
primary colors.
• C = rR + gG + bB
where r, g and b indicate the "amounts" of each primary color.
• Many images have a color depth of eight. Each pixel then has one of
256 possible colors.
• A 24 bit system, True-Color systems are common. Each color
component given 8 bits
5
Example Color Depth=6
Assuming Color Depth = 6 bits
• Thus, the composite dot can be made to glow in a total of 22 X 22 X 22 =64
different colors.
• Some systems have a frame buffer that supports 24 bits color depth. Each of
the DACs has eight input bits, so there are 256 levels of red, 256 of green,
and 256 of blue, for a total of 16 million colors.
• The CRT image must be refreshed rapidly (typically, 60 times a second) to
prevent disturbing flicker.
• There are monochrome video displays, which display a single color in
different intensities. A single DAC converts pixel values in the frame buffer to
voltage levels, which drive a single electron-beam gun. The CRT has only
one type of phosphor, so it can produce various intensities of only one color.
• Note that 6 bits in the frame buffer for monochrome video displays 26 = 64
levels of gray.
6
Indexed Color
•
•
•
The 6 bits stored in each pixel. These bits are used as an index into a table of 64
values, say, LUT [ 0 ] ... LUT [63]. For instance, if a pixel value is 39, the values stored
in LUT [39] are used to drive the DACs. As shown in the figure, LUT [39] contains the
15-bit value 01010 11001 10010
Five of these bits (01010) are routed to drive the "red DAC," 5 others drive the
"green DAC," and the last 5 drive the "blue DAC."
Each of the LUT [ ] entries can be set under program control. For example, the
instruction setPalette(39, 17, 25, 4) ; would set the value in LUT[39] to the 15-bit
quantity 1000111001 00100 (since 17 is 10001 in binary, 25 is 11001, and 4 is
00100).
7
Example
• Set the pixel at x =479 and y=532 with value 39
drawDot(479, 532, 39) ;
• Each time the frame buffer is "scanned out" to the display, this pixel is
read as the value 39, which causes the value stored in LUT[39] to be sent
to the DACs.
• How many possible color could be used in the system of Figure 1.40?
• In the system of Figure 1.40, each entry of the LUT consists of 15 bits, so
each color can be set to one of 215 = 32K = 32,768 possible colors.
• The set of 215 possible colors that the system is capable of displaying is
called its palette, so we say that this display "has a palette of 32K
colors."
• Therefore, this system can display a maximum of 26 = 64 different colors
at one time selected from 215 = 32K = 32,768 possible colors
8
LookUp Table
• The contents of the LUT are not changed in the middle of a
scan-out of the image, so one whole scan-out uses a fixed set
of 26 = 64 palette colors.
• Usually, the contents of the LUT remain fixed for many scan
outs, although a program can change the contents of a small
LUT between two successive scan-outs.
9
General color depth
• In more general terms, suppose that a raster
display system has a color depth of b bits and
that each LUT entry is w bits wide.
• Then the system can display 2w colors, any 2b at
one time.
10
Examples
• A system with b = 8 bit planes and an LUT
width w = 12 can display 4096 colors, any
256 of them at a time.
• A system with b = 8 bit planes and an LUT
width w = 24 can display 224 = 16,777, 216
colors, any 256 at a time.
• If b = 12 and w = 18, the system can display
256K = 262,144 colors, 4,096 at a time
11
Compare the costs
• To compare the costs of two systems:
one with a LUT (pseudo color system) and
one without a LUT (true color system)
• Figure 1. 41 shows an example of two l,024-byl,280-pixel displays (so that each of them
supports about 1.3 million pixels).
• Both systems allow colors to be defined with a
precision of 24 bits, often called "true color."
12
Compare the costs
13