15 ulong outchan = CMAP8;
24 char *show(int, char*);
26 Rawimage** readyuv(int fd, int colorspace);
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, "yuv: 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: yuv -39cdektv [file.yuv ...]\n");
107 err = show(0, "<stdin>");
109 for(i=0; i<argc; i++){
110 fd = open(argv[i], OREAD);
112 fprint(2, "yuv: 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, "yuv: exiting after one file\n");
133 if(initdraw(0, 0, 0) < 0){
134 fprint(2, "yuv: initdraw failed: %r");
137 einit(Ekeyboard|Emouse);
144 show(int fd, char *name)
146 Rawimage **array, *r, *c;
151 array = readyuv(fd, CYCbCr);
152 if(array == nil || array[0]==nil){
153 fprint(2, "yuv: 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);
169 c = totruecolor(r, CRGB24);
172 fprint(2, "yuv: converting %s to local format failed: %r\n", name);
176 if(r->chandesc == CY)
177 i = allocimage(display, c->r, GREY8, 0, 0);
179 i = allocimage(display, c->r, outchan, 0, 0);
181 fprint(2, "yuv: allocimage %s failed: %r\n", name);
184 if(loadimage(i, i->r, c->chans[0], c->chanlen) < 0){
185 fprint(2, "yuv: loadimage %s failed: %r\n", name);
190 if((ch=ekbd())=='q' || ch==Kdel || ch==Keof)
192 draw(screen, screen->clipr, display->white, nil, ZP);
197 chantostr(buf, outchan);
198 print("%11s %11d %11d %11d %11d ", buf,
199 c->r.min.x, c->r.min.y, c->r.max.x, c->r.max.y);
200 if(write(1, c->chans[0], c->chanlen) != c->chanlen){
201 fprint(2, "yuv: %s: write error %r\n", name);
205 if(writerawimage(1, c) < 0){
206 fprint(2, "yuv: %s: write error: %r\n", name);
210 for(j=0; j<r->nchans; j++)