@@ -61,7 +61,7 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
6161 } ;
6262 Image < TPixel > image = new ( this . configuration , ( int ) this . header . Width , ( int ) this . header . Height , metadata ) ;
6363 Buffer2D < TPixel > pixels = image . GetRootFramePixelBuffer ( ) ;
64-
64+
6565 this . ProcessPixels ( stream , pixels ) ;
6666
6767 return image ;
@@ -145,11 +145,11 @@ private void ProcessPixels<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
145145 where TPixel : unmanaged, IPixel < TPixel >
146146 {
147147 Rgba32 [ ] previouslySeenPixels = new Rgba32 [ 64 ] ;
148- Rgba32 previousPixel = new ( 0 , 0 , 0 , 255 ) ;
148+ Rgba32 previousPixel = new ( 0 , 0 , 0 , 255 ) ;
149149
150150 // We save the pixel to avoid loosing the fully opaque black pixel
151151 // See https://github.com/phoboslab/qoi/issues/258
152- int pixelArrayPosition = this . GetArrayPosition ( previousPixel ) ;
152+ int pixelArrayPosition = GetArrayPosition ( previousPixel ) ;
153153 previouslySeenPixels [ pixelArrayPosition ] = previousPixel ;
154154
155155 for ( int i = 0 ; i < this . header . Height ; i ++ )
@@ -159,11 +159,11 @@ private void ProcessPixels<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
159159 byte operationByte = ( byte ) stream . ReadByte ( ) ;
160160 byte [ ] pixelBytes ;
161161 Rgba32 readPixel ;
162- TPixel pixel = new ( ) ;
162+ TPixel pixel = default ;
163163 switch ( ( QoiChunkEnum ) operationByte )
164164 {
165165 // Reading one pixel with previous alpha intact
166- case QoiChunkEnum . QOI_OP_RGB :
166+ case QoiChunkEnum . QoiOpRgb :
167167 pixelBytes = new byte [ 3 ] ;
168168 if ( stream . Read ( pixelBytes ) < 3 )
169169 {
@@ -172,12 +172,12 @@ private void ProcessPixels<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
172172
173173 readPixel = previousPixel with { R = pixelBytes [ 0 ] , G = pixelBytes [ 1 ] , B = pixelBytes [ 2 ] } ;
174174 pixel . FromRgba32 ( readPixel ) ;
175- pixelArrayPosition = this . GetArrayPosition ( readPixel ) ;
175+ pixelArrayPosition = GetArrayPosition ( readPixel ) ;
176176 previouslySeenPixels [ pixelArrayPosition ] = readPixel ;
177177 break ;
178178
179179 // Reading one pixel with new alpha
180- case QoiChunkEnum . QOI_OP_RGBA :
180+ case QoiChunkEnum . QoiOpRgba :
181181 pixelBytes = new byte [ 4 ] ;
182182 if ( stream . Read ( pixelBytes ) < 4 )
183183 {
@@ -186,21 +186,21 @@ private void ProcessPixels<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
186186
187187 readPixel = new Rgba32 ( pixelBytes [ 0 ] , pixelBytes [ 1 ] , pixelBytes [ 2 ] , pixelBytes [ 3 ] ) ;
188188 pixel . FromRgba32 ( readPixel ) ;
189- pixelArrayPosition = this . GetArrayPosition ( readPixel ) ;
189+ pixelArrayPosition = GetArrayPosition ( readPixel ) ;
190190 previouslySeenPixels [ pixelArrayPosition ] = readPixel ;
191191 break ;
192192
193193 default :
194194 switch ( ( QoiChunkEnum ) ( operationByte & 0b11000000 ) )
195195 {
196196 // Getting one pixel from previously seen pixels
197- case QoiChunkEnum . QOI_OP_INDEX :
197+ case QoiChunkEnum . QoiOpIndex :
198198 readPixel = previouslySeenPixels [ operationByte ] ;
199199 pixel . FromRgba32 ( readPixel ) ;
200200 break ;
201201
202202 // Get one pixel from the difference (-2..1) of the previous pixel
203- case QoiChunkEnum . QOI_OP_DIFF :
203+ case QoiChunkEnum . QoiOpDiff :
204204 byte redDifference = ( byte ) ( ( operationByte & 0b00110000 ) >> 4 ) ,
205205 greenDifference = ( byte ) ( ( operationByte & 0b00001100 ) >> 2 ) ,
206206 blueDifference = ( byte ) ( operationByte & 0b00000011 ) ;
@@ -211,30 +211,30 @@ private void ProcessPixels<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
211211 B = ( byte ) ( ( previousPixel . B + ( blueDifference - 2 ) ) % 256 )
212212 } ;
213213 pixel . FromRgba32 ( readPixel ) ;
214- pixelArrayPosition = this . GetArrayPosition ( readPixel ) ;
214+ pixelArrayPosition = GetArrayPosition ( readPixel ) ;
215215 previouslySeenPixels [ pixelArrayPosition ] = readPixel ;
216216 break ;
217217
218218 // Get green difference in 6 bits and red and blue differences
219219 // depending on the green one
220- case QoiChunkEnum . QOI_OP_LUMA :
220+ case QoiChunkEnum . QoiOpLuma :
221221 byte diffGreen = ( byte ) ( operationByte & 0b00111111 ) ,
222222 currentGreen = ( byte ) ( ( previousPixel . G + ( diffGreen - 32 ) ) % 256 ) ,
223223 nextByte = ( byte ) stream . ReadByte ( ) ,
224224 diffRedDG = ( byte ) ( nextByte >> 4 ) ,
225225 diffBlueDG = ( byte ) ( nextByte & 0b00001111 ) ,
226- currentRed = ( byte ) ( ( diffRedDG - 8 + ( diffGreen - 32 ) + previousPixel . R ) % 256 ) ,
227- currentBlue = ( byte ) ( ( diffBlueDG - 8 + ( diffGreen - 32 ) + previousPixel . B ) % 256 ) ;
226+ currentRed = ( byte ) ( ( diffRedDG - 8 + ( diffGreen - 32 ) + previousPixel . R ) % 256 ) ,
227+ currentBlue = ( byte ) ( ( diffBlueDG - 8 + ( diffGreen - 32 ) + previousPixel . B ) % 256 ) ;
228228 readPixel = previousPixel with { R = currentRed , B = currentBlue , G = currentGreen } ;
229229 pixel . FromRgba32 ( readPixel ) ;
230- pixelArrayPosition = this . GetArrayPosition ( readPixel ) ;
230+ pixelArrayPosition = GetArrayPosition ( readPixel ) ;
231231 previouslySeenPixels [ pixelArrayPosition ] = readPixel ;
232232 break ;
233233
234234 // Repeating the previous pixel 1..63 times
235- case QoiChunkEnum . QOI_OP_RUN :
235+ case QoiChunkEnum . QoiOpRun :
236236 byte repetitions = ( byte ) ( operationByte & 0b00111111 ) ;
237- if ( repetitions is 62 or 63 )
237+ if ( repetitions is 62 or 63 )
238238 {
239239 ThrowInvalidImageContentException ( ) ;
240240 }
@@ -248,7 +248,8 @@ private void ProcessPixels<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
248248 j = 0 ;
249249 i ++ ;
250250 }
251- pixels [ j , i ] = pixel ;
251+
252+ pixels [ j , i ] = pixel ;
252253 }
253254
254255 j -- ;
@@ -262,7 +263,7 @@ private void ProcessPixels<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
262263 break ;
263264 }
264265
265- pixels [ j , i ] = pixel ;
266+ pixels [ j , i ] = pixel ;
266267 previousPixel = readPixel ;
267268 }
268269 }
@@ -282,5 +283,5 @@ private void ProcessPixels<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
282283 }
283284 }
284285
285- private int GetArrayPosition ( Rgba32 pixel ) => ( ( pixel . R * 3 ) + ( pixel . G * 5 ) + ( pixel . B * 7 ) + ( pixel . A * 11 ) ) % 64 ;
286+ private static int GetArrayPosition ( Rgba32 pixel ) => ( ( pixel . R * 3 ) + ( pixel . G * 5 ) + ( pixel . B * 7 ) + ( pixel . A * 11 ) ) % 64 ;
286287}
0 commit comments