DDSHeader.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #region License
  2. // Copyright 2015-2016 Kastellanos Nikolaos
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using System;
  17. namespace nkast.Aether.Content.Pipeline
  18. {
  19. internal struct DDSHeader
  20. {
  21. static readonly int DDSignature = (BitConverter.IsLittleEndian) ? 0x20534444:0x44445320;
  22. public Int32 Signature;
  23. public Int32 Size;
  24. public DDS_Flags Flags;
  25. public Int32 Height;
  26. public Int32 Width;
  27. public Int32 PitchOrLinearSize;
  28. public Int32 Depth;
  29. public Int32 MipMapCount;
  30. public Int32 Reserved0, Reserved1, Reserved2, Reserved3;
  31. public Int32 Reserved4, Reserved5, Reserved6, Reserved7;
  32. public Int32 Reserved8, Reserved9, ReservedA;
  33. public DDSPixelFormat PixelFormat;
  34. public DDS_Caps Caps;
  35. public DDS_Caps2 Caps2;
  36. public Int32 Caps3;
  37. public Int32 Caps4;
  38. public Int32 ReservedB;
  39. public DDSHeader(System.IO.BinaryReader reader)
  40. {
  41. Signature = reader.ReadInt32();
  42. if (Signature != DDSHeader.DDSignature)
  43. throw new Exception("This does not appear to be a DDS file");
  44. Size = reader.ReadInt32();
  45. Flags = (DDS_Flags)reader.ReadInt32();
  46. Height = reader.ReadInt32();
  47. Width = reader.ReadInt32();
  48. PitchOrLinearSize = reader.ReadInt32();
  49. Depth = reader.ReadInt32();
  50. MipMapCount = reader.ReadInt32();
  51. Reserved0 = reader.ReadInt32();
  52. Reserved1 = reader.ReadInt32();
  53. Reserved2 = reader.ReadInt32();
  54. Reserved3 = reader.ReadInt32();
  55. Reserved4 = reader.ReadInt32();
  56. Reserved5 = reader.ReadInt32();
  57. Reserved6 = reader.ReadInt32();
  58. Reserved7 = reader.ReadInt32();
  59. Reserved8 = reader.ReadInt32();
  60. Reserved9 = reader.ReadInt32();
  61. ReservedA = reader.ReadInt32();
  62. PixelFormat = new DDSPixelFormat(reader);
  63. Caps = (DDS_Caps)reader.ReadInt32();
  64. Caps2 = (DDS_Caps2)reader.ReadInt32();
  65. Caps3 = reader.ReadInt32();
  66. Caps4 = reader.ReadInt32();
  67. ReservedB = reader.ReadInt32();
  68. }
  69. }
  70. [Flags]
  71. internal enum DDS_Flags: int
  72. {
  73. CAPS = 0x000001,
  74. HEIGHT = 0x000002,
  75. WIDTH = 0x000004,
  76. PITCH = 0x000008,
  77. PIXELFORMAT= 0x001000,
  78. MIPMAPCOUNT= 0x020000,
  79. LINEARSIZE = 0x080000,
  80. DEPTH = 0x800000,
  81. }
  82. [Flags]
  83. internal enum DDS_Caps : int
  84. {
  85. COMPLEX = 0x000008,
  86. MIPMAP = 0x400000,
  87. TEXTURE = 0x001000,
  88. }
  89. [Flags]
  90. internal enum DDS_Caps2 : int
  91. {
  92. CUBEMAP = 0x000200,
  93. CUBEMAP_POSITIVEX = 0x000400,
  94. CUBEMAP_NEGATIVEX = 0x000800,
  95. CUBEMAP_POSITIVEY = 0x001000,
  96. CUBEMAP_NEGATIVEY = 0x002000,
  97. CUBEMAP_POSITIVEZ = 0x004000,
  98. CUBEMAP_NEGATIVEZ = 0x008000,
  99. VOLUME = 0x200000,
  100. }
  101. }