Pillow plugin for Python?
libPGF is an implementation of the Progressive Graphics File (PGF)
Brought to you by:
c_stamm
Hi! Do you know if anyone has attempted to write a plugin for Pillow (https://pillow.readthedocs.io/en/stable/)? This would be cool because it would allow using the PGF format in every Python project. I suppose it's not too difficult, since libpgf can be wrapped as a C extension.
I came up with this question while working on a Python tool interacting with Digikam's databases, and being unable to load the thumbnails, which are stored in PGF format (which in principle is a cool thing).
-------- Ursprüngliche Nachricht --------
Von: David Straub <davidmstraub@users.sourceforge.net>
Datum: Fr., 15. Jan. 2021, 10:50
An: "Ticket #4: Pillow plugin for Python?" <4@feature-requests.libpgf.p.re.sourceforge.net>
Betreff: [libpgf:feature-requests] #4 Pillow plugin for Python?
Hi,
I don't know C or anything about image codecs, but I am a Python developer, so it looks like a good match ;-)
Indeed I would be happy to work on this. I played around a bit with the scaffolding for a Pillow plugin and put what I have cobbled together into a Github repo:
https://github.com/DavidMStraub/Pillow-PGF
Basically there is a Python method
decode
indecoder.py
that calls thedecode
function from the C extension inpgf_decoder.c
. Do you think you could provide something along these lines?If using a Github repo is fine for you I can give you push access.
Best,
David
Hello David
Ok, let's try to write a libpgf plugin for pillow. Github is good for me.
I think a good starting point is an existing simple image format like
PCX, Raw, or TgaRLE. I have seen that in the python part you need to
implement 3 functions:
with 'PGF' = 0x50 0x47 0x46
The signature for the decoding function should be:
int
ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8
*buf, Py_ssize_t bytes) {
The parameter im includes the file descriptor I need to read the
file and buf is the allocated image buffer of size bytes, it will
contain the read image at the end.
The signature for the encoding function should be:
int
ImagingPcxEncode(Imaging im, ImagingCodecState state, UINT8
*buf, int bytes) {
In a first version we should keep it as simple as possbile and not
offer progressive decoding and ROI features.
Best,
Chris
Zitat von David Straub davidmstraub@users.sourceforge.net:
Links:
[1] https://sourceforge.net/p/libpgf/feature-requests/4/
Yes, sounds good, I agree that the simple decoder should be the first step.
This is already done by this piece of code:
https://github.com/DavidMStraub/Pillow-PGF/blob/main/pillow_pgf/init.py#L53-L57
Right. One problem I faced when playing around was that I didn't really understand how to get the decoder working when fully implemented in C. The documentation is very brief and I did not find a single example of a standalone (i.e. not included in the main
Pillow
package) plugin where thedecode
function is implemented (only) in C. I did however find examples where the decode function was a Python function calling a C extension, so this is how I have set up the code for now. So in the PGFDecoder.decode Python method here,https://github.com/DavidMStraub/Pillow-PGF/blob/main/pillow_pgf/decoder.py#L13
a function from a C extension (with whatever signature is convenient) can be called.
I suggest to continue the discussion directly on Github; I opened an issue for this purpose:
https://github.com/DavidMStraub/Pillow-PGF/issues/1
I suggest to tackle this in a second step after we have the decoder working.
Best, David