Skip to content

Commit ebea485

Browse files
Update ResizeWorker.cs
1 parent 0197de6 commit ebea485

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ public void FillDestinationPixels(RowInterval rowInterval, Buffer2D<TPixel> dest
133133

134134
ref Vector4 fpBase = ref transposedFirstPassBufferSpan[top];
135135

136-
for (nint x = left; x < right; x++)
136+
for (nint x = 0; x < (right - left); x++)
137137
{
138-
ref Vector4 firstPassColumnBase = ref Unsafe.Add(ref fpBase, (x - left) * this.workerHeight);
138+
ref Vector4 firstPassColumnBase = ref Unsafe.Add(ref fpBase, x * this.workerHeight);
139139

140140
// Destination color components
141-
Unsafe.Add(ref tempRowBase, x - left) = kernel.ConvolveCore(ref firstPassColumnBase);
141+
Unsafe.Add(ref tempRowBase, x) = kernel.ConvolveCore(ref firstPassColumnBase);
142142
}
143143

144144
Span<TPixel> targetRowSpan = destination.DangerousGetRowSpan(y).Slice(left, width);
@@ -172,6 +172,7 @@ private void CalculateFirstPassValues(RowInterval calculationInterval)
172172

173173
int left = this.targetWorkingRect.Left;
174174
int right = this.targetWorkingRect.Right;
175+
int targetOriginX = left > this.targetOrigin.X ? left - this.targetOrigin.X : this.targetOrigin.X;
175176
for (int y = calculationInterval.Min; y < calculationInterval.Max; y++)
176177
{
177178
Span<TPixel> sourceRow = this.source.DangerousGetRowSpan(y);
@@ -186,13 +187,13 @@ private void CalculateFirstPassValues(RowInterval calculationInterval)
186187
// Span<Vector4> firstPassSpan = transposedFirstPassBufferSpan.Slice(y - this.currentWindow.Min);
187188
ref Vector4 firstPassBaseRef = ref transposedFirstPassBufferSpan[y - this.currentWindow.Min];
188189

189-
for (nint x = left; x < right; x++)
190+
for (nint x = 0; x < (right - left); x++)
190191
{
191-
ResizeKernel kernel = this.horizontalKernelMap.GetKernel(x - this.targetOrigin.X);
192+
ResizeKernel kernel = this.horizontalKernelMap.GetKernel(x - targetOriginX);
192193

193194
// optimization for:
194195
// firstPassSpan[x * this.workerHeight] = kernel.Convolve(tempRowSpan);
195-
Unsafe.Add(ref firstPassBaseRef, (x - left) * this.workerHeight) = kernel.Convolve(tempRowSpan);
196+
Unsafe.Add(ref firstPassBaseRef, x * this.workerHeight) = kernel.Convolve(tempRowSpan);
196197
}
197198
}
198199
}

0 commit comments

Comments
 (0)