Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,14 +1,7 @@
let output_ppm ~oc ~img:(_, r_channel, g_channel, b_channel) =
let width = Bigarray.Array2.dim1 r_channel
and height = Bigarray.Array2.dim2 r_channel in
Printf.fprintf oc "P6\n%d %d\n255\n" width height;
for y = 0 to pred height do
for x = 0 to pred width do
output_char oc (char_of_int r_channel.{x,y});
output_char oc (char_of_int g_channel.{x,y});
output_char oc (char_of_int b_channel.{x,y});
done;
done;
output_char oc '\n';
flush oc;
;;
proc writePPM(img: Image, f: TFile) =
f.writeln "P6\n", img.w, " ", img.h, "\n255"
for x,y in img.indices:
f.write char(img[x,y].r)
f.write char(img[x,y].g)
f.write char(img[x,y].b)

View file

@ -0,0 +1,14 @@
let output_ppm ~oc ~img:(_, r_channel, g_channel, b_channel) =
let width = Bigarray.Array2.dim1 r_channel
and height = Bigarray.Array2.dim2 r_channel in
Printf.fprintf oc "P6\n%d %d\n255\n" width height;
for y = 0 to pred height do
for x = 0 to pred width do
output_char oc (char_of_int r_channel.{x,y});
output_char oc (char_of_int g_channel.{x,y});
output_char oc (char_of_int b_channel.{x,y});
done;
done;
output_char oc '\n';
flush oc;
;;

View file

@ -1,13 +1,12 @@
sub MAIN ($filename = 'default.ppm') {
my $width = my $height = 125;
# Since P6 is a binary format, open in binary mode
my $out = open( $filename, :w, :bin ) or die "$!\n";
$out.say("P6\n$width $height\n255");
for ^$height X ^$width -> $r, $g {
$out.write(Buf.new($r*2,$g*2,255-$r*2));
role PPM {
method P6 returns Blob {
"P6\n{self.width} {self.height}\n255\n".encode('ascii')
~ Blob.new: flat map { .R, .G, .B }, self.data
}
$out.close;
}
my Bitmap $b = Bitmap.new( width => 125, height => 125) but PPM;
for ^$b.height X ^$b.width -> $i, $j {
$b.pixel($i, $j) = Pixel.new: :R($i*2), :G($j*2), :B(255-$i*2);
}
$*OUT.write: $b.P6;

View file

@ -0,0 +1,3 @@
function write {
_.to_s > "$1"
}

View file

@ -0,0 +1,3 @@
Bitmap_t b
# do stuff to b, and save it:
b.write '$HOME/tmp/bitmap.ppm'