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