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