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"; |
53 |
|
|
54 |
|
double gamma = 2.0; /* gamma correction */ |
55 |
|
|
56 |
+ |
int bradj = 0; /* brightness adjustment */ |
57 |
+ |
|
58 |
|
pic *inpic; |
59 |
|
|
60 |
|
char *progname; |
97 |
|
case 'b': |
98 |
|
greyscale = 1; |
99 |
|
break; |
100 |
+ |
case 'e': |
101 |
+ |
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
102 |
+ |
goto userr; |
103 |
+ |
bradj = atoi(argv[++i]); |
104 |
+ |
break; |
105 |
|
case 'c': |
106 |
|
ncolors = atoi(argv[++i]); |
107 |
|
break; |
132 |
|
} |
133 |
|
/* put header */ |
134 |
|
printargs(i, argv, stdout); |
135 |
+ |
fputformat(COLRFMT, stdout); |
136 |
|
putchar('\n'); |
137 |
|
fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); |
138 |
|
/* convert file */ |
139 |
|
tg2ra(&head); |
140 |
|
} else { |
141 |
< |
if (i > argc-1 || i < argc-2) |
141 |
> |
if (i < argc-2 || (!greyscale && i > argc-1)) |
142 |
|
goto userr; |
143 |
|
if ((inpic = openinput(argv[i], &head)) == NULL) { |
144 |
|
sprintf(errmsg, "can't open input \"%s\"", argv[i]); |
161 |
|
quiterr(NULL); |
162 |
|
userr: |
163 |
|
fprintf(stderr, |
164 |
< |
"Usage: %s [-d][-c ncolors][-b][-g gamma] input [output]\n", |
164 |
> |
"Usage: %s [-d][-c ncolors][-b][-g gamma][-e +/-stops] input [output]\n", |
165 |
|
progname); |
166 |
< |
fprintf(stderr, " Or: %s -r [-g gamma] [input [output]]\n", |
166 |
> |
fprintf(stderr, " Or: %s -r [-g gamma][-e +/-stops] [input [output]]\n", |
167 |
|
progname); |
168 |
|
exit(1); |
169 |
|
} |
290 |
|
p->fp = stdin; |
291 |
|
else if ((p->fp = fopen(fname, "r")) == NULL) |
292 |
|
return(NULL); |
293 |
< |
/* discard header */ |
294 |
< |
getheader(p->fp, NULL); |
295 |
< |
if (fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) |
296 |
< |
quiterr("bad picture size"); |
293 |
> |
/* get header info. */ |
294 |
> |
if (checkheader(p->fp, COLRFMT, NULL) < 0 || |
295 |
> |
fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) |
296 |
> |
quiterr("bad picture format"); |
297 |
|
p->nexty = 0; |
298 |
|
p->bytes_line = 0; /* variable length lines */ |
299 |
|
p->pos.y = (long *)ecalloc(ymax, sizeof(long)); |
347 |
|
pow((map.c4[i][3]+.5)/256.,gamma), |
348 |
|
pow((map.c4[i][2]+.5)/256.,gamma), |
349 |
|
pow((map.c4[i][1]+.5)/256.,gamma)); |
350 |
< |
|
350 |
> |
if (bradj) |
351 |
> |
shiftcolrs(ctab, 256, bradj); |
352 |
|
/* allocate targa data */ |
353 |
|
tarData = taralloc(hp); |
354 |
|
/* get data */ |
391 |
|
quiterr("read error in picreadline3"); |
392 |
|
inpic->nexty = y+1; |
393 |
|
/* convert scanline */ |
394 |
< |
normcolrs(inl, xmax, 0); |
394 |
> |
normcolrs(inl, xmax, bradj); |
395 |
|
for (i = 0; i < xmax; i++) { |
396 |
|
l3[i].r = inl[i][RED]; |
397 |
|
l3[i].g = inl[i][GRN]; |
474 |
|
register int i, val; |
475 |
|
|
476 |
|
for (i = 0; i < 256; i++) { |
477 |
< |
val = pow(i/256.0, 1.0/gamma) * 256.0; |
477 |
> |
val = pow((i+0.5)/256.0, 1.0/gamma) * 256.0; |
478 |
|
map[0][i] = map[1][i] = map[2][i] = val; |
479 |
|
} |
480 |
|
} |