September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env perl6
|
||||
|
||||
# Reference:
|
||||
# https://rosettacode.org/wiki/Bitmap/Write_a_PPM_file#Perl_6
|
||||
|
||||
use v6;
|
||||
|
||||
class Pixel { has uint8 ($.R, $.G, $.B) }
|
||||
class Bitmap {
|
||||
has UInt ($.width, $.height);
|
||||
has Pixel @!data;
|
||||
|
||||
method fill(Pixel $p) {
|
||||
@!data = $p.clone xx ($!width*$!height)
|
||||
}
|
||||
method pixel(
|
||||
$i where ^$!width,
|
||||
$j where ^$!height
|
||||
--> Pixel
|
||||
) is rw { @!data[$i*$!height + $j] }
|
||||
|
||||
method data { @!data }
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
my Bitmap $b = Bitmap.new(width => 125, height => 125) but PPM;
|
||||
for flat ^$b.height X ^$b.width -> $i, $j {
|
||||
$b.pixel($i, $j) = Pixel.new: :R($i*2), :G($j*2), :B(255-$i*2);
|
||||
}
|
||||
|
||||
my $proc = run '/usr/bin/convert','-','output_piped.jpg', :in;
|
||||
$proc.in.write: $b.P6;
|
||||
$proc.in.close;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
"""
|
||||
Adapted from https://stackoverflow.com/questions/26937143/ppm-to-jpeg-jpg-conversion-for-python-3-4-1
|
||||
Requires pillow-5.3.0 with Python 3.7.1 32-bit on Windows.
|
||||
Sample ppm graphics files from http://www.cs.cornell.edu/courses/cs664/2003fa/images/
|
||||
"""
|
||||
|
||||
from PIL import Image
|
||||
|
||||
im = Image.open("boxes_1.ppm")
|
||||
im.save("boxes_1.jpg")
|
||||
Loading…
Add table
Add a link
Reference in a new issue