www.pudn.com > 医学算法.rar > bit.c


/*
	bit - convert images to bit planes

	Carl Crawford 
	Purdue University
	W. Lafayette, IN 47907

	October 1981
*/

#include 

char	ibuf[512];	/* input buffer */
char	obuf[64];	/* output buffer */
char	*ifn = "/dev/gr"; /* input file name */
char	*ofn;		/* output file name */
FILE	*ifd;		/* input file descriptor */
FILE	*ofd;		/* output file descriptor */
int	x = 512;	/* x size of picture */
int	y = 480;	/* y size of picture */

char	*table[] = {
		"if",
		"of",
		"x",
		"y",
		0
	};

main(argc,argv)
	int	argc;
	char	**argv;
{
	char	c;
	char	tmp;
	int	i;
	register int j;
	register char *p,*q;

	while(++argv,--argc){
		if(**argv == '-')while(c = *++*argv)switch(c){

		default:
			fprintf(stderr,"bad flag: -%c\n",c);
			exit(1);
		}else switch(comm(*argv)){
		
		case 1:		/* input file name */
			ifn = *argv+3;
			break;
		case 2:		/* output file name */
			ofn = *argv+3;
			break;
		case 3:		/* x */
			x = atoi(*argv + 2);
			break;
		case 4:		/* y */
			y = atoi(*argv + 2);
			break;
		}
	}

	if(x<1 || x>512)err("bad x","");
	if(y<1 || y>512)err("bad y","");

	if(ifn[0] == '-' && !ifn[1]){
		ifd = stdin;
	}else{
		if((ifd=fopen(ifn,"r")) == NULL){
			err("can't open: ",ifn);
		}
	}

	if(ofn){
		if((ofd=fopen(ofn,"w"))==NULL){
			err("can't create: ",ofn);
		}
	}else{
		ofd = stdout;
	}

	for(i=x;i<512;ibuf[i++]=0);

	for(i=0;i