| 1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 36 |
|
|
| 37 |
|
int wrongformat = 0; /* wrong input format? */ |
| 38 |
|
|
| 39 |
+ |
double gamma = 1.0; /* gamma correction */ |
| 40 |
+ |
|
| 41 |
|
COLOR exposure = WHTCOLOR; |
| 42 |
|
|
| 43 |
|
char *progname; |
| 44 |
|
|
| 45 |
|
FILE *fin; |
| 46 |
|
|
| 47 |
+ |
extern double atof(), pow(); |
| 48 |
+ |
|
| 49 |
|
int (*getval)(), (*putval)(); |
| 50 |
|
|
| 51 |
|
|
| 53 |
|
int argc; |
| 54 |
|
char **argv; |
| 55 |
|
{ |
| 52 |
– |
extern double atof(); |
| 56 |
|
extern int checkhead(); |
| 57 |
|
int i; |
| 58 |
|
|
| 70 |
|
case 'o': /* original values */ |
| 71 |
|
original = 1; |
| 72 |
|
break; |
| 73 |
+ |
case 'g': /* gamma correction */ |
| 74 |
+ |
gamma = atof(argv[++i]); |
| 75 |
+ |
break; |
| 76 |
|
case 'r': /* reverse conversion */ |
| 77 |
|
reverse = 1; |
| 78 |
|
break; |
| 204 |
|
scalecolor(exposure, d); |
| 205 |
|
} else if (original && iscolcor(line)) { |
| 206 |
|
colcorval(ctmp, line); |
| 207 |
< |
colval(exposure,RED) /= colval(ctmp,RED); |
| 208 |
< |
colval(exposure,GRN) /= colval(ctmp,GRN); |
| 209 |
< |
colval(exposure,BLU) /= colval(ctmp,BLU); |
| 207 |
> |
setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED), |
| 208 |
> |
colval(exposure,GRN)/colval(ctmp,GRN), |
| 209 |
> |
colval(exposure,BLU)/colval(ctmp,BLU)); |
| 210 |
|
} else if (header) |
| 211 |
|
fputs(line, stdout); |
| 212 |
|
} |
| 214 |
|
|
| 215 |
|
pixtoval() /* convert picture to values */ |
| 216 |
|
{ |
| 217 |
< |
COLOR *scanln; |
| 217 |
> |
register COLOR *scanln; |
| 218 |
> |
int dogamma; |
| 219 |
|
COLOR lastc; |
| 220 |
|
int y; |
| 221 |
|
register int x; |
| 225 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
| 226 |
|
quit(1); |
| 227 |
|
} |
| 228 |
+ |
dogamma = gamma < .95 || gamma > 1.05; |
| 229 |
|
setcolor(lastc, 0.0, 0.0, 0.0); |
| 230 |
|
for (y = yres-1; y >= 0; y--) { |
| 231 |
|
if (freadscan(scanln, xres, fin) < 0) { |
| 234 |
|
} |
| 235 |
|
for (x = 0; x < xres; x++) { |
| 236 |
|
if (uniq) |
| 237 |
< |
if ( scanln[x][RED] == lastc[RED] && |
| 238 |
< |
scanln[x][GRN] == lastc[GRN] && |
| 239 |
< |
scanln[x][BLU] == lastc[BLU] ) |
| 237 |
> |
if ( colval(scanln[x],RED) == |
| 238 |
> |
colval(lastc,RED) && |
| 239 |
> |
colval(scanln[x],GRN) == |
| 240 |
> |
colval(lastc,GRN) && |
| 241 |
> |
colval(scanln[x],BLU) == |
| 242 |
> |
colval(lastc,BLU) ) |
| 243 |
|
continue; |
| 244 |
|
else |
| 245 |
|
copycolor(lastc, scanln[x]); |
| 246 |
|
if (original) |
| 247 |
|
multcolor(scanln[x], exposure); |
| 248 |
+ |
if (dogamma) |
| 249 |
+ |
setcolor(scanln[x], |
| 250 |
+ |
pow(colval(scanln[x],RED), 1.0/gamma), |
| 251 |
+ |
pow(colval(scanln[x],GRN), 1.0/gamma), |
| 252 |
+ |
pow(colval(scanln[x],BLU), 1.0/gamma)); |
| 253 |
|
if (!dataonly) |
| 254 |
|
printf("%7d %7d ", x, y); |
| 255 |
|
if ((*putval)(scanln[x], stdout) < 0) { |
| 264 |
|
|
| 265 |
|
valtopix() /* convert values to a pixel file */ |
| 266 |
|
{ |
| 267 |
< |
COLOR *scanln; |
| 267 |
> |
int dogamma; |
| 268 |
> |
register COLOR *scanln; |
| 269 |
|
int y; |
| 270 |
|
register int x; |
| 271 |
|
|
| 274 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
| 275 |
|
quit(1); |
| 276 |
|
} |
| 277 |
+ |
dogamma = gamma < .95 || gamma > 1.05; |
| 278 |
|
for (y = yres-1; y >= 0; y--) { |
| 279 |
|
for (x = 0; x < xres; x++) { |
| 280 |
|
if (!dataonly) |
| 283 |
|
fprintf(stderr, "%s: read error\n", progname); |
| 284 |
|
quit(1); |
| 285 |
|
} |
| 286 |
+ |
if (dogamma) |
| 287 |
+ |
setcolor(scanln[x], |
| 288 |
+ |
pow(colval(scanln[x],RED), gamma), |
| 289 |
+ |
pow(colval(scanln[x],GRN), gamma), |
| 290 |
+ |
pow(colval(scanln[x],BLU), gamma)); |
| 291 |
|
} |
| 292 |
< |
if (fwritescan(scanln, xres, stdout) < 0 |
| 270 |
< |
|| fflush(stdout) < 0) { |
| 292 |
> |
if (fwritescan(scanln, xres, stdout) < 0) { |
| 293 |
|
fprintf(stderr, "%s: write error\n", progname); |
| 294 |
|
quit(1); |
| 295 |
|
} |