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