15 ulong outchan = CMAP8;
24 char *show(int, char*);
26 Rawimage** readtga(int fd);
33 p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
34 p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
35 return rectaddpt(i->r, subpt(p2, p1));
43 if(new && getwindow(display, Refnone) < 0){
44 fprint(2, "tga: can't reattach to window\n");
50 border(screen, r, -Border, nil, ZP);
51 drawop(screen, r, image, nil, image->r.min, S);
52 flushimage(display, 1);
56 main(int argc, char *argv[])
62 case '3': /* produce encoded, compressed, three-color bitmap file; no display by default */
65 case 't': /* produce encoded, compressed, true-color bitmap file; no display by default */
72 case 'c': /* produce encoded, compressed, bitmap file; no display by default */
79 case 'd': /* suppress display of image */
82 case 'e': /* disable floyd-steinberg error diffusion */
85 case 'k': /* force black and white */
89 case 'v': /* force RGBV */
93 case '9': /* produce plan 9, uncompressed, bitmap file; no display by default */
101 fprint(2, "usage: tga -39cdektv [file ...]\n");
107 err = show(0, "<stdin>");
109 for(i=0; i<argc; i++){
110 fd = open(argv[i], OREAD);
112 fprint(2, "tga: can't open %s: %r\n", argv[i]);
115 err = show(fd, argv[i]);
118 if((nineflag || cflag) && argc>1 && err==nil){
119 fprint(2, "tga: exiting after one file\n");
133 if(initdraw(0, 0, 0) < 0){
134 fprint(2, "tga: initdraw failed: %r");
137 einit(Ekeyboard|Emouse);
144 show(int fd, char *name)
146 Rawimage **array, *r, *c;
152 if(array == nil || array[0]==nil){
153 fprint(2, "tga: decode %s failed: %r\n", name);
159 if(defaultcolor && screen->depth>8)
164 c = torgbv(r, !eflag);
166 if(outchan==GREY8 || (r->chandesc==CY && threeflag==0)){
167 c = totruecolor(r, CY);
170 c = totruecolor(r, CRGB24);
173 fprint(2, "tga: converting %s to local format failed: %r\n", name);
177 if(r->chandesc == CY)
178 i = allocimage(display, c->r, GREY8, 0, 0);
180 i = allocimage(display, c->r, outchan, 0, 0);
183 fprint(2, "tga: allocimage %s failed: %r\n", name);
187 if(loadimage(i, i->r, c->chans[0], c->chanlen) < 0){
188 fprint(2, "tga: loadimage %s failed: %r\n", name);
193 if((ch=ekbd())=='q' || ch==Kdel || ch==Keof)
195 draw(screen, screen->clipr, display->white, nil, ZP);
200 chantostr(buf, outchan);
201 print("%11s %11d %11d %11d %11d ", buf,
202 c->r.min.x, c->r.min.y, c->r.max.x, c->r.max.y);
203 if(write(1, c->chans[0], c->chanlen) != c->chanlen){
204 fprint(2, "tga: %s: write error %r\n", name);
208 if(writerawimage(1, c) < 0){
209 fprint(2, "tga: %s: write error: %r\n", name);
213 for(j=0; j<r->nchans; j++)