1 #include "lib9.h"
2 #include "draw.h"
3 #include "kernel.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
11 void
writecolmap(Display * d,RGB * m)12 writecolmap(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 if(t == nil)
24 return;
25 n = 0;
26 for(i = 0; i < 256; i++) {
27 r = m[i].red>>24;
28 g = m[i].green>>24;
29 b = m[i].blue>>24;
30 n += sprint(t+n, "%d %lud %lud %lud\n", 255-i, r, g, b);
31 }
32 i = libwrite(fd, t, n);
33 free(t);
34 close(fd);
35 if(i != n)
36 drawerror(d, "wrcolmap: bad write");
37 }
38