BSD 4_3_Tahoe development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Fri, 26 Sep 1986 03:11:10 +0000 (19:11 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Fri, 26 Sep 1986 03:11:10 +0000 (19:11 -0800)
Work on file usr/src/new/X/showimg/shutil.c
Work on file usr/src/new/X/showimg/pictio.c
Work on file usr/src/new/X/showimg/calcmap.c
Work on file usr/src/new/X/showimg/Makefile
Work on file usr/src/new/X/showimg/showimg.1
Work on file usr/src/new/X/showimg/shimg.h
Work on file usr/src/new/X/showimg/pan.cursor
Work on file usr/src/new/X/showimg/m51
Work on file usr/src/new/X/showimg/showimg.c
Work on file usr/src/new/X/showimg/menusetup.c
Work on file usr/src/new/X/showimg/d213
Work on file usr/src/new/X/showimg/pal.cursor
Work on file usr/src/new/X/showimg/shopt.h
Work on file usr/src/new/X/showimg/shzoom.c
Work on file usr/src/new/X/showimg/pan_mask.cursor
Work on file usr/src/new/X/showimg/quad_arrow.cursor
Work on file usr/src/new/X/showimg/zoom2.cursor
Work on file usr/src/new/X/showimg/shgetopt.c
Work on file usr/src/new/X/showimg/zoom2_mask.cursor
Work on file usr/src/new/X/showimg/pal_mask.cursor
Work on file usr/src/new/X/showimg/quad_arrow_mask.cursor
Work on file usr/src/new/X/showimg/oldstruct.h
Work on file usr/src/new/X/showimg/print_mask.cursor
Work on file usr/src/new/X/showimg/zoom4.cursor
Work on file usr/src/new/X/showimg/print.cursor
Work on file usr/src/new/X/showimg/shzoom.c.old
Work on file usr/src/new/X/showimg/zoom4_mask.cursor
Work on file usr/src/new/X/showimg/wzoom.cursor
Work on file usr/src/new/X/showimg/show.icon.ic
Work on file usr/src/new/X/showimg/wzoom_mask.cursor

Synthesized-from: CSRG/cd2/4.3tahoe

30 files changed:
usr/src/new/X/showimg/Makefile [new file with mode: 0644]
usr/src/new/X/showimg/calcmap.c [new file with mode: 0644]
usr/src/new/X/showimg/d213 [new file with mode: 0644]
usr/src/new/X/showimg/m51 [new file with mode: 0644]
usr/src/new/X/showimg/menusetup.c [new file with mode: 0644]
usr/src/new/X/showimg/oldstruct.h [new file with mode: 0644]
usr/src/new/X/showimg/pal.cursor [new file with mode: 0644]
usr/src/new/X/showimg/pal_mask.cursor [new file with mode: 0644]
usr/src/new/X/showimg/pan.cursor [new file with mode: 0644]
usr/src/new/X/showimg/pan_mask.cursor [new file with mode: 0644]
usr/src/new/X/showimg/pictio.c [new file with mode: 0644]
usr/src/new/X/showimg/print.cursor [new file with mode: 0644]
usr/src/new/X/showimg/print_mask.cursor [new file with mode: 0644]
usr/src/new/X/showimg/quad_arrow.cursor [new file with mode: 0644]
usr/src/new/X/showimg/quad_arrow_mask.cursor [new file with mode: 0644]
usr/src/new/X/showimg/shgetopt.c [new file with mode: 0644]
usr/src/new/X/showimg/shimg.h [new file with mode: 0644]
usr/src/new/X/showimg/shopt.h [new file with mode: 0644]
usr/src/new/X/showimg/show.icon.ic [new file with mode: 0644]
usr/src/new/X/showimg/showimg.1 [new file with mode: 0644]
usr/src/new/X/showimg/showimg.c [new file with mode: 0644]
usr/src/new/X/showimg/shutil.c [new file with mode: 0644]
usr/src/new/X/showimg/shzoom.c [new file with mode: 0644]
usr/src/new/X/showimg/shzoom.c.old [new file with mode: 0644]
usr/src/new/X/showimg/wzoom.cursor [new file with mode: 0644]
usr/src/new/X/showimg/wzoom_mask.cursor [new file with mode: 0644]
usr/src/new/X/showimg/zoom2.cursor [new file with mode: 0644]
usr/src/new/X/showimg/zoom2_mask.cursor [new file with mode: 0644]
usr/src/new/X/showimg/zoom4.cursor [new file with mode: 0644]
usr/src/new/X/showimg/zoom4_mask.cursor [new file with mode: 0644]

diff --git a/usr/src/new/X/showimg/Makefile b/usr/src/new/X/showimg/Makefile
new file mode 100644 (file)
index 0000000..8de2d72
--- /dev/null
@@ -0,0 +1,61 @@
+# makefile for showimg
+
+DESTDIR =
+CONFDIR = /usr/users/wyatt/bin
+
+# versions for OIR Vaxen
+CFLAGS = -O -DVAX
+LIBS = -lnm
+#CFLAGS = -DVAX -g -DGLOPEROO
+
+# versions for HEA Sun3 version
+#CFLAGS = -O -DMC68000 -DXRAY
+#CFLAGS = -DMC68000 -g -DGLOPEROO -DXRAY
+#LIBS = -lm
+#XRAYLIBS = -lrosat -lheao -lxray -lU77 -lF77 -lI77
+
+XLIB = -lXMenu -lX
+INCS = shimg.h shopt.h
+CURS = quad_arrow.cursor quad_arrow_mask.cursor\
+       pan.cursor pan_mask.cursor print.cursor print_mask.cursor\
+       zoom2.cursor zoom2_mask.cursor \
+       zoom4.cursor zoom4_mask.cursor \
+       pal.cursor pal_mask.cursor show.icon.ic \
+       wzoom.cursor wzoom_mask.cursor
+SRCS = showimg.c calcmap.c pictio.c menusetup.c shutil.c shzoom.c shgetopt.c
+OBJS = showimg.o calcmap.o pictio.o menusetup.o shutil.o shzoom.o shgetopt.o
+
+PROGRAM = showimg
+
+
+all: showimg
+
+showimg: $(OBJS) /usr/include/X/Xlib.h
+       cc $(CFLAGS) $(OBJS) -o $(PROGRAM) $(XLIB) $(LIBS) $(XRAYLIBS)
+
+install:
+       cp $(PROGRAM) $(CONFDIR)
+clean:
+       rm -f core a.out \#* *.o *~
+
+showimg.o: showimg.c shimg.h shopt.h show.icon.ic
+shgetopt.o: shgetopt.c shimg.h shopt.h
+menusetup.o: menusetup.c shimg.h
+calcmap.o: calcmap.c shimg.h
+pictio.o: pictio.c
+shutil.o: shutil.c $(CURS)
+shzoom.o: shzoom.c wzoom.cursor wzoom_mask.cursor
+
+print: 
+       print Makefile $(SRCS) $(INCS) $(CURS)
+
+itwork: 
+       cp Makefile showimg.1 $(SRCS) $(INCS) $(CURS) $(PROGRAM) Working.version
+
+bbackup:
+       rcp -r Makefile showimg.1 Working.version $(SRCS) $(INCS) $(CURS)\
+       cfa:progs/saodemo
+
+paper:
+       vgrind -lcsh Makefile &
+       vgrind $(INCS) $(CURS) $(SRCS) &
diff --git a/usr/src/new/X/showimg/calcmap.c b/usr/src/new/X/showimg/calcmap.c
new file mode 100644 (file)
index 0000000..3810e96
--- /dev/null
@@ -0,0 +1,62 @@
+/* Calculates gray scale based on mouse offset from window center */
+#include <X/Xlib.h>
+
+#ifdef MC68000
+#include <sys/types.h>
+#endif
+
+#include "shimg.h"
+   
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+
+CalcMap(winfo,cmap,x,y,ncolors,flags,key)
+       WindowInfo *winfo;
+       Color *cmap;
+       int x,y, key;
+       int ncolors;
+       u_short flags;
+{
+       register int intercept,slope,intensity,i;
+
+       if(x<0 || y<=0 || x>=winfo->width-2 || y>winfo->height) return;
+
+       intercept = (((x<<1) - winfo->width)<<16) / winfo->width;
+       slope = ((winfo->height - y)<<16) / y;
+
+       for(i=0; i<ncolors; i++) {
+               intensity = (slope * i)/(ncolors-1) + intercept;
+               intensity = MIN(65535,MAX(intensity,0));
+               if(flags & VOP_Inverse)  intensity = 65535 - intensity;
+               if(flags & VOP_RGB) 
+                   switch((int)key) {
+                       case LeftButton:
+                               cmap[i].red = intensity; break;
+                       case MiddleButton:
+                               cmap[i].green = intensity; break;
+                       case RightButton:
+                               cmap[i].blue = intensity; break;
+                   }
+               else {
+                   cmap[i].red = cmap[i].blue = cmap[i].green = intensity;
+               }
+       }
+       return;
+}
+
+initcmap(ncolors,cmap,pixel,nplanes,flags)
+     int ncolors, nplanes, pixel;
+     Color *cmap;
+     unsigned short flags;
+{
+     int i;
+
+/* Initialize color map to slope 1, intercept 0 */
+     for (i = 0; i < ncolors; i++) {
+       cmap[i].pixel = pixel + i;
+       cmap[i].red = cmap[i].green = cmap[i].blue =
+           ( (flags & VOP_Inverse) ? (65535 - (i << (16 - nplanes))) :
+             (i << (16 - nplanes)));
+     }
+     return;
+}
diff --git a/usr/src/new/X/showimg/d213 b/usr/src/new/X/showimg/d213
new file mode 100644 (file)
index 0000000..dac884b
Binary files /dev/null and b/usr/src/new/X/showimg/d213 differ
diff --git a/usr/src/new/X/showimg/m51 b/usr/src/new/X/showimg/m51
new file mode 100644 (file)
index 0000000..ff0526f
Binary files /dev/null and b/usr/src/new/X/showimg/m51 differ
diff --git a/usr/src/new/X/showimg/menusetup.c b/usr/src/new/X/showimg/menusetup.c
new file mode 100644 (file)
index 0000000..966cbb9
--- /dev/null
@@ -0,0 +1,105 @@
+/* menu selection and setup */
+
+#include <stdio.h>
+#include <X/Xlib.h>
+#include <X/XMenu.h>
+
+#include "shimg.h"
+
+/* This structure is mainly created to easily initialize and update the
+ * menu panes and selections. The null elements indicate to the initializing
+ * routine that that particular pane (and eventually the menu) are complete.
+ *
+ * When a menu selection is successful, it returns a pointer to the data
+ * array in the particular element. The first element contains the pane
+ * number in the upper word and the selection flag in the lower word. The
+ * second element contains the inverse of the mask to be applied to the
+ * corresponding flags location to remove the other panes' selection flags
+ * that are orthogonal to this one. The program can then `or' in this
+ * pane's selection flag (if desireable) and take the appropriate action.
+ */
+
+struct menupane {
+  char *label;
+  int active;
+  int data[2];
+};
+
+struct menupane menuset[] = {
+    /* View Ops pane */
+    { "View Ops",   1, VOP, 0 },
+    { "gray scale", 1, { VOP | VOP_GrayScale, VOP_RGB }  },
+    { "rgb",        1, { VOP | VOP_RGB, VOP_GrayScale }  },
+    { "normal",     1, { VOP | VOP_Normal, VOP_Inverse } },
+    { "inverse",    1, { VOP | VOP_Inverse, VOP_Normal } },
+    { "initialize", 1, { VOP | VOP_Initialize, 0 }       },
+    { "EXIT",       1, { 0, 0 } },
+    { 0, 0, 0, 0 },
+
+    /* Cursor Ops pane */
+    { "Cursor Ops", 1, COP, 0 },
+    { "print",      1, { COP | COP_Print, COP_Pan|COP_Zoom2|COP_Zoom4 } },
+    { "pan",        1, { COP | COP_Pan, COP_Print|COP_Zoom2|COP_Zoom4 } },
+    { "zoom x2",    1, { COP | COP_Zoom2, COP_Print|COP_Pan|COP_Zoom4 } },
+    { "zoom x4",    1, { COP | COP_Zoom4, COP_Print|COP_Pan|COP_Zoom2 } },
+/*  { "set origin", 0, COP | COP_SetOrigin, 0 },
+    { "box",        0, COP | COP_Box, 0       },
+*/  { 0, 0, 0, 0 },
+
+    /* Scaling Ops pane */
+    { "Scaling",   1, SOP, 0 },
+    { "linear",    1, { SOP | SOP_Linear, SOP_Log|SOP_Sqrt|SOP_Histogram }  },
+    { "sqrt",      1, { SOP | SOP_Sqrt, SOP_Linear|SOP_Sqrt|SOP_Histogram } },
+/*  { "log",       0, { SOP | SOP_Log, SOP_Linear|SOP_Log|SOP_Histogram }   },
+    { "histogram", 0, { SOP | SOP_Histogram, SOP_Linear|SOP_Log|SOP_Sqrt }  },
+*/  { 0, 0, 0, 0 },
+    
+    /* File Ops pane */
+/*    { "I/O",        0, FOP, 0 },
+    { "read image", 0, FOP | FOP_Read, 0      },
+    { "flatfield",  0, FOP | FOP_Flatfield, 0 },
+    { "add image",  0, FOP | FOP_AddImage, 0  },
+    { 0, 0, 0, 0 },
+*/  
+    { 0, 0, 0, 0 }
+};
+
+XMenu *menusetup(program)
+     char *program;
+{
+     XMenu *menu, *XMenuCreate();
+     int XMenuAddPane(), XMenuAddSelection(), XMenuRecompute();
+     int pane = 0, sel;
+
+     register struct menupane *imenu = &menuset[0];
+
+     if((menu = XMenuCreate(RootWindow,program)) == NULL) {
+       fprintf(stderr,"Menu creation failed!\n");
+       exit(1);
+     }
+     /* insert the panes & selections into the menu structure */
+       
+     while(imenu->label) {
+       sel = 0;
+       if((XMenuAddPane(menu,imenu->label,imenu->active))
+          == XM_FAILURE) {
+                fprintf(stderr,"Can't add pane %d!\n",pane);
+               exit(1);
+       }
+       ++imenu;
+       while(imenu->label) {
+        if((XMenuAddSelection(menu,pane,(char *)&imenu->data[0],
+              imenu->label,imenu->active)) == XM_FAILURE) {
+               fprintf(stderr,"Can't add selection %d to pane %d!\n",
+                       sel, pane);
+               exit(1);
+             }
+        sel++;
+        ++imenu;
+       }
+       pane++;
+       ++imenu;
+     }
+     XMenuRecompute(menu);
+     return(menu);
+}
diff --git a/usr/src/new/X/showimg/oldstruct.h b/usr/src/new/X/showimg/oldstruct.h
new file mode 100644 (file)
index 0000000..0f6f747
--- /dev/null
@@ -0,0 +1,32 @@
+#ifdef NEWSTRUCT
+    char *geometry = NULL;
+    char filegeometry[30];   /* created from file unless overridden */
+    char *display = NULL;
+    char *border_color, *back_color;
+    OpaqueFrame frame;
+    int border_width;
+    Pixmap border_pixmap;
+    Color cdef;
+    u_short VOP_Flags = VOP_GrayScale | VOP_Initialize;
+    u_short SOP_Flags = SOP_Linear;
+    u_short COP_Flags = 0, COP_OldFlags = 0;
+    u_short FOP_Flags = 0;
+    char *option;
+    int nplanes = -1;  /* number of planes to allocate */
+    int ncolors;
+    int pixels[1];             /* color cell from allocation */
+    int planes;                /* plane mask */
+    Color cmap[256];   /* much larger than can be on CAYLITH */
+    char *filename;
+    unsigned char *image;   /* written to display */
+    short *header;          /* header of real image */
+    short *pict;               /* real image */
+    int pmax = -3000;
+    int pmin = 70000;   /* will be 16-bite max, min values (approx.)*/
+    int shift = 0;
+    int fitsflag = 0;   /* indicator to read in FITS images */
+    /* 1=true FITS, 2=disk FITS (swapped bytes)*/
+    int calibration = 0;
+    int headskip = 0;       /* number of header bytes to skip */
+    int nrows = 0, ncols = 0;
+#endif
diff --git a/usr/src/new/X/showimg/pal.cursor b/usr/src/new/X/showimg/pal.cursor
new file mode 100644 (file)
index 0000000..96809e6
--- /dev/null
@@ -0,0 +1,9 @@
+#define pal_width 16
+#define pal_height 16
+#define pal_x_hot 8
+#define pal_y_hot 8
+static short pal_bits[] = {
+   0x0000, 0x0100, 0x0100, 0x0100,
+   0x0100, 0x0100, 0x0100, 0x0100,
+   0x0100, 0x0100, 0x0100, 0x0100,
+   0x0100, 0x0100, 0x0100, 0x0000};
diff --git a/usr/src/new/X/showimg/pal_mask.cursor b/usr/src/new/X/showimg/pal_mask.cursor
new file mode 100644 (file)
index 0000000..d85a154
--- /dev/null
@@ -0,0 +1,7 @@
+#define pal_mask_width 16
+#define pal_mask_height 16
+static short pal_mask_bits[] = {
+   0x0380, 0x0380, 0x0380, 0x0380,
+   0x0380, 0x0380, 0x0380, 0x0380,
+   0x0380, 0x0380, 0x0380, 0x0380,
+   0x0380, 0x0380, 0x0380, 0x0380};
diff --git a/usr/src/new/X/showimg/pan.cursor b/usr/src/new/X/showimg/pan.cursor
new file mode 100644 (file)
index 0000000..09cfcf9
--- /dev/null
@@ -0,0 +1,9 @@
+#define pan_width 16
+#define pan_height 16
+#define pan_x_hot 0
+#define pan_y_hot 0
+static short pan_bits[] = {
+   0xfffe, 0xffc1, 0xfff1, 0xffe1,
+   0xffc5, 0xff8d, 0xff9f, 0xffff,
+   0xffff, 0xb671, 0xa5ad, 0xa5ad,
+   0x9431, 0x95bd, 0xb5bd, 0xffff};
diff --git a/usr/src/new/X/showimg/pan_mask.cursor b/usr/src/new/X/showimg/pan_mask.cursor
new file mode 100644 (file)
index 0000000..e92fb29
--- /dev/null
@@ -0,0 +1,7 @@
+#define pan_mask_width 16
+#define pan_mask_height 16
+static short pan_mask_bits[] = {
+   0x007e, 0x007f, 0x007f, 0x007f,
+   0x00ff, 0x00ff, 0x00ff, 0x00ff,
+   0xffff, 0xffff, 0xffff, 0xffff,
+   0xffff, 0xffff, 0xffff, 0xffff};
diff --git a/usr/src/new/X/showimg/pictio.c b/usr/src/new/X/showimg/pictio.c
new file mode 100644 (file)
index 0000000..891de10
--- /dev/null
@@ -0,0 +1,321 @@
+
+/* read in image header information - if `headskip' flag is non-zero, read
+ * in that many words, leaving unaltered the input nrows and ncols
+ */
+#include <stdio.h>
+#include <math.h>
+
+#include "shimg.h"  /* flag definitions */
+
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+
+#define HALFBOX 10
+
+short *readheader(fd,headskip,nrows,ncols,fitsflag)
+       int fd, headskip, fitsflag;
+       int *nrows, *ncols;
+{
+       char *malloc(), field[80];
+       short *header;
+       int headlen = 1536;  /* standard SAO Nova CCD header length */
+       int nbytes, rfitscard();
+
+       if(headskip) headlen = headskip;
+       if(fitsflag) headlen = FITSBUFLEN;
+
+       if((header = (short *)malloc(headlen)) == NULL) {
+               fprintf(stderr,"Can't malloc() memory for header!\n");
+               exit(1);
+       }
+       if((nbytes = read(fd,header,headlen)) != headlen) {
+               fprintf(stderr,"?? Only %d bytes in header?\n",nbytes);
+               exit(1);
+       }
+    /* see if FITS decode necessary */
+       if(fitsflag) {
+         rfitsheader(header,ncols,nrows);
+          /* skip past furthur header records until END card */
+         while(rfitscard(header,"END     ",field,1,0) == 0)
+           read(fd,header,FITSBUFLEN);
+       }
+    /* pull the parameters from CCD style header */
+       else if(headskip == 0) {
+               *ncols = header[512+127];
+               *nrows = header[512+126];
+       }
+       return(header);
+}
+
+rfitsheader(fitshead,ncols,nrows)
+     char *fitshead;
+     int *ncols, *nrows;
+{
+     int sscanf(), strlen(), strncmp(), strcmp(), atoi();
+     int rfitscard(), naxis;
+     char field[21];
+
+     rfitscard(fitshead,"SIMPLE  ",field,0,1);
+     if(sscanf(field,"%s",field) != 1) 
+       fitserror(fitshead,"Malformed key field");
+     if(strcmp(field,"T") != 0)
+       fitserror(fitshead,"Only SIMPLE = T capability");
+
+     rfitscard(fitshead+80,"BITPIX  ",field,0,1);
+     if(atoi(field) != 16)
+       fitserror(fitshead+80,"Only 16-bit images at this time");
+
+     rfitscard(fitshead+160,"NAXIS   ",field,0,1);
+     if((naxis = atoi(field)) < 2) 
+       fitserror(fitshead+160,"NAXIS less than 2");
+     else if(naxis > 2) {
+       fprintf(stderr,"** WARNING ** Only first 2 axes will be read. ");
+       fprintf(stderr,"(naxis read was %d)\n",naxis);
+     }
+
+     rfitscard(fitshead+240,"NAXIS1  ",field,0,1);
+     if((*ncols = atoi(field)) <= 0)
+       fitserror(fitshead+240,"NAXIS1 value error");
+
+     rfitscard(fitshead+320,"NAXIS2  ",field,0,1);
+     if((*nrows = atoi(field)) <= 0)
+       fitserror(fitshead+240,"NAXIS2 value error");
+
+}
+
+rfitscard(cardbuf,keyword,keyfield,anywhere,fatal)
+     char *cardbuf, *keyword, *keyfield;
+     int anywhere;       /* if non-zero, search entire buffer for keyword */
+     int fatal;          /* if non-zero, fatal if key not found */
+{
+     char errmsg[80];
+     int sscanf();
+     register int i;
+     
+     for(i=0; i<(anywhere ? FITSBUFLEN : 80); i+=80) {
+       if(strncmp(cardbuf+i,keyword,8) == 0) 
+        return(sscanf(cardbuf+i+10,"%20c",keyfield));
+     }
+     if(fatal) {
+       sprintf(errmsg,"No `%s' keyword",keyword);
+       fitserror(cardbuf,errmsg);   /* fatal error exit */
+     }
+     return(0);
+}
+
+fitserror(card,message)
+     char *card, *message;
+{
+     card[79] = 0;
+     fprintf(stderr,"FITS format error: %s\ncard is:\n%s\n",message, card);
+     exit(1);
+}
+
+short *readpict(fd,nrows,ncols,fitsflag)
+       int fd, nrows, ncols, fitsflag;
+{
+       short *picture;
+        char *malloc();
+       register int nbytes = nrows * ncols * 2;
+       register int nread = 0, ntotal = 0;
+       register char *pict;
+
+       if(fitsflag) nbytes =
+         ((nbytes/FITSBUFLEN) + ((nbytes % FITSBUFLEN) ? 1 : 0))
+           * FITSBUFLEN;
+       if((pict = malloc(nbytes)) == NULL) {
+               fprintf(stderr,"Can't allocate picture memory!\n");
+               exit(1);
+       }
+       picture = (short *)pict;
+       if(fitsflag) {   /* do successive reads until enough bytes */
+         while(ntotal < nbytes) {
+           if((nread = read(fd,pict,FITSBUFLEN)) != FITSBUFLEN) {
+                fprintf(stderr,"Bad record of %d bytes read?\n",nread);
+                exit(1);
+           }
+#ifdef VAX
+           if(fitsflag == 1)  /* do not swap bytes if disk fits format */
+                       swab(pict,pict,nread);
+#endif
+           ntotal += nread;
+           pict += nread;
+         }
+         /* read past EOF, if from tape */
+         if((pict = malloc(FITSBUFLEN)) != NULL) 
+            while(read(fd,pict,FITSBUFLEN) > 0) ;
+       }
+       else if((nbytes = read(fd,picture,nbytes)) != (nrows * ncols)<<1) {
+               fprintf(stderr,"only %d bytes in picture?\n",nbytes);
+               exit(1);
+       }
+       return(picture);
+}
+
+/* VERY SIMPLE 16-bit to n-bit scaling for now. We assume we know a
+ * little something about the picture, so as get best contrast soonest.
+ */
+
+scalepict( byteimage, picture, pmaxval, pminval,
+               ncolors, pixoffset, lshift, nrows, ncols, flags)
+       unsigned char *byteimage;
+       short *picture;
+       int pmaxval, pminval, ncolors, pixoffset, lshift, nrows, ncols;
+       unsigned short flags;
+{
+       register unsigned char *image = byteimage;
+       register short *pict = picture;
+       register unsigned char *lookup;
+       register int npix;
+       register int pint = pmaxval;
+       register int pmin = pminval;
+
+       int i,j;
+       double xpinterval;
+       char *malloc();
+
+       if((lookup = (unsigned char *)malloc(65536)) == NULL) {
+           fprintf(stderr,"Can't allocate lookup table?\n");
+           exit(1);
+       }
+
+       for(npix = 0; npix <= pmin+32768;  ) 
+         lookup[npix++] = pixoffset;
+
+       pmin = pixoffset+ncolors-1;
+       for(npix = pint+32768; npix < 65536; )
+         lookup[npix++] = pmin;
+
+       pmin = MAX(-50,pminval);  /* disallow large negative pixels */
+
+       if(flags & SOP_Linear) {
+       /* disallow large positive pixels here, too */
+         pint = MIN(1000+pmin,pint); 
+
+         pint = (pint - pmin)/ncolors;  /* reus as interval measure */
+/* code added by egm */
+         pint = MAX(pint,1);
+/* end of egm code */
+         ncolors--;
+         for(npix=pmin; npix <= pmaxval; npix++) 
+               lookup[npix+32768] =
+                   (MIN(ncolors,(npix-pmin)/pint)<<lshift) + pixoffset;
+       } 
+  /* a little work will generalize this to logarithmic mapping */
+       else if(flags & SOP_Sqrt) {
+         xpinterval = sqrt((double)(pint - pmin))/(double)ncolors;
+         ncolors--;
+         for(npix=pmin; npix <= pmaxval; npix++) {
+            pint = (int)((sqrt((double)(npix-pmin))/xpinterval) + 0.5);
+             lookup[npix+32768] = 
+                  MIN(ncolors, pint<<lshift) + pixoffset;
+        }
+       }
+       else {
+         fprintf(stderr,"Unknown scaling type request!\n");
+         free(lookup);
+         exit(1);
+       }
+       npix = nrows*ncols;
+       image = byteimage;
+       pict = picture;
+       while(npix--) *image++ = *(lookup + *pict++ + 32768);
+       free(lookup);
+       return;
+}
+
+/* return max, min of data in picture (approximately - sample areas likely
+ * to be of interest.
+ */
+maxminpict( picture, nrows, ncols, pmaxval, pminval)
+       short *picture;
+       int nrows, ncols;
+       int *pmaxval, *pminval;  /* RETURNED */
+
+{
+       register short *pict = picture;
+       register int npix;
+       register int pmax = -32768, pmin = 32767;
+       register int i, j;
+       
+       j = ncols*nrows/2;
+       for(i=ncols/8; i<(7*ncols)/8; i++) {
+           npix = pict[i+j];
+           pmax = MAX(pmax,npix);
+           pmin = MIN(pmin,npix);
+       }
+       i = (7*ncols*nrows)/8 + (ncols>>1);
+       for(j=(nrows*ncols/8)+(ncols>>1); j<i; j+=ncols) {
+           npix = pict[j];
+           pmax = MAX(pmax,npix);
+           pmin = MIN(pmin,npix);
+       }
+       /* find min,max from 5 regions (center, 4 areas around it) */
+       for(i=ncols/2-HALFBOX; i<ncols/2+HALFBOX; i++) {
+           for(j=nrows/8-HALFBOX; j<nrows/8+HALFBOX; j++) {
+               npix = pict[j*ncols+i];
+               pmax = MAX(pmax,npix);
+               pmin = MIN(pmin,npix);
+           }
+           for(j=nrows/2-HALFBOX; j<nrows/2+HALFBOX; j++) {
+               npix = pict[j*ncols+i];
+               pmax = MAX(pmax,npix);
+               pmin = MIN(pmin,npix);
+           }
+           for(j=7*nrows/8-HALFBOX; j<7*nrows/8+HALFBOX; j++) {
+               npix = pict[j*ncols+i];
+               pmax = MAX(pmax,npix);
+               pmin = MIN(pmin,npix);
+           }
+       }
+       for(j=nrows/2-HALFBOX; j<nrows/2+HALFBOX; j++) {
+           for(i=ncols/8-HALFBOX; i<ncols/8+HALFBOX; i++) {
+               npix = pict[j*ncols+i];
+               pmax = MAX(pmax,npix);
+               pmin = MIN(pmin,npix);
+           }
+           for(i=7*nrows/8-HALFBOX; i<7*ncols/8+HALFBOX; i++) {
+               npix = pict[j*ncols+i];
+               pmax = MAX(pmax,npix);
+               pmin = MIN(pmin,npix);
+           }
+       }
+
+/*     printf("pixel range is %d to %d\n",pmin,pmax);  */
+
+       *pminval = pmin;
+       *pmaxval = pmax;
+
+       return;
+}
+
+/* print out a piece of the picture */
+/* 
+ * We really shoud use the environment to get the reverse video
+ * escape sequence. Oh well....
+ */
+prpict(pict, wx, wy, xzero, yzero, ncols, nrows, npcol, nprow)
+     short *pict;
+     int wx, wy, xzero, yzero, ncols, nrows, npcol, nprow;
+{
+     int i, j, k, l;
+
+     printf("\n\nRow %d, Col %d:\n\n       ", wy + yzero, wx + xzero);
+     i = MIN( ncols-npcol, MAX( 0, wx + xzero - npcol/2));
+     for(k=i; k<i+npcol; k++) 
+         if(k == wx + xzero) printf("  %c[7m%4d%c[0m",27,k,27);
+        else printf("  %4d",k);
+     printf("\n       ");
+     for(k=i; k<i+npcol; k++) printf("  ----");
+     j = MIN( nrows-nprow, MAX( 0, wy + yzero - nprow/2));
+     for(k=j; k<j+nprow; k++) {
+         if(k == wy + yzero) printf("\n %c[7m%4d%c[0m |",27,k,27);
+        else printf("\n%5d |",k);
+         for(l=i; l<i+npcol; l++)
+               if((l == wx + xzero) && (k == wy + yzero))
+                  printf(" %c[7m%5d%c[0m",27,pict[ k*ncols + l], 27);
+                else printf("%6d",pict[ k*ncols + l]);
+     }
+     printf("\n");
+     return;
+}
diff --git a/usr/src/new/X/showimg/print.cursor b/usr/src/new/X/showimg/print.cursor
new file mode 100644 (file)
index 0000000..e776a98
--- /dev/null
@@ -0,0 +1,9 @@
+#define print_width 16
+#define print_height 16
+#define print_x_hot 15
+#define print_y_hot 0
+static short print_bits[] = {
+   0x7e00, 0x8200, 0x8e00, 0x8600,
+   0xa300, 0xb180, 0xb880, 0xfc80,
+   0xffff, 0x8231, 0xedad, 0xedad,
+   0xee31, 0xeebd, 0xedbd, 0xffff};
diff --git a/usr/src/new/X/showimg/print_mask.cursor b/usr/src/new/X/showimg/print_mask.cursor
new file mode 100644 (file)
index 0000000..9961a9c
--- /dev/null
@@ -0,0 +1,7 @@
+#define print_mask_width 16
+#define print_mask_height 16
+static short print_mask_bits[] = {
+   0x7e00, 0xfe00, 0xfe00, 0xfe00,
+   0xff00, 0xff80, 0xff80, 0xff80,
+   0xffff, 0xffff, 0xffff, 0xffff,
+   0xffff, 0xffff, 0xffff, 0xffff};
diff --git a/usr/src/new/X/showimg/quad_arrow.cursor b/usr/src/new/X/showimg/quad_arrow.cursor
new file mode 100644 (file)
index 0000000..9c84306
--- /dev/null
@@ -0,0 +1,9 @@
+#define quad_arrow_width 16
+#define quad_arrow_height 16
+#define quad_arrow_x_hot 8
+#define quad_arrow_y_hot 7
+static short quad_arrow_bits[] = {
+   0x0000, 0x0180, 0x03c0, 0x07e0,
+   0x0180, 0x1188, 0x300c, 0x7c3e,
+   0x7c3e, 0x300c, 0x1188, 0x0180,
+   0x07e0, 0x03c0, 0x0180, 0x0000};
diff --git a/usr/src/new/X/showimg/quad_arrow_mask.cursor b/usr/src/new/X/showimg/quad_arrow_mask.cursor
new file mode 100644 (file)
index 0000000..5ebf3f3
--- /dev/null
@@ -0,0 +1,7 @@
+#define quad_arrow_mask_width 16
+#define quad_arrow_mask_height 16
+static short quad_arrow_mask_bits[] = {
+   0x03c0, 0x07c0, 0x07e0, 0x0ff0,
+   0x17e8, 0x3bdc, 0xfc3f, 0xfc3f,
+   0xfc3f, 0xfc3f, 0x3bdc, 0x17e8,
+   0x0ff0, 0x07e0, 0x03c0, 0x03c0};
diff --git a/usr/src/new/X/showimg/shgetopt.c b/usr/src/new/X/showimg/shgetopt.c
new file mode 100644 (file)
index 0000000..56b51b5
--- /dev/null
@@ -0,0 +1,233 @@
+
+/* collect and interpret runtime options for showimg,
+ * 
+ * 8/12/86  Bill Wyatt
+ * 
+ * Also opens the display, since to set up certain color
+ * options, the display must be accessible.
+ */
+
+#include <stdio.h>
+#include <X/Xlib.h>
+
+#include "shimg.h"
+#include "shopt.h"
+
+short gray_bits[16] = {
+    0xaaaa, 0x5555, 0xaaaa, 0x5555,
+    0xaaaa, 0x5555, 0xaaaa, 0x5555,
+    0xaaaa, 0x5555, 0xaaaa, 0x5555,
+    0xaaaa, 0x5555, 0xaaaa, 0x5555};
+
+shgetopt(argc, argv, maininfo, colorinfo, imageinfo)
+     int argc;
+     char *argv[];
+     struct windmain *maininfo;
+     struct colorwind *colorinfo;
+     struct imagewind *imageinfo;
+{
+    Color cdef;
+    char *option, *border_color, *back_color;
+    int i, strcmp(), atoi();
+    char *index();
+
+
+    if ((option = XGetDefault(argv[0],"BorderWidth")) != NULL)
+      maininfo->frame.bdrwidth = atoi(option);
+    else maininfo->frame.bdrwidth = 0;
+
+    if ((border_color = XGetDefault(argv[0],"Border")) == NULL)
+      border_color = XGetDefault(argv[0],"BorderColor");
+
+    back_color = XGetDefault(argv[0],"Background");
+
+
+    for (i = 1; i < argc; i++) {
+       if (argv[i][0] == '=') {
+           maininfo->geometry = argv[i];
+           continue;
+       }
+       if (index(argv[i], ':') != NULL) {        /* host:display */
+           maininfo->display = argv[i];
+           continue;
+       }
+       if (strcmp(argv[i], "-bw") == 0 ||
+           strcmp(argv[i], "-border") == 0) {   /* border width */
+               if (++i >= argc) usage(argv[0]);
+               maininfo->frame.bdrwidth = atoi(argv[i]);
+               continue;
+           }
+       if (strcmp(argv[i], "-bd") == 0 ||
+           strcmp(argv[i], "-color") == 0) {    /* border color */
+               if (++i >= argc) usage(argv[0]);
+               border_color = argv[i];
+               continue;
+           }
+       if(strcmp(argv[i], "-bg") == 0 ||
+          strcmp(argv[i], "background") == 0) {  /* background color */
+              if(++i >= argc) usage(argv[0]);
+              back_color = argv[i];
+              continue;
+          }
+       if (strcmp(argv[i], "-p") == 0 ||
+           strcmp(argv[i], "-planes") == 0) {    /* # of planes */
+               if (++i >= argc) usage(argv[0]);
+               colorinfo->nplanes = 
+                 (atoi(argv[i]) > 8) ? 8 : atoi(argv[i]);
+               continue;
+           }
+       if (strcmp(argv[i],"-n") == 0 ||
+           strcmp(argv[i],"-neg") == 0) {        /* negative map */
+               imageinfo->VOP_Flags |= VOP_Inverse;
+               continue;
+           }
+       if (strcmp(argv[i],"-rgb") == 0) {        /* manipulate RGB */
+           /*   rgbmap++; */
+           imageinfo->VOP_Flags &= ~(VOP_GrayScale);
+           imageinfo->VOP_Flags |= VOP_RGB;
+           continue;
+       }
+       if(strcmp(argv[i],"-skip") == 0 ||
+          strcmp(argv[i],"-sk") == 0)    {       /* skip header */
+              if(++i >= argc) usage(argv[0]);
+              imageinfo->headskip = atoi(argv[i]);
+              if(imageinfo->headskip < 0) usage(argv[0]);
+              continue;
+          }
+       if(strcmp(argv[i],"-nrows") == 0 ||
+          strcmp(argv[i],"-nr") == 0)   {       /* explicit set */
+              if(++i >= argc) usage(argv[0]);
+              imageinfo->nrows = atoi(argv[i]);
+              if(imageinfo->nrows <= 0) usage(argv[0]);
+              continue;
+          }
+       if(strcmp(argv[i],"-ncols") == 0 ||
+          strcmp(argv[i],"-nc") == 0)   {        /* explicit set */
+              if(++i >= argc) usage(argv[0]);
+              imageinfo->ncols = atoi(argv[i]);
+              if(imageinfo->ncols <= 0) usage(argv[0]);
+              continue;
+          }
+       if(strcmp(argv[i],"-sqrt") == 0 ||
+          strcmp(argv[i],"-sq") == 0) {          /* sqrt scaling */
+              imageinfo->SOP_Flags = SOP_Sqrt;
+              continue;
+          }
+       if(strcmp(argv[i],"-test") == 0 ||
+          strcmp(argv[i],"-t") == 0) {          /* test gray scale*/
+              imageinfo->calibration++;
+              continue;
+          }
+       if(strcmp(argv[i],"-saturate") == 0 ||   /* set sat. lev.*/
+          strcmp(argv[i],"-sat") == 0) {
+              if(++i >= argc) usage(argv[0]);
+              if((imageinfo->pmax = atoi(argv[i])) > 16383)
+                usage(argv[0]);
+              continue;
+          }
+       if(strcmp(argv[i],"-threshold") == 0 ||  /* set thresh lev.*/
+          strcmp(argv[i],"-thr") == 0) {
+              if(++i >= argc) usage(argv[0]);
+              if((imageinfo->pmin = atoi(argv[i])) < -16383)
+                usage(argv[0]);
+              continue;
+          }
+       if(strcmp(argv[i],"-fits") == 0) { /* select fits file*/
+           imageinfo->fitsflag = 1;
+           continue;
+       }
+       if(strcmp(argv[i],"-dfits") == 0) { /* select disk fits file*/
+           imageinfo->fitsflag = 2;
+           continue;
+       }
+
+#ifdef XRAY
+       /* added by egm */
+       if(strcmp(argv[i],"-ein") ==0 ){
+           if(++i >= argc) usage(argv[0]);
+           imageinfo->iy = atoi(argv[i]);
+           if(++i >= argc) usage(argv[0]);
+           imageinfo->iz = atoi(argv[i]);
+           if(++i >= argc) usage(argv[0]);
+           imageinfo->zoom = atoi(argv[i]);
+           if(++i >= argc) usage(argv[0]);
+           imageinfo->energy = atoi(argv[i]);
+           imageinfo->ein = 1;
+           imageinfo->ncols = 512;
+           imageinfo->nrows = 512;
+           continue;
+       }
+       
+       if(strcmp(argv[i],"-ros") ==0 ){
+           if(++i >= argc) usage(argv[0]);
+           imageinfo->iy = atoi(argv[i]);
+           if(++i >= argc) usage(argv[0]);
+           imageinfo->iz = atoi(argv[i]);
+           if(++i >= argc) usage(argv[0]);
+           imageinfo->zoom = atoi(argv[i]);
+           imageinfo->ros = 1;
+           imageinfo->ncols = 512;
+           imageinfo->nrows = 512;
+           continue;
+       }
+       /* end of egm code */
+#endif
+       
+       if (argv[i][0] == '-') usage(argv[0]);
+       imageinfo->filename = argv[i];
+    }
+
+
+/* do some consistency checks on selected options */
+    if(imageinfo->headskip > 0 && 
+       (imageinfo->nrows == 0 || imageinfo->ncols == 0)) usage(argv[0]);
+    
+    if((imageinfo->pmax == -3000 && imageinfo->pmin != 70000) ||
+       (imageinfo->pmin == 70000 && imageinfo->pmax != -3000)) 
+      usage(argv[0]);
+    
+    if(imageinfo->fitsflag != 0 && 
+       (imageinfo->headskip > 0 || imageinfo->nrows != 0 || 
+       imageinfo->ncols != 0))
+      usage(argv[0]);
+    
+    if (!XOpenDisplay(maininfo->display)) {
+       perror(argv[0]);
+       exit(1);
+    }
+
+    if (border_color && DisplayCells() > 2 &&
+       XParseColor(border_color, &cdef) && XGetHardwareColor(&cdef))
+      maininfo->frame.border = XMakeTile(cdef.pixel);
+    else if (border_color && strcmp(border_color, "black") == 0)
+      maininfo->frame.border = BlackPixmap;
+    else if (border_color && strcmp(border_color, "white") == 0)
+      maininfo->frame.border = WhitePixmap;
+    else
+      maininfo->frame.border = XMakePixmap (XStoreBitmap (16, 16, gray_bits),
+                                  BlackPixel, WhitePixel);
+
+    if (back_color && DisplayCells() > 2 &&
+       XParseColor(back_color, &cdef) && XGetHardwareColor(&cdef))
+      maininfo->frame.background = XMakeTile(cdef.pixel);
+    else if (back_color && strcmp(back_color, "white") == 0)
+      maininfo->frame.background = WhitePixmap;
+    else 
+      maininfo->frame.background = BlackPixmap;
+    
+    return;
+}
+
+
+usage (program)
+    char *program;
+{
+    fprintf(stderr,"usage: %s [ options ] filename\n",program);
+    fprintf(stderr,"     where options are one or more of:\n");
+    fprintf(stderr,"  [host:display] [=geom] [-bw] [-bd] [-bg]\n");
+    fprintf(stderr,"  [-planes #] [-rgb] [-neg] [-sqrt]\n");
+    fprintf(stderr,"  [-skip # -nrows # -ncols #]\n");
+    fprintf(stderr,"  [-saturate # -threshold #]\n");
+    fprintf(stderr,"  [-fits] [ -dfits ]\n");
+    exit(1);
+}
diff --git a/usr/src/new/X/showimg/shimg.h b/usr/src/new/X/showimg/shimg.h
new file mode 100644 (file)
index 0000000..60fe927
--- /dev/null
@@ -0,0 +1,37 @@
+/* defaults for subwindow stuff */
+
+#define PALBORDER 1
+#define PALHEIGHT 32
+
+/* operation flags for image display, manipulation operations */
+
+#define PANEMASK 0xffff0000
+#define SELMASK 0xffff
+
+#define VOP  0x10000
+#define VOP_GrayScale  0x01
+#define VOP_RGB        0x02
+#define VOP_Normal     0x04
+#define VOP_Inverse    0x08
+#define VOP_Initialize 0x10
+
+#define COP  0x20000
+#define COP_Print      0x01
+#define COP_Pan        0x02
+#define COP_Zoom2      0x04
+#define COP_Zoom4      0x08
+#define COP_Box        0x10
+#define COP_SetOrigin  0x20
+
+#define SOP  0x40000
+#define SOP_Linear     0x01
+#define SOP_Log        0x02
+#define SOP_Sqrt       0x04
+#define SOP_Histogram  0x08
+
+#define FOP  0x80000
+#define FOP_Read       0x01
+#define FOP_Flatfield  0x02
+#define FOP_AddImage   0x04
+
+#define FITSBUFLEN 2880
diff --git a/usr/src/new/X/showimg/shopt.h b/usr/src/new/X/showimg/shopt.h
new file mode 100644 (file)
index 0000000..94cdb4e
--- /dev/null
@@ -0,0 +1,58 @@
+/* 
+ * Structures to facilitate option passing in showimg.
+ */
+
+/* main window structures */
+struct windmain {
+    char *display;             /* display name */
+    char filegeometry[30];     /* geometry from file */
+    char *geometry;            /* geometry from command line, if any */
+    OpaqueFrame frame;         /* main window descriptor */
+    WindowInfo winfo;          /* main window information struct */
+    Cursor windcursor;         /* current main window cursor */
+    Cursor lastcursor;         /* previous cursor */
+};
+
+/* Color info */
+struct colorwind {
+    int nplanes;               /* number of color planes */
+    int pixels[1];             /* base for color map */
+    int ncolors;               /* number of colors used */
+    int planes;                /* planes mask */
+    int shift;                 /* #left shifts to adjust zero-based */
+                               /*     pixels to pixels[1] */
+    Color cmap[256];           /* GPX max color map limited to 256 */
+};
+
+/* image, image info, options, operational flags */
+struct imagewind {
+    char *filename;
+    short *header;             /* header data from file */
+    short *picture;            /* 16-bit image */
+    unsigned char *image;      /* 8-bit (or fewer) displayed image */
+    int nrows;
+    int ncols;
+    int pmin;                  /* high min pixel flags not set */
+    int pmax;                  /* low max pixel flags not set */
+    int headskip;              /* bytes to skip before reading */
+    int calibration;           /* flag for test pattern */
+    int fitsflag;              /* file format indicator */
+
+#ifdef XRAY
+    /* added by egm */
+
+    int ein; /* flag for Einstein xray data */
+    int ros; /* flag for Rosat xray data */
+    int iy, iz, zoom, energy; /* parameters on -xray switch */
+    short int ict[513]; /* image file control table */
+    int muthict[2400];  /* it's a muther ict table */
+    char poename[132], hdrname[132];
+    
+    /* end of egm code */
+#endif
+
+    u_short VOP_Flags;
+    u_short SOP_Flags;
+    u_short COP_Flags;
+    u_short FOP_Flags;
+};
diff --git a/usr/src/new/X/showimg/show.icon.ic b/usr/src/new/X/showimg/show.icon.ic
new file mode 100644 (file)
index 0000000..afb351a
--- /dev/null
@@ -0,0 +1,51 @@
+#define show_width 48
+#define show_height 64
+static short show_bits[] = {
+   0xffff, 0xffff, 0xffff, 0xffff,
+   0xffff, 0xffff, 0x0003, 0x0000,
+   0xc000, 0x0003, 0x0000, 0xc000,
+   0x4803, 0x0000, 0xc000, 0x0003,
+   0x0000, 0xc000, 0x0003, 0x0000,
+   0xc000, 0x0003, 0x0000, 0xc000,
+   0x0003, 0x0000, 0xc000, 0x0007,
+   0x0000, 0xc000, 0x0003, 0x0000,
+   0xc010, 0x8003, 0x0011, 0xc000,
+   0xe003, 0x1000, 0xc000, 0x7003,
+   0x0000, 0xc600, 0x3003, 0x0000,
+   0xc200, 0x1803, 0x0000, 0xc300,
+   0x1c03, 0x1e00, 0xc780, 0x0c03,
+   0x3f00, 0xc780, 0x0c03, 0x7380,
+   0xc780, 0x0c03, 0xe1c0, 0xc300,
+   0x0e03, 0xc0c0, 0xc101, 0x0e03,
+   0x81e0, 0xc183, 0x0603, 0x01e0,
+   0xc007, 0x0603, 0x01e0, 0xc007,
+   0x4603, 0x01e0, 0xc006, 0x4603,
+   0x03f0, 0xc00e, 0x0603, 0x07f8,
+   0xc00c, 0x0603, 0x07f8, 0xc01c,
+   0x0e03, 0x0ffc, 0xc01c, 0x0e03,
+   0x07f8, 0xc018, 0x0c03, 0x07f8,
+   0xc018, 0x1c03, 0x03f0, 0xc018,
+   0x1803, 0x01e0, 0xc018, 0x380b,
+   0x01e0, 0xc018, 0x3803, 0x01e0,
+   0xc018, 0x7003, 0x01e0, 0xc61c,
+   0xe003, 0x10c0, 0xc61c, 0xc003,
+   0x10e1, 0xc00c, 0x8003, 0x0073,
+   0xc00c, 0x0003, 0x003f, 0xc00c,
+   0x0003, 0x001e, 0xc00e, 0x0003,
+   0x0000, 0xc006, 0x0003, 0x0000,
+   0xc003, 0x0043, 0x8000, 0xc003,
+   0x0003, 0xc000, 0xc001, 0x0003,
+   0x6000, 0xc000, 0x0003, 0x0000,
+   0xc000, 0x0003, 0x0000, 0xc000,
+   0x0003, 0x0000, 0xc000, 0x0003,
+   0x0000, 0xc000, 0x0003, 0x0040,
+   0xc000, 0x0003, 0x0000, 0xc100,
+   0x0403, 0x0000, 0xc000, 0x0803,
+   0x0000, 0xc000, 0x0003, 0x0000,
+   0xc000, 0x0003, 0x0000, 0xc000,
+   0x0003, 0x0000, 0xc000, 0x0003,
+   0x0000, 0xc000, 0x0003, 0x0000,
+   0xc020, 0x0003, 0x0010, 0xc000,
+   0x0003, 0x0000, 0xc000, 0x0013,
+   0x0100, 0xc000, 0xffff, 0xffff,
+   0xffff, 0xffff, 0xffff, 0xffff};
diff --git a/usr/src/new/X/showimg/showimg.1 b/usr/src/new/X/showimg/showimg.1
new file mode 100644 (file)
index 0000000..c36d4e0
--- /dev/null
@@ -0,0 +1,101 @@
+\" -*-nroff-*-
+.TH SHOWIMG 1 "21 February 1986" "CfA Additions"
+.SH NAME
+showimg \- display CCD\-format images under X windows
+.SH SYNTAX
+.B showimg
+[ \fIoptions\fR ] \fIfilename\fR
+.SH DESCRIPTION
+A CCD file or FITS-format file containing header information and
+16-bit image data is read into memory and presented for display
+highlighting under the X window system. Mouse and cursor manipulations
+allow the control of several interactive functions.  Besides the
+options listed below, the usual menu and window options as documented
+in the \fBX\fR and \fBXMenu\fR manual pages are available, either as
+inputs to the command line or in the \fI.Xdefaults\fR file.
+.SH OPTIONS
+.TP 6
+.B \-planes \fIn\fB
+Allocate \fIn\fR planes to the display image. This will use 2**n colors or
+gray levels.
+.TP 6
+.B \-rgb
+Default to red\-green\-blue color selection on startup instead of gray scale.
+.TP 6
+.B \-neg
+Default to inverse video on startup.
+.TP 6
+.B \-sqrt
+Default to square root mapping on startup instead of linear.
+.TP 6
+.BI \-threshold\  tnum
+Use \fItnum\fR as the threshold level for scaling the 16\-bit image
+instead of the one determined automatically.
+.TP 6
+.BI \-saturate\  snum
+Use \fIsnum\fR as the saturation level for scaling the 16\-bit image
+instead of the one determined automatically.
+.TP 6
+.B -fits
+Assume FITS format. Checks that `SIMPLE = T' and that `BITPIX = 16', 
+and reads the size from `NAXIS1' and `NAXIS2'. The image will be read with
+2880\-byte reads and the 16\bit integers byte-swapped if on a VAX.
+.TP 6
+.B -dfits
+Assume `disk' FITS format. On a VAX this assumes the integers do not need
+to be byte-swapped; otherwise this option is identical to \fI\-fits\fR.
+Checks that `SIMPLE = T' and that `BITPIX = 16', and reads the size from
+`NAXIS1' and `NAXIS2'. The image will be read with 2880\-byte reads.
+.TP 6
+.BI \-skip\  hbytes \ \-nrows \ nr \ \-ncols \ nc
+Do not read image size information from the header (either FITS or CfA CCD);
+skip \fIhbytes\fR bytes
+of information at the beginning of the file instead. The image is \fInc\fR
+columns by \fInr\fR rows of 16-bit pixels. This option can be used to read and
+display images in `foreign' formats.
+.SH Mouse Control
+By default the picture comes up with a linear intensity gray scale. Pressing
+any mouse button, with or without mouse motion, causes the intensities 
+displayed to change. Holding down the control button while pressing a mouse
+button causes a pop\-up menu to appear, providing furthur choices. Releasing 
+the button while pointing to an active selection chooses that selection.
+.PP
+The first pop-up menu selects other functions such as reinitialization to the
+default intensity map, display in red\-green\-blue or gray scale, and inverse
+versus normal video.
+.IP 
+Motion in the horizontal direction while holding down a mouse button down
+corresponds to a 
+change in the threshold or background levels displayed. Motion in the vertical
+direction with a mouse button down changes the contrast. The center of the
+window is considered the default or null point.
+.IP
+If the \-rgb option is selected, either in the command line or via the pop\-up
+menu, the left, middle, and right mouse buttons control the red, green, and
+blue intensity, respectively.
+.PP
+The second menu selects secondary cursor\-activated options: printing,
+panning, and zoom\-in. As each of these is selected, the mouse cursor changes
+to reflect the intended operation. 
+.IP
+Clicking any mouse button with the print option selected prints the 16-bit 
+pixel value under that point, and the pixels atround it in an 11x11 grid.
+.IP
+Under the pan and zoom options, the picture is redisplayed centered around the
+point under the cursor when clicked. If the point is too close to the edge of
+the display window, the point may not actually be displayed in the center. The
+zoom options (x2 and x4) magnify the picture via pixel replication.
+.PP
+The third menu select on of two functions to map the 16-bit intensities into
+the n-bit intensities loaded into the GPX memory: linear and sqrt. The latter
+is useful to relatively de-empahsize the contrast between background and
+bright pixels. After recalculating the mapping, the entire picture will be 
+redrawn with the new pixels in the GPX.
+.SH BUGS
+.PP
+Needs a histogram display function to allow interactive setting of threshold
+and saturation values.
+Should have a true color palette instead of the rgb control to provide 
+independent colors. Needs more types of mapping.
+.SH AUTHOR
+William F. Wyatt, Smithsonian Astrophysical Observatory.
diff --git a/usr/src/new/X/showimg/showimg.c b/usr/src/new/X/showimg/showimg.c
new file mode 100644 (file)
index 0000000..545ebc7
--- /dev/null
@@ -0,0 +1,820 @@
+/* Program to display images on uVax II/GPX under the X window system.
+ *
+ * Bill Wyatt and Jim Gettys, Feb. 12 1986 et. seq.
+ *
+ * 4/23/86 WFW
+ *     Added FITS file reading capability, selected via -fits option.
+ *
+ * 7/86  WFW
+ *     Added disk fits format via -dfits option, for not swapping bytes,
+ *     but file otherwise in disk format.
+ *
+ * 7/86  WFW
+ *     Added palette subwindow, zoomx4 window, independently resizeable.
+ *
+ * 8/11/86  WFW
+ *     If the palette window needs to be independent instead of a subwindow,
+ *     then compile with PALWIND defined.
+ * 
+ * 8/13/86 WFW
+ *     Added  ifdef support from Eric Mandel for ROSAT & Einstein images
+ */
+
+#include <stdio.h>
+#include <sys/file.h>
+#include <X/Xlib.h>
+#include <X/XMenu.h>
+#include <X/Xkeyboard.h>
+
+#ifdef MC68000
+#include <sys/types.h>
+#endif
+
+#include "show.icon.ic"
+
+#include "shimg.h"
+#include "shopt.h"
+
+#define TESTDEFAULT "=512x512+100+134"
+#define PICTDEFAULT "+50+100"
+#define TESTNROWS  512
+
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+
+main(argc, argv)
+int argc;
+char **argv;
+{
+    struct windmain  maininfo;
+    struct colorwind colorinfo;
+    struct imagewind imageinfo;
+
+    Window wind, subwind, palwind, wzoom;
+    Window iconwindow, iconwzoom;
+#ifdef PALWIND
+    Window iconpalwind;   /* palette window is independent, needs icon */
+#endif
+    WindowInfo winfo, palwinfo, wzoominfo;
+
+
+    Cursor imcursor, pancursor, printcursor, zoom2cursor, zoom4cursor;
+    Cursor palcursor;
+    int xcenter = -1;
+    int ycenter = -1;      /* nominal center of displayed image  */
+    int xtempzero, ytempzero;
+    int xzoomsize = 124, yzoomsize = 124;
+    XMenu *showmenu, *menusetup();
+    int XMenuSetFreeze(), XMenuActivate();
+    int *currentflags;
+    int pane = 0, sel = 0;
+    int lastpane = 0, lastsel = 0;
+    unsigned char palette[2048]; /* palette window array */
+    short *readheader(), *readpict();
+    int scalepict();
+    int zoomfactor = 0;     /* replication factor for pixel display */
+    int oldzoomfactor = 0;
+    int fd, open(), close(), ipow();
+    int w_mapped = 1;
+    int rshift = 0;
+    int keycode = 0;
+    int xbut, ybut;
+    char *malloc();
+    char *keystring;  
+    int j, k, l;
+    
+    XEvent event, peekevent;
+    XExposeEvent               *expw  = (XExposeEvent *)&event;
+    register XKeyOrButtonEvent *but   = (XButtonEvent *)&event;
+    register XMouseMovedEvent  *mouse = (XMouseMovedEvent *)&event;
+    
+    register int downbutton = -1; /* mouse button flag */
+    register int xzero, yzero;   /* image coordinates of window(0,0) */
+    register int i;
+    
+
+/* **** MAIN EXECUTION CODE STARTS HERE  **** */
+
+    maininfo.display = NULL;
+    colorinfo.nplanes = -1;
+    imageinfo.pmin = 70000;
+    imageinfo.pmax = -3000;
+    imageinfo.headskip = 0;
+    imageinfo.calibration = 0;
+    imageinfo.fitsflag = 0;
+
+#ifdef XRAY
+    imageinfo.ein = 0;
+    imageinfo.ros = 0;  
+#endif
+
+    imageinfo.VOP_Flags = VOP_GrayScale | VOP_Initialize;
+    imageinfo.SOP_Flags = SOP_Linear;
+    imageinfo.COP_Flags = 0;
+    imageinfo.FOP_Flags = 0;
+
+    shgetopt(argc, argv, &maininfo, &colorinfo, &imageinfo);
+
+    /* create the cursors */
+    make_cursors(&imcursor,&pancursor,&printcursor,
+                &zoom2cursor, &zoom4cursor, &palcursor);
+    
+    /* try for 8 planes (probably only gets 6) */
+    if (colorinfo.nplanes < 0) 
+      colorinfo.nplanes = MAX(DisplayPlanes()-4,8);
+    
+    /* iterate until cells allocated. Check if enough */
+    if (XGetColorCells(1, 1, colorinfo.nplanes, 
+                      &colorinfo.planes, &(colorinfo.pixels[0])) == 0) 
+      {
+          while(--colorinfo.nplanes > 2)
+           if(XGetColorCells(1,1,colorinfo.nplanes,
+                             &colorinfo.planes,
+                             &(colorinfo.pixels[0])) != 0)  break;
+         if(colorinfo.nplanes <= 2) {
+             fprintf(stderr,"Insufficient color planes resource!\n");
+             exit(1);
+         }
+         if(colorinfo.nplanes < 6) 
+           fprintf(stderr, "Allocated %d planes\n",colorinfo.nplanes);
+      }
+
+    colorinfo.ncolors = ipow(2, colorinfo.nplanes);
+
+    /* figure out how many bits we have to left shift the pixels */
+    colorinfo.shift = 0;
+    i = colorinfo.pixels[0] | colorinfo.planes;
+    while (((i >>= 1) & 1) == 0) colorinfo.shift++;
+
+    /* get the menu selections ready */
+    showmenu = menusetup(argv[0]);
+
+    if(imageinfo.calibration) { /** GENERATE TEST SCREEN */
+       imageinfo.ncols = imageinfo.nrows = TESTNROWS;
+       rshift = DisplayPlanes() - colorinfo.nplanes - colorinfo.shift;
+       if((imageinfo.image = 
+           (unsigned char *)malloc(imageinfo.nrows*imageinfo.ncols))
+          == NULL) {
+           fprintf(stderr,"Can't allocate test image!\n");
+           exit(1);
+       }
+       for (j = 0; j < imageinfo.nrows; j++)
+         for (i = 0; i < imageinfo.ncols; i++)
+           *(imageinfo.image + j*imageinfo.ncols + i) = 
+             ((((i + j)&255) >> rshift) & colorinfo.planes)
+               + colorinfo.pixels[0];
+       
+       wind = XCreate(argv[0], argv[0], 
+                      maininfo.geometry, TESTDEFAULT, &maininfo.frame,
+                      100, 134);
+    }
+    else {  /** READ IN IMAGE **/
+
+#ifdef XRAY
+       /* code and conditional added by egm */
+
+       if( imageinfo.ein == 1 ){
+           eimgopen(imageinfo.ict, imageinfo.filename);
+       }
+       else if( imageinfo.ros == 1 ){
+           strcpy(imageinfo.poename, imageinfo.filename);
+           strcat(imageinfo.poename, ".poe");
+           strcpy(imageinfo.hdrname, imageinfo.filename);
+           strcat(imageinfo.hdrname, ".hdr");
+           openpoe(imageinfo.muthict, imageinfo.poename, imageinfo.hdrname);
+       }
+       else {
+#endif
+
+           if((fd = open(imageinfo.filename,O_RDONLY,0)) < 0) {
+               fprintf(stderr,"Error opening file %s\n",imageinfo.filename);
+               exit(1);
+           }
+           if((imageinfo.header =
+               readheader(fd,imageinfo.headskip,
+                          &imageinfo.nrows,&imageinfo.ncols,
+                          imageinfo.fitsflag))
+              == NULL) {
+                  fprintf(stderr,"Error reading header of file %s\n",
+                          imageinfo.filename);
+                  exit(1);
+           }
+
+#ifdef PALWIND
+           sprintf(maininfo.filegeometry,"=%dx%d%s",imageinfo.ncols, 
+                   imageinfo.nrows, PICTDEFAULT);
+#else
+           sprintf(maininfo.filegeometry,"=%dx%d%s",imageinfo.ncols,
+                   imageinfo.nrows+PALHEIGHT+2*PALBORDER, PICTDEFAULT);
+#endif 
+
+#ifdef XRAY
+       }  /* end of conditional code added by egm */
+#endif
+
+       if((imageinfo.image = 
+           (unsigned char *)malloc(imageinfo.nrows*imageinfo.ncols))
+          == NULL) {
+           fprintf(stderr,"Can't allocate byte image?\n");
+           exit(1);
+       }
+
+#ifdef XRAY
+       /* conditional added by egm */
+
+       if( imageinfo.ein == 1 ) {   /* Einstein XRAY image */
+           if((imageinfo.picture = 
+               (short *)malloc(imageinfo.nrows*imageinfo.ncols*2)) == NULL) {
+                 fprintf(stderr,"Can't allocate xray image?\n");
+                 exit(1);
+               }
+           eimgread(imageinfo.ict,imageinfo.picture, 
+                    imageinfo.ncols, imageinfo.nrows, 
+                    imageinfo.iy, imageinfo.iz, 
+                    imageinfo.zoom,imageinfo.zoom, imageinfo.energy);
+       }
+       else if( imageinfo.ros == 1) {   /* ROSAT XRAY image */
+           selectcenter(imageinfo.muthict, imageinfo.iy, imageinfo.iz);
+           selectres(imageinfo.muthict, imageinfo.zoom, imageinfo.zoom);
+           if((imageinfo.picture = 
+               (short *)malloc(imageinfo.nrows*imageinfo.ncols*2)) == NULL) {
+                 fprintf(stderr,"Can't allocate xray image?\n");
+                 exit(1);
+           }
+           readpoe(imageinfo.muthict, imageinfo.picture, 
+                   imageinfo.ncols, imageinfo.nrows);
+       }
+       else { 
+#endif
+         /* SAOCCD or FITS image */
+           if((imageinfo.picture =
+               readpict(fd,imageinfo.nrows,imageinfo.ncols,
+                        imageinfo.fitsflag)) == NULL) {
+               fprintf(stderr,"Error reading file %s\n",imageinfo.filename);
+               exit(1);
+           }
+           close(fd);
+
+#ifdef XRAY
+       }  /* end of conditional added by egm */
+#endif
+
+       if(imageinfo.pmin == 70000 && imageinfo.pmax == -3000)
+         maxminpict(imageinfo.picture, imageinfo.nrows, imageinfo.ncols,
+                    &imageinfo.pmax, &imageinfo.pmin);
+       scalepict(imageinfo.image, imageinfo.picture, 
+                 imageinfo.pmax, imageinfo.pmin,
+                 colorinfo.ncolors, colorinfo.pixels[0], colorinfo.shift,
+                 imageinfo.nrows, imageinfo.ncols, imageinfo.SOP_Flags);
+       wind = XCreate(argv[0], argv[0], 
+                      maininfo.geometry, maininfo.filegeometry,
+                      &maininfo.frame, 100, 100);
+    }
+    if (wind == 0) { 
+       fprintf(stderr, "XCreate on root failed\n");
+       exit(1);
+    }
+       
+    /* get current info so as to be ready for subwindow placing */
+    XQueryWindow(wind, &winfo);
+    
+    if((iconwindow =
+       XCreateWindow(RootWindow, 0, 0,
+                     show_width, show_height, 0, 0, 0)) == 0)
+      {
+         fprintf(stderr, "XCreateWindow on iconwindow failed\n");
+         exit(1);
+      }
+    XSetIconWindow(wind, iconwindow);
+
+#ifdef PALWIND 
+    if((palwind = XCreateWindow(RootWindow, winfo.x,
+                               winfo.y+winfo.height,
+                               winfo.width,
+                               PALHEIGHT, border_width,
+                               maininfo.frame.border, BlackPixmap))
+       == 0) {
+          fprintf(stderr, "XCreateWindow on palwind failed\n");
+          exit(1);
+       }
+    XStoreName(palwind, argv[0]);
+#else
+    if((palwind = XCreateWindow(wind, 0,
+                               winfo.height-PALHEIGHT-2*PALBORDER,
+                               winfo.width-2*PALBORDER,
+                               PALHEIGHT, PALBORDER,
+                               WhitePixmap, BlackPixmap)) == 0) {
+                                   fprintf(stderr, "XCreateWindow on palwind failed\n");
+                                   exit(1);
+                               }
+#endif
+    if((wzoom = XCreateWindow(RootWindow, 
+                             winfo.x+winfo.width+
+                             maininfo.frame.bdrwidth,
+                             winfo.y,
+                             xzoomsize, yzoomsize, 
+                             maininfo.frame.bdrwidth,
+                             maininfo.frame.border, BlackPixmap)) == 0)
+      {
+         fprintf(stderr, "XCreateWindow on wzoom failed\n");
+         exit(1);
+      }
+    XStoreName(wzoom, argv[0]);
+    
+    if((iconwzoom = XCreateWindow(RootWindow, 0, 0,
+                                  show_width, show_height, 0, 0, 0)) == 0) {
+       fprintf(stderr, "XCreateWindow on iconwzoom failed\n");
+       exit(1);
+    }
+    XSetIconWindow(wzoom, iconwzoom);
+
+#ifdef PALWIND
+    if((iconpalwind = XCreateWindow(RootWindow, 0, 0,
+                                  show_width, show_height, 0, 0, 0)) == 0) {
+        fprintf(stderr, "XCreateWindow on iconpalwind failed\n");
+        exit(1);
+    }
+    XSetIconWindow(palwind, iconpalwind);
+#endif
+
+    /* define the cursors */
+    XUndefineCursor(wind);
+    XDefineCursor(wind,imcursor);
+    
+    XUndefineCursor(palwind);
+    XDefineCursor(palwind,palcursor);
+    
+    /* assume we display center of image in center of window */
+    if(xcenter < 0) xcenter = imageinfo.ncols>>1;
+    if(ycenter < 0) ycenter = imageinfo.nrows>>1;
+    
+    XSelectInput(wind, ButtonPressed | ButtonReleased | MouseMoved |
+                KeyPressed |
+                ExposeRegion | ExposeWindow | ExposeCopy | UnmapWindow);
+    XSelectInput(iconwindow, ExposeWindow); 
+
+    XSelectInput(wzoom, ExposeWindow | UnmapWindow);
+    XSelectInput(iconwzoom, ExposeWindow); 
+
+#ifdef PALWIND
+    XSelectInput(palwind, ExposeWindow | UnmapWindow);
+    XSelectInput(iconpalwind, ExposeWindow); 
+#else
+    XSelectInput(palwind, ExposeWindow);
+#endif
+
+    XMapWindow(wind);
+    XMapWindow(wzoom);
+
+#ifdef PALWIND
+    XMapWindow(palwind);
+#else
+    XMapSubwindows(wind); 
+#endif
+
+    XFlush();
+
+    while(1) {
+       if(imageinfo.VOP_Flags & VOP_Initialize) {
+           initcmap(colorinfo.ncolors,colorinfo.cmap,
+                    colorinfo.pixels[0],colorinfo.nplanes,
+                    imageinfo.VOP_Flags);
+           XStoreColors(colorinfo.ncolors, colorinfo.cmap);
+           imageinfo.VOP_Flags &= ~(VOP_Initialize);
+       }
+       
+       XNextEvent(&event);
+       
+#ifdef GLOPEROO
+       describe_XEvent(event.type, event.window, but->detail,
+                       wind, palwind, wzoom);
+#endif
+       switch((int)event.type) {
+         case KeyPressed:
+
+#ifdef VAX
+           keycode = but->detail & 0x00ff;
+           if(IsCursorKey(keycode)) {
+               XUpdateMouse(wind,&mouse->x,&mouse->y,&subwind);
+               i = 1<<zoomfactor;
+               if(keycode == KC_CURSOR_UP)    mouse->y -= i;
+               if(keycode == KC_CURSOR_DOWN)  mouse->y += i;
+               if(keycode == KC_CURSOR_RIGHT) mouse->x += i;
+               if(keycode == KC_CURSOR_LEFT)  mouse->x -= i;
+               if(mouse->x < 0) mouse->x = 0;
+               if(mouse->y < 0) mouse->y = 0;
+               if(mouse->x >= winfo.width) mouse->x = winfo.width-1;
+               if(mouse->y >= winfo.height-PALHEIGHT-2*PALBORDER)
+                   mouse->y = winfo.height-PALHEIGHT-2*PALBORDER-1;
+               XWarpMouse(wind,(int)mouse->x,(int)mouse->y);
+           }
+#else
+           keystring = XLookupMapping(but, &j);
+                /* ANSI cursor keys are esc. seq. */
+           if(j > 0 && *keystring == '\033') {
+               i = 1<<zoomfactor;
+               if(strcmp(keystring,"\033[A") == 0) mouse->y -= i; /* up */
+               if(strcmp(keystring,"\033[B") == 0) mouse->y += i; /* down */
+               if(strcmp(keystring,"\033[C") == 0) mouse->x += i; /* right */
+               if(strcmp(keystring,"\033[D") == 0) mouse->x -= i; /* left */
+               if(mouse->x < 0) mouse->x = 0;
+               if(mouse->y < 0) mouse->y = 0;
+               if(mouse->x >= winfo.width) mouse->x = winfo.width-1;
+               if(mouse->y >= winfo.height-PALHEIGHT-2*PALBORDER)
+               XWarpMouse(wind,(int)mouse->x,(int)mouse->y);
+           }
+#endif
+           break;
+
+         case ButtonPressed:   /* Activate Menu ? */
+           if((but->detail & 
+               (ControlMask | MetaMask | ShiftMask | ShiftLockMask))
+              == ControlMask)
+             {
+                 XQueryWindow(wind, &winfo);
+                 XMenuSetFreeze(showmenu);
+                 pane = lastpane;
+                 sel = lastsel;
+                 if(XMenuActivate(showmenu,&pane,&sel,
+                                  but->x + winfo.x, but->y + winfo.y,
+                                  ButtonReleased, &currentflags)
+                    == XM_SUCCESS) {  /* check out the selection */
+                        lastpane = pane;
+                        lastsel = sel;
+
+                        switch(*currentflags & PANEMASK) {
+                     /* EXIT */
+                          case 0: 
+                            exit(0); /* normal exit */
+
+                     /* Set `viewing mode' - manipulation of color map */
+                          case VOP:
+                            imageinfo.VOP_Flags &= ~(currentflags[1]);
+                            imageinfo.VOP_Flags |= 
+                              (*currentflags & SELMASK);
+                            XUndefineCursor(wind);
+                            XDefineCursor(wind, imcursor);
+                            imageinfo.COP_Flags = 0;
+                            break;
+
+                      /* Set cursor mode - other uses than above */
+                          case COP:
+                            /* if in test mode, disable all but viewing */
+                            if(imageinfo.calibration) break;
+                            imageinfo.COP_Flags &= ~(currentflags[1]);
+                            imageinfo.COP_Flags |= 
+                              (*currentflags & SELMASK);
+                            if(imageinfo.COP_Flags & COP_Print) {
+                                XUndefineCursor(wind);
+                                XDefineCursor(wind, printcursor);
+                            } else if(imageinfo.COP_Flags & COP_Pan) {
+                                XUndefineCursor(wind);
+                                XDefineCursor(wind, pancursor);
+                            } else if(imageinfo.COP_Flags & COP_Zoom2) {
+                                XUndefineCursor(wind);
+                                XDefineCursor(wind, zoom2cursor);
+                            } else if(imageinfo.COP_Flags & COP_Zoom4) {
+                                XUndefineCursor(wind);
+                                XDefineCursor(wind, zoom4cursor);
+                            }
+                            break;
+
+                    /* set picture scaling mode */
+                          case SOP:
+                            /* if in test mode, disable all but viewing */
+                            if(imageinfo.calibration) break;
+                            /* first, see if any different */
+                            if((imageinfo.SOP_Flags & 
+                                (*currentflags & SELMASK)) == 0) 
+                              {
+                                  imageinfo.SOP_Flags &= 
+                                    ~(currentflags[1]);
+                                  imageinfo.SOP_Flags |= 
+                                    (*currentflags & SELMASK);
+                                  scalepict(imageinfo.image, 
+                                            imageinfo.picture,
+                                            imageinfo.pmax, imageinfo.pmin,
+                                            colorinfo.ncolors, 
+                                            colorinfo.pixels[0],
+                                            colorinfo.shift, 
+                                            imageinfo.nrows, 
+                                            imageinfo.ncols, 
+                                            imageinfo.SOP_Flags);
+                                  writepix( wind, imageinfo.image, 
+                                           imageinfo.ncols, 
+                                           imageinfo.nrows,
+                                           zoomfactor, 0, 0, 
+                                           winfo.width, winfo.height,
+                                           xzero, yzero, 0, GXcopy,
+                                           AllPlanes);
+                              }
+                            break;
+
+                          case FOP:
+                            /* if in test mode, disable all but viewing */
+                            if(imageinfo.calibration) break;
+                            break;
+                              
+                          default:
+                            fprintf(stderr,"Unknown menu pane %d\n",
+                                    *currentflags>>16);
+                        }
+                    }
+                 break;
+             }
+           else if((but->detail &
+                    (ControlMask | MetaMask | ShiftMask |
+                     ShiftLockMask)) == 0)
+             {
+                 /* check if viewing or cursor operation selected */
+                 if(imageinfo.COP_Flags) break;
+                 downbutton = but->detail &
+                   (RightButton | MiddleButton | LeftButton);
+                 CalcMap(&winfo,colorinfo.cmap,(int)but->x,(int)but->y,
+                         colorinfo.ncolors, imageinfo.VOP_Flags,
+                         downbutton);
+                 XStoreColors(colorinfo.ncolors,colorinfo.cmap);
+                 break;
+             }
+           break;
+
+         case ButtonReleased:
+           /* check if viewing or cursor operation selected */
+           if(imageinfo.COP_Flags) {
+               if(imageinfo.COP_Flags & COP_Print) {  
+                   /* print 11x11 picture region */
+                   prpict(imageinfo.picture, but->x>>zoomfactor,
+                          but->y>>zoomfactor, xzero, yzero,
+                          imageinfo.ncols, imageinfo.nrows, 11, 11);
+               }
+               /* recenter (pan) on cursor position */
+               if(imageinfo.COP_Flags & 
+                  (COP_Pan | COP_Zoom2 | COP_Zoom4)) {
+                       
+                      xcenter = xzero + (but->x >> zoomfactor);
+                      ycenter = yzero + (but->y >> zoomfactor);
+                       
+                      /* alter zoomfactor to reflect new zoom */
+                      if(imageinfo.COP_Flags & COP_Pan) zoomfactor = 0;
+                      if(imageinfo.COP_Flags & COP_Zoom2) zoomfactor = 1;
+                      if(imageinfo.COP_Flags & COP_Zoom4) zoomfactor = 2;
+                       
+                      xtempzero = 
+                         MAX( 0, MIN(imageinfo.ncols - 
+                                     (winfo.width>>zoomfactor),
+                                   xcenter - (winfo.width>>(zoomfactor+1))));
+                       
+#ifdef PALWIND
+                      ytempzero =
+                         MAX( 0, MIN(imageinfo.nrows-
+                                  (winfo.height>>zoomfactor),
+                                  ycenter - (winfo.height>>(zoomfactor+1))));
+#else
+                      ytempzero =
+                         MAX( 0, MIN(imageinfo.nrows-
+                                     ((winfo.height-PALHEIGHT-2*PALBORDER)
+                                      >>zoomfactor),
+                                 ycenter - ((winfo.height-
+                                             PALHEIGHT-2*PALBORDER)
+                                            >>(zoomfactor+1))));
+#endif
+                      if(xzero != xtempzero || yzero != ytempzero ||
+                         oldzoomfactor != zoomfactor)
+                        {
+                            xzero = xtempzero;
+                            yzero = ytempzero;
+                            writepix( wind, imageinfo.image, 
+                                     imageinfo.ncols, imageinfo.nrows,
+                                     zoomfactor, 0, 0, 
+                                     winfo.width, winfo.height,
+                                     xzero, yzero, 0, GXcopy, AllPlanes);
+                            XWarpMouse(wind, (xcenter-xzero)<<zoomfactor, 
+                                       (ycenter-yzero)<<zoomfactor);
+                        }
+                   /* COP_OldFlags = imageinfo.COP_Flags;  */
+                      oldzoomfactor = zoomfactor;
+                  }
+               break;
+           }
+           if(downbutton < 0) break;
+           CalcMap(&winfo,colorinfo.cmap,(int)but->x,(int)but->y,
+                   colorinfo.ncolors, imageinfo.VOP_Flags,
+                   downbutton);
+           XStoreColors(colorinfo.ncolors,colorinfo.cmap);
+           downbutton = -1;
+           break;
+
+         case MouseMoved:
+           XUpdateMouse(wind, &xbut, &ybut, &subwind);
+           XQueryMouseButtons(wind, &xbut, &ybut,
+                              &subwind, &mouse->detail);
+           
+           if(subwind == 0 && downbutton >= 0) {
+               CalcMap(&winfo,colorinfo.cmap,xbut,ybut,
+                       colorinfo.ncolors,
+                       imageinfo.VOP_Flags,downbutton);
+               XStoreColors(colorinfo.ncolors,colorinfo.cmap);
+           }
+           else { 
+               updatezoom(wzoom, xzoomsize, yzoomsize,
+                          (xzero + (but->x >> zoomfactor)),
+                          (yzero + (but->y >> zoomfactor)),
+                          imageinfo.ncols, imageinfo.nrows, 
+                          imageinfo.image, (1<<zoomfactor));
+           }
+           break;
+               
+           /* On ExposeWindow events, recalculate the image center and
+            * coordinates of upper left hand corner of window.
+            */
+         case ExposeCopy: 
+         case ExposeWindow:
+           if(QLength() > 0) {
+               XPeekEvent(&peekevent);
+               if(peekevent.type == ExposeWindow &&
+                  peekevent.window == expw->window) break;
+           }
+           
+           if(expw->window == iconwindow) {
+               XBitmapBitsPut(iconwindow, 0, 0, 
+                              show_width, show_height, show_bits,
+                              WhitePixel, BlackPixel, 0,
+                              GXcopy, AllPlanes);
+               break;
+           }
+           
+#ifdef PALWIND
+           if(expw->window == iconpalwind) {
+               XBitmapBitsPut(iconpalwind, 0, 0, 
+                              show_width, show_height, show_bits,
+                              WhitePixel, BlackPixel, 0,
+                              GXcopy, AllPlanes);
+               break;
+           }
+#endif
+           if(expw->window == iconwzoom) {
+               XBitmapBitsPut(iconwzoom, 0, 0, 
+                              show_width, show_height, show_bits,
+                              WhitePixel, BlackPixel, 0,
+                              GXcopy, AllPlanes);
+               break;
+           }
+               
+           if(w_mapped == 0) {  /* check if to remap windows */
+#ifdef PALWIND
+               if(expw->window != palwind) XMapWindow(palwind);
+#endif
+               if(expw->window != wind)    XMapWindow(wind);
+               if(expw->window != wzoom)   XMapWindow(wzoom);
+               w_mapped++;
+           }
+               
+           XQueryWindow(wind,&winfo);
+               
+           if(expw->window == wind) {
+               XQueryWindow(palwind,&palwinfo);
+#ifdef PALWIND
+               XConfigureWindow(palwind, winfo.x,
+                                winfo.y+winfo.height+
+                                maininfo.frame.bdrwidth,
+                                winfo.width, PALHEIGHT);
+#else
+               XConfigureWindow(palwind, 0,
+                                winfo.height-PALHEIGHT-2*PALBORDER,
+                                winfo.width-2*PALBORDER,
+                                PALHEIGHT);
+#endif
+               XQueryWindow(wzoom,&wzoominfo);
+               xzoomsize = wzoominfo.width;
+               yzoomsize = wzoominfo.height;
+               XConfigureWindow(wzoom,
+                                winfo.x+winfo.width+
+                                maininfo.frame.bdrwidth,
+                                winfo.y, wzoominfo.width,
+                                wzoominfo.height);
+               
+               xzero = MAX( 0, 
+                           MIN(imageinfo.ncols-(winfo.width>>zoomfactor),
+                               xcenter - 
+                               (winfo.width>>(zoomfactor+1))));
+#ifdef PALWIND
+               yzero = MAX( 0, 
+                           MIN(nrows-
+                               (winfo.height>>zoomfactor),
+                               ycenter -
+                               (winfo.height>>(zoomfactor+1))));
+#else
+               yzero = MAX( 0, 
+                           MIN(imageinfo.nrows-
+                               ((winfo.height-PALHEIGHT-2*PALBORDER)
+                                >>zoomfactor),
+                               ycenter - ((winfo.height -
+                                           PALHEIGHT-2*PALBORDER)
+                                          >>(zoomfactor+1))));
+#endif
+           }
+           
+           if(event.type == ExposeCopy) break;
+
+           /* drop through to ExposeRegion to draw the window, and
+            * redraw the supporting windows */
+
+         case ExposeRegion:
+           if(expw->window == palwind) {
+               XQueryWindow(palwind,&palwinfo);
+               for(i=0; i<palwinfo.width; i++)
+                 palette[i] =
+                   ((colorinfo.ncolors * i)/palwinfo.width) + 
+                     colorinfo.pixels[0];
+               for(i=0; i<palwinfo.height; i++)
+                 XPixmapBitsPutZ(palwind, 0, i, 
+                                 palwinfo.width, 1,
+                                 palette, 0, GXcopy, AllPlanes);
+           } 
+           else if(expw->window == wzoom) {
+               XQueryWindow(wzoom,&wzoominfo);
+               xzoomsize = wzoominfo.width;
+               yzoomsize = wzoominfo.height;
+               updatezoom(wzoom, xzoomsize, yzoomsize,
+                          xcenter, ycenter, 
+                          imageinfo.ncols, imageinfo.nrows,
+                          imageinfo.image, (1<<zoomfactor));
+           } 
+           else {
+               if( expw->x > imageinfo.ncols<<zoomfactor ||
+                  expw->y > imageinfo.nrows<<zoomfactor)
+                 break;
+               
+               writepix( wind, imageinfo.image,
+                        imageinfo.ncols, imageinfo.nrows,
+                        zoomfactor, expw->x, expw->y, 
+                        expw->width, expw->height,
+                        xzero, yzero, 0, GXcopy, AllPlanes);
+           }
+           break;
+               
+       /* If any window is unmapped, all three are unmapped */
+
+         case UnmapWindow:
+
+#ifdef PALWIND
+           if(event.window != palwind) XUnmapWindow(palwind);
+#endif
+           if(event.window != wzoom)   XUnmapWindow(wzoom);
+           if(event.window != wind)     XUnmapWindow(wind);
+           w_mapped = 0;
+           break;
+       }
+    }
+}
+
+
+#ifdef GLOPEROO
+describe_XEvent(etype, ewindow, detail, wind, palwind, wzoom)
+     unsigned long etype;
+     unsigned short detail;
+     Window ewindow, wind, palwind, wzoom;
+{
+    fprintf(stderr,"Window ");
+    if(ewindow == wind) {
+       fprintf(stderr,"wind, ");
+    } else if(ewindow == palwind) {
+       fprintf(stderr,"palwind, ");
+    } else if(ewindow == wzoom) {
+       fprintf(stderr,"wzoom, "); 
+    } else {
+       fprintf("ERROR %d\n", ewindow);
+    }
+    switch((int)etype) {
+      case KeyPressed: fprintf(stderr,"KeyPressed"); 
+                      fprintf(stderr," detail = %x", detail);
+                      break;
+      case KeyReleased: fprintf(stderr,"KeyReleased");
+                      fprintf(stderr," detail = %x", detail);
+                      break;
+      case ButtonPressed: fprintf(stderr,"ButtonPressed");
+                      fprintf(stderr," detail = %x", detail);
+                      break;
+      case ButtonReleased: fprintf(stderr,"ButtonReleased");
+                      fprintf(stderr," detail = %x", detail);
+                      break;
+      case EnterWindow: fprintf(stderr,"EnterWindow");
+                      fprintf(stderr," detail = %x", detail);
+                      break;
+      case LeaveWindow: fprintf(stderr,"LeaveWindow");
+                      fprintf(stderr," detail = %x", detail);
+                      break;
+      case MouseMoved: fprintf(stderr,"MouseMoved");
+                      fprintf(stderr," detail = %x", detail);
+                      break;
+      case ExposeWindow: fprintf(stderr,"ExposeWindow"); break;
+      case ExposeRegion: fprintf(stderr,"ExposeRegion"); break;
+      case ExposeCopy: fprintf(stderr,"ExposeCopy"); break;
+      case UnmapWindow: fprintf(stderr,"UnmapWindow"); break;
+      case FocusChange: fprintf(stderr,"FocusChange"); break;
+      default: fprintf(stderr,"ERROR %d", etype);
+                  }
+    fprintf(stderr,"\n");
+    fflush(stderr);
+}
+#endif
diff --git a/usr/src/new/X/showimg/shutil.c b/usr/src/new/X/showimg/shutil.c
new file mode 100644 (file)
index 0000000..fb1f2d5
--- /dev/null
@@ -0,0 +1,143 @@
+/* split off some utility functions */
+
+#include <stdio.h>
+#include <X/Xlib.h>
+
+#include "quad_arrow.cursor"
+#include "quad_arrow_mask.cursor"
+#include "pan.cursor"
+#include "pan_mask.cursor"
+#include "print.cursor"
+#include "print_mask.cursor"
+#include "zoom2.cursor"
+#include "zoom2_mask.cursor"
+#include "zoom4.cursor"
+#include "zoom4_mask.cursor"
+#include "pal.cursor"
+#include "pal_mask.cursor"
+
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+
+#define SYNCINT 20
+
+ipow( x, n)
+register int x, n;
+{
+       register int p;
+       for (p = 1; n > 0; --n)
+               p *= x;
+       return(p);
+}
+
+make_cursors(imcursor,pancursor,printcursor,zoom2cursor,zoom4cursor,
+            palcursor)
+      Cursor *imcursor, *pancursor, *printcursor;
+      Cursor *zoom2cursor, *zoom4cursor, *palcursor;
+{
+      Cursor XCreateCursor();
+
+     *imcursor = XCreateCursor(quad_arrow_width, quad_arrow_height,
+                             quad_arrow_bits, 
+                             quad_arrow_mask_bits,
+                             quad_arrow_x_hot, quad_arrow_y_hot,
+                             BlackPixel, WhitePixel, GXcopy);
+     *pancursor = XCreateCursor(pan_width, pan_height,
+                             pan_bits, 
+                             pan_mask_bits,
+                             pan_x_hot, pan_y_hot,
+                             BlackPixel, WhitePixel, GXcopy);
+     *printcursor = XCreateCursor(print_width, print_height,
+                             print_bits, 
+                             print_mask_bits,
+                             print_x_hot, print_y_hot,
+                             BlackPixel, WhitePixel, GXcopy);
+     *zoom2cursor = XCreateCursor(zoom2_width, zoom2_height,
+                             zoom2_bits, 
+                             zoom2_mask_bits,
+                             zoom2_x_hot, zoom2_y_hot,
+                             BlackPixel, WhitePixel, GXcopy);
+     *zoom4cursor = XCreateCursor(zoom4_width, zoom4_height,
+                             zoom4_bits, 
+                             zoom4_mask_bits,
+                             zoom4_x_hot, zoom4_y_hot,
+                             BlackPixel, WhitePixel, GXcopy);
+     *palcursor = XCreateCursor(pal_width, pal_height,
+                             pal_bits, 
+                             pal_mask_bits,
+                             pal_x_hot, pal_y_hot,
+                             BlackPixel, WhitePixel, GXcopy);
+     return;
+}
+
+/* write image pixels to the screen according to location, 
+ * zoom factor
+ */
+writepix(wind, image, ncols, nrows, zoomfactor, x, y, width, height,
+        xzero, yzero, mask,func,planes)
+     Window wind;
+     unsigned char *image;
+     short ncols, nrows, zoomfactor, x, y, width, height, xzero, yzero;
+     int mask, func, planes;
+{
+     unsigned char linebuf[8192];
+     int j, k, l, minw, ldebug = 0;
+
+     register unsigned char *byteimage, *line = linebuf;
+     register int ncols_reg = ncols;
+     register minwidth, maxy;
+     register int i;
+
+     minwidth = MIN((ncols_reg-x)<<zoomfactor, width);
+     maxy = MIN(nrows<<zoomfactor, y+height);
+
+     byteimage = image + ((yzero + y) * ncols_reg) + xzero + x;
+
+     XSync(0);
+     if(zoomfactor == 0) {
+         for(i=y; i<maxy; i++) {
+           XPixmapBitsPutZ(wind, x, i,
+               minwidth, 1, byteimage, mask, func, planes);
+           if((i % SYNCINT) == 0) XSync(0); 
+           byteimage += ncols_reg;
+         }
+         return;
+     } else {
+
+       l = 1<<zoomfactor;
+
+       /* adjust for odd pixels */
+       width += x & (l-1);
+       x -= x & (l-1);
+       height += y & (l-1);
+       y -= y & (l-1);
+       if(width & (l-1))
+        width = (width & ~(l-1)) + l;
+       if(height & (l-1))
+        height = (height & ~(l-1))+ l;
+
+       minwidth = MIN((ncols_reg-(x>>zoomfactor))<<zoomfactor, width);
+       maxy = MIN(nrows<<zoomfactor, y+height);
+       minw = minwidth>>zoomfactor;
+
+       byteimage = image + ((yzero + (y>>zoomfactor)) * ncols_reg)
+                      + xzero + (x>>zoomfactor);
+
+       for( j=y; j<maxy; j+=l) {
+          for(k=0; k<minw; k++ ) 
+              for(i=0; i<l; i++)
+                  *line++ = byteimage[k];
+           line = linebuf;
+          for(i=0; i<l; i++) {
+              if(j+i >= maxy) return;
+               XPixmapBitsPutZ(wind, x, j+i, minwidth, 1, line,
+                            mask, func, planes);
+              if(((i+j) % SYNCINT) == 0) XSync(0); 
+          }
+          byteimage += ncols_reg;
+       }
+     }
+     return;
+}
+
+
diff --git a/usr/src/new/X/showimg/shzoom.c b/usr/src/new/X/showimg/shzoom.c
new file mode 100644 (file)
index 0000000..2c84f83
--- /dev/null
@@ -0,0 +1,118 @@
+#include <stdio.h>
+#include <X/Xlib.h>
+
+#include "wzoom.cursor"
+#include "wzoom_mask.cursor"
+
+#define ZOOMFACT 4   /* zoom factor relative to parent window */
+
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+
+static u_char *zimage = NULL;          /* pointer to storage */
+static unsigned long zsize = 0;        /* current storage size */
+static Bitmap wzmask = NULL;
+static int xcur, ycur;
+static int xnstatic = 0, ynstatic = 0;
+static int xzoom = 0, yzoom = 0, f = 0;
+
+updatezoom(wzoom, xzoomsize, yzoomsize,
+          x, y, xsize, ysize, image, wzfactor)
+
+    Window wzoom;              /* zoom window ID */
+    int xzoomsize, yzoomsize;  /* zoom window size */
+    register int x, y;         /* center coord for zoom */
+    int xsize, ysize;          /* size of original image */
+    unsigned char *image;      /* 8-bit image */
+    int wzfactor;              /* parent window zoom factor */
+
+{
+    unsigned char *malloc(), *free();
+    int i;
+    register int j, xn = xnstatic, yn = ynstatic;
+
+    if(x<0 || x>=xsize || y<0 || y>= ysize) return;
+
+/* recalculate the storage needed for nearest larger zoomed pixel */
+    if((f != ZOOMFACT * wzfactor) || (xzoom != xzoomsize) || 
+       (yzoom != yzoomsize)) {
+          f = ZOOMFACT * wzfactor;
+          xn = xnstatic = xzoomsize/f + 1;
+          yn = ynstatic = yzoomsize/f + 1;
+          xzoom = xn*f; 
+          yzoom = yn*f;
+          xcur = (xzoom>>1) - wzoom_x_hot + ((f/ZOOMFACT)<<1);
+          ycur = (yzoom>>1) - wzoom_y_hot + ((f/ZOOMFACT)<<1);
+       }
+
+/* check available storage space */
+    if( (xzoom*yzoom) > zsize) {
+       if(zimage != NULL) free(zimage);
+       zsize = xzoom*yzoom;
+       if((zimage = malloc(zsize)) == NULL) {
+           fprintf(stderr,"Can't allocate zoom image buffer!\n");
+           exit(1);
+       }
+    }
+
+    replicate(x-xn/2,y-yn/2,xsize,ysize,image,f,
+           0,0,xzoom,yzoom,zimage);
+
+    if( (y-yn/2) < 0) 
+      bzero(zimage,xzoom*f*(yn/2-y));
+    if( (y-yn/2+yn) > ysize)
+      bzero(zimage+xzoom*f*(ysize-y+yn/2),
+           xzoom*f*(y-yn/2+yn-ysize));
+    if( (x-xn/2) < 0)
+      for(j=0;j<yzoom;j++) bzero(zimage+j*xzoom,f*(xn/2-x));
+    if( (x-xn/2+xn) > xsize)
+      for(j=0;j<yzoom;j++) bzero(zimage+j*xzoom+f*(xsize-x+xn/2),
+                            f*(x-xn/2+xn-xsize));
+
+    XPixmapBitsPutZ(wzoom,0,0,xzoom,yzoom,zimage,0,GXcopy,AllPlanes);
+
+    if(wzmask == NULL) {
+       wzmask = XStoreBitmap(wzoom_mask_width, wzoom_mask_height,
+                             wzoom_mask_bits);
+    }
+    XBitmapBitsPut(wzoom, xcur, ycur,
+                  wzoom_width, wzoom_height, wzoom_bits,
+                  WhitePixel, BlackPixel, wzmask, GXcopy, AllPlanes);
+}
+
+replicate(x0,y0,w0,h0,from,f,x,y,w,h,to)
+/* Fill array "to" with a piece of "from", each pixel mapping to fxf pixels */
+     unsigned char *from, *to; /* Source array, destination array */
+     int x0,y0,w0,h0;          /* Source origin, dimensions */
+     int x,y,w,h;              /* Destination origin, dimensions */
+     int f;                    /* Replication factor */
+{
+    register unsigned char *s, *d;
+    register int k, n, i;
+    int i0,i1,j0,j1,j;
+
+    j0 = MAX(0,y0);
+    j1 = MIN(h0,y0+(h-y)/f);
+    i0 = MAX(0,x0);
+    i1 = MIN(w0,x0+(w-x)/f);
+    for(j=j0;j<j1;j++) {
+       s = from + w0*j + i0;
+       d = to + w*(f*(j-y0)+y) + x + f*(i0-x0);
+       i = i1 - i0;
+       n = f;
+       while(i--) {
+           k = n;
+           while(k--) *d++ = *s;
+           s++;
+       }
+       i = f-1;
+       n = f*(i1-i0);
+       s = d - f*(i1-i0);
+       d = s + w;
+       while(i--) {
+           bcopy(s,d,n);
+           d += w;
+       }
+    }
+}
+
diff --git a/usr/src/new/X/showimg/shzoom.c.old b/usr/src/new/X/showimg/shzoom.c.old
new file mode 100644 (file)
index 0000000..6478a4b
--- /dev/null
@@ -0,0 +1,129 @@
+#include <stdio.h>
+#include <X/Xlib.h>
+
+#define ZOOMFACT 4   /* zoom factor relative to parent window */
+
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+
+static unsigned char *zimage = NULL;   /* pointer to storage */
+static unsigned int zsize = 0;        /* current storage size */
+
+updatezoom(wzoom, xzoomsize, yzoomsize,
+          x, y, xsize, ysize, image, wzfactor)
+
+    Window wzoom;              /* zoom window ID */
+    int xzoomsize, yzoomsize;  /* zoom window size */
+    int x, y;                  /* center coord for zoom */
+    int xsize, ysize;          /* size of original image */
+    unsigned char *image;      /* 8-bit image */
+    int wzfactor;              /* parent window zoom factor */
+
+{
+    unsigned char *malloc(), *free();
+    int i, f;
+    register int j, xn, yn;
+    register int rx = x, ry = y;
+
+    if(rx<0 || rx>=xsize || ry<0 || ry>= ysize) return;
+
+/* recalculate the storage needed for nearest larger zoomed pixel */
+    f = ZOOMFACT * wzfactor;
+    xn = xzoomsize/f + 1;
+    yn = yzoomsize/f + 1;
+    xzoomsize = xn*f; 
+    yzoomsize = yn*f;
+
+/* check available storage space */
+    if( (xzoomsize*yzoomsize) > zsize) {
+       if(zimage != NULL) free(zimage);
+       zsize = xzoomsize*yzoomsize;
+       if((zimage = malloc(zsize)) == NULL) {
+           fprintf(stderr,"Can't allocate zoom image buffer!\n");
+           exit(1);
+       }
+/*     fprintf(stderr,"aloocating zimage = %x, len =%d bytes\n",zimage,zsize);
+*/
+       bzero(zimage,zsize);
+    }
+
+/*    fprintf(stderr,"Update zoom called: x= %d y= %d zoom= %d\n",rx, ry, f);
+    fprintf(stderr,"  ncols= %d, nrows = %d\n",
+           xsize,ysize);
+    fflush(stderr);
+*/
+    bzero(zimage,zsize);
+    replicate(rx-xn/2,ry-yn/2,xsize,ysize,image,f,
+           0,0,xzoomsize,yzoomsize,zimage);
+/*
+    if( (ry-yn/2) < 0) 
+      bzero(zimage,xzoomsize*(yn/2-ry));
+    if( (ry-yn/2+yn) > ysize)
+      bzero(zimage+xzoomsize*(ysize-ry+yn/2),
+           xzoomsize*(ry-yn/2+yn-ysize));
+    if( (rx-xn/2) < 0)
+      for(j=0;j<yzoomsize;j++) bzero(zimage+j*xzoomsize,f*(xn/2-rx));
+    if( (rx-xn/2+xn) > xsize)
+      for(j=0;j<yzoomsize;j++) bzero(zimage+j*xzoomsize+f*(xsize-rx+xn/2),
+                            f*(rx-xn/2+xn-xsize));
+*/
+/* j is the location of the top left of the central pixel */
+/*  j = f*s*f*((s-1)/2) + f*((s-1)/2);
+    i = j;
+    zimage[i] = BlackPixel;
+    i += f-1;
+    zimage[i] = WhitePixel;
+    i = j + f*s*(f-1);
+    zimage[i] = WhitePixel;
+    i += f-1;
+    zimage[i] = BlackPixel;
+    i = j - f*s - 1;
+    zimage[i] = BlackPixel;
+    i += f+1;
+    zimage[i] = WhitePixel;
+    i = j + f*s*(f-1) + f*s - 1;
+    zimage[i] = WhitePixel;
+    i += f+1;
+    zimage[i] = BlackPixel;
+*/
+ /* Let the Xwindow system take care of clipping */
+    XSync();
+    XPixmapBitsPutZ(wzoom,0,0,xzoomsize,yzoomsize,zimage,0,GXcopy,AllPlanes);
+}
+
+replicate(x0,y0,w0,h0,from,f,x,y,w,h,to)
+/* Fill array "to" with a piece of "from", each pixel mapping to fxf pixels */
+     unsigned char *from, *to; /* Source array, destination array */
+     int x0,y0,w0,h0;          /* Source origin, dimensions */
+     int x,y,w,h;              /* Destination origin, dimensions */
+     int f;                    /* Replication factor */
+{
+    register unsigned char *s, *d;
+    register int k, n, i;
+    int i0,i1,j0,j1,j;
+
+    j0 = MAX(0,y0);
+    j1 = MIN(h0,y0+(h-y)/f);
+    i0 = MAX(0,x0);
+    i1 = MIN(w0,x0+(w-x)/f);
+    for(j=j0;j<j1;j++) {
+       s = from + w0*j + i0;
+       d = to + w*(f*(j-y0)+y) + x + f*(i0-x0);
+       i = i1 - i0;
+       n = f;
+       while(i--) {
+           k = n;
+           while(k--) *d++ = *s;
+           s++;
+       }
+       i = f-1;
+       n = f*(i1-i0);
+       s = d - f*(i1-i0);
+       d = s + w;
+       while(i--) {
+           bcopy(s,d,n);
+           d += w;
+       }
+    }
+}
+
diff --git a/usr/src/new/X/showimg/wzoom.cursor b/usr/src/new/X/showimg/wzoom.cursor
new file mode 100644 (file)
index 0000000..4542af8
--- /dev/null
@@ -0,0 +1,9 @@
+#define wzoom_width 13
+#define wzoom_height 13
+#define wzoom_x_hot 6
+#define wzoom_y_hot 6
+static short wzoom_bits[] = {
+   0x0000, 0x0802, 0x0404, 0x0208,
+   0x01f0, 0x0110, 0x0110, 0x0110,
+   0x01f0, 0x0208, 0x0404, 0x0802,
+   0x0000};
diff --git a/usr/src/new/X/showimg/wzoom_mask.cursor b/usr/src/new/X/showimg/wzoom_mask.cursor
new file mode 100644 (file)
index 0000000..12bbcea
--- /dev/null
@@ -0,0 +1,7 @@
+#define wzoom_mask_width 13
+#define wzoom_mask_height 13
+static short wzoom_mask_bits[] = {
+   0x1803, 0x1c07, 0x0e0e, 0x07fc,
+   0x03f8, 0x0318, 0x0318, 0x0318,
+   0x03f8, 0x07fc, 0x0e0e, 0x1c07,
+   0x1803};
diff --git a/usr/src/new/X/showimg/zoom2.cursor b/usr/src/new/X/showimg/zoom2.cursor
new file mode 100644 (file)
index 0000000..b84b341
--- /dev/null
@@ -0,0 +1,9 @@
+#define zoom2_width 16
+#define zoom2_height 16
+#define zoom2_x_hot 0
+#define zoom2_y_hot 7
+static short zoom2_bits[] = {
+   0xffff, 0xc03f, 0x803f, 0x9f2f,
+   0x9fe7, 0xc7f3, 0xe3f9, 0xf8fc,
+   0xfe39, 0xff33, 0x9f27, 0x802f,
+   0x803f, 0xffff, 0xffff, 0xffff};
diff --git a/usr/src/new/X/showimg/zoom2_mask.cursor b/usr/src/new/X/showimg/zoom2_mask.cursor
new file mode 100644 (file)
index 0000000..3e6770f
--- /dev/null
@@ -0,0 +1,7 @@
+#define zoom2_mask_width 16
+#define zoom2_mask_height 16
+static short zoom2_mask_bits[] = {
+   0xffe0, 0xffe0, 0xfff0, 0xfff8,
+   0xfffc, 0xfffe, 0xffff, 0xffff,
+   0xffff, 0xfffe, 0xfffc, 0xfff8,
+   0xfff0, 0xffe0, 0x0000, 0x0000};
diff --git a/usr/src/new/X/showimg/zoom4.cursor b/usr/src/new/X/showimg/zoom4.cursor
new file mode 100644 (file)
index 0000000..1e6aae9
--- /dev/null
@@ -0,0 +1,9 @@
+#define zoom4_width 16
+#define zoom4_height 16
+#define zoom4_x_hot 0
+#define zoom4_y_hot 7
+static short zoom4_bits[] = {
+   0xff80, 0xc3c0, 0xc3e0, 0xc9d0,
+   0xc9c8, 0xcce4, 0xccf2, 0xce79,
+   0x8072, 0x8064, 0xcfc8, 0xcfd0,
+   0xcfe0, 0xcfc0, 0xff80, 0x0000};
diff --git a/usr/src/new/X/showimg/zoom4_mask.cursor b/usr/src/new/X/showimg/zoom4_mask.cursor
new file mode 100644 (file)
index 0000000..1bb7de6
--- /dev/null
@@ -0,0 +1,7 @@
+#define zoom4_mask_width 16
+#define zoom4_mask_height 16
+static short zoom4_mask_bits[] = {
+   0xff80, 0xffc0, 0xffe0, 0xfff0,
+   0xfff8, 0xfffc, 0xfffe, 0xffff,
+   0xfffe, 0xfffc, 0xfff8, 0xfff0,
+   0xffe0, 0xffc0, 0xff80, 0x0000};