Socket
Socket
Sign inDemoInstall

bitdepth

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitdepth - npm Package Compare versions

Comparing version 1.0.5 to 2.0.0

6

dist/bitdepth-min.js
/*
bitdepth
Change the bit depth of samples to and from 8, 16, 24, 32 & 64-bit.
Copyright (c) 2017 Rafael da Silva Rocha.
Copyright (c) 2017-2018 Rafael da Silva Rocha.
https://github.com/rochars/bitdepth

@@ -11,3 +11,3 @@

(function(d){function c(a){if(e[a])return e[a].a;var b=e[a]={m:a,f:!1,a:{}};d[a].call(b.a,b,b.a,c);b.f=!0;return b.a}var e={};c.l=d;c.h=e;c.b=function(a,b){c.c(a)||Object.defineProperty(a,"a",{configurable:!1,enumerable:!0,get:b})};c.i=function(a){var b=a&&a.g?function(){return a["default"]}:function(){return a};c.b(b,b);return b};c.c=function(a){return Object.prototype.hasOwnProperty.call(a,"a")};c.j="";return c(c.o=0)})([function(){var d=new Float32Array(1),c={8:256,16:65536,24:16777216,32:4294967296,
"32f":1,64:1},e={intToInt:function(a,b){return a=0<a?parseInt(a/b.oldPositive*b.newPositive,10):parseInt(a/b.oldNegative*b.newNegative,10)},floatToInt:function(a,b){return 0<a?a*b.newPositive:a*b.newNegative},intToFloat:function(a,b){return 0<a?a/b.oldPositive:a/b.oldNegative},floatToFloat:function(a,b){"64"==b.original&&"32f"==b.target&&(d[0]=a,a=d[0]);return a}};window.toBitDepth=function(a,b,d){var g="8 16 24 32 32f 64".split(" ");if(-1==g.indexOf(b)||-1==g.indexOf(d))throw Error("Invalid bit depth.");
g=["32f","64"].includes(b)?"float":"int";var k=["32f","64"].includes(d)?"Float":"Int";g=e[g+"To"+k];k=a.length;for(var f=0;f<k;f++){var h=a[f];"8"==b&&(h-=128);a[f]=h;a[f]=g(a[f],{oldNegative:c[b]/2,newNegative:c[d]/2,oldPositive:c[b]/2-1,newPositive:c[d]/2-1,original:b,target:d});h=a[f];"8"==d&&(h+=128);a[f]=h}};window.BitDepthMaxValues=c}]);
"32f":1,64:1},e={intToInt:function(a,b){return a=0<a?parseInt(a/b.oldPositive*b.newPositive,10):parseInt(a/b.oldNegative*b.newNegative,10)},floatToInt:function(a,b){return 0<a?a*b.newPositive:a*b.newNegative},intToFloat:function(a,b){return 0<a?a/b.oldPositive:a/b.oldNegative},floatToFloat:function(a,b){"64"==b.original&&"32f"==b.target&&(d[0]=a,a=d[0]);return a}};window.bitDepth=window.bitDepth||{};window.bitDepth.toBitDepth=function(a,b,d){var g="8 16 24 32 32f 64".split(" ");if(-1==g.indexOf(b)||
-1==g.indexOf(d))throw Error("Invalid bit depth.");g=["32f","64"].includes(b)?"float":"int";var k=["32f","64"].includes(d)?"Float":"Int";g=e[g+"To"+k];k=a.length;for(var f=0;f<k;f++){var h=a[f];"8"==b&&(h-=128);a[f]=h;a[f]=g(a[f],{oldNegative:c[b]/2,newNegative:c[d]/2,oldPositive:c[b]/2-1,newPositive:c[d]/2-1,original:b,target:d});h=a[f];"8"==d&&(h+=128);a[f]=h}}}]);

@@ -73,3 +73,3 @@ /******/ (function(modules) { // webpackBootstrap

* Change the bit depth of samples to and from 8, 16, 24, 32 & 64-bit.
* Copyright (c) 2017 Rafael da Silva Rocha.
* Copyright (c) 2017-2018 Rafael da Silva Rocha.
* https://github.com/rochars/bitdepth

@@ -79,3 +79,4 @@ *

const f64f32 = new Float32Array(1);
/** @private */
const f64f32_ = new Float32Array(1);

@@ -85,4 +86,5 @@ /**

* @enum {number}
* @private
*/
const BitDepthMaxValues = {
const MAX_VALUES = {
"8": 256,

@@ -98,4 +100,6 @@ "16": 65536,

* Functions to change the bit depth of a sample.
* @enum {Function}
* @private
*/
const BitDepthFunctions = {
const CODECS = {

@@ -149,4 +153,4 @@ /**

if (args["original"] == "64" && args["target"] == "32f") {
f64f32[0] = sample;
sample = f64f32[0];
f64f32_[0] = sample;
sample = f64f32_[0];
}

@@ -160,3 +164,3 @@ return sample;

* The input array is modified in-place.
* @param {!Array<number>} samples The samples.
* @param {Array<number>} samples The samples.
* @param {string} originalBitDepth The original bit depth of the data.

@@ -168,14 +172,14 @@ * One of "8", "16", "24", "32", "32f", "64"

function toBitDepth(samples, originalBitDepth, targetBitDepth) {
validateBitDepths(originalBitDepth, targetBitDepth);
let toFunction = getBitDepthFunction(originalBitDepth, targetBitDepth);
validateBitDepths_(originalBitDepth, targetBitDepth);
let toFunction = getBitDepthFunction_(originalBitDepth, targetBitDepth);
let len = samples.length;
for (let i=0; i<len; i++) {
samples[i] = sign8Bit(samples[i], originalBitDepth);
samples[i] = sign8Bit_(samples[i], originalBitDepth);
samples[i] = toFunction(
samples[i],
{
"oldNegative": BitDepthMaxValues[originalBitDepth] / 2,
"newNegative": BitDepthMaxValues[targetBitDepth] / 2,
"oldPositive": BitDepthMaxValues[originalBitDepth] / 2 - 1,
"newPositive": BitDepthMaxValues[targetBitDepth] / 2 - 1,
"oldNegative": MAX_VALUES[originalBitDepth] / 2,
"newNegative": MAX_VALUES[targetBitDepth] / 2,
"oldPositive": MAX_VALUES[originalBitDepth] / 2 - 1,
"newPositive": MAX_VALUES[targetBitDepth] / 2 - 1,
"original": originalBitDepth,

@@ -185,3 +189,3 @@ "target": targetBitDepth

);
samples[i] = unsign8Bit(samples[i], targetBitDepth);
samples[i] = unsign8Bit_(samples[i], targetBitDepth);
}

@@ -197,4 +201,5 @@ }

* @return {Function}
* @private
*/
function getBitDepthFunction(originalBitDepth, targetBitDepth) {
function getBitDepthFunction_(originalBitDepth, targetBitDepth) {
let prefix;

@@ -212,3 +217,3 @@ let suffix;

}
return BitDepthFunctions[prefix + "To" + suffix];
return CODECS[prefix + "To" + suffix];
}

@@ -222,4 +227,5 @@

* @return {number}
* @private
*/
function sign8Bit(sample, originalBitDepth) {
function sign8Bit_(sample, originalBitDepth) {
if (originalBitDepth == "8") {

@@ -237,4 +243,5 @@ sample -= 128;

* @return {number}
* @private
*/
function unsign8Bit(sample, targetBitDepth) {
function unsign8Bit_(sample, targetBitDepth) {
if (targetBitDepth == "8") {

@@ -254,4 +261,5 @@ sample += 128;

* @return {boolean}
* @private
*/
function validateBitDepths(originalBitDepth, targetBitDepth) {
function validateBitDepths_(originalBitDepth, targetBitDepth) {
let validBitDepths = ["8", "16", "24", "32", "32f", "64"];

@@ -265,4 +273,3 @@ if (validBitDepths.indexOf(originalBitDepth) == -1 ||

window['toBitDepth'] = toBitDepth;
window['BitDepthMaxValues'] = BitDepthMaxValues;
window['bitDepth'] = window['bitDepth'] || {};window['bitDepth']['toBitDepth'] = toBitDepth;

@@ -269,0 +276,0 @@

/*!
* bitdepth
* Change the bit depth of samples to and from 8, 16, 24, 32 & 64-bit.
* Copyright (c) 2017 Rafael da Silva Rocha.
* Copyright (c) 2017-2018 Rafael da Silva Rocha.
* https://github.com/rochars/bitdepth

@@ -9,3 +9,4 @@ *

const f64f32 = new Float32Array(1);
/** @private */
const f64f32_ = new Float32Array(1);

@@ -15,4 +16,5 @@ /**

* @enum {number}
* @private
*/
const BitDepthMaxValues = {
const MAX_VALUES = {
"8": 256,

@@ -28,4 +30,6 @@ "16": 65536,

* Functions to change the bit depth of a sample.
* @enum {Function}
* @private
*/
const BitDepthFunctions = {
const CODECS = {

@@ -79,4 +83,4 @@ /**

if (args["original"] == "64" && args["target"] == "32f") {
f64f32[0] = sample;
sample = f64f32[0];
f64f32_[0] = sample;
sample = f64f32_[0];
}

@@ -90,3 +94,3 @@ return sample;

* The input array is modified in-place.
* @param {!Array<number>} samples The samples.
* @param {Array<number>} samples The samples.
* @param {string} originalBitDepth The original bit depth of the data.

@@ -98,14 +102,14 @@ * One of "8", "16", "24", "32", "32f", "64"

function toBitDepth(samples, originalBitDepth, targetBitDepth) {
validateBitDepths(originalBitDepth, targetBitDepth);
let toFunction = getBitDepthFunction(originalBitDepth, targetBitDepth);
validateBitDepths_(originalBitDepth, targetBitDepth);
let toFunction = getBitDepthFunction_(originalBitDepth, targetBitDepth);
let len = samples.length;
for (let i=0; i<len; i++) {
samples[i] = sign8Bit(samples[i], originalBitDepth);
samples[i] = sign8Bit_(samples[i], originalBitDepth);
samples[i] = toFunction(
samples[i],
{
"oldNegative": BitDepthMaxValues[originalBitDepth] / 2,
"newNegative": BitDepthMaxValues[targetBitDepth] / 2,
"oldPositive": BitDepthMaxValues[originalBitDepth] / 2 - 1,
"newPositive": BitDepthMaxValues[targetBitDepth] / 2 - 1,
"oldNegative": MAX_VALUES[originalBitDepth] / 2,
"newNegative": MAX_VALUES[targetBitDepth] / 2,
"oldPositive": MAX_VALUES[originalBitDepth] / 2 - 1,
"newPositive": MAX_VALUES[targetBitDepth] / 2 - 1,
"original": originalBitDepth,

@@ -115,3 +119,3 @@ "target": targetBitDepth

);
samples[i] = unsign8Bit(samples[i], targetBitDepth);
samples[i] = unsign8Bit_(samples[i], targetBitDepth);
}

@@ -127,4 +131,5 @@ }

* @return {Function}
* @private
*/
function getBitDepthFunction(originalBitDepth, targetBitDepth) {
function getBitDepthFunction_(originalBitDepth, targetBitDepth) {
let prefix;

@@ -142,3 +147,3 @@ let suffix;

}
return BitDepthFunctions[prefix + "To" + suffix];
return CODECS[prefix + "To" + suffix];
}

@@ -152,4 +157,5 @@

* @return {number}
* @private
*/
function sign8Bit(sample, originalBitDepth) {
function sign8Bit_(sample, originalBitDepth) {
if (originalBitDepth == "8") {

@@ -167,4 +173,5 @@ sample -= 128;

* @return {number}
* @private
*/
function unsign8Bit(sample, targetBitDepth) {
function unsign8Bit_(sample, targetBitDepth) {
if (targetBitDepth == "8") {

@@ -184,4 +191,5 @@ sample += 128;

* @return {boolean}
* @private
*/
function validateBitDepths(originalBitDepth, targetBitDepth) {
function validateBitDepths_(originalBitDepth, targetBitDepth) {
let validBitDepths = ["8", "16", "24", "32", "32f", "64"];

@@ -196,2 +204,1 @@ if (validBitDepths.indexOf(originalBitDepth) == -1 ||

module.exports.toBitDepth = toBitDepth;
module.exports.BitDepthMaxValues = BitDepthMaxValues;
{
"name": "bitdepth",
"version": "1.0.5",
"version": "2.0.0",
"description": "Change the bit depth of samples to and from 8, 16, 24, 32 & 64-bit.",

@@ -30,12 +30,12 @@ "homepage": "https://github.com/rochars/bitdepth",

"lint": "jshint index.js && jshint test",
"test": "nyc ./node_modules/mocha/bin/_mocha test --recursive",
"test": "nyc ./node_modules/mocha/bin/_mocha test --src --recursive",
"test-dist": "nyc ./node_modules/mocha/bin/_mocha test --dist --recursive",
"coverage": "nyc report --reporter=lcov > coverage.lcov && codecov",
"bundle": "webpack",
"compile": "google-closure-compiler-js dist/bitdepth.js > dist/bitdepth-min.js --compilationLevel=ADVANCED",
"doc": "./node_modules/.bin/jsdoc index.js -d docs -r README.md -t node_modules/docdash",
"qa": "npm run lint && npm test",
"pack": "npm run bundle && npm run compile && npm run doc",
"build": "npm run qa && npm run pack"
"pack": "webpack && npm run compile && npm run doc",
"build": "npm run lint && npm run pack && npm run test-dist && npm test"
},
"devDependencies": {
"browser-env": "^3.2.5",
"chai": "^4.1.2",

@@ -42,0 +42,0 @@ "codecov": "^3.0.0",

# bitdepth
Change the bit depth of samples to and from 8, 16, 24, 32 & 64-bit.
Copyright (c) 2017 Rafael da Silva Rocha.
Copyright (c) 2017-2018 Rafael da Silva Rocha.
https://github.com/rochars/bitdepth
[![Travis](https://img.shields.io/travis/rochars/bitdepth.svg?style=for-the-badge)](https://travis-ci.org/rochars/bitdepth) [![AppVeyor](https://img.shields.io/appveyor/ci/rochars/bitdepth.svg?style=for-the-badge&logo=appveyor)](https://ci.appveyor.com/project/rochars/bitdepth) [![Codecov](https://img.shields.io/codecov/c/github/rochars/bitdepth.svg?style=for-the-badge)](https://codecov.io/gh/rochars/bitdepth) [![NPM version](https://img.shields.io/npm/v/bitdepth.svg?style=for-the-badge)](https://www.npmjs.com/package/bitdepth)
[![NPM version](https://img.shields.io/npm/v/bitdepth.svg?style=for-the-badge)](https://www.npmjs.com/package/bitdepth) [![Docs](https://img.shields.io/badge/docs-online-blue.svg?style=for-the-badge)](https://rochars.github.io/bitdepth/index.html)
[![Codecov](https://img.shields.io/codecov/c/github/rochars/bitdepth.svg?style=flat-square)](https://codecov.io/gh/rochars/bitdepth) [![Unix Build](https://img.shields.io/travis/rochars/bitdepth.svg?style=flat-square)](https://travis-ci.org/rochars/bitdepth) [![Windows Build](https://img.shields.io/appveyor/ci/rochars/bitdepth.svg?style=flat-square&logo=appveyor)](https://ci.appveyor.com/project/rochars/bitdepth) [![Scrutinizer](https://img.shields.io/scrutinizer/g/rochars/bitdepth.svg?style=flat-square&logo=scrutinizer)](https://scrutinizer-ci.com/g/rochars/bitdepth/)

@@ -14,8 +15,10 @@ ## Install

## Use
Currently there is **no dithering** when changing the bit depth.
Supported bit depths (to and from):
- "8": 8-bit int (unsigned)
- "16": 16-bit int
- "24": 24-bit int
- "32": 32-bit int
- "32f": 32-bit float
- "64": 64-bit float
- **16-bit** is always int
- **32-bit** can be int or float
- **64-bit** is always float.
```javascript

@@ -39,3 +42,3 @@ const bitDepth = require("bitdepth");

* The input array is modified in-place.
* @param {!Array<number>} samples The samples.
* @param {Array<number>} samples The samples.
* @param {string} originalBitDepth The original bit depth of the data.

@@ -50,3 +53,3 @@ * One of "8", "16", "24", "32", "32f", "64"

## LICENSE
Copyright (c) 2017 Rafael da Silva Rocha.
Copyright (c) 2017-2018 Rafael da Silva Rocha.

@@ -53,0 +56,0 @@ Permission is hereby granted, free of charge, to any person obtaining

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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