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

Problem with copynone using libjpeg-turbo 3.0.0 #74

Closed
erikogabrielsson opened this issue Aug 18, 2023 · 7 comments
Closed

Problem with copynone using libjpeg-turbo 3.0.0 #74

erikogabrielsson opened this issue Aug 18, 2023 · 7 comments
Assignees

Comments

@erikogabrielsson
Copy link
Contributor

Hi,

I noticed that when using libjpeg-turbo 3.0.0 markers are removed regardless of copynone being set:

libjpeg-turbo 3.0.0:

turbo = TurboJPEG(r"C:\tools\libjpeg-turbo64-3.0.0\bin\turbojpeg.dll")
cropped = turbo.crop_multiple(tile_2, [(0, 0, 32, 32)], copynone=False)[0]
print(cropped[0:30])
>> b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00C\x00\x06\x04\x05\x06\x05'

libjpeg-turbo 2.1.*

turbo = TurboJPEG(r"C:\tools\libjpeg-turbo64\bin\turbojpeg.dll")
cropped = turbo.crop_multiple(tile_2, [(0, 0, 32, 32)], copynone=False)[0]
print(cropped[0:30])
>> b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xfe\x00)Hamama'

On 2.1.* I get the FF-FE comment marker followed by the comment, on 3.0.0 it is missing.

Setting copynone=True on 2.1.* produces the desired output (no comment marker). Also jpegtran in 3.0.0 seems to work with the different copy-switches.

@lilohuang lilohuang reopened this Aug 18, 2023
@lilohuang lilohuang self-assigned this Aug 18, 2023
@lilohuang
Copy link
Owner

I looked at the release notes for libjpeg-turbo 3.0.0, and it appears that there's a known issue where metadata cannot be copied correctly. Could you please share your input file? This might help speed up the process. I'm not certain if I can completely resolve this problem. One more thing, PyTurboJPEG should already be utilizing the mechanism for automatic reallocation of the JPEG destination buffer...


https://github.com/libjpeg-turbo/libjpeg-turbo/releases/tag/3.0.0

image

@erikogabrielsson
Copy link
Contributor Author

Here is the image I tested with. It is derived from CMU-1.ndpi (CC0-1.0 licence) using OpenTile.
tile_2

@erikogabrielsson
Copy link
Contributor Author

When viewing the file in JpegSnoop the comment is the only extra metadata, and it is of length 41.

@erikogabrielsson
Copy link
Contributor Author

erikogabrielsson commented Dec 6, 2023

I have investigated this further. For some reason if I use tj3Transform instead of tjTransform I get the comment marker included in the result for copynone=False, see this branch..

@lilohuang
Copy link
Owner

Hi @erikogabrielsson ,

I apologize for not having had the opportunity to delve into this due to my daily work commitments. I am pleased to learn that you have found a solution, and I have reviewed your branch. It seems ideal to use getattr for checking tj3Transform availability. Could you kindly create a pull request so that I can incorporate your contribution into the mainstream?

Thanks,
Lilo

lilohuang added a commit that referenced this issue Dec 6, 2023
Fixing a problem with copynone using libjpeg-turbo 3.0.0 (#74). Thanks to @erikogabrielsson for his contribution.
---------

Co-authored-by: Erik O Gabrielsson <83275777+erikogabrielsson@users.noreply.github.com>
@lilohuang
Copy link
Owner

Hi @erikogabrielsson ,

Your code change has been merged.

Thanks,
Lilo

@erikogabrielsson
Copy link
Contributor Author

Thank you @lilohuang. Your work with pyTurboJPEG has saved a lot of work so happy to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants