forked from tTh/FloatImg
		
	work on the real PGM export
This commit is contained in:
		
							parent
							
								
									0da81df892
								
							
						
					
					
						commit
						6ffc08188d
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -12,6 +12,7 @@ gmon.out | ||||
| *.swp | ||||
| 
 | ||||
| *.pnm | ||||
| *.pgm | ||||
| *.fimg | ||||
| essai | ||||
| MANIFEST | ||||
|  | ||||
| @ -4,7 +4,7 @@ | ||||
|  *	http://la.buvette.org/photos/cumul
 | ||||
|  */ | ||||
| 
 | ||||
| #define		FIMG_VERSION	167 | ||||
| #define		FIMG_VERSION	169 | ||||
| 
 | ||||
| /*
 | ||||
|  *	in memory descriptor | ||||
| @ -54,6 +54,7 @@ typedef struct { | ||||
| #define FILE_TYPE_BMP			7 | ||||
| #define FILE_TYPE_EXR			8 | ||||
| #define FILE_TYPE_DICOM			9 | ||||
| #define FILE_TYPE_PGM			10 | ||||
| 
 | ||||
| /*	lib/contrast.c			*/ | ||||
| #define CONTRAST_NONE			0 | ||||
| @ -151,6 +152,7 @@ int fimg_export_picture(FloatImg *pic, char *fname, int flags); | ||||
| 
 | ||||
| /*	PNM files module		*/ | ||||
| int fimg_save_as_pnm(FloatImg *head, char *fname, int flags); | ||||
| int fimg_save_as_pgm(FloatImg *head, char *fname, int flags); | ||||
| int fimg_load_from_pnm(char *fname, FloatImg *head, int notused); | ||||
| 
 | ||||
| double fimg_timer_set(int whot); | ||||
|  | ||||
| @ -59,6 +59,10 @@ switch(filetype) { | ||||
| 		fprintf(stderr, "%s: file type EXR experimental\n", __func__); | ||||
| 		foo = fimg_save_as_exr(pic, fname, 0); | ||||
| 		break; | ||||
| 	case FILE_TYPE_PGM: | ||||
| 		fprintf(stderr, "XXX %s EXPERIMENT!\n", __func__); | ||||
| 		foo = fimg_save_as_pgm(pic, fname, 0); | ||||
| 		break; | ||||
| 	default: | ||||
| 		foo = -1789; | ||||
| 		break; | ||||
|  | ||||
| @ -100,6 +100,7 @@ if (!strcasecmp(name, "tif" ))		return FILE_TYPE_TIFF; | ||||
| if (!strcasecmp(name, "fits"))		return FILE_TYPE_FITS; | ||||
| if (!strcasecmp(name, "exr"))		return FILE_TYPE_EXR; | ||||
| if (!strcasecmp(name, "dicom"))		return FILE_TYPE_EXR; | ||||
| if (!strcasecmp(name, "pgm" ))		return FILE_TYPE_PGM; | ||||
| 
 | ||||
| return -1; | ||||
| } | ||||
|  | ||||
| @ -196,3 +196,51 @@ fputs("\n", fp);		fclose(fp); | ||||
| return 0; | ||||
| } | ||||
| /* ---------------------------------------------------------------- */ | ||||
| 
 | ||||
| /* 	nouveau 10 fevrier 2022 */ | ||||
| 
 | ||||
| 
 | ||||
| int fimg_save_as_pgm(FloatImg *src, char *fname, int flags) | ||||
| { | ||||
| FILE		*fp; | ||||
| float		maximum, fk; | ||||
| int		area, idx, printed; | ||||
| float		accu; | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( %p %s %d )\n", __func__, src, fname, flags); | ||||
| #endif | ||||
| 
 | ||||
| if ( src->type != FIMG_TYPE_RGB ) { | ||||
| #if DEBUG_LEVEL  | ||||
| 	fprintf(stderr, "%s : type %d is bad.\n", __func__, src->type); | ||||
| #endif | ||||
| 	return -1; | ||||
| 	} | ||||
| 
 | ||||
| if (NULL==(fp=fopen(fname, "w"))) { | ||||
| 	perror(fname); | ||||
| 	return -2; | ||||
| 	} | ||||
| 
 | ||||
| fprintf(fp, "P2\n%d\n%d\n65532\n\n", src->width, src->height); | ||||
| 
 | ||||
| area = src->width * src->height; | ||||
| maximum = fimg_get_maxvalue(src); | ||||
| fk = maximum / 65535.0; | ||||
| 
 | ||||
| printed = 0; | ||||
| for (idx=0; idx<area; idx++) { | ||||
| 	accu = (src->R[idx] + src->G[idx] + src->B[idx]) / 3.0; | ||||
| 	printed += fprintf(fp, "%d ", (int)(accu/fk)); | ||||
| 	if (printed > 72) { | ||||
| 		fputs("\n", fp); | ||||
| 		printed = 0; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| fclose(fp); | ||||
| 
 | ||||
| return 0; | ||||
| } | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										18
									
								
								lib/t.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								lib/t.c
									
									
									
									
									
								
							| @ -83,12 +83,13 @@ return 0; | ||||
| } | ||||
| /* ---------------------------------------------------------------- */ | ||||
| 
 | ||||
| int essai_2gray(FloatImg *picz, char *outname) | ||||
| int essai_2gray(FloatImg *picz, char *basename) | ||||
| { | ||||
| int		foo; | ||||
| FloatImg	gray; | ||||
| char		outname[200]; | ||||
| 
 | ||||
| fprintf(stderr, ">>> %s ( %p '%s' )\n", __func__, picz, outname); | ||||
| fprintf(stderr, ">>> %s ( %p '%s' )\n", __func__, picz, basename); | ||||
| 
 | ||||
| foo = fimg_create(&gray, picz->width, picz->height, FIMG_TYPE_GRAY); | ||||
| if (foo) { | ||||
| @ -101,9 +102,16 @@ if (foo) { | ||||
| 	exit(1); | ||||
| 	} | ||||
| 
 | ||||
| strcpy(outname,basename); strcat(outname, ".pnm"); | ||||
| foo = fimg_save_as_pnm(&gray, outname, 0); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo); | ||||
| 	fprintf(stderr, "%s : err %d on save_as_PNM\n", __func__, foo); | ||||
| 	exit(1); | ||||
| 	} | ||||
| strcpy(outname,basename); strcat(outname, ".pgm"); | ||||
| foo = fimg_save_as_pgm(&gray, outname, 0); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "%s : err %d on save_as_PGM\n", __func__, foo); | ||||
| 	exit(1); | ||||
| 	} | ||||
| 
 | ||||
| @ -261,8 +269,8 @@ if (verbosity)	{ | ||||
| 	fimg_print_sizeof(); | ||||
| 	} | ||||
| 
 | ||||
| foo = essai_contraste("quux.fimg"); | ||||
| fprintf(stderr, "retour essai contraste -> %d\n", foo); | ||||
| foo = essai_2gray(NULL, "quux"); | ||||
| fprintf(stderr, "retour essai  -> %d\n", foo); | ||||
| 
 | ||||
| // foo = essai_clone_et_copy(0);
 | ||||
| // fprintf(stderr, "retour essai clone'n'copy -> %d\n", foo);
 | ||||
|  | ||||
| @ -43,7 +43,7 @@ puts("\t-v\tincrease verbosity"); | ||||
| puts("\t-o\tname of output file"); | ||||
| puts("\t-g\tconvert to gray level"); | ||||
| puts(""); | ||||
| if (verbosity) { puts(""); fimg_print_version(1); } | ||||
| if (verbosity) { puts("Xperiment"); fimg_print_version(1); } | ||||
| exit(0); | ||||
| } | ||||
| /* --------------------------------------------------------------------- */ | ||||
| @ -54,6 +54,7 @@ int		opt; | ||||
| int		compte = 0; | ||||
| 
 | ||||
| int		to_gray = 0; | ||||
| int		experiment = 0; | ||||
| char		*output_file = "out.fimg"; | ||||
| FloatImg	accu, temp; | ||||
| int		src_loaded = 0; | ||||
| @ -61,12 +62,13 @@ float		vals[6]; | ||||
| 
 | ||||
| g_width = g_height = 0; | ||||
| 
 | ||||
| while ((opt = getopt(argc, argv, "gho:v")) != -1) { | ||||
| while ((opt = getopt(argc, argv, "gho:vx")) != -1) { | ||||
| 	switch(opt) { | ||||
| 		case 'g':	to_gray = 1;			break; | ||||
| 		case 'h':	help(0);			break; | ||||
| 		case 'o':	output_file = optarg;		break; | ||||
| 		case 'v':	verbosity++;			break; | ||||
| 		case 'x':	experiment++;			break; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| @ -101,6 +103,13 @@ for (idx=optind; idx<argc; idx++) { | ||||
| 	compte++; | ||||
| 	} | ||||
| 
 | ||||
| /*			XXX */ | ||||
| if (experiment) { | ||||
| 
 | ||||
| 		} | ||||
| /*			XXX */ | ||||
| 
 | ||||
| 
 | ||||
| if (to_gray) { | ||||
| 	foo = fimg_desaturate(&accu, &accu, 0); | ||||
| 	if (foo) { | ||||
| @ -108,7 +117,8 @@ if (to_gray) { | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| // XXX foo = fimg_dump_to_file(&accu, output_file, 0);
 | ||||
| /* PLEASE CHECK IF EXPORT TO GRAY MAKE A REAL .pgm FILE */ | ||||
| 
 | ||||
| foo = fimg_export_picture(&accu, output_file, 0); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "error %d while saving '%s'\n", foo, output_file); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 tth
						tth