Grayscale image: Difference between revisions

Content added Content deleted
(Updated D entry)
Line 1,487:
 
End Sub</lang>
 
=={{header|zkl}}==
Does an in-place conversion from a color PPM image to a gray scale PPM image (ie rgb is down sampled
but remains rgb vs one byte color). If you wish to write a bit map (or some other format), check out
[[Bitmap/PPM conversion through a pipe#zkl]]
 
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
{{trans|BASIC256}}
<lang zkl>fcn toGrayScale(img){ // in-place conversion
foreach x,y in (img.w,img.h){
r,g,b:=img[x,y].toBigEndian(3);
lum:=(0.2126*r + 0.7152*g + 0.0722*b).toInt();
img[x,y]=((lum*256) + lum)*256 + lum;
}
}</lang>
<lang zkl>img:=PPM.readPPMFile("lena.ppm");
toGrayScale(img);
img.write(File("foo.ppm","wb"));</lang>
 
{{omit from|AWK}}