Pinta.ImageManipulation.Utility.FastScaleByteByByte C# (CSharp) Method

FastScaleByteByByte() public static method

public static FastScaleByteByByte ( byte a, byte b ) : byte
a byte
b byte
return byte
		public static byte FastScaleByteByByte (byte a, byte b)
		{
			int r1 = a * b + 0x80;
			int r2 = ((r1 >> 8) + r1) >> 8;
			return (byte)r2;
		}

Usage Example

        /// <summary>
        /// Constructs a new ColorBgra instance from the values in the given Color instance.
        /// </summary>
//        public static ColorBgra FromColor(Color c)
//        {
//            return FromBgra(c.B, c.G, c.R, c.A);
//        }

        /// <summary>
        /// Converts this ColorBgra instance to a Color instance.
        /// </summary>
//        public Color ToColor()
//        {
//            return Color.FromArgb(A, R, G, B);
//        }

        /// <summary>
        /// Smoothly blends between two colors.
        /// </summary>
        public static ColorBgra Blend(ColorBgra ca, ColorBgra cb, byte cbAlpha)
        {
            uint caA  = (uint)Utility.FastScaleByteByByte((byte)(255 - cbAlpha), ca.A);
            uint cbA  = (uint)Utility.FastScaleByteByByte(cbAlpha, cb.A);
            uint cbAT = caA + cbA;

            uint r;
            uint g;
            uint b;

            if (cbAT == 0)
            {
                r = 0;
                g = 0;
                b = 0;
            }
            else
            {
                r = ((ca.R * caA) + (cb.R * cbA)) / cbAT;
                g = ((ca.G * caA) + (cb.G * cbA)) / cbAT;
                b = ((ca.B * caA) + (cb.B * cbA)) / cbAT;
            }

            return(ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)cbAT));
        }