-
-
Notifications
You must be signed in to change notification settings - Fork 887
Fix resize pad color application for non Nearest Neighbor samplers #2052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
e6ab983
baa8c7b
06bdf13
0197de6
ebea485
afe9505
74dfe7e
aa7c6d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -39,8 +39,6 @@ internal sealed class ResizeWorker<TPixel> : IDisposable | |||||
|
|
||||||
| private readonly ResizeKernelMap verticalKernelMap; | ||||||
|
|
||||||
| private readonly int destWidth; | ||||||
|
|
||||||
| private readonly Rectangle targetWorkingRect; | ||||||
|
|
||||||
| private readonly Point targetOrigin; | ||||||
|
|
@@ -57,7 +55,6 @@ public ResizeWorker( | |||||
| PixelConversionModifiers conversionModifiers, | ||||||
| ResizeKernelMap horizontalKernelMap, | ||||||
| ResizeKernelMap verticalKernelMap, | ||||||
| int destWidth, | ||||||
| Rectangle targetWorkingRect, | ||||||
| Point targetOrigin) | ||||||
| { | ||||||
|
|
@@ -67,7 +64,6 @@ public ResizeWorker( | |||||
| this.conversionModifiers = conversionModifiers; | ||||||
| this.horizontalKernelMap = horizontalKernelMap; | ||||||
| this.verticalKernelMap = verticalKernelMap; | ||||||
| this.destWidth = destWidth; | ||||||
| this.targetWorkingRect = targetWorkingRect; | ||||||
| this.targetOrigin = targetOrigin; | ||||||
|
|
||||||
|
|
@@ -80,19 +76,19 @@ public ResizeWorker( | |||||
|
|
||||||
| int numberOfWindowBands = ResizeHelper.CalculateResizeWorkerHeightInWindowBands( | ||||||
| this.windowBandHeight, | ||||||
| destWidth, | ||||||
| targetWorkingRect.Width, | ||||||
| workingBufferLimitHintInBytes); | ||||||
|
|
||||||
| this.workerHeight = Math.Min(this.sourceRectangle.Height, numberOfWindowBands * this.windowBandHeight); | ||||||
|
|
||||||
| this.transposedFirstPassBuffer = configuration.MemoryAllocator.Allocate2D<Vector4>( | ||||||
| this.workerHeight, | ||||||
| destWidth, | ||||||
| targetWorkingRect.Width, | ||||||
| preferContiguosImageBuffers: true, | ||||||
| options: AllocationOptions.Clean); | ||||||
|
|
||||||
| this.tempRowBuffer = configuration.MemoryAllocator.Allocate<Vector4>(this.sourceRectangle.Width); | ||||||
| this.tempColumnBuffer = configuration.MemoryAllocator.Allocate<Vector4>(destWidth); | ||||||
| this.tempColumnBuffer = configuration.MemoryAllocator.Allocate<Vector4>(targetWorkingRect.Width); | ||||||
|
|
||||||
| this.currentWindow = new RowInterval(0, this.workerHeight); | ||||||
| } | ||||||
|
|
@@ -118,6 +114,9 @@ public void FillDestinationPixels(RowInterval rowInterval, Buffer2D<TPixel> dest | |||||
| // When creating transposedFirstPassBuffer, we made sure it's contiguous: | ||||||
| Span<Vector4> transposedFirstPassBufferSpan = this.transposedFirstPassBuffer.DangerousGetSingleSpan(); | ||||||
|
|
||||||
| int left = this.targetWorkingRect.Left; | ||||||
| int right = this.targetWorkingRect.Right; | ||||||
| int width = this.targetWorkingRect.Width; | ||||||
| for (int y = rowInterval.Min; y < rowInterval.Max; y++) | ||||||
| { | ||||||
| // Ensure offsets are normalized for cropping and padding. | ||||||
|
|
@@ -131,17 +130,18 @@ public void FillDestinationPixels(RowInterval rowInterval, Buffer2D<TPixel> dest | |||||
| ref Vector4 tempRowBase = ref MemoryMarshal.GetReference(tempColSpan); | ||||||
|
|
||||||
| int top = kernel.StartIndex - this.currentWindow.Min; | ||||||
|
|
||||||
| ref Vector4 fpBase = ref transposedFirstPassBufferSpan[top]; | ||||||
|
|
||||||
| for (int x = 0; x < this.destWidth; x++) | ||||||
| for (nint x = left; x < right; x++) | ||||||
|
||||||
| for (nint x = left; x < right; x++) | |
| for (nint x = 0; x < (right - left); x++) |
so that the subtractions below x - left can be eliminated (shifted to the loop variable), so that it's just x.
I assume current JIT won't (completely) CSE that expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot. Not sure how I missed that.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here:
| for (nint x = left; x < right; x++) | |
| for (nint x = 0; x < (right - left); x++) |
?
And adjust below to just x instead of x - left.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I have to add an extra incremental here. I need both x & x - left.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the plain array access
nintdoesn't bring any advantage.Here the JIT misses a optimization (a bug is tracked, but can't find it at the moment).
If you want best machine code here, look at Sharplab method
GetKernelC.It's more C# code and I doubt it's needed here. I'd just go with
int(ornintas you have it now) and wait for the JIT fix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No
MemoryMarshal.GetArrayDataReferencefor us yet unfortunately..... One day!