Some notes about Pixmap

About Monkey 2 Forums Monkey 2 Programming Help Some notes about Pixmap


This topic contains 7 replies, has 5 voices, and was last updated by  Gwenel 7 months, 2 weeks ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • #12101


    Working on ImageTrimmer app I found one interesting thing:

    If you use pixmap with PremultiplyAlpha=True – when loading or after making some changes with pixels, then save pixmap – and you get pixels artefacts in saved version!

    I wanted to save on extra loading of pixmap and my steps were:

    • Load pixmap with premultiply alpha
    • Create image using our pixmap
    • Processing pixmap pixels
    • Save pixmap into file
    • (I load and save PNG format)

    Then I load just saved image and see artefacts in semi-transparent pixels.

    Solution is:

    To load an extra pixmap for processing without premultiply alpha.

    See the GIF with artefacts – bordered version is wrong (don’t pay attention on red cross).

    And see on the second image with sky blue background (I can’t remove incorrect attached file).



    I’ve had problems saving the pixmap to png too. I think it uses some png compression by default thus artifacts. It’s probably just a flag under the hood though.



    @abakobo  try to just resave pixmap without touching pixelFormat and alpha:

    it is an artefacts-free for me.


    Mark Sibly

    I think it uses some png compression by default thus artifacts.

    PNG uses loseless compression – if there are artifacts it’s a bug (possibly mine or STBs).



    mojo.Image uses Pixmap with premultiplied alpha.

    If you’ll save such pixmap then you’ll get artifacts on next loading image – alpha will be premultiplied twice here.

    I think this is the reason.

    PNG loader itself works well.


    Simon Armstrong

    According to the spec PNG should not contain premultiplied alpha pixels. Is it likely the SavePNG function needs to un-premultiply pixel data before saving?



    Can’t reproduce the artifacts I had at a time. All working good now! (not using alpha)



    You can unpremultiply before saving. This is a test using the basic pixellformat (RGBA8 which I think that’s Monkey2’s default format).

    Sorry if it is a bit more lengthy than it needs to be at the moment.


Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.