@@ -9,69 +9,89 @@ namespace CSharpImageLibrary
99{
1010 public partial class ImageFormats
1111 {
12+ /// <summary>
13+ /// Length of header in bytes when Additional DX10 Header is present.
14+ /// </summary>
15+ public const int DDS_DX10_HEADER_LENGTH = 148 ;
16+
17+
18+ /// <summary>
19+ /// Length of header when pre-DX10 format.
20+ /// </summary>
21+ public const int DDS_NO_DX10_HEADER_LENGTH = 128 ;
22+
23+
24+
1225 /// <summary>
1326 /// Detailed representation of an image format.
1427 /// </summary>
1528 [ DebuggerDisplay ( "Format: {Format}, ComponentSize: {ComponentSize}" ) ]
1629 public class ImageEngineFormatDetails
1730 {
31+ /// <summary>
32+ /// Length of header (DDS only)
33+ /// </summary>
34+ public int HeaderSize => Format == ImageEngineFormat . DDS_DX10 ? DDS_DX10_HEADER_LENGTH : DDS_NO_DX10_HEADER_LENGTH ;
35+
36+
1837 /// <summary>
1938 /// Format of details.
2039 /// </summary>
21- public ImageEngineFormat Format ;
40+ public ImageEngineFormat Format { get ; }
2241
2342 /// <summary>
2443 /// Indicates whether format contains premultiplied alpha.
2544 /// </summary>
26- public bool IsPremultipliedFormat ;
45+ public bool IsPremultipliedFormat => Format == ImageEngineFormat . DDS_DXT2 || Format == ImageEngineFormat . DDS_DXT4 ;
2746
2847 /// <summary>
2948 /// Number of bytes in colour.
3049 /// </summary>
31- public int ComponentSize ;
50+ public int ComponentSize => ( BitCount / 8 ) / MaxNumberOfChannels ;
3251
3352 /// <summary>
3453 /// Number of bits in colour.
3554 /// </summary>
36- public int BitCount ;
55+ public int BitCount { get ; }
3756
3857 /// <summary>
3958 /// Indicates whether supported format is Block Compressed.
4059 /// </summary>
41- public bool IsBlockCompressed ;
60+ public bool IsBlockCompressed => IsBlockCompressed ( Format ) ;
4261
4362 /// <summary>
4463 /// Indicates whether format supports mipmaps.
4564 /// </summary>
46- public bool IsMippable ;
65+ public bool IsMippable => IsFormatMippable ( Format ) ;
4766
4867 /// <summary>
4968 /// Size of a discrete block in bytes. (e.g. 2 channel 8 bit colour = 2, DXT1 = 16). Block can mean texel (DXTn) or pixel (uncompressed)
5069 /// </summary>
51- public int BlockSize ;
70+ public int BlockSize => GetBlockSize ( Format , ComponentSize ) ;
5271
5372 /// <summary>
5473 /// String representation of formats' file extension. No '.'.
5574 /// </summary>
56- public string Extension ;
75+ public string Extension => Supported_Extension . ToString ( ) ;
5776
5877 /// <summary>
5978 /// Enum version of formats' file extension.
6079 /// </summary>
61- public SupportedExtensions Supported_Extension ;
80+ public SupportedExtensions Supported_Extension => IsDDS ? SupportedExtensions . DDS : ParseExtension ( Format . ToString ( ) ) ;
6281
6382 /// <summary>
6483 /// Indicates whether format is a DDS format.
6584 /// </summary>
66- public bool IsDDS ;
85+ public bool IsDDS => Format . ToString ( ) . Contains ( "DDS" ) || Format == ImageEngineFormat . DDS_DX10 ;
6786
6887 /// <summary>
6988 /// Max number of supported channels. Usually 4, but some formats are 1 (G8), 2 (V8U8), or 3 (RGB) channels.
7089 /// </summary>
71- public int MaxNumberOfChannels ;
90+ public int MaxNumberOfChannels => MaxNumberOfChannels ( Format ) ;
7291
7392 /// <summary>
7493 /// Writes the max value to array using the correct bit styles.
94+ /// e.g. Will write int.Max when component size is int.Length (4 bytes).
7595 /// </summary>
7696 public Action < byte [ ] , int > SetMaxValue = null ;
7797
@@ -93,7 +113,14 @@ public class ImageEngineFormatDetails
93113 Func < byte [ ] , int , byte [ ] > ReadUShortAsArray = null ;
94114 Func < byte [ ] , int , byte [ ] > ReadFloatAsArray = null ;
95115
116+ /// <summary>
117+ /// Holds the encoder to be used when compressing/writing image.
118+ /// </summary>
96119 public Action < byte [ ] , int , int , byte [ ] , int , AlphaSettings , ImageEngineFormatDetails > BlockEncoder = null ;
120+
121+ /// <summary>
122+ /// Holds the decoder to be used when decompressing/reading image.
123+ /// </summary>
97124 public Action < byte [ ] , int , byte [ ] , int , int , bool > BlockDecoder = null ;
98125
99126 /// <summary>
@@ -109,13 +136,7 @@ public class ImageEngineFormatDetails
109136 public ImageEngineFormatDetails ( ImageEngineFormat inFormat , Headers . DDS_Header . DXGI_FORMAT DX10Format = new Headers . DDS_Header . DXGI_FORMAT ( ) )
110137 {
111138 Format = inFormat ;
112- IsPremultipliedFormat = inFormat == ImageEngineFormat . DDS_DXT2 || inFormat == ImageEngineFormat . DDS_DXT4 ;
113- IsDDS = inFormat . ToString ( ) . Contains ( "DDS" ) || inFormat == ImageEngineFormat . DDS_DX10 ;
114- MaxNumberOfChannels = MaxNumberOfChannels ( inFormat ) ;
115-
116- Supported_Extension = IsDDS ? SupportedExtensions . DDS : ParseExtension ( inFormat . ToString ( ) ) ;
117- Extension = Supported_Extension . ToString ( ) ;
118-
139+
119140 BitCount = 8 ;
120141 {
121142 switch ( inFormat )
@@ -161,11 +182,6 @@ public class ImageEngineFormatDetails
161182 }
162183 }
163184
164- ComponentSize = ( BitCount / 8 ) / MaxNumberOfChannels ;
165- BlockSize = GetBlockSize ( inFormat , ComponentSize ) ;
166- IsBlockCompressed = IsBlockCompressed ( inFormat ) ;
167- IsMippable = IsFormatMippable ( inFormat ) ;
168-
169185 // Functions
170186 ReadByte = ReadByteFromByte ;
171187 ReadUShort = ReadUShortFromByte ;
@@ -206,7 +222,10 @@ public class ImageEngineFormatDetails
206222 BlockEncoder = DDS_Encoders . CompressBC5Block ;
207223 break ;
208224 case ImageEngineFormat . DDS_DX10 :
209- BlockEncoder = DDS_Encoders . CompressBC7Block ;
225+ if ( DX10Format . ToString ( ) . Contains ( "BC7" ) )
226+ BlockEncoder = DDS_Encoders . CompressBC7Block ;
227+ else
228+ BlockEncoder = DDS_Encoders . CompressBC6Block ;
210229 break ;
211230 case ImageEngineFormat . DDS_DXT1 :
212231 BlockEncoder = DDS_Encoders . CompressBC1Block ;
0 commit comments