@ohos-ports/sharp 0.34.5-beta.8 → 0.35.5-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +112 -0
- package/{lib/channel.js → dist/channel.cjs} +1 -1
- package/dist/channel.mjs +177 -0
- package/{lib/colour.js → dist/colour.cjs} +12 -8
- package/dist/colour.mjs +199 -0
- package/{lib/composite.js → dist/composite.cjs} +8 -7
- package/dist/composite.mjs +213 -0
- package/{lib/constructor.js → dist/constructor.cjs} +42 -30
- package/dist/constructor.mjs +511 -0
- package/dist/index.cjs +25 -0
- package/{lib/index.d.ts → dist/index.d.cts} +113 -85
- package/dist/index.d.mts +2046 -0
- package/dist/index.mjs +25 -0
- package/{lib/input.js → dist/input.cjs} +47 -37
- package/dist/input.mjs +819 -0
- package/{lib/is.js → dist/is.cjs} +9 -3
- package/dist/is.mjs +149 -0
- package/{lib/libvips.js → dist/libvips.cjs} +35 -30
- package/dist/libvips.mjs +213 -0
- package/{lib/operation.js → dist/operation.cjs} +39 -53
- package/dist/operation.mjs +1002 -0
- package/{lib/output.js → dist/output.cjs} +167 -47
- package/dist/output.mjs +1786 -0
- package/{lib/resize.js → dist/resize.cjs} +54 -32
- package/dist/resize.mjs +617 -0
- package/dist/sharp.cjs +177 -0
- package/dist/sharp.mjs +177 -0
- package/{lib/utility.js → dist/utility.cjs} +23 -25
- package/dist/utility.mjs +301 -0
- package/install/build.js +3 -3
- package/package.json +56 -56
- package/src/binding.gyp +21 -269
- package/src/common.cc +81 -25
- package/src/common.h +23 -4
- package/src/metadata.cc +66 -8
- package/src/metadata.h +6 -1
- package/src/operations.cc +25 -8
- package/src/operations.h +1 -1
- package/src/pipeline.cc +231 -72
- package/src/pipeline.h +15 -1
- package/src/stats.cc +6 -6
- package/src/utilities.cc +8 -7
- package/install/check.js +0 -73
- package/lib/index.js +0 -16
- package/lib/sharp.js +0 -154
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const is = require('./is');
|
|
6
|
+
const is = require('./is.cjs');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* How accurate an operation should be.
|
|
@@ -78,6 +78,10 @@ function rotate (angle, options) {
|
|
|
78
78
|
* Auto-orient based on the EXIF `Orientation` tag, then remove the tag.
|
|
79
79
|
* Mirroring is supported and may infer the use of a flip operation.
|
|
80
80
|
*
|
|
81
|
+
* Only the EXIF `Orientation` tag is considered; orientation carried in other
|
|
82
|
+
* places, such as an XMP `tiff:Orientation` element, is left untouched and
|
|
83
|
+
* remains the responsibility of the consumer.
|
|
84
|
+
*
|
|
81
85
|
* Previous or subsequent use of `rotate(angle)` and either `flip()` or `flop()`
|
|
82
86
|
* will logically occur after auto-orientation, regardless of call order.
|
|
83
87
|
*
|
|
@@ -178,7 +182,13 @@ function flop (flop) {
|
|
|
178
182
|
* @throws {Error} Invalid parameters
|
|
179
183
|
*/
|
|
180
184
|
function affine (matrix, options) {
|
|
181
|
-
const
|
|
185
|
+
const isValidShape = Array.isArray(matrix) && (
|
|
186
|
+
// 1x4 array of numbers
|
|
187
|
+
(matrix.length === 4 && matrix.every(is.number)) ||
|
|
188
|
+
// 2x2 array of arrays of numbers
|
|
189
|
+
(matrix.length === 2 && matrix.every((row) => Array.isArray(row) && row.length === 2))
|
|
190
|
+
);
|
|
191
|
+
const flatMatrix = isValidShape ? matrix.flat() : [];
|
|
182
192
|
if (flatMatrix.length === 4 && flatMatrix.every(is.number)) {
|
|
183
193
|
this.options.affineMatrix = flatMatrix;
|
|
184
194
|
} else {
|
|
@@ -259,45 +269,18 @@ function affine (matrix, options) {
|
|
|
259
269
|
* })
|
|
260
270
|
* .toBuffer();
|
|
261
271
|
*
|
|
262
|
-
* @param {Object
|
|
272
|
+
* @param {Object} [options] - if present, is an Object with attributes
|
|
263
273
|
* @param {number} [options.sigma] - the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`, between 0.000001 and 10
|
|
264
274
|
* @param {number} [options.m1=1.0] - the level of sharpening to apply to "flat" areas, between 0 and 1000000
|
|
265
275
|
* @param {number} [options.m2=2.0] - the level of sharpening to apply to "jagged" areas, between 0 and 1000000
|
|
266
276
|
* @param {number} [options.x1=2.0] - threshold between "flat" and "jagged", between 0 and 1000000
|
|
267
277
|
* @param {number} [options.y2=10.0] - maximum amount of brightening, between 0 and 1000000
|
|
268
278
|
* @param {number} [options.y3=20.0] - maximum amount of darkening, between 0 and 1000000
|
|
269
|
-
* @param {number} [flat] - (deprecated) see `options.m1`.
|
|
270
|
-
* @param {number} [jagged] - (deprecated) see `options.m2`.
|
|
271
279
|
* @returns {Sharp}
|
|
272
280
|
* @throws {Error} Invalid parameters
|
|
273
281
|
*/
|
|
274
|
-
function sharpen (options
|
|
275
|
-
if (
|
|
276
|
-
// No arguments: default to mild sharpen
|
|
277
|
-
this.options.sharpenSigma = -1;
|
|
278
|
-
} else if (is.bool(options)) {
|
|
279
|
-
// Deprecated boolean argument: apply mild sharpen?
|
|
280
|
-
this.options.sharpenSigma = options ? -1 : 0;
|
|
281
|
-
} else if (is.number(options) && is.inRange(options, 0.01, 10000)) {
|
|
282
|
-
// Deprecated numeric argument: specific sigma
|
|
283
|
-
this.options.sharpenSigma = options;
|
|
284
|
-
// Deprecated control over flat areas
|
|
285
|
-
if (is.defined(flat)) {
|
|
286
|
-
if (is.number(flat) && is.inRange(flat, 0, 10000)) {
|
|
287
|
-
this.options.sharpenM1 = flat;
|
|
288
|
-
} else {
|
|
289
|
-
throw is.invalidParameterError('flat', 'number between 0 and 10000', flat);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
// Deprecated control over jagged areas
|
|
293
|
-
if (is.defined(jagged)) {
|
|
294
|
-
if (is.number(jagged) && is.inRange(jagged, 0, 10000)) {
|
|
295
|
-
this.options.sharpenM2 = jagged;
|
|
296
|
-
} else {
|
|
297
|
-
throw is.invalidParameterError('jagged', 'number between 0 and 10000', jagged);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
} else if (is.plainObject(options)) {
|
|
282
|
+
function sharpen (options) {
|
|
283
|
+
if (is.plainObject(options)) {
|
|
301
284
|
if (is.number(options.sigma) && is.inRange(options.sigma, 0.000001, 10)) {
|
|
302
285
|
this.options.sharpenSigma = options.sigma;
|
|
303
286
|
} else {
|
|
@@ -339,7 +322,7 @@ function sharpen (options, flat, jagged) {
|
|
|
339
322
|
}
|
|
340
323
|
}
|
|
341
324
|
} else {
|
|
342
|
-
|
|
325
|
+
this.options.sharpenSigma = -1;
|
|
343
326
|
}
|
|
344
327
|
return this;
|
|
345
328
|
}
|
|
@@ -451,10 +434,10 @@ function blur (options) {
|
|
|
451
434
|
function dilate (width) {
|
|
452
435
|
if (!is.defined(width)) {
|
|
453
436
|
this.options.dilateWidth = 1;
|
|
454
|
-
} else if (is.integer(width) && width
|
|
437
|
+
} else if (is.integer(width) && is.inRange(width, 1, 65536)) {
|
|
455
438
|
this.options.dilateWidth = width;
|
|
456
439
|
} else {
|
|
457
|
-
throw is.invalidParameterError('
|
|
440
|
+
throw is.invalidParameterError('width', 'integer between 1 and 65536', width);
|
|
458
441
|
}
|
|
459
442
|
return this;
|
|
460
443
|
}
|
|
@@ -474,10 +457,10 @@ function dilate (width) {
|
|
|
474
457
|
function erode (width) {
|
|
475
458
|
if (!is.defined(width)) {
|
|
476
459
|
this.options.erodeWidth = 1;
|
|
477
|
-
} else if (is.integer(width) && width
|
|
460
|
+
} else if (is.integer(width) && is.inRange(width, 1, 65536)) {
|
|
478
461
|
this.options.erodeWidth = width;
|
|
479
462
|
} else {
|
|
480
|
-
throw is.invalidParameterError('
|
|
463
|
+
throw is.invalidParameterError('width', 'integer between 1 and 65536', width);
|
|
481
464
|
}
|
|
482
465
|
return this;
|
|
483
466
|
}
|
|
@@ -510,8 +493,6 @@ function flatten (options) {
|
|
|
510
493
|
*
|
|
511
494
|
* Existing alpha channel values for non-white pixels remain unchanged.
|
|
512
495
|
*
|
|
513
|
-
* This feature is experimental and the API may change.
|
|
514
|
-
*
|
|
515
496
|
* @since 0.32.1
|
|
516
497
|
*
|
|
517
498
|
* @example
|
|
@@ -675,23 +656,23 @@ function normalize (options) {
|
|
|
675
656
|
* .toBuffer();
|
|
676
657
|
*
|
|
677
658
|
* @param {Object} options
|
|
678
|
-
* @param {number} options.width - Integral width of the search window, in pixels.
|
|
679
|
-
* @param {number} options.height - Integral height of the search window, in pixels.
|
|
659
|
+
* @param {number} options.width - Integral width of the search window, in pixels, between 1 and 65536.
|
|
660
|
+
* @param {number} options.height - Integral height of the search window, in pixels, between 1 and 65536.
|
|
680
661
|
* @param {number} [options.maxSlope=3] - Integral level of brightening, between 0 and 100, where 0 disables contrast limiting.
|
|
681
662
|
* @returns {Sharp}
|
|
682
663
|
* @throws {Error} Invalid parameters
|
|
683
664
|
*/
|
|
684
665
|
function clahe (options) {
|
|
685
666
|
if (is.plainObject(options)) {
|
|
686
|
-
if (is.integer(options.width) && options.width
|
|
667
|
+
if (is.integer(options.width) && is.inRange(options.width, 1, 65536)) {
|
|
687
668
|
this.options.claheWidth = options.width;
|
|
688
669
|
} else {
|
|
689
|
-
throw is.invalidParameterError('width', 'integer
|
|
670
|
+
throw is.invalidParameterError('width', 'integer between 1 and 65536', options.width);
|
|
690
671
|
}
|
|
691
|
-
if (is.integer(options.height) && options.height
|
|
672
|
+
if (is.integer(options.height) && is.inRange(options.height, 1, 65536)) {
|
|
692
673
|
this.options.claheHeight = options.height;
|
|
693
674
|
} else {
|
|
694
|
-
throw is.invalidParameterError('height', 'integer
|
|
675
|
+
throw is.invalidParameterError('height', 'integer between 1 and 65536', options.height);
|
|
695
676
|
}
|
|
696
677
|
if (is.defined(options.maxSlope)) {
|
|
697
678
|
if (is.integer(options.maxSlope) && is.inRange(options.maxSlope, 0, 100)) {
|
|
@@ -735,7 +716,8 @@ function convolve (kernel) {
|
|
|
735
716
|
if (!is.object(kernel) || !Array.isArray(kernel.kernel) ||
|
|
736
717
|
!is.integer(kernel.width) || !is.integer(kernel.height) ||
|
|
737
718
|
!is.inRange(kernel.width, 3, 1001) || !is.inRange(kernel.height, 3, 1001) ||
|
|
738
|
-
kernel.height * kernel.width !== kernel.kernel.length
|
|
719
|
+
kernel.height * kernel.width !== kernel.kernel.length ||
|
|
720
|
+
!kernel.kernel.every(is.number)
|
|
739
721
|
) {
|
|
740
722
|
// must pass in a kernel
|
|
741
723
|
throw new Error('Invalid convolution kernel');
|
|
@@ -842,7 +824,7 @@ function linear (a, b) {
|
|
|
842
824
|
this.options.linearA = [];
|
|
843
825
|
} else if (is.number(a)) {
|
|
844
826
|
this.options.linearA = [a];
|
|
845
|
-
} else if (Array.isArray(a) && a.length && a.every(is.number)) {
|
|
827
|
+
} else if (Array.isArray(a) && is.inRange(a.length, 1, 1000000) && a.every(is.number)) {
|
|
846
828
|
this.options.linearA = a;
|
|
847
829
|
} else {
|
|
848
830
|
throw is.invalidParameterError('a', 'number or array of numbers', a);
|
|
@@ -851,7 +833,7 @@ function linear (a, b) {
|
|
|
851
833
|
this.options.linearB = [];
|
|
852
834
|
} else if (is.number(b)) {
|
|
853
835
|
this.options.linearB = [b];
|
|
854
|
-
} else if (Array.isArray(b) && b.length && b.every(is.number)) {
|
|
836
|
+
} else if (Array.isArray(b) && is.inRange(b.length, 1, 1000000) && b.every(is.number)) {
|
|
855
837
|
this.options.linearB = b;
|
|
856
838
|
} else {
|
|
857
839
|
throw is.invalidParameterError('b', 'number or array of numbers', b);
|
|
@@ -888,12 +870,16 @@ function recomb (inputMatrix) {
|
|
|
888
870
|
if (!Array.isArray(inputMatrix)) {
|
|
889
871
|
throw is.invalidParameterError('inputMatrix', 'array', inputMatrix);
|
|
890
872
|
}
|
|
891
|
-
|
|
892
|
-
|
|
873
|
+
const dimensions = inputMatrix.length;
|
|
874
|
+
if (dimensions !== 3 && dimensions !== 4) {
|
|
875
|
+
throw is.invalidParameterError('inputMatrix', '3x3 or 4x4 array', dimensions);
|
|
876
|
+
}
|
|
877
|
+
if (!inputMatrix.every((row) => Array.isArray(row) && row.length === dimensions)) {
|
|
878
|
+
throw is.invalidParameterError('inputMatrix', `array of ${dimensions} arrays of length ${dimensions}`, inputMatrix);
|
|
893
879
|
}
|
|
894
|
-
const recombMatrix = inputMatrix.flat()
|
|
895
|
-
if (recombMatrix.
|
|
896
|
-
throw is.invalidParameterError('inputMatrix', '
|
|
880
|
+
const recombMatrix = inputMatrix.flat();
|
|
881
|
+
if (!recombMatrix.every(is.number)) {
|
|
882
|
+
throw is.invalidParameterError('inputMatrix', 'array of numbers', recombMatrix);
|
|
897
883
|
}
|
|
898
884
|
this.options.recombMatrix = recombMatrix;
|
|
899
885
|
return this;
|