14 ulong outchan = CMAP8;
23 char *show(int, char*);
30 if(new && getwindow(display, Refnone) < 0){
31 fprint(2, "ppm: can't reattach to window\n");
36 r = insetrect(screen->clipr, Edge+Border);
37 r.max.x = r.min.x+Dx(image->r);
38 r.max.y = r.min.y+Dy(image->r);
39 border(screen, r, -Border, nil, ZP);
40 drawop(screen, r, image, nil, image->r.min, S);
41 flushimage(display, 1);
45 main(int argc, char *argv[])
51 case '3': /* produce encoded, compressed, three-color bitmap file; no display by default */
54 case 't': /* produce encoded, compressed, true-color bitmap file; no display by default */
61 case 'c': /* produce encoded, compressed, bitmap file; no display by default */
68 case 'd': /* suppress display of image */
71 case 'e': /* disable floyd-steinberg error diffusion */
74 case 'k': /* force black and white */
78 case 'v': /* force RGBV */
82 case '9': /* produce plan 9, uncompressed, bitmap file; no display by default */
90 fprint(2, "usage: ppm -39cdektv [file.ppm ...]\n");
96 err = show(0, "<stdin>");
98 for(i=0; i<argc; i++){
99 fd = open(argv[i], OREAD);
101 fprint(2, "ppm: can't open %s: %r\n", argv[i]);
104 err = show(fd, argv[i]);
107 if((nineflag || cflag) && argc>1 && err==nil){
108 fprint(2, "ppm: exiting after one file\n");
122 if(initdraw(0, 0, 0) < 0){
123 fprint(2, "ppm: initdraw failed: %r");
126 einit(Ekeyboard|Emouse);
133 show(int fd, char *name)
135 Rawimage **array, *r, *c;
140 array = readpixmap(fd, CRGB);
141 if(array == nil || array[0]==nil){
142 fprint(2, "ppm: decode %s failed: %r\n", name);
148 if(defaultcolor && screen->depth>8)
153 c = torgbv(r, !eflag);
155 if(outchan==GREY8 || (r->chandesc==CY && threeflag==0))
156 c = totruecolor(r, CY);
158 c = totruecolor(r, CRGB24);
161 fprint(2, "ppm: converting %s to local format failed: %r\n", name);
165 if(r->chandesc == CY)
167 i = allocimage(display, c->r, outchan, 0, 0);
169 fprint(2, "ppm: allocimage %s failed: %r\n", name);
172 if(loadimage(i, i->r, c->chans[0], c->chanlen) < 0){
173 fprint(2, "ppm: loadimage %s failed: %r\n", name);
178 if((ch=ekbd())=='q' || ch==0x7F || ch==0x04)
180 draw(screen, screen->clipr, display->white, nil, ZP);
185 if(r->chandesc == CY)
187 chantostr(buf, outchan);
188 print("%11s %11d %11d %11d %11d ", buf,
189 c->r.min.x, c->r.min.y, c->r.max.x, c->r.max.y);
190 if(write(1, c->chans[0], c->chanlen) != c->chanlen){
191 fprint(2, "ppm: %s: write error %r\n", name);
195 if(writerawimage(1, c) < 0){
196 fprint(2, "ppm: %s: write error: %r\n", name);
200 for(j=0; j<r->nchans; j++)