From 64a0ff08e9f9e051236a7de38c6f34f47c5ca80d Mon Sep 17 00:00:00 2001 From: Poker Date: Thu, 17 Aug 2023 22:27:08 +0800 Subject: [PATCH] Fix simple issues in review --- src/ImageSharp/Configuration.cs | 2 +- ...nimationControl.cs => AnimationControl.cs} | 4 +- .../{APngFrameControl.cs => FrameControl.cs} | 22 +++---- .../Formats/Png/MetadataExtensions.cs | 9 ++- ...BlendOperation.cs => PngBlendOperation.cs} | 2 +- src/ImageSharp/Formats/Png/PngConstants.cs | 21 +++++- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 66 +++++-------------- ...oseOperation.cs => PngDisposeOperation.cs} | 2 +- src/ImageSharp/Formats/Png/PngEncoder.cs | 5 -- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 41 ++++++------ src/ImageSharp/Formats/Png/PngFormat.cs | 4 +- ...ngFrameMetadata.cs => PngFrameMetadata.cs} | 20 +++--- src/ImageSharp/ImageSharp.csproj | 1 - 13 files changed, 88 insertions(+), 111 deletions(-) rename src/ImageSharp/Formats/Png/Chunks/{APngAnimationControl.cs => AnimationControl.cs} (92%) rename src/ImageSharp/Formats/Png/Chunks/{APngFrameControl.cs => FrameControl.cs} (89%) rename src/ImageSharp/Formats/Png/{APngBlendOperation.cs => PngBlendOperation.cs} (96%) rename src/ImageSharp/Formats/Png/{APngDisposeOperation.cs => PngDisposeOperation.cs} (95%) rename src/ImageSharp/Formats/Png/{APngFrameMetadata.cs => PngFrameMetadata.cs} (79%) diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index 7692238be1..39fcef9c40 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -43,7 +43,7 @@ public sealed class Configuration /// Initializes a new instance of the class. /// /// A collection of configuration modules to register. - public Configuration(params IImageFormatConfigurationModule[]? configurationModules) + public Configuration(params IImageFormatConfigurationModule[] configurationModules) { if (configurationModules != null) { diff --git a/src/ImageSharp/Formats/Png/Chunks/APngAnimationControl.cs b/src/ImageSharp/Formats/Png/Chunks/AnimationControl.cs similarity index 92% rename from src/ImageSharp/Formats/Png/Chunks/APngAnimationControl.cs rename to src/ImageSharp/Formats/Png/Chunks/AnimationControl.cs index ca8268cd5d..7a76e5a095 100644 --- a/src/ImageSharp/Formats/Png/Chunks/APngAnimationControl.cs +++ b/src/ImageSharp/Formats/Png/Chunks/AnimationControl.cs @@ -5,7 +5,7 @@ using System.Buffers.Binary; namespace SixLabors.ImageSharp.Formats.Png.Chunks; -internal record APngAnimationControl( +internal record AnimationControl( int NumberFrames, int NumberPlays) { @@ -36,7 +36,7 @@ internal record APngAnimationControl( /// /// The data to parse. /// The parsed acTL. - public static APngAnimationControl Parse(ReadOnlySpan data) + public static AnimationControl Parse(ReadOnlySpan data) => new( NumberFrames: BinaryPrimitives.ReadInt32BigEndian(data[..4]), NumberPlays: BinaryPrimitives.ReadInt32BigEndian(data[4..8])); diff --git a/src/ImageSharp/Formats/Png/Chunks/APngFrameControl.cs b/src/ImageSharp/Formats/Png/Chunks/FrameControl.cs similarity index 89% rename from src/ImageSharp/Formats/Png/Chunks/APngFrameControl.cs rename to src/ImageSharp/Formats/Png/Chunks/FrameControl.cs index ac9d1e5602..5f0bc716dc 100644 --- a/src/ImageSharp/Formats/Png/Chunks/APngFrameControl.cs +++ b/src/ImageSharp/Formats/Png/Chunks/FrameControl.cs @@ -5,11 +5,11 @@ using System.Buffers.Binary; namespace SixLabors.ImageSharp.Formats.Png.Chunks; -internal readonly struct APngFrameControl +internal readonly struct FrameControl { public const int Size = 26; - public APngFrameControl( + public FrameControl( int sequenceNumber, int width, int height, @@ -17,8 +17,8 @@ internal readonly struct APngFrameControl int yOffset, short delayNumber, short delayDenominator, - APngDisposeOperation disposeOperation, - APngBlendOperation blendOperation) + PngDisposeOperation disposeOperation, + PngBlendOperation blendOperation) { this.SequenceNumber = sequenceNumber; this.Width = width; @@ -69,12 +69,12 @@ internal readonly struct APngFrameControl /// /// Gets the type of frame area disposal to be done after rendering this frame /// - public APngDisposeOperation DisposeOperation { get; } + public PngDisposeOperation DisposeOperation { get; } /// /// Gets the type of frame area rendering for this frame /// - public APngBlendOperation BlendOperation { get; } + public PngBlendOperation BlendOperation { get; } /// /// Validates the APng fcTL. @@ -120,9 +120,9 @@ internal readonly struct APngFrameControl /// /// The metadata to parse. /// Sequence number. - public static APngFrameControl FromMetadata(APngFrameMetadata frameMetadata, int sequenceNumber) + public static FrameControl FromMetadata(PngFrameMetadata frameMetadata, int sequenceNumber) { - APngFrameControl fcTL = new( + FrameControl fcTL = new( sequenceNumber, frameMetadata.Width, frameMetadata.Height, @@ -158,7 +158,7 @@ internal readonly struct APngFrameControl /// /// The data to parse. /// The parsed fcTL. - public static APngFrameControl Parse(ReadOnlySpan data) + public static FrameControl Parse(ReadOnlySpan data) => new( sequenceNumber: BinaryPrimitives.ReadInt32BigEndian(data[..4]), width: BinaryPrimitives.ReadInt32BigEndian(data[4..8]), @@ -167,6 +167,6 @@ internal readonly struct APngFrameControl yOffset: BinaryPrimitives.ReadInt32BigEndian(data[16..20]), delayNumber: BinaryPrimitives.ReadInt16BigEndian(data[20..22]), delayDenominator: BinaryPrimitives.ReadInt16BigEndian(data[22..24]), - disposeOperation: (APngDisposeOperation)data[24], - blendOperation: (APngBlendOperation)data[25]); + disposeOperation: (PngDisposeOperation)data[24], + blendOperation: (PngBlendOperation)data[25]); } diff --git a/src/ImageSharp/Formats/Png/MetadataExtensions.cs b/src/ImageSharp/Formats/Png/MetadataExtensions.cs index 0ae180e08d..f24b8d1b5c 100644 --- a/src/ImageSharp/Formats/Png/MetadataExtensions.cs +++ b/src/ImageSharp/Formats/Png/MetadataExtensions.cs @@ -23,15 +23,14 @@ public static partial class MetadataExtensions /// Gets the aPng format specific metadata for the image frame. /// /// The metadata this method extends. - /// The . - public static APngFrameMetadata GetAPngFrameMetadata(this ImageFrameMetadata source) => source.GetFormatMetadata(PngFormat.Instance); + /// The . + public static PngFrameMetadata GetPngFrameMetadata(this ImageFrameMetadata source) => source.GetFormatMetadata(PngFormat.Instance); /// /// Gets the aPng format specific metadata for the image frame. /// /// The metadata this method extends. /// The metadata. - /// The . - public static bool TryGetAPngFrameMetadata(this ImageFrameMetadata source, [NotNullWhen(true)] out APngFrameMetadata? metadata) => source.TryGetFormatMetadata(PngFormat.Instance, out metadata); - + /// The . + public static bool TryGetPngFrameMetadata(this ImageFrameMetadata source, [NotNullWhen(true)] out PngFrameMetadata? metadata) => source.TryGetFormatMetadata(PngFormat.Instance, out metadata); } diff --git a/src/ImageSharp/Formats/Png/APngBlendOperation.cs b/src/ImageSharp/Formats/Png/PngBlendOperation.cs similarity index 96% rename from src/ImageSharp/Formats/Png/APngBlendOperation.cs rename to src/ImageSharp/Formats/Png/PngBlendOperation.cs index 0e8cdb4289..b8a84a933e 100644 --- a/src/ImageSharp/Formats/Png/APngBlendOperation.cs +++ b/src/ImageSharp/Formats/Png/PngBlendOperation.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Png; /// /// 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. /// -public enum APngBlendOperation +public enum PngBlendOperation { /// /// All color components of the frame, including alpha, overwrite the current contents of the frame's output buffer region. diff --git a/src/ImageSharp/Formats/Png/PngConstants.cs b/src/ImageSharp/Formats/Png/PngConstants.cs index 7877f84bd8..43f2b0fb25 100644 --- a/src/ImageSharp/Formats/Png/PngConstants.cs +++ b/src/ImageSharp/Formats/Png/PngConstants.cs @@ -80,5 +80,24 @@ internal static class PngConstants /// /// Gets the keyword of the XMP metadata, encoded in an iTXT chunk. /// - public static ReadOnlySpan XmpKeyword => "XML:com.adobe.xmp"u8; + public static ReadOnlySpan XmpKeyword => new[] + { + (byte)'X', + (byte)'M', + (byte)'L', + (byte)':', + (byte)'c', + (byte)'o', + (byte)'m', + (byte)'.', + (byte)'a', + (byte)'d', + (byte)'o', + (byte)'b', + (byte)'e', + (byte)'.', + (byte)'x', + (byte)'m', + (byte)'p' + }; } diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index fa94e6925c..ac9aa5fad0 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -28,11 +28,6 @@ namespace SixLabors.ImageSharp.Formats.Png; /// internal sealed class PngDecoderCore : IImageDecoderInternals { - /// - /// Indicate whether the file is a simple PNG. - /// - private bool isSimplePng; - /// /// The general decoder options. /// @@ -66,7 +61,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals /// /// The png animation control. /// - private APngAnimationControl? animationControl; + private AnimationControl? animationControl; /// /// The number of bytes per pixel. @@ -149,7 +144,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals this.currentStream = stream; this.currentStream.Skip(8); Image? image = null; - APngFrameControl? lastFrameControl = null; + FrameControl? lastFrameControl = null; ImageFrame? currentFrame = null; Span buffer = stackalloc byte[20]; @@ -170,11 +165,6 @@ internal sealed class PngDecoderCore : IImageDecoderInternals this.ReadHeaderChunk(pngMetadata, chunk.Data.GetSpan()); break; case PngChunkType.AnimationControl: - if (this.isSimplePng || this.animationControl is not null) - { - PngThrowHelper.ThrowInvalidAnimationControl(); - } - this.ReadAnimationControlChunk(pngMetadata, chunk.Data.GetSpan()); break; case PngChunkType.Physical: @@ -184,11 +174,6 @@ internal sealed class PngDecoderCore : IImageDecoderInternals ReadGammaChunk(pngMetadata, chunk.Data.GetSpan()); break; case PngChunkType.FrameControl: - if (this.isSimplePng) - { - continue; - } - currentFrame = null; lastFrameControl = this.ReadFrameControlChunk(chunk.Data.GetSpan()); break; @@ -228,11 +213,6 @@ internal sealed class PngDecoderCore : IImageDecoderInternals lastFrameControl = null; break; case PngChunkType.Data: - if (this.animationControl is null) - { - this.isSimplePng = true; - } - if (image is null) { this.InitializeImage(metadata, lastFrameControl, out image); @@ -313,7 +293,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals ImageMetadata metadata = new(); PngMetadata pngMetadata = metadata.GetPngMetadata(); this.currentStream = stream; - APngFrameControl? lastFrameControl = null; + FrameControl? lastFrameControl = null; Span buffer = stackalloc byte[20]; this.currentStream.Skip(8); @@ -330,11 +310,6 @@ internal sealed class PngDecoderCore : IImageDecoderInternals this.ReadHeaderChunk(pngMetadata, chunk.Data.GetSpan()); break; case PngChunkType.AnimationControl: - if (this.isSimplePng || this.animationControl is not null) - { - PngThrowHelper.ThrowInvalidAnimationControl(); - } - this.ReadAnimationControlChunk(pngMetadata, chunk.Data.GetSpan()); break; case PngChunkType.Physical: @@ -356,11 +331,6 @@ internal sealed class PngDecoderCore : IImageDecoderInternals ReadGammaChunk(pngMetadata, chunk.Data.GetSpan()); break; case PngChunkType.FrameControl: - if (this.isSimplePng) - { - continue; - } - lastFrameControl = this.ReadFrameControlChunk(chunk.Data.GetSpan()); break; case PngChunkType.FrameData: @@ -379,11 +349,6 @@ internal sealed class PngDecoderCore : IImageDecoderInternals this.SkipChunkDataAndCrc(chunk); break; case PngChunkType.Data: - if (this.animationControl is null) - { - this.isSimplePng = true; - } - // Spec says tRNS must be before IDAT so safe to exit. if (this.colorMetadataOnly) { @@ -465,7 +430,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals } EOF: - if (this.header is { Width: 0, Height: 0 }) + if (this.header.Width == 0 && this.header.Height == 0) { PngThrowHelper.ThrowInvalidHeader(); } @@ -568,7 +533,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals /// The metadata information for the image /// The frame control information for the frame /// The image that we will populate - private void InitializeImage(ImageMetadata metadata, APngFrameControl? frameControl, out Image image) + private void InitializeImage(ImageMetadata metadata, FrameControl? frameControl, out Image image) where TPixel : unmanaged, IPixel { image = Image.CreateUninitialized( @@ -579,7 +544,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals if (frameControl is { } control) { - APngFrameMetadata frameMetadata = image.Frames.RootFrame.Metadata.GetAPngFrameMetadata(); + PngFrameMetadata frameMetadata = image.Frames.RootFrame.Metadata.GetPngFrameMetadata(); frameMetadata.FromChunk(control); } @@ -603,12 +568,13 @@ internal sealed class PngDecoderCore : IImageDecoderInternals /// The type the pixels will be /// The frame control information for the frame /// The image that we will populate - private void InitializeFrame(APngFrameControl frameControl, Image image, out ImageFrame frame) + /// The created frame + private void InitializeFrame(FrameControl frameControl, Image image, out ImageFrame frame) where TPixel : unmanaged, IPixel { frame = image.Frames.CreateFrame(); - APngFrameMetadata frameMetadata = frame.Metadata.GetAPngFrameMetadata(); + PngFrameMetadata frameMetadata = frame.Metadata.GetPngFrameMetadata(); frameMetadata.FromChunk(frameControl); @@ -716,7 +682,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals { int currentRow = Adam7.FirstRow[0]; int currentRowBytesRead = 0; - int height = image.Metadata.TryGetAPngFrameMetadata(out APngFrameMetadata? frameMetadata) ? frameMetadata.Height : this.header.Height; + int height = image.Metadata.TryGetPngFrameMetadata(out PngFrameMetadata? frameMetadata) ? frameMetadata.Height : this.header.Height; while (currentRow < height) { cancellationToken.ThrowIfCancellationRequested(); @@ -763,7 +729,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals this.ProcessDefilteredScanline(currentRow, scanlineSpan, image, pngMetadata); this.SwapScanlineBuffers(); - ++currentRow; + currentRow++; } } @@ -784,7 +750,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals int pass = 0; int width = this.header.Width; int height = this.header.Height; - if (image.Metadata.TryGetAPngFrameMetadata(out APngFrameMetadata? frameMetadata)) + if (image.Metadata.TryGetPngFrameMetadata(out PngFrameMetadata? frameMetadata)) { width = frameMetadata.Width; height = frameMetadata.Height; @@ -797,7 +763,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals if (numColumns == 0) { - ++pass; + pass++; // This pass contains no data; skip to next pass continue; @@ -1124,7 +1090,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals /// The containing data. private void ReadAnimationControlChunk(PngMetadata pngMetadata, ReadOnlySpan data) { - this.animationControl = APngAnimationControl.Parse(data); + this.animationControl = AnimationControl.Parse(data); pngMetadata.NumberPlays = this.animationControl.NumberPlays; } @@ -1133,9 +1099,9 @@ internal sealed class PngDecoderCore : IImageDecoderInternals /// Reads a header chunk from the data. /// /// The containing data. - private APngFrameControl ReadFrameControlChunk(ReadOnlySpan data) + private FrameControl ReadFrameControlChunk(ReadOnlySpan data) { - APngFrameControl fcTL = APngFrameControl.Parse(data); + FrameControl fcTL = FrameControl.Parse(data); fcTL.Validate(this.header); diff --git a/src/ImageSharp/Formats/Png/APngDisposeOperation.cs b/src/ImageSharp/Formats/Png/PngDisposeOperation.cs similarity index 95% rename from src/ImageSharp/Formats/Png/APngDisposeOperation.cs rename to src/ImageSharp/Formats/Png/PngDisposeOperation.cs index 7b39a220d3..17a5091252 100644 --- a/src/ImageSharp/Formats/Png/APngDisposeOperation.cs +++ b/src/ImageSharp/Formats/Png/PngDisposeOperation.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Png; /// /// Specifies how the output buffer should be changed at the end of the delay (before rendering the next frame). /// -public enum APngDisposeOperation +public enum PngDisposeOperation { /// /// No disposal is done on this frame before rendering the next; the contents of the output buffer are left as is. diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs index bf8b23b8f0..a4ae1ca0b9 100644 --- a/src/ImageSharp/Formats/Png/PngEncoder.cs +++ b/src/ImageSharp/Formats/Png/PngEncoder.cs @@ -19,11 +19,6 @@ public class PngEncoder : QuantizingImageEncoder // quantizer with options appropriate to the encoding bit depth. this.Quantizer = null!; - /// - /// Gets whether the file is a simple PNG. - /// - public bool? IsSimplePng { get; init; } - /// /// Gets the number of bits per sample or per palette index (not per pixel). /// Not all values are allowed for all values. diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 1550417890..da2dc62103 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -25,7 +25,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable /// /// The maximum block size, defaults at 64k for uncompressed blocks. /// - private const int MaxBlockSize = (1 << 16) - 1; + private const int MaxBlockSize = 65535; /// /// Used the manage memory allocations. @@ -168,20 +168,19 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable this.WriteXmpChunk(stream, metadata); this.WriteTextChunks(stream, pngMetadata); - if ((this.encoder.IsSimplePng is null && targetImage.Frames.Count > 1) - || this.encoder.IsSimplePng is false) + if (targetImage.Frames.Count > 1) { this.WriteAnimationControlChunk(stream, targetImage.Frames.Count, pngMetadata.NumberPlays); - this.WriteFrameControlChunk(stream, targetImage.Frames.RootFrame.Metadata.GetAPngFrameMetadata(), 0); + this.WriteFrameControlChunk(stream, targetImage.Frames.RootFrame.Metadata.GetPngFrameMetadata(), 0); _ = this.WriteDataChunks(targetImage.Frames.RootFrame, rootQuantized, stream, false); int index = 1; foreach (ImageFrame imageFrame in ((IEnumerable>)targetImage.Frames).Skip(1)) { - this.WriteFrameControlChunk(stream, imageFrame.Metadata.GetAPngFrameMetadata(), index); - ++index; + this.WriteFrameControlChunk(stream, imageFrame.Metadata.GetPngFrameMetadata(), index); + index++; IndexedImageFrame? quantized = this.CreateQuantizedImageAndUpdateBitDepth(imageFrame); index += this.WriteDataChunks(imageFrame, quantized, stream, true, index); quantized?.Dispose(); @@ -225,10 +224,10 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable // TODO: We should be able to speed this up with SIMD and masking. Rgba32 rgba32 = default; Rgba32 transparent = Color.Transparent; - for (int y = 0; y < accessor.Height; ++y) + for (int y = 0; y < accessor.Height; y++) { Span span = accessor.GetRowSpan(y); - for (int x = 0; x < accessor.Width; ++x) + for (int x = 0; x < accessor.Width; x++) { span[x].ToRgba32(ref rgba32); @@ -278,7 +277,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable PixelOperations.Instance.ToL16(this.configuration, rowSpan, luminanceSpan); // Can't map directly to byte array as it's big-endian. - for (int x = 0, o = 0; x < luminanceSpan.Length; ++x, o += 2) + for (int x = 0, o = 0; x < luminanceSpan.Length; x++, o += 2) { L16 luminance = Unsafe.Add(ref luminanceRef, (uint)x); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), luminance.PackedValue); @@ -318,7 +317,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable PixelOperations.Instance.ToLa32(this.configuration, rowSpan, laSpan); // Can't map directly to byte array as it's big endian. - for (int x = 0, o = 0; x < laSpan.Length; ++x, o += 4) + for (int x = 0, o = 0; x < laSpan.Length; x++, o += 4) { La32 la = Unsafe.Add(ref laRef, (uint)x); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), la.L); @@ -602,11 +601,11 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable /// The number of times to loop this APNG. private void WriteAnimationControlChunk(Stream stream, int framesCount, int playsCount) { - APngAnimationControl acTL = new(framesCount, playsCount); + AnimationControl acTL = new(framesCount, playsCount); acTL.WriteTo(this.chunkDataBuffer.Span); - this.WriteChunk(stream, PngChunkType.AnimationControl, this.chunkDataBuffer.Span, 0, APngAnimationControl.Size); + this.WriteChunk(stream, PngChunkType.AnimationControl, this.chunkDataBuffer.Span, 0, AnimationControl.Size); } /// @@ -643,7 +642,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable ref Rgba32 rgbaPaletteRef = ref MemoryMarshal.GetReference(rgbaPaletteSpan); // Loop, assign, and extract alpha values from the palette. - for (int i = 0; i < paletteLength; ++i) + for (int i = 0; i < paletteLength; i++) { Rgba32 rgba = Unsafe.Add(ref rgbaPaletteRef, (uint)i); byte alpha = rgba.A; @@ -963,13 +962,13 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable /// The containing image data. /// Provides APng specific metadata information for the image frame. /// Sequence number. - private void WriteFrameControlChunk(Stream stream, APngFrameMetadata frameMetadata, int sequenceNumber) + private void WriteFrameControlChunk(Stream stream, PngFrameMetadata frameMetadata, int sequenceNumber) { - APngFrameControl fcTL = APngFrameControl.FromMetadata(frameMetadata, sequenceNumber); + FrameControl fcTL = FrameControl.FromMetadata(frameMetadata, sequenceNumber); fcTL.WriteTo(this.chunkDataBuffer.Span); - this.WriteChunk(stream, PngChunkType.FrameControl, this.chunkDataBuffer.Span, 0, APngFrameControl.Size); + this.WriteChunk(stream, PngChunkType.FrameControl, this.chunkDataBuffer.Span, 0, FrameControl.Size); } /// @@ -1024,10 +1023,10 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable if (bufferLength % maxBlockSize != 0) { - ++numChunks; + numChunks++; } - for (int i = 0; i < numChunks; ++i) + for (int i = 0; i < numChunks; i++) { int length = bufferLength - (i * maxBlockSize); @@ -1078,7 +1077,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable { int width = this.width; int height = this.height; - if (pixels.Metadata.TryGetAPngFrameMetadata(out APngFrameMetadata? pngMetadata)) + if (pixels.Metadata.TryGetAPngFrameMetadata(out PngFrameMetadata? pngMetadata)) { width = pngMetadata.Width; height = pngMetadata.Height; @@ -1095,7 +1094,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable { Span filter = filterBuffer.GetSpan(); Span attempt = attemptBuffer.GetSpan(); - for (int y = 0; y < height; ++y) + for (int y = 0; y < height; y++) { this.CollectAndFilterPixelRow(accessor.GetRowSpan(y), ref filter, ref attempt, quantized, y); deflateStream.Write(filter); @@ -1201,7 +1200,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable col += Adam7.ColumnIncrement[pass]) { block[i] = srcRow[col]; - ++i; + i++; } // Encode data diff --git a/src/ImageSharp/Formats/Png/PngFormat.cs b/src/ImageSharp/Formats/Png/PngFormat.cs index 292f087f27..e5852affa9 100644 --- a/src/ImageSharp/Formats/Png/PngFormat.cs +++ b/src/ImageSharp/Formats/Png/PngFormat.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Png; /// /// Registers the image encoders, decoders and mime type detectors for the png format. /// -public sealed class PngFormat : IImageFormat +public sealed class PngFormat : IImageFormat { private PngFormat() { @@ -33,5 +33,5 @@ public sealed class PngFormat : IImageFormat public PngMetadata CreateDefaultFormatMetadata() => new(); /// - public APngFrameMetadata CreateDefaultFormatFrameMetadata() => new(); + public PngFrameMetadata CreateDefaultFormatFrameMetadata() => new(); } diff --git a/src/ImageSharp/Formats/Png/APngFrameMetadata.cs b/src/ImageSharp/Formats/Png/PngFrameMetadata.cs similarity index 79% rename from src/ImageSharp/Formats/Png/APngFrameMetadata.cs rename to src/ImageSharp/Formats/Png/PngFrameMetadata.cs index f4f5fec916..76d4330562 100644 --- a/src/ImageSharp/Formats/Png/APngFrameMetadata.cs +++ b/src/ImageSharp/Formats/Png/PngFrameMetadata.cs @@ -8,20 +8,20 @@ namespace SixLabors.ImageSharp.Formats.Png; /// /// Provides APng specific metadata information for the image frame. /// -public class APngFrameMetadata : IDeepCloneable +public class PngFrameMetadata : IDeepCloneable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public APngFrameMetadata() + public PngFrameMetadata() { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The metadata to create an instance from. - private APngFrameMetadata(APngFrameMetadata other) + private PngFrameMetadata(PngFrameMetadata other) { this.Width = other.Width; this.Height = other.Height; @@ -66,18 +66,18 @@ public class APngFrameMetadata : IDeepCloneable /// /// Gets or sets the type of frame area disposal to be done after rendering this frame /// - public APngDisposeOperation DisposeOperation { get; set; } + public PngDisposeOperation DisposeOperation { get; set; } /// /// Gets or sets the type of frame area rendering for this frame /// - public APngBlendOperation BlendOperation { get; set; } + public PngBlendOperation BlendOperation { get; set; } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The chunk to create an instance from. - internal void FromChunk(APngFrameControl frameControl) + internal void FromChunk(FrameControl frameControl) { this.Width = frameControl.Width; this.Height = frameControl.Height; @@ -90,5 +90,5 @@ public class APngFrameMetadata : IDeepCloneable } /// - public IDeepCloneable DeepClone() => new APngFrameMetadata(this); + public IDeepCloneable DeepClone() => new PngFrameMetadata(this); } diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 57608a9090..75d4b173c8 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -13,7 +13,6 @@ Image Resize Crop Gif Jpg Jpeg Bitmap Pbm Png Tga Tiff WebP NetCore A new, fully featured, fully managed, cross-platform, 2D graphics API for .NET Debug;Release - preview