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