attempt to speed up generate()
@@ -74,21 +74,19 @@ def generate(source_bytes, max_dim, detailed):
for row in source:
x = 0
for pix in row: # bgr
- pal_key = palette_oct.get((int(pix[2]/32), int(pix[1]/32), int(pix[0]/32)))
+ r = pix[2]
+ g = pix[1]
+ b = pix[0]
- if pal_key is not None:
- continue
- else:
- pal_key = palette_quad.get((int(pix[2]/64), int(pix[1]/64), int(pix[0]/64)))
+ pal_key = palette_oct.get((int(r/32), int(g/32), int(b/32)))
- if pal_key is not None:
- continue
- else:
- pal_key = palette_bi.get((int(pix[2]/128), int(pix[1]/128), int(pix[0]/128)))
+ if pal_key is None:
+ pal_key = palette_quad.get((int(r/64), int(g/64), int(b/64)))
- if pal_key is not None:
- continue
- else:
+ if pal_key is None:
+ pal_key = palette_bi.get((int(r/128), int(g128), int(b/128)))
+
+ if pal_key is None:
pal_key = palette_oct[random.choice([*palette_oct.keys()])]
draw_image(canvas, palette_map[pal_key], x, y)
