forked from tTh/FloatImg
		
	enhancing fimg to pnm converter
This commit is contained in:
		
							parent
							
								
									2aabc8b26b
								
							
						
					
					
						commit
						ffc99e6114
					
				| @ -41,6 +41,7 @@ int   fimg_destroy(FloatImg *fimg); | |||||||
| int   fimg_print_version(int k); | int   fimg_print_version(int k); | ||||||
| void  fimg_printhead(FloatImg *h); | void  fimg_printhead(FloatImg *h); | ||||||
| int   fimg_describe(FloatImg *head, char *txt); | int   fimg_describe(FloatImg *head, char *txt); | ||||||
|  | char *fimg_str_type(int type); | ||||||
| int   fimg_fileinfo(char *fname, int *datas); | int   fimg_fileinfo(char *fname, int *datas); | ||||||
| int   fimg_plot_rgb (FloatImg *head, int x, int y, float r, float g, float b); | int   fimg_plot_rgb (FloatImg *head, int x, int y, float r, float g, float b); | ||||||
| int   fimg_clear(FloatImg *fimg); | int   fimg_clear(FloatImg *fimg); | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ switch (type) { | |||||||
| return 0; | return 0; | ||||||
| } | } | ||||||
| /* --------------------------------------------------------------------- */ | /* --------------------------------------------------------------------- */ | ||||||
| static char *fimg_str_type(int type) | char *fimg_str_type(int type) | ||||||
| { | { | ||||||
| switch (type) { | switch (type) { | ||||||
|  	case FIMG_TYPE_GRAY:		return "gray"; |  	case FIMG_TYPE_GRAY:		return "gray"; | ||||||
|  | |||||||
| @ -24,8 +24,9 @@ foo = fimg_fileinfos(srcname, infos); | |||||||
| if (foo) { fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo); } | if (foo) { fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo); } | ||||||
| 
 | 
 | ||||||
| if (verbosity) { | if (verbosity) { | ||||||
| 	fprintf(stderr, "image '%s' is %d x %d\n", | 	fprintf(stderr, "image '%s' is %d x %d  %s\n", | ||||||
| 				srcname, infos[0], infos[1]); | 				srcname, infos[0], infos[1], | ||||||
|  | 				fimg_str_type(infos[2])); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| foo = fimg_create_from_dump(srcname, &fimg); | foo = fimg_create_from_dump(srcname, &fimg); | ||||||
| @ -44,22 +45,51 @@ if(foo) { fprintf(stderr, "%p to '%s' -> %d\n", &fimg, dstname, foo); } | |||||||
| return 0; | return 0; | ||||||
| } | } | ||||||
| /* --------------------------------------------------------------------- */ | /* --------------------------------------------------------------------- */ | ||||||
|  | static void help(int flag) | ||||||
|  | { | ||||||
|  | if (flag) { | ||||||
|  | 	fprintf(stderr, "conversion FIMG -> PNM 16 bits\n"); | ||||||
|  | 	fimg_print_version(1); | ||||||
|  | 	} | ||||||
|  | puts("usage :"); | ||||||
|  | puts("\tfimg2pnm [flags] infile.fimg outfile.pnm"); | ||||||
|  | } | ||||||
|  | /* --------------------------------------------------------------------- */ | ||||||
| int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||||||
| { | { | ||||||
| int		foo; | int		foo, opt; | ||||||
| 
 | 
 | ||||||
| if (3 != argc) { | if (argc == 1) { | ||||||
| 	fimg_print_version(1); | 	help(0); | ||||||
| 	fprintf(stderr, "usage:\n\t%s foo.fimg bar.pnm\n", argv[0]); | 	exit(0); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | while ((opt = getopt(argc, argv, "v")) != -1) { | ||||||
|  | 	switch(opt) { | ||||||
|  | 		case 'v':	verbosity++;		break; | ||||||
|  | 		case 'h':	help(1);		exit(1); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | #if DEBUG_LEVEL | ||||||
|  | /* mmmm, is it the good way ? */ | ||||||
|  | printf("argc %d -> %d\n", argc, argc-optind); | ||||||
|  | for (foo=optind; foo<argc; foo++) { | ||||||
|  | 	printf("   %d  %s\n", foo, argv[foo]); | ||||||
|  | 	} | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | if (2 != argc-optind) { | ||||||
|  | 	fprintf(stderr, "error: %s need two filenames\n", argv[0]); | ||||||
| 	exit(1); | 	exit(1); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| if ( 0 != access(argv[1], R_OK|W_OK) ) {	/* fimg is NOT readable */ | if ( 0 != access(argv[optind], R_OK) ) {	/* fimg is NOT readable */ | ||||||
| 	fprintf(stderr, "%s: %s don't exist.\n", argv[0], argv[1]); | 	fprintf(stderr, "%s: %s don't exist.\n", argv[0], argv[optind]); | ||||||
| 	exit(2); | 	exit(2); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| foo = convertir_fimg_en_pnm(argv[1], argv[2], 0); | foo = convertir_fimg_en_pnm(argv[optind], argv[optind+1], 0); | ||||||
| if (foo) fprintf(stderr, "conversion -> %d\n", foo); | if (foo) fprintf(stderr, "conversion -> %d\n", foo); | ||||||
| 
 | 
 | ||||||
| return 0; | return 0; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user