1

i am writing some C# code to alpha blend two 32bit pixels in ARGB form like this:

Red = 0xFFFF0000 with an Alpha of 255 "FF"

Anyways, I am trying to avoid byte per byte blending like this:

public static Color Blend(this Color color, Color backColor, double amount)
    {
        amount = (255 - amount);
        byte r = (byte)((color.R * amount / 255) + backColor.R * (255 - amount) / 255);
        byte g = (byte)((color.G * amount / 255) + backColor.G * (255 - amount) / 255);
        byte b = (byte)((color.B * amount / 255) + backColor.B * (255 - amount) / 255);
        return Color.FromArgb(r, g, b);
    }

I'm trying to make this as fast as possible without using double. Is there an equation that can alpha blend two pixels in integer form without breaking it into bytes?

P.S. I cannot use any .Net framework calls like Color.FromARGB and stuff.

Thank's

1 Answers1

0

You could use the other .FromArgb method that accepts an integer alpha parameter.

Jake H
  • 1,720
  • 1
  • 12
  • 13
  • I cant use that with what I am doing sadly. I plan on writing the equation that does what I want to Assembly. – user3213751 Jan 20 '14 at 04:32
  • Then read [this SO answer about ARGB blending](http://stackoverflow.com/questions/1944095/how-to-mix-two-argb-pixels) – Jake H Jan 20 '14 at 04:34
  • 1
    Already read it before asking my question. I need an equation that does not do "byte per byte" blending rather blending of the whole ARGB value so that I can save CPU calculations and time. – user3213751 Jan 20 '14 at 04:40