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> |
12 |
|
|
13 |
|
#include "platform.h" |
14 |
+ |
#include "rtio.h" |
15 |
|
#include "rtmisc.h" |
16 |
|
#include "color.h" |
17 |
|
#include "resolu.h" |
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]; |
30 |
> |
uby8 clrtab[256][3]; |
31 |
|
extern int samplefac; |
32 |
|
double gamv = 2.2; /* gamv correction */ |
33 |
|
int bradj = 0; /* brightness adjustment */ |
34 |
|
char *progname; |
35 |
|
char errmsg[128]; |
36 |
|
COLR *inl; |
37 |
< |
BYTE *tarData; |
37 |
> |
uby8 *tarData; |
38 |
|
int xmax, ymax; |
39 |
|
|
40 |
|
static int getint2(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, BYTE *d, FILE *fp); |
50 |
< |
static void readtarga(struct hdStruct *h, BYTE *data, FILE *fp); |
49 |
> |
static void writetarga(struct hdStruct *h, uby8 *d, FILE *fp); |
50 |
> |
static void readtarga(struct hdStruct *h, uby8 *data, FILE *fp); |
51 |
|
|
52 |
|
|
53 |
|
int |
152 |
|
|
153 |
|
static int |
154 |
|
getint2( /* get a 2-byte positive integer */ |
155 |
< |
register FILE *fp |
155 |
> |
FILE *fp |
156 |
|
) |
157 |
|
{ |
158 |
< |
register int b1, b2; |
158 |
> |
int b1, b2; |
159 |
|
|
160 |
|
if ((b1 = getc(fp)) == EOF || (b2 = getc(fp)) == EOF) |
161 |
|
quiterr("read error"); |
166 |
|
|
167 |
|
static void |
168 |
|
putint2( /* put a 2-byte positive integer */ |
169 |
< |
register int i, |
170 |
< |
register FILE *fp |
169 |
> |
int i, |
170 |
> |
FILE *fp |
171 |
|
) |
172 |
|
{ |
173 |
|
putc(i&0xff, fp); |
189 |
|
|
190 |
|
|
191 |
|
void |
192 |
< |
eputs(s) |
195 |
< |
char *s; |
192 |
> |
eputs(const char *s) |
193 |
|
{ |
194 |
|
fputs(s, stderr); |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
|
void |
199 |
< |
quit(code) |
203 |
< |
int code; |
199 |
> |
quit(int code) |
200 |
|
{ |
201 |
|
exit(code); |
202 |
|
} |
206 |
|
getthead( /* read header from input */ |
207 |
|
struct hdStruct *hp, |
208 |
|
char *ip, |
209 |
< |
register FILE *fp |
209 |
> |
FILE *fp |
210 |
|
) |
211 |
|
{ |
212 |
|
int nidbytes; |
241 |
|
putthead( /* write header to output */ |
242 |
|
struct hdStruct *hp, |
243 |
|
char *ip, |
244 |
< |
register FILE *fp |
244 |
> |
FILE *fp |
245 |
|
) |
246 |
|
{ |
247 |
|
if (ip != NULL) |
269 |
|
|
270 |
|
static int |
271 |
|
getrhead( /* load RADIANCE input file header */ |
272 |
< |
register struct hdStruct *h, |
272 |
> |
struct hdStruct *h, |
273 |
|
FILE *fp |
274 |
|
) |
275 |
|
{ |
305 |
|
) |
306 |
|
{ |
307 |
|
union { |
308 |
< |
BYTE c3[256][3]; |
309 |
< |
BYTE c4[256][4]; |
308 |
> |
uby8 c3[256][3]; |
309 |
> |
uby8 c4[256][4]; |
310 |
|
} map; |
311 |
|
COLR ctab[256]; |
312 |
|
COLR *scanline; |
313 |
< |
register int i, j; |
313 |
> |
int i, j; |
314 |
|
|
315 |
|
/* get color table */ |
316 |
|
if ((hp->CMapBits==24 ? fread((char *)(map.c3+hp->mapOrig), |
357 |
|
) |
358 |
|
{ |
359 |
|
long fpos; |
360 |
< |
register int y; |
360 |
> |
int y; |
361 |
|
|
362 |
|
setcolrgam(gamv); |
363 |
|
fpos = ftell(stdin); |
406 |
|
) |
407 |
|
{ |
408 |
|
int y; |
409 |
< |
register BYTE *dp; |
410 |
< |
register int x; |
409 |
> |
uby8 *dp; |
410 |
> |
int x; |
411 |
|
|
412 |
|
setcolrgam(gamv); |
413 |
|
dp = tarData+xmax*ymax;; |
437 |
|
static void |
438 |
|
writetarga( /* write out targa data */ |
439 |
|
struct hdStruct *h, |
440 |
< |
BYTE *d, |
440 |
> |
uby8 *d, |
441 |
|
FILE *fp |
442 |
|
) |
443 |
|
{ |
444 |
< |
register int i, j; |
444 |
> |
int i, j; |
445 |
|
|
446 |
|
for (i = 0; i < h->mapLength; i++) /* write color map */ |
447 |
|
for (j = 2; j >= 0; j--) |
448 |
|
putc(clrtab[i][j], fp); |
449 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
450 |
< |
if (fwrite((char *)d,h->x*sizeof(BYTE),h->y,fp) != h->y) |
450 |
> |
if (fwrite((char *)d,h->x*sizeof(uby8),h->y,fp) != h->y) |
451 |
|
quiterr("error writing targa file"); |
452 |
|
return; |
453 |
|
} |
458 |
|
static void |
459 |
|
readtarga( /* read in targa data */ |
460 |
|
struct hdStruct *h, |
461 |
< |
BYTE *data, |
461 |
> |
uby8 *data, |
462 |
|
FILE *fp |
463 |
|
) |
464 |
|
{ |
465 |
< |
register int cnt, c; |
466 |
< |
register BYTE *dp; |
465 |
> |
int cnt, c; |
466 |
> |
uby8 *dp; |
467 |
|
|
468 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
469 |
< |
if (fread((char *)data,h->x*sizeof(BYTE),h->y,fp) != h->y) |
469 |
> |
if (fread((char *)data,h->x*sizeof(uby8),h->y,fp) != h->y) |
470 |
|
goto readerr; |
471 |
|
return; |
472 |
|
} |