| 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_t16.c - program to convert between RADIANCE and |
| 6 |
|
* Targa 16, 24 and 32-bit images. |
| 8 |
|
* 11/2/88 Adapted from ra_t8.c |
| 9 |
|
*/ |
| 10 |
|
|
| 14 |
– |
#include <stdio.h> |
| 15 |
– |
|
| 16 |
– |
#ifdef MSDOS |
| 17 |
– |
#include <fcntl.h> |
| 18 |
– |
#endif |
| 19 |
– |
|
| 11 |
|
#include <math.h> |
| 12 |
< |
|
| 12 |
> |
#include "paths.h" |
| 13 |
> |
#include "platform.h" |
| 14 |
> |
#include "rtio.h" |
| 15 |
> |
#include "rtmisc.h" |
| 16 |
|
#include "color.h" |
| 23 |
– |
|
| 17 |
|
#include "resolu.h" |
| 25 |
– |
|
| 18 |
|
#include "random.h" |
| 27 |
– |
|
| 19 |
|
#include "targa.h" |
| 20 |
|
|
| 21 |
|
#define goodpic(h) (((h)->dataType==IM_RGB || (h)->dataType==IM_CRGB) \ |
| 23 |
|
|
| 24 |
|
#define taralloc(h) (unsigned char *)emalloc((h)->x*(h)->y*(h)->dataBits/8) |
| 25 |
|
|
| 26 |
< |
#define readtarga(h,d,f) ((h)->dataBits==16 ? readt16(h,d,f) : \ |
| 27 |
< |
readt24(h,d,f)) |
| 26 |
> |
#define readtarga(h,d,f) ((h)->dataBits==16 ? \ |
| 27 |
> |
readt16(h,(unsigned short*)d,f) : readt24(h,d,f)) |
| 28 |
|
|
| 29 |
< |
#define writetarga(h,d,f) ((h)->dataBits==16 ? writet16(h,d,f) : \ |
| 30 |
< |
writet24(h,d,f)) |
| 29 |
> |
#define writetarga(h,d,f) ((h)->dataBits==16 ? \ |
| 30 |
> |
writet16(h,(unsigned short*)d,f) : writet24(h,d,f)) |
| 31 |
|
|
| 41 |
– |
extern char *ecalloc(), *emalloc(); |
| 42 |
– |
|
| 32 |
|
double gamcor = 2.2; /* gamma correction */ |
| 44 |
– |
|
| 33 |
|
int bradj = 0; /* brightness adjustment */ |
| 46 |
– |
|
| 47 |
– |
char *progname; |
| 48 |
– |
|
| 34 |
|
char msg[128]; |
| 35 |
|
|
| 36 |
+ |
static int getint2(FILE *fp); |
| 37 |
+ |
static void putint2(int i, FILE *fp); |
| 38 |
+ |
static void quiterr(char *err); |
| 39 |
+ |
static int getthead(struct hdStruct *hp, char *ip, FILE *fp); |
| 40 |
+ |
static int putthead(struct hdStruct *hp, char *ip, FILE *fp); |
| 41 |
+ |
static void tg2ra(struct hdStruct *hp); |
| 42 |
+ |
static void ra2tg(struct hdStruct *hp); |
| 43 |
+ |
static void writet24(struct hdStruct *h, unsigned char *d, FILE *fp); |
| 44 |
+ |
static void writet16(struct hdStruct *h, unsigned short *d, FILE *fp); |
| 45 |
+ |
static void readt24(struct hdStruct *h, unsigned char *data, FILE *fp); |
| 46 |
+ |
static void readt16(struct hdStruct *h, unsigned short *data, FILE *fp); |
| 47 |
|
|
| 48 |
< |
main(argc, argv) |
| 49 |
< |
int argc; |
| 50 |
< |
char *argv[]; |
| 48 |
> |
|
| 49 |
> |
int |
| 50 |
> |
main(int argc, char *argv[]) |
| 51 |
|
{ |
| 52 |
|
struct hdStruct head; |
| 53 |
|
int reverse = 0; |
| 54 |
|
int i; |
| 55 |
< |
#ifdef MSDOS |
| 56 |
< |
extern int _fmode; |
| 57 |
< |
_fmode = O_BINARY; |
| 58 |
< |
setmode(fileno(stdin), O_BINARY); |
| 59 |
< |
setmode(fileno(stdout), O_BINARY); |
| 64 |
< |
#endif |
| 65 |
< |
progname = argv[0]; |
| 55 |
> |
|
| 56 |
> |
SET_DEFAULT_BINARY(); |
| 57 |
> |
SET_FILE_BINARY(stdin); |
| 58 |
> |
SET_FILE_BINARY(stdout); |
| 59 |
> |
fixargv0(argv[0]); |
| 60 |
|
|
| 61 |
|
head.dataBits = 16; |
| 62 |
|
for (i = 1; i < argc; i++) |
| 107 |
|
if (!goodpic(&head)) |
| 108 |
|
quiterr("incompatible format"); |
| 109 |
|
/* put header */ |
| 110 |
+ |
newheader("RADIANCE", stdout); |
| 111 |
|
printargs(i, argv, stdout); |
| 112 |
|
fputformat(COLRFMT, stdout); |
| 113 |
|
putchar('\n'); |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
|
| 141 |
< |
int |
| 142 |
< |
getint2(fp) /* get a 2-byte positive integer */ |
| 143 |
< |
register FILE *fp; |
| 141 |
> |
static int |
| 142 |
> |
getint2( /* get a 2-byte positive integer */ |
| 143 |
> |
register FILE *fp |
| 144 |
> |
) |
| 145 |
|
{ |
| 146 |
|
register int b1, b2; |
| 147 |
|
|
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
|
| 155 |
< |
putint2(i, fp) /* put a 2-byte positive integer */ |
| 156 |
< |
register int i; |
| 157 |
< |
register FILE *fp; |
| 155 |
> |
static void |
| 156 |
> |
putint2( /* put a 2-byte positive integer */ |
| 157 |
> |
register int i, |
| 158 |
> |
register FILE *fp |
| 159 |
> |
) |
| 160 |
|
{ |
| 161 |
|
putc(i&0xff, fp); |
| 162 |
|
putc(i>>8&0xff, fp); |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
|
| 166 |
< |
quiterr(err) /* print message and exit */ |
| 167 |
< |
char *err; |
| 166 |
> |
static void |
| 167 |
> |
quiterr( /* print message and exit */ |
| 168 |
> |
char *err |
| 169 |
> |
) |
| 170 |
|
{ |
| 171 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
| 172 |
|
exit(1); |
| 173 |
|
} |
| 174 |
|
|
| 175 |
|
|
| 176 |
< |
eputs(s) |
| 177 |
< |
char *s; |
| 176 |
> |
void |
| 177 |
> |
eputs( |
| 178 |
> |
char *s |
| 179 |
> |
) |
| 180 |
|
{ |
| 181 |
|
fputs(s, stderr); |
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
|
| 185 |
< |
quit(code) |
| 186 |
< |
int code; |
| 185 |
> |
void |
| 186 |
> |
quit( |
| 187 |
> |
int code |
| 188 |
> |
) |
| 189 |
|
{ |
| 190 |
|
exit(code); |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
|
| 194 |
< |
getthead(hp, ip, fp) /* read header from input */ |
| 195 |
< |
struct hdStruct *hp; |
| 196 |
< |
char *ip; |
| 197 |
< |
register FILE *fp; |
| 194 |
> |
static int |
| 195 |
> |
getthead( /* read header from input */ |
| 196 |
> |
struct hdStruct *hp, |
| 197 |
> |
char *ip, |
| 198 |
> |
register FILE *fp |
| 199 |
> |
) |
| 200 |
|
{ |
| 201 |
|
int nidbytes; |
| 202 |
|
|
| 226 |
|
} |
| 227 |
|
|
| 228 |
|
|
| 229 |
< |
putthead(hp, ip, fp) /* write header to output */ |
| 230 |
< |
struct hdStruct *hp; |
| 231 |
< |
char *ip; |
| 232 |
< |
register FILE *fp; |
| 229 |
> |
static int |
| 230 |
> |
putthead( /* write header to output */ |
| 231 |
> |
struct hdStruct *hp, |
| 232 |
> |
char *ip, |
| 233 |
> |
register FILE *fp |
| 234 |
> |
) |
| 235 |
|
{ |
| 236 |
|
if (ip != NULL) |
| 237 |
|
putc(strlen(ip), fp); |
| 256 |
|
} |
| 257 |
|
|
| 258 |
|
|
| 259 |
< |
tg2ra(hp) /* targa file to RADIANCE file */ |
| 260 |
< |
struct hdStruct *hp; |
| 259 |
> |
static void |
| 260 |
> |
tg2ra( /* targa file to RADIANCE file */ |
| 261 |
> |
struct hdStruct *hp |
| 262 |
> |
) |
| 263 |
|
{ |
| 264 |
|
COLR *scanline; |
| 265 |
|
unsigned char *tarData; |
| 300 |
|
if (fwritecolrs(scanline, hp->x, stdout) < 0) |
| 301 |
|
quiterr("error writing RADIANCE file"); |
| 302 |
|
} |
| 303 |
< |
free((char *)scanline); |
| 304 |
< |
free((char *)tarData); |
| 303 |
> |
free((void *)scanline); |
| 304 |
> |
free((void *)tarData); |
| 305 |
|
} |
| 306 |
|
|
| 307 |
|
|
| 308 |
< |
ra2tg(hp) /* convert radiance to targa file */ |
| 309 |
< |
struct hdStruct *hp; |
| 308 |
> |
static void |
| 309 |
> |
ra2tg( /* convert radiance to targa file */ |
| 310 |
> |
struct hdStruct *hp |
| 311 |
> |
) |
| 312 |
|
{ |
| 313 |
|
register int i, j; |
| 314 |
|
unsigned char *tarData; |
| 351 |
|
/* write out targa data */ |
| 352 |
|
writetarga(hp, tarData, stdout); |
| 353 |
|
|
| 354 |
< |
free((char *)inl); |
| 355 |
< |
free((char *)tarData); |
| 354 |
> |
free((void *)inl); |
| 355 |
> |
free((void *)tarData); |
| 356 |
|
} |
| 357 |
|
|
| 358 |
|
|
| 359 |
< |
writet24(h, d, fp) /* write out 24-bit targa data */ |
| 360 |
< |
struct hdStruct *h; |
| 361 |
< |
unsigned char *d; |
| 362 |
< |
FILE *fp; |
| 359 |
> |
static void |
| 360 |
> |
writet24( /* write out 24-bit targa data */ |
| 361 |
> |
struct hdStruct *h, |
| 362 |
> |
unsigned char *d, |
| 363 |
> |
FILE *fp |
| 364 |
> |
) |
| 365 |
|
{ |
| 366 |
|
if (h->dataType == IM_RGB) { /* uncompressed */ |
| 367 |
|
if (fwrite((char *)d, 3*h->x, h->y, fp) != h->y) |
| 372 |
|
} |
| 373 |
|
|
| 374 |
|
|
| 375 |
< |
writet16(h, d, fp) /* write out 16-bit targa data */ |
| 376 |
< |
struct hdStruct *h; |
| 377 |
< |
register unsigned short *d; |
| 378 |
< |
FILE *fp; |
| 375 |
> |
static void |
| 376 |
> |
writet16( /* write out 16-bit targa data */ |
| 377 |
> |
struct hdStruct *h, |
| 378 |
> |
register unsigned short *d, |
| 379 |
> |
FILE *fp |
| 380 |
> |
) |
| 381 |
|
{ |
| 382 |
|
register int cnt; |
| 383 |
|
|
| 392 |
|
} |
| 393 |
|
|
| 394 |
|
|
| 395 |
< |
readt24(h, data, fp) /* read in 24-bit targa data */ |
| 396 |
< |
register struct hdStruct *h; |
| 397 |
< |
unsigned char *data; |
| 398 |
< |
FILE *fp; |
| 395 |
> |
static void |
| 396 |
> |
readt24( /* read in 24-bit targa data */ |
| 397 |
> |
register struct hdStruct *h, |
| 398 |
> |
unsigned char *data, |
| 399 |
> |
FILE *fp |
| 400 |
> |
) |
| 401 |
|
{ |
| 402 |
|
register int cnt, c; |
| 403 |
|
register unsigned char *dp; |
| 435 |
|
} |
| 436 |
|
|
| 437 |
|
|
| 438 |
< |
readt16(h, data, fp) /* read in 16-bit targa data */ |
| 439 |
< |
register struct hdStruct *h; |
| 440 |
< |
unsigned short *data; |
| 441 |
< |
FILE *fp; |
| 438 |
> |
static void |
| 439 |
> |
readt16( /* read in 16-bit targa data */ |
| 440 |
> |
register struct hdStruct *h, |
| 441 |
> |
unsigned short *data, |
| 442 |
> |
FILE *fp |
| 443 |
> |
) |
| 444 |
|
{ |
| 445 |
|
register int cnt, c; |
| 446 |
|
register unsigned short *dp; |