@@ -49,30 +49,31 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat
4949 {
5050 ImageMetadata metadata = new ( ) ;
5151
52- byte [ ] widthBytes , heightBytes ;
53- byte [ ] magicBytes = widthBytes = heightBytes = Array . Empty < byte > ( ) ;
52+ byte [ ] magicBytes = new byte [ 4 ] , widthBytes = new byte [ 4 ] , heightBytes = new byte [ 4 ] ;
5453
5554 // Read magic bytes
56- int read = stream . Read ( magicBytes , 0 , 4 ) ;
57- if ( read != 4 || ! magicBytes . Equals ( QoiConstants . Magic . ToArray ( ) ) )
55+ int read = stream . Read ( magicBytes ) ;
56+ if ( read != 4 || ! magicBytes . SequenceEqual ( QoiConstants . Magic . ToArray ( ) ) )
5857 {
5958 throw new InvalidImageContentException ( "The image is not a QOI image" ) ;
6059 }
6160
6261 // If it's a qoi image, read the rest of properties
63- read = stream . Read ( widthBytes , 0 , 4 ) ;
62+ read = stream . Read ( widthBytes ) ;
6463 if ( read != 4 )
6564 {
6665 throw new InvalidImageContentException ( "The image is not a QOI image" ) ;
6766 }
6867
69- read = stream . Read ( heightBytes , 0 , 4 ) ;
68+ read = stream . Read ( heightBytes ) ;
7069 if ( read != 4 )
7170 {
7271 throw new InvalidImageContentException ( "The image is not a QOI image" ) ;
7372 }
7473
75- Size size = new ( BitConverter . ToInt32 ( widthBytes ) , BitConverter . ToInt32 ( heightBytes ) ) ;
74+ widthBytes = widthBytes . Reverse ( ) . ToArray ( ) ;
75+ heightBytes = heightBytes . Reverse ( ) . ToArray ( ) ;
76+ Size size = new ( ( int ) BitConverter . ToUInt32 ( widthBytes ) , ( int ) BitConverter . ToUInt32 ( heightBytes ) ) ;
7677
7778 int channels = stream . ReadByte ( ) ;
7879 if ( channels == - 1 )
0 commit comments