class SerialPortMTP::Bitmap
Bitmaps
Attributes
height[R]
width[R]
Public Class Methods
new(width_or_source, height=nil, source=nil)
click to toggle source
# File lib/serialport_mtp.rb, line 237 def initialize(width_or_source, height=nil, source=nil) if height.nil? && source.nil? set_source(width_or_source) extract_width_and_height_from_data else set_source(source) @width = width_or_source @height = height end end
Public Instance Methods
each_block() { |width_in_bytes, chunk_height, bytes| ... }
click to toggle source
# File lib/serialport_mtp.rb, line 248 def each_block row_start = 0 width_in_bytes = width / 8 while row_start < height do chunk_height = ((height - row_start) > 255) ? 255 : (height - row_start) bytes = (0...(width_in_bytes * chunk_height)).map { @data.getbyte } yield width_in_bytes, chunk_height, bytes row_start += 255 end end
Private Instance Methods
extract_width_and_height_from_data()
click to toggle source
# File lib/serialport_mtp.rb, line 269 def extract_width_and_height_from_data tmp = @data.getbyte @width = (@data.getbyte << 8) + tmp tmp = @data.getbyte @height = (@data.getbyte << 8) + tmp end
set_source(source)
click to toggle source
# File lib/serialport_mtp.rb, line 261 def set_source(source) if source.respond_to?(:getbyte) @data = source else @data = StringIO.new(source.map(&:chr).join) end end