Pinta.ImageManipulation.ColorBgra.BlendColors4W16IP C# (CSharp) Method

BlendColors4W16IP() public static method

Blends four colors together based on the given weight values.
The weights should be 16-bit fixed point numbers that add up to 65536 ("1.0"). 4W16IP means "4 colors, weights, 16-bit integer precision"
public static BlendColors4W16IP ( ColorBgra c1, uint w1, ColorBgra c2, uint w2, ColorBgra c3, uint w3, ColorBgra c4, uint w4 ) : ColorBgra
c1 ColorBgra
w1 uint
c2 ColorBgra
w2 uint
c3 ColorBgra
w3 uint
c4 ColorBgra
w4 uint
return ColorBgra
        public static ColorBgra BlendColors4W16IP(ColorBgra c1, uint w1, ColorBgra c2, uint w2, ColorBgra c3, uint w3, ColorBgra c4, uint w4)
        {
#if DEBUG
            if ((w1 + w2 + w3 + w4) != 65536)
            {
                throw new ArgumentOutOfRangeException("w1 + w2 + w3 + w4 must equal 65536!");
            }
#endif

            const uint ww = 32768;
            uint af = (c1.A * w1) + (c2.A * w2) + (c3.A * w3) + (c4.A * w4);
            uint a = (af + ww) >> 16;

            uint b;
            uint g;
            uint r;

            if (a == 0)
            {
                b = 0;
                g = 0;
                r = 0;
            }
            else
            {
                b = (uint)((((long)c1.A * c1.B * w1) + ((long)c2.A * c2.B * w2) + ((long)c3.A * c3.B * w3) + ((long)c4.A * c4.B * w4)) / af);
                g = (uint)((((long)c1.A * c1.G * w1) + ((long)c2.A * c2.G * w2) + ((long)c3.A * c3.G * w3) + ((long)c4.A * c4.G * w4)) / af);
                r = (uint)((((long)c1.A * c1.R * w1) + ((long)c2.A * c2.R * w2) + ((long)c3.A * c3.R * w3) + ((long)c4.A * c4.R * w4)) / af);
            }

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

Usage Example

コード例 #1
0
        public static unsafe ColorBgra GetBilinearSampleWrapped(ISurface src, ColorBgra *srcDataPtr, int srcWidth, int srcHeight, float x, float y)
        {
            if (!Utility.IsNumber(x) || !Utility.IsNumber(y))
            {
                return(ColorBgra.Transparent);
            }

            float u = x;
            float v = y;

            unchecked {
                int  iu        = (int)Math.Floor(u);
                uint sxfrac    = (uint)(256 * (u - (float)iu));
                uint sxfracinv = 256 - sxfrac;

                int  iv        = (int)Math.Floor(v);
                uint syfrac    = (uint)(256 * (v - (float)iv));
                uint syfracinv = 256 - syfrac;

                uint wul = (uint)(sxfracinv * syfracinv);
                uint wur = (uint)(sxfrac * syfracinv);
                uint wll = (uint)(sxfracinv * syfrac);
                uint wlr = (uint)(sxfrac * syfrac);

                int sx = iu;
                if (sx < 0)
                {
                    sx = (srcWidth - 1) + ((sx + 1) % srcWidth);
                }
                else if (sx > (srcWidth - 1))
                {
                    sx = sx % srcWidth;
                }

                int sy = iv;
                if (sy < 0)
                {
                    sy = (srcHeight - 1) + ((sy + 1) % srcHeight);
                }
                else if (sy > (srcHeight - 1))
                {
                    sy = sy % srcHeight;
                }

                int sleft = sx;
                int sright;

                if (sleft == (srcWidth - 1))
                {
                    sright = 0;
                }
                else
                {
                    sright = sleft + 1;
                }

                int stop = sy;
                int sbottom;

                if (stop == (srcHeight - 1))
                {
                    sbottom = 0;
                }
                else
                {
                    sbottom = stop + 1;
                }

                ColorBgra cul = src.GetPoint(sleft, stop);
                ColorBgra cur = src.GetPoint(sright, stop);
                ColorBgra cll = src.GetPoint(sleft, sbottom);
                ColorBgra clr = src.GetPoint(sright, sbottom);

                ColorBgra c = ColorBgra.BlendColors4W16IP(cul, wul, cur, wur, cll, wll, clr, wlr);

                return(c);
            }
        }
All Usage Examples Of Pinta.ImageManipulation.ColorBgra::BlendColors4W16IP