@@ -56,6 +56,9 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
5656 VerticalResolution = this . header . Height ,
5757 ResolutionUnits = PixelResolutionUnit . AspectRatio
5858 } ;
59+ QoiMetadata qoiMetadata = metadata . GetQoiMetadata ( ) ;
60+ qoiMetadata . Channels = this . header . Channels ;
61+ qoiMetadata . ColorSpace = this . header . ColorSpace ;
5962 Image < TPixel > image = new ( this . configuration , ( int ) this . header . Width , ( int ) this . header . Height , metadata ) ;
6063 Buffer2D < TPixel > pixels = image . GetRootFramePixelBuffer ( ) ;
6164
@@ -112,8 +115,8 @@ private void ProcessHeader(BufferedReadStream stream)
112115 }
113116
114117 // These numbers are in Big Endian so we have to reverse them to get the real number
115- uint width = BinaryPrimitives . ReadUInt32BigEndian ( widthBytes ) ,
116- height = BinaryPrimitives . ReadUInt32BigEndian ( heightBytes ) ;
118+ uint width = BinaryPrimitives . ReadUInt32BigEndian ( widthBytes ) ;
119+ uint height = BinaryPrimitives . ReadUInt32BigEndian ( heightBytes ) ;
117120 if ( width == 0 || height == 0 )
118121 {
119122 throw new InvalidImageContentException (
@@ -126,8 +129,6 @@ private void ProcessHeader(BufferedReadStream stream)
126129 ThrowInvalidImageContentException ( ) ;
127130 }
128131
129- PixelTypeInfo pixelType = new ( 8 * channels ) ;
130-
131132 int colorSpace = stream . ReadByte ( ) ;
132133 if ( colorSpace is - 1 or ( not 0 and not 1 ) )
133134 {
@@ -201,9 +202,9 @@ private void ProcessPixels<TPixel>(BufferedReadStream stream, Buffer2D<TPixel> p
201202
202203 // Get one pixel from the difference (-2..1) of the previous pixel
203204 case QoiChunk . QoiOpDiff :
204- byte redDifference = ( byte ) ( ( operationByte & 0b00110000 ) >> 4 ) ,
205- greenDifference = ( byte ) ( ( operationByte & 0b00001100 ) >> 2 ) ,
206- blueDifference = ( byte ) ( operationByte & 0b00000011 ) ;
205+ byte redDifference = ( byte ) ( ( operationByte & 0b00110000 ) >> 4 ) ;
206+ byte greenDifference = ( byte ) ( ( operationByte & 0b00001100 ) >> 2 ) ;
207+ byte blueDifference = ( byte ) ( operationByte & 0b00000011 ) ;
207208 readPixel = previousPixel with
208209 {
209210 R = ( byte ) Numerics . Modulo256 ( previousPixel . R + ( redDifference - 2 ) ) ,
@@ -218,13 +219,13 @@ private void ProcessPixels<TPixel>(BufferedReadStream stream, Buffer2D<TPixel> p
218219 // Get green difference in 6 bits and red and blue differences
219220 // depending on the green one
220221 case QoiChunk . QoiOpLuma :
221- byte diffGreen = ( byte ) ( operationByte & 0b00111111 ) ,
222- currentGreen = ( byte ) Numerics . Modulo256 ( previousPixel . G + ( diffGreen - 32 ) ) ,
223- nextByte = ( byte ) stream . ReadByte ( ) ,
224- diffRedDG = ( byte ) ( nextByte >> 4 ) ,
225- diffBlueDG = ( byte ) ( nextByte & 0b00001111 ) ,
226- currentRed = ( byte ) Numerics . Modulo256 ( diffRedDG - 8 + ( diffGreen - 32 ) + previousPixel . R ) ,
227- currentBlue = ( byte ) Numerics . Modulo256 ( diffBlueDG - 8 + ( diffGreen - 32 ) + previousPixel . B ) ;
222+ byte diffGreen = ( byte ) ( operationByte & 0b00111111 ) ;
223+ byte currentGreen = ( byte ) Numerics . Modulo256 ( previousPixel . G + ( diffGreen - 32 ) ) ;
224+ byte nextByte = ( byte ) stream . ReadByte ( ) ;
225+ byte diffRedDG = ( byte ) ( nextByte >> 4 ) ;
226+ byte diffBlueDG = ( byte ) ( nextByte & 0b00001111 ) ;
227+ byte currentRed = ( byte ) Numerics . Modulo256 ( diffRedDG - 8 + ( diffGreen - 32 ) + previousPixel . R ) ;
228+ byte currentBlue = ( byte ) Numerics . Modulo256 ( diffBlueDG - 8 + ( diffGreen - 32 ) + previousPixel . B ) ;
228229 readPixel = previousPixel with { R = currentRed , B = currentBlue , G = currentGreen } ;
229230 pixel . FromRgba32 ( readPixel ) ;
230231 pixelArrayPosition = GetArrayPosition ( readPixel ) ;
0 commit comments