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