Skip to content

Confusion non-premultiplied/pre-multiplied with bilinear resampling #4993

Closed
@rouault

Description

@rouault

msBilinearRasterResampler() uses msAlphaBlendPM() to do composition.
msAlphaBlendPM() assumes that the source pixel r,g,b,a is alpha pre-multiplied. But currently, a division padfPixelSum[i] /= dfWeightSum (dfWeightSum being the alpha channel) after merging the 4 source pixels make r,g,b effectively un-premultiplied. The result is then integer overflow in saveAsPNG(), because it assumes a pre-multiplied buffer and does un-premultiplication since libpng wants un-premultiplication. This can lead to completely wrong colors in areas where alpha is > 0 and < 255.
The issue is similar with GDAL output, but in msSaveImageGDAL() there's a test to avoid overflow above 255.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions