8 |
|
* 8/22/88 Adapted from ra_pr.c |
9 |
|
*/ |
10 |
|
|
11 |
– |
#include <stdio.h> |
12 |
– |
#include <string.h> |
13 |
– |
#include <time.h> |
11 |
|
#include <math.h> |
15 |
– |
|
12 |
|
#include "platform.h" |
13 |
+ |
#include "rtio.h" |
14 |
|
#include "rtmisc.h" |
15 |
|
#include "color.h" |
16 |
|
#include "resolu.h" |
24 |
|
#define my_mapType(h) ((h)->mapType==CM_HASMAP && \ |
25 |
|
((h)->CMapBits==24 || (h)->CMapBits==32)) |
26 |
|
|
27 |
< |
#define taralloc(h) (BYTE *)emalloc((h)->x*(h)->y) |
27 |
> |
#define taralloc(h) (uby8 *)emalloc((h)->x*(h)->y) |
28 |
|
|
29 |
< |
BYTE clrtab[256][3]; |
29 |
> |
uby8 clrtab[256][3]; |
30 |
|
extern int samplefac; |
31 |
|
double gamv = 2.2; /* gamv correction */ |
32 |
|
int bradj = 0; /* brightness adjustment */ |
36 |
– |
char *progname; |
33 |
|
char errmsg[128]; |
34 |
|
COLR *inl; |
35 |
< |
BYTE *tarData; |
35 |
> |
uby8 *tarData; |
36 |
|
int xmax, ymax; |
37 |
|
|
38 |
|
static int getint2(FILE *fp); |
44 |
|
static void tg2ra(struct hdStruct *hp); |
45 |
|
static void getmapped(int nc, int dith); |
46 |
|
static void getgrey(int nc); |
47 |
< |
static void writetarga(struct hdStruct *h, BYTE *d, FILE *fp); |
48 |
< |
static void readtarga(struct hdStruct *h, BYTE *data, FILE *fp); |
47 |
> |
static void writetarga(struct hdStruct *h, uby8 *d, FILE *fp); |
48 |
> |
static void readtarga(struct hdStruct *h, uby8 *data, FILE *fp); |
49 |
|
|
50 |
|
|
51 |
|
int |
60 |
|
int ncolors = 256; |
61 |
|
int greyscale = 0; |
62 |
|
int i; |
63 |
+ |
|
64 |
|
SET_DEFAULT_BINARY(); |
65 |
|
SET_FILE_BINARY(stdin); |
66 |
|
SET_FILE_BINARY(stdout); |
67 |
< |
progname = argv[0]; |
67 |
> |
fixargv0(argv[0]); |
68 |
|
samplefac = 0; |
69 |
|
|
70 |
|
for (i = 1; i < argc; i++) |
151 |
|
|
152 |
|
static int |
153 |
|
getint2( /* get a 2-byte positive integer */ |
154 |
< |
register FILE *fp |
154 |
> |
FILE *fp |
155 |
|
) |
156 |
|
{ |
157 |
< |
register int b1, b2; |
157 |
> |
int b1, b2; |
158 |
|
|
159 |
|
if ((b1 = getc(fp)) == EOF || (b2 = getc(fp)) == EOF) |
160 |
|
quiterr("read error"); |
165 |
|
|
166 |
|
static void |
167 |
|
putint2( /* put a 2-byte positive integer */ |
168 |
< |
register int i, |
169 |
< |
register FILE *fp |
168 |
> |
int i, |
169 |
> |
FILE *fp |
170 |
|
) |
171 |
|
{ |
172 |
|
putc(i&0xff, fp); |
188 |
|
|
189 |
|
|
190 |
|
void |
191 |
< |
eputs(s) |
195 |
< |
char *s; |
191 |
> |
eputs(const char *s) |
192 |
|
{ |
193 |
|
fputs(s, stderr); |
194 |
|
} |
195 |
|
|
196 |
|
|
197 |
|
void |
198 |
< |
quit(code) |
203 |
< |
int code; |
198 |
> |
quit(int code) |
199 |
|
{ |
200 |
|
exit(code); |
201 |
|
} |
205 |
|
getthead( /* read header from input */ |
206 |
|
struct hdStruct *hp, |
207 |
|
char *ip, |
208 |
< |
register FILE *fp |
208 |
> |
FILE *fp |
209 |
|
) |
210 |
|
{ |
211 |
|
int nidbytes; |
240 |
|
putthead( /* write header to output */ |
241 |
|
struct hdStruct *hp, |
242 |
|
char *ip, |
243 |
< |
register FILE *fp |
243 |
> |
FILE *fp |
244 |
|
) |
245 |
|
{ |
246 |
|
if (ip != NULL) |
268 |
|
|
269 |
|
static int |
270 |
|
getrhead( /* load RADIANCE input file header */ |
271 |
< |
register struct hdStruct *h, |
271 |
> |
struct hdStruct *h, |
272 |
|
FILE *fp |
273 |
|
) |
274 |
|
{ |
304 |
|
) |
305 |
|
{ |
306 |
|
union { |
307 |
< |
BYTE c3[256][3]; |
308 |
< |
BYTE c4[256][4]; |
307 |
> |
uby8 c3[256][3]; |
308 |
> |
uby8 c4[256][4]; |
309 |
|
} map; |
310 |
|
COLR ctab[256]; |
311 |
|
COLR *scanline; |
312 |
< |
register int i, j; |
312 |
> |
int i, j; |
313 |
|
|
314 |
|
/* get color table */ |
315 |
|
if ((hp->CMapBits==24 ? fread((char *)(map.c3+hp->mapOrig), |
356 |
|
) |
357 |
|
{ |
358 |
|
long fpos; |
359 |
< |
register int y; |
359 |
> |
int y; |
360 |
|
|
361 |
|
setcolrgam(gamv); |
362 |
|
fpos = ftell(stdin); |
405 |
|
) |
406 |
|
{ |
407 |
|
int y; |
408 |
< |
register BYTE *dp; |
409 |
< |
register int x; |
408 |
> |
uby8 *dp; |
409 |
> |
int x; |
410 |
|
|
411 |
|
setcolrgam(gamv); |
412 |
|
dp = tarData+xmax*ymax;; |
436 |
|
static void |
437 |
|
writetarga( /* write out targa data */ |
438 |
|
struct hdStruct *h, |
439 |
< |
BYTE *d, |
439 |
> |
uby8 *d, |
440 |
|
FILE *fp |
441 |
|
) |
442 |
|
{ |
443 |
< |
register int i, j; |
443 |
> |
int i, j; |
444 |
|
|
445 |
|
for (i = 0; i < h->mapLength; i++) /* write color map */ |
446 |
|
for (j = 2; j >= 0; j--) |
447 |
|
putc(clrtab[i][j], fp); |
448 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
449 |
< |
if (fwrite((char *)d,h->x*sizeof(BYTE),h->y,fp) != h->y) |
449 |
> |
if (fwrite((char *)d,h->x*sizeof(uby8),h->y,fp) != h->y) |
450 |
|
quiterr("error writing targa file"); |
451 |
|
return; |
452 |
|
} |
457 |
|
static void |
458 |
|
readtarga( /* read in targa data */ |
459 |
|
struct hdStruct *h, |
460 |
< |
BYTE *data, |
460 |
> |
uby8 *data, |
461 |
|
FILE *fp |
462 |
|
) |
463 |
|
{ |
464 |
< |
register int cnt, c; |
465 |
< |
register BYTE *dp; |
464 |
> |
int cnt, c; |
465 |
> |
uby8 *dp; |
466 |
|
|
467 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
468 |
< |
if (fread((char *)data,h->x*sizeof(BYTE),h->y,fp) != h->y) |
468 |
> |
if (fread((char *)data,h->x*sizeof(uby8),h->y,fp) != h->y) |
469 |
|
goto readerr; |
470 |
|
return; |
471 |
|
} |