Apple_Generator/apple_ssd1327.rb

35 lines
861 B
Ruby

require 'bundler'
Bundler::require
require 'rmagick'
include Magick
IMAGE_DIR='video/128_128'
OUTPUT_NAME='video/128_128/apple.bin'
COLOR_STEP=(Magick::QuantumRange + 1) / 16
def convert_image(filename)
im = Image.read(filename)
pix_ary = Array.new(8192, 0)
im[0].each_pixel do |pix, col, row|
if col.even? then # Low nibble
pix_ary[row * 64 + col / 2] &= 0xF0
pix_ary[row * 64 + col / 2] |= pix.intensity / COLOR_STEP
else # High nibble
pix_ary[row * 64 + col / 2] &= 0x0F
pix_ary[row * 64 + col / 2] |= (pix.intensity / COLOR_STEP) << 4
end
end
pix_ary
end
File.open(OUTPUT_NAME, "w+") do |f|
Dir.glob("#{IMAGE_DIR}/*.bmp").each_with_index do |img, i|
puts "#{i} image processed."
f.write(convert_image(img).pack("C*"))
end
end