Add support for bit depth with raw input and output (#2762)

* Determine input raw pixel depth from the given typed array
* Allow pixel depth to be set on raw output
This commit is contained in:
Mart
2021-08-03 15:52:54 +02:00
committed by GitHub
parent eabb671b10
commit b7add480c7
9 changed files with 123 additions and 16 deletions

View File

@@ -49,12 +49,26 @@ const buffer = function (val) {
};
/**
* Is this value a Uint8Array or Uint8ClampedArray object?
* Is this value a typed array object?. E.g. Uint8Array or Uint8ClampedArray?
* @private
*/
const uint8Array = function (val) {
// allow both since Uint8ClampedArray simply clamps the values between 0-255
return val instanceof Uint8Array || val instanceof Uint8ClampedArray;
const typedArray = function (val) {
if (defined(val)) {
switch (val.constructor) {
case Uint8Array:
case Uint8ClampedArray:
case Int8Array:
case Uint16Array:
case Int16Array:
case Uint32Array:
case Int32Array:
case Float32Array:
case Float64Array:
return true;
}
}
return false;
};
/**
@@ -119,7 +133,7 @@ module.exports = {
fn: fn,
bool: bool,
buffer: buffer,
uint8Array: uint8Array,
typedArray: typedArray,
string: string,
number: number,
integer: integer,