コード例 #1
0
ファイル: RenderBuffer.cs プロジェクト: dotnet/wpf-test
        private Color GetToleranceSample(Point point, double radius)
        {
            // pixelCenter is factored into this point

            Rect sampleBounds = new Rect(point.X - radius, point.Y - radius, radius * 2, radius * 2);

            sampleBounds = MathEx.InflateToIntegerBounds(sampleBounds);
            List <Color?> colors = new List <Color?>();

            // Get pixel centers enclosed by the circle
            for (int y = (int)sampleBounds.Top; y < sampleBounds.Bottom; y++)
            {
                for (int x = (int)sampleBounds.Left; x < sampleBounds.Right; x++)
                {
                    Point center = new Point(x + Const.pixelCenterX, y + Const.pixelCenterY);
                    Color?color  = SafeGetPixel(x, y);
                    if (color.HasValue)
                    {
                        colors.Add(toleranceBuffer[x, y]);
                    }
                    else
                    {
                        colors.Add(Color.FromArgb(255, 255, 255, 255));
                    }
                }
            }
            Color?result = MathEx.Average(colors);

            if (result.HasValue)
            {
                return(result.Value);
            }
            return(RenderTolerance.DefaultColorTolerance);
        }
コード例 #2
0
ファイル: RenderBuffer.cs プロジェクト: dotnet/wpf-test
        /// <summary>
        /// Create a new RenderBuffer that has 4X blend per pixel
        /// </summary>
        /// <returns>A copy of the current RenderBuffer that is 1/4 of the original size</returns>
        public RenderBuffer DownSample4X()
        {
            RenderBuffer copy = new RenderBuffer(this.width / 2, this.height / 2);

            for (int y = 0; y < height; y += 2)
            {
                for (int x = 0; x < width; x += 2)
                {
                    int copyX = x / 2;
                    int copyY = y / 2;

                    // Blend the Color, Tolerance and Z values by doing a 4-way average
                    copy.frameBuffer[copyX, copyY] = MathEx.Average(
                        frameBuffer[x, y],
                        frameBuffer[x, y + 1],
                        frameBuffer[x + 1, y],
                        frameBuffer[x + 1, y + 1]
                        );
                    copy.toleranceBuffer[copyX, copyY] = MathEx.Average(
                        toleranceBuffer[x, y],
                        toleranceBuffer[x, y + 1],
                        toleranceBuffer[x + 1, y],
                        toleranceBuffer[x + 1, y + 1]
                        );
                    copy.zBuffer[copyX, copyY] = MathEx.Average(
                        zBuffer[x, y],
                        zBuffer[x, y + 1],
                        zBuffer[x + 1, y],
                        zBuffer[x + 1, y + 1]
                        );
                }
            }

            return(copy);
        }
コード例 #3
0
ファイル: BoundingBoxMathTT.cs プロジェクト: sizzles/ecsharp
 public static void Inflate(this BoundingBox self, T amountX, T amountY)
 {
     if (amountX < 0 && -amountX * 2 >= self.Width())
     {
         self.SetXAndWidth(MathEx.Average(self.X1, self.X2), 0);
     }
     else
     {
         self.SetXRange(self.X1 - amountX, self.X2 + amountX);
     }
     if (amountY < 0 && -amountY * 2 >= self.Height())
     {
         self.SetYAndHeight(MathEx.Average(self.Y1, self.Y2), 0);
     }
     else
     {
         self.SetYRange(self.Y1 - amountY, self.Y2 + amountY);
     }
 }
コード例 #4
0
ファイル: BoundingBox.cs プロジェクト: sizzles/ecsharp
        public static void Inflate <T>(this BoundingBox <T> self, T amountX, T amountY) where T : IConvertible, IComparable <T>, IEquatable <T>
        {
            var m = Maths <T> .SignedMath;

            if (amountX.CompareTo(m.Zero) < 0 && m.Shl(m.Negate(amountX), 1).CompareTo(self.Width) >= 0)
            {
                self.SetXAndWidth(MathEx.Average(self.X1, self.X2), m.Zero);
            }
            else
            {
                self.SetXRange(m.Sub(self.X1, amountX), m.Add(self.X2, amountX));
            }
            if (amountY.CompareTo(m.Zero) < 0 && m.Shl(m.Negate(amountY), 1).CompareTo(self.Width) >= 0)
            {
                self.SetYAndHeight(MathEx.Average(self.Y1, self.Y2), m.Zero);
            }
            else
            {
                self.SetYRange(m.Sub(self.Y1, amountY), m.Add(self.Y2, amountY));
            }
        }
コード例 #5
0
ファイル: RenderBuffer.cs プロジェクト: dotnet/wpf-test
        /// <summary>
        /// Get a Color representing the average color of a sample defined by the
        /// rectangle centered at "point" with a width and height of "radius" * 2.
        /// </summary>
        private Color?GetPixelSample(Point point, double radius)
        {
            // pixelCenter is factored into this point

            Rect sampleBounds = new Rect(point.X - radius, point.Y - radius, radius * 2, radius * 2);

            sampleBounds = MathEx.InflateToIntegerBounds(sampleBounds);
            List <Color?> colors = new List <Color?>();

            // Get pixel centers enclosed by the circle
            for (int y = (int)sampleBounds.Top; y < sampleBounds.Bottom; y++)
            {
                for (int x = (int)sampleBounds.Left; x < sampleBounds.Right; x++)
                {
                    Point center = new Point(x + Const.pixelCenterX, y + Const.pixelCenterY);
                    colors.Add(SafeGetPixel(x, y));
                }
            }
            if (colors.Count == 0)
            {
                return(null);
            }
            return(MathEx.Average(colors));
        }
コード例 #6
0
ファイル: BoundingBoxMathTT.cs プロジェクト: sizzles/ecsharp
 public static Point <T> Center(this BoundingBox <T> self)
 {
     return(new Point <T>(MathEx.Average(self.X1, self.X2), MathEx.Average(self.Y1, self.Y2)));
 }
コード例 #7
0
ファイル: BoundingBox.cs プロジェクト: sizzles/ecsharp
 public static Point <T> Center <T>(this BoundingBox <T> self) where T : IConvertible, IComparable <T>, IEquatable <T>
 {
     return(new Point <T>(MathEx.Average(self.X1, self.X2), MathEx.Average(self.Y1, self.Y2)));
 }