# include # include # include # include # include "ppc_array.h" int main ( int arc, char **argv ); void timestamp ( ); /******************************************************************************/ int main ( int arc, char **argv ) /******************************************************************************/ /* Purpose: ppc_netpbm() reads a PBM file and creates a new one. Licensing: This code is distributed under the MIT license. Modified: 13 September 2023 Author: John Burkardt */ { double **a; FILE *fp; int i; char *infile = "aya_matsuura.pgm"; int j; char *outfile = "zz.pgm"; struct pam pam; tuple *row; timestamp ( ); printf ( "\n" ); printf ( "ppc_netpbm():\n" ); printf ( " Demonstrate the use of the netpbm graphics library.\n" ); pm_init ( argv[0], 0 ); /* Read the image header. */ fp = pm_openr ( infile ); pnm_readpaminit ( fp, &pam, PAM_STRUCT_SIZE ( tuple_type ) ); printf ( "image: %dx%d, depth: %d\n", pam.width, pam.height, pam.depth ); if ( ! ( pam.format == PGM_FORMAT || pam.format == RPGM_FORMAT ) ) { fprintf ( stderr, "\n" ); fprintf ( stderr, "ppc_netpbm: Fatal error\n" ); fprintf ( stderr, " This progrma only handles images in PGM format.\n" ); return EXIT_FAILURE; } make_matrix ( a, pam.height, pam.width ); row = pnm_allocpamrow ( &pam ); for ( i = 0; i < pam.height; i++ ) { pnm_readpamrow ( &pam, row ); for ( j = 0; j < pam.width; j++ ) { a[i][j] = row[j][0]; } } pm_close ( fp ); for ( i = 0; i < pam.width && i < pam.height; i++ ) { a[i][i] = 0.0; } fp = pm_openw ( outfile ); pam.file = fp; if ( pam.format == PGM_FORMAT ) { pam.plainformat = 1; } else { pam.plainformat = 0; } pnm_writepaminit ( &pam ); for ( i = 0; i < pam.height; i++ ) { for ( j = 0; j < pam.width; j++ ) { row[j][0] = a[i][j]; } pnm_writepamrow ( &pam, row ); } pm_close ( fp ); printf ( "\n" ); printf ( " Graphics saved as '%s'\n", outfile ); free_matrix ( a ); pnm_freepamrow ( row ); /* Terminate. */ printf ( "\n" ); printf ( "ppc_netpbm():\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 }