1 #include <stdio.h>
2 #include <sys/stat.h>
3 #include <errno.h>
4 
5 unsigned char *deimg;
6 unsigned char *dat;
7 struct stat buf;
8 
SetChar(fn,size_x,size_y)9 void SetChar(fn,size_x,size_y)
10      char *fn;
11      int *size_x,*size_y;
12 {
13       int x, y, size_xy[2], size;
14       FILE *fp;
15       unsigned char s[2][4];
16 
17       if(stat(fn , &buf)) {
18             perror("LoadChar");
19             exit(1);
20       }
21       fprintf(stderr,"%s size %d\n",fn,(int)buf.st_size);
22       if((dat = (unsigned char *)malloc((int)buf.st_size)) == NULL) {
23             perror("LoadChar");
24             exit(1);
25       }
26 
27       if((fp = fopen(fn,"rb")) == NULL) {
28             fprintf(stderr,"Open Error %s\n",fn);
29 	    exit(1);
30       }
31       /*
32       if(fread(s , sizeof(s) , 1 ,fp) != 1) {
33             fprintf(stderr,"Read Error");
34             fclose(fp);
35       }
36       */
37       *size_x = 32;/*(int)(s[0][2]*256+s[0][3]);*/
38       *size_y = 32;/*(int)(s[1][2]*256+s[1][3]);*/
39       size = *size_x * *size_y;
40 
41       if( (deimg = (unsigned char *)malloc(size)) == NULL) {
42             fprintf(stderr,"malloc in Load ");
43 	    exit(1);
44       }
45 
46       if(fread(dat , (int)buf.st_size , 1 ,fp)!=1) {
47 	    fprintf(stderr,"fread in Load");
48 	    free(dat);
49 	    fclose(fp);
50 	    exit(1);
51       }
52       fclose(fp);
53 
54 }
55 
DRl(sx,sy)56 void DRl(sx,sy)
57      int sx,sy;
58 {
59       unsigned char now_p;
60       int x,i,length,c;
61       int size = (int)buf.st_size;
62       int j;
63       c = 0;j=0;
64 
65       for(;size > 0; size-=2) {
66             now_p = dat[c++];
67             length = (int)dat[c++];
68 	    for(;length > 0 ; length--) {
69                   deimg[j++] = now_p;
70             }
71       }
72       free(dat);
73 }
74 
75 
Out(fn,sx,sy)76 void Out(fn,sx,sy)
77      char *fn;
78      int sx,sy;
79 {
80       FILE *fp;
81       unsigned char sc[2][4];
82 
83       memset(sc,0,sizeof(sc));
84 
85       fp = fopen(fn,"wb");
86       sc[0][3] = sx&255;
87       sc[0][2] = (sx>>8)&255;
88       sc[1][3] = sy&255;
89       sc[1][2] = (sy>>8)&255;
90 
91       /*fwrite(sc,sizeof(sc),1,fp);*/
92       fwrite(deimg,sx*sy,1,fp);
93       fclose(fp);
94 }
95 
main(argc,argv)96 main(argc ,argv)
97      int argc;
98      char *argv[];
99 
100 {
101       int sx,sy,size;
102 
103       SetChar(argv[1],&sx,&sy);
104       fprintf(stderr,"%d %d\n",sx,sy);
105       DRl(sx,sy);
106       fprintf(stderr,"out\n");
107       Out(argv[2],sx,sy);
108 }
109