writecolmap.c 725 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <draw.h>
  4. /*
  5. * This code (and the devdraw interface) will have to change
  6. * if we ever get bitmaps with ldepth > 3, because the
  7. * colormap will have to be written in chunks
  8. */
  9. void
  10. writecolmap(Display *d, RGB *m)
  11. {
  12. int i, n, fd;
  13. char buf[64], *t;
  14. ulong r, g, b;
  15. sprint(buf, "/dev/draw/%d/colormap", d->dirno);
  16. fd = open(buf, OWRITE);
  17. if(fd < 0)
  18. drawerror(d, "wrcolmap: open colormap failed");
  19. t = malloc(8192);
  20. n = 0;
  21. for(i = 0; i < 256; i++) {
  22. r = m[i].red>>24;
  23. g = m[i].green>>24;
  24. b = m[i].blue>>24;
  25. n += sprint(t+n, "%d %lud %lud %lud\n", 255-i, r, g, b);
  26. }
  27. i = write(fd, t, n);
  28. free(t);
  29. close(fd);
  30. if(i != n)
  31. drawerror(d, "wrcolmap: bad write");
  32. }