### 7 releases

0.3.0 | Aug 6, 2018 |
---|---|

0.2.1 | Mar 19, 2018 |

0.1.3 | Jun 28, 2017 |

0.1.1 | May 24, 2017 |

#**12** in Encoding

**92** downloads per month

**MIT/Apache**

157KB

3K
SLoC

# RustDCT

RustDCT is a pure-Rust signal processing library that computes the most common Discrete Cosine Transforms:

- Discrete Cosine Transform (DCT) Types 1, 2, 3, 4
- Discrete Sine Transform (DST) Types 1, 2, 3, 4
- Modified Discrete Cosine Transform (MDCT)

## Example

`//` Compute a DCT Type 2 of size 1234
`use` `rustdct``::`DCTplanner`;`
`let` `mut` input`:` `Vec``<``f32``>` `=` `vec!``[``0``f32``;` `1234``]``;`
`let` `mut` output`:` `Vec``<``f32``>` `=` `vec!``[``0``f32``;` `1234``]``;`
`let` `mut` planner `=` `DCTplanner``::`new`(``)``;`
`let` `mut` dct `=` planner`.``plan_dct2``(``1234``)``;`
dct`.``process``(``&``mut` input`,` `&``mut` output`)``;`

## Releases

Release notes are available in RELEASES.md.

###
`lib.rs`

:

RustDCT is a pure-Rust signal processing library that computes the most common Discrete Cosine Transforms

- Discrete Cosine Transform (DCT) Types 1, 2, 3, 4
- Discrete Sine Transform (DST) Types 1, 2, 3, 4
- Modified Discrete Cosine Transform (MDCT)

The recommended way to use RustDCT is to create a

instance, then call its
`DCTplanner`

or `plan_dct1`

or etc methods. Each transform type has its own `plan_dct2`

method which will choose the best algorithm
for the given size.`plan_ *`

`//` Compute a DCT Type 2 of size 1234
`use` `std``::``sync``::`Arc`;`
`use` `rustdct``::`DCTplanner`;`
`let` `mut` input`:` `Vec``<``f32``>` `=` `vec!``[``0``f32``;` `1234``]``;`
`let` `mut` output`:` `Vec``<``f32``>` `=` `vec!``[``0``f32``;` `1234``]``;`
`let` `mut` planner `=` `DCTplanner``::`new`(``)``;`
`let` dct `=` planner`.``plan_dct2``(``1234``)``;`
dct`.``process_dct2``(``&``mut` input`,` `&``mut` output`)``;`
`//` The DCT instance returned by the planner is stored behind an `Arc`, so it's cheap to clone
`let` dct_clone `=` `Arc``::`clone`(``&`dct`)``;`

RustDCT also exposes individual DCT algorithms. For example, if you're writing a JPEG compression library, it's safe to assume you want a DCT2 and DCT3 of size 8. Instead of going through the planner, you can directly create hardcoded DCT instances of size 8.

`//` Compute a DCT type 2 of size 8, and then compute a DCT type 3 of size 8 on the output.
`use` `rustdct``::``{``DCT2``,` `DCT3``}``;`
`use` `rustdct``::``algorithm``::``type2and3_butterflies``::`Type2And3Butterfly8`;`
`let` `mut` input `=` `[``0``f32``;` `8``]``;`
`let` `mut` intermediate `=` `[``0``f32``;` `8``]``;`
`let` `mut` output `=` `[``0``f32``;` `8``]``;`
`let` dct `=` `Type2And3Butterfly8``::`new`(``)``;`
dct`.``process_dct2``(``&``mut` input`,` `&``mut` intermediate`)``;`
dct`.``process_dct3``(``&``mut` intermediate`,` `&``mut` output`)``;`

#### Dependencies

~564KB

~11K SLoC