DXT Compression/Decompression Library
nvDXT is a compression and decompression library to link to your existing projects. You specify compression options in the class CompressionOptions located in nvdxt_options.h. The library will create the MIP map levels for you during compression, or you can specify you own. You can specify your own MIP map compressor callback to receive each of the compressed MIP levels.
The decompressor will decompress all MIP map into one image file where all MIP maps are concatenated together.
The library name is nvDXTLib.lib.
Compresses an image with a user supplied callback with the data for each MIP level created.
For each MIP level, your callback will be called.
Only supports input of RGB 24 or ARGB 32 bpp.
See nvDXT.cpp for example. This example require the NVSDK to build.
HRESULT
nvDXTcompress(unsigned char * raw_data, // pointer to data (24 or 32 bit)unsigned long w, // width in texels
unsigned long h, // height in texels
DWORD pitch, // in bytes
CompressionOptions * options, // structure defined in nvdxt_options.h
DWORD depth, // 3 or 4
MIPcallback callback = 0); // callback for generated levels
if callback is == 0 (or not specified), then WriteDTXnFile is called with all file info
instead of your callback
typedef HRESULT (*MIPcallback)(
void * data, // pointer to the data to compressed data
int miplevel, // what MIP level this is
DWORD size // size of the data
);
// You must write the routines (or provide stubs)
// void WriteDTXnFile(count, buffer);
// void ReadDTXnFile(count, buffer);
//
//
void WriteDTXnFile(DWORD count, void * buffer);
void ReadDTXnFile(DWORD count, void * buffer);
See the file nvdxt_options.h for the definition of CompressionOptions
// error return codes
#define DXTERR_INPUT_POINTER_ZERO -1
#define DXTERR_DEPTH_IS_NOT_3_OR_4 -2
#define DXTERR_NON_POWER_2 -3
example callback to store compressed image in a
Direct3D texture
LPDIRECT3DTEXTURE8 pCurrentTexture = 0;
HRESULT LoadAllMipSurfaces(void * data,
int iLevel)
{
HRESULT hr;
LPDIRECT3DSURFACE8
psurf;
D3DSURFACE_DESC
sd;
D3DLOCKED_RECT
lr;
hr = pCurrentTexture->GetSurfaceLevel(iLevel, &psurf);
if (FAILED(hr))
return hr;
psurf->GetDesc(&sd);
hr = pCurrentTexture->LockRect(iLevel, &lr, NULL, 0);
if (FAILED(hr))
return hr;
memcpy(lr.pBits, data, sd.Size);
hr = pCurrentTexture->UnlockRect(iLevel);
ReleasePpo(&psurf);
return 0;
}
calling sequence
hr = D3DXCreateTexture(m_pd3dDevice, Width, Height, nMips, 0, D3DFMT_DXT3,
D3DPOOL_MANAGED, &pCurrentTexture);
nvDXTcompress(raw_data, Width, Height, pitch, options, 4,
LoadAllMipSurfaces);
If you have
existing MIP maps you must combine them so each MIP level is followed by its
next MIP level. Conceptually, it looks like this:
in CompressionOptions
MipMapType = dUseExistingMipMaps;
You must specify all MIP levels.
To decompress an image use this call to read all MIP chains into one buffer:
unsigned
char * nvDXTdecompress(int & w, int & h, int & depth, int & total_width, int & rowBytes, int & src_format, int SpecifiedMipMaps)
returns pointer to image data;
w : image width
h : image height
depth : number of bytes per pixel, 3 or 4
row_bytes: pitch of main image
The first image starts at 0, the next MIP map image starts at base + row_bytes, next one starts at base + row_bytes / 2, etc.
src_format: format of the file
SpecifiedMipMaps. Load in only this number of MIP maps. zero means read all MIP levels
pitch = row_bytes * 2
see readdxt.cpp for example