JoshKarpel/spiel

Consider using `rich-pixels` instead of custom `Image`

JoshKarpel opened this issue · 1 comments

rich-pixels covers the same ground (and more) as spiel.Image (which, incidentally, I actually forgot to re-export from spiel/__init__.py

from spiel.renderables.image import Image
).

We should probably drop Image and just use rich-pixels for images, potentially with a caching layer on top for our special case of needing to re-render slide contents so often.

Turns out there's a subtle but important difference: it looks like rich-pixels can resize when it loads an image, but it doesn't dynamically size the image to the available size like we do (by using __rich_console__

size = self._determine_size(options)
resized = self._resize(size)
pixels = tuple(resized.getdata())
yield from _pixels_to_segments(pixels, size)
)

I'm also not seeing the "two pixels per row" hack

# use upper-half-blocks for the top pixel row and the background color for the bottom pixel row
segments.append(
Segment(
text="▀",
style=Style.from_color(
color=Color.from_rgb(*top_pixel[:3]) if top_pixel else None,
bgcolor=Color.from_rgb(*bottom_pixel[:3]) if bottom_pixel else None,
),
)
)
in rich-pixels. So, I will stick with Image for now.