# include # include # include # include "ppc_array.h" # include "ppc_image.h" # include "ppc_netpbm_io.h" int main ( int arc, char **argv ); void copy_test ( char **argv, char *original_file, char *copy_file ); void ppm_to_pgm_test ( char **argv, char *ppm_file, char *pgm_file ); void timestamp ( ); /******************************************************************************/ int main ( int arc, char **argv ) /******************************************************************************/ /* Purpose: ppc_netpbm_io_test() tests ppc_netpbm_io(). Licensing: This code is distributed under the MIT license. Modified: 15 September 2023 Author: Original C version by Rouben Rostamian. This version by John Burkardt. */ { char *ppm_file = "mario.ppm"; char *copy_file = "mario_copy.ppm"; char *pgm_file = "mario.pgm"; timestamp ( ); printf ( "\n" ); printf ( "ppc_netpbm_io_test():\n" ); printf ( " C version\n" ); printf ( " Test ppc_netpbm_io().\n" ); copy_test ( argv, ppm_file, copy_file ); ppm_to_pgm_test ( argv, ppm_file, pgm_file ); /* Terminate. */ printf ( "\n" ); printf ( "ppc_netpbm_io_test():\n" ); printf ( " Normal end of execution.\n" ); timestamp ( ); return EXIT_SUCCESS; } /******************************************************************************/ void copy_test ( char **argv, char *original_file, char *copy_file ) /******************************************************************************/ /* Purpose: copy_test() makes a copy of an image file. Licensing: This code is distributed under the MIT license. Modified: 15 September 2023 Author: Original C version by Rouben Rostamian. This version by John Burkardt. */ { printf ( "\n" ); printf ( "copy_test():\n" ); printf ( " Copy an image file.\n" ); pm_init ( argv[0], 0 ); struct image *img = read_image ( original_file ); printf ( "\n" ); printf ( " Image contained in file '%s'\n", original_file ); printf ( " Image is %d x %d x %d\n", img->pam.height, img->pam.width, img->pam.depth ); printf ( " Maxval = %ld\n", img->pam.maxval ); write_image ( copy_file, img ); printf ( "\n" ); printf ( " Copy created as '%s'\n", copy_file ); free_image ( img ); return; } /******************************************************************************/ void ppm_to_pgm_test ( char **argv, char *ppm_file, char *pgm_file ) /******************************************************************************/ /* Purpose: ppm_to_pgm_test() makes a PGM copy of a PPM image. Licensing: This code is distributed under the MIT license. Modified: 15 September 2023 Author: Original C version by Rouben Rostamian. This version by John Burkardt. */ { int i; int j; printf ( "\n" ); printf ( "ppm_to_pgm_test():\n" ); printf ( " Read a ppm file.\n" ); printf ( " Make a gray version of the image.\n" ); printf ( " Write that to a pgm file.\n" ); printf ( "\n" ); printf ( "copy_test():\n" ); printf ( " Copy an image file.\n" ); pm_init ( argv[0], 0 ); struct image *img = read_image ( ppm_file ); printf ( "\n" ); printf ( " Image contained in file '%s'\n", ppm_file ); printf ( " Image is %d x %d x %d\n", img->pam.height, img->pam.width, img->pam.depth ); printf ( " Maxval = %ld\n", img->pam.maxval ); img->pam.format = RPGM_FORMAT; img->pam.depth = 1; for ( i = 0; i < img->pam.height; i++ ) { for ( j = 0; j < img->pam.width; j++ ) { img->g[i][j] = ( int ) ( ( 77.0 * img->r[i][j] + 150.0 * img->g[i][j] + 29.0 * img->b[i][j] ) / 256.0 ); } } write_image ( pgm_file, img ); printf ( "\n" ); printf ( " Gray scale copy created as '%s'\n", pgm_file ); free_image ( img ); return; } /******************************************************************************/ void pgm_test ( ) /******************************************************************************/ /* Purpose: pgm_test() ??? Licensing: This code is distributed under the MIT license. Modified: 15 September 2023 Author: Original C version by Rouben Rostamian. This version by John Burkardt. */ { printf ( "\n" ); printf ( "pgm_test():\n" ); printf ( " ???.\n" ); return; } /******************************************************************************/ void ppm_test ( ) /******************************************************************************/ /* Purpose: ppm_test() ??? Licensing: This code is distributed under the MIT license. Modified: 15 September 2023 Author: Original C version by Rouben Rostamian. This version by John Burkardt. */ { printf ( "\n" ); printf ( "ppm_test():\n" ); printf ( " ???.\n" ); return; } /******************************************************************************/ 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 }