working on lowpass filter
This commit is contained in:
		
							parent
							
								
									12347e9066
								
							
						
					
					
						commit
						c6b75d3bba
					
				| @ -20,7 +20,7 @@ | ||||
|  *	https://git.tetalab.org/tTh/FloatImg
 | ||||
|  */ | ||||
| 
 | ||||
| #define		FIMG_VERSION	(229) | ||||
| #define		FIMG_VERSION	(230) | ||||
| #define		RELEASE_NAME	("noname") | ||||
| #define		PATCH_LEVEL	("aaaa") | ||||
| 
 | ||||
|  | ||||
| @ -29,12 +29,12 @@ fprintf(stderr, "%8.3f   %8.3f   %8.3f\n", M[6], M[7], M[8]); | ||||
| 
 | ||||
| sum = 0.0; | ||||
| for (idx=0; idx<9; idx++)	sum += M[idx]; | ||||
| fprintf(stderr, "     sum  %8.3f\n", sum); | ||||
| fprintf(stderr, "    mult  %8.3f\n", filtr->mult); | ||||
| fprintf(stderr, "  offset  %8.3f\n", filtr->offset); | ||||
| fprintf(stderr, "        sum:  %8.3f\n", sum); | ||||
| fprintf(stderr, "       mult:  %8.3f\n", filtr->mult); | ||||
| fprintf(stderr, "     offset:  %8.3f\n", filtr->offset); | ||||
| 
 | ||||
| value = (sum * filtr->mult) + filtr->offset; | ||||
| fprintf(stderr, "   value  %8.3f   ???\n", value); | ||||
| fprintf(stderr, "      value:  %8.3f\n", value); | ||||
| 
 | ||||
| return 0; | ||||
| } | ||||
| @ -46,9 +46,9 @@ float		*pr, *pg, *pb;		/* alias for src pix filds */ | ||||
| float		*M;			/* alias of filter matrix */ | ||||
| double		dval; | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, src, dst, filtr); | ||||
| #endif | ||||
| // #if DEBUG_LEVEL
 | ||||
| fprintf(stderr, ">>> %s ( %p %p   %p )\n", __func__, src, dst, filtr); | ||||
| // #endif
 | ||||
| 
 | ||||
| if (src->type != FIMG_TYPE_RGB) { | ||||
| 	fprintf(stderr, "%s: src type %d invalid\n", __func__, src->type); | ||||
| @ -59,12 +59,12 @@ if (dst->type != FIMG_TYPE_RGB) { | ||||
| 	return -99; | ||||
| 	} | ||||
| if (fimg_images_not_compatible(src, dst)) { | ||||
| 	fprintf(stderr, "%s: src & dst not comatibles\n", __func__); | ||||
| 	fprintf(stderr, "%s: src & dst not compatibles\n", __func__); | ||||
| 	return -98; | ||||
| 	} | ||||
| 
 | ||||
| if (verbosity > 1) { | ||||
| 	fimg_show_filter(__func__, filtr); | ||||
| 	fimg_show_filter((char *)__func__, filtr); | ||||
| 	} | ||||
| 
 | ||||
| /*	aliasing some vars for cleaner code */ | ||||
| @ -73,9 +73,7 @@ w = src->width;	h = src->height; | ||||
| M = filtr->matrix; | ||||
| 
 | ||||
| for (y=1; y < h-1; y++) { | ||||
| 
 | ||||
| 	for (x=1; x < w-1; x++) { | ||||
| 
 | ||||
| 		of = x + (y * w); | ||||
| 
 | ||||
| 	dval =	M[0] * pr[of-(w+1)]	+ | ||||
| @ -142,9 +140,7 @@ if (img->type != FIMG_TYPE_RGB) { | ||||
| pr = img->R;	pg = img->G;	pb = img->B; | ||||
| 
 | ||||
| for (y=1; y < img->height-1; y++) { | ||||
| 
 | ||||
| 	for (x=1; x < img->width-1; x++) { | ||||
| 
 | ||||
| 		offset = x + (y * img->width); | ||||
| 
 | ||||
| 	cr =	pr[offset]		+	pr[offset+1]	+ | ||||
| @ -159,7 +155,6 @@ for (y=1; y < img->height-1; y++) { | ||||
| 	pr[offset] = cr / 4.0; | ||||
| 	pg[offset] = cg / 4.0; | ||||
| 	pb[offset] = cb / 4.0; | ||||
| 
 | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| @ -237,6 +232,9 @@ return foo; | ||||
| } | ||||
| /* -------------------------------------------------------------------- */ | ||||
| /* -------------------------------------------------------------------- */ | ||||
| /*
 | ||||
|  *	XXX inplace filtering is a BAD IDEA | ||||
|  */ | ||||
| int fimg_lissage_3x3(FloatImg *img) | ||||
| { | ||||
| int		foo; | ||||
| @ -265,6 +263,13 @@ if (foo) { | ||||
| 	fprintf(stderr, "%s: lowpass -> %d\n", __func__, foo); | ||||
| 	abort(); | ||||
| 	} | ||||
| 
 | ||||
| foo = fimg_copy_data(&tmp, img); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "%s: copy data -> %d\n", __func__, foo); | ||||
| 	abort(); | ||||
| 	} | ||||
| 
 | ||||
| foo = fimg_destroy(&tmp); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "%s: destroy -> %d\n", __func__, foo); | ||||
|  | ||||
| @ -8,7 +8,7 @@ cp	tools/mkfimg tools/fimg2pnm tools/fimgops 	\ | ||||
| 	tools/png2fimg tools/fimgstats tools/fimgfx	\ | ||||
| 	tools/cumulfimgs tools/fimg2text		\ | ||||
| 	tools/fimghalfsize				\ | ||||
| 	tools/fimgmetadata				\ | ||||
| 	tools/fimgmetadata tools/fimgfilters		\ | ||||
| 	tools/fimgextract				\ | ||||
| 	/usr/local/bin | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										78
									
								
								tools/fimgfilters.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								tools/fimgfilters.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,78 @@ | ||||
| /*
 | ||||
| 			FIMGFILTERS | ||||
| 			=========== | ||||
|  new: Sun Oct  8 05:51:05 UTC 2023 | ||||
| */ | ||||
| 
 | ||||
| #include  <stdio.h> | ||||
| #include  <string.h> | ||||
| #include  <stdint.h> | ||||
| #include  <stdlib.h> | ||||
| #include  <unistd.h> | ||||
| #include  <time.h> | ||||
| 
 | ||||
| #include  "../floatimg.h" | ||||
| 
 | ||||
| int		verbosity; | ||||
| 
 | ||||
| /* --------------------------------------------------------------------- */ | ||||
| int filtre_image(char *infname, char *outfname) | ||||
| { | ||||
| FloatImg	src, dst; | ||||
| int		foo; | ||||
| 
 | ||||
| static FimgFilter3x3   filtre = { | ||||
|                 { | ||||
|                 2.0,    3.0,    2.0, | ||||
|                 3.0,    4.0,    3.0, | ||||
|                 2.0,    3.0,    2.0, | ||||
|                 }, | ||||
|         1.0/24.0,   0.0 | ||||
|         }; | ||||
| 
 | ||||
| fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, infname, outfname); | ||||
| 
 | ||||
| fimg_show_filter(NULL, &filtre); | ||||
| 
 | ||||
| if ((foo = fimg_create_from_dump(infname, &src))) { | ||||
| 	fprintf(stderr, "read error on '%s' is %d\n", infname, foo); | ||||
| 	exit(2); | ||||
| 	} | ||||
| if ((foo = fimg_clone(&src, &dst, 0))) { | ||||
| 	fprintf(stderr, "clone error on %p is %d\n", &src, foo); | ||||
| 	exit(3); | ||||
| 	} | ||||
| 
 | ||||
| foo = fimg_filter_3x3(&src, &dst, &filtre); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "%s: filtre -> %d\n", __func__, foo); | ||||
| 	exit(4); | ||||
| 	} | ||||
| 
 | ||||
| foo = fimg_dump_to_file(&dst, outfname, 0); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "dumping to file give us a %d\n", foo); | ||||
| 	} | ||||
| 
 | ||||
| return -12; | ||||
| } | ||||
| /* --------------------------------------------------------------------- */ | ||||
| 
 | ||||
| int main(int argc, char *argv[]) | ||||
| { | ||||
| int		foo; | ||||
| 
 | ||||
| if (3 != argc) { | ||||
| 	fprintf(stderr, "usage: %s in.fimg out.fimg\n", argv[0]); | ||||
| 	exit(1); | ||||
| 	} | ||||
| 
 | ||||
| fprintf(stderr, "    +++ %s +++\n", argv[0]); | ||||
| 
 | ||||
| foo = filtre_image(argv[1], argv[2]); | ||||
| fprintf(stderr, "    filtrage -> %d\n", foo); | ||||
| 
 | ||||
| return 0; | ||||
| } | ||||
| /* --------------------------------------------------------------------- */ | ||||
| 
 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 tTh
						tTh