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.0; /* 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; |
161 |
|
getevent(); /* main loop */ |
162 |
|
userr: |
163 |
|
fprintf(stderr, |
164 |
< |
"Usage: %s [=geometry][-b][-m][-d][-f][-c ncolors] file\n", |
164 |
> |
"Usage: %s [=geometry][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
165 |
|
progname); |
166 |
|
quit(1); |
167 |
|
} |
170 |
|
headline(s) /* get relevant info from header */ |
171 |
|
char *s; |
172 |
|
{ |
173 |
< |
static char *altname[] = {"rview","rpict","VIEW=",NULL}; |
173 |
> |
static char *altname[] = {"rview","rpict",VIEWSTR,NULL}; |
174 |
|
register char **an; |
175 |
|
|
176 |
|
if (!strncmp(s, "EXPOSURE=", 9)) |
198 |
|
init() /* get data and open window */ |
199 |
|
{ |
200 |
|
register int i; |
194 |
– |
colormap ourmap; |
201 |
|
OpaqueFrame mainframe; |
202 |
|
char defgeom[32]; |
203 |
|
|
219 |
|
maxcolors = 1<<DisplayPlanes(); |
220 |
|
if (maxcolors > 4) maxcolors -= 2; |
221 |
|
} |
216 |
– |
ourras.width = xmax; |
217 |
– |
ourras.height = ymax; |
222 |
|
/* store image */ |
223 |
< |
if (maxcolors <= 2) { /* monochrome */ |
224 |
< |
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 |
< |
} |
223 |
> |
getras(); |
224 |
> |
|
225 |
|
mainframe.bdrwidth = BORWIDTH; |
226 |
|
mainframe.border = WhitePixmap; |
227 |
|
mainframe.background = BlackPixmap; |
274 |
|
} |
275 |
|
|
276 |
|
|
277 |
+ |
getras() /* get raster file */ |
278 |
+ |
{ |
279 |
+ |
colormap ourmap; |
280 |
+ |
|
281 |
+ |
ourras = (XRASTER *)calloc(1, sizeof(XRASTER)); |
282 |
+ |
if (ourras == NULL) |
283 |
+ |
goto memerr; |
284 |
+ |
ourras->width = xmax; |
285 |
+ |
ourras->height = ymax; |
286 |
+ |
if (maxcolors <= 2) { /* monochrome */ |
287 |
+ |
ourras->data.m = (unsigned short *)malloc(BitmapSize(xmax,ymax)); |
288 |
+ |
if (ourras->data.m == NULL) |
289 |
+ |
goto memerr; |
290 |
+ |
getmono(); |
291 |
+ |
} else { |
292 |
+ |
ourras->data.bz = (unsigned char *)malloc(BZPixmapSize(xmax,ymax)); |
293 |
+ |
if (ourras->data.bz == NULL) |
294 |
+ |
goto memerr; |
295 |
+ |
if (greyscale) |
296 |
+ |
biq(dither,maxcolors,1,ourmap); |
297 |
+ |
else |
298 |
+ |
ciq(dither,maxcolors,1,ourmap); |
299 |
+ |
if (init_rcolors(ourras, ourmap) == 0) |
300 |
+ |
goto memerr; |
301 |
+ |
} |
302 |
+ |
return; |
303 |
+ |
memerr: |
304 |
+ |
quit("out of memory"); |
305 |
+ |
} |
306 |
+ |
|
307 |
+ |
|
308 |
|
getevent() /* process the next event */ |
309 |
|
{ |
310 |
|
WindowInfo info; |
324 |
|
fixwindow(&e); |
325 |
|
break; |
326 |
|
case UnmapWindow: |
327 |
< |
unmap_rcolors(&ourras); |
327 |
> |
unmap_rcolors(ourras); |
328 |
|
break; |
329 |
|
case ButtonPressed: |
330 |
|
if (controlshift(&e)) |
347 |
|
int x, y; |
348 |
|
int w, h; |
349 |
|
{ |
350 |
< |
map_rcolors(&ourras); |
350 |
> |
if (map_rcolors(ourras) == NULL) { |
351 |
> |
fprintf(stderr, "%s: cannot allocate colors\n", progname); |
352 |
> |
return(-1); |
353 |
> |
} |
354 |
|
if (fast) |
355 |
< |
make_rpixmap(&ourras); |
356 |
< |
return(patch_raster(wind,x-xoff,y-yoff,x,y,w,h,&ourras) ? 0 : -1); |
355 |
> |
make_rpixmap(ourras); |
356 |
> |
return(patch_raster(wind,x-xoff,y-yoff,x,y,w,h,ourras) ? 0 : -1); |
357 |
|
} |
358 |
|
|
359 |
|
|
364 |
|
COLOR cval; |
365 |
|
char *cp; |
366 |
|
int n; |
367 |
+ |
double comp; |
368 |
|
FVECT rorg, rdir; |
369 |
|
|
370 |
|
cp = XLookupMapping(ekey, &n); |
389 |
|
sprintf(buf, "%-3gL", bright(cval)*683.0/exposure); |
390 |
|
break; |
391 |
|
case 'c': /* color */ |
392 |
+ |
comp = pow(2.0, (double)scale); |
393 |
|
sprintf(buf, "(%.2f,%.2f,%.2f)", |
394 |
< |
colval(cval,RED), |
395 |
< |
colval(cval,GRN), |
396 |
< |
colval(cval,BLU)); |
394 |
> |
colval(cval,RED)*comp, |
395 |
> |
colval(cval,GRN)*comp, |
396 |
> |
colval(cval,BLU)*comp); |
397 |
|
break; |
398 |
|
} |
399 |
|
XText(wind, box.xmin, box.ymin, buf, strlen(buf), |
415 |
|
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
416 |
|
fflush(stdout); |
417 |
|
return(0); |
418 |
+ |
case '=': /* adjust exposure */ |
419 |
+ |
if (avgbox(cval) == -1) |
420 |
+ |
return(-1); |
421 |
+ |
n = log(.5/bright(cval))/.69315 - scale; /* truncate */ |
422 |
+ |
if (n == 0) |
423 |
+ |
return(0); |
424 |
+ |
scale_rcolors(ourras, pow(2.0, (double)n)); |
425 |
+ |
scale += n; |
426 |
+ |
sprintf(buf, "%+d", scale); |
427 |
+ |
XText(wind, box.xmin, box.ymin, buf, strlen(buf), |
428 |
+ |
fontid, BlackPixel, WhitePixel); |
429 |
+ |
XFlush(); |
430 |
+ |
free_raster(ourras); |
431 |
+ |
getras(); |
432 |
+ |
/* fall through */ |
433 |
|
case CTRL(R): /* redraw */ |
434 |
|
XClear(wind); |
435 |
|
return(redraw(0, 0, width, height)); |
548 |
|
if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
549 |
|
|| (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
550 |
|
quit("out of memory in getmono"); |
551 |
< |
dp = ourras.data.m - 1; |
551 |
> |
dp = ourras->data.m - 1; |
552 |
|
for (y = 0; y < ymax; y++) { |
553 |
|
picreadline3(y, inline); |
554 |
|
err = 0; |
568 |
|
} |
569 |
|
|
570 |
|
|
571 |
< |
init_rcolors(xr, cmap) /* assign color values */ |
571 |
> |
init_rcolors(xr, cmap) /* (re)assign color values */ |
572 |
|
register XRASTER *xr; |
573 |
|
colormap cmap; |
574 |
|
{ |
599 |
|
} |
600 |
|
|
601 |
|
|
602 |
+ |
scale_rcolors(xr, sf) /* scale color map */ |
603 |
+ |
register XRASTER *xr; |
604 |
+ |
double sf; |
605 |
+ |
{ |
606 |
+ |
register int i; |
607 |
+ |
int maxv; |
608 |
+ |
|
609 |
+ |
sf = pow(sf, 1.0/gamcor); |
610 |
+ |
maxv = (1<<16) / sf; |
611 |
+ |
|
612 |
+ |
for (i = xr->ncolors; i--; ) { |
613 |
+ |
xr->cdefs[i].red = xr->cdefs[i].red >= maxv ? |
614 |
+ |
(1<<16)-1 : |
615 |
+ |
xr->cdefs[i].red * sf; |
616 |
+ |
xr->cdefs[i].green = xr->cdefs[i].green >= maxv ? |
617 |
+ |
(1<<16)-1 : |
618 |
+ |
xr->cdefs[i].green * sf; |
619 |
+ |
xr->cdefs[i].blue = xr->cdefs[i].blue >= maxv ? |
620 |
+ |
(1<<16)-1 : |
621 |
+ |
xr->cdefs[i].blue * sf; |
622 |
+ |
} |
623 |
+ |
if (xr->pixels != NULL) |
624 |
+ |
XStoreColors(xr->ncolors, xr->cdefs); |
625 |
+ |
} |
626 |
+ |
|
627 |
+ |
|
628 |
|
getscan(y) |
629 |
|
int y; |
630 |
|
{ |
657 |
|
quiterr("cannot seek for picreadline"); |
658 |
|
/* convert scanline */ |
659 |
|
for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) { |
660 |
< |
shift = l4[EXP] - COLXS; |
660 |
> |
shift = l4[EXP] - COLXS + scale; |
661 |
|
if (shift >= 8) { |
662 |
|
l3->r = l3->g = l3->b = 255; |
663 |
|
} else if (shift <= -8) { |
686 |
|
int y; |
687 |
|
pixel *l; |
688 |
|
{ |
689 |
< |
bcopy(l, ourras.data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1)); |
689 |
> |
bcopy(l, ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1)); |
690 |
|
} |
691 |
|
|
692 |
|
|
706 |
|
picwritecm(map) /* handled elsewhere */ |
707 |
|
colormap map; |
708 |
|
{ |
709 |
+ |
#ifdef DEBUG |
710 |
+ |
register int i; |
711 |
+ |
|
712 |
+ |
for (i = 0; i < 256; i++) |
713 |
+ |
printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]); |
714 |
+ |
#endif |
715 |
|
} |