@4bitlabs/dct
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@4bitlabs/dct

JavaScript/TypeScript implementations of the DCT, with support for TypedArrays.

DCT-II and DCT-III

import { dct, idct } from '@4bitlabs/dct';

const signal = Uint8ClampedArray.of(/* data */);

// Calculate DCT-II from signal
const coefficients = new Float64Array(signal.length);
dct(signal, coefficients);

// Reconstruct signal from coefficients with DCT-III
const reconstruction = new Uint8ClampedArray(coefficients.length);
idct(coefficients, reconstruction);

Fixed-length DCTs

The dct() and idct() will produce an output of the same length as the signal length. This can be convenient, however the implementations make no optimizations for the number of elements in the vector provided. If the number of elements is known in advance, then you can use createDctOfN(n). For example, to create a 16-element DCT:

import { createDctOfN } from '@4bitlabs';

const dct16 = createDctOfN(16);

// DCT-II
const coefficients = new Float64Array(16);
dct16.transform(data, coefficients);

// DCT-III
const reconstruction = new Uint8ClampedArray(16);
dct16.inverse(coefficients, reconstruction);

Fast 8-element DCT

An faster, optimized version of an 8-element DCT is available and implements the same interface:

import { dct, idct } from '@4bitlabs/dct/fast-dtc-8';

const signal = Uint8ClampedArray.of(0, 0, 0, 0, 0, 0, 0, 0);

// DCT-II
const coefficients = new Float64Array(8);
dct(signal, coefficients);

// DCT-III
const reconstruction = new Uint8ClampedArray(8);
idct(coefficients, reconstruction);

Readme

Keywords

Package Sidebar

Install

npm i @4bitlabs/dct

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

23.1 kB

Total Files

27

Last publish

Collaborators

  • 32bitkid