NVIDIA DXT Compression Tools

 

Adobe PhotoShop Plugin.  Reads and writes .dds files compressed or uncompressed

detach.exe - extracts the MIP maps from a .dds file 

stitch.exe - recombine MIP levels to form one .dds

nvDXT.exe - batch compresses (source)

readDXT.exe - reads compressed image and writes .tga file (source)

nvDXTLib.lib - compression library for using compression in your tools, with examples

 


Adobe PhotoShop Plugin

    dds.8bi (with 3D Preview, requires dx8 to be installed)
    copy the plugin to

    \Program Files\Adobe\Photoshop 5.5\Plug-Ins\File Formats  or

    \Program Files\Adobe\Photoshop 6.0\Plug-Ins\File Formats

    this also works with Paint Shop Pro


    Use "Save As" and "DDS" to save compressed files
    Allows dropping .dds files into PhotoShop

    You can save files that are non-power of two if they are uncompressed, but dxtex will not be able to read them.



Save Format

    Chooses which format to save the image as.  This is affected by Options and Fade To Color below it.

    DXT1, DXT1 with alpha, DXT3 and DXT5 are compressed formats

    DXT1's compression ratio is 8:1

    DXT3 and DXT5's are 4:1 compression ratio

    Other formats are uncompressed

        4444 - 4 bits for alpha, red, green and blue

        1555 - 1 bit for alpha, 5 for red, green and blue

        565 - no alpha, 5 bits for red, 6 bits for green, 5 bits for blue

        8888 - 8 bits for alpha, red, green and blue

      

    Options

        Dither - jitters image so 16 bit image look better

        Binary Alpha - treats alpha as one bit only for MIP map generation

        Alpha Border - set the border of the texture to alpha for every MIP level

        Fade To Color - gradually fades from the image to a selectable color over n MIP maps.

        

    Override

        previews the xbox version of DXT1 

    

    Preview Options

        Alpha Blending - enables/disable alpha blending using the alpha channel of the texture

        Show Differences - compares the full precision image with the modes that are selected

        
nvDXT Stand alone batch compressor

    nvdxt [-m] [-1c] [-1a] [-3] [-5] [-a] [-u1] [-u4] [-u5] [-u8] [-b] [-o <output_directory>] [image_file]


    m - generate MIP maps
    o - output directory
    d - dither saving 16 bit formats
    a - all image files in current directory (does not require file name)
    b - browse for directory (does not require file name) 

    1c - DXT1 (color only)
    1a - DXT1 (one bit alpha)
    3 - DXT3
    5 - DXT5
    u1 - uncompressed 1:5:5:5
    u4 - uncompressed 4:4:4:4
    u5 - uncompressed 5:6:5
    u8 - uncompressed 8:8:8:8
    
    h - help


    reads
        .tga
        .bmp
        .gif
        .ppm
        .jpg
        .tif
        .cel


    Known Bugs
        .jpg currently swaps RGB

detach

      Usage: detach <base_filename>

    do not include the .dds extension

    for example to extract MIP maps from wood.dds use

        detach wood

stitch

     Usage: stitch <base_filename>

    do not include the .dds extension

    for example to recombine MIP maps from wood_00.dds,.. wood_01.dds,...

        stitch wood

 

nvDXTLib.lib

        Compression example : nvdxt.cpp
        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
    
        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 TextureFormat, // list below
            bool bGenMipMaps, // auto gen MIP maps
            bool bDither,
            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);



    // TextureFormat, pass this in to request the compression format
    #define TF_DXT1 10
    #define TF_DXT1_1BitAlpha 11
    #define TF_DXT3 12
    #define TF_DXT5 13
    #define TF_RGB4444 14
    #define TF_RGB1555 15
    #define TF_RGB565 16
    #define TF_RGB8888 17


    // 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, DXT3, true, 4, LoadAllMipSurfaces);

 

    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);


        see readdxt.cpp for example


-Doug
send bugs or feature requests to doug@nvidia.com