xref: /netbsd-src/sys/dev/hpc/hpccmap_gen.c (revision dbb7276f40381917c54e55d28c5fd30b3ff92bc6)
1 /*	$NetBSD: hpccmap_gen.c,v 1.2 2001/05/08 14:46:06 uch Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999
5  *         Shin Takemura and PocketBSD Project. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the PocketBSD project
18  *	and its contributors.
19  * 4. Neither the name of the project nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36 
37 typedef unsigned char u_char;
38 typedef void (*output_func)(void*, int, u_char,  u_char, u_char);
39 
40 void main(int ac, char *av[]);
41 void rgb_separate_out(void*, int, u_char, u_char, u_char);
42 void cmap_gen(output_func, void *);
43 
44 unsigned char compo6[6] = {   0,  51, 102, 153, 204, 255 };
45 unsigned char compo7[7] = {   0,  42,  85, 127, 170, 212, 255 };
46 
47 void
48 main(ac, av)
49 	int ac;
50 	char *av[];
51 {
52 	int i;
53 	char *rgb = "rgb";
54 
55 	printf("/*\n");
56 	printf(" *  Do not edit.\n");
57 	printf(" *  This file is automatically generated by hpccmap_gen.\n");
58 	printf(" */\n");
59 	printf("#include <dev/hpc/hpccmapar.h>\n");
60 	for (i = 0; i < 3; i++) {
61 		printf("unsigned char bivideo_cmap_%c[256] = {\n", rgb[i]);
62 		cmap_gen(rgb_separate_out, (void*)i);
63 		printf("};\n");
64 	}
65 }
66 
67 void
68 rgb_separate_out(ctxx, idx, r, g, b)
69 	void* ctxx;
70 	int idx;
71 	unsigned char r, g, b;
72 {
73 	int rgb = (int)ctxx;
74 
75 	if ((idx % 16) == 0)
76 		printf("\t");
77 	switch(rgb) {
78 	case 0:
79 		printf("%3d,", r);
80 		break;
81 	case 1:
82 		printf("%3d,", g);
83 		break;
84 	case 2:
85 		printf("%3d,", b);
86 		break;
87 	}
88 	if ((idx % 16) == 15)
89 		printf("\n");
90 }
91 
92 void
93 cmap_gen(func, ctx)
94 	output_func func;
95 	void *ctx;
96 {
97 	int i, r, g, b;
98 
99 	i = 0;
100 
101 	/*
102 	 * 0 - 15, for ANSI escape sequence
103 	 * (see sys/dev/rasops/rasops.c)
104 	 */
105 	(*func)(ctx, i++, 0x00, 0x00, 0x00); /* black	*/
106 	(*func)(ctx, i++, 0x7f, 0x00, 0x00); /* red	*/
107 	(*func)(ctx, i++, 0x00, 0x7f, 0x00); /* green	*/
108 	(*func)(ctx, i++, 0x7f, 0x7f, 0x00); /* brown	*/
109 	(*func)(ctx, i++, 0x00, 0x00, 0x7f); /* blue	*/
110 	(*func)(ctx, i++, 0x7f, 0x00, 0x7f); /* magenta	*/
111 	(*func)(ctx, i++, 0x00, 0x7f, 0x7f); /* cyan	*/
112 	(*func)(ctx, i++, 0xc7, 0xc7, 0xc7); /* white	*/
113 
114 	(*func)(ctx, i++, 0x7f, 0x7f, 0x7f); /* black	*/
115 	(*func)(ctx, i++, 0xff, 0x00, 0x00); /* red	*/
116 	(*func)(ctx, i++, 0x00, 0xff, 0x00); /* green	*/
117 	(*func)(ctx, i++, 0xff, 0xff, 0x00); /* brown	*/
118 	(*func)(ctx, i++, 0x00, 0x00, 0xff); /* blue	*/
119 	(*func)(ctx, i++, 0xff, 0x00, 0xff); /* magenta	*/
120 	(*func)(ctx, i++, 0x00, 0xff, 0xff); /* cyan	*/
121 	(*func)(ctx, i++, 0xff, 0xff, 0xff); /* white	*/
122 
123 	/*
124 	 * 16 - 31, gray scale
125 	 */
126 	for (; i < 32; i++) {
127 		(*func)(ctx, i, (i - 16) * 17, (i - 16) * 17, (i - 16) * 17);
128 	}
129 
130 	/*
131 	 * 32 - 247, RGB color
132 	 */
133 	for (r = 0; r < 6; r++) {
134 		for (g = 0; g < 6; g++) {
135 			for (b = 0; b < 6; b++) {
136 				(*func)(ctx, i,
137 				    compo6[r], compo6[g], compo6[b]);
138 				i++;
139 			}
140 		}
141 	}
142 
143 	/*
144 	 * 248 - 255, just white
145 	 */
146 	for ( ; i < 256; i++) {
147 		(*func)(ctx, i, 255, 255, 255);
148 	}
149 }
150