1- // Copyright (c) Six Labors and contributors.
2- // Licensed under the Apache License, Version 2.0.
3-
4- using System . Buffers ;
5- using System . Threading . Tasks ;
6-
7- using SixLabors . ImageSharp . Memory ;
8- using SixLabors . ImageSharp . PixelFormats ;
9- using SixLabors . Memory ;
10- using SixLabors . Primitives ;
11-
12- namespace SixLabors . ImageSharp . Processing . Processors . Drawing
13- {
14- /// <summary>
15- /// Combines two images together by blending the pixels.
16- /// </summary>
17- public class DrawImageProcessor : IImageProcessor
18- {
19- /// <summary>
20- /// Initializes a new instance of the <see cref="DrawImageProcessor"/> class.
21- /// </summary>
22- /// <param name="image">The image to blend.</param>
23- /// <param name="location">The location to draw the blended image.</param>
24- /// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param>
25- /// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param>
26- /// <param name="opacity">The opacity of the image to blend.</param>
27- public DrawImageProcessor (
28- Image image ,
29- Point location ,
30- PixelColorBlendingMode colorBlendingMode ,
31- PixelAlphaCompositionMode alphaCompositionMode ,
32- float opacity )
33- {
34- this . Image = image ;
35- this . Location = location ;
36- this . ColorBlendingMode = colorBlendingMode ;
37- this . AlphaCompositionMode = alphaCompositionMode ;
38- this . Opacity = opacity ;
39- }
40-
41- /// <summary>
42- /// Gets the image to blend.
43- /// </summary>
44- public Image Image { get ; }
45-
46- /// <summary>
47- /// Gets the location to draw the blended image.
48- /// </summary>
49- public Point Location { get ; }
50-
51- /// <summary>
52- /// Gets the blending mode to use when drawing the image.
53- /// </summary>
54- public PixelColorBlendingMode ColorBlendingMode { get ; }
55-
56- /// <summary>
57- /// Gets the Alpha blending mode to use when drawing the image.
58- /// </summary>
59- public PixelAlphaCompositionMode AlphaCompositionMode { get ; }
60-
61- /// <summary>
62- /// Gets the opacity of the image to blend.
63- /// </summary>
64- public float Opacity { get ; }
65-
66- /// <inheritdoc />
67- public IImageProcessor < TPixelBg > CreatePixelSpecificProcessor < TPixelBg > ( )
68- where TPixelBg : struct , IPixel < TPixelBg >
69- {
70- var visitor = new ProcessorFactoryVisitor < TPixelBg > ( this ) ;
71- this . Image . AcceptVisitor ( visitor ) ;
72- return visitor . Result ;
73- }
74-
75- private class ProcessorFactoryVisitor < TPixelBg > : IImageVisitor
76- where TPixelBg : struct , IPixel < TPixelBg >
77- {
78- private readonly DrawImageProcessor definition ;
79-
80- public ProcessorFactoryVisitor ( DrawImageProcessor definition )
81- {
82- this . definition = definition ;
83- }
84-
85- public IImageProcessor < TPixelBg > Result { get ; private set ; }
86-
87- public void Visit < TPixelFg > ( Image < TPixelFg > image )
88- where TPixelFg : struct , IPixel < TPixelFg >
89- {
90- this . Result = new DrawImageProcessor < TPixelBg , TPixelFg > (
91- image ,
92- this . definition . Location ,
93- this . definition . ColorBlendingMode ,
94- this . definition . AlphaCompositionMode ,
95- this . definition . Opacity ) ;
96- }
97- }
98- }
1+ // Copyright (c) Six Labors and contributors.
2+ // Licensed under the Apache License, Version 2.0.
3+
4+ using System . Buffers ;
5+ using System . Threading . Tasks ;
6+
7+ using SixLabors . ImageSharp . Memory ;
8+ using SixLabors . ImageSharp . PixelFormats ;
9+ using SixLabors . Memory ;
10+ using SixLabors . Primitives ;
11+
12+ namespace SixLabors . ImageSharp . Processing . Processors . Drawing
13+ {
14+ /// <summary>
15+ /// Combines two images together by blending the pixels.
16+ /// </summary>
17+ public class DrawImageProcessor : IImageProcessor
18+ {
19+ /// <summary>
20+ /// Initializes a new instance of the <see cref="DrawImageProcessor"/> class.
21+ /// </summary>
22+ /// <param name="image">The image to blend.</param>
23+ /// <param name="location">The location to draw the blended image.</param>
24+ /// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param>
25+ /// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param>
26+ /// <param name="opacity">The opacity of the image to blend.</param>
27+ public DrawImageProcessor (
28+ Image image ,
29+ Point location ,
30+ PixelColorBlendingMode colorBlendingMode ,
31+ PixelAlphaCompositionMode alphaCompositionMode ,
32+ float opacity )
33+ {
34+ this . Image = image ;
35+ this . Location = location ;
36+ this . ColorBlendingMode = colorBlendingMode ;
37+ this . AlphaCompositionMode = alphaCompositionMode ;
38+ this . Opacity = opacity ;
39+ }
40+
41+ /// <summary>
42+ /// Gets the image to blend.
43+ /// </summary>
44+ public Image Image { get ; }
45+
46+ /// <summary>
47+ /// Gets the location to draw the blended image.
48+ /// </summary>
49+ public Point Location { get ; }
50+
51+ /// <summary>
52+ /// Gets the blending mode to use when drawing the image.
53+ /// </summary>
54+ public PixelColorBlendingMode ColorBlendingMode { get ; }
55+
56+ /// <summary>
57+ /// Gets the Alpha blending mode to use when drawing the image.
58+ /// </summary>
59+ public PixelAlphaCompositionMode AlphaCompositionMode { get ; }
60+
61+ /// <summary>
62+ /// Gets the opacity of the image to blend.
63+ /// </summary>
64+ public float Opacity { get ; }
65+
66+ /// <inheritdoc />
67+ public IImageProcessor < TPixelBg > CreatePixelSpecificProcessor < TPixelBg > ( )
68+ where TPixelBg : struct , IPixel < TPixelBg >
69+ {
70+ var visitor = new ProcessorFactoryVisitor < TPixelBg > ( this ) ;
71+ this . Image . AcceptVisitor ( visitor ) ;
72+ return visitor . Result ;
73+ }
74+
75+ private class ProcessorFactoryVisitor < TPixelBg > : IImageVisitor
76+ where TPixelBg : struct , IPixel < TPixelBg >
77+ {
78+ private readonly DrawImageProcessor definition ;
79+
80+ public ProcessorFactoryVisitor ( DrawImageProcessor definition )
81+ {
82+ this . definition = definition ;
83+ }
84+
85+ public IImageProcessor < TPixelBg > Result { get ; private set ; }
86+
87+ public void Visit < TPixelFg > ( Image < TPixelFg > image )
88+ where TPixelFg : struct , IPixel < TPixelFg >
89+ {
90+ this . Result = new DrawImageProcessor < TPixelBg , TPixelFg > (
91+ image ,
92+ this . definition . Location ,
93+ this . definition . ColorBlendingMode ,
94+ this . definition . AlphaCompositionMode ,
95+ this . definition . Opacity ) ;
96+ }
97+ }
98+ }
9999}
0 commit comments