@@ -41,7 +41,7 @@ public static void ProcessInterlacedGrayscaleScanline<TPixel>(
4141 Color ? transparentColor )
4242 where TPixel : unmanaged, IPixel < TPixel >
4343 {
44- uint offset = pixelOffset + ( uint ) frameControl . XOffset ;
44+ uint offset = pixelOffset + frameControl . XOffset ;
4545 TPixel pixel = default ;
4646 ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
4747 ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
@@ -132,7 +132,7 @@ public static void ProcessInterlacedGrayscaleWithAlphaScanline<TPixel>(
132132 uint bytesPerSample )
133133 where TPixel : unmanaged, IPixel < TPixel >
134134 {
135- uint offset = pixelOffset + ( uint ) frameControl . XOffset ;
135+ uint offset = pixelOffset + frameControl . XOffset ;
136136 TPixel pixel = default ;
137137 ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
138138 ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
@@ -242,7 +242,7 @@ public static void ProcessInterlacedRgbScanline<TPixel>(
242242 Color ? transparentColor )
243243 where TPixel : unmanaged, IPixel < TPixel >
244244 {
245- uint offset = pixelOffset + ( uint ) frameControl . XOffset ;
245+ uint offset = pixelOffset + frameControl . XOffset ;
246246
247247 TPixel pixel = default ;
248248 ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
@@ -266,20 +266,18 @@ public static void ProcessInterlacedRgbScanline<TPixel>(
266266 }
267267 else
268268 {
269- // Rgb24 rgb = default;
270- // int o = 0;
271- // for (nuint x = offset; x < frameControl.XLimit; x += increment, o += bytesPerPixel)
272- // {
273- // rgb.R = Unsafe.Add(ref scanlineSpanRef, (uint)o);
274- // rgb.G = Unsafe.Add(ref scanlineSpanRef, (uint)(o + bytesPerSample));
275- // rgb.B = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (2 * bytesPerSample)));
276-
277- // pixel.FromRgb24(rgb);
278- // Unsafe.Add(ref rowSpanRef, x) = pixel;
279- // }
280-
281- // PixelOperations<TPixel>.Instance.FromRgb24Bytes(configuration, scanlineSpan, rowSpan, header.Width);
282- PixelOperations < TPixel > . Instance . FromRgb24Bytes ( configuration , scanlineSpan , rowSpan [ ( int ) offset ..] , ( int ) frameControl . XMax ) ;
269+ // TODO: Investigate reintroducing bulk operations optimization here.
270+ Rgb24 rgb = default ;
271+ int o = 0 ;
272+ for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
273+ {
274+ rgb . R = Unsafe . Add ( ref scanlineSpanRef , ( uint ) o ) ;
275+ rgb . G = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + bytesPerSample ) ) ;
276+ rgb . B = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 2 * bytesPerSample ) ) ) ;
277+
278+ pixel . FromRgb24 ( rgb ) ;
279+ Unsafe . Add ( ref rowSpanRef , x ) = pixel;
280+ }
283281 }
284282
285283 return ;
@@ -325,7 +323,6 @@ public static void ProcessInterlacedRgbScanline<TPixel>(
325323 }
326324
327325 public static void ProcessRgbaScanline < TPixel > (
328- Configuration configuration ,
329326 int bitDepth ,
330327 in FrameControl frameControl ,
331328 ReadOnlySpan < byte > scanlineSpan ,
@@ -334,7 +331,6 @@ public static void ProcessRgbaScanline<TPixel>(
334331 int bytesPerSample )
335332 where TPixel : unmanaged, IPixel < TPixel > =>
336333 ProcessInterlacedRgbaScanline (
337- configuration ,
338334 bitDepth ,
339335 frameControl ,
340336 scanlineSpan ,
@@ -345,7 +341,6 @@ public static void ProcessRgbaScanline<TPixel>(
345341 bytesPerSample ) ;
346342
347343 public static void ProcessInterlacedRgbaScanline < TPixel > (
348- Configuration configuration ,
349344 int bitDepth ,
350345 in FrameControl frameControl ,
351346 ReadOnlySpan < byte > scanlineSpan ,
@@ -356,7 +351,7 @@ public static void ProcessInterlacedRgbaScanline<TPixel>(
356351 int bytesPerSample )
357352 where TPixel : unmanaged, IPixel < TPixel >
358353 {
359- uint offset = pixelOffset + ( uint ) frameControl . XOffset ;
354+ uint offset = pixelOffset + frameControl . XOffset ;
360355 TPixel pixel = default ;
361356 ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
362357
@@ -377,22 +372,20 @@ public static void ProcessInterlacedRgbaScanline<TPixel>(
377372 }
378373 else
379374 {
380- // ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan);
381- // Rgba32 rgba = default;
382- // int o = 0;
383- // for (nuint x = offset; x < frameControl.XLimit; x += increment, o += bytesPerPixel)
384- // {
385- // rgba.R = Unsafe.Add(ref scanlineSpanRef, (uint)o);
386- // rgba.G = Unsafe.Add(ref scanlineSpanRef, (uint)(o + bytesPerSample));
387- // rgba.B = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (2 * bytesPerSample)));
388- // rgba.A = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (3 * bytesPerSample)));
389-
390- // pixel.FromRgba32(rgba);
391- // Unsafe.Add(ref rowSpanRef, x) = pixel;
392- // }
393-
394- // PixelOperations<TPixel>.Instance.FromRgba32Bytes(configuration, scanlineSpan, rowSpan, header.Width);
395- PixelOperations < TPixel > . Instance . FromRgba32Bytes ( configuration , scanlineSpan , rowSpan [ ( int ) offset ..] , ( int ) frameControl . XMax ) ;
375+ // TODO: Investigate reintroducing bulk operations optimization here.
376+ ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
377+ Rgba32 rgba = default ;
378+ int o = 0 ;
379+ for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
380+ {
381+ rgba . R = Unsafe . Add ( ref scanlineSpanRef , ( uint ) o ) ;
382+ rgba . G = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + bytesPerSample ) ) ;
383+ rgba . B = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 2 * bytesPerSample ) ) ) ;
384+ rgba . A = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 3 * bytesPerSample ) ) ) ;
385+
386+ pixel . FromRgba32 ( rgba ) ;
387+ Unsafe . Add ( ref rowSpanRef , x ) = pixel;
388+ }
396389 }
397390 }
398391}
0 commit comments