writecolmap.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. /*
  13. * This code (and the devdraw interface) will have to change
  14. * if we ever get bitmaps with ldepth > 3, because the
  15. * colormap will have to be written in chunks
  16. */
  17. void
  18. writecolmap(Display *d, RGB *m)
  19. {
  20. int i, n, fd;
  21. char buf[64], *t;
  22. uint32_t r, g, b;
  23. sprint(buf, "/dev/draw/%d/colormap", d->dirno);
  24. fd = open(buf, OWRITE);
  25. if(fd < 0)
  26. drawerror(d, "writecolmap: open colormap failed");
  27. t = malloc(8192);
  28. if (t == nil)
  29. drawerror(d, "writecolmap: no memory");
  30. n = 0;
  31. for(i = 0; i < 256; i++) {
  32. r = m[i].red>>24;
  33. g = m[i].green>>24;
  34. b = m[i].blue>>24;
  35. n += sprint(t+n, "%d %lu %lu %lu\n", 255-i, r, g, b);
  36. }
  37. i = write(fd, t, n);
  38. free(t);
  39. close(fd);
  40. if(i != n)
  41. drawerror(d, "writecolmap: bad write");
  42. }