@@ -42,7 +42,6 @@ public static void ProcessInterlacedGrayscaleScanline<TPixel>(
4242 where TPixel : unmanaged, IPixel < TPixel >
4343 {
4444 uint offset = pixelOffset + frameControl . XOffset ;
45- TPixel pixel = default ;
4645 ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
4746 ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
4847 int scaleFactor = 255 / ( ColorNumerics . GetColorCountForBitDepth ( bitDepth ) - 1 ) ;
@@ -55,17 +54,15 @@ public static void ProcessInterlacedGrayscaleScanline<TPixel>(
5554 for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += 2 )
5655 {
5756 ushort luminance = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , 2 ) ) ;
58- pixel . FromL16 ( Unsafe . As < ushort , L16 > ( ref luminance ) ) ;
59- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
57+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromL16 ( Unsafe . As < ushort , L16 > ( ref luminance ) ) ;
6058 }
6159 }
6260 else
6361 {
6462 for ( nuint x = offset , o = 0 ; x < frameControl . XMax ; x += increment , o ++ )
6563 {
6664 byte luminance = ( byte ) ( Unsafe . Add ( ref scanlineSpanRef , o ) * scaleFactor ) ;
67- pixel . FromL8 ( Unsafe . As < byte , L8 > ( ref luminance ) ) ;
68- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
65+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromL8 ( Unsafe . As < byte , L8 > ( ref luminance ) ) ;
6966 }
7067 }
7168
@@ -75,30 +72,22 @@ public static void ProcessInterlacedGrayscaleScanline<TPixel>(
7572 if ( bitDepth == 16 )
7673 {
7774 L16 transparent = transparentColor . Value . ToPixel < L16 > ( ) ;
78- La32 source = default ;
7975 int o = 0 ;
8076 for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += 2 )
8177 {
8278 ushort luminance = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , 2 ) ) ;
83- source . L = luminance ;
84- source . A = luminance . Equals ( transparent . PackedValue ) ? ushort . MinValue : ushort . MaxValue ;
85-
86- pixel . FromLa32 ( source ) ;
87- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
79+ La32 source = new ( luminance , luminance . Equals ( transparent . PackedValue ) ? ushort . MinValue : ushort . MaxValue ) ;
80+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromLa32 ( source ) ;
8881 }
8982 }
9083 else
9184 {
9285 byte transparent = ( byte ) ( transparentColor . Value . ToPixel < L8 > ( ) . PackedValue * scaleFactor ) ;
93- La16 source = default ;
9486 for ( nuint x = offset , o = 0 ; x < frameControl . XMax ; x += increment , o ++ )
9587 {
9688 byte luminance = ( byte ) ( Unsafe . Add ( ref scanlineSpanRef , o ) * scaleFactor ) ;
97- source . L = luminance ;
98- source . A = luminance . Equals ( transparent ) ? byte . MinValue : byte . MaxValue ;
99-
100- pixel . FromLa16 ( source ) ;
101- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
89+ La16 source = new ( luminance , luminance . Equals ( transparent ) ? byte . MinValue : byte . MaxValue ) ;
90+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromLa16 ( source ) ;
10291 }
10392 }
10493 }
@@ -133,34 +122,28 @@ public static void ProcessInterlacedGrayscaleWithAlphaScanline<TPixel>(
133122 where TPixel : unmanaged, IPixel < TPixel >
134123 {
135124 uint offset = pixelOffset + frameControl . XOffset ;
136- TPixel pixel = default ;
137125 ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
138126 ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
139127
140128 if ( bitDepth == 16 )
141129 {
142- La32 source = default ;
143130 int o = 0 ;
144131 for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += 4 )
145132 {
146- source . L = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , 2 ) ) ;
147- source . A = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + 2 , 2 ) ) ;
133+ ushort l = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , 2 ) ) ;
134+ ushort a = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + 2 , 2 ) ) ;
148135
149- pixel . FromLa32 ( source ) ;
150- Unsafe . Add ( ref rowSpanRef , ( uint ) x ) = pixel;
136+ Unsafe . Add ( ref rowSpanRef , ( uint ) x ) = TPixel. FromLa32 ( new ( l , a ) ) ;
151137 }
152138 }
153139 else
154140 {
155- La16 source = default ;
156141 nuint offset2 = 0 ;
157142 for ( nuint x = offset ; x < frameControl . XMax ; x += increment )
158143 {
159- source . L = Unsafe . Add ( ref scanlineSpanRef , offset2 ) ;
160- source . A = Unsafe . Add ( ref scanlineSpanRef , offset2 + bytesPerSample ) ;
161-
162- pixel . FromLa16 ( source ) ;
163- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
144+ byte l = Unsafe . Add ( ref scanlineSpanRef , offset2 ) ;
145+ byte a = Unsafe . Add ( ref scanlineSpanRef , offset2 + bytesPerSample ) ;
146+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromLa16 ( new ( l , a ) ) ;
164147 offset2 += bytesPerPixel ;
165148 }
166149 }
@@ -194,16 +177,14 @@ public static void ProcessInterlacedPaletteScanline<TPixel>(
194177 PngThrowHelper . ThrowMissingPalette ( ) ;
195178 }
196179
197- TPixel pixel = default ;
198180 ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
199181 ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
200182 ref Color paletteBase = ref MemoryMarshal . GetReference ( palette . Value . Span ) ;
201183
202184 for ( nuint x = pixelOffset , o = 0 ; x < frameControl . XMax ; x += increment , o ++ )
203185 {
204186 uint index = Unsafe . Add ( ref scanlineSpanRef , o ) ;
205- pixel . FromRgba32 ( Unsafe . Add ( ref paletteBase , index ) . ToPixel < Rgba32 > ( ) ) ;
206- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
187+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgba32 ( Unsafe . Add ( ref paletteBase , index ) . ToPixel < Rgba32 > ( ) ) ;
207188 }
208189 }
209190
@@ -243,25 +224,20 @@ public static void ProcessInterlacedRgbScanline<TPixel>(
243224 where TPixel : unmanaged, IPixel < TPixel >
244225 {
245226 uint offset = pixelOffset + frameControl . XOffset ;
246-
247- TPixel pixel = default ;
248227 ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
249228 ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
250229
251230 if ( transparentColor is null )
252231 {
253232 if ( bitDepth == 16 )
254233 {
255- Rgb48 rgb48 = default ;
256234 int o = 0 ;
257235 for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
258236 {
259- rgb48 . R = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , bytesPerSample ) ) ;
260- rgb48 . G = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + bytesPerSample , bytesPerSample ) ) ;
261- rgb48 . B = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 2 * bytesPerSample ) , bytesPerSample ) ) ;
262-
263- pixel . FromRgb48 ( rgb48 ) ;
264- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
237+ ushort r = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , bytesPerSample ) ) ;
238+ ushort g = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + bytesPerSample , bytesPerSample ) ) ;
239+ ushort b = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 2 * bytesPerSample ) , bytesPerSample ) ) ;
240+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgb48 ( new ( r , g , b ) ) ;
265241 }
266242 }
267243 else if ( pixelOffset == 0 && increment == 1 )
@@ -274,16 +250,13 @@ public static void ProcessInterlacedRgbScanline<TPixel>(
274250 }
275251 else
276252 {
277- Rgb24 rgb = default ;
278253 int o = 0 ;
279254 for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
280255 {
281- rgb . R = Unsafe . Add ( ref scanlineSpanRef , ( uint ) o ) ;
282- rgb . G = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + bytesPerSample ) ) ;
283- rgb . B = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 2 * bytesPerSample ) ) ) ;
284-
285- pixel . FromRgb24 ( rgb ) ;
286- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
256+ byte r = Unsafe . Add ( ref scanlineSpanRef , ( uint ) o ) ;
257+ byte g = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + bytesPerSample ) ) ;
258+ byte b = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 2 * bytesPerSample ) ) ) ;
259+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgb24 ( new ( r , g , b ) ) ;
287260 }
288261 }
289262
@@ -293,27 +266,20 @@ public static void ProcessInterlacedRgbScanline<TPixel>(
293266 if ( bitDepth == 16 )
294267 {
295268 Rgb48 transparent = transparentColor . Value . ToPixel < Rgb48 > ( ) ;
296-
297- Rgb48 rgb48 = default ;
298- Rgba64 rgba64 = default ;
269+ Rgba64 rgba = default ;
299270 int o = 0 ;
300271 for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
301272 {
302- rgb48 . R = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , bytesPerSample ) ) ;
303- rgb48 . G = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + bytesPerSample , bytesPerSample ) ) ;
304- rgb48 . B = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 2 * bytesPerSample ) , bytesPerSample ) ) ;
305-
306- rgba64 . Rgb = rgb48 ;
307- rgba64 . A = rgb48 . Equals ( transparent ) ? ushort . MinValue : ushort . MaxValue ;
308-
309- pixel . FromRgba64 ( rgba64 ) ;
310- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
273+ rgba . R = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , bytesPerSample ) ) ;
274+ rgba . G = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + bytesPerSample , bytesPerSample ) ) ;
275+ rgba . B = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 2 * bytesPerSample ) , bytesPerSample ) ) ;
276+ rgba . A = rgba . Rgb . Equals ( transparent ) ? ushort . MinValue : ushort . MaxValue ;
277+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgba64 ( rgba ) ;
311278 }
312279 }
313280 else
314281 {
315282 Rgb24 transparent = transparentColor . Value . ToPixel < Rgb24 > ( ) ;
316-
317283 Rgba32 rgba = default ;
318284 int o = 0 ;
319285 for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
@@ -322,9 +288,7 @@ public static void ProcessInterlacedRgbScanline<TPixel>(
322288 rgba . G = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + bytesPerSample ) ) ;
323289 rgba . B = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 2 * bytesPerSample ) ) ) ;
324290 rgba . A = transparent . Equals ( rgba . Rgb ) ? byte . MinValue : byte . MaxValue ;
325-
326- pixel . FromRgba32 ( rgba ) ;
327- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
291+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgba32 ( rgba ) ;
328292 }
329293 }
330294 }
@@ -362,22 +326,18 @@ public static void ProcessInterlacedRgbaScanline<TPixel>(
362326 where TPixel : unmanaged, IPixel < TPixel >
363327 {
364328 uint offset = pixelOffset + frameControl . XOffset ;
365- TPixel pixel = default ;
366329 ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
367330
368331 if ( bitDepth == 16 )
369332 {
370- Rgba64 rgba64 = default ;
371333 int o = 0 ;
372334 for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
373335 {
374- rgba64 . R = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , bytesPerSample ) ) ;
375- rgba64 . G = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + bytesPerSample , bytesPerSample ) ) ;
376- rgba64 . B = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 2 * bytesPerSample ) , bytesPerSample ) ) ;
377- rgba64 . A = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 3 * bytesPerSample ) , bytesPerSample ) ) ;
378-
379- pixel . FromRgba64 ( rgba64 ) ;
380- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
336+ ushort r = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , bytesPerSample ) ) ;
337+ ushort g = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + bytesPerSample , bytesPerSample ) ) ;
338+ ushort b = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 2 * bytesPerSample ) , bytesPerSample ) ) ;
339+ ushort a = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 3 * bytesPerSample ) , bytesPerSample ) ) ;
340+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgba64 ( new ( r , g , b , a ) ) ;
381341 }
382342 }
383343 else if ( pixelOffset == 0 && increment == 1 )
@@ -391,17 +351,14 @@ public static void ProcessInterlacedRgbaScanline<TPixel>(
391351 else
392352 {
393353 ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
394- Rgba32 rgba = default ;
395354 int o = 0 ;
396355 for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
397356 {
398- rgba . R = Unsafe . Add ( ref scanlineSpanRef , ( uint ) o ) ;
399- rgba . G = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + bytesPerSample ) ) ;
400- rgba . B = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 2 * bytesPerSample ) ) ) ;
401- rgba . A = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 3 * bytesPerSample ) ) ) ;
402-
403- pixel . FromRgba32 ( rgba ) ;
404- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
357+ byte r = Unsafe . Add ( ref scanlineSpanRef , ( uint ) o ) ;
358+ byte g = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + bytesPerSample ) ) ;
359+ byte b = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 2 * bytesPerSample ) ) ) ;
360+ byte a = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 3 * bytesPerSample ) ) ) ;
361+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgba32 ( new ( r , g , b , a ) ) ;
405362 }
406363 }
407364 }
0 commit comments