示例#1
0
        public static ColorBgra GetColor(DistortionEffectProperties[] props, int x, int y, Surface src, ColorBgra bgra)
        {
            float offsetX  = 0;
            float offsetY  = 0;
            int   radius   = int.MaxValue;
            int   selected = 0;

            for (int i = 0; i < props.Length; ++i)
            {
                float u = x - props[i].Center.X;
                float v = y - props[i].Center.Y;
                int   r = (int)Math.Sqrt(u * u + v * v);
                if (r < radius)
                {
                    offsetX  = u;
                    offsetY  = v;
                    radius   = r;
                    selected = i;
                }
            }

            DistortionEffectProperties selectedProps = props[selected];

            if (radius > 0 && radius < selectedProps.MaxRadius)
            {
                float scaleX = (float)selectedProps.TransferCurves[0][radius] / radius;
                float scaleY = (float)selectedProps.TransferCurves[1][radius] / radius;
                float xp     = offsetX * scaleX;
                float yp     = offsetY * scaleY;
                bgra = src.GetBilinearSampleClamped(selectedProps.Center.X + xp, selectedProps.Center.Y + yp);
            }
            return(bgra);
        }
示例#2
0
        public static ColorBgra GetColor(DistortionEffectProperties props, int x, int y, Surface src, ColorBgra bgra)
        {
            float u      = x - props.Center.X;
            float v      = y - props.Center.Y;
            int   radius = (int)Math.Sqrt(u * u + v * v);

            if (radius > 0 && radius < props.MaxRadius)
            {
                float scaleX = (float)props.TransferCurves[0][radius] / radius;
                float scaleY = (float)props.TransferCurves[1][radius] / radius;
                float xp     = u * scaleX;
                float yp     = v * scaleY;
                bgra = src.GetBilinearSampleClamped(props.Center.X + xp, props.Center.Y + yp);
            }
            return(bgra);
        }
示例#3
0
        protected override void OnSetRenderInfo(DistortionEffectConfigTokens newTokens, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            Surface src       = srcArgs.Surface;
            int     wdiv2     = src.Width / 2;
            int     hdiv2     = src.Height / 2;
            int     maxRadius = Math.Min(wdiv2, hdiv2);

            for (int i = 0; i < newTokens.SubTokens.Length; ++i)
            {
                DistortionEffectConfigToken token = newTokens.SubTokens[i];
                DistortionEffectProperties  props = Props[i];
                props.MaxRadius      = (int)(maxRadius * token.ValueR);
                props.TransferCurves = token.GetTransferCurves(new int[] { props.MaxRadius, props.MaxRadius }, new float[] { props.MaxRadius, props.MaxRadius });
                props.Center         = new PointF(wdiv2 + (float)token.ValueX * wdiv2, hdiv2 + (float)token.ValueY * hdiv2);
            }
        }