diff options
| -rw-r--r-- | fly-tools/ThreadedFilterFlyMask/main.c | 69 | 
1 files changed, 34 insertions, 35 deletions
diff --git a/fly-tools/ThreadedFilterFlyMask/main.c b/fly-tools/ThreadedFilterFlyMask/main.c index 80da5e9..d2da2c6 100644 --- a/fly-tools/ThreadedFilterFlyMask/main.c +++ b/fly-tools/ThreadedFilterFlyMask/main.c @@ -21,6 +21,9 @@  #include <stdlib.h>   #include <libgen.h>  #include <wand/MagickWand.h>  + +#include <wand/composite.h>  +#include <wand/convert.h>   #include "thpool.h"  #define ThrowWandException(wand)  {  char *description; ExceptionType severity; description=MagickGetException(wand,&severity);  (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description);  description=(char *) MagickRelinquishMemory(description);  exit(-1); } @@ -28,35 +31,33 @@  MagickWand *background;  char **global_argv; - - -																																										  void convert_image(char *file) { -	printf("filename: %s", file);  	MagickWand *mask = NewMagickWand();  	MagickBooleanType status; -	char output_name[256]; -	 -		 +	char *output_name = malloc(256);  	if(MagickReadImage(mask, file) == MagickFalse) { -		ThrowWandException(mask); -		printf("could not read file: %s", file ); -		return; -	} +  ThrowWandException(mask); +	 return; +  } -	/* image ops */ -	MagickResizeImage(mask,10,10,LanczosFilter,1.0); -	 -  sprintf(output_name, "%s%s", global_argv[3], basename(file)); +  // convert \\\( -composite -compose Difference $output_dir/Masks/$setname/Background.png {} \\\) \\\( -contrast-stretch 90%x0% \\\) \\\( -threshold 30% \\\) $output_dir/Masks/$setname/Masks/{/} +  int i = MagickGetImageHeight(mask)*MagickGetImageWidth(mask)/100.0f; -	 -	status=MagickWriteImages(mask, output_name , MagickTrue); -	if ( status == MagickFalse ) { -			puts("write error"); - } +  MagickCompositeImage(mask, background, DifferenceCompositeOp, 0, 0); +  MagickContrastStretchImage(mask, .9*i, i);  +//	MagickThresholdImage(mask, 0.30); + +	sprintf(output_name, "%s%s", global_argv[3], basename(file)); +  if(MagickWriteImages(mask, output_name, MagickTrue) == MagickFalse) { +		ThrowWandException(mask); +	}  	mask = DestroyMagickWand(mask); + +	printf("output written to: %s \n", output_name); +	free(output_name); +	free(file);  }  int main( int argc, char **argv){ @@ -65,16 +66,7 @@ int main( int argc, char **argv){  	// argv 2 = input list  	// argv 3 = output folder -	char *stream; - -	stream = "hey \n"; - -	printf("%s", stream); -  if (stream[strlen(stream)] == '\n') { -				  stream[strlen(stream) - 1] == '\0'; -} -	printf("%s", stream); -		MagickBooleanType   status; +	MagickBooleanType   status;  	global_argv = argv;    MagickWandGenesis(); @@ -87,13 +79,20 @@ int main( int argc, char **argv){  	}  	thpool_t* threadpool;             /* make a new thread pool structure     */ -	threadpool=thpool_init(1);        /* initialise it to 4 number of threads */ -	 -	char line[256]; +	threadpool=thpool_init(8);        /* initialise it to 4 number of threads */ + +	char filename[256];	 +	char *temp;  	FILE *f = fopen ( argv[2], "r" );  	if ( f != NULL ) { -		while ( fgets ( line, sizeof line, f ) != NULL ) { -			thpool_add_work(threadpool, (void*)convert_image, (void*)line); +		while ( fgets ( filename, sizeof(filename), f ) != NULL ) { +			temp = strchr(filename, '\n'); +      if (temp != NULL) *temp = '\0';  +			char *filename_r = malloc(256); +			strncpy(filename_r, filename, sizeof(filename)); +			printf("add work: %s \n", filename); + +			thpool_add_work(threadpool, (void*)convert_image, (void*)filename_r);  		}  	fclose ( f );  	}  | 
