bitplane only color mapping works, let's make some bitplanes/copperlists

This commit is contained in:
John Bintz 2024-06-04 12:44:12 -04:00
parent 9ea3e5f8a6
commit 6febe83740
1 changed files with 67 additions and 1 deletions

View File

@ -28,10 +28,17 @@ class Color
@blue = blue @blue = blue
end end
WHITE = new(red: 15, green: 15, blue: 15)
BLACK = new(red: 0, green: 0, blue: 0)
def ==(other) def ==(other)
red == other.red && green == other.green && blue == other.blue red == other.red && green == other.green && blue == other.blue
end end
def -(other)
red - other.red + green - other.green + blue - other.blue
end
alias eql? == alias eql? ==
def hash def hash
@ -87,4 +94,63 @@ image.each_pixel do |px, x, y|
rows[y].add(pixel:, x:) rows[y].add(pixel:, x:)
end end
pp rows[50].colors_with_usage prioritized_colors = rows[50].colors_with_usage.to_a.sort { |a, b| b.last <=> a.last }
presets_by_pixel_color = [
nil, Color::BLACK, Color::WHITE
]
unavailable_bitplane_colors = {
0 => true,
1 => true,
2 => true
}
MAX_BITPLANE_COLORS = 8
bitplane_colors = [
nil,
Color::BLACK,
Color::WHITE
]
color_to_pixel_map = {}
# take 5 + BLACK + WHITE colors into bitplane_colors
prioritized_colors.map(&:first).each do |color|
maybe_preset_index = presets_by_pixel_color.find_index { |c| c && color == c }
if !maybe_preset_index.nil?
bitplane_colors[maybe_preset_index] = color
color_to_pixel_map[color] = maybe_preset_index
unavailable_bitplane_colors[maybe_preset_index] = true
elsif bitplane_colors.count < MAX_BITPLANE_COLORS
next_available_bitplane_color = 8.times.find { |i| !unavailable_bitplane_colors[i] }
bitplane_colors[next_available_bitplane_color] = color
color_to_pixel_map[color] = next_available_bitplane_color
unavailable_bitplane_colors[next_available_bitplane_color] = true
else
closest_match = bitplane_colors.each_with_index.map do |bp_color, index|
next unless bp_color
[(bp_color - color).abs, index]
end.compact.min_by(&:first)
pp color
pp closest_match
pp bitplane_colors[closest_match.last]
puts '************************'
color_to_pixel_map[color] = closest_match.last
end
end
pp prioritized_colors
pp bitplane_colors
pp color_to_pixel_map
# .to_a.sort(&:last).reverse