From 06cdf7fce6018213936cae86ecf03d8baeb05b0b Mon Sep 17 00:00:00 2001 From: mutantturkey Date: Tue, 3 Jul 2012 13:34:42 -0400 Subject: formatting and added a flag to the background deriver --- fly-tools/mask/main.c | 91 +++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 47 deletions(-) (limited to 'fly-tools/mask/main.c') diff --git a/fly-tools/mask/main.c b/fly-tools/mask/main.c index ae8064c..5f7744f 100644 --- a/fly-tools/mask/main.c +++ b/fly-tools/mask/main.c @@ -18,30 +18,27 @@ char *output_folder = NULL; void convert_image(char *file) { - MagickWand *mask = NewMagickWand(); - char *output_name = malloc(256); - if(MagickReadImage(mask, file) == MagickFalse) { - ThrowWandException(mask); - return; + MagickWand *mask = NewMagickWand(); + char *output_name = malloc(256); + if(MagickReadImage(mask, file) == MagickFalse) { + ThrowWandException(mask); + return; } - // convert \\\( -composite -compose Difference $output_dir/Masks/$setname/Background.png {} \\\) \\\( -contrast-stretch 90%x0% \\\) \\\( -threshold 30% \\\) $output_dir/Masks/$setname/Masks/{/} - MagickCompositeImage(mask, background, DifferenceCompositeOp, 0, 0); -// MagickContrastStretchImage(mask, 90000, 0); MagickAutoLevelImage(mask); - MagickThresholdImage(mask, 30000); + MagickThresholdImage(mask, 30000); - sprintf(output_name, "%s%s", output_folder, basename(file)); + sprintf(output_name, "%s%s", output_folder, basename(file)); if(MagickWriteImages(mask, output_name, MagickTrue) == MagickFalse) { - ThrowWandException(mask); - } + ThrowWandException(mask); + } - mask = DestroyMagickWand(mask); + mask = DestroyMagickWand(mask); - printf("output written to: %s \n", output_name); - free(output_name); - free(file); + printf("output written to: %s \n", output_name); + free(output_name); + free(file); } int main( int argc, char **argv){ @@ -70,48 +67,48 @@ int main( int argc, char **argv){ exit(1); break; default: - break; -} + break; + } if( background_file == NULL || image_list == NULL || output_folder == NULL ) { puts(usage); exit(1); - } - MagickBooleanType status; + } + MagickBooleanType status; MagickWandGenesis(); background = NewMagickWand(); status=MagickReadImage(background, background_file); if (status == MagickFalse) { - puts("background could not load error"); - exit(0); - } - - thpool_t* threadpool; /* make a new thread pool structure */ - threadpool=thpool_init(4); /* initialise it to 4 number of threads */ - - char filename[256]; - char *temp; - FILE *f = fopen ( image_list, "r" ); - if ( f != NULL ) { - while ( fgets ( filename, sizeof(filename), f ) != NULL ) { - temp = strchr(filename, '\n'); + puts("background could not load error"); + exit(0); + } + + thpool_t* threadpool; /* make a new thread pool structure */ + threadpool=thpool_init(4); /* initialise it to 4 number of threads */ + + char filename[256]; + char *temp; + FILE *f = fopen ( image_list, "r" ); + if ( f != NULL ) { + 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 ); - } - else { - exit(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 ); + } + else { + exit(0); + } + puts("Will kill threadpool"); - thpool_destroy(threadpool); + thpool_destroy(threadpool); MagickWandTerminus(); - return 0; + return 0; } -- cgit v1.2.3