1 |
< |
/* Copyright (c) 1990 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
30 |
|
#include "pic.h" |
31 |
|
#include "x11raster.h" |
32 |
|
#include "random.h" |
33 |
+ |
#include "resolu.h" |
34 |
|
|
35 |
|
#define FONTNAME "8x13" /* text font we'll use */ |
36 |
|
|
37 |
< |
#define CTRL(c) ('c'-'@') |
37 |
> |
#define CTRL(c) ((c)-'@') |
38 |
|
|
39 |
|
#define BORWIDTH 5 /* border width */ |
40 |
|
|
41 |
+ |
#define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ |
42 |
+ |
|
43 |
|
#define ourscreen DefaultScreen(thedisplay) |
41 |
– |
#define ourblack BlackPixel(thedisplay,ourscreen) |
42 |
– |
#define ourwhite WhitePixel(thedisplay,ourscreen) |
44 |
|
#define ourroot RootWindow(thedisplay,ourscreen) |
44 |
– |
#define ourgc DefaultGC(thedisplay,ourscreen) |
45 |
|
|
46 |
+ |
#define revline(x0,y0,x1,y1) XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1) |
47 |
+ |
|
48 |
|
#define redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras) |
49 |
|
|
50 |
|
double gamcor = 2.2; /* gamma correction */ |
52 |
|
int dither = 1; /* dither colors? */ |
53 |
|
int fast = 0; /* keep picture in Pixmap? */ |
54 |
|
|
55 |
+ |
char *dispname = NULL; /* our display name */ |
56 |
+ |
|
57 |
|
Window wind = 0; /* our output window */ |
58 |
+ |
unsigned long ourblack=1, ourwhite=0; /* black and white for this visual */ |
59 |
|
Font fontid; /* our font */ |
60 |
|
|
61 |
|
int maxcolors = 0; /* maximum colors */ |
71 |
|
|
72 |
|
COLR *scanline; /* scan line buffer */ |
73 |
|
|
74 |
< |
int xmax, ymax; /* picture resolution */ |
74 |
> |
RESOLU inpres; /* input resolution and ordering */ |
75 |
> |
int xmax, ymax; /* picture dimensions */ |
76 |
|
int width, height; /* window size */ |
77 |
|
char *fname = NULL; /* input file name */ |
78 |
|
FILE *fin = stdin; /* input file */ |
81 |
|
|
82 |
|
double exposure = 1.0; /* exposure compensation used */ |
83 |
|
|
84 |
< |
XRASTER *ourras; /* our stored image */ |
84 |
> |
int wrongformat = 0; /* input in another format? */ |
85 |
> |
|
86 |
> |
GC ourgc; /* standard graphics context */ |
87 |
> |
GC revgc; /* graphics context with GXinvert */ |
88 |
> |
|
89 |
> |
int *ourrank; /* our visual class ranking */ |
90 |
> |
XVisualInfo ourvis; /* our visual */ |
91 |
> |
XRASTER *ourras; /* our stored image */ |
92 |
|
unsigned char *ourdata; /* our image data */ |
93 |
|
|
94 |
|
struct { |
97 |
|
|
98 |
|
char *geometry = NULL; /* geometry specification */ |
99 |
|
|
100 |
+ |
char icondata[ICONSIZ*ICONSIZ/8]; /* icon bitmap data */ |
101 |
+ |
int iconwidth = 0, iconheight = 0; |
102 |
+ |
|
103 |
|
char *progname; |
104 |
|
|
105 |
|
char errmsg[128]; |
108 |
|
|
109 |
|
extern char *malloc(), *calloc(); |
110 |
|
|
111 |
< |
extern double atof(), pow(), log(); |
111 |
> |
extern double pow(), log(); |
112 |
|
|
113 |
|
Display *thedisplay; |
114 |
|
|
134 |
|
maxcolors = 2; |
135 |
|
break; |
136 |
|
case 'd': |
137 |
< |
dither = !dither; |
137 |
> |
if (argv[i][2] == 'i') |
138 |
> |
dispname = argv[++i]; |
139 |
> |
else |
140 |
> |
dither = !dither; |
141 |
|
break; |
142 |
|
case 'f': |
143 |
|
fast = !fast; |
148 |
|
scale = atoi(argv[++i]); |
149 |
|
break; |
150 |
|
case 'g': |
151 |
< |
if (!strcmp(argv[i], "-geometry")) |
151 |
> |
if (argv[i][2] == 'e') |
152 |
|
geometry = argv[++i]; |
153 |
|
else |
154 |
|
gamcor = atof(argv[++i]); |
165 |
|
fname = argv[i]; |
166 |
|
fin = fopen(fname, "r"); |
167 |
|
if (fin == NULL) { |
168 |
< |
sprintf(errmsg, "can't open file \"%s\"", fname); |
168 |
> |
sprintf(errmsg, "cannot open file \"%s\"", fname); |
169 |
|
quiterr(errmsg); |
170 |
|
} |
171 |
|
} else if (i != argc) |
172 |
|
goto userr; |
173 |
|
/* get header */ |
174 |
< |
getheader(fin, headline); |
174 |
> |
getheader(fin, headline, NULL); |
175 |
|
/* get picture dimensions */ |
176 |
< |
if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
177 |
< |
quiterr("bad picture size"); |
176 |
> |
if (wrongformat || !fgetsresolu(&inpres, fin)) |
177 |
> |
quiterr("bad picture format"); |
178 |
> |
xmax = scanlen(&inpres); |
179 |
> |
ymax = numscans(&inpres); |
180 |
|
/* set view parameters */ |
181 |
|
if (gotview && setview(&ourview) != NULL) |
182 |
|
gotview = 0; |
189 |
|
getevent(); /* main loop */ |
190 |
|
userr: |
191 |
|
fprintf(stderr, |
192 |
< |
"Usage: %s [-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
192 |
> |
"Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
193 |
|
progname); |
194 |
|
quit(1); |
195 |
|
} |
198 |
|
headline(s) /* get relevant info from header */ |
199 |
|
char *s; |
200 |
|
{ |
201 |
< |
static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; |
181 |
< |
register char **an; |
201 |
> |
char fmt[32]; |
202 |
|
|
203 |
|
if (isexpos(s)) |
204 |
|
exposure *= exposval(s); |
205 |
< |
else |
206 |
< |
for (an = altname; *an != NULL; an++) |
207 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
208 |
< |
if (sscanview(&ourview, s+strlen(*an)) > 0) |
209 |
< |
gotview++; |
190 |
< |
return; |
191 |
< |
} |
205 |
> |
else if (isformat(s)) { |
206 |
> |
formatval(fmt, s); |
207 |
> |
wrongformat = strcmp(fmt, COLRFMT); |
208 |
> |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
209 |
> |
gotview++; |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
|
init() /* get data and open window */ |
214 |
|
{ |
215 |
+ |
XWMHints ourxwmhints; |
216 |
|
XSetWindowAttributes ourwinattr; |
217 |
< |
XSizeHints oursizhints; |
218 |
< |
register int i; |
217 |
> |
XSizeHints oursizhints; |
218 |
> |
register int i; |
219 |
|
|
220 |
|
if (fname != NULL) { |
221 |
|
scanpos = (long *)malloc(ymax*sizeof(long)); |
224 |
|
for (i = 0; i < ymax; i++) |
225 |
|
scanpos[i] = -1; |
226 |
|
} |
227 |
< |
if ((thedisplay = XOpenDisplay(NULL)) == NULL) |
228 |
< |
quiterr("can't open display; DISPLAY variable set?"); |
229 |
< |
if (maxcolors == 0) { /* get number of available colors */ |
230 |
< |
i = DisplayPlanes(thedisplay,ourscreen); |
212 |
< |
maxcolors = i > 8 ? 256 : 1<<i; |
213 |
< |
if (maxcolors > 4) maxcolors -= 2; |
214 |
< |
} |
227 |
> |
if ((thedisplay = XOpenDisplay(dispname)) == NULL) |
228 |
> |
quiterr("cannot open display"); |
229 |
> |
/* get best visual for default screen */ |
230 |
> |
getbestvis(); |
231 |
|
/* store image */ |
232 |
|
getras(); |
233 |
|
/* open window */ |
234 |
|
ourwinattr.border_pixel = ourblack; |
235 |
|
ourwinattr.background_pixel = ourwhite; |
236 |
+ |
ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, |
237 |
+ |
ourvis.visual, AllocNone); |
238 |
|
wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, |
239 |
< |
0, InputOutput, ourras->visual, |
240 |
< |
CWBackPixel|CWBorderPixel, &ourwinattr); |
239 |
> |
ourvis.depth, InputOutput, ourvis.visual, |
240 |
> |
CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
241 |
|
if (wind == 0) |
242 |
< |
quiterr("can't create window"); |
242 |
> |
quiterr("cannot create window"); |
243 |
> |
width = xmax; |
244 |
> |
height = ymax; |
245 |
> |
ourgc = XCreateGC(thedisplay, wind, 0, 0); |
246 |
> |
XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes); |
247 |
> |
revgc = XCreateGC(thedisplay, wind, 0, 0); |
248 |
> |
XSetFunction(thedisplay, revgc, GXinvert); |
249 |
|
fontid = XLoadFont(thedisplay, FONTNAME); |
250 |
|
if (fontid == 0) |
251 |
< |
quiterr("can't get font"); |
251 |
> |
quiterr("cannot get font"); |
252 |
|
XSetFont(thedisplay, ourgc, fontid); |
229 |
– |
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
253 |
|
XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, |
254 |
|
XC_diamond_cross)); |
255 |
+ |
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
256 |
|
if (geometry != NULL) { |
257 |
|
bzero((char *)&oursizhints, sizeof(oursizhints)); |
258 |
|
i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, |
259 |
< |
&oursizhints.width, &oursizhints.height); |
259 |
> |
(unsigned *)&oursizhints.width, |
260 |
> |
(unsigned *)&oursizhints.height); |
261 |
|
if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) |
262 |
|
oursizhints.flags |= USSize; |
263 |
|
else { |
276 |
|
} |
277 |
|
XSetNormalHints(thedisplay, wind, &oursizhints); |
278 |
|
} |
279 |
+ |
ourxwmhints.flags = InputHint|IconPixmapHint; |
280 |
+ |
ourxwmhints.input = True; |
281 |
+ |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, |
282 |
+ |
wind, icondata, iconwidth, iconheight); |
283 |
+ |
XSetWMHints(thedisplay, wind, &ourxwmhints); |
284 |
|
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |
285 |
|
|ButtonMotionMask|StructureNotifyMask |
286 |
|
|KeyPressMask|ExposureMask); |
316 |
|
} |
317 |
|
|
318 |
|
|
319 |
+ |
static int |
320 |
+ |
viscmp(v1,v2) /* compare visual to see which is better, descending */ |
321 |
+ |
register XVisualInfo *v1, *v2; |
322 |
+ |
{ |
323 |
+ |
int bad1 = 0, bad2 = 0; |
324 |
+ |
register int *rp; |
325 |
+ |
|
326 |
+ |
if (v1->class == v2->class) { |
327 |
+ |
if (v1->class == TrueColor || v1->class == DirectColor) { |
328 |
+ |
/* prefer 24-bit to 32-bit */ |
329 |
+ |
if (v1->depth == 24 && v2->depth == 32) |
330 |
+ |
return(-1); |
331 |
+ |
if (v1->depth == 32 && v2->depth == 24) |
332 |
+ |
return(1); |
333 |
+ |
return(0); |
334 |
+ |
} |
335 |
+ |
/* don't be too greedy */ |
336 |
+ |
if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth) |
337 |
+ |
return(v1->depth - v2->depth); |
338 |
+ |
return(v2->depth - v1->depth); |
339 |
+ |
} |
340 |
+ |
/* prefer Pseudo when < 24-bit */ |
341 |
+ |
if ((v1->class == TrueColor || v1->class == DirectColor) && |
342 |
+ |
v1->depth < 24) |
343 |
+ |
bad1 = 1; |
344 |
+ |
if ((v2->class == TrueColor || v2->class == DirectColor) && |
345 |
+ |
v2->depth < 24) |
346 |
+ |
bad2 = -1; |
347 |
+ |
if (bad1 | bad2) |
348 |
+ |
return(bad1+bad2); |
349 |
+ |
/* otherwise, use class ranking */ |
350 |
+ |
for (rp = ourrank; *rp != -1; rp++) { |
351 |
+ |
if (v1->class == *rp) |
352 |
+ |
return(-1); |
353 |
+ |
if (v2->class == *rp) |
354 |
+ |
return(1); |
355 |
+ |
} |
356 |
+ |
return(0); |
357 |
+ |
} |
358 |
+ |
|
359 |
+ |
|
360 |
+ |
getbestvis() /* get the best visual for this screen */ |
361 |
+ |
{ |
362 |
+ |
#ifdef DEBUG |
363 |
+ |
static char vistype[][12] = { |
364 |
+ |
"StaticGray", |
365 |
+ |
"GrayScale", |
366 |
+ |
"StaticColor", |
367 |
+ |
"PseudoColor", |
368 |
+ |
"TrueColor", |
369 |
+ |
"DirectColor" |
370 |
+ |
}; |
371 |
+ |
#endif |
372 |
+ |
static int rankings[3][6] = { |
373 |
+ |
{TrueColor,DirectColor,PseudoColor,GrayScale,StaticGray,-1}, |
374 |
+ |
{PseudoColor,GrayScale,StaticGray,-1}, |
375 |
+ |
{PseudoColor,GrayScale,StaticGray,-1} |
376 |
+ |
}; |
377 |
+ |
XVisualInfo *xvi; |
378 |
+ |
int vismatched; |
379 |
+ |
register int i, j; |
380 |
+ |
|
381 |
+ |
if (greyscale) { |
382 |
+ |
ourrank = rankings[2]; |
383 |
+ |
if (maxcolors < 2) maxcolors = 256; |
384 |
+ |
} else if (maxcolors >= 2 && maxcolors <= 256) |
385 |
+ |
ourrank = rankings[1]; |
386 |
+ |
else { |
387 |
+ |
ourrank = rankings[0]; |
388 |
+ |
maxcolors = 256; |
389 |
+ |
} |
390 |
+ |
/* find best visual */ |
391 |
+ |
ourvis.screen = ourscreen; |
392 |
+ |
xvi = XGetVisualInfo(thedisplay,VisualScreenMask,&ourvis,&vismatched); |
393 |
+ |
if (xvi == NULL) |
394 |
+ |
quiterr("no visuals for this screen!"); |
395 |
+ |
#ifdef DEBUG |
396 |
+ |
fprintf(stderr, "Supported visuals:\n"); |
397 |
+ |
for (i = 0; i < vismatched; i++) |
398 |
+ |
fprintf(stderr, "\ttype %s, depth %d\n", |
399 |
+ |
vistype[xvi[i].class], xvi[i].depth); |
400 |
+ |
#endif |
401 |
+ |
for (i = 0, j = 1; j < vismatched; j++) |
402 |
+ |
if (viscmp(&xvi[i],&xvi[j]) > 0) |
403 |
+ |
i = j; |
404 |
+ |
/* compare to least acceptable */ |
405 |
+ |
for (j = 0; ourrank[j++] != -1; ) |
406 |
+ |
; |
407 |
+ |
ourvis.class = ourrank[--j]; |
408 |
+ |
ourvis.depth = 1; |
409 |
+ |
if (viscmp(&xvi[i],&ourvis) > 0) |
410 |
+ |
quiterr("inadequate visuals on this screen"); |
411 |
+ |
/* OK, we'll use it */ |
412 |
+ |
copystruct(&ourvis, &xvi[i]); |
413 |
+ |
#ifdef DEBUG |
414 |
+ |
fprintf(stderr, "Selected visual type %s, depth %d\n", |
415 |
+ |
vistype[ourvis.class], ourvis.depth); |
416 |
+ |
#endif |
417 |
+ |
/* make appropriate adjustments */ |
418 |
+ |
if (ourvis.class == GrayScale || ourvis.class == StaticGray) |
419 |
+ |
greyscale = 1; |
420 |
+ |
if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors) |
421 |
+ |
maxcolors = ourvis.colormap_size; |
422 |
+ |
if (maxcolors > 4) |
423 |
+ |
maxcolors -= 2; |
424 |
+ |
if (ourvis.class == StaticGray) { |
425 |
+ |
ourblack = 0; |
426 |
+ |
ourwhite = 255; |
427 |
+ |
} else if (ourvis.class == PseudoColor) { |
428 |
+ |
ourblack = BlackPixel(thedisplay,ourscreen); |
429 |
+ |
ourwhite = WhitePixel(thedisplay,ourscreen); |
430 |
+ |
} else { |
431 |
+ |
ourblack = 0; |
432 |
+ |
ourwhite = ~0; |
433 |
+ |
} |
434 |
+ |
XFree((char *)xvi); |
435 |
+ |
} |
436 |
+ |
|
437 |
+ |
|
438 |
|
getras() /* get raster file */ |
439 |
|
{ |
440 |
|
colormap ourmap; |
444 |
|
ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8)); |
445 |
|
if (ourdata == NULL) |
446 |
|
goto fail; |
447 |
< |
ourras = make_raster(thedisplay, ourscreen, 1, ourdata, |
447 |
> |
ourras = make_raster(thedisplay, &ourvis, 1, ourdata, |
448 |
|
xmax, ymax, 8); |
449 |
|
if (ourras == NULL) |
450 |
|
goto fail; |
451 |
|
getmono(); |
452 |
< |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo)) { |
453 |
< |
ourdata = (unsigned char *)malloc(xmax*ymax*3); |
452 |
> |
} else if (ourvis.class == TrueColor || ourvis.class == DirectColor) { |
453 |
> |
ourdata = (unsigned char *)malloc(4*xmax*ymax); |
454 |
|
if (ourdata == NULL) |
455 |
|
goto fail; |
456 |
< |
ourras = make_raster(thedisplay, ourscreen, 24, ourdata, |
457 |
< |
xmax, ymax, 8); |
456 |
> |
ourras = make_raster(thedisplay, &ourvis, 32, |
457 |
> |
ourdata, xmax, ymax, 32); |
458 |
|
if (ourras == NULL) |
459 |
|
goto fail; |
460 |
|
getfull(); |
462 |
|
ourdata = (unsigned char *)malloc(xmax*ymax); |
463 |
|
if (ourdata == NULL) |
464 |
|
goto fail; |
465 |
< |
ourras = make_raster(thedisplay, ourscreen, 8, ourdata, |
465 |
> |
ourras = make_raster(thedisplay, &ourvis, 8, ourdata, |
466 |
|
xmax, ymax, 8); |
467 |
|
if (ourras == NULL) |
468 |
|
goto fail; |
469 |
< |
if (greyscale) |
470 |
< |
biq(dither,maxcolors,1,ourmap); |
471 |
< |
else |
472 |
< |
ciq(dither,maxcolors,1,ourmap); |
473 |
< |
if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0) |
474 |
< |
goto fail; |
469 |
> |
if (ourvis.class == StaticGray) |
470 |
> |
getgrey(); |
471 |
> |
else { |
472 |
> |
if (greyscale) |
473 |
> |
biq(dither,maxcolors,1,ourmap); |
474 |
> |
else |
475 |
> |
ciq(dither,maxcolors,1,ourmap); |
476 |
> |
if (init_rcolors(ourras, ourmap[0], |
477 |
> |
ourmap[1], ourmap[2]) == 0) |
478 |
> |
goto fail; |
479 |
> |
} |
480 |
|
} |
481 |
< |
return; |
481 |
> |
return; |
482 |
|
fail: |
483 |
< |
quit("could not create raster image"); |
483 |
> |
quiterr("could not create raster image"); |
484 |
|
} |
485 |
|
|
486 |
|
|
506 |
|
case MapNotify: |
507 |
|
map_rcolors(ourras, wind); |
508 |
|
if (fast) |
509 |
< |
make_rpixmap(ourras); |
509 |
> |
make_rpixmap(ourras, wind); |
510 |
|
break; |
511 |
|
case UnmapNotify: |
512 |
< |
unmap_rcolors(ourras); |
512 |
> |
if (!fast) |
513 |
> |
unmap_rcolors(ourras); |
514 |
|
break; |
515 |
|
case Expose: |
516 |
|
redraw(e.e.x, e.e.y, e.e.width, e.e.height); |
533 |
|
XColor cvx; |
534 |
|
int com, n; |
535 |
|
double comp; |
536 |
+ |
FLOAT hv[2]; |
537 |
|
FVECT rorg, rdir; |
538 |
|
|
539 |
|
n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); |
542 |
|
com = buf[0]; |
543 |
|
switch (com) { /* interpret command */ |
544 |
|
case 'q': |
545 |
< |
case CTRL(D): /* quit */ |
545 |
> |
case CTRL('D'): /* quit */ |
546 |
|
quit(0); |
547 |
|
case '\n': |
548 |
|
case '\r': |
556 |
|
sprintf(buf, "%.3f", intens(cval)/exposure); |
557 |
|
break; |
558 |
|
case 'l': /* luminance */ |
559 |
< |
sprintf(buf, "%.0fn", bright(cval)*683.0/exposure); |
559 |
> |
sprintf(buf, "%.0fL", luminance(cval)/exposure); |
560 |
|
break; |
561 |
|
case 'c': /* color */ |
562 |
|
comp = pow(2.0, (double)scale); |
582 |
|
XStoreColor(thedisplay, ourras->cmap, &cvx); |
583 |
|
return(0); |
584 |
|
case 'p': /* position */ |
585 |
< |
sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff); |
585 |
> |
pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); |
586 |
> |
sprintf(buf, "(%d,%d)", (int)(hv[0]*inpres.xr), |
587 |
> |
(int)(hv[1]*inpres.yr)); |
588 |
|
XDrawImageString(thedisplay, wind, ourgc, ekey->x, ekey->y, |
589 |
|
buf, strlen(buf)); |
590 |
|
return(0); |
593 |
|
XBell(thedisplay, 0); |
594 |
|
return(-1); |
595 |
|
} |
596 |
< |
viewray(rorg, rdir, &ourview, |
597 |
< |
(ekey->x-xoff+.5)/xmax, |
598 |
< |
(ymax-1-ekey->y+yoff+.5)/ymax); |
596 |
> |
pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); |
597 |
> |
if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
598 |
> |
return(-1); |
599 |
|
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
600 |
|
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
601 |
|
fflush(stdout); |
616 |
|
free_raster(ourras); |
617 |
|
getras(); |
618 |
|
/* fall through */ |
619 |
< |
case CTRL(R): /* redraw */ |
620 |
< |
case CTRL(L): |
619 |
> |
case CTRL('R'): /* redraw */ |
620 |
> |
case CTRL('L'): |
621 |
|
unmap_rcolors(ourras); |
622 |
|
XClearWindow(thedisplay, wind); |
623 |
|
map_rcolors(ourras, wind); |
643 |
|
XButtonReleasedEvent b; |
644 |
|
XPointerMovedEvent m; |
645 |
|
} e; |
646 |
< |
int nxo, nyo; |
646 |
> |
int mxo, myo; |
647 |
|
|
648 |
|
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
649 |
|
while (e.u.type == MotionNotify) { |
650 |
< |
nxo = xoff + e.m.x - ebut->x; |
651 |
< |
nyo = yoff + e.m.y - ebut->y; |
652 |
< |
revbox(nxo, nyo, nxo+xmax, nyo+ymax); |
650 |
> |
mxo = e.m.x; |
651 |
> |
myo = e.m.y; |
652 |
> |
revline(ebut->x, ebut->y, mxo, myo); |
653 |
> |
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
654 |
> |
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
655 |
|
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
656 |
< |
revbox(nxo, nyo, nxo+xmax, nyo+ymax); |
656 |
> |
revline(ebut->x, ebut->y, mxo, myo); |
657 |
> |
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
658 |
> |
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
659 |
|
} |
660 |
|
xoff += e.b.x - ebut->x; |
661 |
|
yoff += e.b.y - ebut->y; |
699 |
|
revbox(x0, y0, x1, y1) /* draw box with reversed lines */ |
700 |
|
int x0, y0, x1, y1; |
701 |
|
{ |
702 |
< |
static GC mygc = 0; |
702 |
> |
revline(x0, y0, x1, y0); |
703 |
> |
revline(x0, y1, x1, y1); |
704 |
> |
revline(x0, y0, x0, y1); |
705 |
> |
revline(x1, y0, x1, y1); |
706 |
> |
} |
707 |
|
|
542 |
– |
if (mygc == 0) { |
543 |
– |
mygc = XCreateGC(thedisplay, wind, 0, 0); |
544 |
– |
XSetFunction(thedisplay, mygc, GXinvert); |
545 |
– |
} |
546 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y0, x1, y0); |
547 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y1, x1, y1); |
548 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y0, x0, y1); |
549 |
– |
XDrawLine(thedisplay, wind, mygc, x1, y0, x1, y1); |
550 |
– |
} /* end of revbox */ |
708 |
|
|
552 |
– |
|
709 |
|
avgbox(clr) /* average color over current box */ |
710 |
|
COLOR clr; |
711 |
|
{ |
712 |
+ |
static COLOR lc; |
713 |
+ |
static int ll, lr, lt, lb; |
714 |
|
int left, right, top, bottom; |
715 |
|
int y; |
716 |
|
double d; |
734 |
|
bottom = ymax; |
735 |
|
if (top >= bottom) |
736 |
|
return(-1); |
737 |
+ |
if (left == ll && right == lr && top == lt && bottom == lb) { |
738 |
+ |
copycolor(clr, lc); |
739 |
+ |
return; |
740 |
+ |
} |
741 |
|
for (y = top; y < bottom; y++) { |
742 |
|
if (getscan(y) == -1) |
743 |
|
return(-1); |
748 |
|
} |
749 |
|
d = 1.0/((right-left)*(bottom-top)); |
750 |
|
scalecolor(clr, d); |
751 |
+ |
ll = left; lr = right; lt = top; lb = bottom; |
752 |
+ |
copycolor(lc, clr); |
753 |
|
return(0); |
754 |
|
} |
755 |
|
|
758 |
|
{ |
759 |
|
register unsigned char *dp; |
760 |
|
register int x, err; |
761 |
< |
int y; |
598 |
< |
rgbpixel *inline; |
761 |
> |
int y, errp; |
762 |
|
short *cerr; |
763 |
|
|
764 |
< |
if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
765 |
< |
|| (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
603 |
< |
quit("out of memory in getmono"); |
764 |
> |
if ((cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
765 |
> |
quiterr("out of memory in getmono"); |
766 |
|
dp = ourdata - 1; |
767 |
|
for (y = 0; y < ymax; y++) { |
768 |
< |
picreadline3(y, inline); |
768 |
> |
if (getscan(y) < 0) |
769 |
> |
quiterr("seek error in getmono"); |
770 |
> |
normcolrs(scanline, xmax, scale); |
771 |
> |
add2icon(y, scanline); |
772 |
|
err = 0; |
773 |
|
for (x = 0; x < xmax; x++) { |
774 |
|
if (!(x&7)) |
775 |
|
*++dp = 0; |
776 |
< |
err += rgb_bright(&inline[x]) + cerr[x]; |
776 |
> |
errp = err; |
777 |
> |
err += normbright(scanline[x]) + cerr[x]; |
778 |
|
if (err > 127) |
779 |
|
err -= 255; |
780 |
|
else |
781 |
|
*dp |= 1<<(7-(x&07)); |
782 |
< |
cerr[x] = err >>= 1; |
782 |
> |
err /= 3; |
783 |
> |
cerr[x] = err + errp; |
784 |
|
} |
785 |
|
} |
619 |
– |
free((char *)inline); |
786 |
|
free((char *)cerr); |
787 |
|
} |
788 |
|
|
789 |
|
|
790 |
+ |
add2icon(y, scan) /* add a scanline to our icon data */ |
791 |
+ |
int y; |
792 |
+ |
COLR *scan; |
793 |
+ |
{ |
794 |
+ |
static short cerr[ICONSIZ]; |
795 |
+ |
static int ynext; |
796 |
+ |
static char *dp; |
797 |
+ |
register int err; |
798 |
+ |
register int x, ti; |
799 |
+ |
int errp; |
800 |
+ |
|
801 |
+ |
if (iconheight == 0) { /* initialize */ |
802 |
+ |
if (xmax <= ICONSIZ && ymax <= ICONSIZ) { |
803 |
+ |
iconwidth = xmax; |
804 |
+ |
iconheight = ymax; |
805 |
+ |
} else if (xmax > ymax) { |
806 |
+ |
iconwidth = ICONSIZ; |
807 |
+ |
iconheight = ICONSIZ*ymax/xmax; |
808 |
+ |
if (iconheight < 1) |
809 |
+ |
iconheight = 1; |
810 |
+ |
} else { |
811 |
+ |
iconwidth = ICONSIZ*xmax/ymax; |
812 |
+ |
if (iconwidth < 1) |
813 |
+ |
iconwidth = 1; |
814 |
+ |
iconheight = ICONSIZ; |
815 |
+ |
} |
816 |
+ |
ynext = 0; |
817 |
+ |
dp = icondata - 1; |
818 |
+ |
} |
819 |
+ |
if (y < ynext*ymax/iconheight) /* skip this one */ |
820 |
+ |
return; |
821 |
+ |
err = 0; |
822 |
+ |
for (x = 0; x < iconwidth; x++) { |
823 |
+ |
if (!(x&7)) |
824 |
+ |
*++dp = 0; |
825 |
+ |
errp = err; |
826 |
+ |
ti = x*xmax/iconwidth; |
827 |
+ |
err += normbright(scan[ti]) + cerr[x]; |
828 |
+ |
if (err > 127) |
829 |
+ |
err -= 255; |
830 |
+ |
else |
831 |
+ |
*dp |= 1<<(x&07); |
832 |
+ |
err /= 3; |
833 |
+ |
cerr[x] = err + errp; |
834 |
+ |
} |
835 |
+ |
ynext++; |
836 |
+ |
} |
837 |
+ |
|
838 |
+ |
|
839 |
|
getfull() /* get full (24-bit) data */ |
840 |
|
{ |
841 |
|
int y; |
842 |
+ |
register unsigned long *dp; |
843 |
+ |
register int x; |
844 |
+ |
/* set gamma correction */ |
845 |
+ |
setcolrgam(gamcor); |
846 |
+ |
/* read and convert file */ |
847 |
+ |
dp = (unsigned long *)ourdata; |
848 |
+ |
for (y = 0; y < ymax; y++) { |
849 |
+ |
if (getscan(y) < 0) |
850 |
+ |
quiterr("seek error in getfull"); |
851 |
+ |
if (scale) |
852 |
+ |
shiftcolrs(scanline, xmax, scale); |
853 |
+ |
colrs_gambs(scanline, xmax); |
854 |
+ |
add2icon(y, scanline); |
855 |
+ |
if (ourras->image->blue_mask & 1) |
856 |
+ |
for (x = 0; x < xmax; x++) |
857 |
+ |
*dp++ = scanline[x][RED] << 16 | |
858 |
+ |
scanline[x][GRN] << 8 | |
859 |
+ |
scanline[x][BLU] ; |
860 |
+ |
else |
861 |
+ |
for (x = 0; x < xmax; x++) |
862 |
+ |
*dp++ = scanline[x][RED] | |
863 |
+ |
scanline[x][GRN] << 8 | |
864 |
+ |
scanline[x][BLU] << 16 ; |
865 |
+ |
} |
866 |
+ |
} |
867 |
|
|
868 |
< |
for (y = 0; y < ymax; y++) |
869 |
< |
picreadline3(y, (rgbpixel *)(ourdata+y*xmax*3)); |
868 |
> |
|
869 |
> |
getgrey() /* get greyscale data */ |
870 |
> |
{ |
871 |
> |
int y; |
872 |
> |
register unsigned char *dp; |
873 |
> |
register int x; |
874 |
> |
/* set gamma correction */ |
875 |
> |
setcolrgam(gamcor); |
876 |
> |
/* read and convert file */ |
877 |
> |
dp = ourdata; |
878 |
> |
for (y = 0; y < ymax; y++) { |
879 |
> |
if (getscan(y) < 0) |
880 |
> |
quiterr("seek error in getfull"); |
881 |
> |
if (scale) |
882 |
> |
shiftcolrs(scanline, xmax, scale); |
883 |
> |
colrs_gambs(scanline, xmax); |
884 |
> |
add2icon(y, scanline); |
885 |
> |
if (ourvis.colormap_size < 256) |
886 |
> |
for (x = 0; x < xmax; x++) |
887 |
> |
*dp++ = ((long)normbright(scanline[x]) * |
888 |
> |
ourvis.colormap_size + 128) >> 8; |
889 |
> |
else |
890 |
> |
for (x = 0; x < xmax; x++) |
891 |
> |
*dp++ = normbright(scanline[x]); |
892 |
> |
} |
893 |
|
} |
894 |
|
|
895 |
|
|
928 |
|
if (scanpos == NULL || scanpos[y] == -1) |
929 |
|
return(-1); |
930 |
|
if (fseek(fin, scanpos[y], 0) == -1) |
931 |
< |
quit("fseek error"); |
931 |
> |
quiterr("fseek error"); |
932 |
|
cury = y; |
933 |
|
} else if (scanpos != NULL) |
934 |
|
scanpos[y] = ftell(fin); |
951 |
|
quiterr("cannot seek for picreadline"); |
952 |
|
/* convert scanline */ |
953 |
|
normcolrs(scanline, xmax, scale); |
954 |
+ |
add2icon(y, scanline); |
955 |
|
for (i = 0; i < xmax; i++) { |
956 |
|
l3[i].r = scanline[i][RED]; |
957 |
|
l3[i].g = scanline[i][GRN]; |
975 |
|
register int i, val; |
976 |
|
|
977 |
|
for (i = 0; i < 256; i++) { |
978 |
< |
val = pow(i/256.0, 1.0/gamcor) * 256.0; |
978 |
> |
val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; |
979 |
|
map[0][i] = map[1][i] = map[2][i] = val; |
980 |
|
} |
981 |
|
} |
984 |
|
picwritecm(map) /* handled elsewhere */ |
985 |
|
colormap map; |
986 |
|
{ |
987 |
< |
#ifdef DEBUG |
987 |
> |
#if 0 |
988 |
|
register int i; |
989 |
|
|
990 |
|
for (i = 0; i < 256; i++) |