HP Visualize J5000 hp workstations - hp-ux 10.20 graphics administration guide - Page 53

RedValue, BlueValue, Xp, Yp, Y Pixel Address MOD 2

Page 53 highlights

A pixel to be dithered is sent to the routine provided in this example. 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 0..255. 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 three bits of red and green and two bits of blue. The quantized results are packed into an 8-bit unsigned char and then stored in the frame buffer. In the process of sending the contents of the frame buffer to the CRT, a special section in the hardware then converts the frame buffer's 8-bit data into 24-bit TrueColor data 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, GreenValue, BlueValue, 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; /* Determine the dither table entries to use based on the pixel address */ x_dither_table = Xp % 16; /* X Pixel Address MOD 16 */ y_dither_table = Yp % 2; /* Y Pixel Address MOD 2 */ /* Start with the initial values as supplied by the calling routine */ red = RedValue; green = GreenValue; blue = BlueValue; /* Generate the red dither value */ red += dither_red[y_dither_table][x_dither_table]; /* Check for overflow or underflow on red value */ if (red > 0xff) red = 0xff; if (red < 0x00) red = 0x00; /* Generate the green dither value */ green += dither_green[y_dither_table][x_dither_table]; Page 53 Graphics Administration Guide for HP-UX 10.20

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171

A pixel to be dithered is sent to the routine provided in this example. 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 0..255.
The given routine receives the color values and the X and Y window address (X
p
and Y
p
) 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 three bits of red and
green and two bits of blue. The quantized results are packed into an 8-bit unsigned char and then stored
in the frame buffer. In the process of sending the contents of the frame buffer to the CRT, a special
section in the hardware then converts the frame buffer's 8-bit data into 24-bit TrueColor data 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, GreenValue, BlueValue, 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;
/* Determine the dither table entries to use based on the pixel address */
x_dither_table = Xp % 16;
/* X Pixel Address MOD 16 */
y_dither_table = Yp % 2;
/* Y Pixel Address MOD 2 */
/* Start with the initial values as supplied by the calling routine */
red
= RedValue;
green = GreenValue;
blue
= BlueValue;
/* Generate the red dither value */
red += dither_red[y_dither_table][x_dither_table];
/* Check for overflow or underflow on red value */
if (red > 0xff) red = 0xff;
if (red < 0x00) red = 0x00;
/* Generate the green dither value */
green += dither_green[y_dither_table][x_dither_table];
Graphics Administration Guide for HP-UX 10.20
Page 53