Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions src/tagstudio/qt/previews/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,25 +780,17 @@ def _blender(filepath: Path) -> Image.Image | None:
)
im: Image.Image | None = None
try:
blend_image = blend_thumb(str(filepath))

bg = Image.new("RGB", blend_image.size, color=bg_color)
bg.paste(blend_image, mask=blend_image.getchannel(3))
im = bg

except (
AttributeError,
UnidentifiedImageError,
TypeError,
) as e:
if str(e) == "expected string or buffer":
if (blend_image := blend_thumb(str(filepath))) is not None:
bg = Image.new("RGB", blend_image.size, color=bg_color)
bg.paste(blend_image, mask=blend_image.getchannel(3))
im = bg
else:
logger.info(
f"[ThumbRenderer][BLENDER][INFO] {filepath.name} "
f"Doesn't have an embedded thumbnail. ({type(e).__name__})"
"Doesn't have an embedded thumbnail."
)

else:
logger.error("Couldn't render thumbnail", filepath=filepath, error=type(e).__name__)
except Exception as e:
logger.error("Couldn't render thumbnail", filepath=filepath, error=type(e).__name__)
return im

@staticmethod
Expand Down
6 changes: 4 additions & 2 deletions src/tagstudio/qt/previews/vendored/blender_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from PIL import Image, ImageOps


def blend_extract_thumb(path):
def blend_extract_thumb(path) -> tuple[bytes | None, int, int]:
rend = b"REND"
test = b"TEST"

Expand Down Expand Up @@ -97,8 +97,10 @@ def blend_extract_thumb(path):
return image_buffer, x, y


def blend_thumb(file_in):
def blend_thumb(file_in) -> Image.Image | None:
buf, width, height = blend_extract_thumb(file_in)
if buf is None:
return None
image = Image.frombuffer(
"RGBA",
(width, height),
Expand Down
2 changes: 1 addition & 1 deletion src/tagstudio/qt/thumb_grid_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def hasHeightForWidth(self) -> bool:
@override
def itemAt(self, index: int) -> QLayoutItem:
if index >= len(self._items):
return None
return None # pyright: ignore[reportReturnType]
return self._items[index]

@override
Expand Down