There is an example in the manpage of libnm. Here are some lines of it: for (row = 0; row < inpam.height; row++) { pnm_readpamrow(&inpam, tuplerow); for (column = 0; column < inpam.width; column++) { for (sample = 0; sample < inpam.depth; column++) { grand_total += tuplerow[row][column][sample]; } } pnm_writepamrow(&outpam, tuplerow); } There are two errors. In the third 'for', there should be "sample++". And in the access to tuplerow, it should be: tuplerow[column][sample]
newer libpnm manual doesnt have an example