Initial apple generator.
This commit is contained in:
commit
1c01bbaa69
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
# gem "rails"
|
||||
|
||||
gem 'rmagick', '~>4'
|
|
@ -0,0 +1,13 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
rmagick (4.2.4)
|
||||
|
||||
PLATFORMS
|
||||
x86_64-linux
|
||||
|
||||
DEPENDENCIES
|
||||
rmagick (~> 4)
|
||||
|
||||
BUNDLED WITH
|
||||
2.3.3
|
|
@ -0,0 +1,34 @@
|
|||
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
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
require 'bundler'
|
||||
|
||||
Bundler::require
|
||||
|
||||
require 'rmagick'
|
||||
include Magick
|
||||
|
||||
IMAGE_DIR='video/256_128'
|
||||
OUTPUT_NAME='video/256_128/apple_st75256.bin'
|
||||
|
||||
COLOR_STEP=(Magick::QuantumRange + 1) / 4
|
||||
|
||||
def convert_image(filename)
|
||||
im = Image.read(filename)
|
||||
pix_ary = Array.new(8192, 0)
|
||||
im[0].each_pixel do |pix, col, row|
|
||||
color = pix.intensity / COLOR_STEP
|
||||
|
||||
byte_offset = 256 * (row / 4) + col
|
||||
bit_offset = (3 - (row % 4)) * 2
|
||||
|
||||
pix_ary[byte_offset] &= ~(3 << bit_offset)
|
||||
pix_ary[byte_offset] |= (color << bit_offset)
|
||||
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
|
||||
|
Loading…
Reference in New Issue