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

Libjpeg-turbo #71

Open
darcymason opened this issue Jul 7, 2023 · 8 comments
Open

Libjpeg-turbo #71

darcymason opened this issue Jul 7, 2023 · 8 comments
Labels
enhancement New feature or request
Milestone

Comments

@darcymason
Copy link
Member

Apparently there is now 12-bit support in libjpeg-turbo as of v3.0.x.

Perhaps it can be investigated as a replacement for / in addition to pylibjpeg-libjpeg, with a more permissive license (BSD-style).

According to the libjpeg-turbo README:

The libjpeg API implementation in libjpeg-turbo is both API/ABI-compatible and mathematically compatible with libjpeg v6b. It can also optionally be configured to be API/ABI-compatible with libjpeg v7 and v8 (see below.)

Which sounds to me (non-expert) like it could be almost a drop-in replacement in the existing libjpeg handler code.

@darcymason darcymason added the enhancement New feature or request label Jul 7, 2023
@mrbean-bremen
Copy link
Member

Good find! Yes, if it has the same functionality and we are able to integrate it, I see no reason to retain the old version, as the other plugins already are under MIT or compatible licenses. I (also as a non-expert) have recently been told in another context that libjpeg can be completely replaced by libjpeg-turbo featurewise, and that both implement the same standard. And libjpeg-turbo should be faster...
So this sounds very promising to me. I may have a closer look at this, though that may take quite some time, as I'm really no expert here (wish @scaramallion would re-surface...). Or you may have a go, as you already have been diving into this.

@darcymason
Copy link
Member Author

(wish @scaramallion would re-surface...).

Same.

Or you may have a go, as you already have been diving into this.

I've looked some more out of curiosity. Seems to me the key is in building the wheels, after that the drop-in should be okay.
But the source layout and make files etc look quite different, so that might not be completely straightforward, but I'll leep looking.

Given that it look like there will be a fair number of changes, I'll probably create a pylibjpeg-libjpegturbo repo (long name but matches the current style) and get that started at least. I'll start locally and push up to create on github if it seems to be going okay. That leaves the existing -libjpeg repo in place for anyone who needs it and we can just use the turbo from pylibjpeg.

@mrbean-bremen
Copy link
Member

Seems to me the key is in building the wheels

I think you can reuse the existing workflow to build the wheels without problems. I think the key is rewiting the _libjpeg.pyx and utils.py (though that won't probably change much) files - basically the interface to the library.

Given that it look like there will be a fair number of changes, I'll probably create a pylibjpeg-libjpegturbo repo

Yes, I have been thinking along the same lines after thinking about it a bit more, so I completely agree. Go ahead!

@darcymason
Copy link
Member Author

basically the interface to the library.

Hmmm ... I started digging into the Cython stuff and all that, then I remembered I had seen PyTurboJPEG - wraps the lib with ctypes calls, but it doesn't build libjpeg-turbo (up to the user to install themselves). Probably enough and simplifies things a lot for us. In fact, can start without even trying to build the wheels ourselves.

And... I was thinking that because pylibjpeg-libjpeg is GPLv3, then we should be careful not to possibly be interpreted as a derived work.

As I look a little more, PyTurboJPEG is really small and simple, we could even just copy the bits we need (it is MIT). I'll start down this line and see how it goes.

@darcymason
Copy link
Member Author

Okay, I've created a structure and opened a public repo: https://github.com/pydicom/pylibjpeg-turbo (I went with the shorter name, too much typing). Still very much WIP, of course.

@mrbean-bremen
Copy link
Member

As I look a little more, PyTurboJPEG is really small and simple, we could even just copy the bits we need (it is MIT). I'll start down this line and see how it goes.

Yes, this is possible, though in general I prefer the sub-module approach - much less maintenance needed for moving to a new version. But if we need only a small part, it certainly makes sense.

@darcymason
Copy link
Member Author

I agree, I think I didn't write carefully, what I meant was to start with PyTurboJPEG as a dependency, but if we need something a little different we could just add it ourselves, (modeling on their code, and contribute it back to PyTurboJPEG if it might be of general interest).

@mrbean-bremen
Copy link
Member

Ah ok, I didn't indeed understand you correctly. This make sense, of course!

@scaramallion scaramallion added this to the v2.0.0 milestone Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants