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
コード例 #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);
            }
        }
コード例 #2
0
        public static unsafe ColorBgra GetBilinearSampleClamped(ISurface src, float x, float y)
        {
            if (!Utility.IsNumber(x) || !Utility.IsNumber(y))
            {
                return(ColorBgra.Transparent);
            }

            float u = x;
            float v = y;

            if (u < 0)
            {
                u = 0;
            }
            else if (u > src.Width - 1)
            {
                u = src.Width - 1;
            }

            if (v < 0)
            {
                v = 0;
            }
            else if (v > src.Height - 1)
            {
                v = src.Height - 1;
            }

            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;
                int sy    = iv;
                int sleft = sx;
                int sright;

                if (sleft == (src.Width - 1))
                {
                    sright = sleft;
                }
                else
                {
                    sright = sleft + 1;
                }

                int stop = sy;
                int sbottom;

                if (stop == (src.Height - 1))
                {
                    sbottom = stop;
                }
                else
                {
                    sbottom = stop + 1;
                }

                ColorBgra *cul = src.GetPointAddress(sleft, stop);
                ColorBgra *cur = cul + (sright - sleft);
                ColorBgra *cll = src.GetPointAddress(sleft, sbottom);
                ColorBgra *clr = cll + (sright - sleft);

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