Skip to content

Commit 64a0ff0

Browse files
committed
Fix simple issues in review
1 parent 01caebd commit 64a0ff0

13 files changed

Lines changed: 88 additions & 111 deletions

src/ImageSharp/Configuration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Configuration()
4343
/// Initializes a new instance of the <see cref="Configuration" /> class.
4444
/// </summary>
4545
/// <param name="configurationModules">A collection of configuration modules to register.</param>
46-
public Configuration(params IImageFormatConfigurationModule[]? configurationModules)
46+
public Configuration(params IImageFormatConfigurationModule[] configurationModules)
4747
{
4848
if (configurationModules != null)
4949
{

src/ImageSharp/Formats/Png/Chunks/APngAnimationControl.cs renamed to src/ImageSharp/Formats/Png/Chunks/AnimationControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace SixLabors.ImageSharp.Formats.Png.Chunks;
77

8-
internal record APngAnimationControl(
8+
internal record AnimationControl(
99
int NumberFrames,
1010
int NumberPlays)
1111
{
@@ -36,7 +36,7 @@ public void WriteTo(Span<byte> buffer)
3636
/// </summary>
3737
/// <param name="data">The data to parse.</param>
3838
/// <returns>The parsed acTL.</returns>
39-
public static APngAnimationControl Parse(ReadOnlySpan<byte> data)
39+
public static AnimationControl Parse(ReadOnlySpan<byte> data)
4040
=> new(
4141
NumberFrames: BinaryPrimitives.ReadInt32BigEndian(data[..4]),
4242
NumberPlays: BinaryPrimitives.ReadInt32BigEndian(data[4..8]));

src/ImageSharp/Formats/Png/Chunks/APngFrameControl.cs renamed to src/ImageSharp/Formats/Png/Chunks/FrameControl.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55

66
namespace SixLabors.ImageSharp.Formats.Png.Chunks;
77

8-
internal readonly struct APngFrameControl
8+
internal readonly struct FrameControl
99
{
1010
public const int Size = 26;
1111

12-
public APngFrameControl(
12+
public FrameControl(
1313
int sequenceNumber,
1414
int width,
1515
int height,
1616
int xOffset,
1717
int yOffset,
1818
short delayNumber,
1919
short delayDenominator,
20-
APngDisposeOperation disposeOperation,
21-
APngBlendOperation blendOperation)
20+
PngDisposeOperation disposeOperation,
21+
PngBlendOperation blendOperation)
2222
{
2323
this.SequenceNumber = sequenceNumber;
2424
this.Width = width;
@@ -69,12 +69,12 @@ public APngFrameControl(
6969
/// <summary>
7070
/// Gets the type of frame area disposal to be done after rendering this frame
7171
/// </summary>
72-
public APngDisposeOperation DisposeOperation { get; }
72+
public PngDisposeOperation DisposeOperation { get; }
7373

7474
/// <summary>
7575
/// Gets the type of frame area rendering for this frame
7676
/// </summary>
77-
public APngBlendOperation BlendOperation { get; }
77+
public PngBlendOperation BlendOperation { get; }
7878

7979
/// <summary>
8080
/// Validates the APng fcTL.
@@ -120,9 +120,9 @@ public void Validate(PngHeader hdr)
120120
/// </summary>
121121
/// <param name="frameMetadata">The metadata to parse.</param>
122122
/// <param name="sequenceNumber">Sequence number.</param>
123-
public static APngFrameControl FromMetadata(APngFrameMetadata frameMetadata, int sequenceNumber)
123+
public static FrameControl FromMetadata(PngFrameMetadata frameMetadata, int sequenceNumber)
124124
{
125-
APngFrameControl fcTL = new(
125+
FrameControl fcTL = new(
126126
sequenceNumber,
127127
frameMetadata.Width,
128128
frameMetadata.Height,
@@ -158,7 +158,7 @@ public void WriteTo(Span<byte> buffer)
158158
/// </summary>
159159
/// <param name="data">The data to parse.</param>
160160
/// <returns>The parsed fcTL.</returns>
161-
public static APngFrameControl Parse(ReadOnlySpan<byte> data)
161+
public static FrameControl Parse(ReadOnlySpan<byte> data)
162162
=> new(
163163
sequenceNumber: BinaryPrimitives.ReadInt32BigEndian(data[..4]),
164164
width: BinaryPrimitives.ReadInt32BigEndian(data[4..8]),
@@ -167,6 +167,6 @@ public static APngFrameControl Parse(ReadOnlySpan<byte> data)
167167
yOffset: BinaryPrimitives.ReadInt32BigEndian(data[16..20]),
168168
delayNumber: BinaryPrimitives.ReadInt16BigEndian(data[20..22]),
169169
delayDenominator: BinaryPrimitives.ReadInt16BigEndian(data[22..24]),
170-
disposeOperation: (APngDisposeOperation)data[24],
171-
blendOperation: (APngBlendOperation)data[25]);
170+
disposeOperation: (PngDisposeOperation)data[24],
171+
blendOperation: (PngBlendOperation)data[25]);
172172
}

src/ImageSharp/Formats/Png/MetadataExtensions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ public static partial class MetadataExtensions
2323
/// Gets the aPng format specific metadata for the image frame.
2424
/// </summary>
2525
/// <param name="source">The metadata this method extends.</param>
26-
/// <returns>The <see cref="APngFrameMetadata"/>.</returns>
27-
public static APngFrameMetadata GetAPngFrameMetadata(this ImageFrameMetadata source) => source.GetFormatMetadata(PngFormat.Instance);
26+
/// <returns>The <see cref="PngFrameMetadata"/>.</returns>
27+
public static PngFrameMetadata GetPngFrameMetadata(this ImageFrameMetadata source) => source.GetFormatMetadata(PngFormat.Instance);
2828

2929
/// <summary>
3030
/// Gets the aPng format specific metadata for the image frame.
3131
/// </summary>
3232
/// <param name="source">The metadata this method extends.</param>
3333
/// <param name="metadata">The metadata.</param>
34-
/// <returns>The <see cref="APngFrameMetadata"/>.</returns>
35-
public static bool TryGetAPngFrameMetadata(this ImageFrameMetadata source, [NotNullWhen(true)] out APngFrameMetadata? metadata) => source.TryGetFormatMetadata(PngFormat.Instance, out metadata);
36-
34+
/// <returns>The <see cref="PngFrameMetadata"/>.</returns>
35+
public static bool TryGetPngFrameMetadata(this ImageFrameMetadata source, [NotNullWhen(true)] out PngFrameMetadata? metadata) => source.TryGetFormatMetadata(PngFormat.Instance, out metadata);
3736
}

src/ImageSharp/Formats/Png/APngBlendOperation.cs renamed to src/ImageSharp/Formats/Png/PngBlendOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Png;
66
/// <summary>
77
/// Specifies whether the frame is to be alpha blended into the current output buffer content, or whether it should completely replace its region in the output buffer.
88
/// </summary>
9-
public enum APngBlendOperation
9+
public enum PngBlendOperation
1010
{
1111
/// <summary>
1212
/// All color components of the frame, including alpha, overwrite the current contents of the frame's output buffer region.

src/ImageSharp/Formats/Png/PngConstants.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,24 @@ internal static class PngConstants
8080
/// <summary>
8181
/// Gets the keyword of the XMP metadata, encoded in an iTXT chunk.
8282
/// </summary>
83-
public static ReadOnlySpan<byte> XmpKeyword => "XML:com.adobe.xmp"u8;
83+
public static ReadOnlySpan<byte> XmpKeyword => new[]
84+
{
85+
(byte)'X',
86+
(byte)'M',
87+
(byte)'L',
88+
(byte)':',
89+
(byte)'c',
90+
(byte)'o',
91+
(byte)'m',
92+
(byte)'.',
93+
(byte)'a',
94+
(byte)'d',
95+
(byte)'o',
96+
(byte)'b',
97+
(byte)'e',
98+
(byte)'.',
99+
(byte)'x',
100+
(byte)'m',
101+
(byte)'p'
102+
};
84103
}

src/ImageSharp/Formats/Png/PngDecoderCore.cs

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ namespace SixLabors.ImageSharp.Formats.Png;
2828
/// </summary>
2929
internal sealed class PngDecoderCore : IImageDecoderInternals
3030
{
31-
/// <summary>
32-
/// Indicate whether the file is a simple PNG.
33-
/// </summary>
34-
private bool isSimplePng;
35-
3631
/// <summary>
3732
/// The general decoder options.
3833
/// </summary>
@@ -66,7 +61,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals
6661
/// <summary>
6762
/// The png animation control.
6863
/// </summary>
69-
private APngAnimationControl? animationControl;
64+
private AnimationControl? animationControl;
7065

7166
/// <summary>
7267
/// The number of bytes per pixel.
@@ -149,7 +144,7 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
149144
this.currentStream = stream;
150145
this.currentStream.Skip(8);
151146
Image<TPixel>? image = null;
152-
APngFrameControl? lastFrameControl = null;
147+
FrameControl? lastFrameControl = null;
153148
ImageFrame<TPixel>? currentFrame = null;
154149
Span<byte> buffer = stackalloc byte[20];
155150

@@ -170,11 +165,6 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
170165
this.ReadHeaderChunk(pngMetadata, chunk.Data.GetSpan());
171166
break;
172167
case PngChunkType.AnimationControl:
173-
if (this.isSimplePng || this.animationControl is not null)
174-
{
175-
PngThrowHelper.ThrowInvalidAnimationControl();
176-
}
177-
178168
this.ReadAnimationControlChunk(pngMetadata, chunk.Data.GetSpan());
179169
break;
180170
case PngChunkType.Physical:
@@ -184,11 +174,6 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
184174
ReadGammaChunk(pngMetadata, chunk.Data.GetSpan());
185175
break;
186176
case PngChunkType.FrameControl:
187-
if (this.isSimplePng)
188-
{
189-
continue;
190-
}
191-
192177
currentFrame = null;
193178
lastFrameControl = this.ReadFrameControlChunk(chunk.Data.GetSpan());
194179
break;
@@ -228,11 +213,6 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
228213
lastFrameControl = null;
229214
break;
230215
case PngChunkType.Data:
231-
if (this.animationControl is null)
232-
{
233-
this.isSimplePng = true;
234-
}
235-
236216
if (image is null)
237217
{
238218
this.InitializeImage(metadata, lastFrameControl, out image);
@@ -313,7 +293,7 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat
313293
ImageMetadata metadata = new();
314294
PngMetadata pngMetadata = metadata.GetPngMetadata();
315295
this.currentStream = stream;
316-
APngFrameControl? lastFrameControl = null;
296+
FrameControl? lastFrameControl = null;
317297
Span<byte> buffer = stackalloc byte[20];
318298

319299
this.currentStream.Skip(8);
@@ -330,11 +310,6 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat
330310
this.ReadHeaderChunk(pngMetadata, chunk.Data.GetSpan());
331311
break;
332312
case PngChunkType.AnimationControl:
333-
if (this.isSimplePng || this.animationControl is not null)
334-
{
335-
PngThrowHelper.ThrowInvalidAnimationControl();
336-
}
337-
338313
this.ReadAnimationControlChunk(pngMetadata, chunk.Data.GetSpan());
339314
break;
340315
case PngChunkType.Physical:
@@ -356,11 +331,6 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat
356331
ReadGammaChunk(pngMetadata, chunk.Data.GetSpan());
357332
break;
358333
case PngChunkType.FrameControl:
359-
if (this.isSimplePng)
360-
{
361-
continue;
362-
}
363-
364334
lastFrameControl = this.ReadFrameControlChunk(chunk.Data.GetSpan());
365335
break;
366336
case PngChunkType.FrameData:
@@ -379,11 +349,6 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat
379349
this.SkipChunkDataAndCrc(chunk);
380350
break;
381351
case PngChunkType.Data:
382-
if (this.animationControl is null)
383-
{
384-
this.isSimplePng = true;
385-
}
386-
387352
// Spec says tRNS must be before IDAT so safe to exit.
388353
if (this.colorMetadataOnly)
389354
{
@@ -465,7 +430,7 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat
465430
}
466431

467432
EOF:
468-
if (this.header is { Width: 0, Height: 0 })
433+
if (this.header.Width == 0 && this.header.Height == 0)
469434
{
470435
PngThrowHelper.ThrowInvalidHeader();
471436
}
@@ -568,7 +533,7 @@ private static void ReadGammaChunk(PngMetadata pngMetadata, ReadOnlySpan<byte> d
568533
/// <param name="metadata">The metadata information for the image</param>
569534
/// <param name="frameControl">The frame control information for the frame</param>
570535
/// <param name="image">The image that we will populate</param>
571-
private void InitializeImage<TPixel>(ImageMetadata metadata, APngFrameControl? frameControl, out Image<TPixel> image)
536+
private void InitializeImage<TPixel>(ImageMetadata metadata, FrameControl? frameControl, out Image<TPixel> image)
572537
where TPixel : unmanaged, IPixel<TPixel>
573538
{
574539
image = Image.CreateUninitialized<TPixel>(
@@ -579,7 +544,7 @@ private void InitializeImage<TPixel>(ImageMetadata metadata, APngFrameControl? f
579544

580545
if (frameControl is { } control)
581546
{
582-
APngFrameMetadata frameMetadata = image.Frames.RootFrame.Metadata.GetAPngFrameMetadata();
547+
PngFrameMetadata frameMetadata = image.Frames.RootFrame.Metadata.GetPngFrameMetadata();
583548
frameMetadata.FromChunk(control);
584549
}
585550

@@ -603,12 +568,13 @@ private void InitializeImage<TPixel>(ImageMetadata metadata, APngFrameControl? f
603568
/// <typeparam name="TPixel">The type the pixels will be</typeparam>
604569
/// <param name="frameControl">The frame control information for the frame</param>
605570
/// <param name="image">The image that we will populate</param>
606-
private void InitializeFrame<TPixel>(APngFrameControl frameControl, Image<TPixel> image, out ImageFrame<TPixel> frame)
571+
/// <param name="frame">The created frame</param>
572+
private void InitializeFrame<TPixel>(FrameControl frameControl, Image<TPixel> image, out ImageFrame<TPixel> frame)
607573
where TPixel : unmanaged, IPixel<TPixel>
608574
{
609575
frame = image.Frames.CreateFrame();
610576

611-
APngFrameMetadata frameMetadata = frame.Metadata.GetAPngFrameMetadata();
577+
PngFrameMetadata frameMetadata = frame.Metadata.GetPngFrameMetadata();
612578

613579
frameMetadata.FromChunk(frameControl);
614580

@@ -716,7 +682,7 @@ private void DecodePixelData<TPixel>(DeflateStream compressedStream, ImageFrame<
716682
{
717683
int currentRow = Adam7.FirstRow[0];
718684
int currentRowBytesRead = 0;
719-
int height = image.Metadata.TryGetAPngFrameMetadata(out APngFrameMetadata? frameMetadata) ? frameMetadata.Height : this.header.Height;
685+
int height = image.Metadata.TryGetPngFrameMetadata(out PngFrameMetadata? frameMetadata) ? frameMetadata.Height : this.header.Height;
720686
while (currentRow < height)
721687
{
722688
cancellationToken.ThrowIfCancellationRequested();
@@ -763,7 +729,7 @@ private void DecodePixelData<TPixel>(DeflateStream compressedStream, ImageFrame<
763729
this.ProcessDefilteredScanline(currentRow, scanlineSpan, image, pngMetadata);
764730

765731
this.SwapScanlineBuffers();
766-
++currentRow;
732+
currentRow++;
767733
}
768734
}
769735

@@ -784,7 +750,7 @@ private void DecodeInterlacedPixelData<TPixel>(DeflateStream compressedStream, I
784750
int pass = 0;
785751
int width = this.header.Width;
786752
int height = this.header.Height;
787-
if (image.Metadata.TryGetAPngFrameMetadata(out APngFrameMetadata? frameMetadata))
753+
if (image.Metadata.TryGetPngFrameMetadata(out PngFrameMetadata? frameMetadata))
788754
{
789755
width = frameMetadata.Width;
790756
height = frameMetadata.Height;
@@ -797,7 +763,7 @@ private void DecodeInterlacedPixelData<TPixel>(DeflateStream compressedStream, I
797763

798764
if (numColumns == 0)
799765
{
800-
++pass;
766+
pass++;
801767

802768
// This pass contains no data; skip to next pass
803769
continue;
@@ -1124,7 +1090,7 @@ private void AssignTransparentMarkers(ReadOnlySpan<byte> alpha, PngMetadata pngM
11241090
/// <param name="data">The <see cref="T:ReadOnlySpan{byte}"/> containing data.</param>
11251091
private void ReadAnimationControlChunk(PngMetadata pngMetadata, ReadOnlySpan<byte> data)
11261092
{
1127-
this.animationControl = APngAnimationControl.Parse(data);
1093+
this.animationControl = AnimationControl.Parse(data);
11281094

11291095
pngMetadata.NumberPlays = this.animationControl.NumberPlays;
11301096
}
@@ -1133,9 +1099,9 @@ private void ReadAnimationControlChunk(PngMetadata pngMetadata, ReadOnlySpan<byt
11331099
/// Reads a header chunk from the data.
11341100
/// </summary>
11351101
/// <param name="data">The <see cref="T:ReadOnlySpan{byte}"/> containing data.</param>
1136-
private APngFrameControl ReadFrameControlChunk(ReadOnlySpan<byte> data)
1102+
private FrameControl ReadFrameControlChunk(ReadOnlySpan<byte> data)
11371103
{
1138-
APngFrameControl fcTL = APngFrameControl.Parse(data);
1104+
FrameControl fcTL = FrameControl.Parse(data);
11391105

11401106
fcTL.Validate(this.header);
11411107

src/ImageSharp/Formats/Png/APngDisposeOperation.cs renamed to src/ImageSharp/Formats/Png/PngDisposeOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Png;
66
/// <summary>
77
/// Specifies how the output buffer should be changed at the end of the delay (before rendering the next frame).
88
/// </summary>
9-
public enum APngDisposeOperation
9+
public enum PngDisposeOperation
1010
{
1111
/// <summary>
1212
/// No disposal is done on this frame before rendering the next; the contents of the output buffer are left as is.

src/ImageSharp/Formats/Png/PngEncoder.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ public PngEncoder() =>
1919
// quantizer with options appropriate to the encoding bit depth.
2020
this.Quantizer = null!;
2121

22-
/// <summary>
23-
/// Gets whether the file is a simple PNG.
24-
/// </summary>
25-
public bool? IsSimplePng { get; init; }
26-
2722
/// <summary>
2823
/// Gets the number of bits per sample or per palette index (not per pixel).
2924
/// Not all values are allowed for all <see cref="ColorType" /> values.

0 commit comments

Comments
 (0)