summaryrefslogtreecommitdiff
path: root/img3d.c
diff options
context:
space:
mode:
Diffstat (limited to 'img3d.c')
-rw-r--r--img3d.c152
1 files changed, 152 insertions, 0 deletions
diff --git a/img3d.c b/img3d.c
new file mode 100644
index 0000000..c808c23
--- /dev/null
+++ b/img3d.c
@@ -0,0 +1,152 @@
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+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<SIZEY;y++)
+ {
+ for(x=0;x<SIZEX;x++)
+ if (sc==1)
+ XPutPixel(dest,x,y,XGetPixel(src,x,y));
+ else
+ XPutPixel(dest,x,y,XGetPixel(src,ScaleX((double)x,sc),
+ ScaleY((double)y,sc)));
+
+ sc+=(1.0/SCANSCALE);
+ }
+}