--- ray/src/px/pextrem.c 2004/01/02 12:47:01 2.9 +++ ray/src/px/pextrem.c 2022/02/04 20:11:49 2.15 @@ -1,14 +1,13 @@ #ifndef lint -static const char RCSid[] = "$Id: pextrem.c,v 2.9 2004/01/02 12:47:01 schorsch Exp $"; +static const char RCSid[] = "$Id: pextrem.c,v 2.15 2022/02/04 20:11:49 greg Exp $"; #endif /* * Find extrema points in a Radiance picture. */ -#include #include -#include +#include "rtio.h" #include "platform.h" #include "color.h" #include "resolu.h" @@ -16,10 +15,10 @@ static const char RCSid[] = "$Id: pextrem.c,v 2.9 2004 int orig = 0; -int wrongformat = 0; - COLOR expos = WHTCOLOR; +char fmt[MAXFMTLEN]; + static gethfunc headline; @@ -29,14 +28,11 @@ headline( /* check header line */ void *p ) { - char fmt[32]; double d; COLOR ctmp; - if (isformat(s)) { /* format */ - formatval(fmt, s); - wrongformat = !globmatch(PICFMT, fmt); - } + if (formatval(fmt, s)) /* format */ + return(0); if (!orig) return(0); if (isexpos(s)) { /* exposure */ @@ -50,9 +46,11 @@ headline( /* check header line */ } -main(argc, argv) -int argc; -char *argv[]; +int +main( + int argc, + char *argv[] +) { int i; int xres, yres; @@ -65,7 +63,9 @@ char *argv[]; SET_FILE_BINARY(stdin); for (i = 1; i < argc; i++) /* get options */ if (!strcmp(argv[i], "-o")) - orig++; + orig = 1; + else if (!strcmp(argv[i], "-O")) + orig = -1; else break; @@ -75,17 +75,19 @@ char *argv[]; exit(1); } /* get our header */ - if (getheader(stdin, headline, NULL) < 0 || wrongformat || + if (getheader(stdin, headline, NULL) < 0 || !globmatch(PICFMT, fmt) || fgetresolu(&xres, &yres, stdin) < 0) { fprintf(stderr, "%s: bad picture format\n", argv[0]); exit(1); } + if (orig < 0 && !strcmp(CIEFMT, fmt)) + scalecolor(expos, 1./WHTEFFICACY); if ((scan = (COLR *)malloc(xres*sizeof(COLR))) == NULL) { fprintf(stderr, "%s: out of memory\n", argv[0]); exit(1); } - setcolr(cmin, 1e10, 1e10, 1e10); - setcolr(cmax, 0., 0., 0.); + setcolr(cmin, 1e30, 1e30, 1e30); + setcolr(cmax, 0., 0., 0.); xmax=ymax=0; /* find extrema */ for (y = yres-1; y >= 0; y--) { if (freadcolrs(scan, xres, stdin) < 0) { @@ -110,11 +112,11 @@ char *argv[]; } } free((void *)scan); - printf("%d %d\t%e %e %e\n", xmin, ymin, + printf("%d %d\t%.2e %.2e %.2e\n", xmin, ymin, colrval(cmin,RED)/colval(expos,RED), colrval(cmin,GRN)/colval(expos,GRN), colrval(cmin,BLU)/colval(expos,BLU)); - printf("%d %d\t%e %e %e\n", xmax, ymax, + printf("%d %d\t%.2e %.2e %.2e\n", xmax, ymax, colrval(cmax,RED)/colval(expos,RED), colrval(cmax,GRN)/colval(expos,GRN), colrval(cmax,BLU)/colval(expos,BLU));