1 |
– |
/* Copyright (c) 1992 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 <string.h> |
13 |
+ |
#include <time.h> |
14 |
+ |
#include <math.h> |
15 |
|
|
16 |
+ |
#include "platform.h" |
17 |
+ |
#include "rtmisc.h" |
18 |
|
#include "color.h" |
17 |
– |
|
19 |
|
#include "resolu.h" |
20 |
< |
|
20 |
< |
#include "pic.h" |
21 |
< |
|
20 |
> |
#include "clrtab.h" |
21 |
|
#include "targa.h" |
22 |
|
|
24 |
– |
#ifdef MSDOS |
25 |
– |
#include <fcntl.h> |
26 |
– |
#endif |
23 |
|
|
28 |
– |
#include <math.h> |
29 |
– |
|
30 |
– |
#ifndef BSD |
31 |
– |
#define bcopy(s,d,n) (void)memcpy(d,s,n) |
32 |
– |
extern char *memcpy(); |
33 |
– |
#endif |
34 |
– |
/* descriptor for a picture file or frame buffer */ |
35 |
– |
typedef struct { |
36 |
– |
char *name; /* file name */ |
37 |
– |
FILE *fp; /* file pointer */ |
38 |
– |
int nexty; /* file positioning */ |
39 |
– |
int bytes_line; /* 0 == variable length lines */ |
40 |
– |
union { |
41 |
– |
long b; /* initial scanline */ |
42 |
– |
long *y; /* individual scanline */ |
43 |
– |
} pos; /* position(s) */ |
44 |
– |
} pic; |
45 |
– |
|
24 |
|
#define goodpic(h) (my_imType(h) && my_mapType(h)) |
25 |
|
#define my_imType(h) (((h)->dataType==IM_CMAP || (h)->dataType==IM_CCMAP) \ |
26 |
|
&& (h)->dataBits==8 && (h)->imType==0) |
27 |
|
#define my_mapType(h) ((h)->mapType==CM_HASMAP && \ |
28 |
|
((h)->CMapBits==24 || (h)->CMapBits==32)) |
29 |
|
|
30 |
< |
#define taralloc(h) (pixel *)emalloc((h)->x*(h)->y*sizeof(pixel)) |
30 |
> |
#define taralloc(h) (BYTE *)emalloc((h)->x*(h)->y) |
31 |
|
|
32 |
< |
extern pic *openinput(); |
33 |
< |
|
34 |
< |
extern char *ecalloc(), *emalloc(); |
57 |
< |
|
58 |
< |
extern long ftell(); |
59 |
< |
|
60 |
< |
double gamma = 2.2; /* gamma correction */ |
61 |
< |
|
32 |
> |
BYTE clrtab[256][3]; |
33 |
> |
extern int samplefac; |
34 |
> |
double gamv = 2.2; /* gamv correction */ |
35 |
|
int bradj = 0; /* brightness adjustment */ |
63 |
– |
|
64 |
– |
pic *inpic; |
65 |
– |
|
36 |
|
char *progname; |
67 |
– |
|
37 |
|
char errmsg[128]; |
69 |
– |
|
38 |
|
COLR *inl; |
39 |
< |
|
72 |
< |
pixel *tarData; |
73 |
< |
|
39 |
> |
BYTE *tarData; |
40 |
|
int xmax, ymax; |
41 |
|
|
42 |
+ |
static int getint2(FILE *fp); |
43 |
+ |
static void putint2(int i, FILE *fp); |
44 |
+ |
static void quiterr(char *err); |
45 |
+ |
static int getthead(struct hdStruct *hp, char *ip, FILE *fp); |
46 |
+ |
static int putthead(struct hdStruct *hp, char *ip, FILE *fp); |
47 |
+ |
static int getrhead(struct hdStruct *h, FILE *fp); |
48 |
+ |
static void tg2ra(struct hdStruct *hp); |
49 |
+ |
static void getmapped(int nc, int dith); |
50 |
+ |
static void getgrey(int nc); |
51 |
+ |
static void writetarga(struct hdStruct *h, BYTE *d, FILE *fp); |
52 |
+ |
static void readtarga(struct hdStruct *h, BYTE *data, FILE *fp); |
53 |
|
|
54 |
< |
main(argc, argv) |
55 |
< |
int argc; |
56 |
< |
char *argv[]; |
54 |
> |
|
55 |
> |
int |
56 |
> |
main( |
57 |
> |
int argc, |
58 |
> |
char *argv[] |
59 |
> |
) |
60 |
|
{ |
81 |
– |
colormap rasmap; |
61 |
|
struct hdStruct head; |
62 |
|
int dither = 1; |
63 |
|
int reverse = 0; |
64 |
|
int ncolors = 256; |
65 |
|
int greyscale = 0; |
66 |
|
int i; |
67 |
< |
#ifdef MSDOS |
68 |
< |
extern int _fmode; |
69 |
< |
_fmode = O_BINARY; |
91 |
< |
setmode(fileno(stdin), O_BINARY); |
92 |
< |
setmode(fileno(stdout), O_BINARY); |
93 |
< |
#endif |
67 |
> |
SET_DEFAULT_BINARY(); |
68 |
> |
SET_FILE_BINARY(stdin); |
69 |
> |
SET_FILE_BINARY(stdout); |
70 |
|
progname = argv[0]; |
71 |
+ |
samplefac = 0; |
72 |
|
|
73 |
|
for (i = 1; i < argc; i++) |
74 |
|
if (argv[i][0] == '-') |
77 |
|
dither = !dither; |
78 |
|
break; |
79 |
|
case 'g': |
80 |
< |
gamma = atof(argv[++i]); |
80 |
> |
gamv = atof(argv[++i]); |
81 |
|
break; |
82 |
|
case 'r': |
83 |
|
reverse = !reverse; |
93 |
|
case 'c': |
94 |
|
ncolors = atoi(argv[++i]); |
95 |
|
break; |
96 |
+ |
case 'n': |
97 |
+ |
samplefac = atoi(argv[++i]); |
98 |
+ |
break; |
99 |
|
default: |
100 |
|
goto userr; |
101 |
|
} |
102 |
|
else |
103 |
|
break; |
104 |
|
|
105 |
+ |
if (i < argc-2) |
106 |
+ |
goto userr; |
107 |
+ |
if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
108 |
+ |
sprintf(errmsg, "cannot open input \"%s\"", argv[i]); |
109 |
+ |
quiterr(errmsg); |
110 |
+ |
} |
111 |
+ |
if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { |
112 |
+ |
sprintf(errmsg, "cannot open output \"%s\"", argv[i+1]); |
113 |
+ |
quiterr(errmsg); |
114 |
+ |
} |
115 |
|
if (reverse) { |
126 |
– |
if (i < argc-2) |
127 |
– |
goto userr; |
128 |
– |
if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
129 |
– |
sprintf(errmsg, "can't open input \"%s\"", argv[i]); |
130 |
– |
quiterr(errmsg); |
131 |
– |
} |
116 |
|
/* get header */ |
117 |
|
if (getthead(&head, NULL, stdin) < 0) |
118 |
|
quiterr("bad targa file"); |
120 |
|
quiterr("incompatible format"); |
121 |
|
xmax = head.x; |
122 |
|
ymax = head.y; |
139 |
– |
/* open output file */ |
140 |
– |
if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { |
141 |
– |
sprintf(errmsg, "can't open output \"%s\"", argv[i+1]); |
142 |
– |
quiterr(errmsg); |
143 |
– |
} |
123 |
|
/* put header */ |
124 |
+ |
newheader("RADIANCE", stdout); |
125 |
|
printargs(i, argv, stdout); |
126 |
|
fputformat(COLRFMT, stdout); |
127 |
|
putchar('\n'); |
129 |
|
/* convert file */ |
130 |
|
tg2ra(&head); |
131 |
|
} else { |
132 |
< |
if (i < argc-2 || (!greyscale && i > argc-1)) |
133 |
< |
goto userr; |
154 |
< |
if ((inpic = openinput(argv[i], &head)) == NULL) { |
155 |
< |
sprintf(errmsg, "can't open input \"%s\"", argv[i]); |
156 |
< |
quiterr(errmsg); |
157 |
< |
} |
158 |
< |
if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { |
159 |
< |
sprintf(errmsg, "can't open output \"%s\"", argv[i+1]); |
160 |
< |
quiterr(errmsg); |
161 |
< |
} |
132 |
> |
if (getrhead(&head, stdin) < 0) |
133 |
> |
quiterr("bad Radiance input"); |
134 |
|
/* write header */ |
135 |
|
putthead(&head, NULL, stdout); |
136 |
|
/* convert file */ |
137 |
|
if (greyscale) |
138 |
< |
biq(dither,ncolors,1,rasmap); |
138 |
> |
getgrey(ncolors); |
139 |
|
else |
140 |
< |
ciq(dither,ncolors,1,rasmap); |
140 |
> |
getmapped(ncolors, dither); |
141 |
|
/* write data */ |
142 |
|
writetarga(&head, tarData, stdout); |
143 |
|
} |
144 |
|
quiterr(NULL); |
145 |
|
userr: |
146 |
|
fprintf(stderr, |
147 |
< |
"Usage: %s [-d][-c ncolors][-b][-g gamma][-e +/-stops] input [output]\n", |
147 |
> |
"Usage: %s [-d][-n samp][-c ncolors][-b][-g gamv][-e +/-stops] input [output]\n", |
148 |
|
progname); |
149 |
< |
fprintf(stderr, " Or: %s -r [-g gamma][-e +/-stops] [input [output]]\n", |
149 |
> |
fprintf(stderr, " Or: %s -r [-g gamv][-e +/-stops] [input [output]]\n", |
150 |
|
progname); |
151 |
|
exit(1); |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
< |
int |
156 |
< |
getint2(fp) /* get a 2-byte positive integer */ |
157 |
< |
register FILE *fp; |
155 |
> |
static int |
156 |
> |
getint2( /* get a 2-byte positive integer */ |
157 |
> |
register FILE *fp |
158 |
> |
) |
159 |
|
{ |
160 |
|
register int b1, b2; |
161 |
|
|
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
< |
putint2(i, fp) /* put a 2-byte positive integer */ |
170 |
< |
register int i; |
171 |
< |
register FILE *fp; |
169 |
> |
static void |
170 |
> |
putint2( /* put a 2-byte positive integer */ |
171 |
> |
register int i, |
172 |
> |
register FILE *fp |
173 |
> |
) |
174 |
|
{ |
175 |
|
putc(i&0xff, fp); |
176 |
|
putc(i>>8&0xff, fp); |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
< |
quiterr(err) /* print message and exit */ |
181 |
< |
char *err; |
180 |
> |
static void |
181 |
> |
quiterr( /* print message and exit */ |
182 |
> |
char *err |
183 |
> |
) |
184 |
|
{ |
185 |
|
if (err != NULL) { |
186 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
+ |
void |
194 |
|
eputs(s) |
195 |
|
char *s; |
196 |
|
{ |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
+ |
void |
202 |
|
quit(code) |
203 |
|
int code; |
204 |
|
{ |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
< |
getthead(hp, ip, fp) /* read header from input */ |
210 |
< |
struct hdStruct *hp; |
211 |
< |
char *ip; |
212 |
< |
register FILE *fp; |
209 |
> |
static int |
210 |
> |
getthead( /* read header from input */ |
211 |
> |
struct hdStruct *hp, |
212 |
> |
char *ip, |
213 |
> |
register FILE *fp |
214 |
> |
) |
215 |
|
{ |
216 |
|
int nidbytes; |
217 |
|
|
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
< |
putthead(hp, ip, fp) /* write header to output */ |
245 |
< |
struct hdStruct *hp; |
246 |
< |
char *ip; |
247 |
< |
register FILE *fp; |
244 |
> |
static int |
245 |
> |
putthead( /* write header to output */ |
246 |
> |
struct hdStruct *hp, |
247 |
> |
char *ip, |
248 |
> |
register FILE *fp |
249 |
> |
) |
250 |
|
{ |
251 |
|
if (ip != NULL) |
252 |
|
putc(strlen(ip), fp); |
271 |
|
} |
272 |
|
|
273 |
|
|
274 |
< |
pic * |
275 |
< |
openinput(fname, h) /* open RADIANCE input file */ |
276 |
< |
char *fname; |
277 |
< |
register struct hdStruct *h; |
274 |
> |
static int |
275 |
> |
getrhead( /* load RADIANCE input file header */ |
276 |
> |
register struct hdStruct *h, |
277 |
> |
FILE *fp |
278 |
> |
) |
279 |
|
{ |
296 |
– |
register pic *p; |
297 |
– |
|
298 |
– |
p = (pic *)emalloc(sizeof(pic)); |
299 |
– |
p->name = fname; |
300 |
– |
if (fname == NULL) |
301 |
– |
p->fp = stdin; |
302 |
– |
else if ((p->fp = fopen(fname, "r")) == NULL) |
303 |
– |
return(NULL); |
280 |
|
/* get header info. */ |
281 |
< |
if (checkheader(p->fp, COLRFMT, NULL) < 0 || |
282 |
< |
fgetresolu(&xmax, &ymax, p->fp) < 0) |
283 |
< |
quiterr("bad picture format"); |
308 |
< |
p->nexty = 0; |
309 |
< |
p->bytes_line = 0; /* variable length lines */ |
310 |
< |
p->pos.y = (long *)ecalloc(ymax, sizeof(long)); |
311 |
< |
p->pos.y[0] = ftell(p->fp); |
281 |
> |
if (checkheader(fp, COLRFMT, NULL) < 0 || |
282 |
> |
fgetresolu(&xmax, &ymax, fp) < 0) |
283 |
> |
return(-1); |
284 |
|
/* assign header */ |
285 |
|
h->textSize = 0; |
286 |
|
h->mapType = CM_HASMAP; |
299 |
|
/* allocate targa data */ |
300 |
|
tarData = taralloc(h); |
301 |
|
|
302 |
< |
return(p); |
302 |
> |
return(0); |
303 |
|
} |
304 |
|
|
305 |
|
|
306 |
< |
tg2ra(hp) /* targa file to RADIANCE file */ |
307 |
< |
struct hdStruct *hp; |
306 |
> |
static void |
307 |
> |
tg2ra( /* targa file to RADIANCE file */ |
308 |
> |
struct hdStruct *hp |
309 |
> |
) |
310 |
|
{ |
311 |
|
union { |
312 |
|
BYTE c3[256][3]; |
326 |
|
for (i = hp->mapOrig; i < hp->mapOrig+hp->mapLength; i++) |
327 |
|
if (hp->CMapBits == 24) |
328 |
|
setcolr(ctab[i], |
329 |
< |
pow((map.c3[i][2]+.5)/256.,gamma), |
330 |
< |
pow((map.c3[i][1]+.5)/256.,gamma), |
331 |
< |
pow((map.c3[i][0]+.5)/256.,gamma)); |
329 |
> |
pow((map.c3[i][2]+.5)/256.,gamv), |
330 |
> |
pow((map.c3[i][1]+.5)/256.,gamv), |
331 |
> |
pow((map.c3[i][0]+.5)/256.,gamv)); |
332 |
|
else |
333 |
|
setcolr(ctab[i], |
334 |
< |
pow((map.c4[i][3]+.5)/256.,gamma), |
335 |
< |
pow((map.c4[i][2]+.5)/256.,gamma), |
336 |
< |
pow((map.c4[i][1]+.5)/256.,gamma)); |
334 |
> |
pow((map.c4[i][3]+.5)/256.,gamv), |
335 |
> |
pow((map.c4[i][2]+.5)/256.,gamv), |
336 |
> |
pow((map.c4[i][1]+.5)/256.,gamv)); |
337 |
|
if (bradj) |
338 |
|
shiftcolrs(ctab, 256, bradj); |
339 |
|
/* allocate targa data */ |
349 |
|
if (fwritecolrs(scanline, xmax, stdout) < 0) |
350 |
|
quiterr("error writing RADIANCE file"); |
351 |
|
} |
352 |
< |
free((char *)scanline); |
353 |
< |
free((char *)tarData); |
352 |
> |
free((void *)scanline); |
353 |
> |
free((void *)tarData); |
354 |
|
} |
355 |
|
|
356 |
|
|
357 |
< |
picreadline3(y, l3) /* read in 3-byte scanline */ |
358 |
< |
int y; |
359 |
< |
register rgbpixel *l3; |
357 |
> |
static void |
358 |
> |
getmapped( /* read in and quantize image */ |
359 |
> |
int nc, /* number of colors to use */ |
360 |
> |
int dith /* use dithering? */ |
361 |
> |
) |
362 |
|
{ |
363 |
< |
register int i; |
363 |
> |
long fpos; |
364 |
> |
register int y; |
365 |
|
|
366 |
< |
if (inpic->nexty != y) { /* find scanline */ |
367 |
< |
if (inpic->bytes_line == 0) { |
368 |
< |
if (inpic->pos.y[y] == 0) { |
369 |
< |
while (inpic->nexty < y) { |
370 |
< |
if (freadcolrs(inl, xmax, inpic->fp) < 0) |
371 |
< |
quiterr("read error in picreadline3"); |
372 |
< |
inpic->pos.y[++inpic->nexty] = ftell(inpic->fp); |
373 |
< |
} |
374 |
< |
} else if (fseek(inpic->fp, inpic->pos.y[y], 0) == EOF) |
375 |
< |
quiterr("seek error in picreadline3"); |
376 |
< |
} else if (fseek(inpic->fp, y*inpic->bytes_line+inpic->pos.b, 0) == EOF) |
377 |
< |
quiterr("seek error in picreadline3"); |
378 |
< |
} else if (inpic->bytes_line == 0 && inpic->pos.y[inpic->nexty] == 0) |
379 |
< |
inpic->pos.y[inpic->nexty] = ftell(inpic->fp); |
403 |
< |
if (freadcolrs(inl, xmax, inpic->fp) < 0) /* read scanline */ |
404 |
< |
quiterr("read error in picreadline3"); |
405 |
< |
inpic->nexty = y+1; |
406 |
< |
/* convert scanline */ |
407 |
< |
normcolrs(inl, xmax, bradj); |
408 |
< |
for (i = 0; i < xmax; i++) { |
409 |
< |
l3[i].r = inl[i][RED]; |
410 |
< |
l3[i].g = inl[i][GRN]; |
411 |
< |
l3[i].b = inl[i][BLU]; |
366 |
> |
setcolrgam(gamv); |
367 |
> |
fpos = ftell(stdin); |
368 |
> |
if ((samplefac ? neu_init(xmax*ymax) : new_histo(xmax*ymax)) == -1) |
369 |
> |
quiterr("cannot initialized histogram"); |
370 |
> |
for (y = ymax-1; y >= 0; y--) { |
371 |
> |
if (freadcolrs(inl, xmax, stdin) < 0) |
372 |
> |
quiterr("error reading Radiance input"); |
373 |
> |
if (bradj) |
374 |
> |
shiftcolrs(inl, xmax, bradj); |
375 |
> |
colrs_gambs(inl, xmax); |
376 |
> |
if (samplefac) |
377 |
> |
neu_colrs(inl, xmax); |
378 |
> |
else |
379 |
> |
cnt_colrs(inl, xmax); |
380 |
|
} |
381 |
+ |
if (fseek(stdin, fpos, 0) == EOF) |
382 |
+ |
quiterr("Radiance input must be from a file"); |
383 |
+ |
if (samplefac) /* map colors */ |
384 |
+ |
neu_clrtab(nc); |
385 |
+ |
else |
386 |
+ |
new_clrtab(nc); |
387 |
+ |
for (y = ymax-1; y >= 0; y--) { |
388 |
+ |
if (freadcolrs(inl, xmax, stdin) < 0) |
389 |
+ |
quiterr("error reading Radiance input"); |
390 |
+ |
if (bradj) |
391 |
+ |
shiftcolrs(inl, xmax, bradj); |
392 |
+ |
colrs_gambs(inl, xmax); |
393 |
+ |
if (samplefac) |
394 |
+ |
if (dith) |
395 |
+ |
neu_dith_colrs(tarData+y*xmax, inl, xmax); |
396 |
+ |
else |
397 |
+ |
neu_map_colrs(tarData+y*xmax, inl, xmax); |
398 |
+ |
else |
399 |
+ |
if (dith) |
400 |
+ |
dith_colrs(tarData+y*xmax, inl, xmax); |
401 |
+ |
else |
402 |
+ |
map_colrs(tarData+y*xmax, inl, xmax); |
403 |
+ |
} |
404 |
|
} |
405 |
|
|
406 |
|
|
407 |
< |
picwriteline(y, l) /* save output scanline */ |
408 |
< |
int y; |
409 |
< |
pixel *l; |
407 |
> |
static void |
408 |
> |
getgrey( /* read in and convert to greyscale image */ |
409 |
> |
int nc /* number of colors to use */ |
410 |
> |
) |
411 |
|
{ |
412 |
< |
bcopy((char *)l, (char *)&tarData[(ymax-1-y)*xmax], xmax*sizeof(pixel)); |
412 |
> |
int y; |
413 |
> |
register BYTE *dp; |
414 |
> |
register int x; |
415 |
> |
|
416 |
> |
setcolrgam(gamv); |
417 |
> |
dp = tarData+xmax*ymax;; |
418 |
> |
for (y = ymax-1; y >= 0; y--) { |
419 |
> |
if (freadcolrs(inl, xmax, stdin) < 0) |
420 |
> |
quiterr("error reading Radiance input"); |
421 |
> |
if (bradj) |
422 |
> |
shiftcolrs(inl, xmax, bradj); |
423 |
> |
x = xmax; |
424 |
> |
while (x--) |
425 |
> |
inl[x][GRN] = normbright(inl[x]); |
426 |
> |
colrs_gambs(inl, xmax); |
427 |
> |
x = xmax; |
428 |
> |
if (nc < 256) |
429 |
> |
while (x--) |
430 |
> |
*--dp = ((long)inl[x][GRN]*nc+nc/2)>>8; |
431 |
> |
else |
432 |
> |
while (x--) |
433 |
> |
*--dp = inl[x][GRN]; |
434 |
> |
} |
435 |
> |
for (x = 0; x < nc; x++) |
436 |
> |
clrtab[x][RED] = clrtab[x][GRN] = |
437 |
> |
clrtab[x][BLU] = ((long)x*256+128)/nc; |
438 |
|
} |
439 |
|
|
440 |
|
|
441 |
< |
writetarga(h, d, fp) /* write out targa data */ |
442 |
< |
struct hdStruct *h; |
443 |
< |
pixel *d; |
444 |
< |
FILE *fp; |
441 |
> |
static void |
442 |
> |
writetarga( /* write out targa data */ |
443 |
> |
struct hdStruct *h, |
444 |
> |
BYTE *d, |
445 |
> |
FILE *fp |
446 |
> |
) |
447 |
|
{ |
448 |
+ |
register int i, j; |
449 |
+ |
|
450 |
+ |
for (i = 0; i < h->mapLength; i++) /* write color map */ |
451 |
+ |
for (j = 2; j >= 0; j--) |
452 |
+ |
putc(clrtab[i][j], fp); |
453 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
454 |
< |
if (fwrite((char *)d,h->x*sizeof(pixel),h->y,fp) != h->y) |
454 |
> |
if (fwrite((char *)d,h->x*sizeof(BYTE),h->y,fp) != h->y) |
455 |
|
quiterr("error writing targa file"); |
456 |
|
return; |
457 |
|
} |
459 |
|
} |
460 |
|
|
461 |
|
|
462 |
< |
readtarga(h, data, fp) /* read in targa data */ |
463 |
< |
struct hdStruct *h; |
464 |
< |
pixel *data; |
465 |
< |
FILE *fp; |
462 |
> |
static void |
463 |
> |
readtarga( /* read in targa data */ |
464 |
> |
struct hdStruct *h, |
465 |
> |
BYTE *data, |
466 |
> |
FILE *fp |
467 |
> |
) |
468 |
|
{ |
469 |
|
register int cnt, c; |
470 |
< |
register pixel *dp; |
470 |
> |
register BYTE *dp; |
471 |
|
|
472 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
473 |
< |
if (fread((char *)data,h->x*sizeof(pixel),h->y,fp) != h->y) |
473 |
> |
if (fread((char *)data,h->x*sizeof(BYTE),h->y,fp) != h->y) |
474 |
|
goto readerr; |
475 |
|
return; |
476 |
|
} |
493 |
|
return; |
494 |
|
readerr: |
495 |
|
quiterr("error reading targa file"); |
470 |
– |
} |
471 |
– |
|
472 |
– |
|
473 |
– |
picwritecm(cm) /* write out color map */ |
474 |
– |
colormap cm; |
475 |
– |
{ |
476 |
– |
register int i, j; |
477 |
– |
|
478 |
– |
for (j = 0; j < 256; j++) |
479 |
– |
for (i = 2; i >= 0; i--) |
480 |
– |
putc(cm[i][j], stdout); |
481 |
– |
} |
482 |
– |
|
483 |
– |
|
484 |
– |
picreadcm(map) /* do gamma correction if requested */ |
485 |
– |
colormap map; |
486 |
– |
{ |
487 |
– |
register int i, val; |
488 |
– |
|
489 |
– |
for (i = 0; i < 256; i++) { |
490 |
– |
val = pow((i+0.5)/256.0, 1.0/gamma) * 256.0; |
491 |
– |
map[0][i] = map[1][i] = map[2][i] = val; |
492 |
– |
} |
496 |
|
} |