1*95e1ffb1Schristos /* $NetBSD: hpccmap_gen.c,v 1.5 2005/12/11 12:21:22 christos Exp $ */
2659f65e0Such
3659f65e0Such /*-
4659f65e0Such * Copyright (c) 1999
5659f65e0Such * Shin Takemura and PocketBSD Project. All rights reserved.
6659f65e0Such *
7659f65e0Such * Redistribution and use in source and binary forms, with or without
8659f65e0Such * modification, are permitted provided that the following conditions
9659f65e0Such * are met:
10659f65e0Such * 1. Redistributions of source code must retain the above copyright
11659f65e0Such * notice, this list of conditions and the following disclaimer.
12659f65e0Such * 2. Redistributions in binary form must reproduce the above copyright
13659f65e0Such * notice, this list of conditions and the following disclaimer in the
14659f65e0Such * documentation and/or other materials provided with the distribution.
15659f65e0Such * 3. All advertising materials mentioning features or use of this software
16659f65e0Such * must display the following acknowledgement:
17659f65e0Such * This product includes software developed by the PocketBSD project
18659f65e0Such * and its contributors.
19659f65e0Such * 4. Neither the name of the project nor the names of its contributors
20659f65e0Such * may be used to endorse or promote products derived from this software
21659f65e0Such * without specific prior written permission.
22659f65e0Such *
23659f65e0Such * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24659f65e0Such * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25659f65e0Such * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26659f65e0Such * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27659f65e0Such * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28659f65e0Such * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29659f65e0Such * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30659f65e0Such * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31659f65e0Such * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32659f65e0Such * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33659f65e0Such * SUCH DAMAGE.
34659f65e0Such *
35659f65e0Such */
36659f65e0Such
379391907dSlukem #include <sys/cdefs.h>
38*95e1ffb1Schristos __RCSID("$NetBSD: hpccmap_gen.c,v 1.5 2005/12/11 12:21:22 christos Exp $");
399391907dSlukem
40659f65e0Such typedef unsigned char u_char;
41659f65e0Such typedef void (*output_func)(void*, int, u_char, u_char, u_char);
42659f65e0Such
43659f65e0Such void main(int ac, char *av[]);
44659f65e0Such void rgb_separate_out(void*, int, u_char, u_char, u_char);
45659f65e0Such void cmap_gen(output_func, void *);
46659f65e0Such
47659f65e0Such unsigned char compo6[6] = { 0, 51, 102, 153, 204, 255 };
48659f65e0Such unsigned char compo7[7] = { 0, 42, 85, 127, 170, 212, 255 };
49659f65e0Such
50659f65e0Such void
main(int ac,char * av[])51859a6a49Such main(int ac, char *av[])
52659f65e0Such {
53659f65e0Such int i;
54659f65e0Such char *rgb = "rgb";
55659f65e0Such
56659f65e0Such printf("/*\n");
57659f65e0Such printf(" * Do not edit.\n");
58659f65e0Such printf(" * This file is automatically generated by hpccmap_gen.\n");
59659f65e0Such printf(" */\n");
60659f65e0Such printf("#include <dev/hpc/hpccmapar.h>\n");
61659f65e0Such for (i = 0; i < 3; i++) {
62659f65e0Such printf("unsigned char bivideo_cmap_%c[256] = {\n", rgb[i]);
63659f65e0Such cmap_gen(rgb_separate_out, (void*)i);
64659f65e0Such printf("};\n");
65659f65e0Such }
66659f65e0Such }
67659f65e0Such
68659f65e0Such void
rgb_separate_out(void * ctxx,int idx,unsigned char r,unsigned char g,unsigned char b)69859a6a49Such rgb_separate_out(void *ctxx, int idx, unsigned char r, unsigned char g,
70859a6a49Such unsigned char b)
71659f65e0Such {
72659f65e0Such int rgb = (int)ctxx;
73659f65e0Such
74659f65e0Such if ((idx % 16) == 0)
75659f65e0Such printf("\t");
76659f65e0Such switch(rgb) {
77659f65e0Such case 0:
78659f65e0Such printf("%3d,", r);
79659f65e0Such break;
80659f65e0Such case 1:
81659f65e0Such printf("%3d,", g);
82659f65e0Such break;
83659f65e0Such case 2:
84659f65e0Such printf("%3d,", b);
85659f65e0Such break;
86659f65e0Such }
87659f65e0Such if ((idx % 16) == 15)
88659f65e0Such printf("\n");
89659f65e0Such }
90659f65e0Such
91659f65e0Such void
cmap_gen(output_func func,void * ctx)92859a6a49Such cmap_gen(output_func func, void *ctx)
93659f65e0Such {
94659f65e0Such int i, r, g, b;
95659f65e0Such
96659f65e0Such i = 0;
97659f65e0Such
98659f65e0Such /*
99659f65e0Such * 0 - 15, for ANSI escape sequence
100659f65e0Such * (see sys/dev/rasops/rasops.c)
101659f65e0Such */
102659f65e0Such (*func)(ctx, i++, 0x00, 0x00, 0x00); /* black */
103659f65e0Such (*func)(ctx, i++, 0x7f, 0x00, 0x00); /* red */
104659f65e0Such (*func)(ctx, i++, 0x00, 0x7f, 0x00); /* green */
105659f65e0Such (*func)(ctx, i++, 0x7f, 0x7f, 0x00); /* brown */
106659f65e0Such (*func)(ctx, i++, 0x00, 0x00, 0x7f); /* blue */
107659f65e0Such (*func)(ctx, i++, 0x7f, 0x00, 0x7f); /* magenta */
108659f65e0Such (*func)(ctx, i++, 0x00, 0x7f, 0x7f); /* cyan */
109659f65e0Such (*func)(ctx, i++, 0xc7, 0xc7, 0xc7); /* white */
110659f65e0Such
111659f65e0Such (*func)(ctx, i++, 0x7f, 0x7f, 0x7f); /* black */
112659f65e0Such (*func)(ctx, i++, 0xff, 0x00, 0x00); /* red */
113659f65e0Such (*func)(ctx, i++, 0x00, 0xff, 0x00); /* green */
114659f65e0Such (*func)(ctx, i++, 0xff, 0xff, 0x00); /* brown */
115659f65e0Such (*func)(ctx, i++, 0x00, 0x00, 0xff); /* blue */
116659f65e0Such (*func)(ctx, i++, 0xff, 0x00, 0xff); /* magenta */
117659f65e0Such (*func)(ctx, i++, 0x00, 0xff, 0xff); /* cyan */
118659f65e0Such (*func)(ctx, i++, 0xff, 0xff, 0xff); /* white */
119659f65e0Such
120659f65e0Such /*
121659f65e0Such * 16 - 31, gray scale
122659f65e0Such */
123659f65e0Such for (; i < 32; i++) {
124659f65e0Such (*func)(ctx, i, (i - 16) * 17, (i - 16) * 17, (i - 16) * 17);
125659f65e0Such }
126659f65e0Such
127659f65e0Such /*
128659f65e0Such * 32 - 247, RGB color
129659f65e0Such */
130659f65e0Such for (r = 0; r < 6; r++) {
131659f65e0Such for (g = 0; g < 6; g++) {
132659f65e0Such for (b = 0; b < 6; b++) {
133659f65e0Such (*func)(ctx, i,
134659f65e0Such compo6[r], compo6[g], compo6[b]);
135659f65e0Such i++;
136659f65e0Such }
137659f65e0Such }
138659f65e0Such }
139659f65e0Such
140659f65e0Such /*
141659f65e0Such * 248 - 255, just white
142659f65e0Such */
143659f65e0Such for ( ; i < 256; i++) {
144659f65e0Such (*func)(ctx, i, 255, 255, 255);
145659f65e0Such }
146659f65e0Such }
147