fix GL_BACK color material bug
[mesa.git] / src / mesa / drivers / windows / colors.h
1 /* File name : colors.h
2 * Version : 2.3
3 *
4 * Header file for display driver for Mesa 2.3 under
5 * Windows95 and WindowsNT
6 * This file defines macros and global variables needed
7 * for converting color format
8 *
9 * Copyright (C) 1996- Li Wei
10 * Address : Institute of Artificial Intelligence
11 * : & Robotics
12 * : Xi'an Jiaotong University
13 * Email : liwei@aiar.xjtu.edu.cn
14 * Web page : http://sun.aiar.xjtu.edu.cn
15 *
16 * This file and its associations are partially based on the
17 * Windows NT driver for Mesa, written by Mark Leaming
18 * (mark@rsinc.com).
19 */
20
21 /* $Log: ddcolors.h 1997/6/14 by Li Wei(liwei@aiar.xjtu.edu.cn)
22 * Macros for pixel format defined
23 */
24
25 /*
26 * $Log: colors.h,v $
27 * Revision 1.1 1999/08/19 00:55:42 jtg
28 * Initial revision
29 *
30 * Revision 1.2 1999/01/03 03:08:57 brianp
31 * Ted Jump's changes
32 *
33 * Revision 1.1 1999/01/03 03:08:12 brianp
34 * Initial revision
35 *
36 * Revision 2.0.2 1997/4/30 15:58:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn)
37 * Add LUTs need for dithering
38 */
39
40 /*
41 * $Log: colors.h,v $
42 * Revision 1.1 1999/08/19 00:55:42 jtg
43 * Initial revision
44 *
45 * Revision 1.2 1999/01/03 03:08:57 brianp
46 * Ted Jump's changes
47 *
48 * Revision 1.1 1999/01/03 03:08:12 brianp
49 * Initial revision
50 *
51 * Revision 2.0.1 1997/4/29 15:52:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn)
52 * Add BGR8 Macro
53 */
54
55 /*
56 * $Log: colors.h,v $
57 * Revision 1.1 1999/08/19 00:55:42 jtg
58 * Initial revision
59 *
60 * Revision 1.2 1999/01/03 03:08:57 brianp
61 * Ted Jump's changes
62 *
63 * Revision 1.1 1999/01/03 03:08:12 brianp
64 * Initial revision
65 *
66 * Revision 2.0 1996/11/15 10:55:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn)
67 * Initial revision
68 */
69 /* Values for wmesa->pixelformat: */
70
71 #define PF_8A8B8G8R 3 /* 32-bit TrueColor: 8-A, 8-B, 8-G, 8-R */
72 #define PF_8R8G8B 4 /* 32-bit TrueColor: 8-R, 8-G, 8-B */
73 #define PF_5R6G5B 5 /* 16-bit TrueColor: 5-R, 6-G, 5-B bits */
74 #define PF_DITHER8 6 /* Dithered RGB using a lookup table */
75 #define PF_LOOKUP 7 /* Undithered RGB using a lookup table */
76 #define PF_GRAYSCALE 10 /* Grayscale or StaticGray */
77 #define PF_BADFORMAT 11
78 #define PF_INDEX8 12
79
80 char ColorMap16[] = {
81 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
82 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
83 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
84 0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
85 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,
86 0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,
87 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
88 0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,
89 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
90 0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,
91 0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,
92 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,
93 0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,
94 0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,
95 0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,
96 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
97 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
98 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
99 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
100 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
101 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,
102 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
103 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16,
104 0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,
105 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
106 0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,
107 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
108 0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,
109 0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,
110 0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,
111 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,
112 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
113
114 #define BGR8(r,g,b) (unsigned)(((BYTE)(b & 0xc0 | (g & 0xe0)>>2 | (r & 0xe0)>>5)))
115 #ifdef DDRAW
116 #define BGR16(r,g,b) ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(g&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[r])) << 11)))
117 #else
118 #define BGR16(r,g,b) ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(ColorMap16[g]) << 5)) | (((WORD)(BYTE)(ColorMap16[r])) << 10)))
119 #endif
120 #define BGR24(r,g,b) (unsigned long)(((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16))) << 8)
121 #define BGR32(r,g,b) (unsigned long)((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16)))
122
123
124
125 /*
126 * If pixelformat==PF_8A8B8G8R:
127 */
128 #define PACK_8A8B8G8R( R, G, B, A ) \
129 ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) )
130
131
132 /*
133 * If pixelformat==PF_8R8G8B:
134 */
135 #define PACK_8R8G8B( R, G, B) ( ((R) << 16) | ((G) << 8) | (B) )
136
137
138 /*
139 * If pixelformat==PF_5R6G5B:
140 */
141
142
143 #ifdef DDRAW
144 #define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(G&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[R])) << 11)))
145 #else
146 #define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(ColorMap16[G]) << 5)) | (((WORD)(BYTE)(ColorMap16[R])) << 10)))
147 #endif
148 /*----------------------------------------------------------------------------
149
150 Division lookup tables. These tables compute 0-255 divided by 51 and
151 modulo 51. These tables could approximate gamma correction.
152
153 */
154
155 char unsigned const aDividedBy51Rounded[256] =
156 {
157 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
158 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
159 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
160 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
161 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
163 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
164 3, 3, 3, 3, 3, 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
182 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5,
183 };
184
185 char unsigned const aModulo51[256] =
186 {
187 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
188 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
189 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6,
190 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
191 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
192 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
193 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
194 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
195 49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
196 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
197 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3,
198 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
199 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
200 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0,
201 };
202
203 /*----------------------------------------------------------------------------
204
205 Multiplication LUTs. These compute 0-5 times 6 and 36.
206
207 */
208
209 char unsigned const aTimes6[6] =
210 {
211 0, 6, 12, 18, 24, 30
212 };
213
214 char unsigned const aTimes36[6] =
215 {
216 0, 36, 72, 108, 144, 180
217 };
218
219
220 /*----------------------------------------------------------------------------
221
222 Dither matrices for 8 bit to 2.6 bit halftones.
223
224 */
225
226 char unsigned const aHalftone16x16[256] =
227 {
228 0, 44, 9, 41, 3, 46, 12, 43, 1, 44, 10, 41, 3, 46, 12, 43,
229 34, 16, 25, 19, 37, 18, 28, 21, 35, 16, 26, 19, 37, 18, 28, 21,
230 38, 6, 47, 3, 40, 9, 50, 6, 38, 7, 47, 4, 40, 9, 49, 6,
231 22, 28, 13, 31, 25, 31, 15, 34, 22, 29, 13, 32, 24, 31, 15, 34,
232 2, 46, 12, 43, 1, 45, 10, 42, 2, 45, 11, 42, 1, 45, 11, 42,
233 37, 18, 27, 21, 35, 17, 26, 20, 36, 17, 27, 20, 36, 17, 26, 20,
234 40, 8, 49, 5, 38, 7, 48, 4, 39, 8, 48, 5, 39, 7, 48, 4,
235 24, 30, 15, 33, 23, 29, 13, 32, 23, 30, 14, 33, 23, 29, 14, 32,
236 2, 46, 12, 43, 0, 44, 10, 41, 3, 47, 12, 44, 0, 44, 10, 41,
237 37, 18, 27, 21, 35, 16, 25, 19, 37, 19, 28, 22, 35, 16, 25, 19,
238 40, 9, 49, 5, 38, 7, 47, 4, 40, 9, 50, 6, 38, 6, 47, 3,
239 24, 30, 15, 34, 22, 29, 13, 32, 25, 31, 15, 34, 22, 28, 13, 31,
240 1, 45, 11, 42, 2, 46, 11, 42, 1, 45, 10, 41, 2, 46, 11, 43,
241 36, 17, 26, 20, 36, 17, 27, 21, 35, 16, 26, 20, 36, 18, 27, 21,
242 39, 8, 48, 4, 39, 8, 49, 5, 38, 7, 48, 4, 39, 8, 49, 5,
243 23, 29, 14, 33, 24, 30, 14, 33, 23, 29, 13, 32, 24, 30, 14, 33,
244 };
245
246 char unsigned const aHalftone8x8[64] =
247 {
248 0, 38, 9, 47, 2, 40, 11, 50,
249 25, 12, 35, 22, 27, 15, 37, 24,
250 6, 44, 3, 41, 8, 47, 5, 43,
251 31, 19, 28, 15, 34, 21, 31, 18,
252 1, 39, 11, 49, 0, 39, 10, 48,
253 27, 14, 36, 23, 26, 13, 35, 23,
254 7, 46, 4, 43, 7, 45, 3, 42,
255 33, 20, 30, 17, 32, 19, 29, 16,
256 };
257
258 char unsigned const aHalftone4x4_1[16] =
259 {
260 0, 25, 6, 31,
261 38, 12, 44, 19,
262 9, 35, 3, 28,
263 47, 22, 41, 15
264 };
265
266 char unsigned const aHalftone4x4_2[16] =
267 {
268 41, 3, 9, 28,
269 35, 15, 22, 47,
270 6, 25, 38, 0,
271 19, 44, 31, 12
272 };
273
274 /***************************************************************************
275 aWinGHalftoneTranslation
276
277 Translates a 2.6 bit-per-pixel halftoned representation into the
278 slightly rearranged WinG Halftone Palette.
279 */
280
281 char unsigned const aWinGHalftoneTranslation[216] =
282 {
283 0,
284 29,
285 30,
286 31,
287 32,
288 249,
289 33,
290 34,
291 35,
292 36,
293 37,
294 38,
295 39,
296 40,
297 41,
298 42,
299 43,
300 44,
301 45,
302 46,
303 47,
304 48,
305 49,
306 50,
307 51,
308 52,
309 53,
310 54,
311 55,
312 56,
313 250,
314 250,
315 57,
316 58,
317 59,
318 251,
319 60,
320 61,
321 62,
322 63,
323 64,
324 65,
325 66,
326 67,
327 68,
328 69,
329 70,
330 71,
331 72,
332 73,
333 74,
334 75,
335 76,
336 77,
337 78,
338 79,
339 80,
340 81,
341 82,
342 83,
343 84,
344 85,
345 86,
346 87,
347 88,
348 89,
349 250,
350 90,
351 91,
352 92,
353 93,
354 94,
355 95,
356 96,
357 97,
358 98,
359 99,
360 100,
361 101,
362 102,
363 103,
364 104,
365 105,
366 106,
367 107,
368 108,
369 109,
370 110,
371 111,
372 227,
373 112,
374 113,
375 114,
376 115,
377 116,
378 117,
379 118,
380 119,
381 151,
382 120,
383 121,
384 122,
385 123,
386 124,
387 228,
388 125,
389 126,
390 229,
391 133,
392 162,
393 135,
394 131,
395 132,
396 137,
397 166,
398 134,
399 140,
400 130,
401 136,
402 143,
403 138,
404 139,
405 174,
406 141,
407 142,
408 177,
409 129,
410 144,
411 145,
412 146,
413 147,
414 148,
415 149,
416 150,
417 157,
418 152,
419 153,
420 154,
421 155,
422 156,
423 192,
424 158,
425 159,
426 160,
427 161,
428 196,
429 163,
430 164,
431 165,
432 127,
433 199,
434 167,
435 168,
436 169,
437 170,
438 171,
439 172,
440 173,
441 207,
442 175,
443 176,
444 210,
445 178,
446 179,
447 180,
448 181,
449 182,
450 183,
451 184,
452 185,
453 186,
454 187,
455 188,
456 189,
457 190,
458 191,
459 224,
460 193,
461 194,
462 195,
463 252,
464 252,
465 197,
466 198,
467 128,
468 253,
469 252,
470 200,
471 201,
472 202,
473 203,
474 204,
475 205,
476 206,
477 230,
478 208,
479 209,
480 231,
481 211,
482 212,
483 213,
484 214,
485 215,
486 216,
487 217,
488 218,
489 219,
490 220,
491 221,
492 222,
493 254,
494 223,
495 232,
496 225,
497 226,
498 255,
499 };