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 */ |
79 |
|
|
80 |
|
char errmsg[128]; |
81 |
|
|
87 |
– |
extern long ftell(); |
82 |
|
|
89 |
– |
extern char *malloc(), *calloc(); |
90 |
– |
|
91 |
– |
extern double atof(), pow(), log(); |
92 |
– |
|
93 |
– |
|
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] == '-') |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
+ |
int |
162 |
|
headline(s) /* get relevant info from header */ |
163 |
|
char *s; |
164 |
|
{ |
171 |
– |
static char *altname[] = {"rview","rpict",VIEWSTR,NULL}; |
172 |
– |
register char **an; |
165 |
|
char fmt[32]; |
166 |
|
|
167 |
|
if (isexpos(s)) |
169 |
|
else if (isformat(s)) { |
170 |
|
formatval(fmt, s); |
171 |
|
wrongformat = strcmp(fmt, COLRFMT); |
172 |
< |
} else |
173 |
< |
for (an = altname; *an != NULL; an++) |
174 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
183 |
< |
if (sscanview(&ourview, s+strlen(*an)) > 0) |
184 |
< |
gotview++; |
185 |
< |
return; |
186 |
< |
} |
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 |
|
{ |
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': |
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; |
541 |
> |
int y, errp; |
542 |
|
rgbpixel *inl; |
543 |
|
short *cerr; |
544 |
|
|
552 |
|
for (x = 0; x < xmax; x++) { |
553 |
|
if (!(x&0xf)) |
554 |
|
*++dp = 0; |
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 *)inl); |
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); |
635 |
|
if (fseek(fin, scanpos[y], 0) == -1) |
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) |
668 |
|
int y; |
669 |
|
pixel *l; |
670 |
|
{ |
671 |
< |
bcopy((char *)l, (char *)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 |
|
|