--- ray/src/px/ra_t16.c 1990/10/20 11:49:02 1.9 +++ ray/src/px/ra_t16.c 1991/12/19 14:52:20 2.2 @@ -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 "random.h" #include "targa.h" @@ -32,10 +34,12 @@ static char SCCSid[] = "$SunId$ LBL"; extern char *ecalloc(), *emalloc(); -extern double atof(), pow(); +extern double pow(); -double gamma = 2.0; /* gamma correction */ +double gamma = 2.2; /* gamma correction */ +int bradj = 0; /* brightness adjustment */ + char *progname; char msg[128]; @@ -67,6 +71,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; } @@ -96,13 +105,14 @@ char *argv[]; quiterr("incompatible format"); /* put header */ printargs(i, argv, stdout); + fputformat(COLRFMT, stdout); putchar('\n'); - fputresolu(YMAJOR|YDECR, head.x, head.y, stdout); + fprtresolu(head.x, head.y, stdout); /* convert file */ tg2ra(&head); } else { - getheader(stdin, NULL); - if (fgetresolu(&head.x, &head.y, stdin) != (YMAJOR|YDECR)) + if (checkheader(stdin, COLRFMT, NULL) < 0 || + fgetresolu(&head.x, &head.y, stdin) < 0) quiterr("bad picture file"); /* assign header */ head.textSize = 0; @@ -118,7 +128,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); } @@ -266,6 +276,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"); } @@ -287,22 +299,31 @@ 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; dp = (unsigned char *)tarData + j*3*hp->x; for (i = 0; i < hp->x; i++) { - *dp++ = inl[i][RED]; - *dp++ = inl[i][GRN]; *dp++ = inl[i][BLU]; + *dp++ = inl[i][GRN]; + *dp++ = inl[i][RED]; } } }