From a701f77b525ddaad7cb3897203eba1b72f3fa56a Mon Sep 17 00:00:00 2001 From: mutantturkey Date: Tue, 26 Jun 2012 19:36:39 -0400 Subject: initial commit of derive-background --- fly-tools/derive-background/pixel.c | 133 ++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 fly-tools/derive-background/pixel.c (limited to 'fly-tools') diff --git a/fly-tools/derive-background/pixel.c b/fly-tools/derive-background/pixel.c new file mode 100644 index 0000000..b38cd82 --- /dev/null +++ b/fly-tools/derive-background/pixel.c @@ -0,0 +1,133 @@ +#include +#include +#include + +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) +#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); } + +int main(int argc, char **argv) { + + MagickWand *magick_wand; + MagickWand *first; + + double green = 0; + double red = 0; + double blue = 0; + + int nImages = 0; + int image = 0; + + int i = 0; + int j = 0; + int k = 0; + int l = 0; + + MagickWandGenesis(); + first = NewMagickWand(); + // Check the height and width of the first image + MagickReadImage(first, "Background.png"); + + const int height = MagickGetImageHeight(first); + const int width = MagickGetImageWidth(first); + + printf("%d %d \n", height, width); + + + // Count how many images there are in the input file + + char fname[256]; + FILE *count = fopen( argv[1], "r"); + if(count != NULL) { + while((fgets(fname, sizeof(fname), count)) != NULL) { + nImages++; + } + fclose(count); + } + + printf("%d \n", nImages); + //this will store the number of pixels in each row + unsigned long number_wands; + + char filename[256]; + char *temp; + FILE *file = fopen ( argv[1], "r" ); + + + // initialize this crazy array. + + long int array[nImages][height][width][3]; + //long int array[nImages][height][width][3]; + + printf("%d", nImages); + if ( file != NULL ) { + while ((fgets(filename, sizeof(filename), file)) != NULL ) { + temp = strchr(filename, '\n'); + if (temp != NULL) *temp = '\0'; + char *filename_r = malloc(256); + strncpy(filename_r, filename, sizeof(filename)); + magick_wand = NewMagickWand(); + MagickReadImage(magick_wand, filename); + + + PixelIterator* iterator = NewPixelIterator(magick_wand); + + PixelWand **pixels = PixelGetNextIteratorRow(iterator,&number_wands); + + for (i=0; pixels != (PixelWand **) NULL; i++) { + for (j=0; j