# include # include # include # include "ppc_array.h" # include "ppc_image.h" # include "ppc_image_analysis.h" # include "ppc_netpbm_io.h" # include "ppc_xmalloc.h" int main ( int argc, char **argv ); void timestamp ( ); /******************************************************************************/ int main ( int argc, char **argv ) /******************************************************************************/ /* Purpose: ppc_image_reduce() reduces a PGM or PPM image using Haar transforms and a relative error. Usage: ppc_image_reduce relerr infile outfile Licensing: This code is distributed under the MIT license. Modified: 06 May 2024 Author: John Burkardt Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 */ { char *endptr; char *infile; char *outfile; double relerr; timestamp ( ); printf ( "\n" ); printf ( "ppc_image_reduce():\n" ); printf ( " C version\n" ); printf ( " ppc_image_reduce relerr infile outfile\n" ); printf ( " applies a Haar transform with given relative error tolerance\n" ); printf ( " to reduce the size of a PGM or PPM image.\n" ); if ( argc != 4 ) { show_usage ( argv[0] ); return EXIT_FAILURE; } relerr = strtod ( argv[1], &endptr ); if ( *endptr != '\0' || relerr < 0.0 || 1.0 < relerr ) { fprintf ( stderr, " 0.0 <= relerr <= 1.0 is required!\n" ); return EXIT_FAILURE; } infile = argv[2]; outfile = argv[3]; pm_init ( argv[0], 0 ); struct image *img = read_image ( infile ); struct pam *pam = &img->pam; if ( pam->format == PGM_FORMAT || pam->format == RPGM_FORMAT ) { reduce_pgm_image ( img, relerr ); } else if ( pam->format == PPM_FORMAT || pam->format == RPPM_FORMAT ) { reduce_ppm_image ( img, relerr ); } else { fprintf ( stderr, " Input file seems to have wrong format.\n" ); return EXIT_FAILURE; } write_image ( outfile, img ); free_image ( img ); /* Terminate. */ printf ( "\n" ); printf ( "ppc_image_analysis_test():\n" ); printf ( " Normal end of execution.\n" ); timestamp ( ); return EXIT_SUCCESS; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 01 May 2021 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }