summaryrefslogtreecommitdiff
path: root/libdraw/writecolmap.c
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
commit37da2899f40661e3e9631e497da8dc59b971cbd0 (patch)
treecbc6d4680e347d906f5fa7fca73214418741df72 /libdraw/writecolmap.c
parent54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff)
20060303a
Diffstat (limited to 'libdraw/writecolmap.c')
-rw-r--r--libdraw/writecolmap.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/libdraw/writecolmap.c b/libdraw/writecolmap.c
new file mode 100644
index 00000000..6bbc7feb
--- /dev/null
+++ b/libdraw/writecolmap.c
@@ -0,0 +1,37 @@
+#include "lib9.h"
+#include "draw.h"
+#include "kernel.h"
+
+/*
+ * This code (and the devdraw interface) will have to change
+ * if we ever get bitmaps with ldepth > 3, because the
+ * colormap will have to be written in chunks
+ */
+
+void
+writecolmap(Display *d, RGB *m)
+{
+ int i, n, fd;
+ char buf[64], *t;
+ ulong r, g, b;
+
+ sprint(buf, "/dev/draw/%d/colormap", d->dirno);
+ fd = open(buf, OWRITE);
+ if(fd < 0)
+ drawerror(d, "wrcolmap: open colormap failed");
+ t = malloc(8192);
+ if(t == nil)
+ return;
+ n = 0;
+ for(i = 0; i < 256; i++) {
+ r = m[i].red>>24;
+ g = m[i].green>>24;
+ b = m[i].blue>>24;
+ n += sprint(t+n, "%d %lud %lud %lud\n", 255-i, r, g, b);
+ }
+ i = libwrite(fd, t, n);
+ free(t);
+ close(fd);
+ if(i != n)
+ drawerror(d, "wrcolmap: bad write");
+}