I need to create transparency, having 2 pixels: A, R, G, Bee values are represents each color byte value Now I am calculating transparency as: But this is very slow I need to do all this with bitwise operators ( and, or, XOR , Prohibition, BIT trick ) I want to do this on Windows Phone 7 XNA --- attached C # code --- You can not mix 8-bit alpha by using a bit bit operation You basically multiplied with the original ops (8 variations-joints). You can do the two methods mentioned in other answers: Use 256 instead of 255, or use a lookup table. Both have problems, but you can reduce them. It really depends on the architecture how you are doing it: multiplication, separation, change, the relative speed of addition and memory load. In any case: Lookup Table: A trivial 256x256 lookup table is 64KB This will erase your data cache and will be very slow. I will not recommend it until your CPU is slow multiplier with instability, but low latency RAM can improve performance by throwing some alpha bits, like A & gt; & Gt; 3, which results in 32x256 = 8KB lookup, which has a better chance of fitting in the cache. Use 256 instead of 255: Idea is being divided by 256 8. Right just one shift, it can be a little bit far away and do it for round, the image is slightly darker , If R = 255, a = 255 then (R * A) / 256 = 254 you (R + A + R + A) / 256 or just (R * A + R) / 256 or (ra AA A) / 256 = 255: Cheat a little more can do this. Or, from scale A to 0..256 first, such as: A = (256 * A) / 255 is 6 instead of just one expensive divide -255. Then, (R * A) / 256 = 255 pixel1: {A, R, G, B} - Foreground Pixel
Pixel 2: {A, R, G, B} - Background Pixels newR = pixel2_R * alpha / 255 + Pixel1_R * (255 - alpha) / 255
newG = pixel2_g * alpha / 255 + pixel1_g * (255 - alpha) / 255
newb = pixel2_B * al F / 255 + pixel1_B * (255 - alpha) / 255
Public stable uint GetPixelForOpacity (uint reductionOpacityLevel, uint pixelBackground, uint pixelForeground, uint pixelCanvasAlpha) {byte surfacer = (byte) ((Pixel Forford & 0x00FF0000) & gt; & Gt; 16); Byte Surgeon = (Byte) ((Pixel Forford & 0x0000FF00) & gt; & gt; 8); Byte Surface B = (Byte) ((Pixel Forford & 0x000000 FF)); Byte source R = (byte) ((; Pixel Background & amp 0x00FF0000) & gt; & gt; 16); Byte sourceG = (byte) ((pixelBackground & amp; 0x0000FF00) & gt; & gt; 8); Byte source B = (byte) ((pixel background and 0x000000 FF)); Camel Never = Surser * Pikselsnvslfa / 256 + Srfsr * (255 - Pikselsnvslfa) / 256; Uint Nevg = Sources * Pikselsnvslfa / 256 + Surfseg * (255 - Pikselsnvslfa) / 256; Uint Nuova Nube = Surseb * Pikselsnvslfa / 256 + Surfasb * (255 - Pikselsnvslfa) / 256; Return (UIT) 255 & lt; & Lt; 24 | New r & lt; & Lt; 16 | New g & lt; & Lt; 8 | Newb; }
Comments
Post a Comment