Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export: images may be needlessly re-encoded in some cases #1509

Closed
scurest opened this issue Dec 19, 2021 · 0 comments · Fixed by #1513
Closed

Export: images may be needlessly re-encoded in some cases #1509

scurest opened this issue Dec 19, 2021 · 0 comments · Fixed by #1513
Labels
exporter This involves or affects the export process Material
Milestone

Comments

@scurest
Copy link
Contributor

scurest commented Dec 19, 2021

Look at this code for getting the already-encoded data for an image

if image.source == 'FILE' and image.file_format == self.file_format and \
not image.is_dirty:
if image.packed_file is not None:
data = image.packed_file.data
else:
src_path = bpy.path.abspath(image.filepath_raw)
if os.path.isfile(src_path):
with open(src_path, 'rb') as f:
data = f.read()

This assumes image.file_format describes the content of the file on disk/packed file. But that's wrong, image.file_format is only the format to use when saving, cf #986. The file_format check should be removed.

To avoid an unnecessary file read in the case of a file on disk, a check for the file extension could be added.

Re-encoding would be especially bad for JPEGs, since it would be lossy.

@scurest scurest changed the title Export: images be be needlessly re-encoded in some cases Export: images may be needlessly re-encoded in some cases Dec 19, 2021
@julienduroure julienduroure added exporter This involves or affects the export process Material labels Dec 19, 2021
julienduroure added a commit that referenced this issue Dec 20, 2021
@julienduroure julienduroure added this to the Blender 3.1 milestone Dec 24, 2021
julienduroure added a commit that referenced this issue Jan 20, 2022
Fix #1509 images may be needlessly re-encoded in some cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exporter This involves or affects the export process Material
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants