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
|
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>
#include <pool.h>
static int invert = 0;
void
main(int argc, char **argv)
{
Memimage *im, *om;
char *s;
ulong ofmt;
ofmt = 0;
ARGBEGIN{
case 'i':
invert = 1;
break;
case 'c':
s = ARGF();
if(s==nil)
break;
ofmt = strtochan(s);
if(ofmt == 0){
fprint(2, "cvbit: bad chan: %s\n", s);
exits("chan");
}
break;
}ARGEND
memimageinit();
im = readmemimage(0);
if(im == nil){
fprint(2, "cvbit: can't read image: %r\n");
exits("read");
}
if(ofmt){
om = allocmemimage(im->r, ofmt);
if(om == nil){
fprint(2, "cvbit: can't allocate new image: %r\n");
exits("alloc");
}
memimagedraw(om, om->r, im, im->r.min, nil, ZP, S);
}else
om = im;
if(invert){
uchar *buf;
int bpl, y, x;
bpl = bytesperline(om->r, om->depth);
buf = malloc(bpl);
for(y=om->r.min.y; y<om->r.max.y; y++){
if(unloadmemimage(om, Rpt(Pt(om->r.min.x,y), Pt(om->r.max.x,y+1)), buf, bpl) != bpl){
fprint(2, "cvbit: can't unload image line\n");
exits("unload");
}
for(x=0; x<bpl; x++)
buf[x] ^= 0xFF;
if(loadmemimage(om, Rpt(Pt(om->r.min.x,y), Pt(om->r.max.x,y+1)), buf, bpl) != bpl){
fprint(2, "cvbit: can't load image line\n");
exits("load");
}
}
}
if(writememimage(1, om) < 0){
fprint(2, "cvbit: can't write image: %r\n");
exits("write");
}
exits(nil);
}
char*
poolname(Pool *p)
{
USED(p);
return "none";
}
void
poolsetcompact(Pool *p, void (*f)(void*, void*))
{
USED(p);
USED(f);
}
|