URI:
       tmkcmap.c - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tmkcmap.c (1394B)
       ---
            1 #include <u.h>
            2 #include <libc.h>
            3 #include <draw.h>
            4 #include <memdraw.h>
            5 
            6 /*
            7 struct Memcmap
            8 {
            9         uchar        cmap2rgb[3*256];
           10         uchar        rgb2cmap[16*16*16];
           11 };
           12 */
           13 
           14 static Memcmap*
           15 mkcmap(void)
           16 {
           17         static Memcmap def;
           18 
           19         int i, rgb, r, g, b;
           20 
           21         for(i=0; i<256; i++){
           22                 rgb = cmap2rgb(i);
           23                 r = (rgb>>16)&0xff;
           24                 g = (rgb>>8)&0xff;
           25                 b = rgb&0xff;
           26                 def.cmap2rgb[3*i] = r;
           27                 def.cmap2rgb[3*i+1] = g;
           28                 def.cmap2rgb[3*i+2] = b;
           29         }
           30 
           31         for(r=0; r<16; r++)
           32         for(g=0; g<16; g++)
           33         for(b=0; b<16; b++)
           34                 def.rgb2cmap[r*16*16+g*16+b] = rgb2cmap(r*0x11, g*0x11, b*0x11);
           35         return &def;
           36 }
           37 
           38 void
           39 main(int argc, char **argv)
           40 {
           41         Memcmap *c;
           42         int i, j, inferno;
           43 
           44         inferno = 0;
           45         ARGBEGIN{
           46         case 'i':
           47                 inferno = 1;
           48         }ARGEND
           49 
           50         memimageinit();
           51         c = mkcmap();
           52         if(!inferno)
           53                 print("#include <u.h>\n#include <libc.h>\n");
           54         else
           55                 print("#include \"lib9.h\"\n");
           56         print("#include <draw.h>\n");
           57         print("#include <memdraw.h>\n\n");
           58         print("static Memcmap def = {\n");
           59         print("/* cmap2rgb */ {\n");
           60         for(i=0; i<sizeof(c->cmap2rgb); ){
           61                 print("\t");
           62                 for(j=0; j<16; j++, i++)
           63                         print("0x%2.2ux,", c->cmap2rgb[i]);
           64                 print("\n");
           65         }
           66         print("},\n");
           67         print("/* rgb2cmap */ {\n");
           68         for(i=0; i<sizeof(c->rgb2cmap);){
           69                 print("\t");
           70                 for(j=0; j<16; j++, i++)
           71                         print("0x%2.2ux,", c->rgb2cmap[i]);
           72                 print("\n");
           73         }
           74         print("}\n");
           75         print("};\n");
           76         print("Memcmap *memdefcmap = &def;\n");
           77         print("void _memmkcmap(void){}\n");
           78         exits(0);
           79 }