From 3ac04d32cd29c535144fbd1f97eea3fafd5c21d6 Mon Sep 17 00:00:00 2001 From: Ian C Date: Fri, 15 May 2020 21:42:38 +0000 Subject: Now builds cleanly. --- Makefile | 10 +++ README | 1 + img.c | 264 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ img3d.c | 152 ++++++++++++++++++++++++++++++++++++ 4 files changed, 427 insertions(+) create mode 100644 Makefile create mode 100644 README create mode 100644 img.c create mode 100644 img3d.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..48374da --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +all: img img3d + +img: img.c + cc -I/usr/openwin/include -L/usr/openwin/lib -O -o img img.c -lm -lX11 + +img3d: img3d.c + cc -I/usr/openwin/include -L/usr/openwin/lib -O -o img3d img3d.c -lm -lX11 + +clean: + rm -f img img3d core diff --git a/README b/README new file mode 100644 index 0000000..cd1b64b --- /dev/null +++ b/README @@ -0,0 +1 @@ +Do 'img -help' or 'img3d -help' to see key and mouse button usage. diff --git a/img.c b/img.c new file mode 100644 index 0000000..4971712 --- /dev/null +++ b/img.c @@ -0,0 +1,264 @@ +#include +#include +#include +#include + +#include +#include +#include + +typedef unsigned long ulong; + +static int MAGFAC =1; + +/* The size of source when magnifying - size of destination when shrinking. +*/ +#define SIZEX 256 +#define SIZEY 256 + +static int AVGMODE =False; + +/* Source box size +*/ +#define SRCWIDTH ((shrink) ? (SIZEX*MAGFAC) : (SIZEX)) +#define SRCHEIGHT ((shrink) ? (SIZEY*MAGFAC) : (SIZEY)) + +/* Destination box size +*/ +#define DESTWIDTH ((shrink) ? (SIZEX) : (SIZEX*MAGFAC)) +#define DESTHEIGHT ((shrink) ? (SIZEY) : (SIZEY*MAGFAC)) + +static Display *display; +static Window window,root; +static XImage *src,*dest; +static XEvent ev; +static ulong black,white; +static int width,height,cx,cy; +static int shrink=False; +static GC gc; + +int main(int argc, char *argv[]) +{ + void ShrinkImg(XImage *src, XImage *dest); + void ScaleImg(XImage *src, XImage *dest); + char str[180]; + Window rw,cw; + int rx,ry,cx,cy,px,py,bmask; + int f; + + if (!(display=XOpenDisplay(NULL))) + { + fprintf(stderr,"%s: couldn't open display\n",argv[0]); + exit(1); + } + + if (argc>1) + { + if (!strcmp(argv[1],"-help")) + { + fprintf(stderr,"Keys :\n"); + fprintf(stderr,"LMB - Increase mag factor\n"); + fprintf(stderr,"MMB - Decrease mag factor\n"); + fprintf(stderr,"A - Toggle average mode\n"); + fprintf(stderr,"RMB - Quit\n"); + } + } + + root=DefaultRootWindow(display); + width=DisplayWidth(display,0); + height=DisplayHeight(display,0); + + window=XCreateSimpleWindow (display,root,0,800,DESTWIDTH,DESTHEIGHT,0,0,0); + + gc=XCreateGC(display,window,0L,NULL); + + white=WhitePixel(display,0); + black=BlackPixel(display,0); + XSetBackground(display,gc,white); + XSetForeground(display,gc,white); + XSetPlaneMask(display,gc,AllPlanes); + + XSelectInput (display,window,ButtonPressMask|KeyPressMask); + XMapWindow(display,window); + + while(True) + { + if (XPending(display)) + { + XNextEvent (display,&ev); + + switch(ev.type) + { + case ButtonPress: + switch(ev.xbutton.button) + { + case 1: + if (shrink) + { + MAGFAC=MAGFAC>>1; + + if (MAGFAC<=1) + { + shrink=False; + MAGFAC=1; + } + } + else + MAGFAC++; + + XResizeWindow(display,window,DESTWIDTH,DESTHEIGHT); + break; + + case 2: + if (shrink) + { + MAGFAC=MAGFAC<<1; + if (((width/MAGFAC)=width) + rx=width-SRCWIDTH; + + if ((ry+SRCHEIGHT)>=height) + ry=height-SRCHEIGHT; + + src=XGetImage(display,root,rx,ry,SRCWIDTH,SRCHEIGHT,AllPlanes,ZPixmap); + + /* Cheat to create an image we know will be the same as the source... + */ + dest=XGetImage(display,root,0,0,DESTWIDTH,DESTHEIGHT,AllPlanes,ZPixmap); + + if (shrink) + ShrinkImg(src,dest); + else + ScaleImg(src,dest); + + XPutImage(display,window,gc,dest,0,0,0,0,DESTWIDTH,DESTHEIGHT); + + px=SRCWIDTH/2; + py=SRCHEIGHT/2; + + if (!shrink) + { + sprintf(str,"Pix: %lu (%lx)",XGetPixel(src,px,py),XGetPixel(src,px,py)); + XDrawString(display,window,gc,0,10,str,strlen(str)); + XDrawRectangle(display,window,gc,px*MAGFAC,py*MAGFAC,MAGFAC,MAGFAC); + } + + XDestroyImage (src); + XDestroyImage (dest); + /* XSync(display,False); */ + } + + XCloseDisplay(display); +} + + +/* Note, assumes 1 byte per pixel... +*/ +void ScaleImg(XImage *src, XImage *dest) +{ + int x,y,sx,sy,bx,by; + ulong b; + + for(x=0;x +#include +#include + +#include +#include +#include + +typedef unsigned long ulong; + +#define SIZEX 400 +#define SIZEX2 (SIZEX/2) +#define SIZEY 400 +#define SIZEY2 (SIZEY/2) + +static int SCANSCALE =64; + +static Display *display; +static Window window,root; +static XImage *src,*dest; +static XEvent ev; +static ulong black,white; +static int width,height,cx,cy; +static int shrink=False; +static GC gc; + +int main(int argc, char *argv[]) +{ + void ScaleImg(XImage *dest, XImage *src); + char str[180]; + Window rw,cw; + int rx,ry,cx,cy,bmask; + int f; + + if (argc>1) + if (!strcmp(argv[1],"-help")) + { + fprintf(stderr,"Keys :\n"); + fprintf(stderr,"LMB - Lower viewing angle\n"); + fprintf(stderr,"MMB - Raise viewing angle\n"); + fprintf(stderr,"RMB - Quit\n"); + } + + if (!(display=XOpenDisplay(NULL))) + { + fprintf(stderr,"%s: couldn't open display\n",argv[0]); + exit(1); + } + + root=DefaultRootWindow(display); + root=RootWindow(display,DefaultScreen(display)); + width=DisplayWidth(display,DefaultScreen(display)); + height=DisplayHeight(display,DefaultScreen(display)); + + window=XCreateSimpleWindow (display,root,0,800,SIZEX,SIZEY,0,0,0); + + gc=XCreateGC(display,window,0L,NULL); + + XSetBackground(display,gc,white=WhitePixel(display,0)); + XSetForeground(display,gc,black=BlackPixel(display,0)); + XSetPlaneMask(display,gc,AllPlanes); + + XSelectInput (display,window,ButtonPressMask); + XMapWindow(display,window); + + while(True) + { + if (XCheckTypedWindowEvent(display,window,ButtonPress,&ev)) + switch(ev.xbutton.button) + { + case 1: + SCANSCALE=SCANSCALE>>1; + + if (SCANSCALE<1) + SCANSCALE=1; + break; + + case 2: + SCANSCALE=SCANSCALE<<1; + break; + + case 3: + XCloseDisplay(display); + exit(0); + break; + } + + XQueryPointer(display,window,&rw,&cw,&rx,&ry,&cx,&cy,&bmask); + + rx-=SIZEX/2; + ry-=SIZEY/2; + + if (rx<0) + rx=0; + + if (ry<0) + ry=0; + + if ((rx+SIZEX)>=width) + rx=width-SIZEX; + + if ((ry+SIZEY)>=height) + ry=height-SIZEY; + + src=XGetImage(display,root,rx,ry,SIZEX,SIZEY,AllPlanes,ZPixmap); + + /* Cheat to create an image we know will be the same as the source... + */ + dest=XGetImage(display,root,0,0,SIZEX,SIZEY,AllPlanes,ZPixmap); + + ScaleImg(src,dest); + + XPutImage(display,window,gc,dest,0,0,0,0,SIZEX,SIZEY); + + XDestroyImage (src); + XDestroyImage (dest); + /* XSync(display,False); */ + } +} + + +int ScaleX (double n, double sc) +{ + return SIZEX2-(int)((SIZEX2-n)/sc); +} + + +int ScaleY (double n, double sc) +{ + return SIZEY2-(int)((SIZEY2-n)/sc); +} + + +void ScaleImg(XImage *src, XImage *dest) +{ + int x,y; + double sc; + + sc=1.0; + + for(y=0;y