Some notes about Pixmap

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

Tagged: 

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

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

    nerobot
    Participant

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

    #12108

    abakobo
    Participant

    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.

    #12111

    nerobot
    Participant

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

    it is an artefacts-free for me.

    #12112

    Mark Sibly
    Keymaster

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

    #12127

    nerobot
    Participant

    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.

    #12128

    Simon Armstrong
    Participant

    According to the spec https://www.w3.org/TR/PNG-Rationale.html PNG should not contain premultiplied alpha pixels. Is it likely the SavePNG function needs to un-premultiply pixel data before saving?

    #12146

    abakobo
    Participant

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

    #15554

    SekaiChi
    Participant

    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.