Discrete Cosine Transform API#

DCT API Quick Reference#

Note: The forward DCTs are Type-II. The inverse of the Type-II DCT is the Type-III DCT, so Type-II and Type-III are supported here.

group dct_api

Functions

void dct6_forward(int32_t y[6], const int32_t x[6])#

6-point 32-bit forward DCT.

This function performs a 6-point forward type-II DCT on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result. To avoid possible overflow or saturation, output $$\bar y$$ is scaled down by a factor of $$2^4$$ (see dct6_exp).

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{2^4} \left( 2\sum_{n=0}^{N-1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 6 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct8_forward(int32_t y[8], const int32_t x[8])#

8-point 32-bit forward DCT.

This function performs a 8-point forward type-II DCT on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result. To avoid possible overflow or saturation, output $$\bar y$$ is scaled down by a factor of $$2^4$$ (see dct8_exp).

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{2^4} \left( 2\sum_{n=0}^{N-1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 8 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct12_forward(int32_t y[12], const int32_t x[12])#

12-point 32-bit forward DCT.

This function performs a 12-point forward type-II DCT on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result. To avoid possible overflow or saturation, output $$\bar y$$ is scaled down by a factor of $$2^7$$ (see dct12_exp).

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{2^7} \left( 2\sum_{n=0}^{N-1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 12 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct16_forward(int32_t y[16], const int32_t x[16])#

16-point 32-bit forward DCT.

This function performs a 16-point forward type-II DCT on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result. To avoid possible overflow or saturation, output $$\bar y$$ is scaled down by a factor of $$2^7$$ (see dct16_exp).

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{2^7} \left( 2\sum_{n=0}^{N-1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 16 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct24_forward(int32_t y[24], const int32_t x[24])#

24-point 32-bit forward DCT.

This function performs a 24-point forward type-II DCT on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result. To avoid possible overflow or saturation, output $$\bar y$$ is scaled down by a factor of $$2^{10}$$ (see dct24_exp).

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{2^{10}} \left( 2\sum_{n=0}^{N-1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 24 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct32_forward(int32_t y[32], const int32_t x[32])#

32-point 32-bit forward DCT.

This function performs a 32-point forward type-II DCT on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result. To avoid possible overflow or saturation, output $$\bar y$$ is scaled down by a factor of $$2^{10}$$ (see dct32_exp).

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{2^{10}} \left( 2\sum_{n=0}^{N-1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 32 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct48_forward(int32_t y[48], const int32_t x[48])#

48-point 32-bit forward DCT.

This function performs a 48-point forward type-II DCT on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result. To avoid possible overflow or saturation, output $$\bar y$$ is scaled down by a factor of $$2^{13}$$ (see dct48_exp).

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{2^{13}} \left( 2\sum_{n=0}^{N-1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 48 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct64_forward(int32_t y[64], const int32_t x[64])#

64-point 32-bit forward DCT.

This function performs a 64-point forward type-II DCT on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result. To avoid possible overflow or saturation, output $$\bar y$$ is scaled down by a factor of $$2^{13}$$ (see dct64_exp).

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{2^{13}} \left( 2\sum_{n=0}^{N-1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 64 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct6_inverse(int32_t y[6], const int32_t x[6])#

6-point 32-bit inverse DCT.

This function performs a 6-point inverse DCT (same as type-III DCT) on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result.

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N-1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 6 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct8_inverse(int32_t y[8], const int32_t x[8])#

8-point 32-bit inverse DCT.

This function performs a 8-point inverse DCT (same as type-III DCT) on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result.

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N-1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 8 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct12_inverse(int32_t y[12], const int32_t x[12])#

12-point 32-bit inverse DCT.

This function performs a 12-point inverse DCT (same as type-III DCT) on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result.

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N-1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 12 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct16_inverse(int32_t y[16], const int32_t x[16])#

16-point 32-bit inverse DCT.

This function performs a 16-point inverse DCT (same as type-III DCT) on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result.

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N-1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 16 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct24_inverse(int32_t y[24], const int32_t x[24])#

24-point 32-bit inverse DCT.

This function performs a 24-point inverse DCT (same as type-III DCT) on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result.

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N-1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 24 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct32_inverse(int32_t y[32], const int32_t x[32])#

32-point 32-bit inverse DCT.

This function performs a 32-point inverse DCT (same as type-III DCT) on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result.

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N-1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 32 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct48_inverse(int32_t y[48], const int32_t x[48])#

48-point 32-bit inverse DCT.

This function performs a 48-point inverse DCT (same as type-III DCT) on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result.

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N-1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 48 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

void dct64_inverse(int32_t y[64], const int32_t x[64])#

64-point 32-bit inverse DCT.

This function performs a 64-point inverse DCT (same as type-III DCT) on input vector $$\bar x$$, and populates output vector $$\bar y$$ with the result.

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N-1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N-1) \\ & \qquad\text{with } N = 64 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

headroom_t dct8x8_forward(int8_t y[8][8], const int8_t x[8][8], const right_shift_t sat)#

8-by-8 2D 8-bit forward DCT.

This function performs a 2-dimensional 8-by-8 type-II DCT on 8-bit input tensor $$\bar x$$ (with elements $$x_{rc}$$). Output tensor $$\bar y$$ (with elements $$y_{rc}$$) is populated with the result.

This 2D DCT is performed by first applying a 1D 8-point DCT across each row of $$\bar x$$, and then applying a 1D 8-point DCT to each column of that intermediate tensor.

The output is scaled by a factor of $$2^{-\mathtt{sat}-8}$$. With $$\mathtt{sat}=0$$ this scaling is just enough to avoid any possible saturation. If saturation is considered acceptable, or known a priori to not be possible, negative values for $$\mathtt{sat}$$ can be used to increase precision on the output.

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_{rc} \leftarrow \frac{4 \sum_{m=0}^{N-1} \sum_{n=0}^{N-1} \left( \ x_{mn} \cos\left( c\pi\frac{2n+1}{2N} \right) \cos\left(r\pi\frac{2m+1}{2N} \right)\right)}{2^{\mathtt{sat}+8}}\\ & \\ & \qquad\text{for } r,c \in \{0,1,\dots,(N-1)\} \\ & \qquad\text{with } N = 8 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

• sat[in] Additional output scaling exponent.

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

headroom_t dct8x8_inverse(int8_t y[8][8], const int8_t x[8][8], const right_shift_t sat)#

8-by-8 2D 8-bit inverse DCT.

This function performs a 2-dimensional 8-by-8 type-III (inverse) DCT on 8-bit input tensor $$\bar x$$ (with elements $$x_{rc}$$). Output tensor $$\bar y$$ (with elements $$y_{rc}$$) is populated with the result.

This 2D DCT is performed by first applying a 1D 8-point DCT across each row of $$\bar x$$, and then applying a 1D 8-point DCT to each column of that intermediate tensor.

The output is scaled by a factor of $$2^{-\mathtt{sat}}$$. With $$\mathtt{sat}=0$$ this scaling is just enough to avoid any possible saturation. If saturation is considered acceptable, or known a priori to not be possible, negative values for $$\mathtt{sat}$$ can be used to increase precision on the output.

This operation may be safely performed in-place if x and y point to the same vector.

x and y must point to 8-byte-aligned addresses.

Operation Performed

\begin{split}\begin{aligned} & y_{rc} \leftarrow \frac{ \frac{1}{N^2} \sum_{m=0}^{N-1} \sum_{n=0}^{N-1} \left( \ x_{mn} \cos\left( n\pi\frac{2c+1}{2N} \right) \cos\left(m\pi\frac{2r+1}{2N} \right)\right)}{2^{\mathtt{sat}}}\\ & \\ & \qquad\text{for } r,c \in \{0,1,\dots,(N-1)\} \\ & \qquad\text{with } N = 8 \\ \end{aligned}\end{split}

Parameters:
• y[out] Output vector $$\bar y$$

• x[in] Input vector $$\bar x$$

• sat[in] Additional output scaling exponent.

Raised if x or y is not double word-aligned (See Note: Vector Alignment)

Variables

static const exponent_t dct6_exp = 4#

Scaling exponent associated with dct6_forward()

Let $$\bar x$$ be the input to dct6_forward() and $$\bar y$$ the output. If $$x\_exp$$ and $$y\_exp$$ are the exponents associated with $$\bar x$$ and $$\bar y$$ respectively, then the following relation holds: $$y\_exp = x\_exp + dct6\_exp$$

static const exponent_t dct8_exp = 4#

Scaling exponent associated with dct8_forward()

Let $$\bar x$$ be the input to dct6_forward() and $$\bar y$$ the output. If $$x\_exp$$ and $$y\_exp$$ are the exponents associated with $$\bar x$$ and $$\bar y$$ respectively, then the following relation holds: $$y\_exp = x\_exp + dct8_exp$$

static const exponent_t dct12_exp = 7#

Scaling exponent associated with dct12_forward()

Let $$\bar x$$ be the input to dct12_forward() and $$\bar y$$ the output. If $$x\_exp$$ and $$y\_exp$$ are the exponents associated with $$\bar x$$ and $$\bar y$$ respectively, then the following relation holds: $$y\_exp = x\_exp + dct12_exp$$

static const exponent_t dct16_exp = 7#

Scaling exponent associated with dct16_forward()

Let $$\bar x$$ be the input to dct16_forward() and $$\bar y$$ the output. If $$x\_exp$$ and $$y\_exp$$ are the exponents associated with $$\bar x$$ and $$\bar y$$ respectively, then the following relation holds: $$y\_exp = x\_exp + dct16_exp$$

static const exponent_t dct24_exp = 10#

Scaling exponent associated with dct24_forward()

Let $$\bar x$$ be the input to dct24_forward() and $$\bar y$$ the output. If $$x\_exp$$ and $$y\_exp$$ are the exponents associated with $$\bar x$$ and $$\bar y$$ respectively, then the following relation holds: $$y\_exp = x\_exp + dct24_exp$$

static const exponent_t dct32_exp = 10#

Scaling exponent associated with dct32_forward()

Let $$\bar x$$ be the input to dct32_forward() and $$\bar y$$ the output. If $$x\_exp$$ and $$y\_exp$$ are the exponents associated with $$\bar x$$ and $$\bar y$$ respectively, then the following relation holds: $$y\_exp = x\_exp + dct32_exp$$

static const exponent_t dct48_exp = 13#

Scaling exponent associated with dct48_forward()

Let $$\bar x$$ be the input to dct48_forward() and $$\bar y$$ the output. If $$x\_exp$$ and $$y\_exp$$ are the exponents associated with $$\bar x$$ and $$\bar y$$ respectively, then the following relation holds: $$y\_exp = x\_exp + dct48\_exp$$

static const exponent_t dct64_exp = 13#

Scaling exponent associated with dct64_forward()

Let $$\bar x$$ be the input to dct64_forward() and $$\bar y$$ the output. If $$x\_exp$$ and $$y\_exp$$ are the exponents associated with $$\bar x$$ and $$\bar y$$ respectively, then the following relation holds: $$y\_exp = x\_exp + dct64\_exp$$