8 |
|
* 8/22/88 Adapted from ra_pr.c |
9 |
|
*/ |
10 |
|
|
11 |
< |
#include <stdio.h> |
11 |
> |
#include <math.h> |
12 |
|
|
13 |
< |
#include <time.h> |
14 |
< |
|
13 |
> |
#include "platform.h" |
14 |
> |
#include "rtio.h" |
15 |
> |
#include "rtmisc.h" |
16 |
|
#include "color.h" |
16 |
– |
|
17 |
|
#include "resolu.h" |
18 |
< |
|
18 |
> |
#include "clrtab.h" |
19 |
|
#include "targa.h" |
20 |
|
|
21 |
– |
#ifdef MSDOS |
22 |
– |
#include <fcntl.h> |
23 |
– |
#endif |
21 |
|
|
25 |
– |
#include <math.h> |
26 |
– |
|
27 |
– |
#ifndef BSD |
28 |
– |
#define bcopy(s,d,n) (void)memcpy(d,s,n) |
29 |
– |
#endif |
30 |
– |
|
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 && \ |
26 |
|
((h)->CMapBits==24 || (h)->CMapBits==32)) |
27 |
|
|
28 |
< |
#define taralloc(h) (BYTE *)emalloc((h)->x*(h)->y) |
28 |
> |
#define taralloc(h) (uby8 *)emalloc((h)->x*(h)->y) |
29 |
|
|
30 |
< |
BYTE clrtab[256][3]; |
40 |
< |
|
30 |
> |
uby8 clrtab[256][3]; |
31 |
|
extern int samplefac; |
42 |
– |
|
43 |
– |
extern char *ecalloc(), *emalloc(); |
44 |
– |
|
45 |
– |
extern long ftell(); |
46 |
– |
|
32 |
|
double gamv = 2.2; /* gamv correction */ |
48 |
– |
|
33 |
|
int bradj = 0; /* brightness adjustment */ |
50 |
– |
|
34 |
|
char *progname; |
52 |
– |
|
35 |
|
char errmsg[128]; |
54 |
– |
|
36 |
|
COLR *inl; |
37 |
< |
|
57 |
< |
BYTE *tarData; |
58 |
< |
|
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 |
|
struct hdStruct head; |
60 |
|
int dither = 1; |
62 |
|
int ncolors = 256; |
63 |
|
int greyscale = 0; |
64 |
|
int i; |
65 |
< |
#ifdef MSDOS |
66 |
< |
extern int _fmode; |
67 |
< |
_fmode = O_BINARY; |
75 |
< |
setmode(fileno(stdin), O_BINARY); |
76 |
< |
setmode(fileno(stdout), O_BINARY); |
77 |
< |
#endif |
65 |
> |
SET_DEFAULT_BINARY(); |
66 |
> |
SET_FILE_BINARY(stdin); |
67 |
> |
SET_FILE_BINARY(stdout); |
68 |
|
progname = argv[0]; |
69 |
|
samplefac = 0; |
70 |
|
|
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); |
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 |
< |
getrhead(h, fp) /* load RADIANCE input file header */ |
273 |
< |
register struct hdStruct *h; |
274 |
< |
FILE *fp; |
272 |
> |
static int |
273 |
> |
getrhead( /* load RADIANCE input file header */ |
274 |
> |
register struct hdStruct *h, |
275 |
> |
FILE *fp |
276 |
> |
) |
277 |
|
{ |
278 |
|
/* get header info. */ |
279 |
|
if (checkheader(fp, COLRFMT, NULL) < 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; |
352 |
|
} |
353 |
|
|
354 |
|
|
355 |
< |
getmapped(nc, dith) /* read in and quantize image */ |
356 |
< |
int nc; /* number of colors to use */ |
357 |
< |
int dith; /* use dithering? */ |
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 |
|
long fpos; |
362 |
|
register int y; |
402 |
|
} |
403 |
|
|
404 |
|
|
405 |
< |
getgrey(nc) /* read in and convert to greyscale image */ |
406 |
< |
int nc; /* number of colors to use */ |
405 |
> |
static void |
406 |
> |
getgrey( /* read in and convert to greyscale image */ |
407 |
> |
int nc /* number of colors to use */ |
408 |
> |
) |
409 |
|
{ |
410 |
|
int y; |
411 |
< |
register BYTE *dp; |
411 |
> |
register uby8 *dp; |
412 |
|
register int x; |
413 |
|
|
414 |
|
setcolrgam(gamv); |
436 |
|
} |
437 |
|
|
438 |
|
|
439 |
< |
writetarga(h, d, fp) /* write out targa data */ |
440 |
< |
struct hdStruct *h; |
441 |
< |
BYTE *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 |
|
|
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(BYTE),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 |
< |
BYTE *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 BYTE *dp; |
468 |
> |
register uby8 *dp; |
469 |
|
|
470 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
471 |
< |
if (fread((char *)data,h->x*sizeof(BYTE),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 |
|
} |