1/*	$NetBSD: hpccmap_gen.c,v 1.3.22.3 2004/09/21 13:27:37 skrll 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#include <sys/cdefs.h>
38__RCSID("$NetBSD: hpccmap_gen.c,v 1.3.22.3 2004/09/21 13:27:37 skrll Exp $");
39
40typedef unsigned char u_char;
41typedef void (*output_func)(void*, int, u_char,  u_char, u_char);
42
43void main(int ac, char *av[]);
44void rgb_separate_out(void*, int, u_char, u_char, u_char);
45void cmap_gen(output_func, void *);
46
47unsigned char compo6[6] = {   0,  51, 102, 153, 204, 255 };
48unsigned char compo7[7] = {   0,  42,  85, 127, 170, 212, 255 };
49
50void
51main(int ac, char *av[])
52{
53	int i;
54	char *rgb = "rgb";
55
56	printf("/*\n");
57	printf(" *  Do not edit.\n");
58	printf(" *  This file is automatically generated by hpccmap_gen.\n");
59	printf(" */\n");
60	printf("#include <dev/hpc/hpccmapar.h>\n");
61	for (i = 0; i < 3; i++) {
62		printf("unsigned char bivideo_cmap_%c[256] = {\n", rgb[i]);
63		cmap_gen(rgb_separate_out, (void*)i);
64		printf("};\n");
65	}
66}
67
68void
69rgb_separate_out(void *ctxx, int idx, unsigned char r, unsigned char g,
70    unsigned char b)
71{
72	int rgb = (int)ctxx;
73
74	if ((idx % 16) == 0)
75		printf("\t");
76	switch(rgb) {
77	case 0:
78		printf("%3d,", r);
79		break;
80	case 1:
81		printf("%3d,", g);
82		break;
83	case 2:
84		printf("%3d,", b);
85		break;
86	}
87	if ((idx % 16) == 15)
88		printf("\n");
89}
90
91void
92cmap_gen(output_func func, void *ctx)
93{
94	int i, r, g, b;
95
96	i = 0;
97
98	/*
99	 * 0 - 15, for ANSI escape sequence
100	 * (see sys/dev/rasops/rasops.c)
101	 */
102	(*func)(ctx, i++, 0x00, 0x00, 0x00); /* black	*/
103	(*func)(ctx, i++, 0x7f, 0x00, 0x00); /* red	*/
104	(*func)(ctx, i++, 0x00, 0x7f, 0x00); /* green	*/
105	(*func)(ctx, i++, 0x7f, 0x7f, 0x00); /* brown	*/
106	(*func)(ctx, i++, 0x00, 0x00, 0x7f); /* blue	*/
107	(*func)(ctx, i++, 0x7f, 0x00, 0x7f); /* magenta	*/
108	(*func)(ctx, i++, 0x00, 0x7f, 0x7f); /* cyan	*/
109	(*func)(ctx, i++, 0xc7, 0xc7, 0xc7); /* white	*/
110
111	(*func)(ctx, i++, 0x7f, 0x7f, 0x7f); /* black	*/
112	(*func)(ctx, i++, 0xff, 0x00, 0x00); /* red	*/
113	(*func)(ctx, i++, 0x00, 0xff, 0x00); /* green	*/
114	(*func)(ctx, i++, 0xff, 0xff, 0x00); /* brown	*/
115	(*func)(ctx, i++, 0x00, 0x00, 0xff); /* blue	*/
116	(*func)(ctx, i++, 0xff, 0x00, 0xff); /* magenta	*/
117	(*func)(ctx, i++, 0x00, 0xff, 0xff); /* cyan	*/
118	(*func)(ctx, i++, 0xff, 0xff, 0xff); /* white	*/
119
120	/*
121	 * 16 - 31, gray scale
122	 */
123	for (; i < 32; i++) {
124		(*func)(ctx, i, (i - 16) * 17, (i - 16) * 17, (i - 16) * 17);
125	}
126
127	/*
128	 * 32 - 247, RGB color
129	 */
130	for (r = 0; r < 6; r++) {
131		for (g = 0; g < 6; g++) {
132			for (b = 0; b < 6; b++) {
133				(*func)(ctx, i,
134				    compo6[r], compo6[g], compo6[b]);
135				i++;
136			}
137		}
138	}
139
140	/*
141	 * 248 - 255, just white
142	 */
143	for ( ; i < 256; i++) {
144		(*func)(ctx, i, 255, 255, 255);
145	}
146}
147