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" |
19 |
|
#include "resolu.h" |
20 |
|
#include "random.h" |
25 |
|
|
26 |
|
#define taralloc(h) (unsigned char *)emalloc((h)->x*(h)->y*(h)->dataBits/8) |
27 |
|
|
28 |
< |
#define readtarga(h,d,f) ((h)->dataBits==16 ? readt16(h,d,f) : \ |
29 |
< |
readt24(h,d,f)) |
28 |
> |
#define readtarga(h,d,f) ((h)->dataBits==16 ? \ |
29 |
> |
readt16(h,(unsigned short*)d,f) : readt24(h,d,f)) |
30 |
|
|
31 |
< |
#define writetarga(h,d,f) ((h)->dataBits==16 ? writet16(h,d,f) : \ |
32 |
< |
writet24(h,d,f)) |
31 |
> |
#define writetarga(h,d,f) ((h)->dataBits==16 ? \ |
32 |
> |
writet16(h,(unsigned short*)d,f) : writet24(h,d,f)) |
33 |
|
|
32 |
– |
extern char *ecalloc(), *emalloc(); |
33 |
– |
|
34 |
|
double gamcor = 2.2; /* gamma correction */ |
35 |
– |
|
35 |
|
int bradj = 0; /* brightness adjustment */ |
37 |
– |
|
36 |
|
char *progname; |
39 |
– |
|
37 |
|
char msg[128]; |
38 |
|
|
39 |
+ |
static int getint2(FILE *fp); |
40 |
+ |
static void putint2(int i, FILE *fp); |
41 |
+ |
static void quiterr(char *err); |
42 |
+ |
static int getthead(struct hdStruct *hp, char *ip, FILE *fp); |
43 |
+ |
static int putthead(struct hdStruct *hp, char *ip, FILE *fp); |
44 |
+ |
static void tg2ra(struct hdStruct *hp); |
45 |
+ |
static void ra2tg(struct hdStruct *hp); |
46 |
+ |
static void writet24(struct hdStruct *h, unsigned char *d, FILE *fp); |
47 |
+ |
static void writet16(struct hdStruct *h, unsigned short *d, FILE *fp); |
48 |
+ |
static void readt24(struct hdStruct *h, unsigned char *data, FILE *fp); |
49 |
+ |
static void readt16(struct hdStruct *h, unsigned short *data, FILE *fp); |
50 |
|
|
51 |
< |
main(argc, argv) |
52 |
< |
int argc; |
53 |
< |
char *argv[]; |
51 |
> |
|
52 |
> |
int |
53 |
> |
main(int argc, char *argv[]) |
54 |
|
{ |
55 |
|
struct hdStruct head; |
56 |
|
int reverse = 0; |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
< |
int |
144 |
< |
getint2(fp) /* get a 2-byte positive integer */ |
145 |
< |
register FILE *fp; |
143 |
> |
static int |
144 |
> |
getint2( /* get a 2-byte positive integer */ |
145 |
> |
register FILE *fp |
146 |
> |
) |
147 |
|
{ |
148 |
|
register int b1, b2; |
149 |
|
|
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
< |
putint2(i, fp) /* put a 2-byte positive integer */ |
158 |
< |
register int i; |
159 |
< |
register FILE *fp; |
157 |
> |
static void |
158 |
> |
putint2( /* put a 2-byte positive integer */ |
159 |
> |
register int i, |
160 |
> |
register FILE *fp |
161 |
> |
) |
162 |
|
{ |
163 |
|
putc(i&0xff, fp); |
164 |
|
putc(i>>8&0xff, fp); |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
< |
quiterr(err) /* print message and exit */ |
169 |
< |
char *err; |
168 |
> |
static void |
169 |
> |
quiterr( /* print message and exit */ |
170 |
> |
char *err |
171 |
> |
) |
172 |
|
{ |
173 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
174 |
|
exit(1); |
176 |
|
|
177 |
|
|
178 |
|
void |
179 |
< |
eputs(s) |
180 |
< |
char *s; |
179 |
> |
eputs( |
180 |
> |
char *s |
181 |
> |
) |
182 |
|
{ |
183 |
|
fputs(s, stderr); |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
void |
188 |
< |
quit(code) |
189 |
< |
int code; |
188 |
> |
quit( |
189 |
> |
int code |
190 |
> |
) |
191 |
|
{ |
192 |
|
exit(code); |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
< |
getthead(hp, ip, fp) /* read header from input */ |
197 |
< |
struct hdStruct *hp; |
198 |
< |
char *ip; |
199 |
< |
register FILE *fp; |
196 |
> |
static int |
197 |
> |
getthead( /* read header from input */ |
198 |
> |
struct hdStruct *hp, |
199 |
> |
char *ip, |
200 |
> |
register FILE *fp |
201 |
> |
) |
202 |
|
{ |
203 |
|
int nidbytes; |
204 |
|
|
228 |
|
} |
229 |
|
|
230 |
|
|
231 |
< |
putthead(hp, ip, fp) /* write header to output */ |
232 |
< |
struct hdStruct *hp; |
233 |
< |
char *ip; |
234 |
< |
register FILE *fp; |
231 |
> |
static int |
232 |
> |
putthead( /* write header to output */ |
233 |
> |
struct hdStruct *hp, |
234 |
> |
char *ip, |
235 |
> |
register FILE *fp |
236 |
> |
) |
237 |
|
{ |
238 |
|
if (ip != NULL) |
239 |
|
putc(strlen(ip), fp); |
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
< |
tg2ra(hp) /* targa file to RADIANCE file */ |
262 |
< |
struct hdStruct *hp; |
261 |
> |
static void |
262 |
> |
tg2ra( /* targa file to RADIANCE file */ |
263 |
> |
struct hdStruct *hp |
264 |
> |
) |
265 |
|
{ |
266 |
|
COLR *scanline; |
267 |
|
unsigned char *tarData; |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
< |
ra2tg(hp) /* convert radiance to targa file */ |
311 |
< |
struct hdStruct *hp; |
310 |
> |
static void |
311 |
> |
ra2tg( /* convert radiance to targa file */ |
312 |
> |
struct hdStruct *hp |
313 |
> |
) |
314 |
|
{ |
315 |
|
register int i, j; |
316 |
|
unsigned char *tarData; |
358 |
|
} |
359 |
|
|
360 |
|
|
361 |
< |
writet24(h, d, fp) /* write out 24-bit targa data */ |
362 |
< |
struct hdStruct *h; |
363 |
< |
unsigned char *d; |
364 |
< |
FILE *fp; |
361 |
> |
static void |
362 |
> |
writet24( /* write out 24-bit targa data */ |
363 |
> |
struct hdStruct *h, |
364 |
> |
unsigned char *d, |
365 |
> |
FILE *fp |
366 |
> |
) |
367 |
|
{ |
368 |
|
if (h->dataType == IM_RGB) { /* uncompressed */ |
369 |
|
if (fwrite((char *)d, 3*h->x, h->y, fp) != h->y) |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
< |
writet16(h, d, fp) /* write out 16-bit targa data */ |
378 |
< |
struct hdStruct *h; |
379 |
< |
register unsigned short *d; |
380 |
< |
FILE *fp; |
377 |
> |
static void |
378 |
> |
writet16( /* write out 16-bit targa data */ |
379 |
> |
struct hdStruct *h, |
380 |
> |
register unsigned short *d, |
381 |
> |
FILE *fp |
382 |
> |
) |
383 |
|
{ |
384 |
|
register int cnt; |
385 |
|
|
394 |
|
} |
395 |
|
|
396 |
|
|
397 |
< |
readt24(h, data, fp) /* read in 24-bit targa data */ |
398 |
< |
register struct hdStruct *h; |
399 |
< |
unsigned char *data; |
400 |
< |
FILE *fp; |
397 |
> |
static void |
398 |
> |
readt24( /* read in 24-bit targa data */ |
399 |
> |
register struct hdStruct *h, |
400 |
> |
unsigned char *data, |
401 |
> |
FILE *fp |
402 |
> |
) |
403 |
|
{ |
404 |
|
register int cnt, c; |
405 |
|
register unsigned char *dp; |
437 |
|
} |
438 |
|
|
439 |
|
|
440 |
< |
readt16(h, data, fp) /* read in 16-bit targa data */ |
441 |
< |
register struct hdStruct *h; |
442 |
< |
unsigned short *data; |
443 |
< |
FILE *fp; |
440 |
> |
static void |
441 |
> |
readt16( /* read in 16-bit targa data */ |
442 |
> |
register struct hdStruct *h, |
443 |
> |
unsigned short *data, |
444 |
> |
FILE *fp |
445 |
> |
) |
446 |
|
{ |
447 |
|
register int cnt, c; |
448 |
|
register unsigned short *dp; |