Anonymous user
Bitmap/Read an image through a pipe: Difference between revisions
Bitmap/Read an image through a pipe (view source)
Revision as of 20:11, 21 October 2020
, 3 years ago→{{header|Ruby}}
(→{{header|Lua}}: added Lua solution) |
|||
Line 422:
=={{header|Ruby}}==
Uses [[Raster graphics operations/Ruby]].
<lang ruby>
require_relative 'raster_graphics'
class Pixmap
def self.read_ppm(ios)
format = ios.gets.chomp
width, height = ios.gets.chomp.split.map
max_colour = ios.gets.chomp
if
ios.close
raise StandardError, "file '#{filename}' does not start with the expected header"
Line 439 ⟶ 442:
ios.binmode if PIXMAP_BINARY_FORMATS.include?(format)
bitmap =
height.times do |y|
width.times do |x|
# read 3 bytes
red, green, blue = case format
when 'P3' then ios.gets.chomp.split
when 'P6' then ios.read(3).unpack('C3')
end
bitmap[x, y] = RGBColour.new(red, green, blue)
end
end
Line 463 ⟶ 466:
end
bitmap = Pixmap.open_from_jpeg('
bitmap.save('foto.ppm')
</lang>
=={{header|Tcl}}==
|