 |
» |
|
|
 |
 |  |  |  |  | NOTE: The algorithm discussed in this section, for the Internal
Color Graphics device, is different than the algorithm discussed
for the HCRX family of graphics devices in the section "Accessing
HP Color Recovery with X Windows" found in Chapter 3 “The HCRX Family of Device Drivers”. |  |  |  |  |
The Starbase and HP-PHIGS graphics libraries provide programmers
who use these APIs with transparent access to the HP Color Recovery
capability of the Internal Color Graphics device. If you are producing
graphics using Xlib calls, then your application must perform some
of the necessary processing. At server start-up, there are two properties
that are defined and placed on the root window if the HP_DISABLE_COLOR_RECOVERY
environment variable has not been exported.
These properties are: _HP_RGB_SMOOTH_PSEUDO_MAP
The existence of these properties indicates that HP Color
Recovery is available on this display. These properties are of type
RGB_COLOR_MAP
and carry pointers to structures of type XStandardColormap. They may
be interrogated with calls to XGetRGBColormaps.
The color maps in these structures identify color maps which are
created at server start-up and are for use with the TrueColor and
PseudoColor visuals, respectively. They are both initialized to
contain the 3:3:2 ramp of 8-bit TrueColor. Neither of these color
maps can be modified as they are read-only. The use of the TrueColor
visual and the color map identified in _HP_RGB_SMOOTH_TRUE_MAP
will be assumed in the procedures outlined below. To use this capability through X windows, create a window
with the TrueColor visual and give it the color map attribute identified
in the property: HP Color Recovery will be enabled for all windows with this
color map. HP Color Recovery uses all 256 entries of one of the available
color maps. The color visual used by HP Color Recovery emulates
the 24-bit TrueColor visual, thus, the colors red, green, and blue
are typically declared as integers in the range from 0 to 255. Note
that each window that uses HP Color Recovery will use the same color
map. For HP Color Recovery to produce the best results, the emulated
24-bit TrueColor data is dithered as explained below. A pixel to be dithered is sent to the routine provided in
this example. Note that the values of the variables RedValue, GreenValue and BlueValue are generated by
an application. In this example, the color values are assumed to
be in the range The given routine receives the color values and the X and
Y window address (Xp
and Yp) of the
pixel. The X and Y address is used to access the dither tables.
The values from the dither tables are added to the color values.
After the dither addition, the resultant color values are quantized
to 3 bits of red and green and 2 bits of blue. The quantized results
are packed into an 8-bit unsigned
char and then stored in the frame buffer. As the
contents of the frame buffer are scanned to the CRT, a special section
in the Internal Color Graphics hardware then converts the 8-bit
data stored in the frame buffer into a 24-bit TrueColor image for
display. Here is a routine that can be used to dither the 24-bit TrueColor
data.  |
unsigned char dither_pixel_for_CR(RedValue,GreenValue,BlueValue,Xp,Yp) int RedValue,GreenValueBlueValue,Xp,Yp; { static short dither_red[2][16] = { {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8}, { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9} }; static short dither_green[2][16] = { { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1}, {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0} }; static short dither_blue[2][16] = { { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4}, { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5} }; int red, green, blue; int x_dither_table, y_dither_table; unsigned char pixel; x_dither_table = Xp % 16; /* X Pixel Address MOD 16 */ y_dither_table = Yp % 2; /* Y Pixel Address MOD 2 */ red = RedValue; green = GreenValue; blue = BlueValue; red += dither_red[y_dither_table][x_dither_table]; if (red > 0xff) red = 0xff; if (red < 0x00) red = 0x00; green += dither_green[y_dither_table][x_dither_table]; if (green > 0xff) green = 0xff; if (green < 0x00) green = 0x00; blue += (dither_blue[y_dither_table][x_dither_table]<<1); if (blue > 0xff) blue = 0xff; if (blue < 0x00) blue = 0x00; pixel = ((red &0xE0) | ((green &0xE0) >> 3) | ((blue &0xC0) >> 6)); return(pixel); } |
 |
|