Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make ARGB transparency using bitwise operators
    primarykey
    data
    text
    <p>I need to make transparency, having 2 pixels:</p> <p><code>pixel1: {A, R, G, B} - foreground pixel<br> pixel2: {A, R, G, B} - background pixel</code></p> <p>A,R,G,B are Byte values</p> <p>each color is represented by byte value</p> <p>now I'm calculating transparency as:</p> <p><code>newR = pixel2_R * alpha / 255 + pixel1_R * (255 - alpha) / 255<br> newG = pixel2_G * alpha / 255 + pixel1_G * (255 - alpha) / 255<br> newB = pixel2_B * alpha / 255 + pixel1_B * (255 - alpha) / 255</code></p> <p>but it is too slow I need to do it with bitwise operators (<strong>AND,OR,XOR, NEGATION, BIT MOVE</strong>)</p> <p>I want to do it on Windows Phone 7 XNA</p> <p>---attached C# code---</p> <pre><code> public static uint GetPixelForOpacity(uint reduceOpacityLevel, uint pixelBackground, uint pixelForeground, uint pixelCanvasAlpha) { byte surfaceR = (byte)((pixelForeground &amp; 0x00FF0000) &gt;&gt; 16); byte surfaceG = (byte)((pixelForeground &amp; 0x0000FF00) &gt;&gt; 8); byte surfaceB = (byte)((pixelForeground &amp; 0x000000FF)); byte sourceR = (byte)((pixelBackground &amp; 0x00FF0000) &gt;&gt; 16); byte sourceG = (byte)((pixelBackground &amp; 0x0000FF00) &gt;&gt; 8); byte sourceB = (byte)((pixelBackground &amp; 0x000000FF)); uint newR = sourceR * pixelCanvasAlpha / 256 + surfaceR * (255 - pixelCanvasAlpha) / 256; uint newG = sourceG * pixelCanvasAlpha / 256 + surfaceG * (255 - pixelCanvasAlpha) / 256; uint newB = sourceB * pixelCanvasAlpha / 256 + surfaceB * (255 - pixelCanvasAlpha) / 256; return (uint)255 &lt;&lt; 24 | newR &lt;&lt; 16 | newG &lt;&lt; 8 | newB; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload