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"; |
15 |
|
|
16 |
|
#include "color.h" |
17 |
|
|
18 |
+ |
#include "resolu.h" |
19 |
+ |
|
20 |
|
#include "pic.h" |
21 |
|
|
22 |
|
#include "targa.h" |
53 |
|
|
54 |
|
extern double atof(), pow(); |
55 |
|
|
56 |
< |
double gamma = 2.0; /* gamma correction */ |
56 |
> |
double gamma = 2.2; /* gamma correction */ |
57 |
|
|
58 |
+ |
int bradj = 0; /* brightness adjustment */ |
59 |
+ |
|
60 |
|
pic *inpic; |
61 |
|
|
62 |
|
char *progname; |
99 |
|
case 'b': |
100 |
|
greyscale = 1; |
101 |
|
break; |
102 |
+ |
case 'e': |
103 |
+ |
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
104 |
+ |
goto userr; |
105 |
+ |
bradj = atoi(argv[++i]); |
106 |
+ |
break; |
107 |
|
case 'c': |
108 |
|
ncolors = atoi(argv[++i]); |
109 |
|
break; |
136 |
|
printargs(i, argv, stdout); |
137 |
|
fputformat(COLRFMT, stdout); |
138 |
|
putchar('\n'); |
139 |
< |
fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); |
139 |
> |
fprtresolu(xmax, ymax, stdout); |
140 |
|
/* convert file */ |
141 |
|
tg2ra(&head); |
142 |
|
} else { |
143 |
< |
if (i > argc-1 || i < argc-2) |
143 |
> |
if (i < argc-2 || (!greyscale && i > argc-1)) |
144 |
|
goto userr; |
145 |
|
if ((inpic = openinput(argv[i], &head)) == NULL) { |
146 |
|
sprintf(errmsg, "can't open input \"%s\"", argv[i]); |
163 |
|
quiterr(NULL); |
164 |
|
userr: |
165 |
|
fprintf(stderr, |
166 |
< |
"Usage: %s [-d][-c ncolors][-b][-g gamma] input [output]\n", |
166 |
> |
"Usage: %s [-d][-c ncolors][-b][-g gamma][-e +/-stops] input [output]\n", |
167 |
|
progname); |
168 |
< |
fprintf(stderr, " Or: %s -r [-g gamma] [input [output]]\n", |
168 |
> |
fprintf(stderr, " Or: %s -r [-g gamma][-e +/-stops] [input [output]]\n", |
169 |
|
progname); |
170 |
|
exit(1); |
171 |
|
} |
294 |
|
return(NULL); |
295 |
|
/* get header info. */ |
296 |
|
if (checkheader(p->fp, COLRFMT, NULL) < 0 || |
297 |
< |
fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) |
297 |
> |
fgetresolu(&xmax, &ymax, p->fp) < 0) |
298 |
|
quiterr("bad picture format"); |
299 |
|
p->nexty = 0; |
300 |
|
p->bytes_line = 0; /* variable length lines */ |
334 |
|
register int i, j; |
335 |
|
|
336 |
|
/* get color table */ |
337 |
< |
if ((hp->CMapBits==24 ? fread((char *)map.c3,sizeof(map.c3),1,stdin) : |
338 |
< |
fread((char *)map.c4,sizeof(map.c4),1,stdin)) != 1) |
337 |
> |
if ((hp->CMapBits==24 ? fread((char *)(map.c3+hp->mapOrig), |
338 |
> |
3*hp->mapLength,1,stdin) : |
339 |
> |
fread((char *)(map.c4+hp->mapOrig), |
340 |
> |
4*hp->mapLength,1,stdin)) != 1) |
341 |
|
quiterr("error reading color table"); |
342 |
|
/* convert table */ |
343 |
|
for (i = hp->mapOrig; i < hp->mapOrig+hp->mapLength; i++) |
351 |
|
pow((map.c4[i][3]+.5)/256.,gamma), |
352 |
|
pow((map.c4[i][2]+.5)/256.,gamma), |
353 |
|
pow((map.c4[i][1]+.5)/256.,gamma)); |
354 |
< |
|
354 |
> |
if (bradj) |
355 |
> |
shiftcolrs(ctab, 256, bradj); |
356 |
|
/* allocate targa data */ |
357 |
|
tarData = taralloc(hp); |
358 |
|
/* get data */ |
395 |
|
quiterr("read error in picreadline3"); |
396 |
|
inpic->nexty = y+1; |
397 |
|
/* convert scanline */ |
398 |
< |
normcolrs(inl, xmax, 0); |
398 |
> |
normcolrs(inl, xmax, bradj); |
399 |
|
for (i = 0; i < xmax; i++) { |
400 |
|
l3[i].r = inl[i][RED]; |
401 |
|
l3[i].g = inl[i][GRN]; |