--- ray/src/px/ra_t16.c 1991/05/17 08:41:52 1.12 +++ ray/src/px/ra_t16.c 2003/06/05 19:29:34 2.7 @@ -1,9 +1,6 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: ra_t16.c,v 2.7 2003/06/05 19:29:34 schorsch Exp $"; #endif - /* * ra_t16.c - program to convert between RADIANCE and * Targa 16, 24 and 32-bit images. @@ -12,11 +9,13 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include +#include +#include +#include "platform.h" #include "color.h" - +#include "resolu.h" #include "random.h" - #include "targa.h" #define goodpic(h) (((h)->dataType==IM_RGB || (h)->dataType==IM_CRGB) \ @@ -32,9 +31,9 @@ static char SCCSid[] = "$SunId$ LBL"; extern char *ecalloc(), *emalloc(); -extern double atof(), pow(); +double gamcor = 2.2; /* gamma correction */ -double gamma = 2.0; /* gamma correction */ +int bradj = 0; /* brightness adjustment */ char *progname; @@ -48,7 +47,9 @@ char *argv[]; struct hdStruct head; int reverse = 0; int i; - + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdin); + SET_FILE_BINARY(stdout); progname = argv[0]; head.dataBits = 16; @@ -56,7 +57,7 @@ char *argv[]; if (argv[i][0] == '-') switch (argv[i][1]) { case 'g': - gamma = atof(argv[++i]); + gamcor = atof(argv[++i]); break; case 'r': reverse = !reverse; @@ -67,6 +68,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; } @@ -86,7 +92,7 @@ char *argv[]; quiterr(msg); } /* set gamma */ - setcolrgam(gamma); + setcolrgam(gamcor); /* convert */ if (reverse) { /* get header */ @@ -95,15 +101,16 @@ char *argv[]; if (!goodpic(&head)) quiterr("incompatible format"); /* put header */ + newheader("RADIANCE", stdout); 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 { if (checkheader(stdin, COLRFMT, NULL) < 0 || - fgetresolu(&head.x, &head.y, stdin) != (YMAJOR|YDECR)) + fgetresolu(&head.x, &head.y, stdin) < 0) quiterr("bad picture file"); /* assign header */ head.textSize = 0; @@ -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); } @@ -155,6 +162,7 @@ char *err; } +void eputs(s) char *s; { @@ -162,6 +170,7 @@ char *s; } +void quit(code) int code; { @@ -267,11 +276,13 @@ 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"); } - free((char *)scanline); - free((char *)tarData); + free((void *)scanline); + free((void *)tarData); } @@ -288,6 +299,8 @@ 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; @@ -317,8 +330,8 @@ struct hdStruct *hp; /* write out targa data */ writetarga(hp, tarData, stdout); - free((char *)inl); - free((char *)tarData); + free((void *)inl); + free((void *)tarData); }