* Create Object containing input and input-related options. * @private
(input, inputOptions, containerOptions)
| 51 | * @private |
| 52 | */ |
| 53 | function _createInputDescriptor (input, inputOptions, containerOptions) { |
| 54 | const inputDescriptor = { |
| 55 | autoOrient: false, |
| 56 | failOn: 'warning', |
| 57 | limitInputPixels: 0x3FFF ** 2, |
| 58 | limitInputChannels: 5, |
| 59 | ignoreIcc: false, |
| 60 | unlimited: false, |
| 61 | sequentialRead: true |
| 62 | }; |
| 63 | if (is.string(input)) { |
| 64 | // filesystem |
| 65 | inputDescriptor.file = input; |
| 66 | } else if (is.buffer(input)) { |
| 67 | // Buffer |
| 68 | if (input.length === 0) { |
| 69 | throw Error('Input Buffer is empty'); |
| 70 | } |
| 71 | inputDescriptor.buffer = input; |
| 72 | } else if (is.arrayBuffer(input)) { |
| 73 | if (input.byteLength === 0) { |
| 74 | throw Error('Input bit Array is empty'); |
| 75 | } |
| 76 | inputDescriptor.buffer = Buffer.from(input, 0, input.byteLength); |
| 77 | } else if (is.typedArray(input)) { |
| 78 | if (input.length === 0) { |
| 79 | throw Error('Input Bit Array is empty'); |
| 80 | } |
| 81 | inputDescriptor.buffer = Buffer.from(input.buffer, input.byteOffset, input.byteLength); |
| 82 | } else if (is.plainObject(input) && !is.defined(inputOptions)) { |
| 83 | // Plain Object descriptor, e.g. create |
| 84 | inputOptions = input; |
| 85 | if (_inputOptionsFromObject(inputOptions)) { |
| 86 | // Stream with options |
| 87 | inputDescriptor.buffer = []; |
| 88 | } |
| 89 | } else if (!is.defined(input) && !is.defined(inputOptions) && is.object(containerOptions) && containerOptions.allowStream) { |
| 90 | // Stream without options |
| 91 | inputDescriptor.buffer = []; |
| 92 | } else if (Array.isArray(input)) { |
| 93 | if (input.length > 1) { |
| 94 | // Join images together |
| 95 | if (!this.options.joining) { |
| 96 | this.options.joining = true; |
| 97 | this.options.join = input.map(i => this._createInputDescriptor(i)); |
| 98 | } else { |
| 99 | throw new Error('Recursive join is unsupported'); |
| 100 | } |
| 101 | } else { |
| 102 | throw new Error('Expected at least two images to join'); |
| 103 | } |
| 104 | } else { |
| 105 | throw new Error(`Unsupported input '${input}' of type ${typeof input}${ |
| 106 | is.defined(inputOptions) ? ` when also providing options of type ${typeof inputOptions}` : '' |
| 107 | }`); |
| 108 | } |
| 109 | if (is.object(inputOptions)) { |
| 110 | // failOn |
nothing calls this directly
no test coverage detected
searching dependent graphs…