#include <stdlib.h>
#include <stdio.h>
#include "../basicColorImage.c"
#include "../basicImage.c"
void copyToPPM( image gimg, colorImage cimg )
{
int r, c, gray;
pixel pix;
for ( r=0; r<cimg.nrows; r++ )
for ( c=0; c<cimg.ncols; c++ )
{
gray = getPixel( gimg, r, c );
pix.red = gray;
pix.grn = gray;
pix.blu = gray;
setColorPixel ( cimg, r, c, pix );
}
}
int main ( int argc, char* argv[] )
{
colorImage cimg;
image gimg;
if ( argc != 3 )
{
printf("PGMtoPPM oldImage.pgm newImage.pgm\n");
exit( EXIT_FAILURE );
}
/* read in the old image */
readPGMimage( &gimg, argv[1] );
/* create empty color image */
newColorImage( &cimg, gimg.nrows, gimg.ncols );
/* fill color image */
copyToPPM( gimg, cimg ) ;
/* write the image to disk and free memory */
writePPMimage( cimg, argv[2]);
freeColorImage( &cimg );
freeImage( &gimg );
}
Comments: