Spaces:
Running
Running
perf: PNG compress_level 6 instead of optimize/9 (faster pack, ~same size on black-bg pieces)
Browse files- src/optimizer.py +4 -1
src/optimizer.py
CHANGED
|
@@ -24,7 +24,10 @@ def encode_piece(rgb: np.ndarray, lossy: bool = False, colors: int = 64) -> byte
|
|
| 24 |
# Median-cut palette; black background collapses to one palette entry.
|
| 25 |
img = img.quantize(colors=max(2, min(256, colors)), method=Image.MEDIANCUT)
|
| 26 |
buf = io.BytesIO()
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
return buf.getvalue()
|
| 29 |
|
| 30 |
|
|
|
|
| 24 |
# Median-cut palette; black background collapses to one palette entry.
|
| 25 |
img = img.quantize(colors=max(2, min(256, colors)), method=Image.MEDIANCUT)
|
| 26 |
buf = io.BytesIO()
|
| 27 |
+
# compress_level=6 (zlib default) instead of optimize=True/level 9: the latter
|
| 28 |
+
# is far slower per piece for ~no size gain on mostly-black fragments, which
|
| 29 |
+
# dominates pack time when there are hundreds of pieces.
|
| 30 |
+
img.save(buf, format="PNG", compress_level=6)
|
| 31 |
return buf.getvalue()
|
| 32 |
|
| 33 |
|