aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/scat/display.c
blob: 11642e59902daa61024f5cd1db5ffa58a61d181a (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <draw.h>
#include "sky.h"

void
displaypic(Picture *pic)
{
	int p[2];
	int i, n;
	uchar *a;
	

	if(pipe(p) < 0){
		fprint(2, "pipe failed: %r\n");
		return;
	}
	switch(rfork(RFPROC|RFFDG)){
	case -1:
		fprint(2, "fork failed: %r\n");
		return;

	case 0:
		close(p[1]);
		dup(p[0], 0);
		close(p[0]);
	//	execl("/bin/page", "page", "-w", 0);
		execlp("img", "img", 0);
		fprint(2, "exec failed: %r\n");
		exits("exec");

	default:
		close(p[0]);
		fprint(p[1], "%11s %11d %11d %11d %11d ",
			"k8", pic->minx, pic->miny, pic->maxx, pic->maxy);
		n = (pic->maxx-pic->minx)*(pic->maxy-pic->miny);
		/* release the memory as we hand it off; this could be a big piece of data */
		a = pic->data;
		while(n > 0){
			i = 8192 - (((int)a)&8191);
			if(i > n)
				i = n;
			if(write(p[1], a, i)!=i)
				fprint(2, "write error: %r\n");
		//	if(i == 8192)	/* page aligned */
		//		segfree(a, i);
			n -= i;
			a += i;
		}
		free(pic->data);
		free(pic);
		close(p[1]);
		break;
	}
}

void
displayimage(Image *im)
{
	int p[2];	

	if(pipe(p) < 0){
		fprint(2, "pipe failed: %r\n");
		return;
	}
	switch(rfork(RFPROC|RFFDG)){
	case -1:
		fprint(2, "fork failed: %r\n");
		return;

	case 0:
		close(p[1]);
		dup(p[0], 0);
		close(p[0]);
		execlp("img", "img", 0);
	//	execl("/bin/page", "page", "-w", 0);
		fprint(2, "exec failed: %r\n");
		exits("exec");

	default:
		close(p[0]);
		writeimage(p[1], im, 0);
		freeimage(im);
		close(p[1]);
		break;
	}
}