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