Sha256: 490dc088cbe3476c6c3803b419e6a950cc9932ed1d73a292329ea385c0bf7d73
Contents?: true
Size: 870 Bytes
Versions: 22
Compression:
Stored size: 870 Bytes
Contents
module ZPNG class Block attr_accessor :width, :height, :pixels def initialize image, x, y, w, h @width, @height = w,h @pixels = [] h.times do |i| w.times do |j| @pixels << image[x+j,y+i] end end end def to_s a = [] height.times do |i| b = [] width.times do |j| b << pixels[i*width+j].to_s end a << b.join(" ") end a.join "\n" end def to_binary_string c_white = ' ', c_black = 'X' @pixels.each do |p| raise "pixel #{p.inspect} is not white nor black" if !p.white? && !p.black? end a = [] height.times do |i| b = [] width.times do |j| b << (pixels[i*width+j].black? ? c_black : c_white) end a << b.join(" ") end a.join "\n" end end end
Version data entries
22 entries across 22 versions & 1 rubygems