--- ray/src/px/ra_t16.c 1991/04/18 14:35:42 1.11 +++ ray/src/px/ra_t16.c 1991/08/07 08:36:35 1.13 @@ -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"; @@ -36,6 +36,8 @@ extern double atof(), pow(); double gamma = 2.0; /* gamma correction */ +int bradj = 0; /* brightness adjustment */ + char *progname; char msg[128]; @@ -67,6 +69,11 @@ char *argv[]; case '3': head.dataBits = 24; break; + case 'e': + if (argv[i+1][0] != '+' && argv[i+1][0] != '-') + goto userr; + bradj = atoi(argv[++i]); + break; default: goto userr; } @@ -119,7 +126,7 @@ char *argv[]; } exit(0); userr: - fprintf(stderr, "Usage: %s [-2|-3|-r][-g gamma] [input [output]]\n", + fprintf(stderr, "Usage: %s [-2|-3|-r][-g gamma][-e +/-stops] [input [output]]\n", progname); exit(1); } @@ -267,6 +274,8 @@ struct hdStruct *hp; } } gambs_colrs(scanline, hp->x); + if (bradj) + shiftcolrs(scanline, hp->x, bradj); if (fwritecolrs(scanline, hp->x, stdout) < 0) quiterr("error writing RADIANCE file"); } @@ -288,14 +297,23 @@ struct hdStruct *hp; for (j = hp->y-1; j >= 0; j--) { if (freadcolrs(inl, hp->x, stdin) < 0) quiterr("error reading RADIANCE file"); + if (bradj) + shiftcolrs(inl, hp->x, bradj); colrs_gambs(inl, hp->x); if (hp->dataBits == 16) { register unsigned short *dp; + register int v; dp = (unsigned short *)tarData + j*hp->x; for (i = 0; i < hp->x; i++) { - *dp = ((inl[i][RED]+(random()&7)) & 0xf8)<<7; - *dp |= ((inl[i][GRN]+(random()&7)) & 0xf8)<<2; - *dp++ |= (inl[i][BLU]+(random()&7))>>3; + v = inl[i][RED] + (random()&7); + if (v > 255) v = 255; + *dp = (v&0xf8)<<7; + v = inl[i][GRN] + (random()&7); + if (v > 255) v = 255; + *dp |= (v&0xf8)<<2; + v = inl[i][BLU] + (random()&7); + if (v > 255) v = 255; + *dp++ |= v>>3; } } else { /* hp->dataBits == 24 */ register unsigned char *dp;