[OpenSmalltalk/opensmalltalk-vm] Proposal for new BitBlt rules (#505)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[OpenSmalltalk/opensmalltalk-vm] Proposal for new BitBlt rules (#505)

David T Lewis
 

In addition to the existing alpha blending rules (24 and 34), I propose 3 new additional rules.

Check https://en.wikipedia.org/wiki/Alpha_compositing

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.

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.

The other two additional proposed rules are for converting to and from premultiplied alpha.

EXISTING blend 24 alphaBlend
resultAlpha = srcAlpha + destAlpha*(1-srcAlpha)
resultRGB = srcAlpha*source + (1-srcAlpha)*dest

EXISTING blendAlphaScaled 34 alphaBlendScaled
resultRGBA = source + (1-srcAlpha)*dest

NEW PROPOSED multiplyRGBByAlpha
Non premultiplied alpha -> premultiplied alpha. Only uses destination. Alpha unmodified. For each RGB component,
resultRGB = dest*destAlpha

NEW PROPOSED divideRGBByAlpha
Premultiplied alpha -> non premultiplied alpha. Only uses destination. Alpha unmodified. For each RGB component,
resultRGB = dest/destAlpha

NEW PROPOSED blendUnscaled
Equivalent to blend, and then divideRGBByAlpha
resultAlpha = srcAlpha + destAlpha*(1-srcAlpha)
resultRGB = (srcAlpha*source + (1-srcAlpha)*dest) / resultAlpha

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.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

<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>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Proposal for new BitBlt rules (#505)

David T. Lewis
 
I believe this proposal is motivated by the issue discussed here:

  https://lists.cuis.st/mailman/archives/cuis-dev/2020-June/001817.html

Is that right?

Dave


On Tue, Jun 02, 2020 at 12:06:42PM -0700, Juan Vuletich wrote:

>  
> In addition to the existing alpha blending rules (24 and 34), I propose 3 new additional rules.
>
> Check https://en.wikipedia.org/wiki/Alpha_compositing 
>
> 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.
>
> 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.
>
> The other two additional proposed rules are for converting to and from premultiplied alpha.
>
> EXISTING blend 24 alphaBlend
> resultAlpha = srcAlpha + destAlpha*(1-srcAlpha)
> resultRGB   = srcAlpha*source + (1-srcAlpha)*dest
>
> EXISTING blendAlphaScaled 34 alphaBlendScaled
> resultRGBA = source + (1-srcAlpha)*dest
>
> NEW PROPOSED multiplyRGBByAlpha
> Non premultiplied alpha -> premultiplied alpha. Only uses destination. Alpha unmodified. For each RGB component,
> resultRGB = dest*destAlpha
>
> NEW PROPOSED divideRGBByAlpha
> Premultiplied alpha -> non premultiplied alpha. Only uses destination. Alpha unmodified. For each RGB component,
> resultRGB = dest/destAlpha
>
> NEW PROPOSED blendUnscaled
> Equivalent to blend, and then divideRGBByAlpha
> resultAlpha = srcAlpha + destAlpha*(1-srcAlpha)
> resultRGB   = (srcAlpha*source + (1-srcAlpha)*dest) / resultAlpha
>
> 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.
>
> --
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly or view it on GitHub:
> https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Proposal for new BitBlt rules (#505)

Stéphane Rollandin
In reply to this post by David T Lewis
 
> In addition to the existing alpha blending rules (24 and 34), I propose
> 3 new additional rules.

+1

(I have spent hours working around these issues for my latest game).

Stef

Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Proposal for new BitBlt rules (#505)

David T Lewis
In reply to this post by David T Lewis
 

Yep. That's right.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505#issuecomment-637802794", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505#issuecomment-637802794", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Proposal for new BitBlt rules (#505)

David T Lewis
In reply to this post by David T Lewis
 

Thanks Juan to report it.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505#issuecomment-638043658", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505#issuecomment-638043658", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Proposal for new BitBlt rules (#505)

David T Lewis
In reply to this post by David T Lewis
 

Would be nice to also have the Smalltalk fall-back code for those new rules. :-)


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505#issuecomment-638046311", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505#issuecomment-638046311", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Proposal for new BitBlt rules (#505)

David T Lewis
In reply to this post by David T Lewis
 

WIP http://source.squeak.org/VMMaker/VMMaker.oscog-nice.2909.diff


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505#issuecomment-750471145", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505#issuecomment-750471145", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Proposal for new BitBlt rules (#505)

timrowledge
 


> On 2020-12-23, at 12:56 PM, Nicolas Cellier <[hidden email]> wrote:
>
>
> WIP http://source.squeak.org/VMMaker/VMMaker.oscog-nice.2909.diff

Without having actually looked into this I just want ot wave a flag to remind us all to be sure it integrates ok with the ARM special purpose bitlbt routines.

Also, we *might* just possibly be getting the gift of some Ben Avison time to make the 64bit ARM equivalents.

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: MBR: Move Bits Randomly


Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Proposal for new BitBlt rules (#505)

David T Lewis
In reply to this post by David T Lewis
 

I won't provide any accelerated assembler for the new ops, not my cup of tea.
But as I understand it, the PI will fall back to the code generated for the BitBlt plugin when no accelerated path is provided, so it should continue to work.
What would be nice now would be to start writing image side code & unit tests in either Cuis or Squeak.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505#issuecomment-751481672", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505#issuecomment-751481672", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Proposal for new BitBlt rules (#505)

David T Lewis
In reply to this post by David T Lewis
 

http://source.squeak.org/inbox/GraphicsTests-nice.57.diff
http://source.squeak.org/inbox/Graphics-nice.442.diff


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505#issuecomment-751501404", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/505#issuecomment-751501404", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>