1 |
< |
/* Copyright (c) 1990 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 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 80 /* maximum icon dimension */ |
41 |
> |
#define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ |
42 |
|
|
43 |
|
#define ourscreen DefaultScreen(thedisplay) |
43 |
– |
#define ourblack BlackPixel(thedisplay,ourscreen) |
44 |
– |
#define ourwhite WhitePixel(thedisplay,ourscreen) |
44 |
|
#define ourroot RootWindow(thedisplay,ourscreen) |
46 |
– |
#define ourgc DefaultGC(thedisplay,ourscreen) |
45 |
|
|
46 |
|
#define revline(x0,y0,x1,y1) XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1) |
47 |
|
|
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=0, ourwhite=1; /* 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 */ |
83 |
|
|
84 |
|
int wrongformat = 0; /* input in another format? */ |
85 |
|
|
86 |
+ |
GC ourgc; /* standard graphics context */ |
87 |
|
GC revgc; /* graphics context with GXinvert */ |
88 |
|
|
89 |
< |
XRASTER *ourras; /* our stored image */ |
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+7)/8*ICONSIZ]; /* icon bitmap data */ |
100 |
> |
char icondata[ICONSIZ*ICONSIZ/8]; /* icon bitmap data */ |
101 |
|
int iconwidth = 0, iconheight = 0; |
102 |
|
|
103 |
|
char *progname; |
108 |
|
|
109 |
|
extern char *malloc(), *calloc(); |
110 |
|
|
111 |
< |
extern double atof(), pow(), log(); |
111 |
> |
extern double pow(), log(); |
112 |
|
|
113 |
|
Display *thedisplay; |
114 |
|
|
116 |
|
int argc; |
117 |
|
char *argv[]; |
118 |
|
{ |
119 |
+ |
extern char *getenv(); |
120 |
+ |
char *gv; |
121 |
|
int headline(); |
122 |
|
int i; |
123 |
|
|
124 |
|
progname = argv[0]; |
125 |
+ |
if ((gv = getenv("GAMMA")) != NULL) |
126 |
+ |
gamcor = atof(gv); |
127 |
|
|
128 |
|
for (i = 1; i < argc; i++) |
129 |
|
if (argv[i][0] == '-') |
138 |
|
maxcolors = 2; |
139 |
|
break; |
140 |
|
case 'd': |
141 |
< |
dither = !dither; |
141 |
> |
if (argv[i][2] == 'i') |
142 |
> |
dispname = argv[++i]; |
143 |
> |
else |
144 |
> |
dither = !dither; |
145 |
|
break; |
146 |
|
case 'f': |
147 |
|
fast = !fast; |
152 |
|
scale = atoi(argv[++i]); |
153 |
|
break; |
154 |
|
case 'g': |
155 |
< |
if (!strcmp(argv[i], "-geometry")) |
155 |
> |
if (argv[i][2] == 'e') |
156 |
|
geometry = argv[++i]; |
157 |
|
else |
158 |
|
gamcor = atof(argv[++i]); |
169 |
|
fname = argv[i]; |
170 |
|
fin = fopen(fname, "r"); |
171 |
|
if (fin == NULL) { |
172 |
< |
sprintf(errmsg, "can't open file \"%s\"", fname); |
172 |
> |
sprintf(errmsg, "cannot open file \"%s\"", fname); |
173 |
|
quiterr(errmsg); |
174 |
|
} |
175 |
|
} else if (i != argc) |
177 |
|
/* get header */ |
178 |
|
getheader(fin, headline, NULL); |
179 |
|
/* get picture dimensions */ |
180 |
< |
if (wrongformat || fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
180 |
> |
if (wrongformat || !fgetsresolu(&inpres, fin)) |
181 |
|
quiterr("bad picture format"); |
182 |
+ |
xmax = scanlen(&inpres); |
183 |
+ |
ymax = numscans(&inpres); |
184 |
|
/* set view parameters */ |
185 |
|
if (gotview && setview(&ourview) != NULL) |
186 |
|
gotview = 0; |
193 |
|
getevent(); /* main loop */ |
194 |
|
userr: |
195 |
|
fprintf(stderr, |
196 |
< |
"Usage: %s [-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
196 |
> |
"Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
197 |
|
progname); |
198 |
|
quit(1); |
199 |
|
} |
202 |
|
headline(s) /* get relevant info from header */ |
203 |
|
char *s; |
204 |
|
{ |
191 |
– |
static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; |
192 |
– |
register char **an; |
205 |
|
char fmt[32]; |
206 |
|
|
207 |
|
if (isexpos(s)) |
209 |
|
else if (isformat(s)) { |
210 |
|
formatval(fmt, s); |
211 |
|
wrongformat = strcmp(fmt, COLRFMT); |
212 |
< |
} else |
213 |
< |
for (an = altname; *an != NULL; an++) |
202 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
203 |
< |
if (sscanview(&ourview, s+strlen(*an)) > 0) |
204 |
< |
gotview++; |
205 |
< |
return; |
206 |
< |
} |
212 |
> |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
213 |
> |
gotview++; |
214 |
|
} |
215 |
|
|
216 |
|
|
218 |
|
{ |
219 |
|
XWMHints ourxwmhints; |
220 |
|
XSetWindowAttributes ourwinattr; |
221 |
< |
XSizeHints oursizhints; |
222 |
< |
register int i; |
221 |
> |
XSizeHints oursizhints; |
222 |
> |
register int i; |
223 |
|
|
224 |
|
if (fname != NULL) { |
225 |
|
scanpos = (long *)malloc(ymax*sizeof(long)); |
228 |
|
for (i = 0; i < ymax; i++) |
229 |
|
scanpos[i] = -1; |
230 |
|
} |
231 |
< |
if ((thedisplay = XOpenDisplay(NULL)) == NULL) |
232 |
< |
quiterr("can't open display; DISPLAY variable set?"); |
233 |
< |
if (maxcolors == 0) { /* get number of available colors */ |
234 |
< |
i = DisplayPlanes(thedisplay,ourscreen); |
228 |
< |
maxcolors = i > 8 ? 256 : 1<<i; |
229 |
< |
if (maxcolors > 4) maxcolors -= 2; |
230 |
< |
} |
231 |
> |
if ((thedisplay = XOpenDisplay(dispname)) == NULL) |
232 |
> |
quiterr("cannot open display"); |
233 |
> |
/* get best visual for default screen */ |
234 |
> |
getbestvis(); |
235 |
|
/* store image */ |
236 |
|
getras(); |
237 |
|
/* open window */ |
238 |
|
ourwinattr.border_pixel = ourblack; |
239 |
|
ourwinattr.background_pixel = ourwhite; |
240 |
+ |
ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, |
241 |
+ |
ourvis.visual, AllocNone); |
242 |
|
wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, |
243 |
< |
0, InputOutput, ourras->visual, |
244 |
< |
CWBackPixel|CWBorderPixel, &ourwinattr); |
243 |
> |
ourvis.depth, InputOutput, ourvis.visual, |
244 |
> |
CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
245 |
|
if (wind == 0) |
246 |
< |
quiterr("can't create window"); |
246 |
> |
quiterr("cannot create window"); |
247 |
> |
XFreeColormap(thedisplay, ourwinattr.colormap); |
248 |
|
width = xmax; |
249 |
|
height = ymax; |
250 |
+ |
ourgc = XCreateGC(thedisplay, wind, 0, 0); |
251 |
+ |
XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes); |
252 |
+ |
revgc = XCreateGC(thedisplay, wind, 0, 0); |
253 |
+ |
XSetFunction(thedisplay, revgc, GXinvert); |
254 |
|
fontid = XLoadFont(thedisplay, FONTNAME); |
255 |
|
if (fontid == 0) |
256 |
< |
quiterr("can't get font"); |
256 |
> |
quiterr("cannot get font"); |
257 |
|
XSetFont(thedisplay, ourgc, fontid); |
247 |
– |
revgc = XCreateGC(thedisplay, wind, 0, 0); |
248 |
– |
XSetFunction(thedisplay, revgc, GXinvert); |
249 |
– |
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
258 |
|
XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, |
259 |
|
XC_diamond_cross)); |
260 |
+ |
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
261 |
|
if (geometry != NULL) { |
262 |
|
bzero((char *)&oursizhints, sizeof(oursizhints)); |
263 |
|
i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
+ |
static int |
325 |
+ |
viscmp(v1,v2) /* compare visual to see which is better, descending */ |
326 |
+ |
register XVisualInfo *v1, *v2; |
327 |
+ |
{ |
328 |
+ |
int bad1 = 0, bad2 = 0; |
329 |
+ |
register int *rp; |
330 |
+ |
|
331 |
+ |
if (v1->class == v2->class) { |
332 |
+ |
if (v1->class == TrueColor || v1->class == DirectColor) { |
333 |
+ |
/* prefer 24-bit to 32-bit */ |
334 |
+ |
if (v1->depth == 24 && v2->depth == 32) |
335 |
+ |
return(-1); |
336 |
+ |
if (v1->depth == 32 && v2->depth == 24) |
337 |
+ |
return(1); |
338 |
+ |
return(0); |
339 |
+ |
} |
340 |
+ |
/* don't be too greedy */ |
341 |
+ |
if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth) |
342 |
+ |
return(v1->depth - v2->depth); |
343 |
+ |
return(v2->depth - v1->depth); |
344 |
+ |
} |
345 |
+ |
/* prefer Pseudo when < 24-bit */ |
346 |
+ |
if ((v1->class == TrueColor || v1->class == DirectColor) && |
347 |
+ |
v1->depth < 24) |
348 |
+ |
bad1 = 1; |
349 |
+ |
if ((v2->class == TrueColor || v2->class == DirectColor) && |
350 |
+ |
v2->depth < 24) |
351 |
+ |
bad2 = -1; |
352 |
+ |
if (bad1 | bad2) |
353 |
+ |
return(bad1+bad2); |
354 |
+ |
/* otherwise, use class ranking */ |
355 |
+ |
for (rp = ourrank; *rp != -1; rp++) { |
356 |
+ |
if (v1->class == *rp) |
357 |
+ |
return(-1); |
358 |
+ |
if (v2->class == *rp) |
359 |
+ |
return(1); |
360 |
+ |
} |
361 |
+ |
return(0); |
362 |
+ |
} |
363 |
+ |
|
364 |
+ |
|
365 |
+ |
getbestvis() /* get the best visual for this screen */ |
366 |
+ |
{ |
367 |
+ |
#ifdef DEBUG |
368 |
+ |
static char vistype[][12] = { |
369 |
+ |
"StaticGray", |
370 |
+ |
"GrayScale", |
371 |
+ |
"StaticColor", |
372 |
+ |
"PseudoColor", |
373 |
+ |
"TrueColor", |
374 |
+ |
"DirectColor" |
375 |
+ |
}; |
376 |
+ |
#endif |
377 |
+ |
static int rankings[3][6] = { |
378 |
+ |
{TrueColor,DirectColor,PseudoColor,GrayScale,StaticGray,-1}, |
379 |
+ |
{PseudoColor,GrayScale,StaticGray,-1}, |
380 |
+ |
{PseudoColor,GrayScale,StaticGray,-1} |
381 |
+ |
}; |
382 |
+ |
XVisualInfo *xvi; |
383 |
+ |
int vismatched; |
384 |
+ |
register int i, j; |
385 |
+ |
|
386 |
+ |
if (greyscale) { |
387 |
+ |
ourrank = rankings[2]; |
388 |
+ |
if (maxcolors < 2) maxcolors = 256; |
389 |
+ |
} else if (maxcolors >= 2 && maxcolors <= 256) |
390 |
+ |
ourrank = rankings[1]; |
391 |
+ |
else { |
392 |
+ |
ourrank = rankings[0]; |
393 |
+ |
maxcolors = 256; |
394 |
+ |
} |
395 |
+ |
/* find best visual */ |
396 |
+ |
ourvis.screen = ourscreen; |
397 |
+ |
xvi = XGetVisualInfo(thedisplay,VisualScreenMask,&ourvis,&vismatched); |
398 |
+ |
if (xvi == NULL) |
399 |
+ |
quiterr("no visuals for this screen!"); |
400 |
+ |
#ifdef DEBUG |
401 |
+ |
fprintf(stderr, "Supported visuals:\n"); |
402 |
+ |
for (i = 0; i < vismatched; i++) |
403 |
+ |
fprintf(stderr, "\ttype %s, depth %d\n", |
404 |
+ |
vistype[xvi[i].class], xvi[i].depth); |
405 |
+ |
#endif |
406 |
+ |
for (i = 0, j = 1; j < vismatched; j++) |
407 |
+ |
if (viscmp(&xvi[i],&xvi[j]) > 0) |
408 |
+ |
i = j; |
409 |
+ |
/* compare to least acceptable */ |
410 |
+ |
for (j = 0; ourrank[j++] != -1; ) |
411 |
+ |
; |
412 |
+ |
ourvis.class = ourrank[--j]; |
413 |
+ |
ourvis.depth = 1; |
414 |
+ |
if (viscmp(&xvi[i],&ourvis) > 0) |
415 |
+ |
quiterr("inadequate visuals on this screen"); |
416 |
+ |
/* OK, we'll use it */ |
417 |
+ |
copystruct(&ourvis, &xvi[i]); |
418 |
+ |
#ifdef DEBUG |
419 |
+ |
fprintf(stderr, "Selected visual type %s, depth %d\n", |
420 |
+ |
vistype[ourvis.class], ourvis.depth); |
421 |
+ |
#endif |
422 |
+ |
/* make appropriate adjustments */ |
423 |
+ |
if (ourvis.class == GrayScale || ourvis.class == StaticGray) |
424 |
+ |
greyscale = 1; |
425 |
+ |
if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors) |
426 |
+ |
maxcolors = ourvis.colormap_size; |
427 |
+ |
if (maxcolors > 4) |
428 |
+ |
maxcolors -= 2; |
429 |
+ |
if (ourvis.class == StaticGray) { |
430 |
+ |
ourblack = 0; |
431 |
+ |
ourwhite = 255; |
432 |
+ |
} else if (ourvis.class == PseudoColor) { |
433 |
+ |
ourblack = BlackPixel(thedisplay,ourscreen); |
434 |
+ |
ourwhite = WhitePixel(thedisplay,ourscreen); |
435 |
+ |
if ((ourblack|ourwhite) & ~255L) { |
436 |
+ |
ourblack = 0; |
437 |
+ |
ourwhite = 1; |
438 |
+ |
} |
439 |
+ |
} else { |
440 |
+ |
ourblack = 0; |
441 |
+ |
ourwhite = ourvis.red_mask|ourvis.green_mask|ourvis.blue_mask; |
442 |
+ |
} |
443 |
+ |
XFree((char *)xvi); |
444 |
+ |
} |
445 |
+ |
|
446 |
+ |
|
447 |
|
getras() /* get raster file */ |
448 |
|
{ |
449 |
|
colormap ourmap; |
453 |
|
ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8)); |
454 |
|
if (ourdata == NULL) |
455 |
|
goto fail; |
456 |
< |
ourras = make_raster(thedisplay, ourscreen, 1, ourdata, |
456 |
> |
ourras = make_raster(thedisplay, &ourvis, 1, ourdata, |
457 |
|
xmax, ymax, 8); |
458 |
|
if (ourras == NULL) |
459 |
|
goto fail; |
460 |
|
getmono(); |
461 |
< |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo) |
462 |
< |
/* kludge for DirectColor */ |
331 |
< |
|| XMatchVisualInfo(thedisplay,ourscreen,24,DirectColor,&vinfo)) { |
332 |
< |
ourdata = (unsigned char *)malloc(xmax*ymax*3); |
461 |
> |
} else if (ourvis.class == TrueColor || ourvis.class == DirectColor) { |
462 |
> |
ourdata = (unsigned char *)malloc(4*xmax*ymax); |
463 |
|
if (ourdata == NULL) |
464 |
|
goto fail; |
465 |
< |
ourras = make_raster(thedisplay, ourscreen, 24, ourdata, |
466 |
< |
xmax, ymax, 8); |
465 |
> |
ourras = make_raster(thedisplay, &ourvis, 32, |
466 |
> |
ourdata, xmax, ymax, 32); |
467 |
|
if (ourras == NULL) |
468 |
|
goto fail; |
469 |
|
getfull(); |
471 |
|
ourdata = (unsigned char *)malloc(xmax*ymax); |
472 |
|
if (ourdata == NULL) |
473 |
|
goto fail; |
474 |
< |
ourras = make_raster(thedisplay, ourscreen, 8, ourdata, |
474 |
> |
ourras = make_raster(thedisplay, &ourvis, 8, ourdata, |
475 |
|
xmax, ymax, 8); |
476 |
|
if (ourras == NULL) |
477 |
|
goto fail; |
478 |
< |
if (greyscale) |
479 |
< |
biq(dither,maxcolors,1,ourmap); |
480 |
< |
else |
481 |
< |
ciq(dither,maxcolors,1,ourmap); |
482 |
< |
if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0) |
483 |
< |
goto fail; |
478 |
> |
if (ourvis.class == StaticGray) |
479 |
> |
getgrey(); |
480 |
> |
else { |
481 |
> |
if (greyscale) |
482 |
> |
biq(dither,maxcolors,1,ourmap); |
483 |
> |
else |
484 |
> |
ciq(dither,maxcolors,1,ourmap); |
485 |
> |
if (init_rcolors(ourras, ourmap[0], |
486 |
> |
ourmap[1], ourmap[2]) == 0) |
487 |
> |
goto fail; |
488 |
> |
} |
489 |
|
} |
490 |
< |
return; |
490 |
> |
return; |
491 |
|
fail: |
492 |
|
quiterr("could not create raster image"); |
493 |
|
} |
515 |
|
case MapNotify: |
516 |
|
map_rcolors(ourras, wind); |
517 |
|
if (fast) |
518 |
< |
make_rpixmap(ourras); |
518 |
> |
make_rpixmap(ourras, wind); |
519 |
|
break; |
520 |
|
case UnmapNotify: |
521 |
< |
unmap_rcolors(ourras); |
521 |
> |
if (!fast) |
522 |
> |
unmap_rcolors(ourras); |
523 |
|
break; |
524 |
|
case Expose: |
525 |
|
redraw(e.e.x, e.e.y, e.e.width, e.e.height); |
542 |
|
XColor cvx; |
543 |
|
int com, n; |
544 |
|
double comp; |
545 |
+ |
FLOAT hv[2]; |
546 |
|
FVECT rorg, rdir; |
547 |
|
|
548 |
|
n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); |
551 |
|
com = buf[0]; |
552 |
|
switch (com) { /* interpret command */ |
553 |
|
case 'q': |
554 |
< |
case CTRL(D): /* quit */ |
554 |
> |
case CTRL('D'): /* quit */ |
555 |
|
quit(0); |
556 |
|
case '\n': |
557 |
|
case '\r': |
591 |
|
XStoreColor(thedisplay, ourras->cmap, &cvx); |
592 |
|
return(0); |
593 |
|
case 'p': /* position */ |
594 |
< |
sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff); |
594 |
> |
pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); |
595 |
> |
sprintf(buf, "(%d,%d)", (int)(hv[0]*inpres.xr), |
596 |
> |
(int)(hv[1]*inpres.yr)); |
597 |
|
XDrawImageString(thedisplay, wind, ourgc, ekey->x, ekey->y, |
598 |
|
buf, strlen(buf)); |
599 |
|
return(0); |
602 |
|
XBell(thedisplay, 0); |
603 |
|
return(-1); |
604 |
|
} |
605 |
< |
if (viewray(rorg, rdir, &ourview, |
606 |
< |
(ekey->x-xoff+.5)/xmax, |
468 |
< |
(ymax-1-ekey->y+yoff+.5)/ymax) < 0) |
605 |
> |
pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); |
606 |
> |
if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
607 |
|
return(-1); |
608 |
|
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
609 |
|
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
625 |
|
free_raster(ourras); |
626 |
|
getras(); |
627 |
|
/* fall through */ |
628 |
< |
case CTRL(R): /* redraw */ |
629 |
< |
case CTRL(L): |
628 |
> |
case CTRL('R'): /* redraw */ |
629 |
> |
case CTRL('L'): |
630 |
|
unmap_rcolors(ourras); |
631 |
|
XClearWindow(thedisplay, wind); |
632 |
|
map_rcolors(ourras, wind); |
718 |
|
avgbox(clr) /* average color over current box */ |
719 |
|
COLOR clr; |
720 |
|
{ |
721 |
+ |
static COLOR lc; |
722 |
+ |
static int ll, lr, lt, lb; |
723 |
|
int left, right, top, bottom; |
724 |
|
int y; |
725 |
|
double d; |
743 |
|
bottom = ymax; |
744 |
|
if (top >= bottom) |
745 |
|
return(-1); |
746 |
+ |
if (left == ll && right == lr && top == lt && bottom == lb) { |
747 |
+ |
copycolor(clr, lc); |
748 |
+ |
return; |
749 |
+ |
} |
750 |
|
for (y = top; y < bottom; y++) { |
751 |
|
if (getscan(y) == -1) |
752 |
|
return(-1); |
757 |
|
} |
758 |
|
d = 1.0/((right-left)*(bottom-top)); |
759 |
|
scalecolor(clr, d); |
760 |
+ |
ll = left; lr = right; lt = top; lb = bottom; |
761 |
+ |
copycolor(lc, clr); |
762 |
|
return(0); |
763 |
|
} |
764 |
|
|
767 |
|
{ |
768 |
|
register unsigned char *dp; |
769 |
|
register int x, err; |
770 |
< |
int y; |
770 |
> |
int y, errp; |
771 |
|
short *cerr; |
772 |
|
|
773 |
|
if ((cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
782 |
|
for (x = 0; x < xmax; x++) { |
783 |
|
if (!(x&7)) |
784 |
|
*++dp = 0; |
785 |
+ |
errp = err; |
786 |
|
err += normbright(scanline[x]) + cerr[x]; |
787 |
|
if (err > 127) |
788 |
|
err -= 255; |
789 |
|
else |
790 |
|
*dp |= 1<<(7-(x&07)); |
791 |
< |
cerr[x] = err >>= 1; |
791 |
> |
err /= 3; |
792 |
> |
cerr[x] = err + errp; |
793 |
|
} |
794 |
|
} |
795 |
|
free((char *)cerr); |
800 |
|
int y; |
801 |
|
COLR *scan; |
802 |
|
{ |
655 |
– |
static char *dp = NULL; |
803 |
|
static short cerr[ICONSIZ]; |
804 |
+ |
static int ynext; |
805 |
+ |
static char *dp; |
806 |
|
register int err; |
807 |
< |
register int x, xi; |
807 |
> |
register int x, ti; |
808 |
> |
int errp; |
809 |
|
|
810 |
|
if (iconheight == 0) { /* initialize */ |
811 |
< |
if (xmax < ICONSIZ && ymax < ICONSIZ) { |
811 |
> |
if (xmax <= ICONSIZ && ymax <= ICONSIZ) { |
812 |
|
iconwidth = xmax; |
813 |
|
iconheight = ymax; |
814 |
|
} else if (xmax > ymax) { |
815 |
|
iconwidth = ICONSIZ; |
816 |
|
iconheight = ICONSIZ*ymax/xmax; |
817 |
+ |
if (iconheight < 1) |
818 |
+ |
iconheight = 1; |
819 |
|
} else { |
820 |
|
iconwidth = ICONSIZ*xmax/ymax; |
821 |
+ |
if (iconwidth < 1) |
822 |
+ |
iconwidth = 1; |
823 |
|
iconheight = ICONSIZ; |
824 |
|
} |
825 |
+ |
ynext = 0; |
826 |
|
dp = icondata - 1; |
827 |
|
} |
828 |
< |
if (dp == NULL) /* done already */ |
828 |
> |
if (y < ynext*ymax/iconheight) /* skip this one */ |
829 |
|
return; |
675 |
– |
if (y % (ymax/iconheight)) /* skip this one */ |
676 |
– |
return; |
830 |
|
err = 0; |
831 |
|
for (x = 0; x < iconwidth; x++) { |
832 |
|
if (!(x&7)) |
833 |
|
*++dp = 0; |
834 |
< |
xi = x*xmax/iconwidth; |
835 |
< |
err += normbright(scan[xi]) + cerr[x]; |
834 |
> |
errp = err; |
835 |
> |
ti = x*xmax/iconwidth; |
836 |
> |
err += normbright(scan[ti]) + cerr[x]; |
837 |
|
if (err > 127) |
838 |
|
err -= 255; |
839 |
|
else |
840 |
|
*dp |= 1<<(x&07); |
841 |
< |
cerr[x] = err >>= 1; |
841 |
> |
err /= 3; |
842 |
> |
cerr[x] = err + errp; |
843 |
|
} |
844 |
< |
if (y >= ymax-ymax/iconheight) /* all done */ |
690 |
< |
dp = NULL; |
844 |
> |
ynext++; |
845 |
|
} |
846 |
|
|
847 |
|
|
848 |
|
getfull() /* get full (24-bit) data */ |
849 |
|
{ |
850 |
|
int y; |
851 |
+ |
register unsigned long *dp; |
852 |
+ |
register int x; |
853 |
+ |
/* set gamma correction */ |
854 |
+ |
setcolrgam(gamcor); |
855 |
+ |
/* read and convert file */ |
856 |
+ |
dp = (unsigned long *)ourdata; |
857 |
+ |
for (y = 0; y < ymax; y++) { |
858 |
+ |
if (getscan(y) < 0) |
859 |
+ |
quiterr("seek error in getfull"); |
860 |
+ |
if (scale) |
861 |
+ |
shiftcolrs(scanline, xmax, scale); |
862 |
+ |
colrs_gambs(scanline, xmax); |
863 |
+ |
add2icon(y, scanline); |
864 |
+ |
if (ourras->image->blue_mask & 1) |
865 |
+ |
for (x = 0; x < xmax; x++) |
866 |
+ |
*dp++ = scanline[x][RED] << 16 | |
867 |
+ |
scanline[x][GRN] << 8 | |
868 |
+ |
scanline[x][BLU] ; |
869 |
+ |
else |
870 |
+ |
for (x = 0; x < xmax; x++) |
871 |
+ |
*dp++ = scanline[x][RED] | |
872 |
+ |
scanline[x][GRN] << 8 | |
873 |
+ |
scanline[x][BLU] << 16 ; |
874 |
+ |
} |
875 |
+ |
} |
876 |
+ |
|
877 |
+ |
|
878 |
+ |
getgrey() /* get greyscale data */ |
879 |
+ |
{ |
880 |
+ |
int y; |
881 |
|
register unsigned char *dp; |
882 |
|
register int x; |
883 |
|
/* set gamma correction */ |
891 |
|
shiftcolrs(scanline, xmax, scale); |
892 |
|
colrs_gambs(scanline, xmax); |
893 |
|
add2icon(y, scanline); |
894 |
< |
for (x = 0; x < xmax; x++) { |
895 |
< |
*dp++ = scanline[x][RED]; |
896 |
< |
*dp++ = scanline[x][GRN]; |
897 |
< |
*dp++ = scanline[x][BLU]; |
898 |
< |
} |
894 |
> |
if (ourvis.colormap_size < 256) |
895 |
> |
for (x = 0; x < xmax; x++) |
896 |
> |
*dp++ = ((long)normbright(scanline[x]) * |
897 |
> |
ourvis.colormap_size + 128) >> 8; |
898 |
> |
else |
899 |
> |
for (x = 0; x < xmax; x++) |
900 |
> |
*dp++ = normbright(scanline[x]); |
901 |
|
} |
902 |
|
} |
903 |
|
|
993 |
|
picwritecm(map) /* handled elsewhere */ |
994 |
|
colormap map; |
995 |
|
{ |
996 |
< |
#ifdef DEBUG |
996 |
> |
#if 0 |
997 |
|
register int i; |
998 |
|
|
999 |
|
for (i = 0; i < 256; i++) |