mkcmap.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <draw.h>
  12. #include <memdraw.h>
  13. /*
  14. struct Memcmap
  15. {
  16. uchar cmap2rgb[3*256];
  17. uchar rgb2cmap[16*16*16];
  18. };
  19. */
  20. static Memcmap*
  21. mkcmap(void)
  22. {
  23. static Memcmap def;
  24. int i, rgb, r, g, b;
  25. for(i=0; i<256; i++){
  26. rgb = cmap2rgb(i);
  27. r = (rgb>>16)&0xff;
  28. g = (rgb>>8)&0xff;
  29. b = rgb&0xff;
  30. def.cmap2rgb[3*i] = r;
  31. def.cmap2rgb[3*i+1] = g;
  32. def.cmap2rgb[3*i+2] = b;
  33. }
  34. for(r=0; r<16; r++)
  35. for(g=0; g<16; g++)
  36. for(b=0; b<16; b++)
  37. def.rgb2cmap[r*16*16+g*16+b] = rgb2cmap(r*0x11, g*0x11, b*0x11);
  38. return &def;
  39. }
  40. void
  41. main(int argc, char **argv)
  42. {
  43. Memcmap *c;
  44. int i, j, inferno;
  45. inferno = 0;
  46. ARGBEGIN{
  47. case 'i':
  48. inferno = 1;
  49. }ARGEND
  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. }