コード例 #1
0
ファイル: dpynorm.c プロジェクト: Booley/nbis
int dpynorm(int argc, char *argv[])
{
   int ret;
   int done=0, align, bpi, bytes;
   unsigned int iw, ih, depth, whitepix;
   unsigned char *data;
   extern int optind, verbose;

   while ( !done && (optind < argc)) {
      if((ret = readfile(argv[optind],&data,&bpi,&iw,&ih,&depth,
                        &whitepix,&align)))
	return(ret);

      if (depth == 1)
         bytes = howmany(iw,CHAR_BIT) * ih;
      else if(depth == 8)
         bytes = iw * ih;
      else /* if(depth == 24) */
         bytes = iw * ih * 3;

      if (verbose > 2) {
         unsigned int zero, one;
         (void) printf("%s:\n",argv[optind]);
         (void) printf("\timage size: %u x %u (%d bytes)\n",
                       iw,ih,bytes);
         (void) printf("\tdepth: %u\n",depth);
                       pixelcount(data,bytes,&zero,&one);
         (void) printf("\tpixel breakdown: %u zero, %u one\n\n",
                       zero,one);
      }

      if((ret = dpyimage(argv[optind],data,iw,ih,depth,whitepix,
                         align,&done))){
         free((char *)data);
         return(ret);
      }

      free((char *)data);
      optind++;
   }

   return(0);
}
コード例 #2
0
ファイル: makechar.cpp プロジェクト: asanoki/nhocr-0.21-a
int main(int ac, char **av){
	char	*infile = NULL;
	char	*outfile = NULL;
	char	*fontfile = NULL;
	FILE	*fp_out;
	int	k;
	int	rcode;
	int	sw_err = 0;
	CharCode	*cclist;
	int	cid, charcount;

	FT_Library	ftlibrary;
	FT_Face		face;

	for ( k=1 ; k<ac ; k++ ){
		if ( 0 == strcmp(av[k],"-h") ){  sw_help = 1;  continue; }
		if ( 0 == strcmp(av[k],"-v") ){  sw_verbose = 1;  continue; }
		if ( 0 == strcmp(av[k],"-font") ){
			if ( ++k >= ac ){  sw_err = 1;  break; }
			fontfile = av[k];  continue;
		}
		if ( infile == NULL ){  infile = av[k]; continue; }
		else{	outfile = av[k]; continue; }
		sw_err = 1;  break;
	}

	if ( sw_err || sw_help \
	  || infile == NULL || outfile == NULL || fontfile == NULL ){
		fputs("Make character images\n",stderr);
		fputs("makechar v1.1  Copyright (C) 2009,2010 Hideaki Goto\n",stderr);
		fputs("usage: makechar [options] in_cctable out_charfile\n",stderr);
		fputs("         -font file : set TrueType font file\n",stderr);
		fputs("         -v         : verbose mode\n",stderr);
		return(1);
	}

	if ( 0 > (charcount = load_codelist(infile, &cclist, 0)) ){
		// Note: The first code is always SPACE.
		fprintf(stderr, "Can't load character code list \"%s\".\n", infile);
		return(2);
	}

	// Initialize FreeType
	if ( 0 != FT_Init_FreeType( &ftlibrary ) ){
		fputs("FreeType initialization failed.\n",stderr);
		return(3);
	}
	if ( 0 != FT_New_Face(ftlibrary, fontfile, 0, &face ) ){
		fprintf(stderr, "Failed in loading TrueType font file \"%s\".\n",fontfile);
		FT_Done_FreeType(ftlibrary);
		return(3);
	}

	if ( NULL == (fp_out = fopen(outfile,"wb")) ){
		fprintf(stderr,"Failed in opening file \"%s\".\n",outfile);
		return(3);
	}

	for ( cid=0 ; cid < charcount -1 ; cid++ ){
		// Note: The first code is always SPACE.
		if ( sw_verbose ){
			fprintf(stderr,"%06d: %s\n", cid, cclist[cid+1].ccode_dic);
		}

		if ( 0 > (rcode = render_character(face, cclist[cid+1].ccode_dic)) ){
			fprintf(stderr,"Character %d rendering failed.\n",cid);
			break;
		}
		else if ( rcode == 1 ){
			fprintf(stderr,"Warning: Width overflow at character %d.\n",cid);
		}

		if ( pixelcount() == 0 ){
			fprintf(stderr,"Warning: Character %d is blank.\n",cid);
		}
		if ( show_image(fp_out) ){
			fprintf(stderr,"Write error on \"%s\".\n",outfile);
			fclose(fp_out);
			unlink(outfile);
			return(3);
		}
	}

	if ( fclose(fp_out) ){
		fprintf(stderr,"Write error on \"%s\".\n",outfile);
		unlink(outfile);
		return(3);
	}

	FT_Done_Face(face);
	FT_Done_FreeType(ftlibrary);
	return(0);
}