Module: BMP2SSD1306
- Defined in:
- lib/bmp2ssd1306.rb,
lib/bmp2ssd1306/version.rb
Constant Summary collapse
- VERSION =
'0.1.0'
Class Method Summary collapse
Class Method Details
.convert(path) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bmp2ssd1306.rb', line 6 def convert(path) buff = '' image = Magick::Image.read(path).first cols = image.columns rows = image.rows (0...rows).step(8) do |row| (0...cols).each do |col| byte = [] (0...8).each do |cur| pixel = image.pixel_color(col, row + cur) bit = pixel.red > 0 && pixel.green > 0 && pixel.blue > 0 ? 0 : 1 byte << bit end buff << [byte.join].pack('b*') end end buff end |