blob: 09c0061377a8603c8efd88e4acd1731c66bc4d5a (
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
|
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>
#include <ctype.h>
#include <bio.h>
#include <flate.h>
#include "imagefile.h"
void
usage(void)
{
fprint(2, "usage: topng [-c 'comment'] [-g 'gamma'] [file]\n");
exits("usage");
}
void
main(int argc, char *argv[])
{
Biobuf bout;
Memimage *i;
int fd;
char *err, *filename;
ImageInfo II;
ARGBEGIN{
case 'c':
II.comment = ARGF();
if(II.comment == nil)
usage();
II.fields_set |= II_COMMENT;
break;
case 'g':
II.gamma = atof(ARGF());
if(II.gamma == 0.)
usage();
II.fields_set |= II_GAMMA;
break;
case 't':
break;
default:
usage();
}ARGEND
if(Binit(&bout, 1, OWRITE) < 0)
sysfatal("Binit failed: %r");
memimageinit();
if(argc == 0){
fd = 0;
filename = "<stdin>";
}else{
fd = open(argv[0], OREAD);
if(fd < 0)
sysfatal("can't open %s: %r", argv[0]);
filename = argv[0];
}
i = readmemimage(fd);
if(i == nil)
sysfatal("can't readimage %s: %r", filename);
close(fd);
err = memwritepng(&bout, i, &II);
freememimage(i);
if(err != nil)
fprint(2, "topng: %s\n", err);
exits(err);
}
|