@@ -64,6 +64,39 @@ public void Blend<TPixelSrc>(
6464 PixelOperations < TPixel > . Instance . FromVector4Destructive ( configuration , destinationVectors [ ..maxLength ] , destination , PixelConversionModifiers . Scale ) ;
6565 }
6666
67+ /// <summary>
68+ /// Blends a row against a constant source color.
69+ /// </summary>
70+ /// <param name="configuration"><see cref="Configuration"/> to use internally</param>
71+ /// <param name="destination">the destination span</param>
72+ /// <param name="background">the background span</param>
73+ /// <param name="source">the source color</param>
74+ /// <param name="amount">
75+ /// A value between 0 and 1 indicating the weight of the second source vector.
76+ /// At amount = 0, "background" is returned, at amount = 1, "source" is returned.
77+ /// </param>
78+ public void Blend (
79+ Configuration configuration ,
80+ Span < TPixel > destination ,
81+ ReadOnlySpan < TPixel > background ,
82+ TPixel source ,
83+ float amount )
84+ {
85+ int maxLength = destination . Length ;
86+ Guard . MustBeGreaterThanOrEqualTo ( background . Length , maxLength , nameof ( background . Length ) ) ;
87+ Guard . MustBeBetweenOrEqualTo ( amount , 0 , 1 , nameof ( amount ) ) ;
88+
89+ using IMemoryOwner < Vector4 > buffer = configuration . MemoryAllocator . Allocate < Vector4 > ( maxLength * 2 ) ;
90+ Span < Vector4 > destinationVectors = buffer . Slice ( 0 , maxLength ) ;
91+ Span < Vector4 > backgroundVectors = buffer . Slice ( maxLength , maxLength ) ;
92+
93+ PixelOperations < TPixel > . Instance . ToVector4 ( configuration , background [ ..maxLength ] , backgroundVectors , PixelConversionModifiers . Scale ) ;
94+
95+ this . BlendFunction ( destinationVectors , backgroundVectors , source . ToScaledVector4 ( ) , amount ) ;
96+
97+ PixelOperations < TPixel > . Instance . FromVector4Destructive ( configuration , destinationVectors [ ..maxLength ] , destination , PixelConversionModifiers . Scale ) ;
98+ }
99+
67100 /// <summary>
68101 /// Blends 2 rows together
69102 /// </summary>
@@ -121,6 +154,39 @@ public void Blend<TPixelSrc>(
121154 PixelOperations < TPixel > . Instance . FromVector4Destructive ( configuration , destinationVectors [ ..maxLength ] , destination , PixelConversionModifiers . Scale ) ;
122155 }
123156
157+ /// <summary>
158+ /// Blends a row against a constant source color.
159+ /// </summary>
160+ /// <param name="configuration"><see cref="Configuration"/> to use internally</param>
161+ /// <param name="destination">the destination span</param>
162+ /// <param name="background">the background span</param>
163+ /// <param name="source">the source color</param>
164+ /// <param name="amount">
165+ /// A span with values between 0 and 1 indicating the weight of the second source vector.
166+ /// At amount = 0, "background" is returned, at amount = 1, "source" is returned.
167+ /// </param>
168+ public void Blend (
169+ Configuration configuration ,
170+ Span < TPixel > destination ,
171+ ReadOnlySpan < TPixel > background ,
172+ TPixel source ,
173+ ReadOnlySpan < float > amount )
174+ {
175+ int maxLength = destination . Length ;
176+ Guard . MustBeGreaterThanOrEqualTo ( background . Length , maxLength , nameof ( background . Length ) ) ;
177+ Guard . MustBeGreaterThanOrEqualTo ( amount . Length , maxLength , nameof ( amount . Length ) ) ;
178+
179+ using IMemoryOwner < Vector4 > buffer = configuration . MemoryAllocator . Allocate < Vector4 > ( maxLength * 2 ) ;
180+ Span < Vector4 > destinationVectors = buffer . Slice ( 0 , maxLength ) ;
181+ Span < Vector4 > backgroundVectors = buffer . Slice ( maxLength , maxLength ) ;
182+
183+ PixelOperations < TPixel > . Instance . ToVector4 ( configuration , background [ ..maxLength ] , backgroundVectors , PixelConversionModifiers . Scale ) ;
184+
185+ this . BlendFunction ( destinationVectors , backgroundVectors , source . ToScaledVector4 ( ) , amount ) ;
186+
187+ PixelOperations < TPixel > . Instance . FromVector4Destructive ( configuration , destinationVectors [ ..maxLength ] , destination , PixelConversionModifiers . Scale ) ;
188+ }
189+
124190 /// <summary>
125191 /// Blend 2 rows together.
126192 /// </summary>
@@ -137,6 +203,22 @@ protected abstract void BlendFunction(
137203 ReadOnlySpan < Vector4 > source ,
138204 float amount ) ;
139205
206+ /// <summary>
207+ /// Blend a row against a constant source color.
208+ /// </summary>
209+ /// <param name="destination">destination span</param>
210+ /// <param name="background">the background span</param>
211+ /// <param name="source">the source color vector</param>
212+ /// <param name="amount">
213+ /// A value between 0 and 1 indicating the weight of the second source vector.
214+ /// At amount = 0, "background" is returned, at amount = 1, "source" is returned.
215+ /// </param>
216+ protected abstract void BlendFunction (
217+ Span < Vector4 > destination ,
218+ ReadOnlySpan < Vector4 > background ,
219+ Vector4 source ,
220+ float amount ) ;
221+
140222 /// <summary>
141223 /// Blend 2 rows together.
142224 /// </summary>
@@ -152,4 +234,20 @@ protected abstract void BlendFunction(
152234 ReadOnlySpan < Vector4 > background ,
153235 ReadOnlySpan < Vector4 > source ,
154236 ReadOnlySpan < float > amount ) ;
237+
238+ /// <summary>
239+ /// Blend a row against a constant source color.
240+ /// </summary>
241+ /// <param name="destination">destination span</param>
242+ /// <param name="background">the background span</param>
243+ /// <param name="source">the source color vector</param>
244+ /// <param name="amount">
245+ /// A span with values between 0 and 1 indicating the weight of the second source vector.
246+ /// At amount = 0, "background" is returned, at amount = 1, "source" is returned.
247+ /// </param>
248+ protected abstract void BlendFunction (
249+ Span < Vector4 > destination ,
250+ ReadOnlySpan < Vector4 > background ,
251+ Vector4 source ,
252+ ReadOnlySpan < float > amount ) ;
155253}
0 commit comments