Bitmap/Bresenham's line algorithm: Difference between revisions

→‎{{header|zkl}}: rewrite readPPM
(→‎{{header|zkl}}: added readPPMFile)
(→‎{{header|zkl}}: rewrite readPPM)
Line 2,924:
}
fcn readPPMFile(fileName){
imagef:=File(f:=fileName,"rb").read; ppm:=readPPM(f); f.close();
image.readln(2);ppm
}
w,h:=image.readln().split().apply("toInt");
fcn readPPM(image){ // image is a PPM byte stream
 
// header is "P6\n[#comment\n]<w> <h>\nmaxPixelValue\n
image.del(0,image.find("\n255\n") + 5); // del PPM header
ppm:=PPMimage.readln(w,h); // "P6"
while("#"==(text:=image.readln().strip())[0]){}
w,h:=image.readln()text.split().apply("toInt");
image.readln(); // max pixel value
ppm,sz,buffer:=PPM(w,h), 3*w, Data(sz);
ppm.data.clear(); // gonna write file image data
// image is stored upside down in my data structure
[h-1..0, -1].pump(ppm.data,'wrapdo(h){ imageppm.data.seekinsert(3*h*w);0, image.read(3*wsz,buffer)) });
ppm
}
Anonymous user