Browse Source

Fix optimization colors handling

master
Dejvino 1 year ago
parent
commit
a5cc0634f6
1 changed files with 8 additions and 15 deletions
  1. +8
    -15
      test.py

+ 8
- 15
test.py View File

@@ -8,11 +8,11 @@ epd_resolution = [600, 448]
epd_colormap = [
[0x00, 0x00, 0x00], # black
[0xff, 0xff, 0xff], # white
[0x00, 0xdd, 0x00], # green
[0x00, 0x90, 0x10], # green
[0x00, 0x00, 0xee], # blue
[0x00, 0xdd, 0x00], # red
[0xff, 0x00, 0x00], # red
[0xff, 0xdd, 0x00], # yellow
[0xff, 0x88, 0x00], # orange
[0xff, 0x77, 0x00], # orange
]

images = ["lambo.bmp", "fallout.bmp", "nasa.bmp"]
@@ -32,17 +32,17 @@ def draw_image(filename):
offset_y = 0
color_map = {}
def header_callback(header):
print("header callback: ", str(header))
#print("header callback: ", str(header))
global epd_resolution
global offset_x, offset_y
w = header[0]
h = header[1]
offset_x = (epd_resolution[0] - w)//2
offset_y = (epd_resolution[1] - h)//2
print("offset: ", offset_x, offset_y)
def pixel_callback(x, y, color):
global epd
global epd_colormap
global offset_x, offset_y
# translate color to color index
color_index = 0
color_key = color[0] + color[1] << 8 + color[2] << 16
@@ -59,18 +59,11 @@ def draw_image(filename):
if score < best_score:
best_score = score
best_index = index
if score < 20:
if score < 10:
break
color_index = best_index
color_map[color_key] = color_index
# hack directly into the 4-bit color buffer instead of:
# epd.pixel(offset_x + x, offset_y + y, color_to_index(color))
buffer_pos = (offset_x + x + (offset_y + y) * epd_resolution[0])
buffer_index = buffer_pos // 2
if buffer_pos % 2 == 1:
buffer_pos = buffer_pos << 4
epd.buffer[buffer_index] = color_index
epd.pixel(offset_x + x, offset_y + y, color_index)
def pixel_row_callback(x, y, colors):
pass
#global epd


Loading…
Cancel
Save