11using Microsoft . VisualStudio . TestTools . UnitTesting ;
22using System ;
3- using System . Collections . Generic ;
4- using System . Drawing ;
53using System . IO ;
6- using System . Text ;
7-
84
95namespace Knightware . Drawing
106{
@@ -21,19 +17,43 @@ public void DrawSolidBitmapTest()
2117 const int width = 808 ;
2218 const int height = 402 ;
2319
24- using ( var stream = BitmapHelper . GenerateSolidColorBitmap ( Primitives . Color . FromArgb ( a , r , g , b ) , width , height ) )
25- {
26- stream . Seek ( 0 , SeekOrigin . Begin ) ;
20+ using var stream = BitmapHelper . GenerateSolidColorBitmap ( Primitives . Color . FromArgb ( a , r , g , b ) , width , height ) ;
21+ stream . Seek ( 0 , SeekOrigin . Begin ) ;
22+
23+ // Parse BMP header directly (works cross-platform without System.Drawing)
24+ using var reader = new BinaryReader ( stream ) ;
25+
26+ // BMP Header (14 bytes)
27+ var signature = new string ( reader . ReadChars ( 2 ) ) ;
28+ Assert . AreEqual ( "BM" , signature , "Invalid BMP signature" ) ;
29+
30+ var fileSize = reader . ReadInt32 ( ) ;
31+ reader . ReadInt32 ( ) ; // Reserved
32+ var dataOffset = reader . ReadInt32 ( ) ;
33+
34+ // DIB Header
35+ var dibHeaderSize = reader . ReadInt32 ( ) ;
36+ var bmpWidth = reader . ReadInt32 ( ) ;
37+ var bmpHeight = reader . ReadInt32 ( ) ;
38+
39+ Assert . AreEqual ( width , bmpWidth , "Width was incorrect" ) ;
40+ Assert . AreEqual ( height , bmpHeight , "Height was incorrect" ) ;
41+
42+ // Skip to pixel data and verify color
43+ reader . ReadInt16 ( ) ; // planes
44+ var bitsPerPixel = reader . ReadInt16 ( ) ;
45+ Assert . AreEqual ( 24 , bitsPerPixel , "Expected 24-bit BMP" ) ;
46+
47+ stream . Seek ( dataOffset , SeekOrigin . Begin ) ;
2748
28- //Use System.Drawing bitmap to confirm
29- using ( var bitmap = Bitmap . FromStream ( stream ) )
30- {
31- Assert . AreEqual ( width , bitmap . Width , "Width was incorrect" ) ;
32- Assert . AreEqual ( height , bitmap . Height , "Height was incorrect" ) ;
49+ // Read first pixel (BGR order in BMP)
50+ byte pixelB = reader . ReadByte ( ) ;
51+ byte pixelG = reader . ReadByte ( ) ;
52+ byte pixelR = reader . ReadByte ( ) ;
3353
34- //TODO: Test all the pixels for the correct color
35- }
36- }
54+ Assert . AreEqual ( b , pixelB , "Blue channel was incorrect" ) ;
55+ Assert . AreEqual ( g , pixelG , "Green channel was incorrect" ) ;
56+ Assert . AreEqual ( r , pixelR , "Red channel was incorrect" ) ;
3757 }
3858 }
39- }
59+ }
0 commit comments