#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

#18 in Encoding

Download history 4/week @ 2018-05-14 11/week @ 2018-05-21 12/week @ 2018-05-28 20/week @ 2018-06-04 3/week @ 2018-06-11 54/week @ 2018-06-18 8/week @ 2018-06-25 66/week @ 2018-07-02 9/week @ 2018-07-09 15/week @ 2018-07-16 5/week @ 2018-07-23 14/week @ 2018-07-30 55/week @ 2018-08-06

92 downloads per month

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);
MIT OR Apache-2.0 license

Dependencies

Reverse deps