9 |
|
*/ |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
< |
|
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" |
16 |
– |
|
19 |
|
#include "resolu.h" |
20 |
< |
|
20 |
> |
#include "clrtab.h" |
21 |
|
#include "targa.h" |
22 |
|
|
21 |
– |
#ifdef MSDOS |
22 |
– |
#include <fcntl.h> |
23 |
– |
#endif |
23 |
|
|
25 |
– |
#include <math.h> |
26 |
– |
|
27 |
– |
#ifndef BSD |
28 |
– |
#define bcopy(s,d,n) (void)memcpy(d,s,n) |
29 |
– |
#endif |
30 |
– |
|
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) |
30 |
|
#define taralloc(h) (BYTE *)emalloc((h)->x*(h)->y) |
31 |
|
|
32 |
|
BYTE clrtab[256][3]; |
40 |
– |
|
33 |
|
extern int samplefac; |
42 |
– |
|
43 |
– |
extern char *ecalloc(), *emalloc(); |
44 |
– |
|
45 |
– |
extern long ftell(); |
46 |
– |
|
34 |
|
double gamv = 2.2; /* gamv correction */ |
48 |
– |
|
35 |
|
int bradj = 0; /* brightness adjustment */ |
50 |
– |
|
36 |
|
char *progname; |
52 |
– |
|
37 |
|
char errmsg[128]; |
54 |
– |
|
38 |
|
COLR *inl; |
56 |
– |
|
39 |
|
BYTE *tarData; |
58 |
– |
|
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 |
|
{ |
61 |
|
struct hdStruct head; |
62 |
|
int dither = 1; |
64 |
|
int ncolors = 256; |
65 |
|
int greyscale = 0; |
66 |
|
int i; |
67 |
< |
#ifdef MSDOS |
68 |
< |
extern int _fmode; |
69 |
< |
_fmode = O_BINARY; |
75 |
< |
setmode(fileno(stdin), O_BINARY); |
76 |
< |
setmode(fileno(stdout), O_BINARY); |
77 |
< |
#endif |
67 |
> |
SET_DEFAULT_BINARY(); |
68 |
> |
SET_FILE_BINARY(stdin); |
69 |
> |
SET_FILE_BINARY(stdout); |
70 |
|
progname = argv[0]; |
71 |
|
samplefac = 0; |
72 |
|
|
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); |
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 |
< |
getrhead(h, fp) /* load RADIANCE input file header */ |
275 |
< |
register struct hdStruct *h; |
276 |
< |
FILE *fp; |
274 |
> |
static int |
275 |
> |
getrhead( /* load RADIANCE input file header */ |
276 |
> |
register struct hdStruct *h, |
277 |
> |
FILE *fp |
278 |
> |
) |
279 |
|
{ |
280 |
|
/* get header info. */ |
281 |
|
if (checkheader(fp, COLRFMT, NULL) < 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]; |
354 |
|
} |
355 |
|
|
356 |
|
|
357 |
< |
getmapped(nc, dith) /* read in and quantize image */ |
358 |
< |
int nc; /* number of colors to use */ |
359 |
< |
int dith; /* use dithering? */ |
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 |
|
long fpos; |
364 |
|
register int y; |
404 |
|
} |
405 |
|
|
406 |
|
|
407 |
< |
getgrey(nc) /* read in and convert to greyscale image */ |
408 |
< |
int nc; /* number of colors to use */ |
407 |
> |
static void |
408 |
> |
getgrey( /* read in and convert to greyscale image */ |
409 |
> |
int nc /* number of colors to use */ |
410 |
> |
) |
411 |
|
{ |
412 |
|
int y; |
413 |
|
register BYTE *dp; |
438 |
|
} |
439 |
|
|
440 |
|
|
441 |
< |
writetarga(h, d, fp) /* write out targa data */ |
442 |
< |
struct hdStruct *h; |
443 |
< |
BYTE *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 |
|
|
459 |
|
} |
460 |
|
|
461 |
|
|
462 |
< |
readtarga(h, data, fp) /* read in targa data */ |
463 |
< |
struct hdStruct *h; |
464 |
< |
BYTE *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 BYTE *dp; |