24 char *show(int, char *, int);
31 p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
32 p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
33 return rectaddpt(i->r, subpt(p2, p1));
41 if(new && getwindow(display, Refnone) < 0)
42 sysfatal("getwindow: %r");
46 border(screen, r, -Border, nil, ZP);
47 drawop(screen, r, image, nil, image->r.min, S);
48 flushimage(display, 1);
54 fprint(2, "usage: %s [-39cdektv] [file.tif ...]\n", argv0);
59 main(int argc, char *argv[])
68 * produce encoded, compressed, bitmap file;
69 * no display by default
78 /* suppress display of image */
82 /* disable floyd-steinberg error diffusion */
86 /* force black and white */
92 * produce encoded, compressed, three-color
93 * bitmap file; no display by default
99 * produce encoded, compressed, true-color
100 * bitmap file; no display by default
115 * produce plan 9, uncompressed, bitmap file;
116 * no display by default
130 exits(show(0, "<stdin>", outchan));
132 for(i = 0; i < argc; i++) {
133 if((fd = open(argv[i], OREAD)) < 0) {
134 fprint(2, "%s: open %s: %r\n",
138 err = show(fd, argv[i], outchan);
141 if((nineflag || cflag) && argc > 1 && err == nil) {
142 fprint(2, "%s: exiting after one file\n",
153 static int inited = 0;
156 if(initdraw(0, 0, 0) < 0) {
157 fprint(2, "%s: initdraw: %r", argv0);
160 einit(Ekeyboard|Emouse);
167 show(int fd, char *name, int outchan)
169 Rawimage **array, *r, *c;
175 if(Binit(&b, fd, OREAD) < 0)
177 array = Breadtif(&b, CRGB24);
178 if(array == nil || array[0] == nil) {
181 fprint(2, "%s: decode %s failed: %r\n",
189 if(defaultcolor && screen->depth > 8)
193 if(outchan != CMAP8) {
194 switch(r->chandesc) {
203 } else if((c = torgbv(r, !eflag)) == nil) {
204 fprint(2, "%s: conversion of %s failed: %r\n",
209 i = allocimage(display, c->r, outchan, 0, 0);
211 fprint(2, "%s: allocimage %s: %r\n",
215 if(loadimage(i, i->r, c->chans[0],
217 fprint(2, "%s: loadimage %s: %r\n",
224 if(ch == 'q' || ch == Kdel || ch == Keof)
226 draw(screen, screen->clipr, display->white,
232 chantostr(buf, outchan);
233 print("%11s %11d %11d %11d %11d ", buf,
234 c->r.min.x, c->r.min.y,
235 c->r.max.x, c->r.max.y);
236 if(write(1, c->chans[0], c->chanlen) !=
238 fprint(2, "%s: %s: write error: %r\n",
242 } else if(cflag && writerawimage(1, c) < 0) {
243 fprint(2, "%s: %s: write error: %r\n",
247 if(c != nil && c != r) {
251 for(j = 0; j < r->nchans; j++)