1 |
– |
/* Copyright (c) 1986 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 |
|
* aedimage.c - RADIANCE driver for AED 512 terminal. |
6 |
|
* |
9 |
|
*/ |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
< |
|
12 |
> |
#include <math.h> |
13 |
|
#include <signal.h> |
17 |
– |
|
14 |
|
#include <sys/ioctl.h> |
15 |
|
|
16 |
|
#include "pic.h" |
17 |
< |
|
17 |
> |
#include "resolu.h" |
18 |
|
#include "color.h" |
19 |
|
|
20 |
|
|
54 |
|
#define byte(b) putc(b, stdout) |
55 |
|
#define flush() fflush(stdout) |
56 |
|
|
57 |
< |
#define GAMMA 2.0 /* gamma value used in correction */ |
57 |
> |
#define GAMMA 2.5 /* gamma value used in correction */ |
58 |
|
|
59 |
|
#define MINCOLOR 8 /* start of device color table */ |
60 |
|
|
93 |
|
extern long ftell(); |
94 |
|
long scanpos[NROWS]; |
95 |
|
|
100 |
– |
extern double atof(); |
96 |
|
double exposure = 1.0; |
97 |
+ |
int wrong_fmt = 0; |
98 |
|
|
99 |
+ |
static gethfunc checkhead; |
100 |
|
|
101 |
+ |
|
102 |
|
main(argc, argv) |
103 |
|
int argc; |
104 |
|
char *argv[]; |
105 |
|
{ |
106 |
|
int onintr(); |
109 |
– |
double atof(); |
107 |
|
char sbuf[256]; |
108 |
|
register int i; |
109 |
|
|
138 |
|
quitmsg(errmsg); |
139 |
|
} |
140 |
|
/* get header */ |
141 |
< |
while (fgets(sbuf, sizeof(sbuf), fin) != NULL && sbuf[0] != '\n') |
142 |
< |
if (!strncmp(sbuf, "EXPOSURE=", 9)) |
143 |
< |
exposure *= atof(sbuf+9); |
147 |
< |
|
141 |
> |
getheader(fin, checkhead, NULL); |
142 |
> |
if (wrong_fmt) |
143 |
> |
quitmsg("input must be a Radiance picture"); |
144 |
|
/* get picture dimensions */ |
145 |
< |
if (fgets(sbuf, sizeof(sbuf), fin) == NULL || |
150 |
< |
sscanf(sbuf, "-Y %d +X %d\n", &ymax, &xmax) != 2) |
145 |
> |
if (fgetresolu(&xmax, &ymax, fin) < 0) |
146 |
|
quitmsg("bad picture size"); |
147 |
|
if (xmax > NCOLS || ymax > NROWS) |
148 |
|
quitmsg("resolution mismatch"); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
+ |
static int |
170 |
+ |
checkhead( /* deal with line from header */ |
171 |
+ |
char *line, |
172 |
+ |
void *p |
173 |
+ |
) |
174 |
+ |
{ |
175 |
+ |
char fmt[32]; |
176 |
+ |
|
177 |
+ |
if (isexpos(line)) |
178 |
+ |
exposure *= exposval(line); |
179 |
+ |
else if (isformat(line)) { |
180 |
+ |
formatval(fmt, line); |
181 |
+ |
wrong_fmt = strcmp(fmt, COLRFMT); |
182 |
+ |
} |
183 |
+ |
return(0); |
184 |
+ |
} |
185 |
+ |
|
186 |
+ |
|
187 |
|
init() /* initialize terminal */ |
188 |
|
{ |
189 |
|
struct sgttyb flags; |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
+ |
void |
249 |
|
eputs(s) |
250 |
|
char *s; |
251 |
|
{ |
253 |
|
} |
254 |
|
|
255 |
|
|
256 |
+ |
void |
257 |
|
quit(status) |
258 |
|
int status; |
259 |
|
{ |
327 |
|
break; |
328 |
|
case 'l': |
329 |
|
case 'L': |
330 |
< |
printf("%-3gL", bright(cval)*683.0/exposure); |
330 |
> |
printf("%-3gL", luminance(cval)/exposure); |
331 |
|
break; |
332 |
|
case 'c': |
333 |
|
case 'C': |
408 |
|
int y; |
409 |
|
register rgbpixel *l3; |
410 |
|
{ |
411 |
< |
register BYTE *l4; |
412 |
< |
register int shift, c; |
398 |
< |
int i; |
399 |
< |
|
411 |
> |
register int i; |
412 |
> |
/* read scanline */ |
413 |
|
getscan(y); |
414 |
|
/* convert scanline */ |
415 |
< |
for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) { |
416 |
< |
shift = l4[EXP] - COLXS; |
417 |
< |
if (shift >= 8) { |
418 |
< |
l3->r = l3->g = l3->b = 255; |
419 |
< |
} else if (shift <= -8) { |
407 |
< |
l3->r = l3->g = l3->b = 0; |
408 |
< |
} else if (shift > 0) { |
409 |
< |
c = l4[RED] << shift; |
410 |
< |
l3->r = c > 255 ? 255 : c; |
411 |
< |
c = l4[GRN] << shift; |
412 |
< |
l3->g = c > 255 ? 255 : c; |
413 |
< |
c = l4[BLU] << shift; |
414 |
< |
l3->b = c > 255 ? 255 : c; |
415 |
< |
} else if (shift < 0) { |
416 |
< |
l3->r = l4[RED] >> -shift; |
417 |
< |
l3->g = l4[GRN] >> -shift; |
418 |
< |
l3->b = l4[BLU] >> -shift; |
419 |
< |
} else { |
420 |
< |
l3->r = l4[RED]; |
421 |
< |
l3->g = l4[GRN]; |
422 |
< |
l3->b = l4[BLU]; |
423 |
< |
} |
415 |
> |
normcolrs(scanline, xmax, 0); |
416 |
> |
for (i = 0; i < xmax; i++) { |
417 |
> |
l3[i].r = scanline[i][RED]; |
418 |
> |
l3[i].g = scanline[i][GRN]; |
419 |
> |
l3[i].b = scanline[i][BLU]; |
420 |
|
} |
421 |
|
} |
422 |
|
|
523 |
|
picreadcm(map) /* do gamma correction */ |
524 |
|
colormap map; |
525 |
|
{ |
530 |
– |
extern double pow(); |
526 |
|
register int i, val; |
527 |
|
|
528 |
|
for (i = 0; i < 256; i++) { |
529 |
< |
val = pow(i/256.0, 1.0/GAMMA) * 256.0; |
529 |
> |
val = pow((i+0.5)/256.0, 1.0/GAMMA) * 256.0; |
530 |
|
map[0][i] = map[1][i] = map[2][i] = val; |
531 |
|
} |
532 |
|
} |