Comparing version 3.1.0 to 3.1.1
@@ -1,5 +0,5 @@ | ||
var l="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 f=c[d];f in b||(b[f]={});b=b[f]}c=c[c.length-1];d=b[c];a=a(d);a!=d&&null!=a&&l(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 f=b[d]={v:d,j:!1,a:{}};c[d].call(f.a,f,f.a,a);f.j=!0;return f.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,e,c,g){if("64"!=e||"64"!=c){m(e);m(c);g=g||a;var k= | ||
a.length;var h=["32f","64"].includes(e)?["32f","64"].includes(c)?q:d:["32f","64"].includes(c)?f:b;var r={g:Math.pow(2,parseInt(e,10))/2,c:Math.pow(2,parseInt(c,10))/2,f:Math.pow(2,parseInt(e,10))/2-1,b:Math.pow(2,parseInt(c,10))/2-1};if("8"==e)for(e=0;e<k;e++)g[e]=a[e]-=128;for(e=0;e<k;e++)g[e]=h(a[e],r);if("8"==c)for(a=0;a<k;a++)g[a]=g[a]+=128}}function b(a,b){return a=0<a?parseInt(a/b.f*b.b,10):parseInt(a/b.g*b.c,10)}function d(a,b){return parseInt(0<a?a*b.b:a*b.c,10)}function f(a,b){return 0<a? | ||
a/b.f:a/b.g}function q(a){h[0]=a;return a=h[0]}function m(a){if("32f"!=a&&"64"!=a&&("8">parseInt(a,10)||"53"<parseInt(a,10)))throw Error("Invalid bit depth.");}var h=new Float32Array(1);c.a=a;window.bitDepth=window.bitDepth||{};window.bitDepth.toBitDepth=a}]); | ||
var g="function"==typeof Object.defineProperties?Object.defineProperty:function(c,a,b){c!=Array.prototype&&c!=Object.prototype&&(c[a]=b.value)},l="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function m(c,a){if(a){var b=l;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&&g(b,c,{configurable:!0,writable:!0,value:a})}} | ||
m("Object.is",function(c){return c?c:function(a,b){return a===b?0!==a||1/a===1/b:a!==a&&b!==b}});m("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(b,a,d,c){h(a);h(d);c=c||b;var f=p(a,d),n={g:Math.pow(2, | ||
parseInt(a,10))/2,c:Math.pow(2,parseInt(d,10))/2,f:Math.pow(2,parseInt(a,10))/2-1,b:Math.pow(2,parseInt(d,10))/2-1},e=b.length;if("8"==a)for(a=0;a<e;a++)c[a]=b[a]-=128;for(a=0;a<e;a++)c[a]=f(b[a],n);if("8"==d)for(b=0;b<e;b++)c[b]=c[b]+=128}function b(a,b){return a=0<a?parseInt(a/b.f*b.b,10):parseInt(a/b.g*b.c,10)}function d(a,b){return parseInt(0<a?a*b.b:a*b.c,10)}function e(a,b){return 0<a?a/b.f:a/b.g}function q(a){k[0]=a;return k[0]}function p(a,c){var f;["32f","64"].includes(a)?["32f","64"].includes(c)? | ||
f=q:f=d:f=["32f","64"].includes(c)?e:b;a==c&&(f=function(a){return a});return f}function h(a){if("32f"!=a&&"64"!=a&&("8">parseInt(a,10)||"53"<parseInt(a,10)))throw Error("Invalid bit depth.");}var k=new Float32Array(1);c.a=a;window.bitDepth=window.bitDepth||{};window.bitDepth.toBitDepth=a}]); |
29
index.js
@@ -24,9 +24,5 @@ /** | ||
function toBitDepth(samples, original, target, outputArray) { | ||
if (original == "64" && target == "64") { | ||
return; | ||
} | ||
validateBitDepth_(original); | ||
validateBitDepth_(target); | ||
outputArray = outputArray || samples; | ||
const len = samples.length; | ||
let toFunction = getBitDepthFunction_(original, target); | ||
@@ -39,2 +35,4 @@ let options = { | ||
}; | ||
const len = samples.length; | ||
// sign the samples if original is 8-bit | ||
if (original == "8") { | ||
@@ -45,5 +43,7 @@ for (let i=0; i<len; i++) { | ||
} | ||
// change the resolution of the samples | ||
for (let i=0; i<len; i++) { | ||
outputArray[i] = toFunction(samples[i], options); | ||
} | ||
// unsign the samples if target is 8-bit | ||
if (target == "8") { | ||
@@ -103,8 +103,7 @@ for (let i=0; i<len; i++) { | ||
f64f32_[0] = sample; | ||
sample = f64f32_[0]; | ||
return sample; | ||
return f64f32_[0]; | ||
} | ||
/** | ||
* Get the function to change the bit depth of a sample. | ||
* Return the function to change the bit depth of a sample. | ||
* @param {!string} original The original bit depth of the data. | ||
@@ -118,15 +117,21 @@ * One of "8" ... "53", "32f", "64" | ||
function getBitDepthFunction_(original, target) { | ||
/** @type {!Function} */ | ||
let func; | ||
if (["32f", "64"].includes(original)) { | ||
if (["32f", "64"].includes(target)) { | ||
return floatToFloat_; | ||
func = floatToFloat_; | ||
} else { | ||
return floatToInt_; | ||
func = floatToInt_; | ||
} | ||
} else { | ||
if (["32f", "64"].includes(target)) { | ||
return intToFloat_; | ||
func = intToFloat_; | ||
} else { | ||
return intToInt_; | ||
func = intToInt_; | ||
} | ||
} | ||
if (original == target) { | ||
func = function(x) {return x;}; | ||
} | ||
return func; | ||
} | ||
@@ -139,3 +144,2 @@ | ||
* @throws {Error} If any argument does not meet the criteria. | ||
* @return {!boolean} | ||
* @private | ||
@@ -148,3 +152,2 @@ */ | ||
} | ||
return true; | ||
} | ||
@@ -151,0 +154,0 @@ |
{ | ||
"name": "bitdepth", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Change the resolution of samples to and from 8, 11, 12, 16, 20, 24, 32, 48 & 64-bit.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/rochars/bitdepth", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67394
15
836