# SIMD/Uses/DCT

## What is the DCT?

The Wikipedia article on the Discrete Cosine Transform summarizes the nature of a DCT as follows:

A discrete cosine transform (DCT) expresses a finite sequence of data points in terms of a sum of cosine functions oscillating at different frequencies. DCTs are important to numerous applications in science and engineering, from lossy compression of audio (e.g. MP3) and images (e.g. JPEG) (where small high-frequency components can be discarded), to spectral methods for the numerical solution of partial differential equations.

The Inverse Discrete Cosine Transform (IDCT) is the reverse to a given DCT.

## Uses

For many multimedia formats, the respective encoder transforms incoming data via a DCT, modifies the transformed data to achieve high compressibility and creates a compact, compressed representation of the original data. The decoder will uncompress this representation, reverse the DCT via an IDCT, and present the result to the user (e.g., a reconstructed image).

## Code examples

The Theora video codec features a DCT and IDCT using integer arithmetics. SSE2 implementations are available can be found in sse2fdct.c (the DCT) and sse2idct.c (the IDCT).

The reference DCT for JPEG is defined using double precision floating values. A SIMD version of this can be found, e.g., in mozjpeg's jfsseflt-64.asm. However, for performance reasons, the JPEG DCT is often approximated with integer arithmetics, as in jfss2fst-64.asm.

### Involved data types

DCTs can be defined both for floating point values and integer value. Furthermore, for maximum performance, DCTs originally designed for floating point operation are often approximated with integers.

The IDCT of the Theora video compression format can implemented using 16-bit arithmetics, according to the Theora specification, section 7.9.3. Thus the natural SIMD data type to use there is int16x8.

For full-precision floating point DCTs, float64x2 is an option. Much more common are integer approximations, though.