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. |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
|
|
13 |
+ |
#include <time.h> |
14 |
+ |
|
15 |
|
#include "color.h" |
16 |
|
|
17 |
|
#include "resolu.h" |
26 |
|
|
27 |
|
#ifndef BSD |
28 |
|
#define bcopy(s,d,n) (void)memcpy(d,s,n) |
30 |
– |
extern char *memcpy(); |
29 |
|
#endif |
30 |
|
|
31 |
|
#define goodpic(h) (my_imType(h) && my_mapType(h)) |
36 |
|
|
37 |
|
#define taralloc(h) (BYTE *)emalloc((h)->x*(h)->y) |
38 |
|
|
39 |
< |
extern BYTE clrtab[][3]; |
39 |
> |
BYTE clrtab[256][3]; |
40 |
|
|
41 |
+ |
extern int samplefac; |
42 |
+ |
|
43 |
|
extern char *ecalloc(), *emalloc(); |
44 |
|
|
45 |
|
extern long ftell(); |
76 |
|
setmode(fileno(stdout), O_BINARY); |
77 |
|
#endif |
78 |
|
progname = argv[0]; |
79 |
+ |
samplefac = 0; |
80 |
|
|
81 |
|
for (i = 1; i < argc; i++) |
82 |
|
if (argv[i][0] == '-') |
101 |
|
case 'c': |
102 |
|
ncolors = atoi(argv[++i]); |
103 |
|
break; |
104 |
+ |
case 'n': |
105 |
+ |
samplefac = atoi(argv[++i]); |
106 |
+ |
break; |
107 |
|
default: |
108 |
|
goto userr; |
109 |
|
} |
129 |
|
xmax = head.x; |
130 |
|
ymax = head.y; |
131 |
|
/* put header */ |
132 |
+ |
newheader("RADIANCE", stdout); |
133 |
|
printargs(i, argv, stdout); |
134 |
|
fputformat(COLRFMT, stdout); |
135 |
|
putchar('\n'); |
152 |
|
quiterr(NULL); |
153 |
|
userr: |
154 |
|
fprintf(stderr, |
155 |
< |
"Usage: %s [-d][-c ncolors][-b][-g gamv][-e +/-stops] input [output]\n", |
155 |
> |
"Usage: %s [-d][-n samp][-c ncolors][-b][-g gamv][-e +/-stops] input [output]\n", |
156 |
|
progname); |
157 |
|
fprintf(stderr, " Or: %s -r [-g gamv][-e +/-stops] [input [output]]\n", |
158 |
|
progname); |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
+ |
void |
197 |
|
eputs(s) |
198 |
|
char *s; |
199 |
|
{ |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
+ |
void |
205 |
|
quit(code) |
206 |
|
int code; |
207 |
|
{ |
344 |
|
if (fwritecolrs(scanline, xmax, stdout) < 0) |
345 |
|
quiterr("error writing RADIANCE file"); |
346 |
|
} |
347 |
< |
free((char *)scanline); |
348 |
< |
free((char *)tarData); |
347 |
> |
free((void *)scanline); |
348 |
> |
free((void *)tarData); |
349 |
|
} |
350 |
|
|
351 |
|
|
358 |
|
|
359 |
|
setcolrgam(gamv); |
360 |
|
fpos = ftell(stdin); |
361 |
< |
new_histo(); /* build histogram */ |
361 |
> |
if ((samplefac ? neu_init(xmax*ymax) : new_histo(xmax*ymax)) == -1) |
362 |
> |
quiterr("cannot initialized histogram"); |
363 |
|
for (y = ymax-1; y >= 0; y--) { |
364 |
|
if (freadcolrs(inl, xmax, stdin) < 0) |
365 |
|
quiterr("error reading Radiance input"); |
366 |
|
if (bradj) |
367 |
|
shiftcolrs(inl, xmax, bradj); |
368 |
|
colrs_gambs(inl, xmax); |
369 |
< |
cnt_colrs(inl, xmax); |
369 |
> |
if (samplefac) |
370 |
> |
neu_colrs(inl, xmax); |
371 |
> |
else |
372 |
> |
cnt_colrs(inl, xmax); |
373 |
|
} |
374 |
|
if (fseek(stdin, fpos, 0) == EOF) |
375 |
|
quiterr("Radiance input must be from a file"); |
376 |
< |
new_clrtab(nc); /* map colors */ |
376 |
> |
if (samplefac) /* map colors */ |
377 |
> |
neu_clrtab(nc); |
378 |
> |
else |
379 |
> |
new_clrtab(nc); |
380 |
|
for (y = ymax-1; y >= 0; y--) { |
381 |
|
if (freadcolrs(inl, xmax, stdin) < 0) |
382 |
|
quiterr("error reading Radiance input"); |
383 |
|
if (bradj) |
384 |
|
shiftcolrs(inl, xmax, bradj); |
385 |
|
colrs_gambs(inl, xmax); |
386 |
< |
if (dith) |
387 |
< |
dith_colrs(tarData+y*xmax, inl, xmax); |
386 |
> |
if (samplefac) |
387 |
> |
if (dith) |
388 |
> |
neu_dith_colrs(tarData+y*xmax, inl, xmax); |
389 |
> |
else |
390 |
> |
neu_map_colrs(tarData+y*xmax, inl, xmax); |
391 |
|
else |
392 |
< |
map_colrs(tarData+y*xmax, inl, xmax); |
392 |
> |
if (dith) |
393 |
> |
dith_colrs(tarData+y*xmax, inl, xmax); |
394 |
> |
else |
395 |
> |
map_colrs(tarData+y*xmax, inl, xmax); |
396 |
|
} |
397 |
|
} |
398 |
|
|