Convert Figma logo to code with AI

GPUOpen-Tools logocompressonator

Tool suite for Texture and 3D Model Compression, Optimization and Analysis using CPUs, GPUs and APUs

1,289
193
1,289
81

Top Related Projects

DirectXTex texture processing library

Basis Universal GPU Texture Codec

The Arm ASTC Encoder, a compressor for the Adaptive Scalable Texture Compression data format.

Quick Overview

The Compressonator is an open-source tool developed by AMD's GPUOpen initiative. It provides a set of utilities and libraries for compressing and decompressing various image and texture formats, including support for GPU-accelerated compression. The project aims to simplify the process of working with compressed media assets in game development and other graphics-intensive applications.

Pros

  • Comprehensive Compression Support: The Compressonator supports a wide range of image and texture formats, including popular ones like DXT, ETC, ASTC, and more, allowing developers to work with a variety of compressed assets.
  • GPU Acceleration: The tool leverages GPU hardware to accelerate the compression and decompression process, improving performance and efficiency.
  • Cross-Platform Compatibility: The Compressonator is designed to be cross-platform, with support for Windows, Linux, and macOS, making it accessible to a wide range of developers.
  • Open-Source and Customizable: As an open-source project, the Compressonator can be customized and extended to fit the specific needs of developers, allowing for greater flexibility and integration with their workflows.

Cons

  • Limited Documentation: The project's documentation, while present, could be more comprehensive and user-friendly, especially for developers new to the tool.
  • Steep Learning Curve: Mastering the Compressonator's features and capabilities may require a significant investment of time and effort, especially for developers unfamiliar with image and texture compression.
  • Potential Performance Limitations: While the tool leverages GPU acceleration, the performance of the compression and decompression process may still be a concern for some high-performance applications.
  • Ongoing Maintenance: As an open-source project, the Compressonator's long-term maintenance and development may depend on the continued involvement of the community and the GPUOpen initiative.

Code Examples

The Compressonator provides a C++ API that allows developers to integrate its compression and decompression functionality into their own applications. Here are a few examples of how to use the library:

  1. Compressing an Image:
#include <compressonator/CMP_Core.h>

CMP_CompressOptions options;
options.dwSize = sizeof(CMP_CompressOptions);
options.format = CMP_FORMAT_DXT5;
options.quality = CMP_Quality_Normal;

CMP_Texture srcTexture, dstTexture;
// Initialize srcTexture with image data

CMP_ProcessTexture(&srcTexture, &dstTexture, &options);

// Use the compressed dstTexture data
  1. Decompressing an Image:
#include <compressonator/CMP_Core.h>

CMP_Texture srcTexture, dstTexture;
// Initialize srcTexture with compressed image data

CMP_DecompressTexture(&srcTexture, &dstTexture, CMP_FORMAT_ARGB_8888);

// Use the decompressed dstTexture data
  1. Batch Processing Images:
#include <compressonator/CMP_Core.h>

std::vector<std::string> inputFiles = { "image1.png", "image2.jpg", "image3.bmp" };
std::vector<std::string> outputFiles = { "image1.dds", "image2.dds", "image3.dds" };

CMP_CompressOptions options;
options.dwSize = sizeof(CMP_CompressOptions);
options.format = CMP_FORMAT_DXT5;
options.quality = CMP_Quality_Normal;

for (size_t i = 0; i < inputFiles.size(); i++) {
    CMP_Texture srcTexture, dstTexture;
    // Load srcTexture from inputFiles[i]
    CMP_ProcessTexture(&srcTexture, &dstTexture, &options);
    // Save dstTexture to outputFiles[i]
}

Getting Started

To get started with the Compressonator, follow these steps:

  1. Clone the repository from GitHub:
git clone https://github.com/GPUOpen-Tools/compressonator.git
  1. Build the

Competitor Comparisons

DirectXTex texture processing library

Pros of DirectXTex

  • Comprehensive Functionality: DirectXTex provides a wide range of functionality for working with DirectX textures, including loading, saving, and converting between various texture formats.
  • Microsoft Backing: As a Microsoft-maintained project, DirectXTex benefits from the company's resources and expertise in DirectX development.
  • Extensive Documentation: The project's documentation is thorough and well-maintained, making it easier for developers to understand and use the library.

Cons of DirectXTex

  • Limited Compression Formats: While DirectXTex supports various texture formats, it lacks support for some advanced compression formats like Basis Universal, which are supported by Compressonator.
  • Dependency on DirectX: DirectXTex is tightly coupled with the DirectX ecosystem, which may limit its usability in non-DirectX-based projects.

Code Comparison

Compressonator:

// Load a texture
CMP_Texture srcTexture;
srcTexture.dwSize = sizeof(CMP_Texture);
srcTexture.dwWidth = 512;
srcTexture.dwHeight = 512;
srcTexture.dwPitch = 512 * 4;
srcTexture.pData = textureData;
srcTexture.format = CMP_FORMAT_ARGB_8888;

// Compress the texture
CMP_Texture destTexture;
destTexture.dwSize = sizeof(CMP_Texture);
CMP_CompressTexture(&srcTexture, &destTexture, CMP_FORMAT_BC1);

DirectXTex:

// Load a texture
ScratchImage image;
LoadFromDDSFile(L"texture.dds", DDS_FLAGS_NONE, nullptr, image);

// Save the texture
SaveToDDSFile(image.GetImages(), image.GetImageCount(), image.GetMetadata(), DDS_FLAGS_NONE, L"compressed_texture.dds");

Basis Universal GPU Texture Codec

Pros of Basis Universal

  • Basis Universal is a highly optimized and efficient texture compression format, offering superior compression ratios compared to traditional formats like DXT/BC.
  • It supports a wide range of features, including HDR, alpha, and mipmap support, making it a versatile choice for various graphics applications.
  • Basis Universal is designed to be hardware-accelerated, providing fast decompression on a variety of platforms, including mobile devices.

Cons of Basis Universal

  • Basis Universal is a proprietary format, which may limit its adoption and integration in certain open-source or non-commercial projects.
  • The compression process can be computationally intensive, which may be a concern for some use cases.
  • The Basis Universal project is primarily maintained by a single company, Binomial LLC, which could potentially impact the long-term development and support of the format.

Code Comparison

Compressonator (GPUOpen-Tools/compressonator):

void CompressBlockBC1(
    const uint8_t* pIn,
    uint8_t* pOut,
    const CMP_GLOBAL CMP_DXTC_PARAMETERS* pParams)
{
    // Compress a single 4x4 block using BC1 (DXT1) compression
    CMP_Vec4uc block[16];
    CMP_ConvertRGBtoBlock(pIn, block);
    CMP_CompressBlockDXT1(block, pOut, pParams);
}

Basis Universal (BinomialLLC/basis_universal):

void basisu_compress_block(
    const uint8_t* pIn_pixels,
    uint32_t output_flags,
    void* pOutput_block_bits,
    uint32_t* pOutput_size_in_bytes,
    const basisu_comp_params* pParams)
{
    // Compress a single 4x4 block using Basis Universal compression
    basisu_block_compressor compressor;
    compressor.compress_block(pIn_pixels, output_flags, pOutput_block_bits, pOutput_size_in_bytes, pParams);
}

The Arm ASTC Encoder, a compressor for the Adaptive Scalable Texture Compression data format.

Pros of ARM-software/astc-encoder

  • Optimized for ARM Architectures: The ARM-software/astc-encoder project is specifically designed and optimized for ARM-based architectures, which can provide better performance and efficiency on ARM-powered devices.
  • Comprehensive Documentation: The project's documentation is extensive, covering various aspects of the ASTC (Adaptive Scalable Texture Compression) format and the encoder's usage.
  • Active Development: The ARM-software/astc-encoder project is actively maintained and regularly updated, ensuring ongoing improvements and bug fixes.

Cons of ARM-software/astc-encoder

  • Limited Platform Support: While optimized for ARM, the ARM-software/astc-encoder may not provide the same level of cross-platform support as the GPUOpen-Tools/compressonator project, which supports a wider range of platforms.
  • Specialized Focus: The ARM-software/astc-encoder is focused solely on the ASTC format, whereas the GPUOpen-Tools/compressonator supports a broader range of compression formats.
  • Potentially Higher Learning Curve: The specialized nature of the ARM-software/astc-encoder may require more domain-specific knowledge compared to the more general-purpose GPUOpen-Tools/compressonator.

Code Comparison

Here's a brief code comparison between the two projects:

GPUOpen-Tools/compressonator (C++ code):

void CCodecFactory::CreateCodec(CODECTYPE codecType, CCodec** ppCodec)
{
    switch (codecType)
    {
    case CODEC_TYPE_DXT1:
        *ppCodec = new CCodecDXT1();
        break;
    case CODEC_TYPE_DXT3:
        *ppCodec = new CCodecDXT3();
        break;
    case CODEC_TYPE_DXT5:
        *ppCodec = new CCodecDXT5();
        break;
    // Additional codec types handled here
    }
}

ARM-software/astc-encoder (C++ code):

void astc_codec_internals::compress_block_fixed_partitioning(
    const float4 * const block_colors,
    const float4 * const block_weights,
    const int partition_count,
    const int partition_index,
    const float2 * const block_endpoints,
    const float2 * const block_weights_vec,
    uint8_t * const output_buffer)
{
    // Compression logic for the ASTC format
}

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Compressonator

CMake download download

Download the latest revision for changes that have been made since the last major release by clicking the CMake button above or the link here. Currently, only Compressonator Framework and Compressonator CLI are built every revision.

Compressonator is a set of tools to allow artists and developers to more easily create compressed texture assets or model mesh optimizations and easily visualize the quality impact of various compression and rendering technologies. It consists of a GUI application, a command line application and an SDK for easy integration into a developer tool chain.

Compressonator supports Microsoft Windows® and Linux builds.

For more details goto the online Compressonator Documents: http://compressonator.readthedocs.io/en/latest/

Build System Updates

The code is undergoing a build setup update. This notice will be removed when the changes are completed! Currently: To use the sln builds run build\fetch_dependencies.py to fetch required external lib dependencies into a Common folder above this repository.

Get Prebuilt Binaries and Installer here:

Latest release

To build the source files follow the instructions in http://compressonator.readthedocs.io/en/latest/build_from_source/build_instructions.html

CMake Build Configuration

As of v4.2, The cmake command line options have settings to build specific libs and applications

Examples: Generating Visual Studio Solution File

Enable building all
    cmake -G "Visual Studio 15 2017 Win64"  
    
Disable all builds except external libs, minimal cmake base setup     
    cmake -DOPTION_ENABLE_ALL_APPS=OFF -G "Visual Studio 15 2017 Win64"
    
Enable only CLI app build    
    cmake -DOPTION_ENABLE_ALL_APPS=OFF -DOPTION_BUILD_APPS_CMP_CLI=ON -G "Visual Studio 15 2017 Win64"

For more details reference the CMakeList file on the root folder.

Style and Format Change

The source code of this product is being reformatted to follow the Google C++ Style Guide https://google.github.io/styleguide/cppguide.html

In the interim you may encounter a mix of both an older C++ coding style, as well as the newer Google C++ Style.

Please refer to the _clang-format file in the root directory of the product for additional style information.

Compressonator Core

Provides block level API access to updated performance and quality driven BCn codecs. The library is designed to be a small self-contained, cross-platform, and linkable library for user applications.

Example usage is shown as below to compress and decompress a single 4x4 image block using BC1 encoder


// To use Compressonator Core "C" interfaces, just include
// a single header file and CMP_Core lib into  your projects

#include "CMP_Core.h"

// Compress a sample image shape0 which is a 4x4 RGBA_8888 block.
// Users can use a pointer to any sized image buffers to reference
// a 4x4 block by supplying a stride offset for the next row.
// Optional BC1 settings is set to null in this example

unsigned char shape0_RGBA[64] = { filled with image source data as RGBA ...};

// cmpBuffer is a byte array of 8 byte to hold the compressed results.
unsigned char cmpBuffer[8]   = { 0 };

// Compress the source into cmpBuffer
CompressBlockBC1(shape0_RGBA, 16, cmpBuffer,null);

// Example to decompress comBuffer back to a RGBA_8888 4x4 image block
unsigned char imgBuffer[64] = { 0 };
DecompressBlockBC1(cmpBuffer,imgBuffer,null)

Compressonator Framework

Includes Compressonator core with interfaces for multi-threading, mipmap generation, file access of images and HPC pipeline interfaces.

Example Mip Level Processing using CPU


// To use Compressonator Framework "C" interfaces, just include
// a single header file and CMP_Framework lib into  your projects

#include "compressonator.h"

 //--------------------------
 // Init frameworks
 // plugin and IO interfaces
 //--------------------------
 CMP_InitFramework();

//---------------
// Load the image
//---------------
CMP_MipSet MipSetIn;
memset(&MipSetIn, 0, sizeof(CMP_MipSet));
cmp_status = CMP_LoadTexture(pszSourceFile, &MipSetIn);
if (cmp_status != CMP_OK) {
    std::printf("Error %d: Loading source file!\n",cmp_status);
    return -1;
}

//----------------------------------------------------------------------
// generate mipmap level for the source image, if not already generated
//----------------------------------------------------------------------

if (MipSetIn.m_nMipLevels <= 1)
{
    CMP_INT requestLevel = 10; // Request 10 miplevels for the source image

    //------------------------------------------------------------------------
    // Checks what the minimum image size will be for the requested mip levels
    // if the request is too large, a adjusted minimum size will be returned
    //------------------------------------------------------------------------
    CMP_INT nMinSize = CMP_CalcMinMipSize(MipSetIn.m_nHeight, MipSetIn.m_nWidth, 10);

    //--------------------------------------------------------------
    // now that the minimum size is known, generate the miplevels
    // users can set any requested minumum size to use. The correct
    // miplevels will be set acordingly.
    //--------------------------------------------------------------
    CMP_GenerateMIPLevels(&MipSetIn, nMinSize);
}

//==========================
// Set Compression Options
//==========================
KernelOptions   kernel_options;
memset(&kernel_options, 0, sizeof(KernelOptions));

kernel_options.format   = destFormat;   // Set the format to process
kernel_options.fquality = fQuality;     // Set the quality of the result
kernel_options.threads  = 0;            // Auto setting

//=====================================================
// example of using BC1 encoder options 
// kernel_options.bc15 is valid for BC1 to BC5 formats
//=====================================================
if (destFormat == CMP_FORMAT_BC1)
{
    // Enable punch through alpha setting
    kernel_options.bc15.useAlphaThreshold = true;
    kernel_options.bc15.alphaThreshold    = 128;

    // Enable setting channel weights
    kernel_options.bc15.useChannelWeights = true;
    kernel_options.bc15.channelWeights[0] = 0.3086f;
    kernel_options.bc15.channelWeights[1] = 0.6094f;
    kernel_options.bc15.channelWeights[2] = 0.0820f;
}

//--------------------------------------------------------------
// Setup a results buffer for the processed file,
// the content will be set after the source texture is processed
// in the call to CMP_ProcessTexture()
//--------------------------------------------------------------
CMP_MipSet MipSetCmp;
memset(&MipSetCmp, 0, sizeof(CMP_MipSet));

//===============================================
// Compress the texture using Framework Lib
//===============================================
cmp_status = CMP_ProcessTexture(&MipSetIn, &MipSetCmp, kernel_options, CompressionCallback);
if (cmp_status != CMP_OK) {
  ...
}

//----------------------------------------------------------------
// Save the result into a DDS file
//----------------------------------------------------------------
cmp_status = CMP_SaveTexture(pszDestFile, &MipSetCmp);

CMP_FreeMipSet(&MipSetIn);
CMP_FreeMipSet(&MipSetCmp);

Example GPU based processing using OpenCL


// Note: Only MD x64 build is used for GPU processing
// SDK files required for application:
//     compressonator.h
//     CMP_Framework_xx.lib  For static libs xx is either MD or MDd, 
//                      When using DLL's make sure the  CMP_Framework_xx_DLL.dll is in exe path
//
// File(s) required to run with the built application
//
// Using OpenCL (OCL) 
//     CMP_GPU_OCL_MD_DLL.dll    or CMP_GPU_OCL_MDd_DLL.dll
//     Encode Kernel files in plugins/compute folder
//     BC1_Encode_Kernel.cpp
//     BC1_Encode_Kernel.h
//     BCn_Common_kernel.h
//     Common_Def.h
//
// Using DirectX (DXC) 
//     CMP_GPU_DXC_MD_DLL.dll    or CMP_GPU_DXC_MDd_DLL.dll
//     Encode Kernel files in plugins/compute folder
//     BC1_Encode_Kernel.hlsl
//     BCn_Common_kernel.h
//     Common_Def.h

#include "compressonator.h"

CMP_FORMAT      destFormat = CMP_FORMAT_BC1;

//---------------
// Load the image
//---------------
CMP_MipSet MipSetIn;
memset(&MipSetIn, 0, sizeof(CMP_MipSet));
if (CMP_LoadTexture(pszSourceFile, &MipSetIn) != CMP_OK) {
    std::printf("Error: Loading source file!\n");
    return -1;
  } 

 //-----------------------------------------------------
 // when using GPU: The texture must have width and height as a multiple of 4
 // Check texture for width and height
 //-----------------------------------------------------
 if ((MipSetIn.m_nWidth % 4) > 0 || (MipSetIn.m_nHeight % 4) > 0) {
    std::printf("Error: Texture width and height must be multiple of 4\n");
    return -1;
 }
    
//----------------------------------------------------------------------------------------------------------
// Set the target compression format and the host framework to use
// For this example OpenCL is been used
//-----------------------------------------------------------------------------------------------------------
KernelOptions   kernel_options;
memset(&kernel_options, 0, sizeof(KernelOptions));

kernel_options.encodeWith = CMP_GPU_OCL;         // Using OpenCL GPU Encoder, can replace with DXC for DirectX
kernel_options.format     = destFormat;          // Set the format to process
kernel_options.fquality   = fQuality;            // Set the quality of the result

//--------------------------------------------------------------
// Setup a results buffer for the processed file,
// the content will be set after the source texture is processed
// in the call to CMP_ProcessTexture()
//--------------------------------------------------------------
CMP_MipSet MipSetCmp;
memset(&MipSetCmp, 0, sizeof(CMP_MipSet));

//===============================================
// Compress the texture using Framework Lib
//===============================================
cmp_status = CMP_ProcessTexture(&MipSetIn, &MipSetCmp, kernel_options, CompressionCallback);
if (cmp_status != CMP_OK) {
  ...
}

//----------------------------------------------------------------
// Save the result into a DDS file
//----------------------------------------------------------------
cmp_status = CMP_SaveTexture(pszDestFile, &MipSetCmp);

CMP_FreeMipSet(&MipSetIn);
CMP_FreeMipSet(&MipSetCmp);

Compressonator SDK

Compressonator SDK supported codecs includes BC1-BC7/DXTC, ETC1, ETC2, ASTC, ATC, ATI1N, ATI2N, all available in a single library.

With the new SDK installation, several example applications with source code are provided that demonstrate how easy it is to add texture compression to your own applications using either "High Level" or "Block Level" APIs.

A simple thread safe interface can compress, decompress and transcode any image as required

CMP_ConvertTexture(CMP_Texture* pSourceTexture, CMP_Texture* pDestTexture,...);

For Example:


// To use Compressonator's portable "C" interfaces, just include
// a single header file and Compresonator.lib into  your projects

#include "Compressonator.h"
...

//==========================
// Load Source Texture
//==========================
CMP_Texture srcTexture;
// note that LoadDDSFile function is a utils function to initialize the source CMP_Texture
// you can also initialize the source CMP_Texture the same way as initialize destination CMP_Texture
if (!LoadDDSFile(pszSourceFile, srcTexture))
{
  ...
}

//===================================
// Initialize Compressed Destination
//===================================
CMP_Texture destTexture;
destTexture.dwSize     = sizeof(destTexture);
destTexture.dwWidth    = srcTexture.dwWidth;
destTexture.dwHeight   = srcTexture.dwHeight;
destTexture.dwPitch    = 0;
destTexture.format     = CMP_FORMAT_BC6H;
destTexture.dwDataSize = CMP_CalculateBufferSize(&destTexture);
destTexture.pData      = (CMP_BYTE*)malloc(destTexture.dwDataSize);

//==========================
// Set Compression Options
//==========================
CMP_CompressOptions options = {0};
options.dwSize       = sizeof(options);
options.fquality     = 0.05f;
options.dwnumThreads = 8;

//==========================
// Compress Texture
//==========================
CMP_ERROR   cmp_status;
cmp_status = CMP_ConvertTexture(&srcTexture, &destTexture, &options, &CompressionCallback, NULL, NULL);
if (cmp_status != CMP_OK)
{
  ...
}

//==========================
// Save Compressed Testure
//==========================
SaveDDSFile(pszDestFile, destTexture))

free(srcTexture.pData);
free(destTexture.pData);

Compressonator CLI

Command line application that can be batch processed and supports:

  • Texture Compression, Decompression, Format Transcoding.
  • 3D Model Optimization and Mesh Compression.
  • Performance and Analysis Logs such as SSIM, MSE, PSNR.
  • MIP Maps, Image Differences, etc. ...
C:\>CompressonatorCLI -fd BC7 .\images .results
C:\>CompressonatorCLI -log -fd BC7 .\images\ruby.png ruby_bc7.dds
CompressonatorCLI Performance Log v1.0

Source        : .\images\ruby.png, Height 416, Wideth 576, Size 0.936 MBytes
Destination   : ruby_bc7.dds
Using         : CPU
Quality       : 0.05
Processed to  : BC7        with  1 iteration(s) in 1.422 seconds
MSE           : 0.78
PSNR          : 49.2
SSIM          : 0.9978
Total time    : 1.432 seconds

--------------

Compressonator GUI

Comprehensive graphical application that can be used to visualize Images and 3D Models, with support for:

  • Texture Compression, Decompression, Format Transcoding.
  • 3D Model Optimization and Mesh Compression.
  • Multiple Image and 3D Model Views.
  • MIP Maps, Differences, Analysis, etc. ...

screenshot 1

glTF 2.0 Model Render View

screenshot 2

Contributors

Compressonator's GitHub repository (http://github.com/GPUOpen-Tools/Compressonator) is moderated by Advanced Micro Devices, Inc. as part of the GPUOpen initiative.

AMD encourages any and all contributors to submit changes, features, and bug fixes via Git pull requests to this repository.

Users are also encouraged to submit issues and feature requests via the repository's issue tracker.