1 |
– |
/* Copyright (c) 1992 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_t8.c - program to convert between RADIANCE and |
6 |
|
* Targa 8-bit color-mapped images. |
9 |
|
*/ |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
+ |
#include <time.h> |
13 |
+ |
#include <math.h> |
14 |
|
|
15 |
+ |
#include "platform.h" |
16 |
|
#include "color.h" |
17 |
– |
|
17 |
|
#include "resolu.h" |
19 |
– |
|
18 |
|
#include "targa.h" |
19 |
|
|
22 |
– |
#ifdef MSDOS |
23 |
– |
#include <fcntl.h> |
24 |
– |
#endif |
20 |
|
|
26 |
– |
#include <math.h> |
27 |
– |
|
28 |
– |
#ifndef BSD |
29 |
– |
#define bcopy(s,d,n) (void)memcpy(d,s,n) |
30 |
– |
extern char *memcpy(); |
31 |
– |
#endif |
32 |
– |
|
21 |
|
#define goodpic(h) (my_imType(h) && my_mapType(h)) |
22 |
|
#define my_imType(h) (((h)->dataType==IM_CMAP || (h)->dataType==IM_CCMAP) \ |
23 |
|
&& (h)->dataBits==8 && (h)->imType==0) |
26 |
|
|
27 |
|
#define taralloc(h) (BYTE *)emalloc((h)->x*(h)->y) |
28 |
|
|
29 |
< |
extern BYTE clrtab[][3]; |
29 |
> |
BYTE clrtab[256][3]; |
30 |
|
|
31 |
+ |
extern int samplefac; |
32 |
+ |
|
33 |
|
extern char *ecalloc(), *emalloc(); |
34 |
|
|
35 |
|
extern long ftell(); |
59 |
|
int ncolors = 256; |
60 |
|
int greyscale = 0; |
61 |
|
int i; |
62 |
< |
#ifdef MSDOS |
63 |
< |
extern int _fmode; |
64 |
< |
_fmode = O_BINARY; |
75 |
< |
setmode(fileno(stdin), O_BINARY); |
76 |
< |
setmode(fileno(stdout), O_BINARY); |
77 |
< |
#endif |
62 |
> |
SET_DEFAULT_BINARY(); |
63 |
> |
SET_FILE_BINARY(stdin); |
64 |
> |
SET_FILE_BINARY(stdout); |
65 |
|
progname = argv[0]; |
66 |
+ |
samplefac = 0; |
67 |
|
|
68 |
|
for (i = 1; i < argc; i++) |
69 |
|
if (argv[i][0] == '-') |
88 |
|
case 'c': |
89 |
|
ncolors = atoi(argv[++i]); |
90 |
|
break; |
91 |
+ |
case 'n': |
92 |
+ |
samplefac = atoi(argv[++i]); |
93 |
+ |
break; |
94 |
|
default: |
95 |
|
goto userr; |
96 |
|
} |
139 |
|
quiterr(NULL); |
140 |
|
userr: |
141 |
|
fprintf(stderr, |
142 |
< |
"Usage: %s [-d][-c ncolors][-b][-g gamv][-e +/-stops] input [output]\n", |
142 |
> |
"Usage: %s [-d][-n samp][-c ncolors][-b][-g gamv][-e +/-stops] input [output]\n", |
143 |
|
progname); |
144 |
|
fprintf(stderr, " Or: %s -r [-g gamv][-e +/-stops] [input [output]]\n", |
145 |
|
progname); |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
+ |
void |
184 |
|
eputs(s) |
185 |
|
char *s; |
186 |
|
{ |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
+ |
void |
192 |
|
quit(code) |
193 |
|
int code; |
194 |
|
{ |
331 |
|
if (fwritecolrs(scanline, xmax, stdout) < 0) |
332 |
|
quiterr("error writing RADIANCE file"); |
333 |
|
} |
334 |
< |
free((char *)scanline); |
335 |
< |
free((char *)tarData); |
334 |
> |
free((void *)scanline); |
335 |
> |
free((void *)tarData); |
336 |
|
} |
337 |
|
|
338 |
|
|
345 |
|
|
346 |
|
setcolrgam(gamv); |
347 |
|
fpos = ftell(stdin); |
348 |
< |
new_histo(); /* build histogram */ |
348 |
> |
if ((samplefac ? neu_init(xmax*ymax) : new_histo(xmax*ymax)) == -1) |
349 |
> |
quiterr("cannot initialized histogram"); |
350 |
|
for (y = ymax-1; y >= 0; y--) { |
351 |
|
if (freadcolrs(inl, xmax, stdin) < 0) |
352 |
|
quiterr("error reading Radiance input"); |
353 |
|
if (bradj) |
354 |
|
shiftcolrs(inl, xmax, bradj); |
355 |
|
colrs_gambs(inl, xmax); |
356 |
< |
cnt_colrs(inl, xmax); |
356 |
> |
if (samplefac) |
357 |
> |
neu_colrs(inl, xmax); |
358 |
> |
else |
359 |
> |
cnt_colrs(inl, xmax); |
360 |
|
} |
361 |
|
if (fseek(stdin, fpos, 0) == EOF) |
362 |
|
quiterr("Radiance input must be from a file"); |
363 |
< |
new_clrtab(nc); /* map colors */ |
363 |
> |
if (samplefac) /* map colors */ |
364 |
> |
neu_clrtab(nc); |
365 |
> |
else |
366 |
> |
new_clrtab(nc); |
367 |
|
for (y = ymax-1; y >= 0; y--) { |
368 |
|
if (freadcolrs(inl, xmax, stdin) < 0) |
369 |
|
quiterr("error reading Radiance input"); |
370 |
|
if (bradj) |
371 |
|
shiftcolrs(inl, xmax, bradj); |
372 |
|
colrs_gambs(inl, xmax); |
373 |
< |
if (dith) |
374 |
< |
dith_colrs(tarData+y*xmax, inl, xmax); |
373 |
> |
if (samplefac) |
374 |
> |
if (dith) |
375 |
> |
neu_dith_colrs(tarData+y*xmax, inl, xmax); |
376 |
> |
else |
377 |
> |
neu_map_colrs(tarData+y*xmax, inl, xmax); |
378 |
|
else |
379 |
< |
map_colrs(tarData+y*xmax, inl, xmax); |
379 |
> |
if (dith) |
380 |
> |
dith_colrs(tarData+y*xmax, inl, xmax); |
381 |
> |
else |
382 |
> |
map_colrs(tarData+y*xmax, inl, xmax); |
383 |
|
} |
384 |
|
} |
385 |
|
|