@@ -56,12 +56,8 @@ public void TgaEncoder_PreserveBitsPerPixel(string imagePath, TgaBitsPerPixel bm
5656 [ MemberData ( nameof ( TgaBitsPerPixelFiles ) ) ]
5757 public void TgaEncoder_WithCompression_PreserveBitsPerPixel ( string imagePath , TgaBitsPerPixel bmpBitsPerPixel )
5858 {
59- var options = new TgaEncoder ( )
60- {
61- Compression = TgaCompression . RunLength
62- } ;
63-
64- TestFile testFile = TestFile . Create ( imagePath ) ;
59+ var options = new TgaEncoder ( ) { Compression = TgaCompression . RunLength } ;
60+ var testFile = TestFile . Create ( imagePath ) ;
6561 using ( Image < Rgba32 > input = testFile . CreateRgba32Image ( ) )
6662 {
6763 using ( var memStream = new MemoryStream ( ) )
@@ -121,6 +117,24 @@ public void TgaEncoder_Bit24_WithRunLengthEncoding_Works<TPixel>(TestImageProvid
121117 public void TgaEncoder_Bit32_WithRunLengthEncoding_Works < TPixel > ( TestImageProvider < TPixel > provider , TgaBitsPerPixel bitsPerPixel = TgaBitsPerPixel . Pixel32 )
122118 where TPixel : unmanaged, IPixel < TPixel > => TestTgaEncoderCore ( provider , bitsPerPixel , TgaCompression . RunLength ) ;
123119
120+ [ Theory ]
121+ [ WithFile ( WhiteStripesPattern , PixelTypes . Rgba32 , 2748 ) ]
122+ public void TgaEncoder_DoesNotAlwaysUseRunLengthPackets < TPixel > ( TestImageProvider < TPixel > provider , int expectedBytes )
123+ where TPixel : unmanaged, IPixel < TPixel >
124+ {
125+ // The test image has alternating black and white pixels, which should make using always RLE data inefficient.
126+ using ( Image < TPixel > image = provider . GetImage ( ) )
127+ {
128+ var options = new TgaEncoder ( ) { Compression = TgaCompression . RunLength } ;
129+ using ( var memStream = new MemoryStream ( ) )
130+ {
131+ image . Save ( memStream , options ) ;
132+ byte [ ] imageBytes = memStream . ToArray ( ) ;
133+ Assert . Equal ( expectedBytes , imageBytes . Length ) ;
134+ }
135+ }
136+ }
137+
124138 [ Theory ]
125139 [ WithFile ( Bit32BottomLeft , PixelTypes . Rgba32 , TgaBitsPerPixel . Pixel32 ) ]
126140 [ WithFile ( Bit24BottomLeft , PixelTypes . Rgba32 , TgaBitsPerPixel . Pixel24 ) ]
0 commit comments