Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)

Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.

    function setrgb {
        _.r=$1
        _.g=$2
        _.b=$3
    }
    function grayscale {
        integer x=$(( round( 0.2126*_.r + 0.7152*_.g + 0.0722*_.b ) ))
        _.r=$x
        _.g=$x
        _.b=$x
    }