14 ulong outchan = CMAP8;
23 char *show(int, char*);
25 Rawimage** readbmp(int fd, int colorspace);
32 if(new && getwindow(display, Refnone) < 0){
33 fprint(2, "bmp: can't reattach to window\n");
38 r = rectaddpt(image->r, subpt(screen->r.min, image->r.min));
41 flushimage(display, 1);
47 fprint(2, "usage: bmp -39cdektv -W winsize [file.bmp ...]\n");
52 main(int argc, char *argv[])
59 winsize = EARGF(usage());
61 case '3': /* produce encoded, compressed, three-color bitmap file; no display by default */
64 case 't': /* produce encoded, compressed, true-color bitmap file; no display by default */
71 case 'c': /* produce encoded, compressed, bitmap file; no display by default */
78 case 'd': /* suppress display of image */
81 case 'e': /* disable floyd-steinberg error diffusion */
84 case 'k': /* force black and white */
88 case 'v': /* force RGBV */
92 case '9': /* produce plan 9, uncompressed, bitmap file; no display by default */
105 err = show(0, "<stdin>");
107 for(i=0; i<argc; i++){
108 fd = open(argv[i], OREAD);
110 fprint(2, "bmp: can't open %s: %r\n", argv[i]);
113 err = show(fd, argv[i]);
116 if((nineflag || cflag) && argc>1 && err==nil){
117 fprint(2, "bmp: exiting after one file\n");
131 if(initdraw(0, 0, 0) < 0){
132 fprint(2, "bmp: initdraw failed: %r");
135 einit(Ekeyboard|Emouse);
142 show(int fd, char *name)
144 Rawimage **array, *r, *c;
149 array = readbmp(fd, CRGB);
150 if(array == nil || array[0]==nil){
151 fprint(2, "bmp: decode %s failed: %r\n", name);
157 if(defaultcolor && screen->depth>8)
162 c = torgbv(r, !eflag);
164 if(outchan==GREY8 || (r->chandesc==CY && threeflag==0))
165 c = totruecolor(r, CY);
167 c = totruecolor(r, CRGB24);
170 fprint(2, "bmp: converting %s to local format failed: %r\n", name);
174 if(r->chandesc == CY)
175 i = allocimage(display, c->r, GREY8, 0, 0);
177 i = allocimage(display, c->r, outchan, 0, 0);
179 fprint(2, "bmp: allocimage %s failed: %r\n", name);
182 if(loadimage(i, i->r, c->chans[0], c->chanlen) < 0){
183 fprint(2, "bmp: loadimage %s failed: %r\n", name);
188 if((ch=ekbd())=='q' || ch==0x7F || ch==0x04)
190 draw(screen, screen->clipr, display->white, nil, ZP);
195 chantostr(buf, outchan);
196 print("%11s %11d %11d %11d %11d ", buf,
197 c->r.min.x, c->r.min.y, c->r.max.x, c->r.max.y);
198 if(write(1, c->chans[0], c->chanlen) != c->chanlen){
199 fprint(2, "bmp: %s: write error %r\n", name);
203 if(writerawimage(1, c) < 0){
204 fprint(2, "bmp: %s: write error: %r\n", name);
208 for(j=0; j<r->nchans; j++)