1 |
< |
/* Copyright (c) 1990 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1993 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
24 |
|
#include <X11/Xlib.h> |
25 |
|
#include <X11/cursorfont.h> |
26 |
|
#include <X11/Xutil.h> |
27 |
+ |
#include <X11/Xatom.h> |
28 |
|
|
29 |
|
#include "color.h" |
30 |
|
#include "view.h" |
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 |
|
|
52 |
|
int dither = 1; /* dither colors? */ |
53 |
|
int fast = 0; /* keep picture in Pixmap? */ |
54 |
|
|
55 |
< |
Window wind = 0; /* our output window */ |
56 |
< |
Font fontid; /* our font */ |
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 |
|
int maxcolors = 0; /* maximum colors */ |
60 |
|
int greyscale = 0; /* in grey */ |
61 |
|
|
69 |
|
|
70 |
|
COLR *scanline; /* scan line buffer */ |
71 |
|
|
72 |
< |
int xmax, ymax; /* picture resolution */ |
72 |
> |
RESOLU inpres; /* input resolution and ordering */ |
73 |
> |
int xmax, ymax; /* picture dimensions */ |
74 |
|
int width, height; /* window size */ |
75 |
|
char *fname = NULL; /* input file name */ |
76 |
|
FILE *fin = stdin; /* input file */ |
79 |
|
|
80 |
|
double exposure = 1.0; /* exposure compensation used */ |
81 |
|
|
82 |
+ |
int wrongformat = 0; /* input in another format? */ |
83 |
+ |
|
84 |
+ |
GC ourgc; /* standard graphics context */ |
85 |
|
GC revgc; /* graphics context with GXinvert */ |
86 |
|
|
87 |
< |
XRASTER *ourras; /* our stored image */ |
87 |
> |
int *ourrank; /* our visual class ranking */ |
88 |
> |
XVisualInfo ourvis; /* our visual */ |
89 |
> |
XRASTER *ourras; /* our stored image */ |
90 |
|
unsigned char *ourdata; /* our image data */ |
91 |
|
|
92 |
|
struct { |
95 |
|
|
96 |
|
char *geometry = NULL; /* geometry specification */ |
97 |
|
|
98 |
+ |
char icondata[ICONSIZ*ICONSIZ/8]; /* icon bitmap data */ |
99 |
+ |
int iconwidth = 0, iconheight = 0; |
100 |
+ |
|
101 |
|
char *progname; |
102 |
|
|
103 |
|
char errmsg[128]; |
104 |
|
|
105 |
+ |
extern BYTE clrtab[256][3]; /* global color map */ |
106 |
+ |
|
107 |
|
extern long ftell(); |
108 |
|
|
97 |
– |
extern char *malloc(), *calloc(); |
98 |
– |
|
99 |
– |
extern double atof(), pow(), log(); |
100 |
– |
|
109 |
|
Display *thedisplay; |
110 |
+ |
Atom closedownAtom, wmProtocolsAtom; |
111 |
|
|
112 |
+ |
|
113 |
|
main(argc, argv) |
114 |
|
int argc; |
115 |
|
char *argv[]; |
116 |
|
{ |
117 |
+ |
extern char *getenv(); |
118 |
+ |
char *gv; |
119 |
|
int headline(); |
120 |
|
int i; |
121 |
|
|
122 |
|
progname = argv[0]; |
123 |
+ |
if ((gv = getenv("GAMMA")) != NULL) |
124 |
+ |
gamcor = atof(gv); |
125 |
|
|
126 |
|
for (i = 1; i < argc; i++) |
127 |
|
if (argv[i][0] == '-') |
136 |
|
maxcolors = 2; |
137 |
|
break; |
138 |
|
case 'd': |
139 |
< |
dither = !dither; |
139 |
> |
if (argv[i][2] == 'i') |
140 |
> |
dispname = argv[++i]; |
141 |
> |
else |
142 |
> |
dither = !dither; |
143 |
|
break; |
144 |
|
case 'f': |
145 |
|
fast = !fast; |
150 |
|
scale = atoi(argv[++i]); |
151 |
|
break; |
152 |
|
case 'g': |
153 |
< |
if (!strcmp(argv[i], "-geometry")) |
153 |
> |
if (argv[i][2] == 'e') |
154 |
|
geometry = argv[++i]; |
155 |
|
else |
156 |
|
gamcor = atof(argv[++i]); |
167 |
|
fname = argv[i]; |
168 |
|
fin = fopen(fname, "r"); |
169 |
|
if (fin == NULL) { |
170 |
< |
sprintf(errmsg, "can't open file \"%s\"", fname); |
170 |
> |
sprintf(errmsg, "cannot open file \"%s\"", fname); |
171 |
|
quiterr(errmsg); |
172 |
|
} |
173 |
|
} else if (i != argc) |
174 |
|
goto userr; |
175 |
|
/* get header */ |
176 |
< |
getheader(fin, headline); |
176 |
> |
getheader(fin, headline, NULL); |
177 |
|
/* get picture dimensions */ |
178 |
< |
if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
179 |
< |
quiterr("bad picture size"); |
178 |
> |
if (wrongformat || !fgetsresolu(&inpres, fin)) |
179 |
> |
quiterr("bad picture format"); |
180 |
> |
xmax = scanlen(&inpres); |
181 |
> |
ymax = numscans(&inpres); |
182 |
|
/* set view parameters */ |
183 |
|
if (gotview && setview(&ourview) != NULL) |
184 |
|
gotview = 0; |
185 |
|
if ((scanline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) |
186 |
|
quiterr("out of memory"); |
187 |
|
|
188 |
< |
init(); /* get file and open window */ |
188 |
> |
init(argc, argv); /* get file and open window */ |
189 |
|
|
190 |
|
for ( ; ; ) |
191 |
|
getevent(); /* main loop */ |
192 |
|
userr: |
193 |
|
fprintf(stderr, |
194 |
< |
"Usage: %s [-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
194 |
> |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic\n", |
195 |
|
progname); |
196 |
< |
quit(1); |
196 |
> |
exit(1); |
197 |
|
} |
198 |
|
|
199 |
|
|
200 |
|
headline(s) /* get relevant info from header */ |
201 |
|
char *s; |
202 |
|
{ |
203 |
< |
static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; |
185 |
< |
register char **an; |
203 |
> |
char fmt[32]; |
204 |
|
|
205 |
|
if (isexpos(s)) |
206 |
|
exposure *= exposval(s); |
207 |
< |
else |
208 |
< |
for (an = altname; *an != NULL; an++) |
209 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
210 |
< |
if (sscanview(&ourview, s+strlen(*an)) > 0) |
211 |
< |
gotview++; |
194 |
< |
return; |
195 |
< |
} |
207 |
> |
else if (isformat(s)) { |
208 |
> |
formatval(fmt, s); |
209 |
> |
wrongformat = strcmp(fmt, COLRFMT); |
210 |
> |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
211 |
> |
gotview++; |
212 |
|
} |
213 |
|
|
214 |
|
|
215 |
< |
init() /* get data and open window */ |
215 |
> |
init(argc, argv) /* get data and open window */ |
216 |
> |
int argc; |
217 |
> |
char **argv; |
218 |
|
{ |
219 |
|
XSetWindowAttributes ourwinattr; |
220 |
< |
XSizeHints oursizhints; |
221 |
< |
register int i; |
220 |
> |
XClassHint xclshints; |
221 |
> |
XWMHints xwmhints; |
222 |
> |
XSizeHints xszhints; |
223 |
> |
XTextProperty windowName, iconName; |
224 |
> |
XGCValues xgcv; |
225 |
> |
char *name; |
226 |
> |
register int i; |
227 |
|
|
228 |
|
if (fname != NULL) { |
229 |
|
scanpos = (long *)malloc(ymax*sizeof(long)); |
230 |
|
if (scanpos == NULL) |
231 |
< |
goto memerr; |
231 |
> |
quiterr("out of memory"); |
232 |
|
for (i = 0; i < ymax; i++) |
233 |
|
scanpos[i] = -1; |
234 |
< |
} |
235 |
< |
if ((thedisplay = XOpenDisplay(NULL)) == NULL) |
236 |
< |
quiterr("can't open display; DISPLAY variable set?"); |
237 |
< |
if (maxcolors == 0) { /* get number of available colors */ |
238 |
< |
i = DisplayPlanes(thedisplay,ourscreen); |
239 |
< |
maxcolors = i > 8 ? 256 : 1<<i; |
240 |
< |
if (maxcolors > 4) maxcolors -= 2; |
241 |
< |
} |
234 |
> |
name = fname; |
235 |
> |
} else |
236 |
> |
name = progname; |
237 |
> |
/* remove directory prefix from name */ |
238 |
> |
for (i = strlen(name); i-- > 0; ) |
239 |
> |
if (name[i] == '/') |
240 |
> |
break; |
241 |
> |
name += i+1; |
242 |
> |
if ((thedisplay = XOpenDisplay(dispname)) == NULL) |
243 |
> |
quiterr("cannot open display"); |
244 |
> |
/* get best visual for default screen */ |
245 |
> |
getbestvis(); |
246 |
|
/* store image */ |
247 |
|
getras(); |
248 |
< |
/* open window */ |
249 |
< |
ourwinattr.border_pixel = ourblack; |
250 |
< |
ourwinattr.background_pixel = ourwhite; |
224 |
< |
wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, |
225 |
< |
0, InputOutput, ourras->visual, |
226 |
< |
CWBackPixel|CWBorderPixel, &ourwinattr); |
227 |
< |
if (wind == 0) |
228 |
< |
quiterr("can't create window"); |
229 |
< |
width = xmax; |
230 |
< |
height = ymax; |
231 |
< |
fontid = XLoadFont(thedisplay, FONTNAME); |
232 |
< |
if (fontid == 0) |
233 |
< |
quiterr("can't get font"); |
234 |
< |
XSetFont(thedisplay, ourgc, fontid); |
235 |
< |
revgc = XCreateGC(thedisplay, wind, 0, 0); |
236 |
< |
XSetFunction(thedisplay, revgc, GXinvert); |
237 |
< |
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
238 |
< |
XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, |
239 |
< |
XC_diamond_cross)); |
248 |
> |
/* get size and position */ |
249 |
> |
xszhints.flags = 0; |
250 |
> |
xszhints.width = xmax; xszhints.height = ymax; |
251 |
|
if (geometry != NULL) { |
252 |
< |
bzero((char *)&oursizhints, sizeof(oursizhints)); |
253 |
< |
i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, |
254 |
< |
&oursizhints.width, &oursizhints.height); |
252 |
> |
i = XParseGeometry(geometry, &xszhints.x, &xszhints.y, |
253 |
> |
(unsigned *)&xszhints.width, |
254 |
> |
(unsigned *)&xszhints.height); |
255 |
|
if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) |
256 |
< |
oursizhints.flags |= USSize; |
257 |
< |
else { |
258 |
< |
oursizhints.width = xmax; |
248 |
< |
oursizhints.height = ymax; |
249 |
< |
oursizhints.flags |= PSize; |
250 |
< |
} |
256 |
> |
xszhints.flags |= USSize; |
257 |
> |
else |
258 |
> |
xszhints.flags |= PSize; |
259 |
|
if ((i&(XValue|YValue)) == (XValue|YValue)) { |
260 |
< |
oursizhints.flags |= USPosition; |
260 |
> |
xszhints.flags |= USPosition; |
261 |
|
if (i & XNegative) |
262 |
< |
oursizhints.x += DisplayWidth(thedisplay, |
263 |
< |
ourscreen)-1-oursizhints.width-2*BORWIDTH; |
262 |
> |
xszhints.x += DisplayWidth(thedisplay, |
263 |
> |
ourscreen)-1-xszhints.width-2*BORWIDTH; |
264 |
|
if (i & YNegative) |
265 |
< |
oursizhints.y += DisplayHeight(thedisplay, |
266 |
< |
ourscreen)-1-oursizhints.height-2*BORWIDTH; |
265 |
> |
xszhints.y += DisplayHeight(thedisplay, |
266 |
> |
ourscreen)-1-xszhints.height-2*BORWIDTH; |
267 |
|
} |
260 |
– |
XSetNormalHints(thedisplay, wind, &oursizhints); |
268 |
|
} |
269 |
< |
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |
270 |
< |
|ButtonMotionMask|StructureNotifyMask |
271 |
< |
|KeyPressMask|ExposureMask); |
269 |
> |
/* open window */ |
270 |
> |
ourwinattr.border_pixel = ourwhite; |
271 |
> |
ourwinattr.background_pixel = ourblack; |
272 |
> |
ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, |
273 |
> |
ourvis.visual, AllocNone); |
274 |
> |
ourwinattr.event_mask = ExposureMask|KeyPressMask|ButtonPressMask| |
275 |
> |
ButtonReleaseMask|ButtonMotionMask|StructureNotifyMask; |
276 |
> |
ourwinattr.cursor = XCreateFontCursor(thedisplay, XC_diamond_cross); |
277 |
> |
wind = XCreateWindow(thedisplay, ourroot, xszhints.x, xszhints.y, |
278 |
> |
xszhints.width, xszhints.height, BORWIDTH, |
279 |
> |
ourvis.depth, InputOutput, ourvis.visual, CWEventMask| |
280 |
> |
CWCursor|CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
281 |
> |
if (wind == 0) |
282 |
> |
quiterr("cannot create window"); |
283 |
> |
width = xmax; |
284 |
> |
height = ymax; |
285 |
> |
xgcv.foreground = ourblack; |
286 |
> |
xgcv.background = ourwhite; |
287 |
> |
if ((xgcv.font = XLoadFont(thedisplay, FONTNAME)) == 0) |
288 |
> |
quiterr("cannot get font"); |
289 |
> |
ourgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground| |
290 |
> |
GCFont, &xgcv); |
291 |
> |
xgcv.function = GXinvert; |
292 |
> |
revgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground| |
293 |
> |
GCFunction, &xgcv); |
294 |
> |
|
295 |
> |
/* set up the window manager */ |
296 |
> |
xwmhints.flags = InputHint|IconPixmapHint; |
297 |
> |
xwmhints.input = True; |
298 |
> |
xwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, |
299 |
> |
wind, icondata, iconwidth, iconheight); |
300 |
> |
|
301 |
> |
windowName.encoding = iconName.encoding = XA_STRING; |
302 |
> |
windowName.format = iconName.format = 8; |
303 |
> |
windowName.value = (u_char *)name; |
304 |
> |
windowName.nitems = strlen(windowName.value); |
305 |
> |
iconName.value = (u_char *)name; |
306 |
> |
iconName.nitems = strlen(windowName.value); |
307 |
> |
|
308 |
> |
xclshints.res_name = NULL; |
309 |
> |
xclshints.res_class = "Ximage"; |
310 |
> |
XSetWMProperties(thedisplay, wind, &windowName, &iconName, |
311 |
> |
argv, argc, &xszhints, &xwmhints, &xclshints); |
312 |
> |
closedownAtom = XInternAtom(thedisplay, "WM_DELETE_WINDOW", False); |
313 |
> |
wmProtocolsAtom = XInternAtom(thedisplay, "WM_PROTOCOLS", False); |
314 |
> |
XSetWMProtocols(thedisplay, wind, &closedownAtom, 1); |
315 |
> |
|
316 |
|
XMapWindow(thedisplay, wind); |
317 |
|
return; |
267 |
– |
memerr: |
268 |
– |
quiterr("out of memory"); |
318 |
|
} /* end of init */ |
319 |
|
|
320 |
|
|
329 |
|
} |
330 |
|
|
331 |
|
|
332 |
< |
eputs(s) |
333 |
< |
char *s; |
332 |
> |
static int |
333 |
> |
viscmp(v1,v2) /* compare visual to see which is better, descending */ |
334 |
> |
register XVisualInfo *v1, *v2; |
335 |
|
{ |
336 |
< |
fputs(s, stderr); |
336 |
> |
int bad1 = 0, bad2 = 0; |
337 |
> |
register int *rp; |
338 |
> |
|
339 |
> |
if (v1->class == v2->class) { |
340 |
> |
if (v1->class == TrueColor || v1->class == DirectColor) { |
341 |
> |
/* prefer 24-bit to 32-bit */ |
342 |
> |
if (v1->depth == 24 && v2->depth == 32) |
343 |
> |
return(-1); |
344 |
> |
if (v1->depth == 32 && v2->depth == 24) |
345 |
> |
return(1); |
346 |
> |
return(0); |
347 |
> |
} |
348 |
> |
/* don't be too greedy */ |
349 |
> |
if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth) |
350 |
> |
return(v1->depth - v2->depth); |
351 |
> |
return(v2->depth - v1->depth); |
352 |
> |
} |
353 |
> |
/* prefer Pseudo when < 24-bit */ |
354 |
> |
if ((v1->class == TrueColor || v1->class == DirectColor) && |
355 |
> |
v1->depth < 24) |
356 |
> |
bad1 = 1; |
357 |
> |
if ((v2->class == TrueColor || v2->class == DirectColor) && |
358 |
> |
v2->depth < 24) |
359 |
> |
bad2 = -1; |
360 |
> |
if (bad1 | bad2) |
361 |
> |
return(bad1+bad2); |
362 |
> |
/* otherwise, use class ranking */ |
363 |
> |
for (rp = ourrank; *rp != -1; rp++) { |
364 |
> |
if (v1->class == *rp) |
365 |
> |
return(-1); |
366 |
> |
if (v2->class == *rp) |
367 |
> |
return(1); |
368 |
> |
} |
369 |
> |
return(0); |
370 |
|
} |
371 |
|
|
372 |
|
|
373 |
< |
quit(code) |
291 |
< |
int code; |
373 |
> |
getbestvis() /* get the best visual for this screen */ |
374 |
|
{ |
375 |
< |
exit(code); |
375 |
> |
#ifdef DEBUG |
376 |
> |
static char vistype[][12] = { |
377 |
> |
"StaticGray", |
378 |
> |
"GrayScale", |
379 |
> |
"StaticColor", |
380 |
> |
"PseudoColor", |
381 |
> |
"TrueColor", |
382 |
> |
"DirectColor" |
383 |
> |
}; |
384 |
> |
#endif |
385 |
> |
static int rankings[3][6] = { |
386 |
> |
{TrueColor,DirectColor,PseudoColor,GrayScale,StaticGray,-1}, |
387 |
> |
{PseudoColor,GrayScale,StaticGray,-1}, |
388 |
> |
{PseudoColor,GrayScale,StaticGray,-1} |
389 |
> |
}; |
390 |
> |
XVisualInfo *xvi; |
391 |
> |
int vismatched; |
392 |
> |
register int i, j; |
393 |
> |
|
394 |
> |
if (greyscale) { |
395 |
> |
ourrank = rankings[2]; |
396 |
> |
if (maxcolors < 2) maxcolors = 256; |
397 |
> |
} else if (maxcolors >= 2 && maxcolors <= 256) |
398 |
> |
ourrank = rankings[1]; |
399 |
> |
else { |
400 |
> |
ourrank = rankings[0]; |
401 |
> |
maxcolors = 256; |
402 |
> |
} |
403 |
> |
/* find best visual */ |
404 |
> |
ourvis.screen = ourscreen; |
405 |
> |
xvi = XGetVisualInfo(thedisplay,VisualScreenMask,&ourvis,&vismatched); |
406 |
> |
if (xvi == NULL) |
407 |
> |
quiterr("no visuals for this screen!"); |
408 |
> |
#ifdef DEBUG |
409 |
> |
fprintf(stderr, "Supported visuals:\n"); |
410 |
> |
for (i = 0; i < vismatched; i++) |
411 |
> |
fprintf(stderr, "\ttype %s, depth %d\n", |
412 |
> |
vistype[xvi[i].class], xvi[i].depth); |
413 |
> |
#endif |
414 |
> |
for (i = 0, j = 1; j < vismatched; j++) |
415 |
> |
if (viscmp(&xvi[i],&xvi[j]) > 0) |
416 |
> |
i = j; |
417 |
> |
/* compare to least acceptable */ |
418 |
> |
for (j = 0; ourrank[j++] != -1; ) |
419 |
> |
; |
420 |
> |
ourvis.class = ourrank[--j]; |
421 |
> |
ourvis.depth = 1; |
422 |
> |
if (viscmp(&xvi[i],&ourvis) > 0) |
423 |
> |
quiterr("inadequate visuals on this screen"); |
424 |
> |
/* OK, we'll use it */ |
425 |
> |
copystruct(&ourvis, &xvi[i]); |
426 |
> |
#ifdef DEBUG |
427 |
> |
fprintf(stderr, "Selected visual type %s, depth %d\n", |
428 |
> |
vistype[ourvis.class], ourvis.depth); |
429 |
> |
#endif |
430 |
> |
/* make appropriate adjustments */ |
431 |
> |
if (ourvis.class == GrayScale || ourvis.class == StaticGray) |
432 |
> |
greyscale = 1; |
433 |
> |
if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors) |
434 |
> |
maxcolors = ourvis.colormap_size; |
435 |
> |
if (ourvis.class == StaticGray) { |
436 |
> |
ourblack = 0; |
437 |
> |
ourwhite = 255; |
438 |
> |
} else if (ourvis.class == PseudoColor) { |
439 |
> |
ourblack = BlackPixel(thedisplay,ourscreen); |
440 |
> |
ourwhite = WhitePixel(thedisplay,ourscreen); |
441 |
> |
if ((ourblack|ourwhite) & ~255L) { |
442 |
> |
ourblack = 0; |
443 |
> |
ourwhite = 1; |
444 |
> |
} |
445 |
> |
if (maxcolors > 4) |
446 |
> |
maxcolors -= 2; |
447 |
> |
} else { |
448 |
> |
ourblack = 0; |
449 |
> |
ourwhite = ourvis.red_mask|ourvis.green_mask|ourvis.blue_mask; |
450 |
> |
} |
451 |
> |
XFree((char *)xvi); |
452 |
|
} |
453 |
|
|
454 |
|
|
455 |
|
getras() /* get raster file */ |
456 |
|
{ |
299 |
– |
colormap ourmap; |
457 |
|
XVisualInfo vinfo; |
458 |
|
|
459 |
|
if (maxcolors <= 2) { /* monochrome */ |
460 |
|
ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8)); |
461 |
|
if (ourdata == NULL) |
462 |
|
goto fail; |
463 |
< |
ourras = make_raster(thedisplay, ourscreen, 1, ourdata, |
463 |
> |
ourras = make_raster(thedisplay, &ourvis, 1, ourdata, |
464 |
|
xmax, ymax, 8); |
465 |
|
if (ourras == NULL) |
466 |
|
goto fail; |
467 |
|
getmono(); |
468 |
< |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo)) { |
469 |
< |
ourdata = (unsigned char *)malloc(xmax*ymax*3); |
468 |
> |
} else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { |
469 |
> |
ourdata = (unsigned char *)malloc(4*xmax*ymax); |
470 |
|
if (ourdata == NULL) |
471 |
|
goto fail; |
472 |
< |
ourras = make_raster(thedisplay, ourscreen, 24, ourdata, |
473 |
< |
xmax, ymax, 8); |
472 |
> |
ourras = make_raster(thedisplay, &ourvis, 32, |
473 |
> |
ourdata, xmax, ymax, 32); |
474 |
|
if (ourras == NULL) |
475 |
|
goto fail; |
476 |
|
getfull(); |
478 |
|
ourdata = (unsigned char *)malloc(xmax*ymax); |
479 |
|
if (ourdata == NULL) |
480 |
|
goto fail; |
481 |
< |
ourras = make_raster(thedisplay, ourscreen, 8, ourdata, |
481 |
> |
ourras = make_raster(thedisplay, &ourvis, 8, ourdata, |
482 |
|
xmax, ymax, 8); |
483 |
|
if (ourras == NULL) |
484 |
|
goto fail; |
485 |
< |
if (greyscale) |
486 |
< |
biq(dither,maxcolors,1,ourmap); |
485 |
> |
if (greyscale | ourvis.class == StaticGray) |
486 |
> |
getgrey(); |
487 |
|
else |
488 |
< |
ciq(dither,maxcolors,1,ourmap); |
489 |
< |
if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0) |
488 |
> |
getmapped(); |
489 |
> |
if (ourvis.class != StaticGray && !init_rcolors(ourras,clrtab)) |
490 |
|
goto fail; |
491 |
|
} |
492 |
|
return; |
493 |
|
fail: |
494 |
< |
quit("could not create raster image"); |
494 |
> |
quiterr("could not create raster image"); |
495 |
|
} |
496 |
|
|
497 |
|
|
498 |
|
getevent() /* process the next event */ |
499 |
|
{ |
500 |
< |
union { |
344 |
< |
XEvent u; |
345 |
< |
XConfigureEvent c; |
346 |
< |
XExposeEvent e; |
347 |
< |
XButtonPressedEvent b; |
348 |
< |
XKeyPressedEvent k; |
349 |
< |
} e; |
500 |
> |
XEvent xev; |
501 |
|
|
502 |
< |
XNextEvent(thedisplay, &e.u); |
503 |
< |
switch (e.u.type) { |
502 |
> |
XNextEvent(thedisplay, &xev); |
503 |
> |
switch ((int)xev.type) { |
504 |
|
case KeyPress: |
505 |
< |
docom(&e.k); |
505 |
> |
docom(&xev.xkey); |
506 |
|
break; |
507 |
|
case ConfigureNotify: |
508 |
< |
width = e.c.width; |
509 |
< |
height = e.c.height; |
508 |
> |
width = xev.xconfigure.width; |
509 |
> |
height = xev.xconfigure.height; |
510 |
|
break; |
511 |
|
case MapNotify: |
512 |
|
map_rcolors(ourras, wind); |
513 |
|
if (fast) |
514 |
< |
make_rpixmap(ourras); |
514 |
> |
make_rpixmap(ourras, wind); |
515 |
|
break; |
516 |
|
case UnmapNotify: |
517 |
< |
unmap_rcolors(ourras); |
517 |
> |
if (!fast) |
518 |
> |
unmap_rcolors(ourras); |
519 |
|
break; |
520 |
|
case Expose: |
521 |
< |
redraw(e.e.x, e.e.y, e.e.width, e.e.height); |
521 |
> |
redraw(xev.xexpose.x, xev.xexpose.y, |
522 |
> |
xev.xexpose.width, xev.xexpose.height); |
523 |
|
break; |
524 |
|
case ButtonPress: |
525 |
< |
if (e.b.state & (ShiftMask|ControlMask)) |
526 |
< |
moveimage(&e.b); |
525 |
> |
if (xev.xbutton.state & (ShiftMask|ControlMask)) |
526 |
> |
moveimage(&xev.xbutton); |
527 |
> |
else if (xev.xbutton.button == Button2) |
528 |
> |
traceray(xev.xbutton.x, xev.xbutton.y); |
529 |
|
else |
530 |
< |
getbox(&e.b); |
530 |
> |
getbox(&xev.xbutton); |
531 |
|
break; |
532 |
+ |
case ClientMessage: |
533 |
+ |
if ((xev.xclient.message_type == wmProtocolsAtom) && |
534 |
+ |
(xev.xclient.data.l[0] == closedownAtom)) |
535 |
+ |
quiterr(NULL); |
536 |
+ |
break; |
537 |
|
} |
538 |
|
} |
539 |
|
|
540 |
|
|
541 |
< |
docom(ekey) /* execute command */ |
541 |
> |
traceray(xpos, ypos) /* print ray corresponding to pixel */ |
542 |
> |
int xpos, ypos; |
543 |
> |
{ |
544 |
> |
FLOAT hv[2]; |
545 |
> |
FVECT rorg, rdir; |
546 |
> |
|
547 |
> |
if (!gotview) { /* no view, no can do */ |
548 |
> |
XBell(thedisplay, 0); |
549 |
> |
return(-1); |
550 |
> |
} |
551 |
> |
pix2loc(hv, &inpres, xpos-xoff, ypos-yoff); |
552 |
> |
if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
553 |
> |
return(-1); |
554 |
> |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
555 |
> |
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
556 |
> |
fflush(stdout); |
557 |
> |
return(0); |
558 |
> |
} |
559 |
> |
|
560 |
> |
|
561 |
> |
docom(ekey) /* execute command */ |
562 |
|
XKeyPressedEvent *ekey; |
563 |
|
{ |
564 |
|
char buf[80]; |
566 |
|
XColor cvx; |
567 |
|
int com, n; |
568 |
|
double comp; |
569 |
< |
FVECT rorg, rdir; |
569 |
> |
FLOAT hv[2]; |
570 |
|
|
571 |
|
n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); |
572 |
|
if (n == 0) |
574 |
|
com = buf[0]; |
575 |
|
switch (com) { /* interpret command */ |
576 |
|
case 'q': |
577 |
< |
case CTRL(D): /* quit */ |
578 |
< |
quit(0); |
577 |
> |
case 'Q': |
578 |
> |
case CTRL('D'): /* quit */ |
579 |
> |
quiterr(NULL); |
580 |
|
case '\n': |
581 |
|
case '\r': |
582 |
|
case 'l': |
589 |
|
sprintf(buf, "%.3f", intens(cval)/exposure); |
590 |
|
break; |
591 |
|
case 'l': /* luminance */ |
592 |
< |
sprintf(buf, "%.0fn", bright(cval)*683.0/exposure); |
592 |
> |
sprintf(buf, "%.0fL", luminance(cval)/exposure); |
593 |
|
break; |
594 |
|
case 'c': /* color */ |
595 |
|
comp = pow(2.0, (double)scale); |
615 |
|
XStoreColor(thedisplay, ourras->cmap, &cvx); |
616 |
|
return(0); |
617 |
|
case 'p': /* position */ |
618 |
< |
sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff); |
618 |
> |
pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); |
619 |
> |
sprintf(buf, "(%d,%d)", (int)(hv[0]*inpres.xr), |
620 |
> |
(int)(hv[1]*inpres.yr)); |
621 |
|
XDrawImageString(thedisplay, wind, ourgc, ekey->x, ekey->y, |
622 |
|
buf, strlen(buf)); |
623 |
|
return(0); |
624 |
|
case 't': /* trace */ |
625 |
< |
if (!gotview) { |
443 |
< |
XBell(thedisplay, 0); |
444 |
< |
return(-1); |
445 |
< |
} |
446 |
< |
viewray(rorg, rdir, &ourview, |
447 |
< |
(ekey->x-xoff+.5)/xmax, |
448 |
< |
(ymax-1-ekey->y+yoff+.5)/ymax); |
449 |
< |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
450 |
< |
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
451 |
< |
fflush(stdout); |
452 |
< |
return(0); |
625 |
> |
return(traceray(ekey->x, ekey->y)); |
626 |
|
case '=': /* adjust exposure */ |
627 |
+ |
case '@': /* adaptation level */ |
628 |
|
if (avgbox(cval) == -1) |
629 |
|
return(-1); |
630 |
< |
n = log(.5/bright(cval))/.69315 - scale; /* truncate */ |
630 |
> |
comp = com=='@' |
631 |
> |
? 106./pow(1.219+pow(luminance(cval)/exposure,.4),2.5)/exposure |
632 |
> |
: .5/bright(cval) ; |
633 |
> |
comp = log(comp)/.69315 - scale; |
634 |
> |
n = comp < 0 ? comp-.5 : comp+.5 ; /* round */ |
635 |
|
if (n == 0) |
636 |
|
return(0); |
637 |
|
scale_rcolors(ourras, pow(2.0, (double)n)); |
644 |
|
free_raster(ourras); |
645 |
|
getras(); |
646 |
|
/* fall through */ |
647 |
< |
case CTRL(R): /* redraw */ |
648 |
< |
case CTRL(L): |
647 |
> |
case CTRL('R'): /* redraw */ |
648 |
> |
case CTRL('L'): |
649 |
|
unmap_rcolors(ourras); |
650 |
|
XClearWindow(thedisplay, wind); |
651 |
|
map_rcolors(ourras, wind); |
652 |
|
if (fast) |
653 |
< |
make_rpixmap(ourras); |
653 |
> |
make_rpixmap(ourras, wind); |
654 |
|
redraw(0, 0, width, height); |
655 |
|
return(0); |
656 |
+ |
case 'f': /* turn on fast redraw */ |
657 |
+ |
fast = 1; |
658 |
+ |
make_rpixmap(ourras, wind); |
659 |
+ |
return(0); |
660 |
+ |
case 'F': /* turn off fast redraw */ |
661 |
+ |
fast = 0; |
662 |
+ |
free_rpixmap(ourras); |
663 |
+ |
return(0); |
664 |
+ |
case '0': /* recenter origin */ |
665 |
+ |
if (xoff == 0 & yoff == 0) |
666 |
+ |
return(0); |
667 |
+ |
xoff = yoff = 0; |
668 |
+ |
XClearWindow(thedisplay, wind); |
669 |
+ |
redraw(0, 0, width, height); |
670 |
+ |
return(0); |
671 |
|
case ' ': /* clear */ |
672 |
|
redraw(box.xmin, box.ymin, box.xsiz, box.ysiz); |
673 |
|
return(0); |
681 |
|
moveimage(ebut) /* shift the image */ |
682 |
|
XButtonPressedEvent *ebut; |
683 |
|
{ |
684 |
< |
union { |
492 |
< |
XEvent u; |
493 |
< |
XButtonReleasedEvent b; |
494 |
< |
XPointerMovedEvent m; |
495 |
< |
} e; |
684 |
> |
XEvent e; |
685 |
|
int mxo, myo; |
686 |
|
|
687 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
688 |
< |
while (e.u.type == MotionNotify) { |
689 |
< |
mxo = e.m.x; |
690 |
< |
myo = e.m.y; |
687 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); |
688 |
> |
while (e.type == MotionNotify) { |
689 |
> |
mxo = e.xmotion.x; |
690 |
> |
myo = e.xmotion.y; |
691 |
|
revline(ebut->x, ebut->y, mxo, myo); |
692 |
|
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
693 |
|
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
694 |
< |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
694 |
> |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); |
695 |
|
revline(ebut->x, ebut->y, mxo, myo); |
696 |
|
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
697 |
|
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
698 |
|
} |
699 |
< |
xoff += e.b.x - ebut->x; |
700 |
< |
yoff += e.b.y - ebut->y; |
699 |
> |
xoff += e.xbutton.x - ebut->x; |
700 |
> |
yoff += e.xbutton.y - ebut->y; |
701 |
|
XClearWindow(thedisplay, wind); |
702 |
|
redraw(0, 0, width, height); |
703 |
|
} |
706 |
|
getbox(ebut) /* get new box */ |
707 |
|
XButtonPressedEvent *ebut; |
708 |
|
{ |
709 |
< |
union { |
521 |
< |
XEvent u; |
522 |
< |
XButtonReleasedEvent b; |
523 |
< |
XPointerMovedEvent m; |
524 |
< |
} e; |
709 |
> |
XEvent e; |
710 |
|
|
711 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
712 |
< |
while (e.u.type == MotionNotify) { |
713 |
< |
revbox(ebut->x, ebut->y, box.xmin = e.m.x, box.ymin = e.m.y); |
714 |
< |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
711 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); |
712 |
> |
while (e.type == MotionNotify) { |
713 |
> |
revbox(ebut->x, ebut->y, box.xmin = e.xmotion.x, box.ymin = e.xmotion.y); |
714 |
> |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); |
715 |
|
revbox(ebut->x, ebut->y, box.xmin, box.ymin); |
716 |
|
} |
717 |
< |
box.xmin = e.b.x<0 ? 0 : (e.b.x>=width ? width-1 : e.b.x); |
718 |
< |
box.ymin = e.b.y<0 ? 0 : (e.b.y>=height ? height-1 : e.b.y); |
717 |
> |
box.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x); |
718 |
> |
box.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y); |
719 |
|
if (box.xmin > ebut->x) { |
720 |
|
box.xsiz = box.xmin - ebut->x + 1; |
721 |
|
box.xmin = ebut->x; |
744 |
|
avgbox(clr) /* average color over current box */ |
745 |
|
COLOR clr; |
746 |
|
{ |
747 |
+ |
static COLOR lc; |
748 |
+ |
static int ll, lr, lt, lb; |
749 |
|
int left, right, top, bottom; |
750 |
|
int y; |
751 |
|
double d; |
769 |
|
bottom = ymax; |
770 |
|
if (top >= bottom) |
771 |
|
return(-1); |
772 |
+ |
if (left == ll && right == lr && top == lt && bottom == lb) { |
773 |
+ |
copycolor(clr, lc); |
774 |
+ |
return(0); |
775 |
+ |
} |
776 |
|
for (y = top; y < bottom; y++) { |
777 |
|
if (getscan(y) == -1) |
778 |
|
return(-1); |
783 |
|
} |
784 |
|
d = 1.0/((right-left)*(bottom-top)); |
785 |
|
scalecolor(clr, d); |
786 |
+ |
ll = left; lr = right; lt = top; lb = bottom; |
787 |
+ |
copycolor(lc, clr); |
788 |
|
return(0); |
789 |
|
} |
790 |
|
|
793 |
|
{ |
794 |
|
register unsigned char *dp; |
795 |
|
register int x, err; |
796 |
< |
int y; |
604 |
< |
rgbpixel *inline; |
796 |
> |
int y, errp; |
797 |
|
short *cerr; |
798 |
|
|
799 |
< |
if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
800 |
< |
|| (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
609 |
< |
quit("out of memory in getmono"); |
799 |
> |
if ((cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
800 |
> |
quiterr("out of memory in getmono"); |
801 |
|
dp = ourdata - 1; |
802 |
|
for (y = 0; y < ymax; y++) { |
803 |
< |
picreadline3(y, inline); |
803 |
> |
getscan(y); |
804 |
> |
add2icon(y, scanline); |
805 |
> |
normcolrs(scanline, xmax, scale); |
806 |
|
err = 0; |
807 |
|
for (x = 0; x < xmax; x++) { |
808 |
|
if (!(x&7)) |
809 |
|
*++dp = 0; |
810 |
< |
err += rgb_bright(&inline[x]) + cerr[x]; |
810 |
> |
errp = err; |
811 |
> |
err += normbright(scanline[x]) + cerr[x]; |
812 |
|
if (err > 127) |
813 |
|
err -= 255; |
814 |
|
else |
815 |
|
*dp |= 1<<(7-(x&07)); |
816 |
< |
cerr[x] = err >>= 1; |
816 |
> |
err /= 3; |
817 |
> |
cerr[x] = err + errp; |
818 |
|
} |
819 |
|
} |
625 |
– |
free((char *)inline); |
820 |
|
free((char *)cerr); |
821 |
|
} |
822 |
|
|
823 |
|
|
824 |
+ |
add2icon(y, scan) /* add a scanline to our icon data */ |
825 |
+ |
int y; |
826 |
+ |
COLR *scan; |
827 |
+ |
{ |
828 |
+ |
static short cerr[ICONSIZ]; |
829 |
+ |
static int ynext; |
830 |
+ |
static char *dp; |
831 |
+ |
COLR clr; |
832 |
+ |
register int err; |
833 |
+ |
register int x, ti; |
834 |
+ |
int errp; |
835 |
+ |
|
836 |
+ |
if (iconheight == 0) { /* initialize */ |
837 |
+ |
if (xmax <= ICONSIZ && ymax <= ICONSIZ) { |
838 |
+ |
iconwidth = xmax; |
839 |
+ |
iconheight = ymax; |
840 |
+ |
} else if (xmax > ymax) { |
841 |
+ |
iconwidth = ICONSIZ; |
842 |
+ |
iconheight = ICONSIZ*ymax/xmax; |
843 |
+ |
if (iconheight < 1) |
844 |
+ |
iconheight = 1; |
845 |
+ |
} else { |
846 |
+ |
iconwidth = ICONSIZ*xmax/ymax; |
847 |
+ |
if (iconwidth < 1) |
848 |
+ |
iconwidth = 1; |
849 |
+ |
iconheight = ICONSIZ; |
850 |
+ |
} |
851 |
+ |
ynext = 0; |
852 |
+ |
dp = icondata - 1; |
853 |
+ |
} |
854 |
+ |
if (y < ynext*ymax/iconheight) /* skip this one */ |
855 |
+ |
return; |
856 |
+ |
err = 0; |
857 |
+ |
for (x = 0; x < iconwidth; x++) { |
858 |
+ |
if (!(x&7)) |
859 |
+ |
*++dp = 0; |
860 |
+ |
errp = err; |
861 |
+ |
ti = x*xmax/iconwidth; |
862 |
+ |
copycolr(clr, scan[ti]); |
863 |
+ |
normcolrs(clr, 1, scale); |
864 |
+ |
err += normbright(clr) + cerr[x]; |
865 |
+ |
if (err > 127) |
866 |
+ |
err -= 255; |
867 |
+ |
else |
868 |
+ |
*dp |= 1<<(x&07); |
869 |
+ |
err /= 3; |
870 |
+ |
cerr[x] = err + errp; |
871 |
+ |
} |
872 |
+ |
ynext++; |
873 |
+ |
} |
874 |
+ |
|
875 |
+ |
|
876 |
|
getfull() /* get full (24-bit) data */ |
877 |
|
{ |
878 |
|
int y; |
879 |
+ |
register unsigned long *dp; |
880 |
+ |
register int x; |
881 |
+ |
/* set gamma correction */ |
882 |
+ |
setcolrgam(gamcor); |
883 |
+ |
/* read and convert file */ |
884 |
+ |
dp = (unsigned long *)ourdata; |
885 |
+ |
for (y = 0; y < ymax; y++) { |
886 |
+ |
getscan(y); |
887 |
+ |
add2icon(y, scanline); |
888 |
+ |
if (scale) |
889 |
+ |
shiftcolrs(scanline, xmax, scale); |
890 |
+ |
colrs_gambs(scanline, xmax); |
891 |
+ |
if (ourras->image->blue_mask & 1) |
892 |
+ |
for (x = 0; x < xmax; x++) |
893 |
+ |
*dp++ = scanline[x][RED] << 16 | |
894 |
+ |
scanline[x][GRN] << 8 | |
895 |
+ |
scanline[x][BLU] ; |
896 |
+ |
else |
897 |
+ |
for (x = 0; x < xmax; x++) |
898 |
+ |
*dp++ = scanline[x][RED] | |
899 |
+ |
scanline[x][GRN] << 8 | |
900 |
+ |
scanline[x][BLU] << 16 ; |
901 |
+ |
} |
902 |
+ |
} |
903 |
|
|
904 |
< |
for (y = 0; y < ymax; y++) |
905 |
< |
picreadline3(y, (rgbpixel *)(ourdata+y*xmax*3)); |
904 |
> |
|
905 |
> |
getgrey() /* get greyscale data */ |
906 |
> |
{ |
907 |
> |
int y; |
908 |
> |
register unsigned char *dp; |
909 |
> |
register int x; |
910 |
> |
/* set gamma correction */ |
911 |
> |
setcolrgam(gamcor); |
912 |
> |
/* read and convert file */ |
913 |
> |
dp = ourdata; |
914 |
> |
for (y = 0; y < ymax; y++) { |
915 |
> |
getscan(y); |
916 |
> |
add2icon(y, scanline); |
917 |
> |
if (scale) |
918 |
> |
shiftcolrs(scanline, xmax, scale); |
919 |
> |
for (x = 0; x < xmax; x++) |
920 |
> |
scanline[x][GRN] = normbright(scanline[x]); |
921 |
> |
colrs_gambs(scanline, xmax); |
922 |
> |
if (maxcolors < 256) |
923 |
> |
for (x = 0; x < xmax; x++) |
924 |
> |
*dp++ = ((long)scanline[x][GRN] * |
925 |
> |
maxcolors + maxcolors/2) >> 8; |
926 |
> |
else |
927 |
> |
for (x = 0; x < xmax; x++) |
928 |
> |
*dp++ = scanline[x][GRN]; |
929 |
> |
} |
930 |
> |
for (x = 0; x < maxcolors; x++) |
931 |
> |
clrtab[x][RED] = clrtab[x][GRN] = |
932 |
> |
clrtab[x][BLU] = ((long)x*256 + 128)/maxcolors; |
933 |
|
} |
934 |
|
|
935 |
|
|
936 |
+ |
getmapped() /* get color-mapped data */ |
937 |
+ |
{ |
938 |
+ |
int y; |
939 |
+ |
/* set gamma correction */ |
940 |
+ |
setcolrgam(gamcor); |
941 |
+ |
/* make histogram */ |
942 |
+ |
new_histo(); |
943 |
+ |
for (y = 0; y < ymax; y++) { |
944 |
+ |
if (getscan(y) < 0) |
945 |
+ |
quiterr("seek error in getmapped"); |
946 |
+ |
add2icon(y, scanline); |
947 |
+ |
if (scale) |
948 |
+ |
shiftcolrs(scanline, xmax, scale); |
949 |
+ |
colrs_gambs(scanline, xmax); |
950 |
+ |
cnt_colrs(scanline, xmax); |
951 |
+ |
} |
952 |
+ |
/* map pixels */ |
953 |
+ |
if (!new_clrtab(maxcolors)) |
954 |
+ |
quiterr("cannot create color map"); |
955 |
+ |
for (y = 0; y < ymax; y++) { |
956 |
+ |
if (getscan(y) < 0) |
957 |
+ |
quiterr("seek error in getmapped"); |
958 |
+ |
if (scale) |
959 |
+ |
shiftcolrs(scanline, xmax, scale); |
960 |
+ |
colrs_gambs(scanline, xmax); |
961 |
+ |
if (dither) |
962 |
+ |
dith_colrs(ourdata+y*xmax, scanline, xmax); |
963 |
+ |
else |
964 |
+ |
map_colrs(ourdata+y*xmax, scanline, xmax); |
965 |
+ |
} |
966 |
+ |
} |
967 |
+ |
|
968 |
+ |
|
969 |
|
scale_rcolors(xr, sf) /* scale color map */ |
970 |
|
register XRASTER *xr; |
971 |
|
double sf; |
1001 |
|
if (scanpos == NULL || scanpos[y] == -1) |
1002 |
|
return(-1); |
1003 |
|
if (fseek(fin, scanpos[y], 0) == -1) |
1004 |
< |
quit("fseek error"); |
1004 |
> |
quiterr("fseek error"); |
1005 |
|
cury = y; |
1006 |
< |
} else if (scanpos != NULL) |
1006 |
> |
} else if (scanpos != NULL && scanpos[y] == -1) |
1007 |
|
scanpos[y] = ftell(fin); |
1008 |
|
|
1009 |
|
if (freadcolrs(scanline, xmax, fin) < 0) |
1011 |
|
|
1012 |
|
cury++; |
1013 |
|
return(0); |
684 |
– |
} |
685 |
– |
|
686 |
– |
|
687 |
– |
picreadline3(y, l3) /* read in 3-byte scanline */ |
688 |
– |
int y; |
689 |
– |
register rgbpixel *l3; |
690 |
– |
{ |
691 |
– |
register int i; |
692 |
– |
/* read scanline */ |
693 |
– |
if (getscan(y) < 0) |
694 |
– |
quiterr("cannot seek for picreadline"); |
695 |
– |
/* convert scanline */ |
696 |
– |
normcolrs(scanline, xmax, scale); |
697 |
– |
for (i = 0; i < xmax; i++) { |
698 |
– |
l3[i].r = scanline[i][RED]; |
699 |
– |
l3[i].g = scanline[i][GRN]; |
700 |
– |
l3[i].b = scanline[i][BLU]; |
701 |
– |
} |
702 |
– |
} |
703 |
– |
|
704 |
– |
|
705 |
– |
picwriteline(y, l) /* add 8-bit scanline to image */ |
706 |
– |
int y; |
707 |
– |
pixel *l; |
708 |
– |
{ |
709 |
– |
bcopy((char *)l, (char *)ourdata+y*xmax, xmax); |
710 |
– |
} |
711 |
– |
|
712 |
– |
|
713 |
– |
picreadcm(map) /* do gamma correction */ |
714 |
– |
colormap map; |
715 |
– |
{ |
716 |
– |
extern double pow(); |
717 |
– |
register int i, val; |
718 |
– |
|
719 |
– |
for (i = 0; i < 256; i++) { |
720 |
– |
val = pow(i/256.0, 1.0/gamcor) * 256.0; |
721 |
– |
map[0][i] = map[1][i] = map[2][i] = val; |
722 |
– |
} |
723 |
– |
} |
724 |
– |
|
725 |
– |
|
726 |
– |
picwritecm(map) /* handled elsewhere */ |
727 |
– |
colormap map; |
728 |
– |
{ |
729 |
– |
#ifdef DEBUG |
730 |
– |
register int i; |
731 |
– |
|
732 |
– |
for (i = 0; i < 256; i++) |
733 |
– |
printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]); |
734 |
– |
#endif |
1014 |
|
} |