1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include <X11/X.h>
5 #include <X11/Xlib.h>
6 #include <X11/Xutil.h>
7 #include <X11/Xos.h>
8 #include "filtere.c"
9
10 #define ANT 1000000
11
main(int argc,char ** argv)12 void main(int argc,char **argv)
13 {
14 int x,y,i=0,j;
15 int a,f1,f2,a1,a2,offsetx,offsety;
16 char *buffer,*buffer3;
17 double factor;
18
19 if(argc<3) fprintf(stderr,"Spesifiser x og y [vis] <inn.fil> ut.fil\n");
20 a1=atoi(argv[1]);
21 a2=atoi(argv[2]);
22 buffer3=(char *)malloc(ANT*sizeof(char));
23 buffer=load(stdin,&x,&y,RLK|MYGETPUT);
24
25 for(i=0;i<a1;i++)
26 for(j=0;j<a2;j++) buffer3[i*a1+j]=0;
27
28 if((double)(x)/(double)(a1)>(double)(y)/(double)(a2))
29 factor=((double)(a1)/(double)(x));
30 else
31 factor=((double)(a2)/(double)(y));
32
33 a=(int)factor+1;
34 factor/=(double)a;
35
36 offsety = abs((a2-(int)((double)(y*a)*factor))/2);
37 offsetx = abs((a1-(int)((double)(x*a)*factor))/2);
38
39 for(j=0;j<y;j++)
40 for(f1=0;f1<a;f1++)
41 for(i=0;i<x;i++)
42 for(f2=0;f2<a;f2++)
43 if(buffer[i+j*x])
44 buffer3[ ( (int) ((double)(j*a+f1)*factor) +offsety)*a1+
45 (int) ((double)(i*a+f2)*factor) +offsetx]=1;
46
47
48 save(stdout,buffer3,a1,a2,RLK|MYGETPUT);
49
50 if (argc>3)
51 {
52 Display *display;
53 GC wingc;
54 Window window;
55 XSetWindowAttributes attributes;
56 XSizeHints size_hints;
57 XEvent event;
58 XImage *image;
59 Visual *visual;
60 int scr;
61 int bwidth=2;
62 int bdcolor,bgcolor;
63 char *win_name;
64
65 display = XOpenDisplay(NULL);
66 scr = DefaultScreen(display);
67 wingc = DefaultGC(display,scr);
68 visual = DefaultVisual(display,scr);
69 bgcolor = BlackPixel(display,scr);
70 bdcolor = WhitePixel(display,scr);
71 win_name=(char*)(malloc(100));
72 sprintf(win_name,"%d x %d , buffer",a1,a2);
73 size_hints.x = 0;
74 size_hints.y = 0;
75 size_hints.width = a1;
76 size_hints.height = a2;
77 window = XCreateSimpleWindow(display,RootWindow(display,scr),
78 size_hints.x,size_hints.y,
79 size_hints.width,size_hints.height,
80 bwidth,bdcolor,bgcolor);
81 XSetStandardProperties(display,window,win_name,NULL,
82 NULL,argv,argc,&size_hints);
83 attributes.backing_store = Always;
84 XChangeWindowAttributes(display,window,CWBackingStore,&attributes);
85 XMapWindow(display,window);
86 XSync(display,False);
87 XSelectInput(display,window,ButtonPressMask);
88 image=XCreateImage(display,visual,8,
89 ZPixmap,0,(char *)buffer3,
90 a1,a2,8,0);
91 XPutImage(display,window,wingc,image,0,0,0,0,a1,a2);
92 XNextEvent(display,&event);
93 XCloseDisplay(display);
94 }
95 }
96
97
98
99
100
101