diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
| commit | 37da2899f40661e3e9631e497da8dc59b971cbd0 (patch) | |
| tree | cbc6d4680e347d906f5fa7fca73214418741df72 /libdraw/loadimage.c | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'libdraw/loadimage.c')
| -rw-r--r-- | libdraw/loadimage.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/libdraw/loadimage.c b/libdraw/loadimage.c new file mode 100644 index 00000000..6c00a250 --- /dev/null +++ b/libdraw/loadimage.c @@ -0,0 +1,70 @@ +#include "lib9.h" +#include "draw.h" +#include "kernel.h" + +int +loadimage(Image *i, Rectangle r, uchar *data, int ndata) +{ + long dy; + int n, bpl, roff, dstroff, lskip, llen, y; + uchar *a; + int chunk; + Rectangle dstr; + + chunk = i->display->bufsize - 64; + + bpl = bytesperline(r, i->depth); + n = bpl*Dy(r); + if(n > ndata){ + kwerrstr("loadimage: insufficient data"); + return -1; + } + + dstr = r; + rectclip(&dstr, i->r); + rectclip(&dstr, i->clipr); + + if (!rectinrect(dstr, i->r)) + return 0; + + roff = (r.min.x*i->depth)>>3; + dstroff = dstr.min.x * i->depth >> 3; + lskip = dstroff - roff; + llen = (dstr.max.x*i->depth + 7 >> 3) - dstroff; + data += (dstr.min.y - r.min.y) * bpl + lskip; + + ndata = 0; + while(dstr.max.y > dstr.min.y){ + dy = dstr.max.y - dstr.min.y; + if(dy*llen > chunk) + dy = chunk/llen; + if(dy <= 0){ + kwerrstr("loadimage: image too wide for buffer"); + return -1; + } + n = dy*llen; + a = bufimage(i->display, 21+n); + if(a == nil){ + kwerrstr("bufimage failed"); + return -1; + } + a[0] = 'y'; + BPLONG(a+1, i->id); + BPLONG(a+5, dstr.min.x); + BPLONG(a+9, dstr.min.y); + BPLONG(a+13, dstr.max.x); + BPLONG(a+17, dstr.min.y+dy); + a += 21; + for (y = 0; y < dy; y++) { + memmove(a, data, llen); + a += llen; + ndata += llen; + data += bpl; + } + dstr.min.y += dy; + } + if(flushimage(i->display, 0) < 0) + return -1; + return ndata; +} + |
