diff options
| author | bhgv <bhgv.empire@gmail.com> | 2018-03-01 16:54:45 +0200 |
|---|---|---|
| committer | bhgv <bhgv.empire@gmail.com> | 2018-03-01 16:54:45 +0200 |
| commit | b786f20bbab5a59046aa78a2c6c2a11536497202 (patch) | |
| tree | 0851ecdec889eb9b7ba3751cc04d4f0b474e4a9e /libdraw/writecolmap.c | |
inferno-os tree was separated from the inferno-os-android (separated from the Android driver)
Diffstat (limited to 'libdraw/writecolmap.c')
| -rw-r--r-- | libdraw/writecolmap.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libdraw/writecolmap.c b/libdraw/writecolmap.c new file mode 100644 index 0000000..6bbc7fe --- /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"); +} |
