// 2D and image functions // #include "ppm.h" void row_zero( unsigned char z[], int n) { // zero out a 1D array for( int k = 0; k < n; ++k) z[k] = 0; } // int x[][] -- won't work, need to know the number of columns void zero( unsigned char **x, int rows, int cols ) { // zero out a 2D array // for( int i = 0; i < rows; ++i) for( int j = 0; j < cols; ++j) { // x[i][j] = 0; // } for( int i = 0; i < rows; ++i) row_zero( x[i], cols); } void gray( ppm a) { // change image to grayscale for( int i = 0; i < a.rows; ++i) for( int j = 0; j < a.cols; ++j) { // a.r[i][j] = 0; // remove red int avg = (a.r[i][j] + a.g[i][j] + a.b[i][j])/3; // if( avg < 50) avg = 0; else avg = 255; // black and white a.r[i][j] = a.g[i][j] = a.b[i][j] = avg; // grayscale } } int main( void) { ppm a = ppm_read(); // a.rows, a.cols, a.r, a.g, a.b // gray(a); zero( a.g, a.rows, a.cols); ppm_write( a); return 0; }