forked from tTh/FloatImg
		
	+ movepixels experiment
This commit is contained in:
		
							parent
							
								
									f24ad0d229
								
							
						
					
					
						commit
						40bf700a32
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -85,4 +85,5 @@ experiment/*.fimg | ||||
| experiment/*.pnm | ||||
| experiment/*.o | ||||
| experiment/muxplanes | ||||
| experiment/movepixels | ||||
| 
 | ||||
|  | ||||
| @ -1,12 +1,13 @@ | ||||
| 
 | ||||
| #  experiments
 | ||||
| 
 | ||||
| #
 | ||||
| #  some ugly experiments, do not use in production
 | ||||
| #
 | ||||
| 
 | ||||
| COPT = -Wall -fpic -g -DDEBUG_LEVEL=1 -lm | ||||
| DEPS = ../floatimg.h  ../libfloatimg.a Makefile | ||||
| LIBS = -ltiff -lpnglite -lcfitsio | ||||
| 
 | ||||
| all:	assemblage extracteur muxplanes | ||||
| all:	assemblage extracteur muxplanes movepixels | ||||
| 
 | ||||
| assemblage:	assemblage.c ${DEPS}  | ||||
| 	gcc $(COPT) $< ../libfloatimg.a ${LIBS} -o $@ | ||||
| @ -16,3 +17,6 @@ extracteur:	extracteur.c ${DEPS} | ||||
| 
 | ||||
| muxplanes:	muxplanes.c ${DEPS} | ||||
| 	gcc $(COPT) $<  ../libfloatimg.a ${LIBS} -o $@ | ||||
| 
 | ||||
| movepixels:	movepixels.c ${DEPS} | ||||
| 	gcc $(COPT) $<  ../libfloatimg.a ${LIBS} -o $@ | ||||
|  | ||||
							
								
								
									
										154
									
								
								experiment/movepixels.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										154
									
								
								experiment/movepixels.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,154 @@ | ||||
| /*
 | ||||
|  *		MOVEPIXELS | ||||
|  * | ||||
|  *	This is experimental, do not use in production ! | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| #include   <stdio.h> | ||||
| #include   <stdlib.h> | ||||
| #include   <stdint.h> | ||||
| 
 | ||||
| #include   <floatimg.h> | ||||
| 
 | ||||
| int		verbosity; | ||||
| 
 | ||||
| /* ------------------------------------------------------------------- */ | ||||
| int displace(FloatImg *psrc, FloatImg *pshift, FloatImg *pdst, float k) | ||||
| { | ||||
| int		xd, yd, xs, ys; | ||||
| float		rgb[3], disp[3], maxv; | ||||
| float		minmax[6]; | ||||
| int		foo, inside, outside; | ||||
| float		dltr, dltg, dltb;	/* delta des minmax */ | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( %p %p %p %g )\n", __func__, | ||||
| 			psrc, pshift, pdst, k); | ||||
| #endif | ||||
| 
 | ||||
| if (FIMG_TYPE_RGB != psrc->type) { | ||||
| 	fprintf(stderr, "%s: bad src type %d\n", __func__, psrc->type); | ||||
| 	return -7; | ||||
| 	} | ||||
| if (fimg_images_not_compatible(psrc, pshift)) { | ||||
| 	fprintf(stderr, "%s: bad shift image %d\n", __func__, pshift->type); | ||||
| 	return -8; | ||||
| 	} | ||||
| if (fimg_images_not_compatible(psrc, pdst)) { | ||||
| 	fprintf(stderr, "%s: bad dst image %d\n", __func__, pdst->type); | ||||
| 	return -8; | ||||
| 	} | ||||
| 
 | ||||
| foo = fimg_get_minmax_rgb(pshift, minmax); | ||||
| if (verbosity) { | ||||
| 	fimg_print_minmax(minmax, (char *)__func__); | ||||
| 	} | ||||
| dltr = minmax[1] - minmax[0]; | ||||
| dltg = minmax[3] - minmax[2]; | ||||
| dltb = minmax[5] - minmax[4]; | ||||
| if (verbosity) fprintf(stderr, "delta shift  %f %f %f\n", dltr, dltg, dltb); | ||||
| 
 | ||||
| maxv = fimg_get_maxvalue(psrc); | ||||
| inside = outside = 0; | ||||
| 
 | ||||
| /* hardcoded parameters. this is very dirty :) */ | ||||
| 
 | ||||
| #define  MULT  (140.0) | ||||
| #define  OFFS  (70.0) | ||||
| 
 | ||||
| /* loop over all the pixels of the DESTINATION picture */ | ||||
| for (yd=0; yd<pdst->height; yd++) { | ||||
| 
 | ||||
| 	for (xd=0; xd<pdst->width; xd++) { | ||||
| 
 | ||||
| 		fimg_get_rgb(pshift, xd, yd, disp); | ||||
| 
 | ||||
| 		xs = xd + ((disp[0]/dltr*MULT) - OFFS); | ||||
| 		ys = yd + ((disp[2]/dltb*MULT) - OFFS); | ||||
| 
 | ||||
| 		if ( xs<0 || xs>psrc->width 	|| | ||||
| 		     ys<0 || ys>psrc->height ) { | ||||
| 			rgb[0] = maxv;			/* fucking bug XXX */ | ||||
| 			rgb[1] = rgb[2] = 0.0; | ||||
| 			outside++; | ||||
| 			} | ||||
| 		else { | ||||
| 			fimg_get_rgb(psrc, xs, ys, rgb); | ||||
| 			inside++; | ||||
| 			} | ||||
| 
 | ||||
| 		fimg_put_rgb(pdst, xd, yd, rgb); | ||||
| 
 | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| // fprintf(stderr, "%s: inside %d outside %d\n", __func__, inside, outside);
 | ||||
| 
 | ||||
| return 0; | ||||
| } | ||||
| /* ------------------------------------------------------------------- */ | ||||
| 
 | ||||
| int move_the_pixels(char *infile, char *statfile, char *outfile, int k) | ||||
| { | ||||
| int		foo; | ||||
| FloatImg	src, shift, dst; | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( %s %s 0x%04x )\n", __func__, | ||||
| 				infile, outfile, k); | ||||
| #endif | ||||
| 
 | ||||
| /* 'infile' contains the shifting values */ | ||||
| foo = fimg_create_from_dump(infile, &shift); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "%s: error loading '%s'\n", __func__, infile); | ||||
| 	return foo; | ||||
| 	} | ||||
| 
 | ||||
| fimg_clone(&shift, &dst, 0); | ||||
| 
 | ||||
| foo = fimg_create_from_dump(statfile, &src); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "%s: error loading 'cumul.fimg'\n", __func__); | ||||
| 	return foo; | ||||
| 	} | ||||
| 
 | ||||
| foo = displace(&src, &shift, &dst, 42.42); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "%s: err %d in disp map 0\n", __func__, foo); | ||||
| 	return foo; | ||||
| 	} | ||||
| 
 | ||||
| foo = fimg_export_picture(&dst, outfile, 0); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "%s: err %d saving result\n", __func__, foo); | ||||
| 	return foo; | ||||
| 	} | ||||
| 
 | ||||
| return 0; | ||||
| } | ||||
| /* ------------------------------------------------------------------- */ | ||||
| 
 | ||||
| int main(int argc, char *argv[]) | ||||
| { | ||||
| int		foo; | ||||
| char		*srcfile, *dstfile; | ||||
| 
 | ||||
| if (3 != argc) { | ||||
| 	fprintf(stderr, "usage:\n\t%s src.fimg dst.fimg\n", argv[0]); | ||||
| 	exit(1); | ||||
| 	} | ||||
| 
 | ||||
| srcfile = argv[1]; | ||||
| dstfile = argv[2]; | ||||
| verbosity = 0; | ||||
| 
 | ||||
| foo = move_the_pixels(srcfile, "cumul.fimg", dstfile, 3); | ||||
| 
 | ||||
| // fprintf(stderr, "move pixels %s -> %s = %d\n", srcfile, dstfile, foo);
 | ||||
| 
 | ||||
| return 0; | ||||
| } | ||||
| /* ------------------------------------------------------------------- */ | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 tth
						tth