Beispiel #1
0
    /// <summary>
    /// Perform blur.
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="z"></param>
    /// <returns></returns>
    public override double GetValue(double x, double y, double z)
    {
        // Bitshift the source module by 1 one so we can
        // "divide" each pixel into 4 quadrants
        var shifted = new BitShiftInput(this.Source0)
        {
            Amount = 1,
            Left   = false
        };

        var self   = shifted.GetValue(x, y, z);
        var values = new double[8]
        {
            self,     // weighted average filter
            self,     // center gets a higher weight
            self,
            self,
            shifted.GetValue(x, y, z + 1),
            shifted.GetValue(x, y, z - 1),
            shifted.GetValue(x + 1, y, z),
            shifted.GetValue(x - 1, y, z),
        };

        return(values.Average());
    }
Beispiel #2
0
    public override double GetValue(double x, double y, double z)
    {
        // Bitshift the source module by 1 one so we can
        // "divide" each pixel into 4 quadrants
        var shifted = new BitShiftInput(this.Source0)
        {
            Amount = 1,
            Left   = false
        };

        var center = shifted.GetValue(x, y, z);

        bool isRight = Math.Abs(x) % 2 != 0; // This is b/c C# doesn't modulo negatives correctly.
        bool isTop   = Math.Abs(z) % 2 != 0;

        // If this is the top right, and above and to the right are different but match each other, time to smooth
        if (isTop && isRight)
        {
            var top   = shifted.GetValue(x, y, z + 1);
            var right = shifted.GetValue(x + 1, y, z);
            return(top != center && top == right ? top : center);
        }

        if (!isTop && isRight)
        {
            var bottom = shifted.GetValue(x, y, z - 1);
            var right  = shifted.GetValue(x + 1, y, z);
            return(bottom != center && bottom == right ? bottom : center);
        }

        if (!isTop && !isRight)
        {
            var bottom = shifted.GetValue(x, y, z - 1);
            var left   = shifted.GetValue(x - 1, y, z);
            return(bottom != center && bottom == left ? bottom : center);
        }

        if (isTop && !isRight)
        {
            var top  = shifted.GetValue(x, y, z + 1);
            var left = shifted.GetValue(x - 1, y, z);
            return(top != center && top == left ? top : center);
        }

        // okay compiler, sure...
        return(center);
    }