@@ -42,37 +42,25 @@ private BmpMetadata(BmpMetadata other)
4242 public static BmpMetadata FromFormatConnectingMetadata ( FormatConnectingMetadata metadata )
4343 {
4444 int bpp = metadata . PixelTypeInfo . BitsPerPixel ;
45- if ( bpp == 1 )
45+ return bpp switch
4646 {
47- return new BmpMetadata { BitsPerPixel = BmpBitsPerPixel . Pixel1 } ;
48- }
49-
50- if ( bpp == 2 )
51- {
52- return new BmpMetadata { BitsPerPixel = BmpBitsPerPixel . Pixel2 } ;
53- }
54-
55- if ( bpp <= 4 )
56- {
57- return new BmpMetadata { BitsPerPixel = BmpBitsPerPixel . Pixel4 } ;
58- }
59-
60- if ( bpp <= 8 )
61- {
62- return new BmpMetadata { BitsPerPixel = BmpBitsPerPixel . Pixel8 } ;
63- }
64-
65- if ( bpp <= 16 )
66- {
67- return new BmpMetadata { BitsPerPixel = BmpBitsPerPixel . Pixel16 , InfoHeaderType = BmpInfoHeaderType . WinVersion3 } ;
68- }
69-
70- if ( bpp <= 24 )
71- {
72- return new BmpMetadata { BitsPerPixel = BmpBitsPerPixel . Pixel24 , InfoHeaderType = BmpInfoHeaderType . WinVersion4 } ;
73- }
74-
75- return new BmpMetadata { BitsPerPixel = BmpBitsPerPixel . Pixel32 , InfoHeaderType = BmpInfoHeaderType . WinVersion5 } ;
47+ 1 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel . Pixel1 } ,
48+ 2 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel . Pixel2 } ,
49+ <= 4 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel . Pixel4 } ,
50+ <= 8 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel . Pixel8 } ,
51+ <= 16 => new BmpMetadata
52+ {
53+ BitsPerPixel = BmpBitsPerPixel . Pixel16 , InfoHeaderType = BmpInfoHeaderType . WinVersion3
54+ } ,
55+ <= 24 => new BmpMetadata
56+ {
57+ BitsPerPixel = BmpBitsPerPixel . Pixel24 , InfoHeaderType = BmpInfoHeaderType . WinVersion4
58+ } ,
59+ _ => new BmpMetadata
60+ {
61+ BitsPerPixel = BmpBitsPerPixel . Pixel32 , InfoHeaderType = BmpInfoHeaderType . WinVersion5
62+ }
63+ } ;
7664 }
7765
7866 /// <inheritdoc/>
@@ -97,30 +85,42 @@ BmpInfoHeaderType.WinVersion5 or
9785 _ => bpp < 32 ? PixelAlphaRepresentation . None : PixelAlphaRepresentation . Unassociated
9886 } ;
9987
100- PixelComponentInfo info = this . BitsPerPixel switch
88+ PixelComponentInfo info ;
89+ PixelColorType color ;
90+ switch ( this . BitsPerPixel )
10191 {
102- BmpBitsPerPixel . Pixel1 => PixelComponentInfo . Create ( 1 , bpp , 1 ) ,
103- BmpBitsPerPixel . Pixel2 => PixelComponentInfo . Create ( 1 , bpp , 2 ) ,
104- BmpBitsPerPixel . Pixel4 => PixelComponentInfo . Create ( 1 , bpp , 4 ) ,
105- BmpBitsPerPixel . Pixel8 => PixelComponentInfo . Create ( 1 , bpp , 8 ) ,
92+ case BmpBitsPerPixel . Pixel1 :
93+ info = PixelComponentInfo . Create ( 1 , bpp , 1 ) ;
94+ color = PixelColorType . Indexed ;
95+ break ;
96+ case BmpBitsPerPixel . Pixel2 :
97+ info = PixelComponentInfo . Create ( 1 , bpp , 2 ) ;
98+ color = PixelColorType . Indexed ;
99+ break ;
100+ case BmpBitsPerPixel . Pixel4 :
101+ info = PixelComponentInfo . Create ( 1 , bpp , 4 ) ;
102+ color = PixelColorType . Indexed ;
103+ break ;
104+ case BmpBitsPerPixel . Pixel8 :
105+ info = PixelComponentInfo . Create ( 1 , bpp , 8 ) ;
106+ color = PixelColorType . Indexed ;
107+ break ;
106108
107109 // Could be 555 with padding but 565 is more common in newer bitmaps and offers
108110 // greater accuracy due to extra green precision.
109- BmpBitsPerPixel . Pixel16 => PixelComponentInfo . Create ( 3 , bpp , 5 , 6 , 5 ) ,
110- BmpBitsPerPixel . Pixel24 => PixelComponentInfo . Create ( 3 , bpp , 8 , 8 , 8 ) ,
111- BmpBitsPerPixel . Pixel32 or _ => PixelComponentInfo . Create ( 4 , bpp , 8 , 8 , 8 , 8 ) ,
112- } ;
113-
114- PixelColorType color = this . BitsPerPixel switch
115- {
116- BmpBitsPerPixel . Pixel1 or
117- BmpBitsPerPixel . Pixel2 or
118- BmpBitsPerPixel . Pixel4 or
119- BmpBitsPerPixel . Pixel8 => PixelColorType . Indexed ,
120- BmpBitsPerPixel . Pixel16 or
121- BmpBitsPerPixel . Pixel24 => PixelColorType . RGB ,
122- BmpBitsPerPixel . Pixel32 or _ => PixelColorType . RGB | PixelColorType . Alpha ,
123- } ;
111+ case BmpBitsPerPixel . Pixel16 :
112+ info = PixelComponentInfo . Create ( 3 , bpp , 5 , 6 , 5 ) ;
113+ color = PixelColorType . RGB ;
114+ break ;
115+ case BmpBitsPerPixel . Pixel24 :
116+ info = PixelComponentInfo . Create ( 3 , bpp , 8 , 8 , 8 ) ;
117+ color = PixelColorType . RGB ;
118+ break ;
119+ case BmpBitsPerPixel . Pixel32 or _:
120+ info = PixelComponentInfo . Create ( 4 , bpp , 8 , 8 , 8 , 8 ) ;
121+ color = PixelColorType . RGB | PixelColorType . Alpha ;
122+ break ;
123+ }
124124
125125 return new ( )
126126 {
0 commit comments