Skip to content

Commit 4b7718e

Browse files
Undo unrelated changes and clean up.
1 parent eefa57e commit 4b7718e

File tree

11 files changed

+44
-51
lines changed

11 files changed

+44
-51
lines changed

src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void Invoke(int i)
6565
var rows = new RowInterval(yMin, yMax);
6666

6767
// Skip the safety copy when invoking a potentially impure method on a readonly field
68-
Unsafe.AsRef(this.operation).Invoke(in rows);
68+
Unsafe.AsRef(in this.operation).Invoke(in rows);
6969
}
7070
}
7171

@@ -103,7 +103,7 @@ public void Invoke(int i)
103103

104104
using IMemoryOwner<TBuffer> buffer = this.allocator.Allocate<TBuffer>(this.info.MaxX);
105105

106-
Unsafe.AsRef(this.operation).Invoke(in rows, buffer.Memory.Span);
106+
Unsafe.AsRef(in this.operation).Invoke(in rows, buffer.Memory.Span);
107107
}
108108
}
109109
}

src/ImageSharp/Advanced/ParallelRowIterator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static void IterateRows<T>(
5959
if (numOfSteps == 1)
6060
{
6161
var rows = new RowInterval(top, bottom);
62-
Unsafe.AsRef(operation).Invoke(in rows);
62+
Unsafe.AsRef(in operation).Invoke(in rows);
6363
return;
6464
}
6565

@@ -125,7 +125,7 @@ public static void IterateRows<T, TBuffer>(
125125
var rows = new RowInterval(top, bottom);
126126
using (IMemoryOwner<TBuffer> buffer = allocator.Allocate<TBuffer>(width))
127127
{
128-
Unsafe.AsRef(operation).Invoke(rows, buffer.Memory.Span);
128+
Unsafe.AsRef(operation).Invoke(in rows, buffer.Memory.Span);
129129
}
130130

131131
return;

src/ImageSharp/Formats/Png/PngEncoderCore.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,14 +554,8 @@ private void WritePaletteChunk<TPixel>(Stream stream, IQuantizedFrame<TPixel> qu
554554
return;
555555
}
556556

557-
/* Grab the palette and write it to the stream.
558-
* Here the palette is reinterpreted as a mutable Memory<TPixel> value,
559-
* which is possible because the two memory types have the same layout.
560-
* This is done so that the Span<TPixel> we're working on is mutable,
561-
* so that we can skip the safety copies done by the compiler when we
562-
* invoke the IPixel.ToRgba32 method below, which is not marked as readonly. */
563-
ReadOnlyMemory<TPixel> paletteMemory = quantized.Palette;
564-
Span<TPixel> palette = Unsafe.As<ReadOnlyMemory<TPixel>, Memory<TPixel>>(ref paletteMemory).Span;
557+
// Grab the palette and write it to the stream.
558+
ReadOnlySpan<TPixel> palette = quantized.Palette.Span;
565559
int paletteLength = Math.Min(palette.Length, 256);
566560
int colorTableLength = paletteLength * 3;
567561
bool anyAlpha = false;

src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public void FromVector4(Vector4 vector)
218218

219219
/// <inheritdoc />
220220
[MethodImpl(InliningOptions.ShortMethod)]
221-
public readonly Vector4 ToVector4() => new Vector4(this.R, this.G, this.B, this.A) / Max;
221+
public Vector4 ToVector4() => new Vector4(this.R, this.G, this.B, this.A) / Max;
222222

223223
/// <inheritdoc />
224224
[MethodImpl(InliningOptions.ShortMethod)]
@@ -343,7 +343,7 @@ public void FromRgb48(Rgb48 source)
343343
/// </summary>
344344
/// <returns>The <see cref="Rgba32"/>.</returns>
345345
[MethodImpl(InliningOptions.ShortMethod)]
346-
public readonly Rgba32 ToRgba32()
346+
public Rgba32 ToRgba32()
347347
{
348348
byte r = ImageMaths.DownScaleFrom16BitTo8Bit(this.R);
349349
byte g = ImageMaths.DownScaleFrom16BitTo8Bit(this.G);
@@ -357,7 +357,7 @@ public readonly Rgba32 ToRgba32()
357357
/// </summary>
358358
/// <returns>The <see cref="Bgra32"/>.</returns>
359359
[MethodImpl(InliningOptions.ShortMethod)]
360-
public readonly Bgra32 ToBgra32()
360+
public Bgra32 ToBgra32()
361361
{
362362
byte r = ImageMaths.DownScaleFrom16BitTo8Bit(this.R);
363363
byte g = ImageMaths.DownScaleFrom16BitTo8Bit(this.G);
@@ -371,7 +371,7 @@ public readonly Bgra32 ToBgra32()
371371
/// </summary>
372372
/// <returns>The <see cref="Argb32"/>.</returns>
373373
[MethodImpl(InliningOptions.ShortMethod)]
374-
public readonly Argb32 ToArgb32()
374+
public Argb32 ToArgb32()
375375
{
376376
byte r = ImageMaths.DownScaleFrom16BitTo8Bit(this.R);
377377
byte g = ImageMaths.DownScaleFrom16BitTo8Bit(this.G);
@@ -385,7 +385,7 @@ public readonly Argb32 ToArgb32()
385385
/// </summary>
386386
/// <returns>The <see cref="Rgb24"/>.</returns>
387387
[MethodImpl(InliningOptions.ShortMethod)]
388-
public readonly Rgb24 ToRgb24()
388+
public Rgb24 ToRgb24()
389389
{
390390
byte r = ImageMaths.DownScaleFrom16BitTo8Bit(this.R);
391391
byte g = ImageMaths.DownScaleFrom16BitTo8Bit(this.G);
@@ -398,7 +398,7 @@ public readonly Rgb24 ToRgb24()
398398
/// </summary>
399399
/// <returns>The <see cref="Bgr24"/>.</returns>
400400
[MethodImpl(InliningOptions.ShortMethod)]
401-
public readonly Bgr24 ToBgr24()
401+
public Bgr24 ToBgr24()
402402
{
403403
byte r = ImageMaths.DownScaleFrom16BitTo8Bit(this.R);
404404
byte g = ImageMaths.DownScaleFrom16BitTo8Bit(this.G);

src/ImageSharp/PixelFormats/Utils/Vector4Converters.RgbaCompatible.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ internal static void ToVector4<TPixel>(
6666
MemoryMarshal.Cast<Rgba32, byte>(lastQuarterOfDestBuffer),
6767
MemoryMarshal.Cast<Vector4, float>(destVectors.Slice(0, countWithoutLastItem)));
6868

69-
// Reinterpret as a mutable reference to skip the safety copy of the readonly value
70-
destVectors[countWithoutLastItem] = Unsafe.AsRef(sourcePixels[countWithoutLastItem]).ToVector4();
69+
destVectors[countWithoutLastItem] = sourcePixels[countWithoutLastItem].ToVector4();
7170

7271
// TODO: Investigate optimized 1-pass approach!
7372
ApplyForwardConversionModifiers(destVectors, modifiers);

src/ImageSharp/Primitives/Rectangle.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public Rectangle(Point point, Size size)
8181
public Point Location
8282
{
8383
[MethodImpl(MethodImplOptions.AggressiveInlining)]
84-
readonly get => new Point(this.X, this.Y);
84+
get => new Point(this.X, this.Y);
8585

8686
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8787
set
@@ -98,7 +98,7 @@ public Point Location
9898
public Size Size
9999
{
100100
[MethodImpl(MethodImplOptions.AggressiveInlining)]
101-
readonly get => new Size(this.Width, this.Height);
101+
get => new Size(this.Width, this.Height);
102102

103103
[MethodImpl(MethodImplOptions.AggressiveInlining)]
104104
set
@@ -112,17 +112,17 @@ public Size Size
112112
/// Gets a value indicating whether this <see cref="Rectangle"/> is empty.
113113
/// </summary>
114114
[EditorBrowsable(EditorBrowsableState.Never)]
115-
public readonly bool IsEmpty => this.Equals(Empty);
115+
public bool IsEmpty => this.Equals(Empty);
116116

117117
/// <summary>
118118
/// Gets the y-coordinate of the top edge of this <see cref="Rectangle"/>.
119119
/// </summary>
120-
public readonly int Top => this.Y;
120+
public int Top => this.Y;
121121

122122
/// <summary>
123123
/// Gets the x-coordinate of the right edge of this <see cref="Rectangle"/>.
124124
/// </summary>
125-
public readonly int Right
125+
public int Right
126126
{
127127
[MethodImpl(MethodImplOptions.AggressiveInlining)]
128128
get => unchecked(this.X + this.Width);
@@ -131,7 +131,7 @@ public readonly int Right
131131
/// <summary>
132132
/// Gets the y-coordinate of the bottom edge of this <see cref="Rectangle"/>.
133133
/// </summary>
134-
public readonly int Bottom
134+
public int Bottom
135135
{
136136
[MethodImpl(MethodImplOptions.AggressiveInlining)]
137137
get => unchecked(this.Y + this.Height);
@@ -140,7 +140,7 @@ public readonly int Bottom
140140
/// <summary>
141141
/// Gets the x-coordinate of the left edge of this <see cref="Rectangle"/>.
142142
/// </summary>
143-
public readonly int Left => this.X;
143+
public int Left => this.X;
144144

145145
/// <summary>
146146
/// Creates a <see cref="RectangleF"/> with the coordinates of the specified <see cref="Rectangle"/>.
@@ -327,7 +327,7 @@ public static Rectangle Union(Rectangle a, Rectangle b)
327327
/// <param name="y">The out value for Y.</param>
328328
/// <param name="width">The out value for the width.</param>
329329
/// <param name="height">The out value for the height.</param>
330-
public readonly void Deconstruct(out int x, out int y, out int width, out int height)
330+
public void Deconstruct(out int x, out int y, out int width, out int height)
331331
{
332332
x = this.X;
333333
y = this.Y;
@@ -383,15 +383,15 @@ public void Inflate(int width, int height)
383383
/// <param name="y">The y-coordinate of the given point.</param>
384384
/// <returns>The <see cref="bool"/>.</returns>
385385
[MethodImpl(MethodImplOptions.AggressiveInlining)]
386-
public readonly bool Contains(int x, int y) => this.X <= x && x < this.Right && this.Y <= y && y < this.Bottom;
386+
public bool Contains(int x, int y) => this.X <= x && x < this.Right && this.Y <= y && y < this.Bottom;
387387

388388
/// <summary>
389389
/// Determines if the specified point is contained within the rectangular region defined by this <see cref="Rectangle"/> .
390390
/// </summary>
391391
/// <param name="point">The point.</param>
392392
/// <returns>The <see cref="bool"/>.</returns>
393393
[MethodImpl(MethodImplOptions.AggressiveInlining)]
394-
public readonly bool Contains(Point point) => this.Contains(point.X, point.Y);
394+
public bool Contains(Point point) => this.Contains(point.X, point.Y);
395395

396396
/// <summary>
397397
/// Determines if the rectangular region represented by <paramref name="rectangle"/> is entirely contained
@@ -400,7 +400,7 @@ public void Inflate(int width, int height)
400400
/// <param name="rectangle">The rectangle.</param>
401401
/// <returns>The <see cref="bool"/>.</returns>
402402
[MethodImpl(MethodImplOptions.AggressiveInlining)]
403-
public readonly bool Contains(Rectangle rectangle) =>
403+
public bool Contains(Rectangle rectangle) =>
404404
(this.X <= rectangle.X) && (rectangle.Right <= this.Right) &&
405405
(this.Y <= rectangle.Y) && (rectangle.Bottom <= this.Bottom);
406406

@@ -411,7 +411,7 @@ public readonly bool Contains(Rectangle rectangle) =>
411411
/// <param name="rectangle">The other Rectange. </param>
412412
/// <returns>The <see cref="bool"/>.</returns>
413413
[MethodImpl(MethodImplOptions.AggressiveInlining)]
414-
public readonly bool IntersectsWith(Rectangle rectangle) =>
414+
public bool IntersectsWith(Rectangle rectangle) =>
415415
(rectangle.X < this.Right) && (this.X < rectangle.Right) &&
416416
(rectangle.Y < this.Bottom) && (this.Y < rectangle.Bottom);
417417

@@ -438,13 +438,13 @@ public void Offset(int dx, int dy)
438438
}
439439

440440
/// <inheritdoc/>
441-
public override readonly int GetHashCode()
441+
public override int GetHashCode()
442442
{
443443
return HashCode.Combine(this.X, this.Y, this.Width, this.Height);
444444
}
445445

446446
/// <inheritdoc/>
447-
public override readonly string ToString()
447+
public override string ToString()
448448
{
449449
return $"Rectangle [ X={this.X}, Y={this.Y}, Width={this.Width}, Height={this.Height} ]";
450450
}
@@ -454,7 +454,7 @@ public override readonly string ToString()
454454

455455
/// <inheritdoc/>
456456
[MethodImpl(MethodImplOptions.AggressiveInlining)]
457-
public readonly bool Equals(Rectangle other) =>
457+
public bool Equals(Rectangle other) =>
458458
this.X.Equals(other.X) &&
459459
this.Y.Equals(other.Y) &&
460460
this.Width.Equals(other.Width) &&

src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,14 @@ private void OnFrameApplyCore(
316316
Vector4 parameters = Unsafe.Add(ref paramsRef, i);
317317

318318
// Compute the vertical 1D convolution
319-
var verticalOperation = new ApplyVerticalConvolutionRowIntervalOperation(ref sourceRectangle, firstPassBuffer, source.PixelBuffer, kernel);
319+
var verticalOperation = new ApplyVerticalConvolutionRowIntervalOperation(sourceRectangle, firstPassBuffer, source.PixelBuffer, kernel);
320320
ParallelRowIterator.IterateRows(
321321
configuration,
322322
sourceRectangle,
323323
in verticalOperation);
324324

325325
// Compute the horizontal 1D convolutions and accumulate the partial results on the target buffer
326-
var horizontalOperation = new ApplyHorizontalConvolutionRowIntervalOperation(ref sourceRectangle, processingBuffer, firstPassBuffer, kernel, parameters.Z, parameters.W);
326+
var horizontalOperation = new ApplyHorizontalConvolutionRowIntervalOperation(sourceRectangle, processingBuffer, firstPassBuffer, kernel, parameters.Z, parameters.W);
327327
ParallelRowIterator.IterateRows(
328328
configuration,
329329
sourceRectangle,
@@ -345,7 +345,7 @@ private void OnFrameApplyCore(
345345

346346
[MethodImpl(InliningOptions.ShortMethod)]
347347
public ApplyVerticalConvolutionRowIntervalOperation(
348-
ref Rectangle bounds,
348+
Rectangle bounds,
349349
Buffer2D<ComplexVector4> targetValues,
350350
Buffer2D<TPixel> sourcePixels,
351351
Complex64[] kernel)
@@ -390,7 +390,7 @@ public void Invoke(in RowInterval rows)
390390

391391
[MethodImpl(InliningOptions.ShortMethod)]
392392
public ApplyHorizontalConvolutionRowIntervalOperation(
393-
ref Rectangle bounds,
393+
Rectangle bounds,
394394
Buffer2D<Vector4> targetValues,
395395
Buffer2D<ComplexVector4> sourceValues,
396396
Complex64[] kernel,

src/ImageSharp/Processing/Processors/Normalization/GlobalHistogramEqualizationProcessor{TPixel}.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ protected override void OnFrameApply(ImageFrame<TPixel> source)
4747
{
4848
MemoryAllocator memoryAllocator = this.Configuration.MemoryAllocator;
4949
int numberOfPixels = source.Width * source.Height;
50-
var workingRect = new Rectangle(0, 0, source.Width, source.Height);
50+
var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
5151

5252
using IMemoryOwner<int> histogramBuffer = memoryAllocator.Allocate<int>(this.LuminanceLevels, AllocationOptions.Clean);
5353

5454
// Build the histogram of the grayscale levels
55-
var grayscaleOperation = new GrayscaleLevelsRowIntervalOperation(workingRect, histogramBuffer, source, this.LuminanceLevels);
55+
var grayscaleOperation = new GrayscaleLevelsRowIntervalOperation(interest, histogramBuffer, source, this.LuminanceLevels);
5656
ParallelRowIterator.IterateRows(
5757
this.Configuration,
58-
workingRect,
58+
interest,
5959
in grayscaleOperation);
6060

6161
Span<int> histogram = histogramBuffer.GetSpan();
@@ -75,10 +75,10 @@ ref MemoryMarshal.GetReference(histogram),
7575
float numberOfPixelsMinusCdfMin = numberOfPixels - cdfMin;
7676

7777
// Apply the cdf to each pixel of the image
78-
var cdfOperation = new CdfApplicationRowIntervalOperation(workingRect, cdfBuffer, source, this.LuminanceLevels, numberOfPixelsMinusCdfMin);
78+
var cdfOperation = new CdfApplicationRowIntervalOperation(interest, cdfBuffer, source, this.LuminanceLevels, numberOfPixelsMinusCdfMin);
7979
ParallelRowIterator.IterateRows(
8080
this.Configuration,
81-
workingRect,
81+
interest,
8282
in cdfOperation);
8383
}
8484

@@ -94,7 +94,7 @@ ref MemoryMarshal.GetReference(histogram),
9494

9595
[MethodImpl(InliningOptions.ShortMethod)]
9696
public GrayscaleLevelsRowIntervalOperation(
97-
in Rectangle bounds,
97+
Rectangle bounds,
9898
IMemoryOwner<int> histogramBuffer,
9999
ImageFrame<TPixel> source,
100100
int luminanceLevels)
@@ -136,7 +136,7 @@ public void Invoke(in RowInterval rows)
136136

137137
[MethodImpl(InliningOptions.ShortMethod)]
138138
public CdfApplicationRowIntervalOperation(
139-
in Rectangle bounds,
139+
Rectangle bounds,
140140
IMemoryOwner<int> cdfBuffer,
141141
ImageFrame<TPixel> source,
142142
int luminanceLevels,

src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source, ImageFrame<TPixe
5151
ParallelExecutionSettings parallelSettings =
5252
ParallelExecutionSettings.FromConfiguration(this.Configuration).MultiplyMinimumPixelsPerTask(4);
5353

54-
var operation = new RowIntervalOperation(ref bounds, source, destination);
54+
var operation = new RowIntervalOperation(bounds, source, destination);
5555

5656
ParallelRowIterator.IterateRows(
5757
bounds,
@@ -75,7 +75,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source, ImageFrame<TPixe
7575
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current instance.</param>
7676
/// <param name="destination">The destination <see cref="Image{TPixel}"/> for the current instance.</param>
7777
[MethodImpl(InliningOptions.ShortMethod)]
78-
public RowIntervalOperation(ref Rectangle bounds, ImageFrame<TPixel> source, ImageFrame<TPixel> destination)
78+
public RowIntervalOperation(Rectangle bounds, ImageFrame<TPixel> source, ImageFrame<TPixel> destination)
7979
{
8080
this.bounds = bounds;
8181
this.source = source;

src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source, ImageFrame<TPixe
6060
{
6161
Rectangle sourceBounds = this.SourceRectangle;
6262

63-
var nnOperation = new NearestNeighborRowIntervalOperation(ref sourceBounds, ref matrix, width, source, destination);
63+
var nnOperation = new NearestNeighborRowIntervalOperation(sourceBounds, ref matrix, width, source, destination);
6464
ParallelRowIterator.IterateRows(
6565
configuration,
6666
targetBounds,
@@ -88,7 +88,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source, ImageFrame<TPixe
8888

8989
[MethodImpl(InliningOptions.ShortMethod)]
9090
public NearestNeighborRowIntervalOperation(
91-
ref Rectangle bounds,
91+
Rectangle bounds,
9292
ref Matrix4x4 matrix,
9393
int maxX,
9494
ImageFrame<TPixel> source,

0 commit comments

Comments
 (0)