load.c (1031B)
1 #include "u.h" 2 #include "lib.h" 3 #include "draw.h" 4 #include "memdraw.h" 5 #include "memlayer.h" 6 7 int 8 memload(Memimage *dst, Rectangle r, uchar *data, int n, int iscompressed) 9 { 10 int (*loadfn)(Memimage*, Rectangle, uchar*, int); 11 Memimage *tmp; 12 Memlayer *dl; 13 Rectangle lr; 14 int dx; 15 16 loadfn = loadmemimage; 17 if(iscompressed) 18 loadfn = cloadmemimage; 19 20 Top: 21 dl = dst->layer; 22 if(dl == nil) 23 return loadfn(dst, r, data, n); 24 25 /* 26 * Convert to screen coordinates. 27 */ 28 lr = r; 29 r.min.x += dl->delta.x; 30 r.min.y += dl->delta.y; 31 r.max.x += dl->delta.x; 32 r.max.y += dl->delta.y; 33 dx = dl->delta.x&(7/dst->depth); 34 if(dl->clear && dx==0){ 35 dst = dl->screen->image; 36 goto Top; 37 } 38 39 /* 40 * dst is an obscured layer or data is unaligned 41 */ 42 if(dl->save && dx==0){ 43 n = loadfn(dl->save, lr, data, n); 44 if(n > 0) 45 memlexpose(dst, r); 46 return n; 47 } 48 tmp = allocmemimage(lr, dst->chan); 49 if(tmp == nil) 50 return -1; 51 n = loadfn(tmp, lr, data, n); 52 memdraw(dst, lr, tmp, lr.min, nil, lr.min, S); 53 freememimage(tmp); 54 return n; 55 }