| 2 |
|
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 4 |
|
/* |
| 5 |
< |
* Find extrema points in a Radiance picture. |
| 5 |
> |
* Find extrema points in a Radiance picture (RGBE, XYZE, or HyperSpectral) |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
|
#include <math.h> |
| 33 |
|
|
| 34 |
|
if (formatval(fmt, s)) /* format */ |
| 35 |
|
return(0); |
| 36 |
< |
if (!orig) |
| 36 |
> |
if (iswlsplit(s)) { /* wavelength splits */ |
| 37 |
> |
wlsplitval(WLPART, s); |
| 38 |
|
return(0); |
| 39 |
+ |
} |
| 40 |
+ |
if (isncomp(s)) { /* # spectral components */ |
| 41 |
+ |
NCSAMP = ncompval(s); |
| 42 |
+ |
return(0); |
| 43 |
+ |
} |
| 44 |
+ |
if (!orig) /* don't undo exposure? */ |
| 45 |
+ |
return(0); |
| 46 |
|
if (isexpos(s)) { /* exposure */ |
| 47 |
|
d = exposval(s); |
| 48 |
|
scalecolor(expos, d); |
| 63 |
|
int i; |
| 64 |
|
int xres, yres; |
| 65 |
|
int y; |
| 66 |
< |
register int x; |
| 67 |
< |
COLR *scan; |
| 68 |
< |
COLR cmin, cmax; |
| 66 |
> |
int x; |
| 67 |
> |
COLRV *scan; |
| 68 |
> |
SCOLR cmin, cmax; |
| 69 |
> |
COLOR tcol; |
| 70 |
|
int xmin, ymin, xmax, ymax; |
| 71 |
+ |
|
| 72 |
|
SET_DEFAULT_BINARY(); |
| 73 |
|
SET_FILE_BINARY(stdin); |
| 74 |
|
for (i = 1; i < argc; i++) /* get options */ |
| 82 |
|
if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
| 83 |
|
fprintf(stderr, "%s: can't open input \"%s\"\n", |
| 84 |
|
argv[0], argv[i]); |
| 85 |
< |
exit(1); |
| 85 |
> |
return(1); |
| 86 |
|
} |
| 87 |
|
/* get our header */ |
| 88 |
< |
if (getheader(stdin, headline, NULL) < 0 || !globmatch(PICFMT, fmt) || |
| 88 |
> |
if (getheader(stdin, headline, NULL) < 0 || |
| 89 |
> |
(!globmatch(PICFMT, fmt) && strcmp(fmt, SPECFMT)) || |
| 90 |
|
fgetresolu(&xres, &yres, stdin) < 0) { |
| 91 |
|
fprintf(stderr, "%s: bad picture format\n", argv[0]); |
| 92 |
< |
exit(1); |
| 92 |
> |
return(1); |
| 93 |
|
} |
| 94 |
+ |
if (setspectrsamp(CNDX, WLPART) < 0) { |
| 95 |
+ |
fprintf(stderr, "%s: bad wavelength split or component count", |
| 96 |
+ |
argv[0]); |
| 97 |
+ |
return(1); |
| 98 |
+ |
} |
| 99 |
|
if (orig < 0 && !strcmp(CIEFMT, fmt)) |
| 100 |
|
scalecolor(expos, 1./WHTEFFICACY); |
| 101 |
< |
if ((scan = (COLR *)malloc(xres*sizeof(COLR))) == NULL) { |
| 101 |
> |
if ((scan = (COLRV *)malloc(xres*sizeof(COLRV)*(NCSAMP+1))) == NULL) { |
| 102 |
|
fprintf(stderr, "%s: out of memory\n", argv[0]); |
| 103 |
< |
exit(1); |
| 103 |
> |
return(1); |
| 104 |
|
} |
| 105 |
< |
setcolr(cmin, 1e30, 1e30, 1e30); |
| 106 |
< |
setcolr(cmax, 0., 0., 0.); xmax=ymax=0; |
| 105 |
> |
setscolr(cmin, 1e30, 1e30, 1e30); xmin=ymin=0; |
| 106 |
> |
scolrblack(cmax); xmax=ymax=0; |
| 107 |
|
/* find extrema */ |
| 108 |
|
for (y = yres-1; y >= 0; y--) { |
| 109 |
< |
if (freadcolrs(scan, xres, stdin) < 0) { |
| 109 |
> |
if (freadscolrs(scan, NCSAMP, xres, stdin) < 0) { |
| 110 |
|
fprintf(stderr, "%s: read error on input\n", argv[0]); |
| 111 |
< |
exit(1); |
| 111 |
> |
return(1); |
| 112 |
|
} |
| 113 |
|
for (x = xres; x-- > 0; ) { |
| 114 |
< |
if (scan[x][EXP] > cmax[EXP] || |
| 115 |
< |
(scan[x][EXP] == cmax[EXP] && |
| 116 |
< |
normbright(scan[x]) > |
| 117 |
< |
normbright(cmax))) { |
| 118 |
< |
copycolr(cmax, scan[x]); |
| 114 |
> |
const COLRV * sclr = scan + x*(NCSAMP+1); |
| 115 |
> |
if (sclr[CNDX[EXP]] > cmax[CNDX[EXP]] || |
| 116 |
> |
(sclr[CNDX[EXP]] == cmax[CNDX[EXP]] && |
| 117 |
> |
normpbright(sclr) > normpbright(cmax))) { |
| 118 |
> |
copyscolr(cmax, sclr); |
| 119 |
|
xmax = x; ymax = y; |
| 120 |
|
} |
| 121 |
< |
if (scan[x][EXP] < cmin[EXP] || |
| 122 |
< |
(scan[x][EXP] == cmin[EXP] && |
| 123 |
< |
normbright(scan[x]) < |
| 124 |
< |
normbright(cmin))) { |
| 109 |
< |
copycolr(cmin, scan[x]); |
| 121 |
> |
if (sclr[CNDX[EXP]] < cmin[CNDX[EXP]] || |
| 122 |
> |
(sclr[CNDX[EXP]] == cmin[CNDX[EXP]] && |
| 123 |
> |
normpbright(sclr) < normpbright(cmin))) { |
| 124 |
> |
copyscolr(cmin, sclr); |
| 125 |
|
xmin = x; ymin = y; |
| 126 |
|
} |
| 127 |
|
} |
| 128 |
|
} |
| 129 |
< |
free((void *)scan); |
| 129 |
> |
free(scan); |
| 130 |
> |
scolr_color(tcol, cmin); |
| 131 |
|
printf("%d %d\t%.2e %.2e %.2e\n", xmin, ymin, |
| 132 |
< |
colrval(cmin,RED)/colval(expos,RED), |
| 133 |
< |
colrval(cmin,GRN)/colval(expos,GRN), |
| 134 |
< |
colrval(cmin,BLU)/colval(expos,BLU)); |
| 132 |
> |
colval(tcol,RED)/colval(expos,RED), |
| 133 |
> |
colval(tcol,GRN)/colval(expos,GRN), |
| 134 |
> |
colval(tcol,BLU)/colval(expos,BLU)); |
| 135 |
> |
scolr_color(tcol, cmax); |
| 136 |
|
printf("%d %d\t%.2e %.2e %.2e\n", xmax, ymax, |
| 137 |
< |
colrval(cmax,RED)/colval(expos,RED), |
| 138 |
< |
colrval(cmax,GRN)/colval(expos,GRN), |
| 139 |
< |
colrval(cmax,BLU)/colval(expos,BLU)); |
| 140 |
< |
exit(0); |
| 137 |
> |
colval(tcol,RED)/colval(expos,RED), |
| 138 |
> |
colval(tcol,GRN)/colval(expos,GRN), |
| 139 |
> |
colval(tcol,BLU)/colval(expos,BLU)); |
| 140 |
> |
return(0); |
| 141 |
|
} |