September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
17
Task/Bitmap-Write-a-PPM-file/Zkl/bitmap-write-a-ppm-file.zkl
Normal file
17
Task/Bitmap-Write-a-PPM-file/Zkl/bitmap-write-a-ppm-file.zkl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// convert Windows BMP (bit map) image to PPM
|
||||
|
||||
// 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
|
||||
|
||||
// Write BMP to PPM image (in memory)
|
||||
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]){ // BGR 1 byte each, image is stored upside down
|
||||
bmp[y*width*3,width*3].pump(ppm,T(Void.Read,2),fcn(b,g,r){ return(r,g,b) });
|
||||
}
|
||||
|
||||
File("foo.ppm","wb").write(ppm); // File.stdout isn't binary, let GC close file
|
||||
Loading…
Add table
Add a link
Reference in a new issue