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 = insetrect(screen->clipr, Edge+Border);
39 r.max.x = r.min.x+Dx(image->r);
40 r.max.y = r.min.y+Dy(image->r);
41 border(screen, r, -Border, nil, ZP);
42 drawop(screen, r, image, nil, image->r.min, S);
43 flushimage(display, 1);
47 main(int argc, char *argv[])
53 case '3': /* produce encoded, compressed, three-color bitmap file; no display by default */
56 case 't': /* produce encoded, compressed, true-color bitmap file; no display by default */
63 case 'c': /* produce encoded, compressed, bitmap file; no display by default */
70 case 'd': /* suppress display of image */
73 case 'e': /* disable floyd-steinberg error diffusion */
76 case 'k': /* force black and white */
80 case 'v': /* force RGBV */
84 case '9': /* produce plan 9, uncompressed, bitmap file; no display by default */
92 fprint(2, "usage: bmp -39cdektv [file.bmp ...]\n");
98 err = show(0, "<stdin>");
100 for(i=0; i<argc; i++){
101 fd = open(argv[i], OREAD);
103 fprint(2, "bmp: can't open %s: %r\n", argv[i]);
106 err = show(fd, argv[i]);
109 if((nineflag || cflag) && argc>1 && err==nil){
110 fprint(2, "bmp: exiting after one file\n");
124 if(initdraw(0, 0, 0) < 0){
125 fprint(2, "bmp: initdraw failed: %r");
128 einit(Ekeyboard|Emouse);
135 show(int fd, char *name)
137 Rawimage **array, *r, *c;
142 array = readbmp(fd, CRGB);
143 if(array == nil || array[0]==nil){
144 fprint(2, "bmp: decode %s failed: %r\n", name);
150 if(defaultcolor && screen->depth>8)
155 c = torgbv(r, !eflag);
157 if(outchan==GREY8 || (r->chandesc==CY && threeflag==0))
158 c = totruecolor(r, CY);
160 c = totruecolor(r, CRGB24);
163 fprint(2, "bmp: converting %s to local format failed: %r\n", name);
167 if(r->chandesc == CY)
168 i = allocimage(display, c->r, GREY8, 0, 0);
170 i = allocimage(display, c->r, outchan, 0, 0);
172 fprint(2, "bmp: allocimage %s failed: %r\n", name);
175 if(loadimage(i, i->r, c->chans[0], c->chanlen) < 0){
176 fprint(2, "bmp: loadimage %s failed: %r\n", name);
181 if((ch=ekbd())=='q' || ch==0x7F || ch==0x04)
183 draw(screen, screen->clipr, display->white, nil, ZP);
188 chantostr(buf, outchan);
189 print("%11s %11d %11d %11d %11d ", buf,
190 c->r.min.x, c->r.min.y, c->r.max.x, c->r.max.y);
191 if(write(1, c->chans[0], c->chanlen) != c->chanlen){
192 fprint(2, "bmp: %s: write error %r\n", name);
196 if(writerawimage(1, c) < 0){
197 fprint(2, "bmp: %s: write error: %r\n", name);
201 for(j=0; j<r->nchans; j++)