New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@4bitlabs/dct

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@4bitlabs/dct

Discrete cosine transform algorithms in js and ts

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
0
Weekly downloads
 
Created
Source

@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);

Keywords

FAQs

Package last updated on 21 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc