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