Esempio n. 1
0
    private void GenerateInner(PixelsInfo pixels, byte[] lineRaw, ref int smallBox)
    {
        int mx  = 0;
        int my  = 0;
        int box = 0;

        int[,] dp = new int[pixels.row, pixels.col];
        for (int i = 0; i < pixels.row; ++i)
        {
            for (int j = 0; j < pixels.col; ++j)
            {
                int o = pixels.x + i + (pixels.y + j) * width;
                if (CheckList(pixels.pixelsId, o))
                {
                    if (i == 0 || j == 0)
                    {
                        dp[i, j] = 1;
                    }
                    else
                    {
                        dp[i, j] = Mathf.Min(dp[i - 1, j - 1], Math.Min(dp[i - 1, j], dp[i, j - 1])) + 1;
                    }
                    if (dp[i, j] > box)
                    {
                        mx  = pixels.x + i;
                        my  = pixels.y + j;
                        box = dp[i, j];
                    }
                }
            }
        }
        if (box > minBox)
        {
            ZoneInfo zi = new ZoneInfo();
            zi.zoneId = zoneCount;
            ++zoneCount;
            zi.x = mx - box / 2;
            zi.y = height - (my - box / 2);
            float bound = (float)box / 1.5f == 0 ? 1 : (float)box / 1.5f;
            zi.size        = bound > 100 ? 100 : (int)bound;
            zi.sketchColor = pixels.clr;
            zi.pixels      = pixels.pixels;
            if (!sketchList.Contains(zi.sketchColor))
            {
                sketchList.Add(zi.sketchColor);
            }
            zoneList.Add(zi);
        }
        else
        {
            foreach (var p in pixels.pixels)
            {
                SetColor(lineRaw, p * 4, 0, 0, 0, 255);
            }
            smallBox++;
        }
    }
Esempio n. 2
0
        private MonitorUtils(Common.WindowWrapper windowWrapper)
        {
            var di = windowWrapper.DisplayInformation();
            di.OrientationChanged += new Common.WeakReference<MonitorUtils, DisplayInformation, object>(this)
            {
                EventAction = (i, s, e) => Changed?.Invoke(i, EventArgs.Empty),
                DetachAction = (i, w) => di.OrientationChanged -= w.Handler
            }.Handler;

            var av = windowWrapper.ApplicationView();
            av.VisibleBoundsChanged += new Common.WeakReference<MonitorUtils, ApplicationView, object>(this)
            {
                EventAction = (i, s, e) => Changed?.Invoke(i, EventArgs.Empty),
                DetachAction = (i, w) => av.VisibleBoundsChanged -= w.Handler
            }.Handler;

            Inches = new InchesInfo(windowWrapper);
            Pixels = new PixelsInfo(windowWrapper);
        }
Esempio n. 3
0
        private MonitorUtils(Common.WindowWrapper windowWrapper)
        {
            var di = windowWrapper.DisplayInformation();
            di.OrientationChanged += new Common.WeakReference<MonitorUtils, DisplayInformation, object>(this)
            {
                EventAction = (i, s, e) => Changed?.Invoke(i, EventArgs.Empty),
                DetachAction = (i, w) => di.OrientationChanged -= w.Handler
            }.Handler;

            var av = windowWrapper.ApplicationView();
            av.VisibleBoundsChanged += new Common.WeakReference<MonitorUtils, ApplicationView, object>(this)
            {
                EventAction = (i, s, e) => Changed?.Invoke(i, EventArgs.Empty),
                DetachAction = (i, w) => av.VisibleBoundsChanged -= w.Handler
            }.Handler;

            Inches = new InchesInfo(windowWrapper);
            Pixels = new PixelsInfo(windowWrapper);
        }
Esempio n. 4
0
    private void FloodFillNew(int x, int y, byte[] lineRaw, ref int smallPixels)
    {
        int         offset    = width * y + x;
        byte        r         = lineRaw[4 * offset + 1];
        byte        g         = lineRaw[4 * offset + 2];
        byte        b         = lineRaw[4 * offset + 3];
        Queue <int> queue     = new Queue <int>();
        Queue <int> queue2    = new Queue <int>();
        List <int>  tmpPixels = new List <int>();

        queue.Enqueue(x);
        queue2.Enqueue(y);
        int count = 0;
        int mark  = 138;
        int maxX  = 0;
        int minX  = int.MaxValue;
        int maxY  = 0;
        int minY  = int.MaxValue;

        while (queue.Count > 0)
        {
            int num  = queue.Dequeue();
            int num2 = queue2.Dequeue();
            if (num2 - 1 > -1)
            {
                int num3 = width * (num2 - 1) + num;
                int num4 = num3 * 4;
                if (CheckColor(lineRaw, num4, r, g, b) && GetAlpha(lineRaw, num4) == 255)
                {
                    queue.Enqueue(num);
                    queue2.Enqueue(num2 - 1);
                    ++count;
                    tmpPixels.Add(num3);
                    lineRaw[num4] = (byte)mark;
                    if (num > maxX)
                    {
                        maxX = num;
                    }
                    if (num < minX)
                    {
                        minX = num;
                    }
                    if (num2 - 1 > maxY)
                    {
                        maxY = num2 - 1;
                    }
                    if (num2 - 1 < minY)
                    {
                        minY = num2 - 1;
                    }
                }
            }
            if (num + 1 < width)
            {
                int num3 = width * num2 + (num + 1);
                int num4 = num3 * 4;
                if (CheckColor(lineRaw, num4, r, g, b) && GetAlpha(lineRaw, num4) == 255)
                {
                    queue.Enqueue(num + 1);
                    queue2.Enqueue(num2);
                    ++count;
                    tmpPixels.Add(num3);
                    lineRaw[num4] = (byte)mark;
                    if (num + 1 > maxX)
                    {
                        maxX = num;
                    }
                    if (num + 1 < minX)
                    {
                        minX = num;
                    }
                    if (num2 > maxY)
                    {
                        maxY = num2 - 1;
                    }
                    if (num2 < minY)
                    {
                        minY = num2 - 1;
                    }
                }
            }
            if (num - 1 > -1)
            {
                int num3 = width * num2 + (num - 1);
                int num4 = num3 * 4;
                if (CheckColor(lineRaw, num4, r, g, b) && GetAlpha(lineRaw, num4) == 255)
                {
                    queue.Enqueue(num - 1);
                    queue2.Enqueue(num2);
                    ++count;
                    tmpPixels.Add(num3);
                    lineRaw[num4] = (byte)mark;
                    if (num - 1 > maxX)
                    {
                        maxX = num;
                    }
                    if (num - 1 < minX)
                    {
                        minX = num;
                    }
                    if (num2 > maxY)
                    {
                        maxY = num2 - 1;
                    }
                    if (num2 < minY)
                    {
                        minY = num2 - 1;
                    }
                }
            }
            if (num2 + 1 < height)
            {
                int num3 = width * (num2 + 1) + num;
                int num4 = num3 * 4;
                if (CheckColor(lineRaw, num4, r, g, b) && GetAlpha(lineRaw, num4) == 255)
                {
                    queue.Enqueue(num);
                    queue2.Enqueue(num2 + 1);
                    ++count;
                    tmpPixels.Add(num3);
                    lineRaw[num4] = (byte)mark;
                    if (num > maxX)
                    {
                        maxX = num;
                    }
                    if (num < minX)
                    {
                        minX = num;
                    }
                    if (num2 + 1 > maxY)
                    {
                        maxY = num2 - 1;
                    }
                    if (num2 + 1 < minY)
                    {
                        minY = num2 - 1;
                    }
                }
            }
        }
        if (count > minPixels)
        {
            var clr = new Color32(r, g, b, 255);
            var pi  = new PixelsInfo();
            pi.clr      = clr;
            pi.pixels   = tmpPixels;
            pi.pixelsId = pixelsIdCount;
            pixelsList.Add(pi);
            pixelsIdCount++;
            pi.x   = minX;
            pi.y   = minY;
            pi.row = maxX - minX;
            pi.col = maxY - minY;
            foreach (var p in tmpPixels)
            {
                queryList[p] = pi.pixelsId;
            }
        }
        else
        {
            smallPixels++;
            foreach (var p in tmpPixels)
            {
                SetColor(lineRaw, p * 4, 0, 0, 0, 255);
            }
        }
    }