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 |
|
|
38 |
|
|
39 |
|
#define BORWIDTH 5 /* border width */ |
40 |
|
|
41 |
+ |
#define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ |
42 |
+ |
|
43 |
|
#define ourscreen DefaultScreen(thedisplay) |
44 |
|
#define ourblack BlackPixel(thedisplay,ourscreen) |
45 |
|
#define ourwhite WhitePixel(thedisplay,ourscreen) |
46 |
|
#define ourroot RootWindow(thedisplay,ourscreen) |
47 |
|
#define ourgc DefaultGC(thedisplay,ourscreen) |
48 |
|
|
49 |
+ |
#define revline(x0,y0,x1,y1) XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1) |
50 |
+ |
|
51 |
+ |
#define redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras) |
52 |
+ |
|
53 |
|
double gamcor = 2.2; /* gamma correction */ |
54 |
|
|
55 |
|
int dither = 1; /* dither colors? */ |
58 |
|
Window wind = 0; /* our output window */ |
59 |
|
Font fontid; /* our font */ |
60 |
|
|
61 |
< |
long maxcolors = 0; /* maximum colors */ |
61 |
> |
int maxcolors = 0; /* maximum colors */ |
62 |
|
int greyscale = 0; /* in grey */ |
63 |
|
|
64 |
|
int scale = 0; /* scalefactor; power of two */ |
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 |
+ |
int wrongformat = 0; /* input in another format? */ |
85 |
+ |
|
86 |
+ |
GC revgc; /* graphics context with GXinvert */ |
87 |
+ |
|
88 |
|
XRASTER *ourras; /* our stored image */ |
89 |
|
unsigned char *ourdata; /* our image data */ |
90 |
|
|
94 |
|
|
95 |
|
char *geometry = NULL; /* geometry specification */ |
96 |
|
|
97 |
+ |
char icondata[ICONSIZ*ICONSIZ/8]; /* icon bitmap data */ |
98 |
+ |
int iconwidth = 0, iconheight = 0; |
99 |
+ |
|
100 |
|
char *progname; |
101 |
|
|
102 |
|
char errmsg[128]; |
105 |
|
|
106 |
|
extern char *malloc(), *calloc(); |
107 |
|
|
108 |
< |
extern double atof(), pow(), log(); |
108 |
> |
extern double pow(), log(); |
109 |
|
|
110 |
|
Display *thedisplay; |
111 |
|
|
150 |
|
default: |
151 |
|
goto userr; |
152 |
|
} |
153 |
+ |
else if (argv[i][0] == '=') |
154 |
+ |
geometry = argv[i]; |
155 |
|
else |
156 |
|
break; |
157 |
|
|
158 |
< |
if (argc-i == 1) { |
158 |
> |
if (i == argc-1) { |
159 |
|
fname = argv[i]; |
160 |
|
fin = fopen(fname, "r"); |
161 |
|
if (fin == NULL) { |
162 |
|
sprintf(errmsg, "can't open file \"%s\"", fname); |
163 |
|
quiterr(errmsg); |
164 |
|
} |
165 |
< |
} |
165 |
> |
} else if (i != argc) |
166 |
> |
goto userr; |
167 |
|
/* get header */ |
168 |
< |
getheader(fin, headline); |
168 |
> |
getheader(fin, headline, NULL); |
169 |
|
/* get picture dimensions */ |
170 |
< |
if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
171 |
< |
quiterr("bad picture size"); |
170 |
> |
if (wrongformat || !fgetsresolu(&inpres, fin)) |
171 |
> |
quiterr("bad picture format"); |
172 |
> |
xmax = scanlen(&inpres); |
173 |
> |
ymax = numscans(&inpres); |
174 |
|
/* set view parameters */ |
175 |
|
if (gotview && setview(&ourview) != NULL) |
176 |
|
gotview = 0; |
194 |
|
{ |
195 |
|
static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; |
196 |
|
register char **an; |
197 |
+ |
char fmt[32]; |
198 |
|
|
199 |
< |
if (!strncmp(s, "EXPOSURE=", 9)) |
200 |
< |
exposure *= atof(s+9); |
201 |
< |
else |
199 |
> |
if (isexpos(s)) |
200 |
> |
exposure *= exposval(s); |
201 |
> |
else if (isformat(s)) { |
202 |
> |
formatval(fmt, s); |
203 |
> |
wrongformat = strcmp(fmt, COLRFMT); |
204 |
> |
} else |
205 |
|
for (an = altname; *an != NULL; an++) |
206 |
|
if (!strncmp(*an, s, strlen(*an))) { |
207 |
< |
if (sscanview(&ourview, s+strlen(*an)) == 0) |
207 |
> |
if (sscanview(&ourview, s+strlen(*an)) > 0) |
208 |
|
gotview++; |
209 |
|
return; |
210 |
|
} |
213 |
|
|
214 |
|
init() /* get data and open window */ |
215 |
|
{ |
216 |
+ |
XWMHints ourxwmhints; |
217 |
+ |
XSetWindowAttributes ourwinattr; |
218 |
|
XSizeHints oursizhints; |
219 |
|
register int i; |
220 |
|
|
227 |
|
} |
228 |
|
if ((thedisplay = XOpenDisplay(NULL)) == NULL) |
229 |
|
quiterr("can't open display; DISPLAY variable set?"); |
204 |
– |
wind = XCreateSimpleWindow(thedisplay, |
205 |
– |
ourroot, 0, 0, xmax, ymax, BORWIDTH, ourblack, ourwhite); |
206 |
– |
if (wind == 0) |
207 |
– |
quiterr("can't create window"); |
230 |
|
if (maxcolors == 0) { /* get number of available colors */ |
231 |
< |
maxcolors = 1<<DisplayPlanes(thedisplay,ourscreen); |
231 |
> |
i = DisplayPlanes(thedisplay,ourscreen); |
232 |
> |
maxcolors = i > 8 ? 256 : 1<<i; |
233 |
|
if (maxcolors > 4) maxcolors -= 2; |
234 |
|
} |
235 |
+ |
/* store image */ |
236 |
+ |
getras(); |
237 |
+ |
/* open window */ |
238 |
+ |
ourwinattr.border_pixel = ourblack; |
239 |
+ |
ourwinattr.background_pixel = ourwhite; |
240 |
+ |
wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, |
241 |
+ |
0, InputOutput, ourras->visual, |
242 |
+ |
CWBackPixel|CWBorderPixel, &ourwinattr); |
243 |
+ |
if (wind == 0) |
244 |
+ |
quiterr("can't create window"); |
245 |
+ |
width = xmax; |
246 |
+ |
height = ymax; |
247 |
|
fontid = XLoadFont(thedisplay, FONTNAME); |
248 |
|
if (fontid == 0) |
249 |
|
quiterr("can't get font"); |
250 |
|
XSetFont(thedisplay, ourgc, fontid); |
251 |
< |
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
251 |
> |
revgc = XCreateGC(thedisplay, wind, 0, 0); |
252 |
> |
XSetFunction(thedisplay, revgc, GXinvert); |
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); |
260 |
< |
if (i & (XValue|YValue) == (XValue|YValue)) { |
259 |
> |
(unsigned *)&oursizhints.width, |
260 |
> |
(unsigned *)&oursizhints.height); |
261 |
> |
if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) |
262 |
> |
oursizhints.flags |= USSize; |
263 |
> |
else { |
264 |
> |
oursizhints.width = xmax; |
265 |
> |
oursizhints.height = ymax; |
266 |
> |
oursizhints.flags |= PSize; |
267 |
> |
} |
268 |
> |
if ((i&(XValue|YValue)) == (XValue|YValue)) { |
269 |
|
oursizhints.flags |= USPosition; |
270 |
|
if (i & XNegative) |
271 |
< |
oursizhints.x += DisplayWidth(thedisplay,ourscreen)-1; |
271 |
> |
oursizhints.x += DisplayWidth(thedisplay, |
272 |
> |
ourscreen)-1-oursizhints.width-2*BORWIDTH; |
273 |
|
if (i & YNegative) |
274 |
< |
oursizhints.y += DisplayHeight(thedisplay,ourscreen)-1; |
274 |
> |
oursizhints.y += DisplayHeight(thedisplay, |
275 |
> |
ourscreen)-1-oursizhints.height-2*BORWIDTH; |
276 |
|
} |
230 |
– |
if (i & (WidthValue|HeightValue) == (WidthValue|HeightValue)) |
231 |
– |
oursizhints.flags |= USSize; |
277 |
|
XSetNormalHints(thedisplay, wind, &oursizhints); |
278 |
|
} |
279 |
< |
/* store image */ |
280 |
< |
getras(); |
281 |
< |
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask| |
282 |
< |
StructureNotifyMask|ButtonMotionMask| |
283 |
< |
KeyPressMask|ExposureMask); |
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); |
287 |
|
XMapWindow(thedisplay, wind); |
288 |
|
return; |
289 |
|
memerr: |
319 |
|
getras() /* get raster file */ |
320 |
|
{ |
321 |
|
colormap ourmap; |
274 |
– |
unsigned char rmap[256], gmap[256], bmap[256]; |
322 |
|
XVisualInfo vinfo; |
276 |
– |
register int i; |
323 |
|
|
324 |
|
if (maxcolors <= 2) { /* monochrome */ |
325 |
|
ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8)); |
330 |
|
if (ourras == NULL) |
331 |
|
goto fail; |
332 |
|
getmono(); |
333 |
< |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo)) { |
333 |
> |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo) |
334 |
> |
/* kludge for DirectColor */ |
335 |
> |
|| XMatchVisualInfo(thedisplay,ourscreen,24,DirectColor,&vinfo)) { |
336 |
|
ourdata = (unsigned char *)malloc(xmax*ymax*3); |
337 |
|
if (ourdata == NULL) |
338 |
|
goto fail; |
353 |
|
biq(dither,maxcolors,1,ourmap); |
354 |
|
else |
355 |
|
ciq(dither,maxcolors,1,ourmap); |
356 |
< |
for (i = 0; i < 256; i++) { |
309 |
< |
rmap[i] = ourmap[0][i]; |
310 |
< |
gmap[i] = ourmap[1][i]; |
311 |
< |
bmap[i] = ourmap[2][i]; |
312 |
< |
} |
313 |
< |
if (init_rcolors(ourras, rmap, gmap, bmap) == 0) |
356 |
> |
if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0) |
357 |
|
goto fail; |
358 |
|
} |
359 |
|
return; |
360 |
|
fail: |
361 |
< |
quit("could not create raster image"); |
361 |
> |
quiterr("could not create raster image"); |
362 |
|
} |
363 |
|
|
364 |
|
|
402 |
|
} |
403 |
|
|
404 |
|
|
362 |
– |
redraw(x, y, w, h) /* redraw section of window */ |
363 |
– |
int x, y; |
364 |
– |
int w, h; |
365 |
– |
{ |
366 |
– |
patch_raster(wind,x-xoff,y-yoff,x,y,w,h,ourras); |
367 |
– |
} |
368 |
– |
|
369 |
– |
|
405 |
|
docom(ekey) /* execute command */ |
406 |
|
XKeyPressedEvent *ekey; |
407 |
|
{ |
410 |
|
XColor cvx; |
411 |
|
int com, n; |
412 |
|
double comp; |
413 |
+ |
FLOAT hv[2]; |
414 |
|
FVECT rorg, rdir; |
415 |
|
|
416 |
|
n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); |
433 |
|
sprintf(buf, "%.3f", intens(cval)/exposure); |
434 |
|
break; |
435 |
|
case 'l': /* luminance */ |
436 |
< |
sprintf(buf, "%.0fn", bright(cval)*683.0/exposure); |
436 |
> |
sprintf(buf, "%.0fL", luminance(cval)/exposure); |
437 |
|
break; |
438 |
|
case 'c': /* color */ |
439 |
|
comp = pow(2.0, (double)scale); |
443 |
|
colval(cval,BLU)*comp); |
444 |
|
break; |
445 |
|
} |
446 |
< |
XDrawImageString(thedisplay, wind, ourgc, box.xmin, box.ymin, |
447 |
< |
buf, strlen(buf)); |
446 |
> |
XDrawImageString(thedisplay, wind, ourgc, |
447 |
> |
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
448 |
|
return(0); |
449 |
|
case 'i': /* identify (contour) */ |
450 |
|
if (ourras->pixels == NULL) |
455 |
|
cvx.red = random() & 65535; |
456 |
|
cvx.green = random() & 65535; |
457 |
|
cvx.blue = random() & 65535; |
458 |
< |
XStoreColors(thedisplay, ourras->cmap, &cvx, 1); |
458 |
> |
cvx.flags = DoRed|DoGreen|DoBlue; |
459 |
> |
XStoreColor(thedisplay, ourras->cmap, &cvx); |
460 |
|
return(0); |
461 |
|
case 'p': /* position */ |
462 |
< |
sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff); |
462 |
> |
pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); |
463 |
> |
sprintf(buf, "(%d,%d)", (int)(hv[0]*inpres.xr), |
464 |
> |
(int)(hv[1]*inpres.yr)); |
465 |
|
XDrawImageString(thedisplay, wind, ourgc, ekey->x, ekey->y, |
466 |
|
buf, strlen(buf)); |
467 |
|
return(0); |
470 |
|
XBell(thedisplay, 0); |
471 |
|
return(-1); |
472 |
|
} |
473 |
< |
viewray(rorg, rdir, &ourview, |
474 |
< |
(ekey->x-xoff+.5)/xmax, |
475 |
< |
(ymax-1-ekey->y+yoff+.5)/ymax); |
473 |
> |
pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); |
474 |
> |
if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
475 |
> |
return(-1); |
476 |
|
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
477 |
|
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
478 |
|
fflush(stdout); |
486 |
|
scale_rcolors(ourras, pow(2.0, (double)n)); |
487 |
|
scale += n; |
488 |
|
sprintf(buf, "%+d", scale); |
489 |
< |
XDrawImageString(thedisplay, wind, ourgc, box.xmin, box.ymin, |
490 |
< |
buf, strlen(buf)); |
489 |
> |
XDrawImageString(thedisplay, wind, ourgc, |
490 |
> |
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
491 |
|
XFlush(thedisplay); |
492 |
|
free(ourdata); |
493 |
|
free_raster(ourras); |
506 |
|
redraw(box.xmin, box.ymin, box.xsiz, box.ysiz); |
507 |
|
return(0); |
508 |
|
default: |
509 |
< |
XBell(0); |
509 |
> |
XBell(thedisplay, 0); |
510 |
|
return(-1); |
511 |
|
} |
512 |
|
} |
513 |
|
|
514 |
|
|
515 |
< |
moveimage(ep) /* shift the image */ |
516 |
< |
XButtonPressedEvent *ep; |
515 |
> |
moveimage(ebut) /* shift the image */ |
516 |
> |
XButtonPressedEvent *ebut; |
517 |
|
{ |
518 |
< |
XButtonPressedEvent eb; |
518 |
> |
union { |
519 |
> |
XEvent u; |
520 |
> |
XButtonReleasedEvent b; |
521 |
> |
XPointerMovedEvent m; |
522 |
> |
} e; |
523 |
> |
int mxo, myo; |
524 |
|
|
525 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask, &eb); |
526 |
< |
xoff += eb.x - ep->x; |
527 |
< |
yoff += eb.y - ep->y; |
525 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
526 |
> |
while (e.u.type == MotionNotify) { |
527 |
> |
mxo = e.m.x; |
528 |
> |
myo = e.m.y; |
529 |
> |
revline(ebut->x, ebut->y, mxo, myo); |
530 |
> |
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
531 |
> |
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
532 |
> |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
533 |
> |
revline(ebut->x, ebut->y, mxo, myo); |
534 |
> |
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
535 |
> |
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
536 |
> |
} |
537 |
> |
xoff += e.b.x - ebut->x; |
538 |
> |
yoff += e.b.y - ebut->y; |
539 |
|
XClearWindow(thedisplay, wind); |
540 |
|
redraw(0, 0, width, height); |
486 |
– |
return(0); |
541 |
|
} |
542 |
|
|
543 |
|
|
545 |
|
XButtonPressedEvent *ebut; |
546 |
|
{ |
547 |
|
union { |
548 |
< |
XEvent e; |
548 |
> |
XEvent u; |
549 |
|
XButtonReleasedEvent b; |
550 |
|
XPointerMovedEvent m; |
551 |
|
} e; |
552 |
|
|
553 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.e); |
554 |
< |
while (e.e.type == ButtonMotionMask) { |
553 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
554 |
> |
while (e.u.type == MotionNotify) { |
555 |
|
revbox(ebut->x, ebut->y, box.xmin = e.m.x, box.ymin = e.m.y); |
556 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, |
503 |
< |
&e.e); |
556 |
> |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
557 |
|
revbox(ebut->x, ebut->y, box.xmin, box.ymin); |
558 |
|
} |
559 |
|
box.xmin = e.b.x<0 ? 0 : (e.b.x>=width ? width-1 : e.b.x); |
576 |
|
revbox(x0, y0, x1, y1) /* draw box with reversed lines */ |
577 |
|
int x0, y0, x1, y1; |
578 |
|
{ |
579 |
< |
static GC mygc = 0; |
579 |
> |
revline(x0, y0, x1, y0); |
580 |
> |
revline(x0, y1, x1, y1); |
581 |
> |
revline(x0, y0, x0, y1); |
582 |
> |
revline(x1, y0, x1, y1); |
583 |
> |
} |
584 |
|
|
528 |
– |
if (mygc == 0) { |
529 |
– |
mygc = XCreateGC(thedisplay, wind, 0, 0); |
530 |
– |
XSetPlaneMask(thedisplay, mygc, ~0L); |
531 |
– |
XSetFunction(thedisplay, mygc, GXinvert); |
532 |
– |
} |
533 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y0, x1, y0); |
534 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y1, x1, y1); |
535 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y0, x0, y1); |
536 |
– |
XDrawLine(thedisplay, wind, mygc, x1, y0, x1, y1); |
537 |
– |
} /* end of revbox */ |
585 |
|
|
539 |
– |
|
586 |
|
avgbox(clr) /* average color over current box */ |
587 |
|
COLOR clr; |
588 |
|
{ |
589 |
+ |
static COLOR lc; |
590 |
+ |
static int ll, lr, lt, lb; |
591 |
|
int left, right, top, bottom; |
592 |
|
int y; |
593 |
|
double d; |
611 |
|
bottom = ymax; |
612 |
|
if (top >= bottom) |
613 |
|
return(-1); |
614 |
+ |
if (left == ll && right == lr && top == lt && bottom == lb) { |
615 |
+ |
copycolor(clr, lc); |
616 |
+ |
return; |
617 |
+ |
} |
618 |
|
for (y = top; y < bottom; y++) { |
619 |
|
if (getscan(y) == -1) |
620 |
|
return(-1); |
625 |
|
} |
626 |
|
d = 1.0/((right-left)*(bottom-top)); |
627 |
|
scalecolor(clr, d); |
628 |
+ |
ll = left; lr = right; lt = top; lb = bottom; |
629 |
+ |
copycolor(lc, clr); |
630 |
|
return(0); |
631 |
|
} |
632 |
|
|
635 |
|
{ |
636 |
|
register unsigned char *dp; |
637 |
|
register int x, err; |
638 |
< |
int y; |
585 |
< |
rgbpixel *inline; |
638 |
> |
int y, errp; |
639 |
|
short *cerr; |
640 |
|
|
641 |
< |
if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
642 |
< |
|| (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
590 |
< |
quit("out of memory in getmono"); |
641 |
> |
if ((cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
642 |
> |
quiterr("out of memory in getmono"); |
643 |
|
dp = ourdata - 1; |
644 |
|
for (y = 0; y < ymax; y++) { |
645 |
< |
picreadline3(y, inline); |
645 |
> |
if (getscan(y) < 0) |
646 |
> |
quiterr("seek error in getmono"); |
647 |
> |
normcolrs(scanline, xmax, scale); |
648 |
> |
add2icon(y, scanline); |
649 |
|
err = 0; |
650 |
|
for (x = 0; x < xmax; x++) { |
651 |
|
if (!(x&7)) |
652 |
|
*++dp = 0; |
653 |
< |
err += rgb_bright(&inline[x]) + cerr[x]; |
653 |
> |
errp = err; |
654 |
> |
err += normbright(scanline[x]) + cerr[x]; |
655 |
|
if (err > 127) |
656 |
|
err -= 255; |
657 |
|
else |
658 |
< |
*dp |= 1<<(x&07); |
659 |
< |
cerr[x] = err >>= 1; |
658 |
> |
*dp |= 1<<(7-(x&07)); |
659 |
> |
err /= 3; |
660 |
> |
cerr[x] = err + errp; |
661 |
|
} |
662 |
|
} |
606 |
– |
free((char *)inline); |
663 |
|
free((char *)cerr); |
664 |
|
} |
665 |
|
|
666 |
|
|
667 |
+ |
add2icon(y, scan) /* add a scanline to our icon data */ |
668 |
+ |
int y; |
669 |
+ |
COLR *scan; |
670 |
+ |
{ |
671 |
+ |
static short cerr[ICONSIZ]; |
672 |
+ |
static int ynext; |
673 |
+ |
static char *dp; |
674 |
+ |
register int err; |
675 |
+ |
register int x, ti; |
676 |
+ |
int errp; |
677 |
+ |
|
678 |
+ |
if (iconheight == 0) { /* initialize */ |
679 |
+ |
if (xmax <= ICONSIZ && ymax <= ICONSIZ) { |
680 |
+ |
iconwidth = xmax; |
681 |
+ |
iconheight = ymax; |
682 |
+ |
} else if (xmax > ymax) { |
683 |
+ |
iconwidth = ICONSIZ; |
684 |
+ |
iconheight = ICONSIZ*ymax/xmax; |
685 |
+ |
if (iconheight < 1) |
686 |
+ |
iconheight = 1; |
687 |
+ |
} else { |
688 |
+ |
iconwidth = ICONSIZ*xmax/ymax; |
689 |
+ |
if (iconwidth < 1) |
690 |
+ |
iconwidth = 1; |
691 |
+ |
iconheight = ICONSIZ; |
692 |
+ |
} |
693 |
+ |
ynext = 0; |
694 |
+ |
dp = icondata - 1; |
695 |
+ |
} |
696 |
+ |
if (y < ynext*ymax/iconheight) /* skip this one */ |
697 |
+ |
return; |
698 |
+ |
err = 0; |
699 |
+ |
for (x = 0; x < iconwidth; x++) { |
700 |
+ |
if (!(x&7)) |
701 |
+ |
*++dp = 0; |
702 |
+ |
errp = err; |
703 |
+ |
ti = x*xmax/iconwidth; |
704 |
+ |
err += normbright(scan[ti]) + cerr[x]; |
705 |
+ |
if (err > 127) |
706 |
+ |
err -= 255; |
707 |
+ |
else |
708 |
+ |
*dp |= 1<<(x&07); |
709 |
+ |
err /= 3; |
710 |
+ |
cerr[x] = err + errp; |
711 |
+ |
} |
712 |
+ |
ynext++; |
713 |
+ |
} |
714 |
+ |
|
715 |
+ |
|
716 |
|
getfull() /* get full (24-bit) data */ |
717 |
|
{ |
718 |
|
int y; |
719 |
< |
|
720 |
< |
for (y = 0; y < ymax; y++) |
721 |
< |
picreadline3(y, (rgbpixel *)(ourdata+y*xmax*3)); |
719 |
> |
register unsigned char *dp; |
720 |
> |
register int x; |
721 |
> |
/* set gamma correction */ |
722 |
> |
setcolrgam(gamcor); |
723 |
> |
/* read and convert file */ |
724 |
> |
dp = ourdata; |
725 |
> |
for (y = 0; y < ymax; y++) { |
726 |
> |
if (getscan(y) < 0) |
727 |
> |
quiterr("seek error in getfull"); |
728 |
> |
if (scale) |
729 |
> |
shiftcolrs(scanline, xmax, scale); |
730 |
> |
colrs_gambs(scanline, xmax); |
731 |
> |
add2icon(y, scanline); |
732 |
> |
for (x = 0; x < xmax; x++) { |
733 |
> |
*dp++ = scanline[x][RED]; |
734 |
> |
*dp++ = scanline[x][GRN]; |
735 |
> |
*dp++ = scanline[x][BLU]; |
736 |
> |
} |
737 |
> |
} |
738 |
|
} |
739 |
|
|
740 |
|
|
773 |
|
if (scanpos == NULL || scanpos[y] == -1) |
774 |
|
return(-1); |
775 |
|
if (fseek(fin, scanpos[y], 0) == -1) |
776 |
< |
quit("fseek error"); |
776 |
> |
quiterr("fseek error"); |
777 |
|
cury = y; |
778 |
|
} else if (scanpos != NULL) |
779 |
|
scanpos[y] = ftell(fin); |
796 |
|
quiterr("cannot seek for picreadline"); |
797 |
|
/* convert scanline */ |
798 |
|
normcolrs(scanline, xmax, scale); |
799 |
+ |
add2icon(y, scanline); |
800 |
|
for (i = 0; i < xmax; i++) { |
801 |
|
l3[i].r = scanline[i][RED]; |
802 |
|
l3[i].g = scanline[i][GRN]; |
820 |
|
register int i, val; |
821 |
|
|
822 |
|
for (i = 0; i < 256; i++) { |
823 |
< |
val = pow(i/256.0, 1.0/gamcor) * 256.0; |
823 |
> |
val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; |
824 |
|
map[0][i] = map[1][i] = map[2][i] = val; |
825 |
|
} |
826 |
|
} |