Python Plugin: Best ways to process drawable bytes into PNG?

In my Gimp 2.99 plugin, I have the bytes of a layer that I obtained from a Gegl.Buffer like this:

    width: int = drawable_in.get_width()
    height: int = drawable_in.get_height()
    buffer: Gegl.Buffer = drawable_in.get_buffer()
    rect: Gegl.Rectangle = Gegl.Rectangle.new(0, 0, width, height)
    Gegl.init(None)  # As Seen from https://gitlab.gnome.org/GNOME/gimp/-/issues/8689
    # see https://developer.gimp.org/api/gegl/method.Buffer.get.html
    src_pixels: bytes = buffer.get(rect,  # GeglRectangle rect
                                   1.0,  # double scale
                                   None,  # Babl format
                                   Gegl.AbyssPolicy.CLAMP  # GeglAbyssPolicy repeat_mode
                                   )

I want to process src_pixels into a PNG array of bytes. Ideally, I would like to do this all in memory, without saving to a file, then reading the file back in, because I would like to avoid platform issues and the IO performance bottleneck. But I understand that might be the only practical way.
Regardless, I would appreciate some advice and perhaps a code snippet, on how to proceed. The online docs for GEGL are hard to understand, and the very few examples I’ve found for python seem largely inapplicable.
Thanks!

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.