Bitmap/Read a PPM file: Difference between revisions

Added zkl
m (Repositioned PL/I code in alphabetical order.)
(Added zkl)
Line 1,488:
SetVid(3); \restore normal text display
]</lang>
 
=={{header|zkl}}==
{{trans|FBSL}}
Read a colored PPM file, convert it (in place) to grayscale and write the new image back to disk under a different name. Sanity checks are omitted.
 
I used a slightly different image from what is shown, but the results are the same.
[[File:FBSLGrayscalePPM.PNG|right]]
<lang zkl>//24-bpp P6 PPM solution:
image:=File("lena.ppm","rb").read();
start:=image.find("\n255\n")+5; // Get sizeof PPM header
foreach n in ([start..image.len()-1,3]){ // Transform color triplets
r,g,b:=image[n,3]; // Read colors stored in RGB order
l:=(0.2126*r + 0.7152*g + 0.0722*b).toInt(); // Derive luminance
image[n,3]=T(l,l,l);
}
 
File("lenaGrey.ppm","wb").write(image);</lang>
 
 
 
{{omit from|AWK}}
Anonymous user