public void _1DarkBlueRect_2BlendHotPinkRect <TPixel>(
            TestImageProvider <TPixel> provider,
            PixelColorBlendingMode blending,
            PixelAlphaCompositionMode composition)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> img = provider.GetImage())
            {
                int scaleX = img.Width / 100;
                int scaleY = img.Height / 100;
                img.Mutate(
                    x => x.Fill(
                        Color.DarkBlue,
                        new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)
                        )
                    .Fill(
                        new GraphicsOptions {
                    Antialias = true, ColorBlendingMode = blending, AlphaCompositionMode = composition
                },
                        Color.HotPink,
                        new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY))
                    );

                VerifyImage(provider, blending, composition, img);
            }
        }
 /// <summary>
 /// Draws the given image together with the current one by blending their pixels.
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="image">The image to blend with the currently processing image.</param>
 /// <param name="colorBlending">The color blending mode.</param>
 /// <param name="alphaComposition">The alpha composition mode.</param>
 /// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
 /// <returns>The <see cref="Image{TPixelDst}"/>.</returns>
 public static IImageProcessingContext DrawImage(
     this IImageProcessingContext source,
     Image image,
     PixelColorBlendingMode colorBlending,
     PixelAlphaCompositionMode alphaComposition,
     float opacity) =>
 source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, colorBlending, alphaComposition, opacity));
Example #3
0
        public void WorksWithDifferentConfigurations <TPixel>(
            TestImageProvider <TPixel> provider,
            string brushImage,
            PixelColorBlendingMode mode,
            float opacity)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
                using (var blend = Image.Load <TPixel>(TestFile.Create(brushImage).Bytes))
                {
                    var size     = new Size(image.Width * 3 / 4, image.Height * 3 / 4);
                    var position = new Point(image.Width / 8, image.Height / 8);
                    blend.Mutate(x => x.Resize(size.Width, size.Height, KnownResamplers.Bicubic));
                    image.Mutate(x => x.DrawImage(blend, position, mode, opacity));
                    FormattableString testInfo = $"{System.IO.Path.GetFileNameWithoutExtension(brushImage)}-{mode}-{opacity}";

                    var encoder = new PngEncoder();

                    if (provider.PixelType == PixelTypes.Rgba64)
                    {
                        encoder.BitDepth = PngBitDepth.Bit16;
                    }

                    image.DebugSave(provider, testInfo, encoder: encoder);
                    image.CompareToReferenceOutput(ImageComparer.TolerantPercentage(0.01f),
                                                   provider,
                                                   testInfo);
                }
        }
        public void _1DarkBlueRect_2BlendHotPinkRect_3BlendTransparentEllipse <TPixel>(
            TestImageProvider <TPixel> provider,
            PixelColorBlendingMode blending,
            PixelAlphaCompositionMode composition)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> img = provider.GetImage())
            {
                int scaleX = img.Width / 100;
                int scaleY = img.Height / 100;
                img.Mutate(
                    x => x.Fill(
                        NamedColors <TPixel> .DarkBlue,
                        new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)));
                img.Mutate(
                    x => x.Fill(
                        new GraphicsOptions(true)
                {
                    ColorBlendingMode = blending, AlphaCompositionMode = composition
                },
                        NamedColors <TPixel> .HotPink,
                        new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY)));
                img.Mutate(
                    x => x.Fill(
                        new GraphicsOptions(true)
                {
                    ColorBlendingMode = blending, AlphaCompositionMode = composition
                },
                        NamedColors <TPixel> .Transparent,
                        new Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY))
                    );

                VerifyImage(provider, blending, composition, img);
            }
        }
        public void _1DarkBlueRect_2BlendBlackEllipse <TPixel>(
            TestImageProvider <TPixel> provider,
            PixelColorBlendingMode blending,
            PixelAlphaCompositionMode composition)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> dstImg = provider.GetImage(), srcImg = provider.GetImage())
            {
                int scaleX = (dstImg.Width / 100);
                int scaleY = (dstImg.Height / 100);

                dstImg.Mutate(
                    x => x.Fill(
                        NamedColors <TPixel> .DarkBlue,
                        new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)));

                srcImg.Mutate(
                    x => x.Fill(
                        NamedColors <TPixel> .Black,
                        new Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY)));

                dstImg.Mutate(
                    x => x.DrawImage(srcImg, new GraphicsOptions(true)
                {
                    ColorBlendingMode = blending, AlphaCompositionMode = composition
                })
                    );

                VerifyImage(provider, blending, composition, dstImg);
            }
        }
#pragma warning disable IDE1006 // Naming Styles
#pragma warning disable SA1300  // Element should begin with upper-case letter
        public void _1DarkBlueRect_2BlendHotPinkRect <TPixel>(
            TestImageProvider <TPixel> provider,
            PixelColorBlendingMode blending,
            PixelAlphaCompositionMode composition)
            where TPixel : unmanaged, IPixel <TPixel>
#pragma warning restore SA1300  // Element should begin with upper-case letter
#pragma warning restore IDE1006 // Naming Styles
        {
            using (Image <TPixel> img = provider.GetImage())
            {
                int scaleX = img.Width / 100;
                int scaleY = img.Height / 100;
                img.Mutate(
                    x => x.Fill(
                        Color.DarkBlue,
                        new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY))

                    .Fill(
                        new ShapeGraphicsOptions
                {
                    GraphicsOptions =
                    {
                        Antialias = true, ColorBlendingMode = blending, AlphaCompositionMode = composition
                    }
                },
                        Color.HotPink,
                        new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY)));

                VerifyImage(provider, blending, composition, img);
            }
        }
        public void DefaultGraphicsOptionsColorBlendingMode()
        {
            const PixelColorBlendingMode Expected = PixelColorBlendingMode.Normal;

            Assert.Equal(Expected, this.newGraphicsOptions.ColorBlendingMode);
            Assert.Equal(Expected, this.cloneGraphicsOptions.ColorBlendingMode);
        }
Example #8
0
        public void _1DarkBlueRect_2BlendBlackEllipse <TPixel>(
            TestImageProvider <TPixel> provider,
            PixelColorBlendingMode blending,
            PixelAlphaCompositionMode composition)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            using (Image <TPixel> dstImg = provider.GetImage(), srcImg = provider.GetImage())
            {
                int scaleX = dstImg.Width / 100;
                int scaleY = dstImg.Height / 100;

                dstImg.Mutate(
                    x => x.Fill(
                        Color.DarkBlue,
                        new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)));

                srcImg.Mutate(
                    x => x.Fill(
                        Color.Black,
                        new EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY)));

                dstImg.Mutate(
                    x => x.DrawImage(srcImg, new GraphicsOptions {
                    Antialias = true, ColorBlendingMode = blending, AlphaCompositionMode = composition
                }));

                VerifyImage(provider, blending, composition, dstImg);
            }
        }
#pragma warning disable IDE1006 // Naming Styles
#pragma warning disable SA1300  // Element should begin with upper-case letter
        public void _1DarkBlueRect_2BlendBlackEllipse <TPixel>(
            TestImageProvider <TPixel> provider,
            PixelColorBlendingMode blending,
            PixelAlphaCompositionMode composition)
            where TPixel : unmanaged, IPixel <TPixel>
#pragma warning restore SA1300  // Element should begin with upper-case letter
#pragma warning restore IDE1006 // Naming Styles
        {
            using (Image <TPixel> dstImg = provider.GetImage(), srcImg = provider.GetImage())
            {
                int scaleX = dstImg.Width / 100;
                int scaleY = dstImg.Height / 100;

                dstImg.Mutate(
                    x => x.Fill(
                        Color.DarkBlue,
                        new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)));

                srcImg.Mutate(
                    x => x.Fill(
                        Color.Black,
                        new EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY)));

                dstImg.Mutate(
                    x => x.DrawImage(srcImg, new GraphicsOptions {
                    Antialias = true, ColorBlendingMode = blending, AlphaCompositionMode = composition
                }));

                VerifyImage(provider, blending, composition, dstImg);
            }
        }
        public void BlendFillColorOverBackround <TPixel>(
            TestImageProvider <TPixel> provider,
            bool triggerFillRegion,
            string newColorName,
            float alpha,
            PixelColorBlendingMode blenderMode,
            float blendPercentage)
            where TPixel : struct, IPixel <TPixel>
        {
            var vec = TestUtils.GetPixelOfNamedColor <RgbaVector>(newColorName).ToVector4();

            vec.W = alpha;

            TPixel fillColor = default;

            fillColor.PackFromVector4(vec);

            using (Image <TPixel> image = provider.GetImage())
            {
                TPixel bgColor = image[0, 0];

                var options = new GraphicsOptions(false)
                {
                    ColorBlendingMode = blenderMode,
                    BlendPercentage   = blendPercentage
                };

                if (triggerFillRegion)
                {
                    var region = new ShapeRegion(new RectangularPolygon(0, 0, 16, 16));

                    image.Mutate(c => c.Fill(options, new SolidBrush <TPixel>(fillColor), region));
                }
                else
                {
                    image.Mutate(c => c.Fill(options, new SolidBrush <TPixel>(fillColor)));
                }

                var testOutputDetails = new
                {
                    triggerFillRegion = triggerFillRegion,
                    newColorName      = newColorName,
                    alpha             = alpha,
                    blenderMode       = blenderMode,
                    blendPercentage   = blendPercentage
                };

                image.DebugSave(
                    provider,
                    testOutputDetails,
                    appendPixelTypeToFileName: false,
                    appendSourceFileOrDescription: false);

                PixelBlender <TPixel> blender = PixelOperations <TPixel> .Instance.GetPixelBlender(blenderMode, PixelAlphaCompositionMode.SrcOver);

                TPixel expectedPixel = blender.Blend(bgColor, fillColor, blendPercentage);

                image.ComparePixelBufferTo(expectedPixel);
            }
        }
Example #11
0
        public void BlendFillColorOverBackground <TPixel>(
            TestImageProvider <TPixel> provider,
            bool triggerFillRegion,
            string newColorName,
            float alpha,
            PixelColorBlendingMode blenderMode,
            float blendPercentage)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            Color fillColor = TestUtils.GetColorByName(newColorName).WithAlpha(alpha);

            using (Image <TPixel> image = provider.GetImage())
            {
                TPixel bgColor = image[0, 0];

                var options = new DrawingOptions
                {
                    GraphicsOptions = new GraphicsOptions
                    {
                        Antialias         = false,
                        ColorBlendingMode = blenderMode,
                        BlendPercentage   = blendPercentage
                    }
                };

                if (triggerFillRegion)
                {
                    var path = new RectangularPolygon(0, 0, 16, 16);
                    image.Mutate(c => c.SetGraphicsOptions(options.GraphicsOptions).Fill(new SolidBrush(fillColor), path));
                }
                else
                {
                    image.Mutate(c => c.Fill(options, new SolidBrush(fillColor)));
                }

                var testOutputDetails = new
                {
                    triggerFillRegion,
                    newColorName,
                    alpha,
                    blenderMode,
                    blendPercentage
                };

                image.DebugSave(
                    provider,
                    testOutputDetails,
                    appendPixelTypeToFileName: false,
                    appendSourceFileOrDescription: false);

                PixelBlender <TPixel> blender = PixelOperations <TPixel> .Instance.GetPixelBlender(
                    blenderMode,
                    PixelAlphaCompositionMode.SrcOver);

                TPixel expectedPixel = blender.Blend(bgColor, fillColor.ToPixel <TPixel>(), blendPercentage);

                image.ComparePixelBufferTo(expectedPixel);
            }
        }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphicsOptions"/> struct.
 /// </summary>
 /// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
 public GraphicsOptions(bool enableAntialiasing)
 {
     this.colorBlendingMode      = PixelColorBlendingMode.Normal;
     this.alphaCompositionMode   = PixelAlphaCompositionMode.SrcOver;
     this.blendPercentage        = 1;
     this.antialiasSubpixelDepth = 16;
     this.antialias = enableAntialiasing;
 }
Example #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsOptions"/> struct.
        /// </summary>
        /// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
        /// <param name="opacity">blending percentage to apply to the drawing operation</param>
        /// <param name="blending">color blending mode to apply to the drawing operation</param>
        /// <param name="composition">alpha composition mode to apply to the drawing operation</param>
        public GraphicsOptions(bool enableAntialiasing, PixelColorBlendingMode blending, PixelAlphaCompositionMode composition, float opacity)
        {
            Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));

            this.colorBlendingMode      = blending;
            this.alphaCompositionMode   = composition;
            this.blendPercentage        = opacity;
            this.antialiasSubpixelDepth = 16;
            this.antialias = enableAntialiasing;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DrawImageProcessor{TPixelDst, TPixelSrc}"/> class.
        /// </summary>
        /// <param name="image">The image to blend with the currently processing image.</param>
        /// <param name="location">The location to draw the blended image.</param>
        /// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param>
        /// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param>
        /// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
        public DrawImageProcessor(Image <TPixelSrc> image, Point location, PixelColorBlendingMode colorBlendingMode, PixelAlphaCompositionMode alphaCompositionMode, float opacity)
        {
            Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));

            this.Image   = image;
            this.Opacity = opacity;
            this.Blender = PixelOperations <TPixelDst> .Instance.GetPixelBlender(colorBlendingMode, alphaCompositionMode);

            this.Location = location;
        }
 /// <summary>
 /// Draws the given image together with the current one by blending their pixels.
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="image">The image to blend with the currently processing image.</param>
 /// <param name="location">The location to draw the blended image.</param>
 /// <param name="colorBlending">The color blending to apply.</param>
 /// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
 /// <returns>The <see cref="Image{TPixelDst}"/>.</returns>
 public static IImageProcessingContext DrawImage(
     this IImageProcessingContext source,
     Image image,
     Point location,
     PixelColorBlendingMode colorBlending,
     float opacity) =>
 source.ApplyProcessor(
     new DrawImageProcessor(
         image,
         location,
         colorBlending,
         GraphicsOptions.Default.AlphaCompositionMode,
         opacity));
Example #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DrawImageProcessor"/> class.
 /// </summary>
 /// <param name="image">The image to blend.</param>
 /// <param name="location">The location to draw the blended image.</param>
 /// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param>
 /// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param>
 /// <param name="opacity">The opacity of the image to blend.</param>
 public DrawImageProcessor(
     Image image,
     Point location,
     PixelColorBlendingMode colorBlendingMode,
     PixelAlphaCompositionMode alphaCompositionMode,
     float opacity)
 {
     this.Image                = image;
     this.Location             = location;
     this.ColorBlendingMode    = colorBlendingMode;
     this.AlphaCompositionMode = alphaCompositionMode;
     this.Opacity              = opacity;
 }
Example #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextGraphicsOptions" /> struct.
        /// </summary>
        /// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
        public TextGraphicsOptions(bool enableAntialiasing)
        {
            this.applyKerning        = true;
            this.tabWidth            = 4;
            this.wrapTextWidth       = 0;
            this.horizontalAlignment = HorizontalAlignment.Left;
            this.verticalAlignment   = VerticalAlignment.Top;

            this.antialiasSubpixelDepth = 16;
            this.colorBlendingMode      = PixelColorBlendingMode.Normal;
            this.alphaCompositionMode   = PixelAlphaCompositionMode.SrcOver;
            this.blendPercentage        = 1;
            this.antialias = enableAntialiasing;
            this.dpiX      = DefaultTextDpi;
            this.dpiY      = DefaultTextDpi;
        }
Example #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:SixLabors.ImageSharp.Processing.Processors.Drawing.DrawImageProcessor`2" /> class.
        /// </summary>
        /// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
        /// <param name="image">The foreground <see cref="T:SixLabors.ImageSharp.Image`1" /> to blend with the currently processing image.</param>
        /// <param name="source">The source <see cref="T:SixLabors.ImageSharp.Image`1" /> for the current processor instance.</param>
        /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
        /// <param name="location">The location to draw the blended image.</param>
        /// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param>
        /// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param>
        /// <param name="interpolationValue">The interpolation progress. Must be between 0 and 1.</param>
        public InterpolateProcessor(Configuration configuration,
                                    SixLabors.ImageSharp.Image <TPixelFg> image,
                                    SixLabors.ImageSharp.Image <TPixelBg> source,
                                    SixLabors.ImageSharp.Rectangle sourceRectangle,
                                    Point location,
                                    PixelColorBlendingMode colorBlendingMode,
                                    PixelAlphaCompositionMode alphaCompositionMode,
                                    float interpolationValue) : base(configuration, source, sourceRectangle)
        {
            //	Guard.MustBeBetweenOrEqualTo(opacity, 0.0f, 1f, nameof(opacity));
            this.Image = image;
            this.InterpolationValue = interpolationValue;
            this.Blender            = PixelOperations <TPixelBg> .Instance.GetPixelBlender(colorBlendingMode, alphaCompositionMode);

            this.Location = location;
        }
#pragma warning disable IDE1006 // Naming Styles
#pragma warning disable SA1300  // Element should begin with upper-case letter
        public void _1DarkBlueRect_2BlendHotPinkRect_3BlendSemiTransparentRedEllipse <TPixel>(
            TestImageProvider <TPixel> provider,
            PixelColorBlendingMode blending,
            PixelAlphaCompositionMode composition)
            where TPixel : unmanaged, IPixel <TPixel>
#pragma warning restore SA1300  // Element should begin with upper-case letter
#pragma warning restore IDE1006 // Naming Styles
        {
            using (Image <TPixel> img = provider.GetImage())
            {
                int scaleX = img.Width / 100;
                int scaleY = img.Height / 100;
                img.Mutate(
                    x => x.Fill(
                        Color.DarkBlue,
                        new Rectangle(0 * scaleX, 40, 100 * scaleX, 20 * scaleY)));
                img.Mutate(
                    x => x.Fill(
                        new DrawingOptions
                {
                    GraphicsOptions = new GraphicsOptions {
                        Antialias = true, ColorBlendingMode = blending, AlphaCompositionMode = composition
                    }
                },
                        Color.HotPink,
                        new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY)));

                Color transparentRed = Color.Red.WithAlpha(0.5f);

                img.Mutate(
                    x => x.Fill(
                        new DrawingOptions
                {
                    GraphicsOptions = new GraphicsOptions {
                        Antialias = true, ColorBlendingMode = blending, AlphaCompositionMode = composition
                    }
                },
                        transparentRed,
                        new EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY)));

                VerifyImage(provider, blending, composition, img);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DrawImageProcessor{TPixelBg, TPixelFg}"/> class.
        /// </summary>
        /// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
        /// <param name="image">The foreground <see cref="Image{TPixelFg}"/> to blend with the currently processing image.</param>
        /// <param name="source">The source <see cref="Image{TPixelBg}"/> for the current processor instance.</param>
        /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
        /// <param name="location">The location to draw the blended image.</param>
        /// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param>
        /// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param>
        /// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
        public DrawImageProcessor(
            Configuration configuration,
            Image <TPixelFg> image,
            Image <TPixelBg> source,
            Rectangle sourceRectangle,
            Point location,
            PixelColorBlendingMode colorBlendingMode,
            PixelAlphaCompositionMode alphaCompositionMode,
            float opacity)
            : base(configuration, source, sourceRectangle)
        {
            Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));

            this.Image   = image;
            this.Opacity = opacity;
            this.Blender = PixelOperations <TPixelBg> .Instance.GetPixelBlender(colorBlendingMode, alphaCompositionMode);

            this.Location = location;
        }
        public void _1DarkBlueRect_2BlendHotPinkRect_3BlendSemiTransparentRedEllipse <TPixel>(
            TestImageProvider <TPixel> provider,
            PixelColorBlendingMode blending,
            PixelAlphaCompositionMode composition)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            using (Image <TPixel> img = provider.GetImage())
            {
                int scaleX = (img.Width / 100);
                int scaleY = (img.Height / 100);
                img.Mutate(
                    x => x.Fill(
                        Color.DarkBlue,
                        new Rectangle(0 * scaleX, 40, 100 * scaleX, 20 * scaleY)));
                img.Mutate(
                    x => x.Fill(
                        new ShapeGraphicsOptions
                {
                    GraphicsOptions = new GraphicsOptions {
                        Antialias = true, ColorBlendingMode = blending, AlphaCompositionMode = composition
                    }
                },
                        Color.HotPink,
                        new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY)));

                Color transparentRed = Color.Red.WithAlpha(0.5f);

                img.Mutate(
                    x => x.Fill(
                        new ShapeGraphicsOptions
                {
                    GraphicsOptions = new GraphicsOptions {
                        Antialias = true, ColorBlendingMode = blending, AlphaCompositionMode = composition
                    }
                },
                        transparentRed,
                        new EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY))
                    );

                VerifyImage(provider, blending, composition, img);;
            }
        }
Example #22
0
        private static void VerifyImage <TPixel>(
            TestImageProvider <TPixel> provider,
            PixelColorBlendingMode mode,
            Image <TPixel> img)
            where TPixel : struct, IPixel <TPixel>
        {
            img.DebugSave(
                provider,
                new { mode },
                appendPixelTypeToFileName: false,
                appendSourceFileOrDescription: false);

            var comparer = ImageComparer.TolerantPercentage(0.01F, 3);

            img.CompareFirstFrameToReferenceOutput(comparer,
                                                   provider,
                                                   new { mode },
                                                   appendPixelTypeToFileName: false,
                                                   appendSourceFileOrDescription: false);
        }
        public void _1DarkBlueRect_2BlendHotPinkRect_3BlendSemiTransparentRedEllipse <TPixel>(
            TestImageProvider <TPixel> provider,
            PixelColorBlendingMode blending,
            PixelAlphaCompositionMode composition)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> img = provider.GetImage())
            {
                int scaleX = (img.Width / 100);
                int scaleY = (img.Height / 100);
                img.Mutate(
                    x => x.Fill(
                        NamedColors <TPixel> .DarkBlue,
                        new Rectangle(0 * scaleX, 40, 100 * scaleX, 20 * scaleY)));
                img.Mutate(
                    x => x.Fill(
                        new GraphicsOptions(true)
                {
                    ColorBlendingMode = blending, AlphaCompositionMode = composition
                },
                        NamedColors <TPixel> .HotPink,
                        new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY)));
                var c = NamedColors <TPixel> .Red.ToVector4();

                c.W *= 0.5f;
                var pixel = default(TPixel);
                pixel.FromVector4(c);

                img.Mutate(
                    x => x.Fill(
                        new GraphicsOptions(true)
                {
                    ColorBlendingMode = blending, AlphaCompositionMode = composition
                },
                        pixel,
                        new Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY))
                    );

                VerifyImage(provider, blending, composition, img);;
            }
        }
Example #24
0
        private static void VerifyImage <TPixel>(
            TestImageProvider <TPixel> provider,
            PixelColorBlendingMode blending,
            PixelAlphaCompositionMode composition,
            Image <TPixel> img)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            img.DebugSave(
                provider,
                new { composition, blending },
                appendPixelTypeToFileName: false,
                appendSourceFileOrDescription: false);

            var comparer = ImageComparer.TolerantPercentage(0.01f, 3);

            img.CompareFirstFrameToReferenceOutput(comparer,
                                                   provider,
                                                   new { composition, blending },
                                                   appendPixelTypeToFileName: false,
                                                   appendSourceFileOrDescription: false);
        }
Example #25
0
 /// <summary>
 ///     Composes the underlay with a target image.
 /// </summary>
 private void Compose(Image target, PixelColorBlendingMode blendingMode = PixelColorBlendingMode.Normal)
 {
     _image.Mutate(context => context.DrawImage(target, blendingMode, 1.0f));
 }
Example #26
0
 public void ImageBlendingMatchesSvgSpecExamples <TPixel>(TestImageProvider <TPixel> provider, PixelColorBlendingMode mode)
     where TPixel : struct, IPixel <TPixel>
 {
     using (Image <TPixel> background = provider.GetImage())
         using (var source = Image.Load <TPixel>(TestFile.Create(TestImages.Png.Ducky).Bytes))
         {
             background.Mutate(x => x.DrawImage(source, mode, 1F));
             VerifyImage(provider, mode, background);
         }
 }
Example #27
0
        public void ImageShouldDrawTransformedImage <TPixel>(TestImageProvider <TPixel> provider, PixelColorBlendingMode mode)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
                using (var blend = Image.Load <TPixel>(TestFile.Create(TestImages.Bmp.Car).Bytes))
                {
                    AffineTransformBuilder builder = new AffineTransformBuilder()
                                                     .AppendRotationDegrees(45F)
                                                     .AppendScale(new SizeF(.25F, .25F))
                                                     .AppendTranslation(new PointF(10, 10));

                    // Apply a background color so we can see the translation.
                    blend.Mutate(x => x.Transform(builder).BackgroundColor(NamedColors <TPixel> .HotPink));

                    // Lets center the matrix so we can tell whether any cut-off issues we may have belong to the drawing processor
                    var position = new Point((image.Width - blend.Width) / 2, (image.Height - blend.Height) / 2);
                    image.Mutate(x => x.DrawImage(blend, position, mode, .75F));
                    image.DebugSave(provider, new[] { "Transformed" });
                }
        }
Example #28
0
        public void TestColorBlendingModes(Rgba32 backdrop, Rgba32 source, float opacity, PixelColorBlendingMode mode, Rgba32 expectedResult)
        {
            PixelBlender <Rgba32> blender = PixelOperations <Rgba32> .Instance.GetPixelBlender(mode, PixelAlphaCompositionMode.SrcOver);

            Rgba32 actualResult = blender.Blend(backdrop, source, opacity);

            // var str = actualResult.Rgba.ToString("X8"); // used to extract expectedResults
            Assert.Equal(actualResult.ToVector4(), expectedResult.ToVector4());
        }
Example #29
0
        public void ReturnsCorrectBlender <TPixel>(TestPixel <TPixel> pixel, Type type, PixelColorBlendingMode mode)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            PixelBlender <TPixel> blender = PixelOperations <TPixel> .Instance.GetPixelBlender(mode, PixelAlphaCompositionMode.SrcOver);

            Assert.IsType(type, blender);
        }
Example #30
0
        public void ImageBlendingMatchesSvgSpecExamples <TPixel>(TestImageProvider <TPixel> provider, PixelColorBlendingMode mode)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> background = provider.GetImage())
                using (var source = Image.Load <TPixel>(TestFile.Create(TestImages.Png.Ducky).Bytes))
                {
                    background.Mutate(x => x.DrawImage(source, mode, 1F));
                    background.DebugSave(
                        provider,
                        new { mode = mode },
                        appendPixelTypeToFileName: false,
                        appendSourceFileOrDescription: false);

                    var comparer = ImageComparer.TolerantPercentage(0.01F);
                    background.CompareToReferenceOutput(comparer,
                                                        provider,
                                                        new { mode = mode },
                                                        appendPixelTypeToFileName: false,
                                                        appendSourceFileOrDescription: false);
                }
        }