--- ray/src/px/ra_t8.c 1990/03/12 15:14:46 1.7 +++ ray/src/px/ra_t8.c 1991/08/23 13:40:01 1.11 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -51,8 +51,10 @@ extern long ftell(); extern double atof(), pow(); -double gamma = 2.0; /* gamma correction */ +double gamma = 2.2; /* gamma correction */ +int bradj = 0; /* brightness adjustment */ + pic *inpic; char *progname; @@ -95,6 +97,11 @@ char *argv[]; case 'b': greyscale = 1; break; + case 'e': + if (argv[i+1][0] != '+' && argv[i+1][0] != '-') + goto userr; + bradj = atoi(argv[++i]); + break; case 'c': ncolors = atoi(argv[++i]); break; @@ -125,12 +132,13 @@ char *argv[]; } /* put header */ printargs(i, argv, stdout); + fputformat(COLRFMT, stdout); putchar('\n'); fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); /* convert file */ tg2ra(&head); } else { - if (i > argc-1 || i < argc-2) + if (i < argc-2 || (!greyscale && i > argc-1)) goto userr; if ((inpic = openinput(argv[i], &head)) == NULL) { sprintf(errmsg, "can't open input \"%s\"", argv[i]); @@ -153,9 +161,9 @@ char *argv[]; quiterr(NULL); userr: fprintf(stderr, - "Usage: %s [-d][-c ncolors][-b][-g gamma] input [output]\n", + "Usage: %s [-d][-c ncolors][-b][-g gamma][-e +/-stops] input [output]\n", progname); - fprintf(stderr, " Or: %s -r [-g gamma] [input [output]]\n", + fprintf(stderr, " Or: %s -r [-g gamma][-e +/-stops] [input [output]]\n", progname); exit(1); } @@ -282,10 +290,10 @@ register struct hdStruct *h; p->fp = stdin; else if ((p->fp = fopen(fname, "r")) == NULL) return(NULL); - /* discard header */ - getheader(p->fp, NULL); - if (fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) - quiterr("bad picture size"); + /* get header info. */ + if (checkheader(p->fp, COLRFMT, NULL) < 0 || + fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) + quiterr("bad picture format"); p->nexty = 0; p->bytes_line = 0; /* variable length lines */ p->pos.y = (long *)ecalloc(ymax, sizeof(long)); @@ -339,7 +347,8 @@ struct hdStruct *hp; pow((map.c4[i][3]+.5)/256.,gamma), pow((map.c4[i][2]+.5)/256.,gamma), pow((map.c4[i][1]+.5)/256.,gamma)); - + if (bradj) + shiftcolrs(ctab, 256, bradj); /* allocate targa data */ tarData = taralloc(hp); /* get data */ @@ -382,7 +391,7 @@ register rgbpixel *l3; quiterr("read error in picreadline3"); inpic->nexty = y+1; /* convert scanline */ - normcolrs(inl, xmax, 0); + normcolrs(inl, xmax, bradj); for (i = 0; i < xmax; i++) { l3[i].r = inl[i][RED]; l3[i].g = inl[i][GRN]; @@ -465,7 +474,7 @@ colormap map; register int i, val; for (i = 0; i < 256; i++) { - val = pow(i/256.0, 1.0/gamma) * 256.0; + val = pow((i+0.5)/256.0, 1.0/gamma) * 256.0; map[0][i] = map[1][i] = map[2][i] = val; } }