Menu

#4 Pillow plugin for Python?

open
nobody
None
5
2021-01-20
2021-01-15
No

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).

Discussion

  • Christoph Stamm

    Christoph Stamm - 2021-01-18
    Hello David

    Thanks for your proposal. I agree with you that an integration in Pillow would be interesting, but I don't know anybody who is working on this. I've checked the source code of Pillow and have seen that it needs a python and a C part to write a PGF plugin.
    Since I'm not a Python programmer I could only implement the C part if someone else, maybe you, would implement the python part of the plugin.
    Let me know if you would like to work on that.

    Chris



    -------- 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?

    [feature-requests:#4] Pillow plugin for Python?

    Status: open
    Group: Next Release (example)
    Created: Fri Jan 15, 2021 09:50 AM UTC by David Straub
    Last Updated: Fri Jan 15, 2021 09:50 AM UTC
    Owner: nobody

    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).


    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/libpgf/feature-requests/4/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

     
    • David Straub

      David Straub - 2021-01-18

      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 in decoder.py that calls the decode function from the C extension in pgf_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

       
      • Christoph Stamm

        Christoph Stamm - 2021-01-19

        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:

        • checking a file if it contains a PGF image; each PGF image starts
          with 'PGF' = 0x50 0x47 0x46
        • reading and decoding an image file to a memory buffer
        • encoding and writing an image file

        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:

        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 in decoder.py that calls
        the decode function from the C extension in pgf_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


        [FEATURE-REQUESTS:#4][1] PILLOW PLUGIN FOR PYTHON?

        STATUS: open
        GROUP: Next Release (example)
        CREATED: Fri Jan 15, 2021 09:50 AM UTC by David Straub
        LAST UPDATED: Fri Jan 15, 2021 09:50 AM UTC
        OWNER: nobody

        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).


        Sent from sourceforge.net because you indicated interest in
        https://sourceforge.net/p/libpgf/feature-requests/4/

        To unsubscribe from further messages, please visit
        https://sourceforge.net/auth/subscriptions/

        [1] https://sourceforge.net/p/libpgf/feature-requests/4/

         
  • David Straub

    David Straub - 2021-01-20

    Yes, sounds good, I agree that the simple decoder should be the first step.

    checking a file if it contains a PGF image; each PGF image starts
    with 'PGF' = 0x50 0x47 0x46

    This is already done by this piece of code:
    https://github.com/DavidMStraub/Pillow-PGF/blob/main/pillow_pgf/init.py#L53-L57

    reading and decoding an image file to a memory buffer

    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 the decode 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

    encoding and writing an image file

    I suggest to tackle this in a second step after we have the decoder working.

    Best, David

     

Log in to post a comment.