FastScaleByteByByte() public static method

public static FastScaleByteByByte ( byte a, byte b ) : byte
a byte
b byte
return byte
Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
        private unsafe bool ProcessGradientLine(byte startAlpha, byte endAlpha, int y, Rectangle rect, ImageSurface surface, ColorBgra *src_data_ptr, int src_width)
        {
            var pixelPtr = surface.GetPointAddressUnchecked(src_data_ptr, src_width, rect.Left, y);
            var right    = rect.GetRight();

            if (alphaOnly && alphaBlending)
            {
                for (var x = rect.Left; x <= right; ++x)
                {
                    var lerpByte    = ComputeByteLerp(x, y);
                    var lerpAlpha   = lerpAlphas[lerpByte];
                    var resultAlpha = Utility.FastScaleByteByByte(pixelPtr->A, lerpAlpha);
                    pixelPtr->A = resultAlpha;
                    ++pixelPtr;
                }
            }
            else if (alphaOnly && !alphaBlending)
            {
                for (var x = rect.Left; x <= right; ++x)
                {
                    var lerpByte  = ComputeByteLerp(x, y);
                    var lerpAlpha = lerpAlphas[lerpByte];
                    pixelPtr->A = lerpAlpha;
                    ++pixelPtr;
                }
            }
            else if (!alphaOnly && (alphaBlending && (startAlpha != 255 || endAlpha != 255)))
            {
                // If we're doing all color channels, and we're doing alpha blending, and if alpha blending is necessary
                for (var x = rect.Left; x <= right; ++x)
                {
                    var lerpByte  = ComputeByteLerp(x, y);
                    var lerpColor = lerpColors[lerpByte];
                    var result    = normalBlendOp.Apply(*pixelPtr, lerpColor);
                    *   pixelPtr  = result;
                    ++pixelPtr;
                }
                //if (!this.alphaOnly && !this.alphaBlending) // or sC.A == 255 && eC.A == 255
            }
            else
            {
                for (var x = rect.Left; x <= right; ++x)
                {
                    var lerpByte  = ComputeByteLerp(x, y);
                    var lerpColor = lerpColors[lerpByte];
                    *   pixelPtr  = lerpColor;
                    ++pixelPtr;
                }
            }
            return(true);
        }