38 |
|
#define BORWIDTH 5 /* border width */ |
39 |
|
#define BARHEIGHT 25 /* menu bar size */ |
40 |
|
|
41 |
< |
double gamcor = 2.0; /* gamcor correction */ |
41 |
> |
double gamcor = 2.2; /* gamma correction */ |
42 |
|
|
43 |
< |
XRASTER ourras; /* our stored raster image */ |
43 |
> |
XRASTER *ourras = NULL; /* our stored raster image */ |
44 |
|
|
45 |
|
int dither = 1; /* dither colors? */ |
46 |
|
int fast = 0; /* keep picture in Pixmap? */ |
51 |
|
int maxcolors = 0; /* maximum colors */ |
52 |
|
int greyscale = 0; /* in grey */ |
53 |
|
|
54 |
+ |
int scale = 0; /* scalefactor; power of two */ |
55 |
+ |
|
56 |
|
int xoff = 0; /* x image offset */ |
57 |
|
int yoff = 0; /* y image offset */ |
58 |
|
|
84 |
|
|
85 |
|
extern char *malloc(), *calloc(); |
86 |
|
|
87 |
< |
extern double atof(); |
87 |
> |
extern double atof(), pow(), log(); |
88 |
|
|
89 |
|
|
90 |
|
main(argc, argv) |
114 |
|
case 'f': |
115 |
|
fast = !fast; |
116 |
|
break; |
117 |
+ |
case 'e': |
118 |
+ |
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
119 |
+ |
goto userr; |
120 |
+ |
scale = atoi(argv[++i]); |
121 |
+ |
break; |
122 |
|
case 'g': |
123 |
|
gamcor = atof(argv[++i]); |
124 |
|
break; |
137 |
|
sprintf(errmsg, "can't open file \"%s\"", fname); |
138 |
|
quiterr(errmsg); |
139 |
|
} |
140 |
< |
} else |
134 |
< |
goto userr; |
135 |
< |
|
140 |
> |
} |
141 |
|
/* get header */ |
142 |
|
getheader(fin, headline); |
143 |
|
/* get picture dimensions */ |
144 |
< |
if (fscanf(fin, "-Y %d +X %d\n", &ymax, &xmax) != 2) |
144 |
> |
if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
145 |
|
quiterr("bad picture size"); |
146 |
|
/* set view parameters */ |
147 |
|
if (gotview) { |
159 |
|
getevent(); /* main loop */ |
160 |
|
userr: |
161 |
|
fprintf(stderr, |
162 |
< |
"Usage: %s [=geometry][-b][-m][-d][-f][-c ncolors] file\n", |
162 |
> |
"Usage: %s [=geometry][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
163 |
|
progname); |
164 |
|
quit(1); |
165 |
|
} |
168 |
|
headline(s) /* get relevant info from header */ |
169 |
|
char *s; |
170 |
|
{ |
171 |
< |
static char *altname[] = {"rview","rpict","VIEW=",NULL}; |
171 |
> |
static char *altname[] = {"rview","rpict",VIEWSTR,NULL}; |
172 |
|
register char **an; |
173 |
|
|
174 |
|
if (!strncmp(s, "EXPOSURE=", 9)) |
196 |
|
init() /* get data and open window */ |
197 |
|
{ |
198 |
|
register int i; |
194 |
– |
colormap ourmap; |
199 |
|
OpaqueFrame mainframe; |
200 |
|
char defgeom[32]; |
201 |
|
|
217 |
|
maxcolors = 1<<DisplayPlanes(); |
218 |
|
if (maxcolors > 4) maxcolors -= 2; |
219 |
|
} |
216 |
– |
ourras.width = xmax; |
217 |
– |
ourras.height = ymax; |
220 |
|
/* store image */ |
221 |
< |
if (maxcolors <= 2) { /* monochrome */ |
222 |
< |
ourras.data.m = (unsigned short *)malloc(BitmapSize(xmax,ymax)); |
221 |
< |
if (ourras.data.m == NULL) |
222 |
< |
goto memerr; |
223 |
< |
getmono(); |
224 |
< |
} else { |
225 |
< |
ourras.data.bz = (unsigned char *)malloc(BZPixmapSize(xmax,ymax)); |
226 |
< |
if (ourras.data.bz == NULL) |
227 |
< |
goto memerr; |
228 |
< |
if (greyscale) |
229 |
< |
biq(dither,maxcolors,1,ourmap); |
230 |
< |
else |
231 |
< |
ciq(dither,maxcolors,1,ourmap); |
232 |
< |
if (init_rcolors(&ourras, ourmap) == 0) |
233 |
< |
goto memerr; |
234 |
< |
} |
221 |
> |
getras(); |
222 |
> |
|
223 |
|
mainframe.bdrwidth = BORWIDTH; |
224 |
|
mainframe.border = WhitePixmap; |
225 |
|
mainframe.background = BlackPixmap; |
272 |
|
} |
273 |
|
|
274 |
|
|
275 |
+ |
getras() /* get raster file */ |
276 |
+ |
{ |
277 |
+ |
colormap ourmap; |
278 |
+ |
|
279 |
+ |
ourras = (XRASTER *)calloc(1, sizeof(XRASTER)); |
280 |
+ |
if (ourras == NULL) |
281 |
+ |
goto memerr; |
282 |
+ |
ourras->width = xmax; |
283 |
+ |
ourras->height = ymax; |
284 |
+ |
if (maxcolors <= 2) { /* monochrome */ |
285 |
+ |
ourras->data.m = (unsigned short *)malloc(BitmapSize(xmax,ymax)); |
286 |
+ |
if (ourras->data.m == NULL) |
287 |
+ |
goto memerr; |
288 |
+ |
getmono(); |
289 |
+ |
} else { |
290 |
+ |
ourras->data.bz = (unsigned char *)malloc(BZPixmapSize(xmax,ymax)); |
291 |
+ |
if (ourras->data.bz == NULL) |
292 |
+ |
goto memerr; |
293 |
+ |
if (greyscale) |
294 |
+ |
biq(dither,maxcolors,1,ourmap); |
295 |
+ |
else |
296 |
+ |
ciq(dither,maxcolors,1,ourmap); |
297 |
+ |
if (init_rcolors(ourras, ourmap) == 0) |
298 |
+ |
goto memerr; |
299 |
+ |
} |
300 |
+ |
return; |
301 |
+ |
memerr: |
302 |
+ |
quit("out of memory"); |
303 |
+ |
} |
304 |
+ |
|
305 |
+ |
|
306 |
|
getevent() /* process the next event */ |
307 |
|
{ |
308 |
|
WindowInfo info; |
322 |
|
fixwindow(&e); |
323 |
|
break; |
324 |
|
case UnmapWindow: |
325 |
< |
unmap_rcolors(&ourras); |
325 |
> |
unmap_rcolors(ourras); |
326 |
|
break; |
327 |
|
case ButtonPressed: |
328 |
|
if (controlshift(&e)) |
345 |
|
int x, y; |
346 |
|
int w, h; |
347 |
|
{ |
348 |
< |
map_rcolors(&ourras); |
348 |
> |
if (ourras->ncolors && map_rcolors(ourras) == NULL) { |
349 |
> |
fprintf(stderr, "%s: cannot allocate colors\n", progname); |
350 |
> |
return(-1); |
351 |
> |
} |
352 |
|
if (fast) |
353 |
< |
make_rpixmap(&ourras); |
354 |
< |
return(patch_raster(wind,x-xoff,y-yoff,x,y,w,h,&ourras) ? 0 : -1); |
353 |
> |
make_rpixmap(ourras); |
354 |
> |
return(patch_raster(wind,x-xoff,y-yoff,x,y,w,h,ourras) ? 0 : -1); |
355 |
|
} |
356 |
|
|
357 |
|
|
362 |
|
COLOR cval; |
363 |
|
char *cp; |
364 |
|
int n; |
365 |
+ |
double comp; |
366 |
|
FVECT rorg, rdir; |
367 |
|
|
368 |
|
cp = XLookupMapping(ekey, &n); |
387 |
|
sprintf(buf, "%-3gL", bright(cval)*683.0/exposure); |
388 |
|
break; |
389 |
|
case 'c': /* color */ |
390 |
+ |
comp = pow(2.0, (double)scale); |
391 |
|
sprintf(buf, "(%.2f,%.2f,%.2f)", |
392 |
< |
colval(cval,RED), |
393 |
< |
colval(cval,GRN), |
394 |
< |
colval(cval,BLU)); |
392 |
> |
colval(cval,RED)*comp, |
393 |
> |
colval(cval,GRN)*comp, |
394 |
> |
colval(cval,BLU)*comp); |
395 |
|
break; |
396 |
|
} |
397 |
|
XText(wind, box.xmin, box.ymin, buf, strlen(buf), |
413 |
|
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
414 |
|
fflush(stdout); |
415 |
|
return(0); |
416 |
+ |
case '=': /* adjust exposure */ |
417 |
+ |
if (avgbox(cval) == -1) |
418 |
+ |
return(-1); |
419 |
+ |
n = log(.5/bright(cval))/.69315 - scale; /* truncate */ |
420 |
+ |
if (n == 0) |
421 |
+ |
return(0); |
422 |
+ |
scale_rcolors(ourras, pow(2.0, (double)n)); |
423 |
+ |
scale += n; |
424 |
+ |
sprintf(buf, "%+d", scale); |
425 |
+ |
XText(wind, box.xmin, box.ymin, buf, strlen(buf), |
426 |
+ |
fontid, BlackPixel, WhitePixel); |
427 |
+ |
XFlush(); |
428 |
+ |
free_raster(ourras); |
429 |
+ |
getras(); |
430 |
+ |
/* fall through */ |
431 |
|
case CTRL(R): /* redraw */ |
432 |
+ |
case CTRL(L): |
433 |
|
XClear(wind); |
434 |
|
return(redraw(0, 0, width, height)); |
435 |
|
case ' ': /* clear */ |
547 |
|
if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
548 |
|
|| (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
549 |
|
quit("out of memory in getmono"); |
550 |
< |
dp = ourras.data.m - 1; |
550 |
> |
dp = ourras->data.m - 1; |
551 |
|
for (y = 0; y < ymax; y++) { |
552 |
|
picreadline3(y, inline); |
553 |
|
err = 0; |
567 |
|
} |
568 |
|
|
569 |
|
|
570 |
< |
init_rcolors(xr, cmap) /* assign color values */ |
570 |
> |
init_rcolors(xr, cmap) /* (re)assign color values */ |
571 |
|
register XRASTER *xr; |
572 |
|
colormap cmap; |
573 |
|
{ |
598 |
|
} |
599 |
|
|
600 |
|
|
601 |
+ |
scale_rcolors(xr, sf) /* scale color map */ |
602 |
+ |
register XRASTER *xr; |
603 |
+ |
double sf; |
604 |
+ |
{ |
605 |
+ |
register int i; |
606 |
+ |
int maxv; |
607 |
+ |
|
608 |
+ |
sf = pow(sf, 1.0/gamcor); |
609 |
+ |
maxv = (1<<16) / sf; |
610 |
+ |
|
611 |
+ |
for (i = xr->ncolors; i--; ) { |
612 |
+ |
xr->cdefs[i].red = xr->cdefs[i].red >= maxv ? |
613 |
+ |
(1<<16)-1 : |
614 |
+ |
xr->cdefs[i].red * sf; |
615 |
+ |
xr->cdefs[i].green = xr->cdefs[i].green >= maxv ? |
616 |
+ |
(1<<16)-1 : |
617 |
+ |
xr->cdefs[i].green * sf; |
618 |
+ |
xr->cdefs[i].blue = xr->cdefs[i].blue >= maxv ? |
619 |
+ |
(1<<16)-1 : |
620 |
+ |
xr->cdefs[i].blue * sf; |
621 |
+ |
} |
622 |
+ |
if (xr->pixels != NULL) |
623 |
+ |
XStoreColors(xr->ncolors, xr->cdefs); |
624 |
+ |
} |
625 |
+ |
|
626 |
+ |
|
627 |
|
getscan(y) |
628 |
|
int y; |
629 |
|
{ |
648 |
|
int y; |
649 |
|
register rgbpixel *l3; |
650 |
|
{ |
651 |
< |
register BYTE *l4; |
652 |
< |
register int shift, c; |
587 |
< |
int i; |
588 |
< |
|
651 |
> |
register int i; |
652 |
> |
/* read scanline */ |
653 |
|
if (getscan(y) < 0) |
654 |
|
quiterr("cannot seek for picreadline"); |
655 |
|
/* convert scanline */ |
656 |
< |
for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) { |
657 |
< |
shift = l4[EXP] - COLXS; |
658 |
< |
if (shift >= 8) { |
659 |
< |
l3->r = l3->g = l3->b = 255; |
660 |
< |
} else if (shift <= -8) { |
597 |
< |
l3->r = l3->g = l3->b = 0; |
598 |
< |
} else if (shift > 0) { |
599 |
< |
c = l4[RED] << shift; |
600 |
< |
l3->r = c > 255 ? 255 : c; |
601 |
< |
c = l4[GRN] << shift; |
602 |
< |
l3->g = c > 255 ? 255 : c; |
603 |
< |
c = l4[BLU] << shift; |
604 |
< |
l3->b = c > 255 ? 255 : c; |
605 |
< |
} else if (shift < 0) { |
606 |
< |
l3->r = l4[RED] >> -shift; |
607 |
< |
l3->g = l4[GRN] >> -shift; |
608 |
< |
l3->b = l4[BLU] >> -shift; |
609 |
< |
} else { |
610 |
< |
l3->r = l4[RED]; |
611 |
< |
l3->g = l4[GRN]; |
612 |
< |
l3->b = l4[BLU]; |
613 |
< |
} |
656 |
> |
normcolrs(scanline, xmax); |
657 |
> |
for (i = 0; i < xmax; i++) { |
658 |
> |
l3[i].r = scanline[i][RED]; |
659 |
> |
l3[i].g = scanline[i][GRN]; |
660 |
> |
l3[i].b = scanline[i][BLU]; |
661 |
|
} |
662 |
|
} |
663 |
|
|
666 |
|
int y; |
667 |
|
pixel *l; |
668 |
|
{ |
669 |
< |
bcopy(l, ourras.data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1)); |
669 |
> |
bcopy(l, ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1)); |
670 |
|
} |
671 |
|
|
672 |
|
|
673 |
< |
picreadcm(map) /* do gamcor correction */ |
673 |
> |
picreadcm(map) /* do gamma correction */ |
674 |
|
colormap map; |
675 |
|
{ |
676 |
|
extern double pow(); |
686 |
|
picwritecm(map) /* handled elsewhere */ |
687 |
|
colormap map; |
688 |
|
{ |
689 |
+ |
#ifdef DEBUG |
690 |
+ |
register int i; |
691 |
+ |
|
692 |
+ |
for (i = 0; i < 256; i++) |
693 |
+ |
printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]); |
694 |
+ |
#endif |
695 |
|
} |