S3TC: Difference between revisions

From MultimediaWiki
Jump to navigation Jump to search
(first draft, explain dxt1 format)
 
(clearer distinction between colors and components; description of dxt2/3)
Line 9: Line 9:
16 input pixels are encoded as follows:
16 input pixels are encoded as follows:


  uint16_t c0;
  uint16_t color0;
  uint16_t c1;
  uint16_t color1;
  uint32_t pixels;
  uint32_t pixels;


''c0'' and ''c1'' are RGB565 color values. ''pixels'' are 16 2-bit pixels, referring to ''c0..c3''. Each component of ''c2'' and ''c3'' is calculated by:
''color0'' and ''color1'' are RGB565 color values. ''pixels'' are 16 2-bit pixels, referring to ''color0..3''. Each component of ''color2'' and ''color3'' is calculated by:


  if (c0 > c1)
  if (color0 > color1)
   c2 = (2 * c0 + c1) / 3
   c2 = (2 * c0 + c1) / 3
   c3 = (2 * c1 + c0) / 3
   c3 = (2 * c1 + c0) / 3
Line 22: Line 22:
   c3 = 0
   c3 = 0


The pixels are stored in raster scan order and start at the least significant two bits of ''pixels''.
The pixels are stored in raster scan order and start at the least significant two bits of ''pixels''. The alpha channel of each pixel is considered fully opaque, except when color0 <= color1. In that case, the alpha channel of color3 is considered fully transparent.


==DXT2/3==
==DXT2/3==
16 input pixels are encoded as follows:
uint64_t alpha;
uint16_t color0;
uint16_t color1;
uint32_t pixels;
''alpha'' contains the alpha channel, 4 bits for each pixel. The colors are encoded similar to DXT1, with the exception that the components of ''color2'' and ''color3'' are always calculated by:
c2 = (2 * c0 + c1) / 3
c3 = (2 * c1 + c0) / 3
DXT2 considers the pixel values premultiplied by alpha. DXT3 does not.


==DXT4/5==
==DXT4/5==

Revision as of 10:16, 30 April 2007

S3 Texture Compression (S3TC) is a family of image compression algorithms developed by S3 for their Savage 3D line of graphics cards. It is also known as DXTn or DXTC.

Introduction

S3TC is a lossy compression algorithm that transforms blocks of 4x4 RGBA32 pixels to either 64 or 128 bits. The different compression schemes are often denoted by their Microsoft assigned FourCC.

DXT1

16 input pixels are encoded as follows:

uint16_t color0;
uint16_t color1;
uint32_t pixels;

color0 and color1 are RGB565 color values. pixels are 16 2-bit pixels, referring to color0..3. Each component of color2 and color3 is calculated by:

if (color0 > color1)
 c2 = (2 * c0 + c1) / 3
 c3 = (2 * c1 + c0) / 3
else
 c2 = (c0 + c1) / 2
 c3 = 0

The pixels are stored in raster scan order and start at the least significant two bits of pixels. The alpha channel of each pixel is considered fully opaque, except when color0 <= color1. In that case, the alpha channel of color3 is considered fully transparent.

DXT2/3

16 input pixels are encoded as follows:

uint64_t alpha;
uint16_t color0;
uint16_t color1;
uint32_t pixels;

alpha contains the alpha channel, 4 bits for each pixel. The colors are encoded similar to DXT1, with the exception that the components of color2 and color3 are always calculated by:

c2 = (2 * c0 + c1) / 3
c3 = (2 * c1 + c0) / 3

DXT2 considers the pixel values premultiplied by alpha. DXT3 does not.

DXT4/5

Containers

S3TC compressed textures can be found in the following containers: