int METHOD(entry, main)(void *_this, int argc, char* argv[]) { #ifdef BLUR_DEBUG printf ("DEBUG : entry method from component Dispatcher\n"); #endif int result; int block_size; int maxrgb; int nb_block; char *filein_name; char *fileout_name; array = NULL; filein_name = "in.ppm"; fileout_name = "out.ppm"; block_size = 512; #ifdef BLUR_DEBUG printf ("DEBUG : reading data for file %s\n", filein_name); #endif /* Read the data. */ result = ppmb_read (filein_name, &xsize, &ysize, &maxrgb, &array); nb_block = (block_size + xsize - 1) / block_size; nb_block = nb_block * nb_block; if ( result != 0 ) printf ("ERROR : ppmb_read error!\n" ); #ifdef BLUR_DEBUG else { printf ("DEBUG : Info for image %s :\n", filein_name); printf ("\twidth :%d\n", xsize); printf ("\theight :%d\n", ysize); printf ("\tmax color :%d\n", maxrgb); printf ("\tblock_size : %d\n", block_size); printf ("\tnb_block : %d\n", nb_block); } #endif CALL(REQUIRED.infos, set_info, fileout_name, xsize, ysize, maxrgb, array); #ifdef BLUR_DEBUG printf ("DEBUG : Dispatch and apply blur to data\n"); #endif CALL (REQUIRED.work, blur, array, ysize, 0, 0, xsize, ysize); if ( result != 0 ) printf ("ERROR : dispatch_blur error!\n" ); }
int main(int argc, char *argv[]) { if(argc != 4) { printf("Usage: %s input-file histogram output-file\n", argv[0]); exit(1); } struct img input, output; if(!ppmb_read(argv[1], &input.xsize, &input.ysize, &input.maxrgb, &input.r, &input.g, &input.b)) { if(input.maxrgb > 255) { printf("Maxrgb %d not supported\n", input.maxrgb); exit(1); } int *hist_r, *hist_g, *hist_b; int *xlat_r, *xlat_g, *xlat_b; int N; FILE *hist; hist = fopen(argv[2], "r"); if(!hist) { fprintf(stderr, "Unable to read histogram file '%s'\n", argv[2]); exit(1); } read_histogram(hist, &hist_r, &N); if(N != input.maxrgb+1) { fprintf(stderr, "maxrgb != red histogram length\n"); exit(1); } read_histogram(hist, &hist_g, &N); if(N != input.maxrgb+1) { fprintf(stderr, "maxrgb != green histogram length\n"); exit(1); } read_histogram(hist, &hist_b, &N); if(N != input.maxrgb+1) { fprintf(stderr, "maxrgb != blue histogram length\n"); exit(1); } gen_xlat(input.xsize * input.ysize, N, hist_r, &xlat_r); gen_xlat(input.xsize * input.ysize, N, hist_g, &xlat_g); gen_xlat(input.xsize * input.ysize, N, hist_b, &xlat_b); ggc::Timer t("equalize"); t.start(); equalize(&input, &output, xlat_r, xlat_g, xlat_b); t.stop(); if(ppmb_write(argv[3], output.xsize, output.ysize, output.r, output.g, output.b)) { fprintf(stderr, "Unable to write output\n"); exit(1); } printf("Time: %llu ns\n", t.duration()); } }
int main(int argc, char *argv[]) { if(argc != 2) { printf("Usage: %s input-file\n", argv[0]); exit(1); } struct img input; if(!ppmb_read(argv[1], &input.xsize, &input.ysize, &input.maxrgb, &input.r, &input.g, &input.b)) { if(input.maxrgb > 255) { printf("Maxrgb %d not supported\n", input.maxrgb); exit(1); } int *hist_r, *hist_g, *hist_b; hist_r = (int *) calloc(input.maxrgb+1, sizeof(int)); hist_g = (int *) calloc(input.maxrgb+1, sizeof(int)); hist_b = (int *) calloc(input.maxrgb+1, sizeof(int)); ggc::Timer t("histogram"); t.start(); histogram(&input, hist_r, hist_g, hist_b); t.stop(); char *output = get_output_file(argv[1]); FILE *out = fopen(output, "w"); if(out) { print_histogram(out, hist_r, input.maxrgb); print_histogram(out, hist_g, input.maxrgb); print_histogram(out, hist_b, input.maxrgb); fclose(out); } else { fprintf(stderr, "Unable to output!\n"); } printf("Time: %llu ns\n", t.duration()); } }
bool ppmb_read_test ( char *file_name ) /******************************************************************************/ /* Purpose: PPMB_READ_TEST tests the binary portable pixel map read routines. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 June 2012 Author: John Burkardt Parameters: Input, char *FILE_NAME, the name of the file containing the binary portable pixel map data. Output, bool PPMB_READ_TEST, equals true, if the test could not be carried out, false, if the test was carried out. */ { unsigned char *barray; unsigned char *garray; int maxrgb; unsigned char *rarray; bool result; int xsize; int ysize; rarray = NULL; garray = NULL; barray = NULL; /* Read the data. */ result = ppmb_read ( file_name, &xsize, &ysize, &maxrgb, &rarray, &garray, &barray ); if ( result ) { printf ( "\n" ); printf ( "PPMB_READ_TEST: Fatal error!\n" ); printf ( " PPMB_READ failed.\n" ); if ( rarray != NULL ) { free ( rarray ); } if ( garray != NULL ) { free ( garray ); } if ( barray != NULL ) { free ( barray ); } return true; } /* Check the data. */ result = ppmb_check_data ( xsize, ysize, maxrgb, rarray, garray, barray ); if ( rarray != NULL ) { free ( rarray ); } if ( garray != NULL ) { free ( garray ); } if ( barray != NULL ) { free ( barray ); } if ( result ) { printf ( "\n" ); printf ( " PPMB_CHECK_DATA reports bad data from the file.\n" ); return true; } printf ( "\n" ); printf ( " PPMB_CHECK_DATA passes the data from the file.\n" ); return false; }
int main (int argc, char* argv[]) { #ifdef BLUR_DEBUG printf ("DEBUG : entry method from component Dispatcher\n"); #endif int result; int block_size; int maxrgb; int nb_block; int numbytes; char *filein_name; char *fileout_name; #ifdef BLUR_TIMING double t0, t1, t2; /* Timing : */ t0 = get_elapsedtime(); #endif array = NULL; if (argc > 1) filein_name= argv[1]; else filein_name = "/home/claferri/img/Lena.512.ppm"; if (argc > 2) fileout_name = argv[2]; else fileout_name = "img.ppm"; if (argc > 3) block_size = atoi (argv[3]); else block_size = 128; #ifdef BLUR_DEBUG printf ("DEBUG : reading data for file %s\n", filein_name); #endif printf ("# Blur Sequentiel : %s -> %s :: %d\n", filein_name, fileout_name, block_size); /* Read the data. */ result = ppmb_read (filein_name, &xsize, &ysize, &maxrgb, &array); numbytes = 3 * ( xsize ) * ( ysize ) * sizeof ( int ); out = ( int * ) malloc ( numbytes ); nb_block = (block_size + (xsize - (2*NB_NEIGHBOURS)) - 1) / block_size; nb_block = nb_block * nb_block; if ( result != 0 ) printf ("ERROR : ppmb_read error!\n" ); #ifdef BLUR_DEBUG else { printf ("DEBUG : Info for image %s :\n", filein_name); printf ("\twidth :%d\n", xsize); printf ("\theight :%d\n", ysize); printf ("\tmax color :%d\n", maxrgb); printf ("\tblock_size : %d\n", block_size); printf ("\tnb_block : %d\n", nb_block); } #endif set_info (fileout_name, xsize, ysize, maxrgb, out, nb_block); #ifdef BLUR_DEBUG printf ("DEBUG : Dispatch and apply blur to data\n"); #endif #ifdef BLUR_TIMING /* Timing : */ t1 = get_elapsedtime(); printf("fopen %f\n", t1-t0); #endif result = dispatch_blur (block_size); if ( result != 0 ) printf ("ERROR : dispatch_blur error!\n" ); #ifdef BLUR_TIMING /* Timing : */ t2 = get_elapsedtime(); printf("total %f\n", t2-t0); #endif }