Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 3.0.1 to 3.0.2

18

dist/bitdepth-min.js

@@ -1,13 +0,5 @@

/*
bitdepth
Change the resolution of samples to and from 8, 11, 12, 16, 20, 24, 32, 48 & 64-bit.
Copyright (c) 2017-2018 Rafael da Silva Rocha.
https://github.com/rochars/bitdepth
*/
var k="function"==typeof Object.defineProperties?Object.defineProperty:function(c,d,a){c!=Array.prototype&&c!=Object.prototype&&(c[d]=a.value)},l="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function m(c,d){if(d){var a=l;c=c.split(".");for(var b=0;b<c.length-1;b++){var e=c[b];e in a||(a[e]={});a=a[e]}c=c[c.length-1];b=a[c];d=d(b);d!=b&&null!=d&&k(a,c,{configurable:!0,writable:!0,value:d})}}
m("Object.is",function(c){return c?c:function(d,a){return d===a?0!==d||1/d===1/a:d!==d&&a!==a}});m("Array.prototype.includes",function(c){return c?c:function(d,a){var b=this;b instanceof String&&(b=String(b));var c=b.length;for(a=a||0;a<c;a++)if(b[a]==d||Object.is(b[a],d))return!0;return!1}});
(function(c){function d(b){if(a[b])return a[b].a;var e=a[b]={m:b,f:!1,a:{}};c[b].call(e.a,e,e.a,d);e.f=!0;return e.a}var a={};d.l=c;d.h=a;d.b=function(a,c){d.c(a)||Object.defineProperty(a,"a",{configurable:!1,enumerable:!0,get:c})};d.i=function(a){var b=a&&a.g?function(){return a["default"]}:function(){return a};d.b(b,b);return b};d.c=function(a){return Object.prototype.hasOwnProperty.call(a,"a")};d.j="";return d(d.o=0)})([function(){var c=new Float32Array(1),d={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?parseInt(a*b.newPositive,10):parseInt(a*b.newNegative,10)},intToFloat:function(a,b){return 0<a?a/b.oldPositive:a/b.oldNegative},floatToFloat:function(a,b){"64"==b.original&&"32f"==b.target&&(c[0]=a,a=c[0]);return a}};window.bitDepth=window.bitDepth||{};window.bitDepth.toBitDepth=function(a,b,c){for(var e=[],g=8;49>g;g++)e.push(g.toString());e.push("32f");e.push("64");if(-1==
e.indexOf(b)||-1==e.indexOf(c))throw Error("Invalid bit depth.");e=["32f","64"].includes(b)?"float":"int";g=["32f","64"].includes(c)?"Float":"Int";e=d[e+"To"+g];g=a.length;for(var f=0;f<g;f++){var h=a[f];"8"==b&&(h-=128);a[f]=h;a[f]=e(a[f],{oldNegative:parseInt(Math.pow(2,parseInt(b,10))/2,10),newNegative:parseInt(Math.pow(2,parseInt(c,10))/2,10),oldPositive:parseInt(Math.pow(2,parseInt(b,10))/2-1,10),newPositive:parseInt(Math.pow(2,parseInt(c,10))/2-1,10),original:b,target:c});h=a[f];"8"==c&&(h+=
128);a[f]=h}}}]);
var m="function"==typeof Object.defineProperties?Object.defineProperty:function(c,a,b){c!=Array.prototype&&c!=Object.prototype&&(c[a]=b.value)},n="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function p(c,a){if(a){var b=n;c=c.split(".");for(var d=0;d<c.length-1;d++){var e=c[d];e in b||(b[e]={});b=b[e]}c=c[c.length-1];d=b[c];a=a(d);a!=d&&null!=a&&m(b,c,{configurable:!0,writable:!0,value:a})}}
p("Object.is",function(c){return c?c:function(a,b){return a===b?0!==a||1/a===1/b:a!==a&&b!==b}});p("Array.prototype.includes",function(c){return c?c:function(a,b){var d=this;d instanceof String&&(d=String(d));var c=d.length;for(b=b||0;b<c;b++)if(d[b]==a||Object.is(d[b],a))return!0;return!1}});
(function(c){function a(d){if(b[d])return b[d].a;var e=b[d]={v:d,j:!1,a:{}};c[d].call(e.a,e,e.a,a);e.j=!0;return e.a}var b={};a.u=c;a.m=b;a.h=function(d,b){a.i(d)||Object.defineProperty(d,"a",{configurable:!1,enumerable:!0,get:b})};a.o=function(d){var b=d&&d.l?function(){return d["default"]}:function(){return d};a.h(b,b);return b};a.i=function(b){return Object.prototype.hasOwnProperty.call(b,"a")};a.s="";return a(a.w=0)})([function(c){function a(a,c,g){if(c==g)return a;for(var h=["32f","64"],k=8;54>
k;k++)h.push(k.toString());if(-1==h.indexOf(c)||-1==h.indexOf(g))throw Error("Invalid bit depth.");h=["32f","64"].includes(c)?["32f","64"].includes(g)?q:d:["32f","64"].includes(g)?e:b;k=a.length;for(var l={f:parseInt(Math.pow(2,parseInt(c,10))/2,10),b:parseInt(Math.pow(2,parseInt(g,10))/2,10),g:parseInt(Math.pow(2,parseInt(c,10))/2-1,10),c:parseInt(Math.pow(2,parseInt(g,10))/2-1,10),A:c,target:g},f=0;f<k;f++)a[f]="8"==c?a[f]-128:a[f],a[f]=h(a[f],l),a[f]="8"==g?a[f]+128:a[f]}function b(a,b){return a=
0<a?parseInt(a/b.g*b.c,10):parseInt(a/b.f*b.b,10)}function d(a,b){return 0<a?parseInt(a*b.c,10):parseInt(a*b.b,10)}function e(a,b){return 0<a?a/b.g:a/b.f}function q(a){l[0]=a;return a=l[0]}var l=new Float32Array(1);c.a=a;window.bitDepth=window.bitDepth||{};window.bitDepth.toBitDepth=a}]);

@@ -1,2 +0,2 @@

/*!
/**
* bitdepth

@@ -13,92 +13,35 @@ * Change the resolution of samples to and from 8, 11, 12, 16, 20, 24, 32, 48 & 64-bit.

/**
* Functions to change the resolution of a sample.
* @enum {Function}
* @private
*/
const CODECS = {
/**
* Change the bit depth from int to int.
* @param {number} sample The sample.
* @param {Object} args Data about the original and target bit depths.
* @return {number}
*/
"intToInt": function(sample, args) {
if (sample > 0) {
sample = parseInt(
(sample / args["oldPositive"]) * args["newPositive"], 10);
} else {
sample = parseInt(
(sample / args["oldNegative"]) * args["newNegative"], 10);
}
return sample;
},
/**
* Change the bit depth from float to int.
* @param {number} sample The sample.
* @param {Object} args Data about the original and target bit depths.
* @return {number}
*/
"floatToInt": function(sample, args) {
return sample > 0 ?
parseInt(sample * args["newPositive"], 10) :
parseInt(sample * args["newNegative"], 10);
},
/**
* Change the bit depth from int to float.
* @param {number} sample The sample.
* @param {Object} args Data about the original and target bit depths.
* @return {number}
*/
"intToFloat": function(sample, args) {
return sample > 0 ?
sample / args["oldPositive"] : sample / args["oldNegative"];
},
/**
* Change the bit depth from float to float.
* @param {number} sample The sample.
* @param {Object} args Data about the original and target bit depths.
* @return {number}
*/
"floatToFloat": function(sample, args) {
if (args["original"] == "64" && args["target"] == "32f") {
f64f32_[0] = sample;
sample = f64f32_[0];
}
return sample;
}
};
/**
* Change the bit depth of the data in a array.
* The input array is modified in-place.
* @param {Array<number>} samples The samples.
* @param {string} originalBitDepth The original bit depth of the data.
* One of "8" ... "48", "32f", "64"
* @param {string} targetBitDepth The new bit depth of the data.
* One of "8" ... "48", "32f", "64"
* @param {!Array<number>} samples The samples.
* @param {!string} originalBitDepth The original bit depth of the data.
* One of "8" ... "53", "32f", "64"
* @param {!string} targetBitDepth The desired bit depth for the data.
* One of "8" ... "53", "32f", "64"
*/
function toBitDepth(samples, originalBitDepth, targetBitDepth) {
if (originalBitDepth == targetBitDepth) {
return samples;
}
validateBitDepths_(originalBitDepth, targetBitDepth);
let toFunction = getBitDepthFunction_(originalBitDepth, targetBitDepth);
let len = samples.length;
let options = {
oldNegative: parseInt(
Math.pow(2, parseInt(originalBitDepth, 10)) / 2, 10),
newNegative: parseInt(
Math.pow(2, parseInt(targetBitDepth, 10)) / 2, 10),
oldPositive: parseInt(
Math.pow(2, parseInt(originalBitDepth, 10)) / 2 - 1, 10),
newPositive: parseInt(
Math.pow(2, parseInt(targetBitDepth, 10)) / 2 - 1, 10),
original: originalBitDepth,
target: targetBitDepth
};
for (let i=0; i<len; i++) {
samples[i] = sign8Bit_(samples[i], originalBitDepth);
samples[i] = originalBitDepth == "8" ? samples[i] - 128 : samples[i];
samples[i] = toFunction(
samples[i],
{
"oldNegative": parseInt(
Math.pow(2, parseInt(originalBitDepth, 10)) / 2, 10),
"newNegative": parseInt(
Math.pow(2, parseInt(targetBitDepth, 10)) / 2, 10),
"oldPositive": parseInt(
Math.pow(2, parseInt(originalBitDepth, 10)) / 2 - 1, 10),
"newPositive": parseInt(
Math.pow(2, parseInt(targetBitDepth, 10)) / 2 - 1, 10),
"original": originalBitDepth,
"target": targetBitDepth
});
samples[i] = unsign8Bit_(samples[i], targetBitDepth);
options);
samples[i] = targetBitDepth == "8" ? samples[i] + 128 : samples[i];
}

@@ -108,38 +51,54 @@ }

/**
* Get the function to change the bit depth of a sample.
* @param {string} originalBitDepth The original bit depth of the data.
* One of "8" ... "48", "32f", "64"
* @param {string} targetBitDepth The new bit depth of the data.
* One of "8" ... "48", "32f", "64"
* @return {Function}
* Change the bit depth from int to int.
* @param {!number} sample The sample.
* @param {!Object} args Data about the original and target bit depths.
* @return {!number}
* @private
*/
function getBitDepthFunction_(originalBitDepth, targetBitDepth) {
let prefix;
let suffix;
if (["32f", "64"].includes(originalBitDepth)) {
prefix = "float";
function intToInt_(sample, args) {
if (sample > 0) {
sample = parseInt(
(sample / args.oldPositive) * args.newPositive, 10);
} else {
prefix = "int";
sample = parseInt(
(sample / args.oldNegative) * args.newNegative, 10);
}
if (["32f", "64"].includes(targetBitDepth)) {
suffix = "Float";
} else {
suffix = "Int";
}
return CODECS[prefix + "To" + suffix];
return sample;
}
/**
* Sign unsigned 8-bit data.
* @param {number} sample The sample.
* @param {string} originalBitDepth The original bit depth of the data.
* One of "8" ... "48", "32f", "64"
* @return {number}
* Change the bit depth from float to int.
* @param {!number} sample The sample.
* @param {!Object} args Data about the original and target bit depths.
* @return {!number}
* @private
*/
function sign8Bit_(sample, originalBitDepth) {
if (originalBitDepth == "8") {
sample -= 128;
}
function floatToInt_(sample, args) {
return sample > 0 ?
parseInt(sample * args.newPositive, 10) :
parseInt(sample * args.newNegative, 10);
}
/**
* Change the bit depth from int to float.
* @param {!number} sample The sample.
* @param {!Object} args Data about the original and target bit depths.
* @return {!number}
* @private
*/
function intToFloat_(sample, args) {
return sample > 0 ?
sample / args.oldPositive : sample / args.oldNegative;
}
/**
* Change the bit depth from float to float.
* @param {!number} sample The sample.
* @param {!Object} args Data about the original and target bit depths.
* @return {!number}
* @private
*/
function floatToFloat_(sample, args) {
f64f32_[0] = sample;
sample = f64f32_[0];
return sample;

@@ -149,14 +108,24 @@ }

/**
* Unsign signed 8-bit data.
* @param {number} sample The sample.
* @param {string} targetBitDepth The target bit depth of the data.
* One of "8" ... "48", "32f", "64"
* @return {number}
* Get the function to change the bit depth of a sample.
* @param {!string} originalBitDepth The original bit depth of the data.
* One of "8" ... "53", "32f", "64"
* @param {!string} targetBitDepth The new bit depth of the data.
* One of "8" ... "53", "32f", "64"
* @return {!Function}
* @private
*/
function unsign8Bit_(sample, targetBitDepth) {
if (targetBitDepth == "8") {
sample += 128;
function getBitDepthFunction_(originalBitDepth, targetBitDepth) {
if (["32f", "64"].includes(originalBitDepth)) {
if (["32f", "64"].includes(targetBitDepth)) {
return floatToFloat_;
} else {
return floatToInt_;
}
} else {
if (["32f", "64"].includes(targetBitDepth)) {
return intToFloat_;
} else {
return intToInt_;
}
}
return sample;
}

@@ -166,17 +135,15 @@

* Validate the bit depth.
* @param {string} originalBitDepth The original bit depth.
* Should be one of "8" ... "48", "32f", "64".
* @param {string} targetBitDepth The target bit depth.
* Should be one of "8" ... "48", "32f", "64".
* @param {!string} originalBitDepth The original bit depth.
* Should be one of "8" ... "53", "32f", "64".
* @param {!string} targetBitDepth The target bit depth.
* Should be one of "8" ... "53", "32f", "64".
* @throws {Error} If any argument does not meet the criteria.
* @return {boolean}
* @return {!boolean}
* @private
*/
function validateBitDepths_(originalBitDepth, targetBitDepth) {
let validBitDepths = [];
for (let i=8; i<49; i++) {
let validBitDepths = ["32f", "64"];
for (let i=8; i<54; i++) {
validBitDepths.push(i.toString());
}
validBitDepths.push("32f");
validBitDepths.push("64");
if (validBitDepths.indexOf(originalBitDepth) == -1 ||

@@ -189,2 +156,3 @@ validBitDepths.indexOf(targetBitDepth) == -1) {

module.exports = toBitDepth;
module.exports.toBitDepth = toBitDepth;
{
"name": "bitdepth",
"version": "3.0.1",
"version": "3.0.2",
"description": "Change the resolution of samples to and from 8, 11, 12, 16, 20, 24, 32, 48 & 64-bit.",

@@ -37,6 +37,5 @@ "homepage": "https://github.com/rochars/bitdepth",

"coverage": "nyc report --reporter=lcov > coverage.lcov && codecov",
"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",
"pack": "webpack && npm run compile && npm run doc",
"build": "npm run lint && npm run pack && npm run test-dist && npm test"
"pack": "webpack && npm run test-dist",
"build": "npm run lint && npm run pack && npm test && npm run doc"
},

@@ -43,0 +42,0 @@ "devDependencies": {

@@ -17,3 +17,3 @@ # bitdepth

- "8": 8-bit int (unsigned)
- Anything between "9" and "48" (integers, signed)
- Anything between "9" and "53" (integers, signed)
- "32f": 32-bit float

@@ -40,7 +40,7 @@ - "64": 64-bit float

* The input array is modified in-place.
* @param {Array<number>} samples The samples.
* @param {string} originalBitDepth The original bit depth of the data.
* One of "8" ... "48", "32f", "64"
* @param {string} targetBitDepth The new bit depth of the data.
* One of "8" ... "48", "32f", "64"
* @param {!Array<number>} samples The samples.
* @param {!string} originalBitDepth The original bit depth of the data.
* One of "8" ... "53", "32f", "64"
* @param {!string} targetBitDepth The desired bit depth for the data.
* One of "8" ... "53", "32f", "64"
*/

@@ -47,0 +47,0 @@ function toBitDepth(samples, originalBitDepth, targetBitDepth) {}

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