Class: A2Printer::Bitmap
- Inherits:
-
Object
- Object
- A2Printer::Bitmap
- Defined in:
- lib/a2_printer.rb
Overview
Bitmaps
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #each_block ⇒ Object
-
#initialize(width_or_source, height = nil, source = nil) ⇒ Bitmap
constructor
A new instance of Bitmap.
Constructor Details
#initialize(width_or_source, height = nil, source = nil) ⇒ Bitmap
Returns a new instance of Bitmap.
204 205 206 207 208 209 210 211 212 213 |
# File 'lib/a2_printer.rb', line 204 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 |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
202 203 204 |
# File 'lib/a2_printer.rb', line 202 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
202 203 204 |
# File 'lib/a2_printer.rb', line 202 def width @width end |
Instance Method Details
#each_block ⇒ Object
215 216 217 218 219 220 221 222 223 224 |
# File 'lib/a2_printer.rb', line 215 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 |