1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <malloc.h>
4 #include <fcntl.h>
5 #include <sys/types.h>
6 #include <sys/mman.h>
7 #include "filtere.c"
8
9 #define OFSETT 800
10 #define WIDTH_HOLE 300
11 #define WIDTH 300
12 #define HEIGHT 300
13 #define get(x,y) ColorStart[OFSETT+(x)+WIDTH_HOLE*(y)]
14
15 typedef unsigned char byte;
16
do_it()17 void do_it()
18 {
19 int minx=WIDTH,miny=HEIGHT,maxx=0,maxy=0;
20 int tx,ty,count;
21 int dx,dy;
22 byte basis;
23 byte *data;
24 byte *ColorStart;
25
26 ColorStart=(byte *)malloc(HEIGHT*WIDTH_HOLE+800);
27 fread(ColorStart,sizeof(char),HEIGHT*WIDTH_HOLE+800,stdin);
28 data=(byte *)malloc(633000);
29 basis=get(0,0);
30 for(ty=0;ty<HEIGHT;ty++)
31 for(tx=0;tx<WIDTH;tx++)
32 if(get(tx,ty)!=basis)
33 {
34 if (tx>maxx) maxx=tx;
35 if (tx<minx) minx=tx;
36 if (ty>maxy) maxy=ty;
37 if (ty<miny) miny=ty;
38 }
39 if ((maxx>=WIDTH-1)||(maxy>=HEIGHT-1))
40 {
41 fprintf(stderr,"The picture exceeds the frame\n");
42 exit(1);
43 }
44 count=0;
45 for(ty=miny;ty<=maxy;ty++)
46 for(tx=minx;tx<=maxx;tx++)
47 if(get(tx,ty)==basis)
48 data[count++]=0;
49 else
50 data[count++]=1;
51
52 dx=maxx-minx+1;
53 dy=maxy-miny+1;
54 save(stdout,(char *)data,dx,dy,RLK|MYGETPUT);
55 }
56
57
main()58 void main()
59 {
60 do_it();
61 }
62