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