Пример #1
0
    public static void BlurVertically()
    {
        if (width > 0 && height > 0)
        {
            if (tempData.Length < total)
            {
                tempData = new byte[total];
            }

            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    var a = GetDefault(x, y - 1);
                    var b = GetDefault(x, y);
                    var c = GetDefault(x, y + 1);
                    var t = (int)a + (int)b + (int)c;

                    tempData[x + y * width] = (byte)(t / 3);
                }
            }

            D2D_Helper.Swap(ref data, ref tempData);
        }
    }
Пример #2
0
    public static void Resize(int newWidth, int newHeight)
    {
        if (newWidth >= 0 && newHeight >= 0 && width > 0 && height > 0)
        {
            var newTotal = newWidth * newHeight;

            if (tempData.Length < newTotal)
            {
                tempData = new byte[newTotal];
            }

            var w = (float)(newWidth - 1);
            var h = (float)(newHeight - 1);

            for (var y = 0; y < newHeight; y++)
            {
                for (var x = 0; x < newWidth; x++)
                {
                    tempData[x + y * newWidth] = GetBilinear((float)x / w, (float)y / h);
                }
            }

            width  = newWidth;
            height = newHeight;
            total  = newTotal;

            D2D_Helper.Swap(ref data, ref tempData);
        }
    }
Пример #3
0
    public static void Halve()
    {
        if (width > 0 && height > 0)
        {
            var newWidth  = width / 2;
            var newHeight = height / 2;

            if (newWidth >= 0 && newHeight >= 0)
            {
                var newTotal = newWidth * newHeight;

                if (tempData.Length < newTotal)
                {
                    tempData = new byte[newTotal];
                }

                for (var y = 0; y < newHeight; y++)
                {
                    var y0 = y * 2;
                    var y1 = y0 + 1;

                    for (var x = 0; x < newWidth; x++)
                    {
                        var x0 = x * 2;
                        var x1 = x0 + 1;

                        var a = GetClamp(x0, y0);
                        var b = GetClamp(x1, y0);
                        var c = GetClamp(x0, y1);
                        var d = GetClamp(x1, y1);
                        var t = (int)a + (int)b + (int)c + (int)d;

                        tempData[x + y * newWidth] = (byte)(t / 4);
                    }
                }

                width  = newWidth;
                height = newHeight;
                total  = newTotal;

                D2D_Helper.Swap(ref data, ref tempData);
            }
        }
    }
Пример #4
0
    public void AddTriangle(D2D_Point a, D2D_Point b, D2D_Point c)
    {
        if (a.Y != b.Y || a.Y != c.Y)
        {
            // Make a highest, and c lowest
            if (b.Y > a.Y)
            {
                D2D_Helper.Swap(ref a, ref b);
            }
            if (c.Y > a.Y)
            {
                D2D_Helper.Swap(ref c, ref a);
            }
            if (c.Y > b.Y)
            {
                D2D_Helper.Swap(ref b, ref c);
            }

            var fth = a.Y - c.Y;             // Full triangle height
            var tth = a.Y - b.Y;             // Top triangle height
            var bth = b.Y - c.Y;             // Bottom triangle height

            // Find a to c intercept along b plane
            var inx = c.X + (a.X - c.X) * D2D_Helper.Divide(bth, fth);
            var d   = new D2D_Point((int)inx, b.Y);

            // Top triangle
            var abs = D2D_Helper.Divide(a.X - b.X, tth);             // A/B slope
            var ads = D2D_Helper.Divide(a.X - d.X, tth);             // A/D slope

            AddTriangle(b.X, d.X, abs, ads, b.Y, 1, tth);

            // Bottom triangle
            var cbs = D2D_Helper.Divide(c.X - b.X, bth);             // C/B slope
            var cds = D2D_Helper.Divide(c.X - d.X, bth);             // C/D slope

            AddTriangle(b.X, d.X, cbs, cds, b.Y, -1, bth);
        }
    }
Пример #5
0
    public void AddTriangle(float l, float r, float ls, float rs, int y, int s, int c)     // left x, right x, left slope, right slope, y, sign, count
    {
        if (l > r)
        {
            D2D_Helper.Swap(ref l, ref r);
            D2D_Helper.Swap(ref ls, ref rs);
        }

        for (var i = 0; i < c; i++)
        {
            var il = Mathf.FloorToInt(l);
            var ir = Mathf.CeilToInt(r);

            for (var x = il; x < ir; x++)
            {
                AddPixel(x, y);
            }

            y += s;
            l += ls;
            r += rs;
        }
    }