1 |
– |
/* Copyright (c) 1986 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* ra_t8.c - program to convert between RADIANCE and |
6 |
|
* Targa 8-bit color-mapped images. |
9 |
|
*/ |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
+ |
#include <time.h> |
13 |
+ |
#include <math.h> |
14 |
|
|
15 |
+ |
#include "platform.h" |
16 |
|
#include "color.h" |
17 |
< |
|
18 |
< |
#include "pic.h" |
19 |
< |
|
17 |
> |
#include "resolu.h" |
18 |
|
#include "targa.h" |
19 |
|
|
22 |
– |
/* descriptor for a picture file or frame buffer */ |
23 |
– |
typedef struct { |
24 |
– |
char *name; /* file name */ |
25 |
– |
FILE *fp; /* file pointer */ |
26 |
– |
int nexty; /* file positioning */ |
27 |
– |
int bytes_line; /* 0 == variable length lines */ |
28 |
– |
union { |
29 |
– |
long b; /* initial scanline */ |
30 |
– |
long *y; /* individual scanline */ |
31 |
– |
} pos; /* position(s) */ |
32 |
– |
} pic; |
20 |
|
|
21 |
< |
#define goodpic(h) (my_imType(h) && my_mapType(h)) |
22 |
< |
#define my_imType(h) (((h)->dataType==IM_CMAP || (h)->dataType==IM_CCMAP) \ |
21 |
> |
#define goodpic(h) (my_imType(h) && my_mapType(h)) |
22 |
> |
#define my_imType(h) (((h)->dataType==IM_CMAP || (h)->dataType==IM_CCMAP) \ |
23 |
|
&& (h)->dataBits==8 && (h)->imType==0) |
24 |
< |
#define my_mapType(h) ((h)->mapType==CM_HASMAP && \ |
24 |
> |
#define my_mapType(h) ((h)->mapType==CM_HASMAP && \ |
25 |
|
((h)->CMapBits==24 || (h)->CMapBits==32)) |
26 |
|
|
27 |
< |
#define taralloc(h) (pixel *)emalloc((h)->x*(h)->y*sizeof(pixel)) |
27 |
> |
#define taralloc(h) (BYTE *)emalloc((h)->x*(h)->y) |
28 |
|
|
29 |
< |
extern pic *openinput(); |
29 |
> |
BYTE clrtab[256][3]; |
30 |
|
|
31 |
+ |
extern int samplefac; |
32 |
+ |
|
33 |
|
extern char *ecalloc(), *emalloc(); |
34 |
|
|
35 |
|
extern long ftell(); |
36 |
|
|
37 |
< |
extern double atof(), pow(); |
37 |
> |
double gamv = 2.2; /* gamv correction */ |
38 |
|
|
39 |
< |
double gamma = 2.0; /* gamma correction */ |
39 |
> |
int bradj = 0; /* brightness adjustment */ |
40 |
|
|
52 |
– |
pic *inpic; |
53 |
– |
|
41 |
|
char *progname; |
42 |
|
|
43 |
|
char errmsg[128]; |
44 |
|
|
45 |
< |
COLR *inline; |
45 |
> |
COLR *inl; |
46 |
|
|
47 |
< |
pixel *tarData; |
47 |
> |
BYTE *tarData; |
48 |
|
|
49 |
|
int xmax, ymax; |
50 |
|
|
53 |
|
int argc; |
54 |
|
char *argv[]; |
55 |
|
{ |
56 |
< |
colormap rasmap; |
70 |
< |
struct hdStruct head; |
56 |
> |
struct hdStruct head; |
57 |
|
int dither = 1; |
58 |
|
int reverse = 0; |
59 |
|
int ncolors = 256; |
60 |
|
int greyscale = 0; |
61 |
|
int i; |
62 |
< |
|
62 |
> |
SET_DEFAULT_BINARY(); |
63 |
> |
SET_FILE_BINARY(stdin); |
64 |
> |
SET_FILE_BINARY(stdout); |
65 |
|
progname = argv[0]; |
66 |
+ |
samplefac = 0; |
67 |
|
|
68 |
|
for (i = 1; i < argc; i++) |
69 |
|
if (argv[i][0] == '-') |
72 |
|
dither = !dither; |
73 |
|
break; |
74 |
|
case 'g': |
75 |
< |
gamma = atof(argv[++i]); |
75 |
> |
gamv = atof(argv[++i]); |
76 |
|
break; |
77 |
|
case 'r': |
78 |
|
reverse = !reverse; |
80 |
|
case 'b': |
81 |
|
greyscale = 1; |
82 |
|
break; |
83 |
+ |
case 'e': |
84 |
+ |
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
85 |
+ |
goto userr; |
86 |
+ |
bradj = atoi(argv[++i]); |
87 |
+ |
break; |
88 |
|
case 'c': |
89 |
|
ncolors = atoi(argv[++i]); |
90 |
|
break; |
91 |
+ |
case 'n': |
92 |
+ |
samplefac = atoi(argv[++i]); |
93 |
+ |
break; |
94 |
|
default: |
95 |
|
goto userr; |
96 |
|
} |
97 |
|
else |
98 |
|
break; |
99 |
|
|
100 |
+ |
if (i < argc-2) |
101 |
+ |
goto userr; |
102 |
+ |
if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
103 |
+ |
sprintf(errmsg, "cannot open input \"%s\"", argv[i]); |
104 |
+ |
quiterr(errmsg); |
105 |
+ |
} |
106 |
+ |
if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { |
107 |
+ |
sprintf(errmsg, "cannot open output \"%s\"", argv[i+1]); |
108 |
+ |
quiterr(errmsg); |
109 |
+ |
} |
110 |
|
if (reverse) { |
104 |
– |
if (i < argc-2) |
105 |
– |
goto userr; |
106 |
– |
if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
107 |
– |
sprintf(errmsg, "can't open input \"%s\"", argv[i]); |
108 |
– |
quiterr(errmsg); |
109 |
– |
} |
111 |
|
/* get header */ |
112 |
|
if (getthead(&head, NULL, stdin) < 0) |
113 |
|
quiterr("bad targa file"); |
115 |
|
quiterr("incompatible format"); |
116 |
|
xmax = head.x; |
117 |
|
ymax = head.y; |
117 |
– |
/* open output file */ |
118 |
– |
if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { |
119 |
– |
sprintf(errmsg, "can't open output \"%s\"", argv[i+1]); |
120 |
– |
quiterr(errmsg); |
121 |
– |
} |
118 |
|
/* put header */ |
119 |
< |
printargs(argc, argv, stdout); |
119 |
> |
newheader("RADIANCE", stdout); |
120 |
> |
printargs(i, argv, stdout); |
121 |
> |
fputformat(COLRFMT, stdout); |
122 |
|
putchar('\n'); |
123 |
< |
printf("-Y %d +X %d\n", ymax, xmax); |
123 |
> |
fprtresolu(xmax, ymax, stdout); |
124 |
|
/* convert file */ |
125 |
|
tg2ra(&head); |
126 |
|
} else { |
127 |
< |
if (i > argc-1 || i < argc-2) |
128 |
< |
goto userr; |
131 |
< |
if ((inpic = openinput(argv[i], &head)) == NULL) { |
132 |
< |
sprintf(errmsg, "can't open input \"%s\"", argv[i]); |
133 |
< |
quiterr(errmsg); |
134 |
< |
} |
135 |
< |
if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { |
136 |
< |
sprintf(errmsg, "can't open output \"%s\"", argv[i+1]); |
137 |
< |
quiterr(errmsg); |
138 |
< |
} |
127 |
> |
if (getrhead(&head, stdin) < 0) |
128 |
> |
quiterr("bad Radiance input"); |
129 |
|
/* write header */ |
130 |
|
putthead(&head, NULL, stdout); |
131 |
|
/* convert file */ |
132 |
|
if (greyscale) |
133 |
< |
biq(dither,ncolors,1,rasmap); |
133 |
> |
getgrey(ncolors); |
134 |
|
else |
135 |
< |
ciq(dither,ncolors,1,rasmap); |
135 |
> |
getmapped(ncolors, dither); |
136 |
|
/* write data */ |
137 |
|
writetarga(&head, tarData, stdout); |
138 |
|
} |
139 |
|
quiterr(NULL); |
140 |
|
userr: |
141 |
|
fprintf(stderr, |
142 |
< |
"Usage: %s [-d][-c ncolors][-b][-g gamma] input [output]\n", |
142 |
> |
"Usage: %s [-d][-n samp][-c ncolors][-b][-g gamv][-e +/-stops] input [output]\n", |
143 |
|
progname); |
144 |
< |
fprintf(stderr, " Or: %s -r [-g gamma] [input [output]]\n", |
144 |
> |
fprintf(stderr, " Or: %s -r [-g gamv][-e +/-stops] [input [output]]\n", |
145 |
|
progname); |
146 |
|
exit(1); |
147 |
|
} |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
+ |
void |
184 |
|
eputs(s) |
185 |
|
char *s; |
186 |
|
{ |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
+ |
void |
192 |
|
quit(code) |
193 |
|
int code; |
194 |
|
{ |
197 |
|
|
198 |
|
|
199 |
|
getthead(hp, ip, fp) /* read header from input */ |
200 |
< |
struct hdStruct *hp; |
200 |
> |
struct hdStruct *hp; |
201 |
|
char *ip; |
202 |
|
register FILE *fp; |
203 |
|
{ |
219 |
|
|
220 |
|
if (ip != NULL) |
221 |
|
if (nidbytes) |
222 |
< |
fread(ip, nidbytes, 1, fp); |
222 |
> |
fread((char *)ip, nidbytes, 1, fp); |
223 |
|
else |
224 |
|
*ip = '\0'; |
225 |
|
else if (nidbytes) |
230 |
|
|
231 |
|
|
232 |
|
putthead(hp, ip, fp) /* write header to output */ |
233 |
< |
struct hdStruct *hp; |
233 |
> |
struct hdStruct *hp; |
234 |
|
char *ip; |
235 |
|
register FILE *fp; |
236 |
|
{ |
257 |
|
} |
258 |
|
|
259 |
|
|
260 |
< |
pic * |
269 |
< |
openinput(fname, h) /* open RADIANCE input file */ |
270 |
< |
char *fname; |
260 |
> |
getrhead(h, fp) /* load RADIANCE input file header */ |
261 |
|
register struct hdStruct *h; |
262 |
+ |
FILE *fp; |
263 |
|
{ |
264 |
< |
register pic *p; |
265 |
< |
|
266 |
< |
p = (pic *)emalloc(sizeof(pic)); |
267 |
< |
p->name = fname; |
277 |
< |
if (fname == NULL) |
278 |
< |
p->fp = stdin; |
279 |
< |
else if ((p->fp = fopen(fname, "r")) == NULL) |
280 |
< |
return(NULL); |
281 |
< |
/* discard header */ |
282 |
< |
getheader(p->fp, NULL); |
283 |
< |
if (fscanf(p->fp, "-Y %d +X %d\n", &ymax, &xmax) != 2) |
284 |
< |
quiterr("bad picture size"); |
285 |
< |
p->nexty = 0; |
286 |
< |
p->bytes_line = 0; /* variable length lines */ |
287 |
< |
p->pos.y = (long *)ecalloc(ymax, sizeof(long)); |
288 |
< |
p->pos.y[0] = ftell(p->fp); |
264 |
> |
/* get header info. */ |
265 |
> |
if (checkheader(fp, COLRFMT, NULL) < 0 || |
266 |
> |
fgetresolu(&xmax, &ymax, fp) < 0) |
267 |
> |
return(-1); |
268 |
|
/* assign header */ |
269 |
|
h->textSize = 0; |
270 |
|
h->mapType = CM_HASMAP; |
279 |
|
h->dataBits = 8; |
280 |
|
h->imType = 0; |
281 |
|
/* allocate scanline */ |
282 |
< |
inline = (COLR *)emalloc(xmax*sizeof(COLR)); |
282 |
> |
inl = (COLR *)emalloc(xmax*sizeof(COLR)); |
283 |
|
/* allocate targa data */ |
284 |
|
tarData = taralloc(h); |
285 |
|
|
286 |
< |
return(p); |
286 |
> |
return(0); |
287 |
|
} |
288 |
|
|
289 |
|
|
290 |
|
tg2ra(hp) /* targa file to RADIANCE file */ |
291 |
< |
struct hdStruct *hp; |
291 |
> |
struct hdStruct *hp; |
292 |
|
{ |
293 |
|
union { |
294 |
|
BYTE c3[256][3]; |
299 |
|
register int i, j; |
300 |
|
|
301 |
|
/* get color table */ |
302 |
< |
if ((hp->CMapBits==24 ? fread(map.c3, sizeof(map.c3), 1, stdin) : |
303 |
< |
fread(map.c4, sizeof(map.c4), 1, stdin)) != 1) |
302 |
> |
if ((hp->CMapBits==24 ? fread((char *)(map.c3+hp->mapOrig), |
303 |
> |
3*hp->mapLength,1,stdin) : |
304 |
> |
fread((char *)(map.c4+hp->mapOrig), |
305 |
> |
4*hp->mapLength,1,stdin)) != 1) |
306 |
|
quiterr("error reading color table"); |
307 |
|
/* convert table */ |
308 |
|
for (i = hp->mapOrig; i < hp->mapOrig+hp->mapLength; i++) |
309 |
|
if (hp->CMapBits == 24) |
310 |
|
setcolr(ctab[i], |
311 |
< |
pow((map.c3[i][2]+.5)/256.,gamma), |
312 |
< |
pow((map.c3[i][1]+.5)/256.,gamma), |
313 |
< |
pow((map.c3[i][0]+.5)/256.,gamma)); |
311 |
> |
pow((map.c3[i][2]+.5)/256.,gamv), |
312 |
> |
pow((map.c3[i][1]+.5)/256.,gamv), |
313 |
> |
pow((map.c3[i][0]+.5)/256.,gamv)); |
314 |
|
else |
315 |
|
setcolr(ctab[i], |
316 |
< |
pow((map.c4[i][3]+.5)/256.,gamma), |
317 |
< |
pow((map.c4[i][2]+.5)/256.,gamma), |
318 |
< |
pow((map.c4[i][1]+.5)/256.,gamma)); |
319 |
< |
|
316 |
> |
pow((map.c4[i][3]+.5)/256.,gamv), |
317 |
> |
pow((map.c4[i][2]+.5)/256.,gamv), |
318 |
> |
pow((map.c4[i][1]+.5)/256.,gamv)); |
319 |
> |
if (bradj) |
320 |
> |
shiftcolrs(ctab, 256, bradj); |
321 |
|
/* allocate targa data */ |
322 |
|
tarData = taralloc(hp); |
323 |
|
/* get data */ |
331 |
|
if (fwritecolrs(scanline, xmax, stdout) < 0) |
332 |
|
quiterr("error writing RADIANCE file"); |
333 |
|
} |
334 |
< |
free((char *)scanline); |
335 |
< |
free((char *)tarData); |
334 |
> |
free((void *)scanline); |
335 |
> |
free((void *)tarData); |
336 |
|
} |
337 |
|
|
338 |
|
|
339 |
< |
picreadline3(y, l3) /* read in 3-byte scanline */ |
340 |
< |
int y; |
341 |
< |
register rgbpixel *l3; |
339 |
> |
getmapped(nc, dith) /* read in and quantize image */ |
340 |
> |
int nc; /* number of colors to use */ |
341 |
> |
int dith; /* use dithering? */ |
342 |
|
{ |
343 |
< |
register BYTE *l4; |
344 |
< |
register int shift, c; |
363 |
< |
int i; |
343 |
> |
long fpos; |
344 |
> |
register int y; |
345 |
|
|
346 |
< |
if (inpic->nexty != y) { /* find scanline */ |
347 |
< |
if (inpic->bytes_line == 0) { |
348 |
< |
if (inpic->pos.y[y] == 0) { |
349 |
< |
while (inpic->nexty < y) { |
350 |
< |
if (freadcolrs(inline, xmax, inpic->fp) < 0) |
351 |
< |
quiterr("read error in picreadline3"); |
352 |
< |
inpic->pos.y[++inpic->nexty] = ftell(inpic->fp); |
353 |
< |
} |
354 |
< |
} else if (fseek(inpic->fp, inpic->pos.y[y], 0) == EOF) |
355 |
< |
quiterr("seek error in picreadline3"); |
356 |
< |
} else if (fseek(inpic->fp, y*inpic->bytes_line+inpic->pos.b, 0) == EOF) |
357 |
< |
quiterr("seek error in picreadline3"); |
358 |
< |
} else if (inpic->bytes_line == 0 && inpic->pos.y[inpic->nexty] == 0) |
359 |
< |
inpic->pos.y[inpic->nexty] = ftell(inpic->fp); |
379 |
< |
if (freadcolrs(inline, xmax, inpic->fp) < 0) /* read scanline */ |
380 |
< |
quiterr("read error in picreadline3"); |
381 |
< |
inpic->nexty = y+1; |
382 |
< |
/* convert scanline */ |
383 |
< |
for (l4=inline[0], i=xmax; i--; l4+=4, l3++) { |
384 |
< |
shift = l4[EXP] - COLXS; |
385 |
< |
if (shift >= 8) { |
386 |
< |
l3->r = l3->g = l3->b = 255; |
387 |
< |
} else if (shift <= -8) { |
388 |
< |
l3->r = l3->g = l3->b = 0; |
389 |
< |
} else if (shift > 0) { |
390 |
< |
c = l4[RED] << shift; |
391 |
< |
l3->r = c > 255 ? 255 : c; |
392 |
< |
c = l4[GRN] << shift; |
393 |
< |
l3->g = c > 255 ? 255 : c; |
394 |
< |
c = l4[BLU] << shift; |
395 |
< |
l3->b = c > 255 ? 255 : c; |
396 |
< |
} else if (shift < 0) { |
397 |
< |
l3->r = l4[RED] >> -shift; |
398 |
< |
l3->g = l4[GRN] >> -shift; |
399 |
< |
l3->b = l4[BLU] >> -shift; |
400 |
< |
} else { |
401 |
< |
l3->r = l4[RED]; |
402 |
< |
l3->g = l4[GRN]; |
403 |
< |
l3->b = l4[BLU]; |
404 |
< |
} |
346 |
> |
setcolrgam(gamv); |
347 |
> |
fpos = ftell(stdin); |
348 |
> |
if ((samplefac ? neu_init(xmax*ymax) : new_histo(xmax*ymax)) == -1) |
349 |
> |
quiterr("cannot initialized histogram"); |
350 |
> |
for (y = ymax-1; y >= 0; y--) { |
351 |
> |
if (freadcolrs(inl, xmax, stdin) < 0) |
352 |
> |
quiterr("error reading Radiance input"); |
353 |
> |
if (bradj) |
354 |
> |
shiftcolrs(inl, xmax, bradj); |
355 |
> |
colrs_gambs(inl, xmax); |
356 |
> |
if (samplefac) |
357 |
> |
neu_colrs(inl, xmax); |
358 |
> |
else |
359 |
> |
cnt_colrs(inl, xmax); |
360 |
|
} |
361 |
+ |
if (fseek(stdin, fpos, 0) == EOF) |
362 |
+ |
quiterr("Radiance input must be from a file"); |
363 |
+ |
if (samplefac) /* map colors */ |
364 |
+ |
neu_clrtab(nc); |
365 |
+ |
else |
366 |
+ |
new_clrtab(nc); |
367 |
+ |
for (y = ymax-1; y >= 0; y--) { |
368 |
+ |
if (freadcolrs(inl, xmax, stdin) < 0) |
369 |
+ |
quiterr("error reading Radiance input"); |
370 |
+ |
if (bradj) |
371 |
+ |
shiftcolrs(inl, xmax, bradj); |
372 |
+ |
colrs_gambs(inl, xmax); |
373 |
+ |
if (samplefac) |
374 |
+ |
if (dith) |
375 |
+ |
neu_dith_colrs(tarData+y*xmax, inl, xmax); |
376 |
+ |
else |
377 |
+ |
neu_map_colrs(tarData+y*xmax, inl, xmax); |
378 |
+ |
else |
379 |
+ |
if (dith) |
380 |
+ |
dith_colrs(tarData+y*xmax, inl, xmax); |
381 |
+ |
else |
382 |
+ |
map_colrs(tarData+y*xmax, inl, xmax); |
383 |
+ |
} |
384 |
|
} |
385 |
|
|
386 |
|
|
387 |
< |
picwriteline(y, l) /* save output scanline */ |
388 |
< |
int y; |
411 |
< |
pixel *l; |
387 |
> |
getgrey(nc) /* read in and convert to greyscale image */ |
388 |
> |
int nc; /* number of colors to use */ |
389 |
|
{ |
390 |
< |
bcopy(l, &tarData[(ymax-1-y)*xmax], xmax*sizeof(pixel)); |
390 |
> |
int y; |
391 |
> |
register BYTE *dp; |
392 |
> |
register int x; |
393 |
> |
|
394 |
> |
setcolrgam(gamv); |
395 |
> |
dp = tarData+xmax*ymax;; |
396 |
> |
for (y = ymax-1; y >= 0; y--) { |
397 |
> |
if (freadcolrs(inl, xmax, stdin) < 0) |
398 |
> |
quiterr("error reading Radiance input"); |
399 |
> |
if (bradj) |
400 |
> |
shiftcolrs(inl, xmax, bradj); |
401 |
> |
x = xmax; |
402 |
> |
while (x--) |
403 |
> |
inl[x][GRN] = normbright(inl[x]); |
404 |
> |
colrs_gambs(inl, xmax); |
405 |
> |
x = xmax; |
406 |
> |
if (nc < 256) |
407 |
> |
while (x--) |
408 |
> |
*--dp = ((long)inl[x][GRN]*nc+nc/2)>>8; |
409 |
> |
else |
410 |
> |
while (x--) |
411 |
> |
*--dp = inl[x][GRN]; |
412 |
> |
} |
413 |
> |
for (x = 0; x < nc; x++) |
414 |
> |
clrtab[x][RED] = clrtab[x][GRN] = |
415 |
> |
clrtab[x][BLU] = ((long)x*256+128)/nc; |
416 |
|
} |
417 |
|
|
418 |
|
|
419 |
|
writetarga(h, d, fp) /* write out targa data */ |
420 |
< |
struct hdStruct *h; |
421 |
< |
pixel *d; |
420 |
> |
struct hdStruct *h; |
421 |
> |
BYTE *d; |
422 |
|
FILE *fp; |
423 |
|
{ |
424 |
+ |
register int i, j; |
425 |
+ |
|
426 |
+ |
for (i = 0; i < h->mapLength; i++) /* write color map */ |
427 |
+ |
for (j = 2; j >= 0; j--) |
428 |
+ |
putc(clrtab[i][j], fp); |
429 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
430 |
< |
if (fwrite(d, h->x*sizeof(pixel), h->y, fp) != h->y) |
430 |
> |
if (fwrite((char *)d,h->x*sizeof(BYTE),h->y,fp) != h->y) |
431 |
|
quiterr("error writing targa file"); |
432 |
|
return; |
433 |
|
} |
436 |
|
|
437 |
|
|
438 |
|
readtarga(h, data, fp) /* read in targa data */ |
439 |
< |
struct hdStruct *h; |
440 |
< |
pixel *data; |
439 |
> |
struct hdStruct *h; |
440 |
> |
BYTE *data; |
441 |
|
FILE *fp; |
442 |
|
{ |
443 |
|
register int cnt, c; |
444 |
< |
register pixel *dp; |
444 |
> |
register BYTE *dp; |
445 |
|
|
446 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
447 |
< |
if (fread(data, h->x*sizeof(pixel), h->y, fp) != h->y) |
447 |
> |
if (fread((char *)data,h->x*sizeof(BYTE),h->y,fp) != h->y) |
448 |
|
goto readerr; |
449 |
|
return; |
450 |
|
} |
467 |
|
return; |
468 |
|
readerr: |
469 |
|
quiterr("error reading targa file"); |
463 |
– |
} |
464 |
– |
|
465 |
– |
|
466 |
– |
picwritecm(cm) /* write out color map */ |
467 |
– |
colormap cm; |
468 |
– |
{ |
469 |
– |
register int i, j; |
470 |
– |
|
471 |
– |
for (j = 0; j < 256; j++) |
472 |
– |
for (i = 2; i >= 0; i--) |
473 |
– |
putc(cm[i][j], stdout); |
474 |
– |
} |
475 |
– |
|
476 |
– |
|
477 |
– |
picreadcm(map) /* do gamma correction if requested */ |
478 |
– |
colormap map; |
479 |
– |
{ |
480 |
– |
register int i, val; |
481 |
– |
|
482 |
– |
for (i = 0; i < 256; i++) { |
483 |
– |
val = pow(i/256.0, 1.0/gamma) * 256.0; |
484 |
– |
map[0][i] = map[1][i] = map[2][i] = val; |
485 |
– |
} |
470 |
|
} |