📄 com2pgm.c
字号:
/*This program is wrote by Fujian Shi(fieagle@yahoo.com.cn)*/
/*It can transform the com file to pgm file ,you can watch the picture*/
#include "stddef.h"
#include "stdio.h"
void put_measure(FILE *file,unsigned int val,char th)
{
int i=10000,temp,time=0;
if (th == 0) i /=10;
while(1) {
i/=10;
temp=val/i;
if (temp >0)
time++;
if(temp>10) {
printf("Please increase the origin value of i,now it is 10000.\n");
exit(0);
}
if ((time==0) && (temp==0))
continue;
putc((char) (temp+48),file);
if((val-=i*temp)==0)
break;
}
}
main(int argc,char *argv[])
{
#define UCH(x) ((int) (x))
#define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \
(((unsigned int) UCH(array[offset+1])) << 8))
#define JFREAD(file,buf,sizeofbuf) \
((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
FILE *file1,*file2;
char c1;
unsigned int width,height;
int c2;
unsigned char width_height[4];
if ((file1=fopen(argv[1],"rb"))==NULL)
printf("the %scan't be opened",argv[1]);
if ((file2=fopen(argv[2],"wb+"))==NULL)
printf("the %scan't be opened",argv[2]);
if (! ReadOK(file1, width_height, 4)){
printf("error when read the head of file1");
exit(0);
}
width=GET_2B(width_height,0);
height=GET_2B(width_height,2);
c1=80;
fputc(c1,file2);
c1=0x35;
fputc(c1,file2);
c1=10;
fputc(c1,file2);
/*fputc((char) 48,file2);*/
put_measure(file2,width,1);
c1=32;
fputc(c1,file2);
/*fputc((char) 48,file2);*/
put_measure(file2,height,1);
c1=10;
fputc(c1,file2);
put_measure(file2,(unsigned int)255,0);
fputc((char) (10),file2);
while ((c2 = getc(file1)) != EOF)
putc((char) (c2),file2);
fclose(file1);
fclose(file2);
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -