refactor: cleanup vendored blender file

This commit is contained in:
Travis Abendshien
2026-07-26 10:35:10 -07:00
parent e2c9d30ed3
commit e050fc0db7
2 changed files with 8 additions and 10 deletions
+1 -3
View File
@@ -9,9 +9,7 @@ from PIL import Image
from PySide6.QtCore import Qt
from PySide6.QtGui import QGuiApplication
from tagstudio.renderers.vendored.blender_renderer import (
blend_thumb, # pyright: ignore[reportUnknownVariableType]
)
from tagstudio.renderers.vendored.blender_thumbnailer import blend_thumb
logger = structlog.get_logger(__name__)
@@ -1,29 +1,29 @@
# SPDX-FileCopyrightText: (c) 2017 The Blender Foundation
# SPDX-FileCopyrightText: (c) 2017 Blender Foundation
# SPDX-FileCopyrightText: (c) TagStudio Contributors
# SPDX-License-Identifier: GPL-3.0-only
## This file is a modified script that gets the thumbnail data stored in a blend file
"""Extract an embedded thumbnail from a Blender file."""
import gzip
import os
import struct
from io import BufferedReader
from pathlib import Path
from PIL import Image, ImageOps
def blend_extract_thumb(path) -> tuple[bytes | None, int, int]:
def blend_extract_thumb(path: Path | str) -> tuple[bytes | None, int, int]:
rend = b"REND"
test = b"TEST"
blendfile: BufferedReader | gzip.GzipFile = open(path, "rb") # noqa: SIM115
blendfile: BufferedReader | gzip.GzipFile = open(path, "rb")
head = blendfile.read(12)
if head[0:2] == b"\x1f\x8b": # gzip magic
blendfile.close()
blendfile = gzip.GzipFile("", "rb", 0, open(path, "rb")) # noqa: SIM115
blendfile = gzip.GzipFile("", "rb", 0, open(path, "rb"))
head = blendfile.read(12)
if not head.startswith(b"BLENDER"):
@@ -78,7 +78,7 @@ def blend_extract_thumb(path) -> tuple[bytes | None, int, int]:
return image_buffer, x, y
def blend_thumb(file_in) -> Image.Image | None:
def blend_thumb(file_in: Path | str) -> Image.Image | None:
buf, width, height = blend_extract_thumb(file_in)
if buf is None:
return None