Initial apple generator.

This commit is contained in:
imi415 2022-08-30 00:00:48 +08:00
commit 1c01bbaa69
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
4 changed files with 88 additions and 0 deletions

7
Gemfile Normal file
View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
source "https://rubygems.org"
# gem "rails"
gem 'rmagick', '~>4'

13
Gemfile.lock Normal file
View File

@ -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

34
apple_ssd1327.rb Normal file
View File

@ -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

34
apple_st75256.rb Normal file
View File

@ -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