Quantcast
Channel: WriteableBitmapEx
Viewing all articles
Browse latest Browse all 360

Edited Issue: Bug in Blit function for WPF [21788]

$
0
0
Hello,
there is bug in Blit function, when using BlendMode.Alpha.

instead of code

```
if (blendMode == BlendMode.Alpha)
{
var isa = 255 - sa;
#if NETFX_CORE
// Special case for WinRT since it does not use pARGB (pre-multiplied alpha)
destPixel = ((da & 0xff) << 24) |
((((sr * sa + isa * dr) >> 8) & 0xff) << 16) |
((((sg * sa + isa * dg) >> 8) & 0xff) << 8) |
(((sb * sa + isa * db) >> 8) & 0xff);
#else
destPixel =
((((sa << 8) + isa * da) >> 8) << 24) |
(((((sr << 8) + isa * dr) >> 8) & 0xff) << 16) |
(((((sg << 8) + isa * dg) >> 8) & 0xff) << 8) |
((((sb << 8) + isa * db) >> 8) & 0xff);
#endif
```

should be

```
if (BlendMode == BlendMode.Alpha)
{
var isa = 255 - sa;
#if NETFX_CORE
// Special case for WinRT since it does not use pARGB (pre-multiplied alpha)
destPixel = ((da & 0xff) << 24) |
((((sr * sa + isa * dr) >> 8) & 0xff) << 16) |
((((sg * sa + isa * dg) >> 8) & 0xff) << 8) |
(((sb * sa + isa * db) >> 8) & 0xff);
#else
destPixel = ((da & 0xff) << 24) |
(((((sr * sa) + isa * dr) >> 8) & 0xff) << 16) |
(((((sg * sa) + isa * dg) >> 8) & 0xff) << 8) |
((((sb * sa) + isa * db) >> 8) & 0xff);
#endif
}
```

(instead of (((sr << 8) + isa * dr) >> 8) should be (((sr * sa + isa * dr) >> 8), difference in A component is not subject of this issue
Tested with some icons, fixed version renders nice blended icons
Comments: ** Comment from web user: teichgraf **

I assume you were using it on WPF?
Keep in mind that the WB uses pre-multiplied so the RGB components are already multiplied with their alpha values on most platforms, so performing sr * sa actually means (sr*sa) * sa. I added an additional check for the WPF build if the source.Format is pRGBA. This should work for all cases now. Please get latest source code from the repository and try it.
Thanks for raising this issue.


Viewing all articles
Browse latest Browse all 360

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>