Blob
1 #include <u.h>2 #include <libc.h>3 #include <draw.h>5 /*6 * This code (and the devdraw interface) will have to change7 * if we ever get bitmaps with ldepth > 3, because the8 * colormap will have to be written in chunks9 */11 void12 writecolmap(Display *d, RGB *m)13 {14 int i, n, fd;15 char buf[64], *t;16 ulong r, g, b;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 }