1 /* File name : colors.h
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
9 * Copyright (C) 1996- Li Wei
10 * Address : Institute of Artificial Intelligence
12 * : Xi'an Jiaotong University
13 * Email : liwei@aiar.xjtu.edu.cn
14 * Web page : http://sun.aiar.xjtu.edu.cn
16 * This file and its associations are partially based on the
17 * Windows NT driver for Mesa, written by Mark Leaming
22 * Macros for pixel format defined
26 * Revision 1.1 2004/04/20 11:13:11 alanh
27 * add SciTech's GLDirect driver for Windows.
29 * This code is donated to Mesa which allows the usage of
30 * a Direct3D layer (DX7, DX8, DX9 or complete software fallback).
32 * No build system exists for this code yet, that will come.....
34 * Revision 1.1.1.1 1999/08/19 00:55:42 jtg
37 * Revision 1.2 1999/01/03 03:08:57 brianp
40 * Revision 1.1 1999/01/03 03:08:12 brianp
43 * Revision 2.0.2 1997/4/30 15:58:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn)
44 * Add LUTs need for dithering
48 * Revision 1.1 2004/04/20 11:13:11 alanh
49 * add SciTech's GLDirect driver for Windows.
51 * This code is donated to Mesa which allows the usage of
52 * a Direct3D layer (DX7, DX8, DX9 or complete software fallback).
54 * No build system exists for this code yet, that will come.....
56 * Revision 1.1.1.1 1999/08/19 00:55:42 jtg
59 * Revision 1.2 1999/01/03 03:08:57 brianp
62 * Revision 1.1 1999/01/03 03:08:12 brianp
65 * Revision 2.0.1 1997/4/29 15:52:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn)
70 * Revision 1.1 2004/04/20 11:13:11 alanh
71 * add SciTech's GLDirect driver for Windows.
73 * This code is donated to Mesa which allows the usage of
74 * a Direct3D layer (DX7, DX8, DX9 or complete software fallback).
76 * No build system exists for this code yet, that will come.....
78 * Revision 1.1.1.1 1999/08/19 00:55:42 jtg
81 * Revision 1.2 1999/01/03 03:08:57 brianp
84 * Revision 1.1 1999/01/03 03:08:12 brianp
87 * Revision 2.0 1996/11/15 10:55:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn)
90 /* Values for wmesa->pixelformat: */
92 #define PF_8A8B8G8R 3 /* 32-bit TrueColor: 8-A, 8-B, 8-G, 8-R */
93 #define PF_8R8G8B 4 /* 32-bit TrueColor: 8-R, 8-G, 8-B */
94 #define PF_5R6G5B 5 /* 16-bit TrueColor: 5-R, 6-G, 5-B bits */
95 #define PF_DITHER8 6 /* Dithered RGB using a lookup table */
96 #define PF_LOOKUP 7 /* Undithered RGB using a lookup table */
97 #define PF_GRAYSCALE 10 /* Grayscale or StaticGray */
98 #define PF_BADFORMAT 11
101 char ColorMap16
[] = {
102 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
103 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
104 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
105 0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
106 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,
107 0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,
108 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
109 0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,
110 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
111 0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,
112 0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,
113 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,
114 0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,
115 0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,
116 0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,
117 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
118 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
119 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
120 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
121 0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
122 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,
123 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
124 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16,
125 0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,
126 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
127 0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,
128 0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
129 0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,
130 0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,
131 0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,
132 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,
133 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
135 #define BGR8(r,g,b) (unsigned)(((BYTE)(b & 0xc0 | (g & 0xe0)>>2 | (r & 0xe0)>>5)))
137 #define BGR16(r,g,b) ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(g&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[r])) << 11)))
139 #define BGR16(r,g,b) ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(ColorMap16[g]) << 5)) | (((WORD)(BYTE)(ColorMap16[r])) << 10)))
141 #define BGR24(r,g,b) (unsigned long)(((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16))) << 8)
142 #define BGR32(r,g,b) (unsigned long)((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16)))
147 * If pixelformat==PF_8A8B8G8R:
149 #define PACK_8A8B8G8R( R, G, B, A ) \
150 ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) )
154 * If pixelformat==PF_8R8G8B:
156 #define PACK_8R8G8B( R, G, B) ( ((R) << 16) | ((G) << 8) | (B) )
160 * If pixelformat==PF_5R6G5B:
165 #define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(G&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[R])) << 11)))
167 #define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(ColorMap16[G]) << 5)) | (((WORD)(BYTE)(ColorMap16[R])) << 10)))
169 /*----------------------------------------------------------------------------
171 Division lookup tables. These tables compute 0-255 divided by 51 and
172 modulo 51. These tables could approximate gamma correction.
176 char unsigned const aDividedBy51Rounded
[256] =
178 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
179 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
180 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
181 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
182 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
183 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
184 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
185 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
186 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 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 19,
209 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
210 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6,
211 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
212 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
213 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
214 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
215 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
216 49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
217 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
218 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3,
219 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
220 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
221 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0,
224 /*----------------------------------------------------------------------------
226 Multiplication LUTs. These compute 0-5 times 6 and 36.
230 char unsigned const aTimes6
[6] =
235 char unsigned const aTimes36
[6] =
237 0, 36, 72, 108, 144, 180
241 /*----------------------------------------------------------------------------
243 Dither matrices for 8 bit to 2.6 bit halftones.
247 char unsigned const aHalftone16x16
[256] =
249 0, 44, 9, 41, 3, 46, 12, 43, 1, 44, 10, 41, 3, 46, 12, 43,
250 34, 16, 25, 19, 37, 18, 28, 21, 35, 16, 26, 19, 37, 18, 28, 21,
251 38, 6, 47, 3, 40, 9, 50, 6, 38, 7, 47, 4, 40, 9, 49, 6,
252 22, 28, 13, 31, 25, 31, 15, 34, 22, 29, 13, 32, 24, 31, 15, 34,
253 2, 46, 12, 43, 1, 45, 10, 42, 2, 45, 11, 42, 1, 45, 11, 42,
254 37, 18, 27, 21, 35, 17, 26, 20, 36, 17, 27, 20, 36, 17, 26, 20,
255 40, 8, 49, 5, 38, 7, 48, 4, 39, 8, 48, 5, 39, 7, 48, 4,
256 24, 30, 15, 33, 23, 29, 13, 32, 23, 30, 14, 33, 23, 29, 14, 32,
257 2, 46, 12, 43, 0, 44, 10, 41, 3, 47, 12, 44, 0, 44, 10, 41,
258 37, 18, 27, 21, 35, 16, 25, 19, 37, 19, 28, 22, 35, 16, 25, 19,
259 40, 9, 49, 5, 38, 7, 47, 4, 40, 9, 50, 6, 38, 6, 47, 3,
260 24, 30, 15, 34, 22, 29, 13, 32, 25, 31, 15, 34, 22, 28, 13, 31,
261 1, 45, 11, 42, 2, 46, 11, 42, 1, 45, 10, 41, 2, 46, 11, 43,
262 36, 17, 26, 20, 36, 17, 27, 21, 35, 16, 26, 20, 36, 18, 27, 21,
263 39, 8, 48, 4, 39, 8, 49, 5, 38, 7, 48, 4, 39, 8, 49, 5,
264 23, 29, 14, 33, 24, 30, 14, 33, 23, 29, 13, 32, 24, 30, 14, 33,
267 char unsigned const aHalftone8x8
[64] =
269 0, 38, 9, 47, 2, 40, 11, 50,
270 25, 12, 35, 22, 27, 15, 37, 24,
271 6, 44, 3, 41, 8, 47, 5, 43,
272 31, 19, 28, 15, 34, 21, 31, 18,
273 1, 39, 11, 49, 0, 39, 10, 48,
274 27, 14, 36, 23, 26, 13, 35, 23,
275 7, 46, 4, 43, 7, 45, 3, 42,
276 33, 20, 30, 17, 32, 19, 29, 16,
279 char unsigned const aHalftone4x4_1
[16] =
287 char unsigned const aHalftone4x4_2
[16] =
295 /***************************************************************************
296 aWinGHalftoneTranslation
298 Translates a 2.6 bit-per-pixel halftoned representation into the
299 slightly rearranged WinG Halftone Palette.
302 char unsigned const aWinGHalftoneTranslation
[216] =