Advanced DXTn Texture Compression Tool
Copyright (c) 2009-2012 Tenacious Software LLC and Rich Geldreich, Jr.




Downloads
Release Notes: ddsexport is a hybrid managed/native tool written in C++/CLI. The UI is managed code (Windows Forms), with all the heavy lifting done using native code. It only utilizes .NET 2.0 components, but it may require .NET 3.5 to run (I'm not really sure). This package also includes the "crunch" command line tool. The executables only archive also contains the x64 version of the command line tool.



Introduction

ddsexport is a 32-bit Windows app that demonstrates some of the capabilities of the open-source DXTn texture compression library crnlib. The .DDS texture files created by ddsexport are much more compressible by lossless compression algorithms such as LZMA, Deflate (zlib), LZO, etc. compared to files created by other libraries/tools. Assuming your engine already supports some form of lossless asset compression (most do), adding ddsexport to your product's texture export pipeline can reduce the amount of compressed texture data distributed to customers (or placed on disc, etc.) by 10-40% or more.

ddsexport implements a form of rate-distortion optimization, except for DXTc compressed texture data instead of video:

ddsexport's compression engine is heavily multithreaded. It's highly recommended to run it on a CPU supporting at least 4 cores/8 hardware threads (the more the merrier, 12+ threads are recommended).

This tool supports the following source texture/image formats:
  • Texture formats (with or without mipmaps, ddsexport reads these files natively): .DDS, .CRN
  • Image formats (no mipmaps, FreeImage is used to read these files):  .BMP, .GIF, .JPG, .JP2, .PSD, .TGA, .TIF/.TIFF, .PNG, .PPM, .PGM
It is highly recommended to use uncompressed source files, such as .PNG, .TGA, .TIF, .BMP, etc. images (or 24/32-bit .DDS files). Otherwise, you'll be layering two lossy compression algorithms on top of each other, which will needlessly degrade quality. For example, taking an already compressed DXTn .DDS file, or a .JPG compressed file and furthering compressing it to clustered DXTn .DDS using this tool isn't the best idea.

.DDS files created by this tool can be loaded with AMD's Compressonator (recommended, because it properly supports swizzled DXTn formats), by the DirectX SDK's dxtex.exe tool, or by any software that supports DX9-class .DDS files. (.DDS is easy to read, for one example see the dds_texture::read_dds_internal() method in this C++ source file.)

Supported DXTn Formats

DDSExport doesn't support cubemaps, but it works fine with color (albedo/specular/gloss/heightfields/etc.) and normal maps (tangent or object space, optionally swizzled). When compressing normal maps, be sure to disable "Perceptual Colorspace Metrics" in the "Compression Options" dialog box. (The tool tries to detect normal maps and do this automatically, but this can sometimes fail.)

It supports the same DXTn formats as crnlib:
  • 4bpp: DXT1 and DXT1A. DXT1A must be explicitly enabled in the "Compression Options" dialog box.
  • 8bpp: DXT5 or swizzled DXT5 (component order is: DXT5_RGBA, where x=unused component). All swizzled formats except DXT5_CCxY are supported by AMD's Compressonator.
    • DXT5 (non-swizzled, RGB=Color, A=Opacity)
    • DXT5_CCxY (custom to crnlib, RGB=Chroma, A=Luma, currently using a standard YCbCr encoding, see crnlib/crn_color.h, functions RGB_to_YCC() and YCC_to_RGB()). The FOURCC is CCxY.
    • DXT5_xGxR (swizzled normal map: G=Y, A=X)
    • DXT5_xGBR (swizzled normal map: G=Y, B=Z, A=X)
    • DXT5_AGBR (swizzled normal map: R=Alpha, G=Y, B=Z, A=X)
  • 4bpp: DXT5A (Opacity or Luma)
  • 8bpp: X360 DXN and AMD/ATI 3DC (two DXT5A blocks, supports either XY or YX component order)
DDSExport exposes only a subset of the features supported by the crunch command line tool.

For support, bugs, feature requests, or feedback please contact Rich Geldreich <richgel99 at gmail dot com>.



Known Problems/Limitations
  • This is an alpha/demo version of ddsexport. I have a roadmap of cool features to add, but I don't have much free time to keep enhancing this tool unless there's interest.
  • [5/1/12] - The version of crnlib that ddsexport is linked against does not write .DDS files having the pitch/linearsize fields of DXTc files set. Some DDS readers expect valid values here (and expect the DDSD_LINEARSIZE flag to be set too). I'll be fixing this and releasing a new version once crunch v1.03 is fully ported to Linux.
  • The adaptive block size option (enabled by default) sometimes too aggressively chooses large (4x8, 8x4 or 8x8) tiles, resulting in overly blocky results on texture areas with high contrast edges. I'm toning this option down in the next version. For now, if the output appears too blocky near high-contrast edges then try turning this option off in the Compression Options dialog.
  • Currently, this tool can only write .DDS files (with or without mipmaps). I will eventually add support for writing .CRN format files, which are usually much smaller (at the same quality level index) or higher quality (at the same file size).
  • ddsexport always assumes the resulting .DDS texture will be losslessly compressed by LZMA. It would be very nice to allow selecting different codecs (LZO, zlib, snappy, etc.)
  • The "compressed size" and "quality" bars animate on some systems (probably depends on your Windows desktop theme settings). This is not on purpose, and can be pretty annoying.
  • The displayed PSNR is computed from either the Luma error (for DXT1 or DXT5_CCxY), or the RG, RGB, RGBA, or alpha error depending on the currently selected format. This can be confusing because there's no indication of what's currently being displayed.


Quick Instructions
  • Press the "Select File" button in the "Input Texture" pane to load an image/texture to compress to DXTn (or clustered DXTn). Alternately, copy the image to compress into the Windows Clipboard, then press ddsexport's "Read Clipboard" button to load this image into the tool.
  • Manipulate the DXT Quality, DXT format, Compression Options, and Mipmap Options as needed.
  • Double check the file listed in the "Output Texture" pane has the correct path/filename.
  • Important: Double check that your Mipmap Options and Compression Options are correct. For example, some textures don't typically need mipmaps (such as textures used for UI/Flash rendering).
  • Select the "Save DDS" button to save the current texture to a .DDS file on disk. 
Note: The processed texture is NOT saved until you click the "Save DDS" button!



Loading an Image/Texture from the Command Line

Specifying a filename on the command line causes ddsexport.exe to load that file once the dialog pops up. For example:

ddsexport.exe my_most_excellent_24bpp_texture.dds



Planned Features
  • Find a better name than "ddsexport" (suggestions welcome).
  • XML or JSON Metadata Files: The tool currently doesn't record any of the settings (DXTn format, mipmap/compression options, quality index, etc.) used to save textures. It would be really nice if it somehow remembered the settings used on each texture between runs, and if these settings could be checked in along with the source/output images. Right now everything must be set manually.
  • Support other codecs other than LZMA. Many engines use other codecs such as LZO, zlib, etc.
  • Support compressing to fractional bitrates or target file sizes, instead of a manually selected quality level.
  • .CRN file format support.
  • Better defaults: Right now, the tool is pretty dumb. It doesn't try to intelligently set the DXTn format, mipmap options, etc. after a new image is loaded. 
  • The file saving mechanic isn't obvious enough.
  • The image viewer should auto-center the image when the main form is maximized.
  • Ditch managed code/Windows Forms for the UI and switch to Qt.
  • GPU acceleration using D3D11 Compute Shaders.
  • Drag and drop support.
  • Example Photoshop integration via scripting.



Tech Info

ddsexport makes use of the following open source libraries and code: crnlib, LZMA, FreeImage, stb_image, and ryg_dxt. For more info, see crnlib's main page and Technical Details Wiki.



Legal Stuff

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.