DDS文件格式解析
来源:互联网 发布:黄章晋 知乎 编辑:程序博客网 时间:2024/05/22 00:36
DDS是DirectDrawSurface的缩写,它是DirectX纹理压缩(DirectX TextureCompression,简称DXTC)的产物。
DXTC减少了纹理内存消耗的50%甚至更多,有3种DXTC的格式可供使用,分别是DXT1,DXT3和DXT5。
DXT1 压缩比例:1:8
压缩比最高,它只有1BitAlpha,Alpha通道信息几乎完全丧失。一般将不带Alpha通道的图片压缩成这种格式。如WorldWind用的卫星图片
DXT3 压缩比例:1:4
使用了4BitAlpha,可以有16个Alpha值,可很好地用于alpha通道锐利、对比强烈的半透和镂空材质。
DXT5 压缩比例:1:4
使用了线形插值的4BitAlpha,特别适合Alpha通道柔和的材质,比如高光掩码材质。
dds格式分为2个部分:
1、dds头
2、dxt压缩数据
dds的头文件信息如下:
typedef struct _DDCOLORKEY
{
uint32 dwColorSpaceLowvalue; // lowboundary of color space that is to
//be treated as Color Key, inclusive
uint32 dwColorSpaceHighvalue; // highboundary of color space that is
//to be treated as Color Key, inclusive
} DDCOLORKEY;
typedef struct _DDSCAPS2
{
uint32 dwCaps; // capabilities of surface wanted
uint32 dwCaps2;
uint32 dwCaps3;
union
{
uint32 dwCaps4;
uint32 dwVolumeDepth;
}DUMMYUNIONNAMEN(1);
} DDSCAPS2;
typedef struct _DDPIXELFORMAT
{
uint32 dwSize; // size of structure
uint32 dwFlags; //pixel format flags
uint32 dwFourCC; // (FOURCC code)
union
{
uint32 dwRGBBitCount; //how many bits per pixel
uint32 dwYUVBitCount; //how many bits per pixel
uint32 dwZBufferBitDepth; //how many total bits/pixel in z buffer (including any stencilbits)
uint32 dwAlphaBitDepth; //how many bits for alpha channels
uint32 dwLuminanceBitCount; //how many bits per pixel
uint32 dwBumpBitCount; // how many bits per "buxel", total
uint32 dwPrivateFormatBitCount;// Bits per pixel of private driverformats. Only valid in texture
//format list and if DDPF_D3DFORMAT is set
}DUMMYUNIONNAMEN(1);
union