예제 #1
0
 public void CompressRanges()
 {
     ClusterClearEffectPlugin.CompressRanges(Ranges);
 }
예제 #2
0
            public void Create(Point seed, Surface src, RectangleRef[] limits, ColorBgra color, float Tolerance, ClusterClearEffectPlugin controller, bool[,] safePoints)
            {
                Ranges.Clear();
                int xL = seed.X;

                while (xL >= 0 && ColorUtils.RGBPercentage(color, src[xL, seed.Y]) <= Tolerance)
                {
                    --xL;
                }
                ++xL;
                int xR   = seed.X + 1;
                int maxR = src.Width;

                while (xR < maxR && ColorUtils.RGBPercentage(color, src[xR, seed.Y]) <= Tolerance)
                {
                    ++xR;
                }
                --xR;
                Ranges.Add(new RectangleRef(xL, seed.Y, xR - xL + 1, 1));

                Stack <ScanRange> scanRanges = new Stack <ScanRange>();

                scanRanges.Push(new ScanRange(xL, xR, seed.Y, 1));
                scanRanges.Push(new ScanRange(xL, xR, seed.Y, -1));
                int       xMin = 0;
                int       xMax = src.Width - 1;
                int       yMin = 0;
                int       yMax = src.Height - 1;
                ScanRange r;
                int       sleft;
                int       sright;

                while (scanRanges.Count != 0)
                {
                    if (controller.IsCancelRequested)
                    {
                        return;
                    }
                    r = scanRanges.Pop();
                    //scan left
                    for (sleft = r.left - 1; sleft >= xMin && ColorUtils.RGBPercentage(color, src[sleft, r.y]) <= Tolerance; --sleft)
                    {
                        safePoints[sleft, r.y] = true;
                    }
                    ++sleft;

                    //scan right
                    for (sright = r.right + 1; sright <= xMax && ColorUtils.RGBPercentage(color, src[sright, r.y]) <= Tolerance; ++sright)
                    {
                        safePoints[sright, r.y] = true;
                    }
                    --sright;
                    Ranges.Add(new RectangleRef(sleft, r.y, sright - sleft, 1));

                    //scan in same direction vertically
                    bool rangeFound = false;
                    int  rangeStart = 0;
                    int  newy       = r.y + r.direction;
                    if (newy >= yMin && newy <= yMax)
                    {
                        xL = sleft;
                        while (xL <= sright)
                        {
                            for (; xL <= sright; ++xL)
                            {
                                if (ColorUtils.RGBPercentage(color, src[xL, newy]) <= Tolerance)
                                {
                                    safePoints[xL, newy] = true;
                                    rangeFound           = true;
                                    rangeStart           = xL++;
                                    break;
                                }
                            }
                            for (; xL <= sright; ++xL)
                            {
                                if (ColorUtils.RGBPercentage(color, src[xL, newy]) > Tolerance)
                                {
                                    break;
                                }
                                safePoints[xL, newy] = true;
                            }
                            if (rangeFound)
                            {
                                rangeFound = false;
                                scanRanges.Push(new ScanRange(rangeStart, xL - 1, newy, r.direction));
                            }
                        }
                    }

                    //scan opposite direction vertically
                    newy = r.y - r.direction;
                    if (newy >= yMin && newy <= yMax)
                    {
                        xL = sleft;
                        while (xL < r.left)
                        {
                            for (; xL < r.left; ++xL)
                            {
                                if (ColorUtils.RGBPercentage(color, src[xL, newy]) <= Tolerance)
                                {
                                    safePoints[xL, newy] = true;
                                    rangeFound           = true;
                                    rangeStart           = xL++;
                                    break;
                                }
                            }
                            for (; xL < r.left; ++xL)
                            {
                                if (ColorUtils.RGBPercentage(color, src[xL, newy]) > Tolerance)
                                {
                                    break;
                                }
                                safePoints[xL, newy] = true;
                            }
                            if (rangeFound)
                            {
                                rangeFound = false;
                                scanRanges.Push(new ScanRange(rangeStart, xL - 1, newy, -r.direction));
                            }
                        }
                        xL = r.right + 1;
                        while (xL <= sright)
                        {
                            for (; xL <= sright; ++xL)
                            {
                                if (ColorUtils.RGBPercentage(color, src[xL, newy]) <= Tolerance)
                                {
                                    safePoints[xL, newy] = true;
                                    rangeFound           = true;
                                    rangeStart           = xL++;
                                    break;
                                }
                            }
                            for (; xL <= sright; ++xL)
                            {
                                if (ColorUtils.RGBPercentage(color, src[xL, newy]) > Tolerance)
                                {
                                    break;
                                }
                                safePoints[xL, newy] = true;
                            }
                            if (rangeFound)
                            {
                                rangeFound = false;
                                scanRanges.Push(new ScanRange(rangeStart, xL - 1, newy, -r.direction));
                            }
                        }
                    }
                }
                CompressRanges();
            }