Update blender_thumbnailer.py to read Blender 5.x files - #1481
Update blender_thumbnailer.py to read Blender 5.x files#1481050011-code wants to merge 5 commits into
Conversation
Updates blender_thumbnailer.py to read Blender 5.x files. Also refactor blender_thumbnailer.py to improve readability and maintainability. (Declaring this bit as AI made) Handle file operations more safely.
|
Thats on me for not remembering to fix the formating |
|
I'm sorry I was trying to make this pull request on my own fork! There are still errors as its current state was not meant to be for the original repo |
Refactor blender_thumbnailer.py to use type hints and improve readability.
Removed unnecessary logging statements to clean up code.
Updated image resizing method to use Image.Resampling.BICUBIC.
Thank you for your willingness to contribute and fix this issue. Before I start making review comments on this, I'd like to cite our
If you're not able to explain why you made specific changes in this (preferably with sources from Blender where applicable) then I'm afraid I won't review this as per our contributing policy. If you do know what you're doing with these changes and are open to me (heavily) scrutinizing the AI-assisted changes, then I'll go ahead with an in-depth review. I wouldn't pester you over exact undocumented byte ranges as long as they work, but every other change I'd want explanations for. Also, I just pulled this to actually give it a quick test, and it's not working with my Blender 5.x test file: |
| finally: | ||
| if blendfile is not None: | ||
| blendfile.close() | ||
|
|
||
| return image_buffer, x, y | ||
| if raw_file is not None and raw_file is not blendfile: | ||
| raw_file.close() |
There was a problem hiding this comment.
If all you're doing with the try finally block is to manage opening and closing files, you should instead use "with" context managers
| # -------------------------------------------------------------- | ||
| # Open file. | ||
| # -------------------------------------------------------------- |
There was a problem hiding this comment.
Unnecessary to add three lines of comments to a self-explaining line of code (this comment style is a pattern in this PR)
| # -------------------------------------------------------------- | |
| # Open file. | |
| # -------------------------------------------------------------- |
| # -------------------------------------------------------------- | ||
| # GZIP-compressed blend file. | ||
| # -------------------------------------------------------------- |
There was a problem hiding this comment.
Unnecessary to have fluff comments like these lines
| # -------------------------------------------------------------- | |
| # GZIP-compressed blend file. | |
| # -------------------------------------------------------------- | |
| # GZIP-compressed blend file. |
| # -------------------------------------------------------------- | ||
| # Walk the BHeads until we find TEST. | ||
| # -------------------------------------------------------------- |
There was a problem hiding this comment.
| # -------------------------------------------------------------- | |
| # Walk the BHeads until we find TEST. | |
| # -------------------------------------------------------------- | |
| # Walk the BHeads until we find TEST. |
| # ---------------------------------------------------------- | ||
| # REND contains render information before TEST. | ||
| # Skip its payload. | ||
| # ---------------------------------------------------------- |
There was a problem hiding this comment.
| # ---------------------------------------------------------- | |
| # REND contains render information before TEST. | |
| # Skip its payload. | |
| # ---------------------------------------------------------- | |
| # REND contains render information before TEST, skip its payload. |
| if code == rend: | ||
| blendfile.seek(length, os.SEEK_CUR) | ||
| # ---------------------------------------------------------- | ||
| # Blender 5+ BHead |
There was a problem hiding this comment.
Nit: Make version numbers consistent with one another
| # Blender 5+ BHead | |
| # Blender 5.0+ BHead |
| code: bytes = bhead[:4] | ||
|
|
||
| # ---------------------------------------------------------- | ||
| # Blender 5+ |
There was a problem hiding this comment.
| # Blender 5+ | |
| # Blender 5.0+ |
| length: int = struct.unpack_from( | ||
| "<Q", | ||
| bhead, | ||
| 16, | ||
| )[0] |
There was a problem hiding this comment.
This can be one line
| length: int = struct.unpack_from( | |
| "<Q", | |
| bhead, | |
| 16, | |
| )[0] | |
| length: int = struct.unpack_from("<Q", bhead, 16)[0] |
| length = struct.unpack_from( | ||
| int_endian + "i", | ||
| bhead, | ||
| 4, | ||
| )[0] |
There was a problem hiding this comment.
This can be one line
| length = struct.unpack_from( | |
| int_endian + "i", | |
| bhead, | |
| 4, | |
| )[0] | |
| length = struct.unpack_from(int_endian + "i", bhead, 4)[0] |
| x, y = struct.unpack( | ||
| int_endian_pair, | ||
| dimensions, | ||
| ) |
There was a problem hiding this comment.
| x, y = struct.unpack( | |
| int_endian_pair, | |
| dimensions, | |
| ) | |
| x, y = struct.unpack(int_endian_pair, dimensions) |

Summary
Updates blender_thumbnailer.py to read Blender 5.x files.
Refactor blender_thumbnailer.py to improve readability and maintainability. (Declaring this bit as AI made)
Handle file operations more safely.
Tasks Completed