--- ray/src/px/aedimage.c 1989/09/12 13:04:16 1.3 +++ ray/src/px/aedimage.c 2004/01/02 12:47:01 2.6 @@ -1,9 +1,6 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: aedimage.c,v 2.6 2004/01/02 12:47:01 schorsch Exp $"; #endif - /* * aedimage.c - RADIANCE driver for AED 512 terminal. * @@ -12,13 +9,12 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include - +#include #include - #include #include "pic.h" - +#include "resolu.h" #include "color.h" @@ -97,16 +93,17 @@ FILE *fin; extern long ftell(); long scanpos[NROWS]; -extern double atof(); double exposure = 1.0; +int wrong_fmt = 0; +static gethfunc checkhead; + main(argc, argv) int argc; char *argv[]; { int onintr(); - double atof(); char sbuf[256]; register int i; @@ -141,12 +138,11 @@ char *argv[]; quitmsg(errmsg); } /* get header */ - while (fgets(sbuf, sizeof(sbuf), fin) != NULL && sbuf[0] != '\n') - if (!strncmp(sbuf, "EXPOSURE=", 9)) - exposure *= atof(sbuf+9); - + getheader(fin, checkhead, NULL); + if (wrong_fmt) + quitmsg("input must be a Radiance picture"); /* get picture dimensions */ - if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) + if (fgetresolu(&xmax, &ymax, fin) < 0) quitmsg("bad picture size"); if (xmax > NCOLS || ymax > NROWS) quitmsg("resolution mismatch"); @@ -170,6 +166,24 @@ userr: } +static int +checkhead( /* deal with line from header */ + char *line, + void *p +) +{ + char fmt[32]; + + if (isexpos(line)) + exposure *= exposval(line); + else if (isformat(line)) { + formatval(fmt, line); + wrong_fmt = strcmp(fmt, COLRFMT); + } + return(0); +} + + init() /* initialize terminal */ { struct sgttyb flags; @@ -231,6 +245,7 @@ char *err; } +void eputs(s) char *s; { @@ -238,6 +253,7 @@ char *s; } +void quit(status) int status; { @@ -311,7 +327,7 @@ loopcom() /* print pixel values interactively */ break; case 'l': case 'L': - printf("%-3gL", bright(cval)*683.0/exposure); + printf("%-3gL", luminance(cval)/exposure); break; case 'c': case 'C': @@ -392,34 +408,15 @@ picreadline3(y, l3) /* read in 3-byte scanline */ int y; register rgbpixel *l3; { - register BYTE *l4; - register int shift, c; - int i; - + register int i; + /* read scanline */ getscan(y); /* convert scanline */ - for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) { - shift = l4[EXP] - COLXS; - if (shift >= 8) { - l3->r = l3->g = l3->b = 255; - } else if (shift <= -8) { - l3->r = l3->g = l3->b = 0; - } else if (shift > 0) { - c = l4[RED] << shift; - l3->r = c > 255 ? 255 : c; - c = l4[GRN] << shift; - l3->g = c > 255 ? 255 : c; - c = l4[BLU] << shift; - l3->b = c > 255 ? 255 : c; - } else if (shift < 0) { - l3->r = l4[RED] >> -shift; - l3->g = l4[GRN] >> -shift; - l3->b = l4[BLU] >> -shift; - } else { - l3->r = l4[RED]; - l3->g = l4[GRN]; - l3->b = l4[BLU]; - } + normcolrs(scanline, xmax, 0); + for (i = 0; i < xmax; i++) { + l3[i].r = scanline[i][RED]; + l3[i].g = scanline[i][GRN]; + l3[i].b = scanline[i][BLU]; } } @@ -526,11 +523,10 @@ int offset[3]; picreadcm(map) /* do gamma correction */ colormap map; { - extern double pow(); register int i, val; for (i = 0; i < 256; i++) { - val = pow(i/256.0, 1.0/GAMMA) * 256.0; + val = pow((i+0.5)/256.0, 1.0/GAMMA) * 256.0; map[0][i] = map[1][i] = map[2][i] = val; } }