summaryrefslogtreecommitdiff
path: root/appl/grid/jpg2bit.b
blob: 9c452edd383c62afc15b4bc58710523e590200db (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
implement jpg2bit;

include "sys.m";
	sys : Sys;

include "draw.m";
	draw: Draw;
	Context, Display, Point, Rect, Image, Screen, Font: import draw;

include "grid/readjpg.m";
	readjpg: Readjpg;

display : ref draw->Display;
screen : ref draw->Screen;
context : ref draw->Context;

jpg2bit : module {
	init : fn (ctxt : ref Draw->Context, argv : list of string);
};

init(ctxt : ref Draw->Context, argv : list of string)
{
	display = ctxt.display;
	screen = ctxt.screen;
	context = ctxt;

	sys = load Sys Sys->PATH;
	readjpg = load Readjpg Readjpg->PATH;
	readjpg->init(display);
	
	draw = load Draw Draw->PATH;
	argv = tl argv;
	if (argv == nil) exit;
	filename := hd argv;
	filename2 : string;
	if (tl argv == nil) {
		if (len filename > 3) filename2 = filename[:len filename - 4];
		filename2 += ".bit";
	}
	else filename2 = hd tl argv;
	img := readjpg->jpg2img(hd argv, "", chan of string, nil);
	fd := sys->create(filename2, sys->OWRITE,8r666);
	if (fd != nil)
		display.writeimage(fd,img);

}