00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef DDS_H
00015 #define DDS_H
00016
00017 #include "il_internal.h"
00018
00019
00020 #ifdef _WIN32
00021 #pragma pack(push, dds_struct, 1)
00022 #endif
00023 typedef struct DDSHEAD
00024 {
00025 ILbyte Signature[4];
00026
00027 ILuint Size1;
00028 ILuint Flags1;
00029 ILuint Height;
00030 ILuint Width;
00031 ILuint LinearSize;
00032 ILuint Depth;
00033 ILuint MipMapCount;
00034 ILuint AlphaBitDepth;
00035
00036 ILuint NotUsed[10];
00037
00038 ILuint Size2;
00039 ILuint Flags2;
00040 ILuint FourCC;
00041 ILuint RGBBitCount;
00042 ILuint RBitMask;
00043 ILuint GBitMask;
00044 ILuint BBitMask;
00045 ILuint RGBAlphaBitMask;
00046
00047 ILuint ddsCaps1, ddsCaps2, ddsCaps3, ddsCaps4;
00048 ILuint TextureStage;
00049 } IL_PACKSTRUCT DDSHEAD;
00050 #ifdef _WIN32
00051 #pragma pack(pop, dds_struct)
00052 #endif
00053
00054
00055
00056
00057
00058 typedef struct Color8888
00059 {
00060 ILubyte r;
00061 ILubyte g;
00062 ILubyte b;
00063 ILubyte a;
00064 } Color8888;
00065
00066
00067 typedef struct Color888
00068 {
00069 ILubyte r;
00070 ILubyte g;
00071 ILubyte b;
00072 } Color888;
00073
00074
00075 typedef struct Color565
00076 {
00077 unsigned nBlue : 5;
00078 unsigned nGreen : 6;
00079 unsigned nRed : 5;
00080 } Color565;
00081
00082
00083 typedef struct DXTColBlock
00084 {
00085 ILshort col0;
00086 ILshort col1;
00087
00088
00089 ILbyte row[4];
00090 } DXTColBlock;
00091
00092 typedef struct DXTAlphaBlockExplicit
00093 {
00094 ILshort row[4];
00095 } DXTAlphaBlockExplicit;
00096
00097 typedef struct DXTAlphaBlock3BitLinear
00098 {
00099 ILbyte alpha0;
00100 ILbyte alpha1;
00101
00102 ILbyte stuff[6];
00103 } DXTAlphaBlock3BitLinear;
00104
00105
00106
00107
00108
00109
00110 #define DDS_CAPS 0x00000001L
00111 #define DDS_HEIGHT 0x00000002L
00112 #define DDS_WIDTH 0x00000004L
00113
00114 #define DDS_RGB 0x00000040L
00115 #define DDS_PIXELFORMAT 0x00001000L
00116
00117 #define DDS_LUMINANCE 0x00020000L
00118
00119 #define DDS_ALPHAPIXELS 0x00000001L
00120 #define DDS_ALPHA 0x00000002L
00121 #define DDS_FOURCC 0x00000004L
00122 #define DDS_PITCH 0x00000008L
00123 #define DDS_COMPLEX 0x00000008L
00124 #define DDS_TEXTURE 0x00001000L
00125 #define DDS_MIPMAPCOUNT 0x00020000L
00126 #define DDS_LINEARSIZE 0x00080000L
00127 #define DDS_VOLUME 0x00200000L
00128 #define DDS_MIPMAP 0x00400000L
00129 #define DDS_DEPTH 0x00800000L
00130
00131 #define DDS_CUBEMAP 0x00000200L
00132 #define DDS_CUBEMAP_POSITIVEX 0x00000400L
00133 #define DDS_CUBEMAP_NEGATIVEX 0x00000800L
00134 #define DDS_CUBEMAP_POSITIVEY 0x00001000L
00135 #define DDS_CUBEMAP_NEGATIVEY 0x00002000L
00136 #define DDS_CUBEMAP_POSITIVEZ 0x00004000L
00137 #define DDS_CUBEMAP_NEGATIVEZ 0x00008000L
00138
00139
00140 #define IL_MAKEFOURCC(ch0, ch1, ch2, ch3) \
00141 ((ILint)(ILbyte)(ch0) | ((ILint)(ILbyte)(ch1) << 8) | \
00142 ((ILint)(ILbyte)(ch2) << 16) | ((ILint)(ILbyte)(ch3) << 24 ))
00143
00144 enum PixFormat
00145 {
00146 PF_ARGB,
00147 PF_RGB,
00148 PF_DXT1,
00149 PF_DXT2,
00150 PF_DXT3,
00151 PF_DXT4,
00152 PF_DXT5,
00153 PF_3DC,
00154 PF_ATI1N,
00155 PF_LUMINANCE,
00156 PF_LUMINANCE_ALPHA,
00157 PF_RXGB,
00158 PF_A16B16G16R16,
00159 PF_R16F,
00160 PF_G16R16F,
00161 PF_A16B16G16R16F,
00162 PF_R32F,
00163 PF_G32R32F,
00164 PF_A32B32G32R32F,
00165 PF_UNKNOWN = 0xFF
00166 };
00167
00168 #define CUBEMAP_SIDES 6
00169
00170
00171 ILboolean iLoadDdsInternal(void);
00172 ILboolean iIsValidDds(void);
00173 ILboolean iCheckDds(DDSHEAD *Head);
00174 void AdjustVolumeTexture(DDSHEAD *Head, ILuint CompFormat);
00175 ILboolean ReadData();
00176 ILboolean AllocImage(ILuint CompFormat);
00177 ILboolean DdsDecompress(ILuint CompFormat);
00178 ILboolean ReadMipmaps(ILuint CompFormat);
00179 ILuint DecodePixelFormat();
00180 void DxtcReadColor(ILushort Data, Color8888* Out);
00181 void DxtcReadColors(const ILubyte* Data, Color8888* Out);
00182 ILboolean DecompressARGB(ILuint CompFormat);
00183 ILboolean DecompressARGB16(ILuint CompFormat);
00184 ILboolean DecompressDXT1(ILimage *lImage, ILubyte *lCompData);
00185 ILboolean DecompressDXT2(ILimage *lImage, ILubyte *lCompData);
00186 ILboolean DecompressDXT3(ILimage *lImage, ILubyte *lCompData);
00187 ILboolean DecompressDXT4(ILimage *lImage, ILubyte *lCompData);
00188 ILboolean DecompressDXT5(ILimage *lImage, ILubyte *lCompData);
00189 ILboolean Decompress3Dc();
00190 ILboolean DecompressAti1n();
00191 ILboolean DecompressRXGB();
00192 ILboolean iConvFloat16ToFloat32(ILuint* dest, ILushort* src, ILuint size);
00193 ILboolean DecompressFloat(ILuint lCompFormat);
00194 void CorrectPreMult();
00195 void GetBitsFromMask(ILuint Mask, ILuint *ShiftLeft, ILuint *ShiftRight);
00196 ILboolean iSaveDdsInternal(void);
00197 ILboolean WriteHeader(ILimage *Image, ILenum DXTCFormat, ILuint CubeFlags);
00198 ILushort *CompressTo565(ILimage *Image);
00199 ILubyte *CompressTo88(ILimage *Image);
00200 ILuint Compress(ILimage *Image, ILenum DXTCFormat);
00201 ILboolean GetBlock(ILushort *Block, ILushort *Data, ILimage *Image, ILuint XPos, ILuint YPos);
00202 ILboolean GetAlphaBlock(ILubyte *Block, ILubyte *Data, ILimage *Image, ILuint XPos, ILuint YPos);
00203 ILboolean Get3DcBlock(ILubyte *Block, ILubyte *Data, ILimage *Image, ILuint XPos, ILuint YPos, int channel);
00204 void ShortToColor565(ILushort Pixel, Color565 *Colour);
00205 void ShortToColor888(ILushort Pixel, Color888 *Colour);
00206 ILushort Color565ToShort(Color565 *Colour);
00207 ILushort Color888ToShort(Color888 *Colour);
00208 ILuint GenBitMask(ILushort ex0, ILushort ex1, ILuint NumCols, ILushort *In, ILubyte *Alpha, Color888 *OutCol);
00209 void GenAlphaBitMask(ILubyte a0, ILubyte a1, ILubyte *In, ILubyte *Mask, ILubyte *Out);
00210 ILuint RMSAlpha(ILubyte *Orig, ILubyte *Test);
00211 ILuint Distance(Color888 *c1, Color888 *c2);
00212 void ChooseEndpoints(ILushort *Block, ILushort *ex0, ILushort *ex1);
00213 void ChooseAlphaEndpoints(ILubyte *Block, ILubyte *a0, ILubyte *a1);
00214 void CorrectEndDXT1(ILushort *ex0, ILushort *ex1, ILboolean HasAlpha);
00215 void PreMult(ILushort *Data, ILubyte *Alpha);
00216
00217
00218 extern ILuint CubemapDirections[CUBEMAP_SIDES];
00219
00220
00221 #endif//DDS_H