예제 #1
0
        /// <summary>
        /// Copies a source image into a destination image using the specified masking image.
        /// Only pixels in the source image whose corresponding mask image pixels are > 0
        /// are copied to the destination image. Only pixels from the srcRect are copied
        /// to the destination rect.
        /// </summary>
        /// <param name="srcImage">Source image</param>
        /// <param name="srcRect">Source rectangle to copy from</param>
        /// <param name="dstImage">Destination image</param>
        /// <param name="dstRect">Destunatuin rectangle to copy to</param>
        public static void CopyTo(this Image srcImage, Rectangle srcRect, Image dstImage, Rectangle dstRect)
        {
            if (srcImage.Width != dstImage.Width || srcImage.Height != dstImage.Height)
            {
                throw new System.Exception("Source and destination images must be the same size");
            }

            srcImage.CopyTo(srcRect, dstImage, dstRect, null);
        }
예제 #2
0
        /// <summary>
        /// Copies a source image into a destination image using the specified masking image.
        /// Only pixels in the source image whose corresponding mask image pixels are > 0
        /// are copied to the destination image.
        /// </summary>
        /// <param name="srcImage">Source image</param>
        /// <param name="dstImage">Destination image</param>
        /// <param name="maskImage">Masking image</param>
        public static void CopyTo(this Image srcImage, Image dstImage, Image maskImage)
        {
            if (srcImage.Width != dstImage.Width || srcImage.Height != dstImage.Height)
            {
                throw new System.Exception("Source and destination images must be the same size");
            }

            Rectangle srcRect = new Rectangle(0, 0, srcImage.Width - 1, srcImage.Height - 1);
            Rectangle dstRect = new Rectangle(0, 0, dstImage.Width - 1, dstImage.Height - 1);

            srcImage.CopyTo(srcRect, dstImage, dstRect, maskImage);
        }
예제 #3
0
        /// <summary>
        /// Common code shared by the average color tests.
        /// </summary>
        /// <param name="format">The format in which to perform the test.</param>
        private static void AverageSolidColorTestRunner(PixelFormat format)
        {
            var shared = ImagePool.GetOrCreate(SolidColorImage.Width, SolidColorImage.Height, format);
            var image  = shared.Resource;

            SolidColorImage.CopyTo(image);
            var results = new Dictionary <System.Drawing.Rectangle, Color>();

            using (var pipeline = Pipeline.Create())
            {
                var source = Generators.Sequence(
                    pipeline,
                    SolidColorAverages.Keys.Select(rect => (rect, image.AverageColor(rect.Left, rect.Top, rect.Width, rect.Height))),
                    TimeSpan.FromTicks(1))
                             .Do(r =>
                {
                    (var rect, var color) = r;

                    // Simply store the resulting value and compare it later at the bottom of this method.
                    results[rect] = color;
                });
                pipeline.Run(new ReplayDescriptor(DateTime.UtcNow, DateTime.MaxValue));
            }

            foreach (var expectation in SolidColorAverages)
            {
                var expectedColor = expectation.Value;
                var returnedColor = results[expectation.Key];

                // Compensate for grayscale formats.
                if (format == PixelFormat.Gray_16bpp || format == PixelFormat.Gray_8bpp)
                {
                    var gray = Microsoft.Psi.Imaging.Operators.Rgb2Gray(expectedColor.R, expectedColor.G, expectedColor.B);
                    expectedColor = Color.FromArgb((int)gray, (int)gray, (int)gray);
                }

                // Assert.AreEqual(expectedColor, returnedColor, $"Region {expectation.Key}");
                Assert.AreEqual(expectedColor.R, returnedColor.R, 1, $"Average red channel for solid color test region {expectation.Key}");
                Assert.AreEqual(expectedColor.G, returnedColor.G, 1, $"Average green channel for solid color test region {expectation.Key}");
                Assert.AreEqual(expectedColor.B, returnedColor.B, 1, $"Average blue channel for solid color test region {expectation.Key}");
            }
        }
예제 #4
0
 /// <summary>
 /// Copies the depth image from a specified source image of the same size and <see cref="PixelFormat.Gray_16bpp"/> format.
 /// </summary>
 /// <param name="source">Source image to copy the depth image from.</param>
 /// <remarks><para>The method copies the current depth image from the specified source image.
 /// The size of the images must be the same, and the source image must have <see cref="PixelFormat.Gray_16bpp"/> format.</para></remarks>
 public void CopyFrom(Image source)
 {
     source.CopyTo(this);
 }