@@ -56,6 +56,9 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
56
56
VerticalResolution = this . header . Height ,
57
57
ResolutionUnits = PixelResolutionUnit . AspectRatio
58
58
} ;
59
+ QoiMetadata qoiMetadata = metadata . GetQoiMetadata ( ) ;
60
+ qoiMetadata . Channels = this . header . Channels ;
61
+ qoiMetadata . ColorSpace = this . header . ColorSpace ;
59
62
Image < TPixel > image = new ( this . configuration , ( int ) this . header . Width , ( int ) this . header . Height , metadata ) ;
60
63
Buffer2D < TPixel > pixels = image . GetRootFramePixelBuffer ( ) ;
61
64
@@ -112,8 +115,8 @@ private void ProcessHeader(BufferedReadStream stream)
112
115
}
113
116
114
117
// 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 ) ;
117
120
if ( width == 0 || height == 0 )
118
121
{
119
122
throw new InvalidImageContentException (
@@ -126,8 +129,6 @@ private void ProcessHeader(BufferedReadStream stream)
126
129
ThrowInvalidImageContentException ( ) ;
127
130
}
128
131
129
- PixelTypeInfo pixelType = new ( 8 * channels ) ;
130
-
131
132
int colorSpace = stream . ReadByte ( ) ;
132
133
if ( colorSpace is - 1 or ( not 0 and not 1 ) )
133
134
{
@@ -201,9 +202,9 @@ private void ProcessPixels<TPixel>(BufferedReadStream stream, Buffer2D<TPixel> p
201
202
202
203
// Get one pixel from the difference (-2..1) of the previous pixel
203
204
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 ) ;
207
208
readPixel = previousPixel with
208
209
{
209
210
R = ( byte ) Numerics . Modulo256 ( previousPixel . R + ( redDifference - 2 ) ) ,
@@ -218,13 +219,13 @@ private void ProcessPixels<TPixel>(BufferedReadStream stream, Buffer2D<TPixel> p
218
219
// Get green difference in 6 bits and red and blue differences
219
220
// depending on the green one
220
221
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 ) ;
228
229
readPixel = previousPixel with { R = currentRed , B = currentBlue , G = currentGreen } ;
229
230
pixel . FromRgba32 ( readPixel ) ;
230
231
pixelArrayPosition = GetArrayPosition ( readPixel ) ;
0 commit comments