readcolmap.c 745 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <draw.h>
  4. #include <bio.h>
  5. static ulong
  6. getval(char **p)
  7. {
  8. ulong v;
  9. char *q;
  10. v = strtoul(*p, &q, 0);
  11. v |= v<<8;
  12. v |= v<<16;
  13. *p = q;
  14. return v;
  15. }
  16. void
  17. readcolmap(Display *d, RGB *colmap)
  18. {
  19. int i;
  20. char *p, *q;
  21. Biobuf *b;
  22. char buf[128];
  23. USED(screen);
  24. sprint(buf, "/dev/draw/%d/colormap", d->dirno);
  25. b = Bopen(buf, OREAD);
  26. if(b == 0)
  27. drawerror(d, "rdcolmap: can't open colormap device");
  28. for(;;) {
  29. p = Brdline(b, '\n');
  30. if(p == 0)
  31. break;
  32. i = strtoul(p, &q, 0);
  33. if(i < 0 || i > 255) {
  34. fprint(2, "rdcolmap: bad index\n");
  35. exits("bad");
  36. }
  37. p = q;
  38. colmap[255-i].red = getval(&p);
  39. colmap[255-i].green = getval(&p);
  40. colmap[255-i].blue = getval(&p);
  41. }
  42. Bterm(b);
  43. }