Skip to content

Correct implementation of "msAlphaBlendPM".#7358

Open
ThomasCusson wants to merge 1 commit intoMapServer:mainfrom
ThomasCusson:main
Open

Correct implementation of "msAlphaBlendPM".#7358
ThomasCusson wants to merge 1 commit intoMapServer:mainfrom
ThomasCusson:main

Conversation

@ThomasCusson
Copy link

At our company we noticed, using the composite "src-over" blending mode (default), that some darkening is happening when opacity is not 0% or 100%. This is a typical problem of pre-multiplied alpha, so I looked into it.

It seems that the msAlphaBlendPM (PM stands for Pre-Multiplied) acts as if the bands were not pre-multiplied already, in a fashion similar to msAlphaBlend.
It results in a double multiplication by alpha channel, producing colors that are too dark on half-transparent areas. This issue probably arise only when using a change of projection, as it is only called in mapresample.c.

I also used "256" values instead of 255, to match the implementation from msAlphaBlend, but maybe it's not useful, I'll leave that up to your judgement.

@Guillaume0789
Copy link

Hey !
I work with Thomas and here a screenshot of the problem we encountered.
weird effect between images

@ThomasCusson ThomasCusson changed the title Correct implementation of "msAlphaBlendPM". Bands are already pre-mul… Correct implementation of "msAlphaBlendPM". Oct 6, 2025
…tiplied, no need to multiply them again.

Compliance with the optimized approach of msAlphaBlend (using 256 instead of 255)
@jmckenna
Copy link
Member

jmckenna commented Oct 6, 2025

thanks @ThomasCusson . Please also include a test for this as part of your pull request (you can see a few other COMPOP tests in /msautotest/renderers/). Find more info about msautotest at https://mapserver.org/development/tests/autotest.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants