20 lines
733 B
Plaintext
20 lines
733 B
Plaintext
class PPM{ // (0,0) is logically bottom left
|
|
fcn init(width,height){
|
|
sz:=width*height*3;
|
|
var [const]
|
|
data=sz.pump(Data(sz),0), // initialize to Black (RGB=000)
|
|
w=width, h=height;
|
|
}
|
|
fcn fill(rgb){
|
|
sz:=data.len()/3;
|
|
data.clear(); sz.pump(data,T(Void,rgb.toBigEndian(3)));
|
|
}
|
|
fcn __sGet(x,y) { data.toBigEndian(3*y*w + 3*x,3); } //ppm[x,y]
|
|
fcn __sSet(rbg,x,y){ data[3*y*w + 3*x,3]=rbg.toBigEndian(3); } //ppm[x,y]=rgb
|
|
fcn write(out){ // write bottom to top to move (0,0) from bottom left to bottom left
|
|
out.write("P6\n#rosettacode PPM\n%d %d\n255\n".fmt(w,h));
|
|
[h-1..0, -1].pump(out,'wrap(h){ data.seek(3*h*w); data.read(3*w) });
|
|
out.close();
|
|
}
|
|
}
|