--- ray/src/px/ra_t8.c 1991/04/18 14:35:45 1.9 +++ ray/src/px/ra_t8.c 1991/11/12 16:05:11 2.1 @@ -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"; @@ -15,6 +15,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" +#include "resolu.h" + #include "pic.h" #include "targa.h" @@ -51,8 +53,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 +99,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; @@ -127,11 +136,11 @@ char *argv[]; printargs(i, argv, stdout); fputformat(COLRFMT, stdout); putchar('\n'); - fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); + fprtresolu(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]); @@ -154,9 +163,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); } @@ -285,7 +294,7 @@ register struct hdStruct *h; return(NULL); /* get header info. */ if (checkheader(p->fp, COLRFMT, NULL) < 0 || - fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) + fgetresolu(&xmax, &ymax, p->fp) < 0) quiterr("bad picture format"); p->nexty = 0; p->bytes_line = 0; /* variable length lines */ @@ -325,8 +334,10 @@ struct hdStruct *hp; register int i, j; /* get color table */ - if ((hp->CMapBits==24 ? fread((char *)map.c3,sizeof(map.c3),1,stdin) : - fread((char *)map.c4,sizeof(map.c4),1,stdin)) != 1) + if ((hp->CMapBits==24 ? fread((char *)(map.c3+hp->mapOrig), + 3*hp->mapLength,1,stdin) : + fread((char *)(map.c4+hp->mapOrig), + 4*hp->mapLength,1,stdin)) != 1) quiterr("error reading color table"); /* convert table */ for (i = hp->mapOrig; i < hp->mapOrig+hp->mapLength; i++) @@ -340,7 +351,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 */ @@ -383,7 +395,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];