<p></p>
<p>In addition to the existing alpha blending rules (24 and 34), I propose 3 new additional rules.</p>
<p>Check <a href="https://en.wikipedia.org/wiki/Alpha_compositing" rel="nofollow">https://en.wikipedia.org/wiki/Alpha_compositing</a></p>
<p>Existing rule 34 is a correct implementation of Alpha Blending for scaled forms, i.e. if premultiplied alpha is used. But rule 24 is a correct implementation of non-scaled forms, only for the case where destination is opaque (i.e. it's alpha is 1.0 in every pixel). If destination includes translucency (or it is completely transparent), the result is not correct. In order to fix it, the RGB of each pixel need to be divided by the pixel alpha.</p>
<p>The proposed blendUnscaled is the basic (for non-scaled forms) alpha blending described in Wikipedia. Note that users knowing that destination background is opaque might call the faster rule 24 instead.</p>
<p>The other two additional proposed rules are for converting to and from premultiplied alpha.</p>
<p>EXISTING blend 24      alphaBlend<br>
resultAlpha = srcAlpha + destAlpha*(1-srcAlpha)<br>
resultRGB   = srcAlpha*source + (1-srcAlpha)*dest</p>
<p>EXISTING blendAlphaScaled      34      alphaBlendScaled<br>
resultRGBA = source + (1-srcAlpha)*dest</p>
<p>NEW PROPOSED multiplyRGBByAlpha<br>
Non premultiplied alpha -> premultiplied alpha. Only uses destination. Alpha unmodified. For each RGB component,<br>
resultRGB = dest*destAlpha</p>
<p>NEW PROPOSED divideRGBByAlpha<br>
Premultiplied alpha -> non premultiplied alpha. Only uses destination. Alpha unmodified. For each RGB component,<br>
resultRGB = dest/destAlpha</p>
<p>NEW PROPOSED blendUnscaled<br>
Equivalent to blend, and then divideRGBByAlpha<br>
resultAlpha = srcAlpha + destAlpha*(1-srcAlpha)<br>
resultRGB   = (srcAlpha*source + (1-srcAlpha)*dest) / resultAlpha</p>
<p>This would allow handling of scaled (premultiplied-alpha) forms, and blending of regular forms including translucency, without the need to call slower smalltalk code to fix the results.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AIJPEW2OPOGHNV5DX67AQATRUVEUFANCNFSM4NQ73OWA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AIJPEW7G7CDKQ6HWLO7GSBDRUVEUFA5CNFSM4NQ73OWKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4JMERT7Q.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505",
"url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>