1 |
– |
/* Copyright (c) 1987 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* ximage.c - driver for X-windows |
6 |
|
* |
15 |
|
#include <X/cursors/bcross_mask.cursor> |
16 |
|
|
17 |
|
#include <sys/types.h> |
18 |
< |
|
18 |
> |
#include <string.h> |
19 |
|
#include <ctype.h> |
20 |
+ |
#include <time.h> |
21 |
|
|
22 |
|
#include "color.h" |
23 |
< |
|
23 |
> |
#include "resolu.h" |
24 |
|
#include "xraster.h" |
27 |
– |
|
25 |
|
#include "view.h" |
29 |
– |
|
26 |
|
#include "pic.h" |
31 |
– |
|
27 |
|
#include "random.h" |
28 |
|
|
29 |
|
#define controlshift(e) (((XButtonEvent *)(e))->detail & (ShiftMask|ControlMask)) |
30 |
|
|
31 |
|
#define FONTNAME "9x15" /* text font we'll use */ |
32 |
|
|
33 |
< |
#define CTRL(c) ('c'-'@') |
33 |
> |
#define CTRL(c) ((c)-'@') |
34 |
|
|
35 |
|
#define BORWIDTH 5 /* border width */ |
36 |
|
#define BARHEIGHT 25 /* menu bar size */ |
53 |
|
int xoff = 0; /* x image offset */ |
54 |
|
int yoff = 0; /* y image offset */ |
55 |
|
|
56 |
< |
VIEW ourview = STDVIEW(0); /* image view parameters */ |
56 |
> |
VIEW ourview = STDVIEW; /* image view parameters */ |
57 |
|
int gotview = 0; /* got parameters from file */ |
58 |
|
|
59 |
|
COLR *scanline; /* scan line buffer */ |
67 |
|
|
68 |
|
double exposure = 1.0; /* exposure compensation used */ |
69 |
|
|
70 |
+ |
int wrongformat = 0; /* input in another format */ |
71 |
+ |
|
72 |
|
struct { |
73 |
|
int xmin, ymin, xsiz, ysiz; |
74 |
|
} box = {0, 0, 0, 0}; /* current box */ |
79 |
|
|
80 |
|
char errmsg[128]; |
81 |
|
|
85 |
– |
extern long ftell(); |
82 |
|
|
87 |
– |
extern char *malloc(), *calloc(); |
88 |
– |
|
89 |
– |
extern double atof(), pow(), log(); |
90 |
– |
|
91 |
– |
|
83 |
|
main(argc, argv) |
84 |
|
int argc; |
85 |
|
char *argv[]; |
86 |
|
{ |
87 |
+ |
extern char *getenv(); |
88 |
+ |
char *gv; |
89 |
|
int headline(); |
90 |
|
int i; |
91 |
|
|
92 |
|
progname = argv[0]; |
93 |
+ |
if ((gv = getenv("DISPLAY_GAMMA")) != NULL) |
94 |
+ |
gamcor = atof(gv); |
95 |
|
|
96 |
|
for (i = 1; i < argc; i++) |
97 |
|
if (argv[i][0] == '-') |
136 |
|
} |
137 |
|
} |
138 |
|
/* get header */ |
139 |
< |
getheader(fin, headline); |
139 |
> |
getheader(fin, headline, NULL); |
140 |
|
/* get picture dimensions */ |
141 |
< |
if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
141 |
> |
if (wrongformat || fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
142 |
|
quiterr("bad picture size"); |
143 |
|
/* set view parameters */ |
144 |
< |
if (gotview) { |
145 |
< |
ourview.hresolu = xmax; |
151 |
< |
ourview.vresolu = ymax; |
152 |
< |
if (setview(&ourview) != NULL) |
153 |
< |
gotview = 0; |
154 |
< |
} |
144 |
> |
if (gotview && setview(&ourview) != NULL) |
145 |
> |
gotview = 0; |
146 |
|
if ((scanline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) |
147 |
|
quiterr("out of memory"); |
148 |
|
|
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
+ |
int |
162 |
|
headline(s) /* get relevant info from header */ |
163 |
|
char *s; |
164 |
|
{ |
165 |
< |
static char *altname[] = {"rview","rpict",VIEWSTR,NULL}; |
174 |
< |
register char **an; |
165 |
> |
char fmt[32]; |
166 |
|
|
167 |
|
if (isexpos(s)) |
168 |
|
exposure *= exposval(s); |
169 |
< |
else |
170 |
< |
for (an = altname; *an != NULL; an++) |
171 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
172 |
< |
if (sscanview(&ourview, s+strlen(*an)) == 0) |
173 |
< |
gotview++; |
174 |
< |
return; |
184 |
< |
} |
169 |
> |
else if (isformat(s)) { |
170 |
> |
formatval(fmt, s); |
171 |
> |
wrongformat = strcmp(fmt, COLRFMT); |
172 |
> |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
173 |
> |
gotview++; |
174 |
> |
return(0); |
175 |
|
} |
176 |
|
|
177 |
|
|
240 |
|
} |
241 |
|
|
242 |
|
|
243 |
+ |
void |
244 |
|
eputs(s) |
245 |
|
char *s; |
246 |
|
{ |
248 |
|
} |
249 |
|
|
250 |
|
|
251 |
+ |
void |
252 |
|
quit(code) |
253 |
|
int code; |
254 |
|
{ |
283 |
|
} |
284 |
|
return; |
285 |
|
memerr: |
286 |
< |
quit("out of memory"); |
286 |
> |
quiterr("out of memory"); |
287 |
|
} |
288 |
|
|
289 |
|
|
355 |
|
return(0); |
356 |
|
switch (*cp) { /* interpret command */ |
357 |
|
case 'q': |
358 |
< |
case CTRL(D): /* quit */ |
358 |
> |
case CTRL('D'): /* quit */ |
359 |
|
quit(0); |
360 |
|
case '\n': |
361 |
|
case '\r': |
369 |
|
sprintf(buf, "%.3f", intens(cval)/exposure); |
370 |
|
break; |
371 |
|
case 'l': /* luminance */ |
372 |
< |
sprintf(buf, "%.0fn", bright(cval)*683.0/exposure); |
372 |
> |
sprintf(buf, "%.0fL", luminance(cval)/exposure); |
373 |
|
break; |
374 |
|
case 'c': /* color */ |
375 |
|
comp = pow(2.0, (double)scale); |
403 |
|
XFeep(0); |
404 |
|
return(-1); |
405 |
|
} |
406 |
< |
rayview(rorg, rdir, &ourview, |
407 |
< |
ekey->x-xoff + .5, ymax-1-ekey->y+yoff + .5); |
406 |
> |
if (viewray(rorg, rdir, &ourview, (ekey->x-xoff+.5)/xmax, |
407 |
> |
(ymax-1-ekey->y+yoff+.5)/ymax) < 0) |
408 |
> |
return(-1); |
409 |
|
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
410 |
|
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
411 |
|
fflush(stdout); |
425 |
|
free_raster(ourras); |
426 |
|
getras(); |
427 |
|
/* fall through */ |
428 |
< |
case CTRL(R): /* redraw */ |
429 |
< |
case CTRL(L): |
428 |
> |
case CTRL('R'): /* redraw */ |
429 |
> |
case CTRL('L'): |
430 |
|
unmap_rcolors(ourras); |
431 |
|
XClear(wind); |
432 |
|
return(redraw(0, 0, width, height)); |
538 |
|
{ |
539 |
|
register unsigned short *dp; |
540 |
|
register int x, err; |
541 |
< |
int y; |
542 |
< |
rgbpixel *inline; |
541 |
> |
int y, errp; |
542 |
> |
rgbpixel *inl; |
543 |
|
short *cerr; |
544 |
|
|
545 |
< |
if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
545 |
> |
if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
546 |
|
|| (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
547 |
< |
quit("out of memory in getmono"); |
547 |
> |
quiterr("out of memory in getmono"); |
548 |
|
dp = ourras->data.m - 1; |
549 |
|
for (y = 0; y < ymax; y++) { |
550 |
< |
picreadline3(y, inline); |
550 |
> |
picreadline3(y, inl); |
551 |
|
err = 0; |
552 |
|
for (x = 0; x < xmax; x++) { |
553 |
|
if (!(x&0xf)) |
554 |
|
*++dp = 0; |
555 |
< |
err += rgb_bright(&inline[x]) + cerr[x]; |
555 |
> |
errp = err; |
556 |
> |
err += rgb_bright(&inl[x]) + cerr[x]; |
557 |
|
if (err > 127) |
558 |
|
err -= 255; |
559 |
|
else |
560 |
|
*dp |= 1<<(x&0xf); |
561 |
< |
cerr[x] = err >>= 1; |
561 |
> |
err /= 3; |
562 |
> |
cerr[x] = err + errp; |
563 |
|
} |
564 |
|
} |
565 |
< |
free((char *)inline); |
566 |
< |
free((char *)cerr); |
565 |
> |
free((void *)inl); |
566 |
> |
free((void *)cerr); |
567 |
|
} |
568 |
|
|
569 |
|
|
591 |
|
xr->cdefs[xr->ncolors].pixel = *p; |
592 |
|
xr->pmap[*p] = xr->ncolors++; |
593 |
|
} |
594 |
< |
xr->cdefs = (Color *)realloc((char *)xr->cdefs, xr->ncolors*sizeof(Color)); |
594 |
> |
xr->cdefs = (Color *)realloc((void *)xr->cdefs, xr->ncolors*sizeof(Color)); |
595 |
|
if (xr->cdefs == NULL) |
596 |
|
return(0); |
597 |
|
return(1); |
633 |
|
if (scanpos == NULL || scanpos[y] == -1) |
634 |
|
return(-1); |
635 |
|
if (fseek(fin, scanpos[y], 0) == -1) |
636 |
< |
quit("fseek error"); |
636 |
> |
quiterr("fseek error"); |
637 |
|
cury = y; |
638 |
< |
} else if (scanpos != NULL) |
638 |
> |
} else if (scanpos != NULL && scanpos[y] == -1) |
639 |
|
scanpos[y] = ftell(fin); |
640 |
|
|
641 |
|
if (freadcolrs(scanline, xmax, fin) < 0) |
655 |
|
if (getscan(y) < 0) |
656 |
|
quiterr("cannot seek for picreadline"); |
657 |
|
/* convert scanline */ |
658 |
< |
if (scale) |
664 |
< |
for (i = 0; i < xmax; i++) |
665 |
< |
if (scanline[i][EXP]) |
666 |
< |
scanline[i][EXP] += scale; |
667 |
< |
normcolrs(scanline, xmax); |
658 |
> |
normcolrs(scanline, xmax, scale); |
659 |
|
for (i = 0; i < xmax; i++) { |
660 |
|
l3[i].r = scanline[i][RED]; |
661 |
|
l3[i].g = scanline[i][GRN]; |
668 |
|
int y; |
669 |
|
pixel *l; |
670 |
|
{ |
671 |
< |
bcopy(l, ourras->data.bz+BZPixmapSize(xmax,y), BZPixmapSize(xmax,1)); |
671 |
> |
memcpy((void *)ourras->data.bz+BZPixmapSize(xmax,y), (void *)l, BZPixmapSize(xmax,1)); |
672 |
|
} |
673 |
|
|
674 |
|
|
679 |
|
register int i, val; |
680 |
|
|
681 |
|
for (i = 0; i < 256; i++) { |
682 |
< |
val = pow(i/256.0, 1.0/gamcor) * 256.0; |
682 |
> |
val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; |
683 |
|
map[0][i] = map[1][i] = map[2][i] = val; |
684 |
|
} |
685 |
|
} |