@@ -29,12 +29,12 @@ internal sealed class TgaDecoderCore : IImageDecoderInternals
29
29
/// <summary>
30
30
/// The metadata.
31
31
/// </summary>
32
- private ImageMetadata metadata = null ! ;
32
+ private ImageMetadata ? metadata ;
33
33
34
34
/// <summary>
35
35
/// The tga specific metadata.
36
36
/// </summary>
37
- private TgaMetadata tgaMetadata = null ! ;
37
+ private TgaMetadata ? tgaMetadata ;
38
38
39
39
/// <summary>
40
40
/// The file header containing general information about the image.
@@ -533,6 +533,9 @@ private void ReadBgra32<TPixel>(BufferedReadStream stream, int width, int height
533
533
{
534
534
TPixel color = default ;
535
535
bool invertX = InvertX ( origin ) ;
536
+
537
+ Guard . NotNull ( this . tgaMetadata ) ;
538
+
536
539
if ( this . tgaMetadata . AlphaChannelBits == 8 && ! invertX )
537
540
{
538
541
using IMemoryOwner < byte > row = this . memoryAllocator . AllocatePaddedPixelRowBuffer ( width , 4 , 0 ) ;
@@ -591,6 +594,9 @@ private void ReadRle<TPixel>(BufferedReadStream stream, int width, int height, B
591
594
where TPixel : unmanaged, IPixel < TPixel >
592
595
{
593
596
TPixel color = default ;
597
+
598
+ Guard . NotNull ( this . tgaMetadata ) ;
599
+
594
600
byte alphaBits = this . tgaMetadata . AlphaChannelBits ;
595
601
using ( IMemoryOwner < byte > buffer = this . memoryAllocator . Allocate < byte > ( width * height * bytesPerPixel , AllocationOptions . Clean ) )
596
602
{
@@ -722,6 +728,8 @@ private void ReadBgra32Pixel<TPixel>(BufferedReadStream stream, int x, TPixel co
722
728
TgaThrowHelper . ThrowInvalidImageContentException ( "Not enough data to read a bgra pixel" ) ;
723
729
}
724
730
731
+ Guard . NotNull ( this . tgaMetadata ) ;
732
+
725
733
byte alpha = this . tgaMetadata . AlphaChannelBits == 0 ? byte . MaxValue : this . scratchBuffer [ 3 ] ;
726
734
color . FromBgra32 ( new Bgra32 ( this . scratchBuffer [ 2 ] , this . scratchBuffer [ 1 ] , this . scratchBuffer [ 0 ] , alpha ) ) ;
727
735
pixelRow [ x ] = color ;
0 commit comments