Discrete Cosine Transform API#
DCT API Quick Reference#
Note: The forward DCTs are TypeII. The inverse of the TypeII DCT is the TypeIII DCT, so TypeII and TypeIII are supported here.
Brief 
Forward Function 
Inverse Function 

6point DCT 

8point DCT 

12point DCT 

16point DCT 

24point DCT 

32point DCT 

48point DCT 

64point DCT 

8by8 2dimensional DCT 
 group dct_api
Functions

void dct6_forward(int32_t y[6], const int32_t x[6])#
6point 32bit forward DCT.
This function performs a 6point forward typeII 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 inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{2^4} \left( 2\sum_{n=0}^{N1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 6 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct8_forward(int32_t y[8], const int32_t x[8])#
8point 32bit forward DCT.
This function performs a 8point forward typeII 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 inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{2^4} \left( 2\sum_{n=0}^{N1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 8 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct12_forward(int32_t y[12], const int32_t x[12])#
12point 32bit forward DCT.
This function performs a 12point forward typeII 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 inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{2^7} \left( 2\sum_{n=0}^{N1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 12 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct16_forward(int32_t y[16], const int32_t x[16])#
16point 32bit forward DCT.
This function performs a 16point forward typeII 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 inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{2^7} \left( 2\sum_{n=0}^{N1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 16 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct24_forward(int32_t y[24], const int32_t x[24])#
24point 32bit forward DCT.
This function performs a 24point forward typeII 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 inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{2^{10}} \left( 2\sum_{n=0}^{N1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 24 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct32_forward(int32_t y[32], const int32_t x[32])#
32point 32bit forward DCT.
This function performs a 32point forward typeII 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 inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{2^{10}} \left( 2\sum_{n=0}^{N1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 32 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct48_forward(int32_t y[48], const int32_t x[48])#
48point 32bit forward DCT.
This function performs a 48point forward typeII 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 inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{2^{13}} \left( 2\sum_{n=0}^{N1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 48 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct64_forward(int32_t y[64], const int32_t x[64])#
64point 32bit forward DCT.
This function performs a 64point forward typeII 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 inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{2^{13}} \left( 2\sum_{n=0}^{N1} x_n \cos\left( k\pi \frac{2n+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 64 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct6_inverse(int32_t y[6], const int32_t x[6])#
6point 32bit inverse DCT.
This function performs a 6point inverse DCT (same as typeIII DCT) on input vector \(\bar x\), and populates output vector \(\bar y\) with the result.
This operation may be safely performed inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 6 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct8_inverse(int32_t y[8], const int32_t x[8])#
8point 32bit inverse DCT.
This function performs a 8point inverse DCT (same as typeIII DCT) on input vector \(\bar x\), and populates output vector \(\bar y\) with the result.
This operation may be safely performed inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 8 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct12_inverse(int32_t y[12], const int32_t x[12])#
12point 32bit inverse DCT.
This function performs a 12point inverse DCT (same as typeIII DCT) on input vector \(\bar x\), and populates output vector \(\bar y\) with the result.
This operation may be safely performed inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 12 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct16_inverse(int32_t y[16], const int32_t x[16])#
16point 32bit inverse DCT.
This function performs a 16point inverse DCT (same as typeIII DCT) on input vector \(\bar x\), and populates output vector \(\bar y\) with the result.
This operation may be safely performed inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 16 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct24_inverse(int32_t y[24], const int32_t x[24])#
24point 32bit inverse DCT.
This function performs a 24point inverse DCT (same as typeIII DCT) on input vector \(\bar x\), and populates output vector \(\bar y\) with the result.
This operation may be safely performed inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 24 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct32_inverse(int32_t y[32], const int32_t x[32])#
32point 32bit inverse DCT.
This function performs a 32point inverse DCT (same as typeIII DCT) on input vector \(\bar x\), and populates output vector \(\bar y\) with the result.
This operation may be safely performed inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 32 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct48_inverse(int32_t y[48], const int32_t x[48])#
48point 32bit inverse DCT.
This function performs a 48point inverse DCT (same as typeIII DCT) on input vector \(\bar x\), and populates output vector \(\bar y\) with the result.
This operation may be safely performed inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 48 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

void dct64_inverse(int32_t y[64], const int32_t x[64])#
64point 32bit inverse DCT.
This function performs a 64point inverse DCT (same as typeIII DCT) on input vector \(\bar x\), and populates output vector \(\bar y\) with the result.
This operation may be safely performed inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_k \leftarrow \frac{1}{N} \left( \frac{x_0}{2} + \ \sum_{n=1}^{N1} x_n \cos\left( n\pi \frac{2k+1}{2N} \right) \right) \\ & \qquad\text{for } k = 0,1,\dots,(N1) \\ & \qquad\text{with } N = 64 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

headroom_t dct8x8_forward(int8_t y[8][8], const int8_t x[8][8], const right_shift_t sat)#
8by8 2D 8bit forward DCT.
This function performs a 2dimensional 8by8 typeII DCT on 8bit 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 8point DCT across each row of \(\bar x\), and then applying a 1D 8point 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 inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_{rc} \leftarrow \frac{4 \sum_{m=0}^{N1} \sum_{n=0}^{N1} \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,(N1)\} \\ & \qquad\text{with } N = 8 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
sat – [in] Additional output scaling exponent.
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (See Note: Vector Alignment)

headroom_t dct8x8_inverse(int8_t y[8][8], const int8_t x[8][8], const right_shift_t sat)#
8by8 2D 8bit inverse DCT.
This function performs a 2dimensional 8by8 typeIII (inverse) DCT on 8bit 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 8point DCT across each row of \(\bar x\), and then applying a 1D 8point 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 inplace if
x
andy
point to the same vector.x
andy
must point to 8bytealigned addresses. Operation Performed:
 \[\begin{split}\begin{flalign*} & y_{rc} \leftarrow \frac{ \frac{1}{N^2} \sum_{m=0}^{N1} \sum_{n=0}^{N1} \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,(N1)\} \\ & \qquad\text{with } N = 8 \\ && \end{flalign*}\end{split}\]
 Parameters:
y – [out] Output vector \(\bar y\)
x – [in] Input vector \(\bar x\)
sat – [in] Additional output scaling exponent.
 Throws ET_LOAD_STORE:
Raised if
x
ory
is not double wordaligned (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\)

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