@@ -77,26 +77,28 @@ public BokehBlurProcessor(Configuration configuration, BokehBlurProcessor defini
7777 /// <inheritdoc/>
7878 protected override void OnFrameApply ( ImageFrame < TPixel > source )
7979 {
80+ var sourceRectangle = Rectangle . Intersect ( this . SourceRectangle , source . Bounds ( ) ) ;
81+
8082 // Preliminary gamma highlight pass
81- var gammaOperation = new ApplyGammaExposureRowOperation ( this . SourceRectangle , source . PixelBuffer , this . Configuration , this . gamma ) ;
83+ var gammaOperation = new ApplyGammaExposureRowOperation ( sourceRectangle , source . PixelBuffer , this . Configuration , this . gamma ) ;
8284 ParallelRowIterator . IterateRows < ApplyGammaExposureRowOperation , Vector4 > (
8385 this . Configuration ,
84- this . SourceRectangle ,
86+ sourceRectangle ,
8587 in gammaOperation ) ;
8688
8789 // Create a 0-filled buffer to use to store the result of the component convolutions
8890 using Buffer2D < Vector4 > processingBuffer = this . Configuration . MemoryAllocator . Allocate2D < Vector4 > ( source . Size ( ) , AllocationOptions . Clean ) ;
8991
9092 // Perform the 1D convolutions on all the kernel components and accumulate the results
91- this . OnFrameApplyCore ( source , this . SourceRectangle , this . Configuration , processingBuffer ) ;
93+ this . OnFrameApplyCore ( source , sourceRectangle , this . Configuration , processingBuffer ) ;
9294
9395 float inverseGamma = 1 / this . gamma ;
9496
9597 // Apply the inverse gamma exposure pass, and write the final pixel data
96- var operation = new ApplyInverseGammaExposureRowOperation ( this . SourceRectangle , source . PixelBuffer , processingBuffer , this . Configuration , inverseGamma ) ;
98+ var operation = new ApplyInverseGammaExposureRowOperation ( sourceRectangle , source . PixelBuffer , processingBuffer , this . Configuration , inverseGamma ) ;
9799 ParallelRowIterator . IterateRows (
98100 this . Configuration ,
99- this . SourceRectangle ,
101+ sourceRectangle ,
100102 in operation ) ;
101103 }
102104
@@ -116,8 +118,6 @@ private void OnFrameApplyCore(
116118 // Allocate the buffer with the intermediate convolution results
117119 using Buffer2D < ComplexVector4 > firstPassBuffer = configuration . MemoryAllocator . Allocate2D < ComplexVector4 > ( source . Size ( ) ) ;
118120
119- var interest = Rectangle . Intersect ( sourceRectangle , source . Bounds ( ) ) ;
120-
121121 // Unlike in the standard 2 pass convolution processor, we use a rectangle of 1x the interest width
122122 // to speedup the actual convolution, by applying bulk pixel conversion and clamping calculation.
123123 // The second half of the buffer will just target the temporary buffer of complex pixel values.
@@ -128,8 +128,8 @@ private void OnFrameApplyCore(
128128 using var mapX = new KernelSamplingMap ( configuration . MemoryAllocator ) ;
129129 using var mapY = new KernelSamplingMap ( configuration . MemoryAllocator ) ;
130130
131- mapX . BuildSamplingOffsetMap ( 1 , this . kernelSize , interest ) ;
132- mapY . BuildSamplingOffsetMap ( this . kernelSize , 1 , interest ) ;
131+ mapX . BuildSamplingOffsetMap ( 1 , this . kernelSize , sourceRectangle ) ;
132+ mapY . BuildSamplingOffsetMap ( this . kernelSize , 1 , sourceRectangle ) ;
133133
134134 ref Complex64 [ ] baseRef = ref MemoryMarshal . GetReference ( this . kernels . AsSpan ( ) ) ;
135135 ref Vector4 paramsRef = ref MemoryMarshal . GetReference ( this . kernelParameters . AsSpan ( ) ) ;
@@ -143,7 +143,7 @@ private void OnFrameApplyCore(
143143
144144 // Horizontal convolution
145145 var horizontalOperation = new FirstPassConvolutionRowOperation (
146- interest ,
146+ sourceRectangle ,
147147 firstPassBuffer ,
148148 source . PixelBuffer ,
149149 mapX ,
@@ -152,12 +152,12 @@ private void OnFrameApplyCore(
152152
153153 ParallelRowIterator . IterateRows < FirstPassConvolutionRowOperation , Vector4 > (
154154 configuration ,
155- interest ,
155+ sourceRectangle ,
156156 in horizontalOperation ) ;
157157
158158 // Vertical 1D convolutions to accumulate the partial results on the target buffer
159159 var verticalOperation = new BokehBlurProcessor . SecondPassConvolutionRowOperation (
160- interest ,
160+ sourceRectangle ,
161161 processingBuffer ,
162162 firstPassBuffer ,
163163 mapY ,
@@ -167,7 +167,7 @@ private void OnFrameApplyCore(
167167
168168 ParallelRowIterator . IterateRows (
169169 configuration ,
170- interest ,
170+ sourceRectangle ,
171171 in verticalOperation ) ;
172172 }
173173 }
0 commit comments