// magnify PPM image // #include #include #include "ppm.h" #define MAG 100 // default magnification factor void scale( unsigned char **b, unsigned char **a, int brows, int bcols, int mag) { for( int i = 0; i < brows; ++i) for( int j = 0; j < bcols; ++j) b[i][j] = a[i/mag][j/mag]; } ppm magnify( ppm a, int mag) { ppm b = ppm_new( a.rows*mag, a.cols*mag); scale( b.r, a.r, b.rows, b.cols, mag); scale( b.g, a.g, b.rows, b.cols, mag); scale( b.b, a.b, b.rows, b.cols, mag); return b; } int main( int argc, char *argv[]) { int mag = MAG; if( argc > 1) { int t = atoi( argv[1]); if( t > 0) mag = t; } ppm a = ppm_read(); ppm b = magnify( a, mag); ppm_write( b); return 0; }