Hello everyone,
I am doing a research regarding PNG and I'm obtaining inconsistent results exporting PNG using Photoshop , while I got consistent results using other software (Affinity, Kryta, ...).
The exported images seem identical. However when I make a pixel per pixel comparison, I see some differences.
Differences seem to occur when two layers overlap.
I'm overlapping two layer with Normal blending mode. So we're just talking about simple alpha compositing.

To make thing easier I extracted some pixels from the two layers. Here their RGBA values:
Pixel 1
a) Top layer (RGBA): 56, 0, 8, 250
b) Bottom layer (RGBA): 133, 92, 78, 250
Photoshop resulting PNG: 58, 2, 9, 255
Mathematical result: 57, 2, 9, 255
Where (to simplify formulae visualization ð means dividing by 255):
- αo = 250 + 250 * (255 - 250)ð = 254.9019608 -> rounded: 255
- Cor = (56*250ð + 133 * 250ð * (255 - 250)ð) / 254.9019608 * 255 = 57.48076923 -> rounded: 57
- Cog = (0*250ð + 92 * 250ð * (255 - 250)ð) / 254.9019608 * 255 = 1.769230769 -> rounded: 2
- Cob = (8*250ð + 78 * 250ð * (255 - 250)ð) / 254.9019608 * 255 = 9.346153846 -> rounded: 9
Pixel 2
a) Top layer (RGBA): 59, 0, 0, 13
b) Bottom layer (RGBA): 137, 98, 78, 13
Photoshop resulting PNG: 96, 47, 37, 25
Mathematical result: 97, 48, 38, 25
Where:
- αo = 13 + 13 * (255 - 13)ð / 255 = 25.3372549 -> rounded: 25
- Cor = (59*13ð + 137 * 13ð * (255 - 13)ð) / 25.3372549 * 255 = 96.97987928 -> rounded: 97
- Cog = (0*13ð + 98 * 13ð * (255 - 13)ð) / 25.3372549 * 255 = 47.71830986 -> rounded: 58
- Cob = (0*13ð + 78 * 13ð * (255 - 13)ð) / 25.3372549 * 255 = 37.97987928 -> rounded: 38
Actually things get worse when there's some layer opacity involved.
My conclusions are:
- I'm applying the wrong formula, and/or
- There's some strange rounding involved that I cannot understand
However for my research I need to export several PNG with Photoshop and if the results are not consistent with math I have at least put a caveats on that explaining why this happen.
Is there anyone helping me understanding why this occurs?
Thanks!