int cflag = 0;
int dflag = 0;
int eflag = 0;
int jflag = 0;
int fflag = 0;
int Fflag = 0;
int nineflag = 0;
int threeflag = 0;
int colorspace = CYCbCr; /* default for 8-bit displays: combine color rotation with dither */
int output = 0;
ulong outchan = CMAP8;
Image *image;
int defaultcolor = 1;
void
main(int argc, char *argv[])
{
int fd, i, yflag;
char *err;
char buf[12+1];
yflag = 0;
ARGBEGIN{
case 'c': /* produce encoded, compressed, bitmap file; no display by default */
cflag++;
dflag++;
output++;
if(defaultcolor)
outchan = CMAP8;
break;
case 'd': /* suppress display of image */
dflag++;
break;
case 'e': /* disable floyd-steinberg error diffusion */
eflag++;
break;
case 'F':
Fflag++; /* make a movie */
fflag++; /* merge two fields per image */
break;
case 'f':
fflag++; /* merge two fields per image */
break;
case 'J': /* decode jpeg only; no display or remap (for debugging, etc.) */
jflag++;
break;
case 'k': /* force black and white */
defaultcolor = 0;
outchan = GREY8;
break;
case 'r':
colorspace = CRGB;
break;
case '3': /* produce encoded, compressed, three-color bitmap file; no display by default */
threeflag++;
/* fall through */
case 't': /* produce encoded, compressed, true-color bitmap file; no display by default */
cflag++;
dflag++;
output++;
defaultcolor = 0;
outchan = RGB24;
break;
case 'v': /* force RGBV */
defaultcolor = 0;
outchan = CMAP8;
break;
case 'y': /* leave it in CYCbCr; for debugging only */
yflag = 1;
colorspace = CYCbCr;
break;
case '9': /* produce plan 9, uncompressed, bitmap file; no display by default */
nineflag++;
dflag++;
output++;
if(defaultcolor)
outchan = CMAP8;
break;
default:
fprint(2, "usage: jpg -39cdefFkJrtv [file.jpg ...]\n");
exits("usage");
}ARGEND;
if(yflag==0 && dflag==0 && colorspace==CYCbCr){ /* see if we should convert right to RGB */
fd = open("/dev/screen", OREAD);
if(fd > 0){
buf[12] = '\0';
if(read(fd, buf, 12)==12 && chantodepth(strtochan(buf))>8)
colorspace = CRGB;
close(fd);
}
}