#discrete #transform #dct #mdct #cosine

rustdct

Compute Discrete Cosine Transforms (DCT) (and related transforms) of any size in O(nlogn) time, in pure Rust

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

Download history 14/week @ 2018-11-01 43/week @ 2018-11-08 18/week @ 2018-11-15 7/week @ 2018-11-22 21/week @ 2018-11-29 21/week @ 2018-12-06 17/week @ 2018-12-13 2/week @ 2018-12-20 54/week @ 2018-12-27 12/week @ 2019-01-03 8/week @ 2019-01-10 16/week @ 2019-01-17

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![0f32; 1234];
let mut output: Vec<f32> = vec![0f32; 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 DCTplanner instance, then call its plan_dct1 or plan_dct2 or etc methods. Each transform type has its own plan_* method which will choose the best algorithm for the given size.

// Compute a DCT Type 2 of size 1234
use std::sync::Arc;
use rustdct::DCTplanner;

let mut input:  Vec<f32> = vec![0f32; 1234];
let mut output: Vec<f32> = vec![0f32; 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 = [0f32; 8];
let mut intermediate = [0f32; 8];
let mut output = [0f32; 8];

let dct = Type2And3Butterfly8::new();

dct.process_dct2(&mut input, &mut intermediate);
dct.process_dct3(&mut intermediate, &mut output);

Dependencies

~564KB
~11K SLoC