Пример #1
0
        private static void scanUpBelowPixelsRegionBackward(ref int xLeft, ref int xRight, ref int baseY, ref int maxY, ref PointsRegion pointsRegion,
                                                            ref Color32[] colors, ref bool[] persistentBorder, ref Color32 seedColor, ref Queue queue, bool[,] resultRegion, ref int width)
        {
            __newPointsRegion = new PointsRegion();

            __yy = baseY - pointsRegion.direction;
            if (__yy >= 0 && __yy < maxY)
            {
                __prevPixelSeed = false;
                for (__xx = xLeft; __xx <= xRight; __xx++)
                {
                    i32 = __yy * width + __xx;
                    if (resultRegion[__xx, __yy] != true &&
                        (!persistentBorder[i32] && // is pixel seed start
                         ((colors[i32].a < 255) ||
                          (seedColor.r == colors[i32].r &&
                           seedColor.g == colors[i32].g &&
                           seedColor.b == colors[i32].b &&
                           seedColor.a == colors[i32].a)))             //is pixel seed end
                        )
                    {
                        if (!__prevPixelSeed)
                        {
                            __newPointsRegion.direction = -pointsRegion.direction;
                            __newPointsRegion.y         = __yy;
                            __newPointsRegion.xLeft     = __xx;
                            __prevPixelSeed             = true;
                        }
                    }
                    else
                    {
                        if (__prevPixelSeed)
                        {
                            __newPointsRegion.xRight = __xx - 1;
                            __prevPixelSeed          = false;
                            queue.Enqueue(__newPointsRegion);
                        }
                    }
                }

                if (__prevPixelSeed)
                {
                    __newPointsRegion.xRight = xRight;
                    queue.Enqueue(__newPointsRegion);
                }
            }
        }
Пример #2
0
        public static bool[,] floodFillLineGetRegion(Vector2 point, Color32[] colors, bool[] persistentLayer, int width, int height)
        {
            //go to left and to the right
            // if down pixel vector has border get righ pixel to bottomQueue
            // if upper pixel has unvisited node


            if (resultBoolRegion == null || resultBoolRegion.GetLongLength(0) != width || resultBoolRegion.GetLength(1) != height)
            {
                resultBoolRegion = new bool[width, height];
            }
            else
            {
                for (int i = 0; i < width; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        resultBoolRegion[i, j] = false;
                    }
                }
            }

            Color32      seedColor = colors[(int)((point.y * width) + point.x)];
            PointsRegion initial   = new PointsRegion();

            initial.xLeft     = (int)point.x;
            initial.xRight    = (int)point.x;
            initial.y         = (int)point.y;
            initial.direction = 1;

            Queue queue = new Queue();

            queue.Enqueue(initial);

            scanLeftPixelsForBound(colors, ref seedColor, persistentLayer, ref initial, ref width);
            scanRightPixelsForBound(width, colors, ref seedColor, persistentLayer, ref initial, ref width);

            scanUpBelowPixelsRegionBackward(ref initial.xLeft, ref initial.xRight, ref initial.y, ref height, ref initial,
                                            ref colors, ref persistentLayer, ref seedColor, ref queue, resultBoolRegion, ref width);


            while (queue.Count > 0)
            {
                PointsRegion pointsRegion = (PointsRegion)queue.Dequeue();

                if (isPointsRegionVisited(pointsRegion, resultBoolRegion))
                {
                    continue;
                }


                originalXLeft = pointsRegion.xLeft - 1;
                scanLeftPixelsForBound(colors, ref seedColor, persistentLayer, ref pointsRegion, ref width);
                if (originalXLeft > pointsRegion.xLeft)
                {
                    scanUpBelowPixelsRegionBackward(ref pointsRegion.xLeft, ref originalXLeft, ref pointsRegion.y, ref height, ref pointsRegion,
                                                    ref colors, ref persistentLayer, ref seedColor, ref queue, resultBoolRegion, ref width);
                }

                originalXRigth = pointsRegion.xRight + 1;
                scanRightPixelsForBound(width, colors, ref seedColor, persistentLayer, ref pointsRegion, ref width);
                if (originalXRigth < pointsRegion.xRight)
                {
                    scanUpBelowPixelsRegionBackward(ref originalXRigth, ref pointsRegion.xRight, ref pointsRegion.y, ref height, ref pointsRegion,
                                                    ref colors, ref persistentLayer, ref seedColor, ref queue, resultBoolRegion, ref width);
                }

                for (int xx = pointsRegion.xLeft; xx <= pointsRegion.xRight; xx++)
                {
                    resultBoolRegion[xx, pointsRegion.y] = true;
                }

                // 2. get DownPixel  -this is not exactly down pixel (it depends of direction)
                scanUpBelowPixelsRegionForward(ref pointsRegion.xLeft, ref pointsRegion.xRight, ref pointsRegion.y, ref height, ref pointsRegion,
                                               ref colors, ref persistentLayer, ref seedColor, ref queue, resultBoolRegion, ref width);
            }


            return(resultBoolRegion);
        }
Пример #3
0
 static bool isPointsRegionVisited(PointsRegion pointsRegion, bool[,] resultBoolRegion)
 {
     return(resultBoolRegion[pointsRegion.xLeft, pointsRegion.y]);
 }
Пример #4
0
 static void scanLeftPixelsForBound(Color32[] colors, ref Color32 seedColor, bool[] persistentLayer, ref PointsRegion pointsRegion, ref int width)
 {
     for (int xx = pointsRegion.xLeft; xx >= 0; xx--)
     {
         if (isPixelSeed(ref xx, ref pointsRegion.y, ref seedColor, ref colors, ref persistentLayer, ref width))
         {
             pointsRegion.xLeft = xx;
         }
         else
         {
             break;
         }
     }
 }
Пример #5
0
 static void scanRightPixelsForBound(int workspaceWidth, Color32[] colors, ref Color32 seedColor, bool[] persistentLayer, ref PointsRegion pointsRegion, ref int width)
 {
     for (int xx = pointsRegion.xRight; xx < workspaceWidth; xx++)
     {
         if (isPixelSeed(ref xx, ref pointsRegion.y, ref seedColor, ref colors, ref persistentLayer, ref width))
         {
             pointsRegion.xRight = xx;
         }
         else
         {
             break;
         }
     }
 }
Пример #6
0
    private static void scanUpBelowPixelsRegionForward(ref int xLeft, ref int xRight, ref int baseY, ref int maxY, ref PointsRegion pointsRegion, 
							ref Color32[] colors, ref bool[] persistentBorder, ref Color32 seedColor, ref Queue queue, bool[,] resultRegion, ref int width)
    {
        __newPointsRegion = new PointsRegion ();

        __yy = baseY + pointsRegion.direction;
        if (__yy >= 0 && __yy < maxY) {
            __prevPixelSeed = false;
            for (__xx = xLeft; __xx<=xRight; __xx++) {
                i31 = __yy *width + __xx;
                if (resultRegion [__xx, __yy] != true
                    && (!persistentBorder [i31] //is pixel seed start
                        && ((colors [i31].a < 255)
                             || (   seedColor.r == colors[i31].r
                             && seedColor.g == colors[i31].g
                             && seedColor.b == colors[i31].b
                             && seedColor.a == colors[i31].a))) //is pixel seed end

                    ) {
                    if (!__prevPixelSeed) {
                        __newPointsRegion.direction = pointsRegion.direction         ;
                        __newPointsRegion.y         = __yy                ;
                        __newPointsRegion.xLeft     = __xx                ;
                        __prevPixelSeed             = true              ;
                    }
                } else {
                    if (__prevPixelSeed) {
                        __newPointsRegion.xRight  = __xx-1;
                        __prevPixelSeed = false;
                        queue.Enqueue (__newPointsRegion);
                    }
                }
            }
            if(__prevPixelSeed){
                __newPointsRegion.xRight = xRight;
                queue.Enqueue(__newPointsRegion);
            }
        }
    }
Пример #7
0
 static void scanRightPixelsForBound(int workspaceWidth, Color32[] colors,ref Color32 seedColor, bool[] persistentLayer, ref PointsRegion pointsRegion, ref int width)
 {
     for (int xx=pointsRegion.xRight; xx<workspaceWidth; xx++) {
         if (isPixelSeed (ref xx, ref pointsRegion.y,ref seedColor, ref colors, ref persistentLayer, ref width)) {
             pointsRegion.xRight = xx;
         } else {
             break;
         }
     }
 }
Пример #8
0
    static void scanLeftPixelsForBound(Color32[] colors,ref Color32 seedColor, bool[] persistentLayer, ref PointsRegion pointsRegion, ref int width)
    {
        for (int xx=pointsRegion.xLeft; xx>=0; xx--) {
            if (isPixelSeed (ref xx, ref pointsRegion.y,ref seedColor, ref colors, ref persistentLayer, ref width)) {
                pointsRegion.xLeft = xx;
            } else {
                break;
            }

        }
    }
Пример #9
0
 static bool isPointsRegionVisited(PointsRegion pointsRegion, bool[,] resultBoolRegion)
 {
     return resultBoolRegion [pointsRegion.xLeft, pointsRegion.y];
 }
Пример #10
0
    public static bool[,] floodFillLineGetRegion(IntVector2 point, Color32[] colors, bool[] persistentLayer, int width, int height)
    {
        //go to left and to the right
        // if down pixel vector has border get righ pixel to bottomQueue
        // if upper pixel has unvisited node

        if (resultBoolRegion == null || resultBoolRegion.GetLongLength(0) != width || resultBoolRegion.GetLength(1) != height){
            resultBoolRegion = new bool[width, height];
        } else {
            for (int i = 0; i < width; i++) {
                for (int j = 0; j < height; j++) {
                    resultBoolRegion[i,j] = false;
                }
            }
        }

        Color32 seedColor = colors[point.y * width + point.x];
        PointsRegion initial = new PointsRegion ();
        initial.xLeft = point.x;
        initial.xRight = point.x;
        initial.y = point.y;
        initial.direction = 1;

        Queue queue = new Queue ();
        queue.Enqueue (initial);

        scanLeftPixelsForBound (colors,ref seedColor, persistentLayer, ref initial, ref width);
        scanRightPixelsForBound (width, colors,ref seedColor, persistentLayer, ref initial, ref width);

        scanUpBelowPixelsRegionBackward (ref initial.xLeft, ref initial.xRight, ref initial.y, ref height, ref initial,
                                 ref colors, ref persistentLayer, ref seedColor, ref queue, resultBoolRegion, ref width);

        while (queue.Count>0) {
            PointsRegion pointsRegion = (PointsRegion)queue.Dequeue ();

            if (isPointsRegionVisited (pointsRegion, resultBoolRegion))
                continue;

            originalXLeft = pointsRegion.xLeft - 1;
            scanLeftPixelsForBound (colors, ref seedColor, persistentLayer, ref pointsRegion, ref width);
            if (originalXLeft > pointsRegion.xLeft)
                scanUpBelowPixelsRegionBackward (ref pointsRegion.xLeft, ref originalXLeft, ref pointsRegion.y, ref height, ref pointsRegion,
                                         ref colors, ref persistentLayer, ref seedColor, ref queue, resultBoolRegion, ref width);

            originalXRigth = pointsRegion.xRight+1;
            scanRightPixelsForBound (width, colors,ref seedColor, persistentLayer, ref pointsRegion, ref width);
            if (originalXRigth < pointsRegion.xRight)
                scanUpBelowPixelsRegionBackward (ref originalXRigth, ref pointsRegion.xRight, ref pointsRegion.y, ref height, ref pointsRegion,
                                         ref colors, ref persistentLayer, ref seedColor, ref queue, resultBoolRegion, ref width);

            for (int xx=pointsRegion.xLeft; xx<=pointsRegion.xRight; xx++) {
                resultBoolRegion [xx, pointsRegion.y] = true;
            }

            // 2. get DownPixel  -this is not exactly down pixel (it depends of direction)
            scanUpBelowPixelsRegionForward (ref pointsRegion.xLeft, ref pointsRegion.xRight, ref pointsRegion.y, ref height, ref pointsRegion,
                                     ref colors, ref persistentLayer, ref seedColor, ref queue, resultBoolRegion, ref width);
        }

        return resultBoolRegion;
    }