mkcmap.c 1.4 KB

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