il_dds.h
Upload User: wmy0603
Upload Date: 2022-05-02
Package Size: 1808k
Code Size: 6k
Development Platform:

Visual C++

  1. //-----------------------------------------------------------------------------
  2. //
  3. // ImageLib Sources
  4. // Copyright (C) 2000-2008 by Denton Woods
  5. // Last modified: 12/27/2008
  6. //
  7. // Filename: src-IL/include/il_dds.h
  8. //
  9. // Description: Reads from a DirectDraw Surface (.dds) file.
  10. //
  11. //-----------------------------------------------------------------------------
  12. #ifndef DDS_H
  13. #define DDS_H
  14. #include "il_internal.h"
  15. #ifdef _WIN32
  16. #pragma pack(push, dds_struct, 1)
  17. #endif
  18. typedef struct DDSHEAD
  19. {
  20. ILbyte Signature[4];
  21. ILuint Size1; // size of the structure (minus MagicNum)
  22. ILuint Flags1;  // determines what fields are valid
  23. ILuint Height;  // height of surface to be created
  24. ILuint Width; // width of input surface
  25. ILuint LinearSize;  // Formless late-allocated optimized surface size
  26. ILuint Depth; // Depth if a volume texture
  27. ILuint MipMapCount; // number of mip-map levels requested
  28. ILuint AlphaBitDepth; // depth of alpha buffer requested
  29. ILuint NotUsed[10];
  30. ILuint Size2; // size of structure
  31. ILuint Flags2; // pixel format flags
  32. ILuint FourCC; // (FOURCC code)
  33. ILuint RGBBitCount; // how many bits per pixel
  34. ILuint RBitMask; // mask for red bit
  35. ILuint GBitMask; // mask for green bits
  36. ILuint BBitMask; // mask for blue bits
  37. ILuint RGBAlphaBitMask; // mask for alpha channel
  38. ILuint ddsCaps1, ddsCaps2, ddsCaps3, ddsCaps4; // direct draw surface capabilities
  39. ILuint TextureStage;
  40. } IL_PACKSTRUCT DDSHEAD;
  41. #ifdef _WIN32
  42. #pragma pack(pop, dds_struct)
  43. #endif
  44. // use cast to struct instead of RGBA_MAKE as struct is
  45. //  much
  46. typedef struct Color8888
  47. {
  48. ILubyte r; // change the order of names to change the 
  49. ILubyte g; //  order of the output ARGB or BGRA, etc...
  50. ILubyte b; //  Last one is MSB, 1st is LSB.
  51. ILubyte a;
  52. } Color8888;
  53. typedef struct Color888
  54. {
  55. ILubyte r; // change the order of names to change the 
  56. ILubyte g; //  order of the output ARGB or BGRA, etc...
  57. ILubyte b; //  Last one is MSB, 1st is LSB.
  58. } Color888;
  59. typedef struct Color565
  60. {
  61. unsigned nBlue  : 5; // order of names changes
  62. unsigned nGreen : 6; //  byte order of output to 32 bit
  63. unsigned nRed : 5;
  64. } Color565;
  65. typedef struct DXTColBlock
  66. {
  67. ILshort col0;
  68. ILshort col1;
  69. // no bit fields - use bytes
  70. ILbyte row[4];
  71. } DXTColBlock;
  72. typedef struct DXTAlphaBlockExplicit
  73. {
  74. ILshort row[4];
  75. } DXTAlphaBlockExplicit;
  76. typedef struct DXTAlphaBlock3BitLinear
  77. {
  78. ILbyte alpha0;
  79. ILbyte alpha1;
  80. ILbyte stuff[6];
  81. } DXTAlphaBlock3BitLinear;
  82. // Defines
  83. //Those 4 were added on 20040516 to make
  84. //the written dds files more standard compliant
  85. #define DDS_CAPS 0x00000001L
  86. #define DDS_HEIGHT 0x00000002L
  87. #define DDS_WIDTH 0x00000004L
  88. #define DDS_RGB 0x00000040L
  89. #define DDS_PIXELFORMAT 0x00001000L
  90. #define DDS_LUMINANCE 0x00020000L
  91. #define DDS_ALPHAPIXELS 0x00000001L
  92. #define DDS_ALPHA 0x00000002L
  93. #define DDS_FOURCC 0x00000004L
  94. #define DDS_PITCH 0x00000008L
  95. #define DDS_COMPLEX 0x00000008L
  96. #define DDS_TEXTURE 0x00001000L
  97. #define DDS_MIPMAPCOUNT 0x00020000L
  98. #define DDS_LINEARSIZE 0x00080000L
  99. #define DDS_VOLUME 0x00200000L
  100. #define DDS_MIPMAP 0x00400000L
  101. #define DDS_DEPTH 0x00800000L
  102. #define DDS_CUBEMAP 0x00000200L
  103. #define DDS_CUBEMAP_POSITIVEX 0x00000400L
  104. #define DDS_CUBEMAP_NEGATIVEX 0x00000800L
  105. #define DDS_CUBEMAP_POSITIVEY 0x00001000L
  106. #define DDS_CUBEMAP_NEGATIVEY 0x00002000L
  107. #define DDS_CUBEMAP_POSITIVEZ 0x00004000L
  108. #define DDS_CUBEMAP_NEGATIVEZ 0x00008000L
  109. #define IL_MAKEFOURCC(ch0, ch1, ch2, ch3) 
  110. ((ILint)(ILbyte)(ch0) | ((ILint)(ILbyte)(ch1) << 8) |
  111. ((ILint)(ILbyte)(ch2) << 16) | ((ILint)(ILbyte)(ch3) << 24 ))
  112. enum PixFormat
  113. {
  114. PF_ARGB,
  115. PF_RGB,
  116. PF_DXT1,
  117. PF_DXT2,
  118. PF_DXT3,
  119. PF_DXT4,
  120. PF_DXT5,
  121. PF_3DC,
  122. PF_ATI1N,
  123. PF_LUMINANCE,
  124. PF_LUMINANCE_ALPHA,
  125. PF_RXGB, //Doom3 normal maps
  126. PF_A16B16G16R16,
  127. PF_R16F,
  128. PF_G16R16F,
  129. PF_A16B16G16R16F,
  130. PF_R32F,
  131. PF_G32R32F,
  132. PF_A32B32G32R32F,
  133. PF_UNKNOWN = 0xFF
  134. };
  135. #define CUBEMAP_SIDES 6
  136. // Internal functions
  137. ILboolean iLoadDdsInternal(void);
  138. ILboolean iIsValidDds(void);
  139. ILboolean iCheckDds(DDSHEAD *Head);
  140. void AdjustVolumeTexture(DDSHEAD *Head, ILuint CompFormat);
  141. ILboolean ReadData();
  142. ILboolean AllocImage(ILuint CompFormat);
  143. ILboolean DdsDecompress(ILuint CompFormat);
  144. ILboolean ReadMipmaps(ILuint CompFormat);
  145. ILuint DecodePixelFormat();
  146. void DxtcReadColor(ILushort Data, Color8888* Out);
  147. void DxtcReadColors(const ILubyte* Data, Color8888* Out);
  148. ILboolean DecompressARGB();
  149. ILboolean DecompressDXT1(ILimage *lImage, ILubyte *lCompData);
  150. ILboolean DecompressDXT2(ILimage *lImage, ILubyte *lCompData);
  151. ILboolean DecompressDXT3(ILimage *lImage, ILubyte *lCompData);
  152. ILboolean DecompressDXT4(ILimage *lImage, ILubyte *lCompData);
  153. ILboolean DecompressDXT5(ILimage *lImage, ILubyte *lCompData);
  154. ILboolean Decompress3Dc();
  155. ILboolean DecompressAti1n();
  156. ILboolean DecompressRXGB();
  157. ILboolean iConvFloat16ToFloat32(ILuint* dest, ILushort* src, ILuint size);
  158. ILboolean DecompressFloat(ILuint lCompFormat);
  159. void CorrectPreMult();
  160. void GetBitsFromMask(ILuint Mask, ILuint *ShiftLeft, ILuint *ShiftRight);
  161. ILboolean iSaveDdsInternal(void);
  162. ILboolean WriteHeader(ILimage *Image, ILenum DXTCFormat, ILuint CubeFlags);
  163. ILushort *CompressTo565(ILimage *Image);
  164. ILubyte *CompressTo88(ILimage *Image);
  165. ILuint Compress(ILimage *Image, ILenum DXTCFormat);
  166. ILboolean GetBlock(ILushort *Block, ILushort *Data, ILimage *Image, ILuint XPos, ILuint YPos);
  167. ILboolean GetAlphaBlock(ILubyte *Block, ILubyte *Data, ILimage *Image, ILuint XPos, ILuint YPos);
  168. ILboolean Get3DcBlock(ILubyte *Block, ILubyte *Data, ILimage *Image, ILuint XPos, ILuint YPos, int channel);
  169. void ShortToColor565(ILushort Pixel, Color565 *Colour);
  170. void ShortToColor888(ILushort Pixel, Color888 *Colour);
  171. ILushort Color565ToShort(Color565 *Colour);
  172. ILushort Color888ToShort(Color888 *Colour);
  173. ILuint GenBitMask(ILushort ex0, ILushort ex1, ILuint NumCols, ILushort *In, ILubyte *Alpha, Color888 *OutCol);
  174. void GenAlphaBitMask(ILubyte a0, ILubyte a1, ILubyte *In, ILubyte *Mask, ILubyte *Out);
  175. ILuint RMSAlpha(ILubyte *Orig, ILubyte *Test);
  176. ILuint Distance(Color888 *c1, Color888 *c2);
  177. void ChooseEndpoints(ILushort *Block, ILushort *ex0, ILushort *ex1);
  178. void ChooseAlphaEndpoints(ILubyte *Block, ILubyte *a0, ILubyte *a1);
  179. void CorrectEndDXT1(ILushort *ex0, ILushort *ex1, ILboolean HasAlpha);
  180. void PreMult(ILushort *Data, ILubyte *Alpha);
  181. extern ILuint CubemapDirections[CUBEMAP_SIDES];
  182. #endif//DDS_H