File: load.c

package info (click to toggle)
drawterm-9front 0~git20220608.bee4db6-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,256 kB
  • sloc: ansic: 57,635; makefile: 607; java: 492; objc: 436; xml: 174; asm: 19
file content (55 lines) | stat: -rw-r--r-- 1,032 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>
#include <memlayer.h>

int
memload(Memimage *dst, Rectangle r, uchar *data, int n, int iscompressed)
{
	int (*loadfn)(Memimage*, Rectangle, uchar*, int);
	Memimage *tmp;
	Memlayer *dl;
	Rectangle lr;
	int dx;

	loadfn = loadmemimage;
	if(iscompressed)
		loadfn = cloadmemimage;

    Top:
	dl = dst->layer;
	if(dl == nil)
		return loadfn(dst, r, data, n);

	/*
 	 * Convert to screen coordinates.
	 */
	lr = r;
	r.min.x += dl->delta.x;
	r.min.y += dl->delta.y;
	r.max.x += dl->delta.x;
	r.max.y += dl->delta.y;
	dx = dl->delta.x&(7/dst->depth);
	if(dl->clear && dx==0){
		dst = dl->screen->image;
		goto Top;
	}

	/*
	 * dst is an obscured layer or data is unaligned
	 */
	if(dl->save && dx==0){
		n = loadfn(dl->save, lr, data, n);
		if(n > 0)
			memlexpose(dst, r);
		return n;
	}
	tmp = allocmemimage(lr, dst->chan);
	if(tmp == nil)
		return -1;
	n = loadfn(tmp, lr, data, n);
	memdraw(dst, lr, tmp, lr.min, nil, lr.min, S);
	freememimage(tmp);
	return n;
}