Skip to content

Commit

Permalink
lv_img_conf: improvements from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
NeroBurner committed Oct 26, 2023
1 parent 3620f73 commit ad56ee9
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/resources/lv_img_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ def main():
for x in range(img_width):
i = (y*img_width + x)*4 # buffer-index
pixel = img.getpixel((x,y))
r = pixel[0]
g = pixel[1]
b = pixel[2]
a = pixel[3]
r, g, b, a = pixel
buf[i + 0] = r
buf[i + 1] = g
buf[i + 2] = b
Expand All @@ -126,12 +123,9 @@ def main():
g_act = classify_pixel(pixel[1], 6)
b_act = classify_pixel(pixel[2], 5)
a = pixel[3]
if r_act > 0xF8:
r_act = 0xF8
if g_act > 0xFC:
g_act = 0xFC
if b_act > 0xF8:
b_act = 0xF8
r_act = min(r_act, 0xF8)
g_act = min(g_act, 0xFC)
b_act = min(b_act, 0xF8)
c16 = ((r_act) << 8) | ((g_act) << 3) | ((b_act) >> 3) # RGR565
buf[i + 0] = (c16 >> 8) & 0xFF
buf[i + 1] = c16 & 0xFF
Expand All @@ -148,17 +142,15 @@ def main():
for x in range(img_width):
c, a = img.getpixel((x,y))
p = w * y + (x >> 3) + 8 # +8 for the palette
#if(!isset(this.d_out[p])) this.d_out[p] = 0 # Clear the bits first
buf[p] |= (c & 0x1) << (7 - (x & 0x7))
# write palette information
palette_size = 2
bits_per_value = 1
# write palette information, for indexed-1-bit we need palette with two values
# write 8 palette bytes
buf[0] = 0
buf[1] = 0
buf[2] = 0
buf[3] = 0
# Normally there is much math behind this, but for the current use case this is close enough
# only needs to be more complicated if we have more than 2 colors in the palette
buf[4] = 255
buf[5] = 255
buf[6] = 255
Expand Down

0 comments on commit ad56ee9

Please sign in to comment.