Anonymous user
Bitmap/Write a PPM file: Difference between revisions
m
→{{header|zkl}}: reformat
m (→{{header|zkl}}: reformat) |
|||
Line 1,607:
=={{header|zkl}}==
<lang zkl>// convert Windows BMP (bit map) image to PPM
bmp:=File.stdin.read(); // BMP to memory▼
// Read BMP file
▲bmp:=File.stdin.read().howza(0); // BMP to memory (byte bucket), treat as bytes
_assert_(bmp[0]==0x42,"Stdin not a BMP file");
width:=bmp.toLittleEndian(18,2,False); height:=bmp.toLittleEndian(22,2,False); // signed
println(width," x ",height);
bmp.del(0,14 + bmp.toLittleEndian(14,2)); // get rid of header
ppm:=Data(width*height*3 + 100); // sized byte bucket plus some header slop
ppm.write("P6\n#rosettacode BMP to PPM test\n%d %d\n255\n".fmt(width,height));
foreach y in ([height - 1 .. 0,-1]){ //
bmp[y*width*3,width*3].pump(
}
Line 1,622 ⟶ 1,626:
<pre>
$ zkl bbb < lena.bmp
512 x 512
$ ls -l foo.ppm
-rw-r--r-- 1 craigd craigd 786476 Aug 30 01:31 foo.ppm
|