diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libdraw/unloadimage.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libdraw/unloadimage.c')
-rwxr-xr-x | sys/src/libdraw/unloadimage.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/sys/src/libdraw/unloadimage.c b/sys/src/libdraw/unloadimage.c new file mode 100755 index 000000000..ead36b0c8 --- /dev/null +++ b/sys/src/libdraw/unloadimage.c @@ -0,0 +1,53 @@ +#include <u.h> +#include <libc.h> +#include <draw.h> + +int +unloadimage(Image *i, Rectangle r, uchar *data, int ndata) +{ + int bpl, n, ntot, dy; + uchar *a; + Display *d; + + if(!rectinrect(r, i->r)){ + werrstr("unloadimage: bad rectangle"); + return -1; + } + bpl = bytesperline(r, i->depth); + if(ndata < bpl*Dy(r)){ + werrstr("unloadimage: buffer too small"); + return -1; + } + + d = i->display; + flushimage(d, 0); /* make sure subsequent flush is for us only */ + ntot = 0; + while(r.min.y < r.max.y){ + a = bufimage(d, 1+4+4*4); + if(a == 0){ + werrstr("unloadimage: %r"); + return -1; + } + dy = 8000/bpl; + if(dy <= 0){ + werrstr("unloadimage: image too wide"); + return -1; + } + if(dy > Dy(r)) + dy = Dy(r); + a[0] = 'r'; + BPLONG(a+1, i->id); + BPLONG(a+5, r.min.x); + BPLONG(a+9, r.min.y); + BPLONG(a+13, r.max.x); + BPLONG(a+17, r.min.y+dy); + if(flushimage(d, 0) < 0) + return -1; + n = read(d->fd, data+ntot, ndata-ntot); + if(n < 0) + return n; + ntot += n; + r.min.y += dy; + } + return ntot; +} |