readcolmap.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 <bio.h>
  13. static uint32_t
  14. getval(char **p)
  15. {
  16. uint32_t v;
  17. char *q;
  18. v = strtoul(*p, &q, 0);
  19. v |= v<<8;
  20. v |= v<<16;
  21. *p = q;
  22. return v;
  23. }
  24. void
  25. readcolmap(Display *d, RGB *colmap)
  26. {
  27. int i;
  28. char *p, *q;
  29. Biobuf *b;
  30. char buf[128];
  31. USED(screen);
  32. sprint(buf, "/dev/draw/%d/colormap", d->dirno);
  33. b = Bopen(buf, OREAD);
  34. if(b == 0)
  35. drawerror(d, "rdcolmap: can't open colormap device");
  36. for(;;) {
  37. p = Brdline(b, '\n');
  38. if(p == 0)
  39. break;
  40. i = strtoul(p, &q, 0);
  41. if(i < 0 || i > 255) {
  42. fprint(2, "rdcolmap: bad index\n");
  43. exits("bad");
  44. }
  45. p = q;
  46. colmap[255-i].red = getval(&p);
  47. colmap[255-i].green = getval(&p);
  48. colmap[255-i].blue = getval(&p);
  49. }
  50. Bterm(b);
  51. }