@@ -28,11 +28,6 @@ namespace SixLabors.ImageSharp.Formats.Png;
2828/// </summary>
2929internal 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
0 commit comments