sharp 0.34.0-rc.0 → 0.34.0
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/lib/constructor.js +4 -0
- package/lib/index.d.ts +16 -0
- package/lib/libvips.js +3 -1
- package/lib/operation.js +48 -0
- package/lib/sharp.js +10 -2
- package/package.json +27 -27
- package/src/binding.gyp +4 -0
- package/src/operations.cc +22 -0
- package/src/operations.h +9 -0
- package/src/pipeline.cc +16 -9
- package/src/pipeline.h +5 -1
- package/src/sharp.cc +1 -0
- package/src/utilities.cc +17 -0
- package/src/utilities.h +1 -0
package/lib/constructor.js
CHANGED
|
@@ -263,6 +263,8 @@ const Sharp = function (input, options) {
|
|
|
263
263
|
trimBackground: [],
|
|
264
264
|
trimThreshold: -1,
|
|
265
265
|
trimLineArt: false,
|
|
266
|
+
dilateWidth: 0,
|
|
267
|
+
erodeWidth: 0,
|
|
266
268
|
gamma: 0,
|
|
267
269
|
gammaOut: 0,
|
|
268
270
|
greyscale: false,
|
|
@@ -296,6 +298,8 @@ const Sharp = function (input, options) {
|
|
|
296
298
|
withExif: {},
|
|
297
299
|
withExifMerge: true,
|
|
298
300
|
resolveWithObject: false,
|
|
301
|
+
loop: 1,
|
|
302
|
+
delay: [],
|
|
299
303
|
// output format
|
|
300
304
|
jpegQuality: 80,
|
|
301
305
|
jpegProgressive: false,
|
package/lib/index.d.ts
CHANGED
|
@@ -504,6 +504,22 @@ declare namespace sharp {
|
|
|
504
504
|
*/
|
|
505
505
|
blur(sigma?: number | boolean | BlurOptions): Sharp;
|
|
506
506
|
|
|
507
|
+
/**
|
|
508
|
+
* Expand foreground objects using the dilate morphological operator.
|
|
509
|
+
* @param {Number} [width=1] dilation width in pixels.
|
|
510
|
+
* @throws {Error} Invalid parameters
|
|
511
|
+
* @returns A sharp instance that can be used to chain operations
|
|
512
|
+
*/
|
|
513
|
+
dilate(width?: number): Sharp;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Shrink foreground objects using the erode morphological operator.
|
|
517
|
+
* @param {Number} [width=1] erosion width in pixels.
|
|
518
|
+
* @throws {Error} Invalid parameters
|
|
519
|
+
* @returns A sharp instance that can be used to chain operations
|
|
520
|
+
*/
|
|
521
|
+
erode(width?: number): Sharp;
|
|
522
|
+
|
|
507
523
|
/**
|
|
508
524
|
* Merge alpha transparency channel, if any, with background.
|
|
509
525
|
* @param flatten true to enable and false to disable (defaults to true)
|
package/lib/libvips.js
CHANGED
|
@@ -113,7 +113,9 @@ const sha512 = (s) => createHash('sha512').update(s).digest('hex');
|
|
|
113
113
|
const yarnLocator = () => {
|
|
114
114
|
try {
|
|
115
115
|
const identHash = sha512(`imgsharp-libvips-${buildPlatformArch()}`);
|
|
116
|
-
const npmVersion = semverCoerce(optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`]
|
|
116
|
+
const npmVersion = semverCoerce(optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`], {
|
|
117
|
+
includePrerelease: true
|
|
118
|
+
}).version;
|
|
117
119
|
return sha512(`${identHash}npm:${npmVersion}`).slice(0, 10);
|
|
118
120
|
} catch {}
|
|
119
121
|
return '';
|
package/lib/operation.js
CHANGED
|
@@ -443,6 +443,52 @@ function blur (options) {
|
|
|
443
443
|
return this;
|
|
444
444
|
}
|
|
445
445
|
|
|
446
|
+
/**
|
|
447
|
+
* Expand foreground objects using the dilate morphological operator.
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* const output = await sharp(input)
|
|
451
|
+
* .dilate()
|
|
452
|
+
* .toBuffer();
|
|
453
|
+
*
|
|
454
|
+
* @param {Number} [width=1] dilation width in pixels.
|
|
455
|
+
* @returns {Sharp}
|
|
456
|
+
* @throws {Error} Invalid parameters
|
|
457
|
+
*/
|
|
458
|
+
function dilate (width) {
|
|
459
|
+
if (!is.defined(width)) {
|
|
460
|
+
this.options.dilateWidth = 1;
|
|
461
|
+
} else if (is.integer(width) && width > 0) {
|
|
462
|
+
this.options.dilateWidth = width;
|
|
463
|
+
} else {
|
|
464
|
+
throw is.invalidParameterError('dilate', 'positive integer', dilate);
|
|
465
|
+
}
|
|
466
|
+
return this;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Shrink foreground objects using the erode morphological operator.
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
* const output = await sharp(input)
|
|
474
|
+
* .erode()
|
|
475
|
+
* .toBuffer();
|
|
476
|
+
*
|
|
477
|
+
* @param {Number} [width=1] erosion width in pixels.
|
|
478
|
+
* @returns {Sharp}
|
|
479
|
+
* @throws {Error} Invalid parameters
|
|
480
|
+
*/
|
|
481
|
+
function erode (width) {
|
|
482
|
+
if (!is.defined(width)) {
|
|
483
|
+
this.options.erodeWidth = 1;
|
|
484
|
+
} else if (is.integer(width) && width > 0) {
|
|
485
|
+
this.options.erodeWidth = width;
|
|
486
|
+
} else {
|
|
487
|
+
throw is.invalidParameterError('erode', 'positive integer', erode);
|
|
488
|
+
}
|
|
489
|
+
return this;
|
|
490
|
+
}
|
|
491
|
+
|
|
446
492
|
/**
|
|
447
493
|
* Merge alpha transparency channel, if any, with a background, then remove the alpha channel.
|
|
448
494
|
*
|
|
@@ -958,6 +1004,8 @@ module.exports = function (Sharp) {
|
|
|
958
1004
|
flop,
|
|
959
1005
|
affine,
|
|
960
1006
|
sharpen,
|
|
1007
|
+
erode,
|
|
1008
|
+
dilate,
|
|
961
1009
|
median,
|
|
962
1010
|
blur,
|
|
963
1011
|
flatten,
|
package/lib/sharp.js
CHANGED
|
@@ -17,9 +17,9 @@ const paths = [
|
|
|
17
17
|
'@img/sharp-wasm32/sharp.node'
|
|
18
18
|
];
|
|
19
19
|
|
|
20
|
-
let sharp;
|
|
20
|
+
let path, sharp;
|
|
21
21
|
const errors = [];
|
|
22
|
-
for (
|
|
22
|
+
for (path of paths) {
|
|
23
23
|
try {
|
|
24
24
|
sharp = require(path);
|
|
25
25
|
break;
|
|
@@ -29,6 +29,14 @@ for (const path of paths) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/* istanbul ignore next */
|
|
33
|
+
if (sharp && path.startsWith('@img/sharp-linux-x64') && !sharp._isUsingX64V2()) {
|
|
34
|
+
const err = new Error('Prebuilt binaries for linux-x64 require v2 microarchitecture');
|
|
35
|
+
err.code = 'Unsupported CPU';
|
|
36
|
+
errors.push(err);
|
|
37
|
+
sharp = null;
|
|
38
|
+
}
|
|
39
|
+
|
|
32
40
|
/* istanbul ignore next */
|
|
33
41
|
if (sharp) {
|
|
34
42
|
module.exports = sharp;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sharp",
|
|
3
3
|
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
|
|
4
|
-
"version": "0.34.0
|
|
4
|
+
"version": "0.34.0",
|
|
5
5
|
"author": "Lovell Fuller <npm@lovell.info>",
|
|
6
6
|
"homepage": "https://sharp.pixelplumbing.com",
|
|
7
7
|
"contributors": [
|
|
@@ -142,36 +142,36 @@
|
|
|
142
142
|
"semver": "^7.7.1"
|
|
143
143
|
},
|
|
144
144
|
"optionalDependencies": {
|
|
145
|
-
"@img/sharp-darwin-arm64": "0.34.0
|
|
146
|
-
"@img/sharp-darwin-x64": "0.34.0
|
|
147
|
-
"@img/sharp-libvips-darwin-arm64": "1.1.0
|
|
148
|
-
"@img/sharp-libvips-darwin-x64": "1.1.0
|
|
149
|
-
"@img/sharp-libvips-linux-arm": "1.1.0
|
|
150
|
-
"@img/sharp-libvips-linux-arm64": "1.1.0
|
|
151
|
-
"@img/sharp-libvips-linux-ppc64": "1.1.0
|
|
152
|
-
"@img/sharp-libvips-linux-s390x": "1.1.0
|
|
153
|
-
"@img/sharp-libvips-linux-x64": "1.1.0
|
|
154
|
-
"@img/sharp-libvips-linuxmusl-arm64": "1.1.0
|
|
155
|
-
"@img/sharp-libvips-linuxmusl-x64": "1.1.0
|
|
156
|
-
"@img/sharp-linux-arm": "0.34.0
|
|
157
|
-
"@img/sharp-linux-arm64": "0.34.0
|
|
158
|
-
"@img/sharp-linux-s390x": "0.34.0
|
|
159
|
-
"@img/sharp-linux-x64": "0.34.0
|
|
160
|
-
"@img/sharp-linuxmusl-arm64": "0.34.0
|
|
161
|
-
"@img/sharp-linuxmusl-x64": "0.34.0
|
|
162
|
-
"@img/sharp-wasm32": "0.34.0
|
|
163
|
-
"@img/sharp-win32-ia32": "0.34.0
|
|
164
|
-
"@img/sharp-win32-x64": "0.34.0
|
|
145
|
+
"@img/sharp-darwin-arm64": "0.34.0",
|
|
146
|
+
"@img/sharp-darwin-x64": "0.34.0",
|
|
147
|
+
"@img/sharp-libvips-darwin-arm64": "1.1.0",
|
|
148
|
+
"@img/sharp-libvips-darwin-x64": "1.1.0",
|
|
149
|
+
"@img/sharp-libvips-linux-arm": "1.1.0",
|
|
150
|
+
"@img/sharp-libvips-linux-arm64": "1.1.0",
|
|
151
|
+
"@img/sharp-libvips-linux-ppc64": "1.1.0",
|
|
152
|
+
"@img/sharp-libvips-linux-s390x": "1.1.0",
|
|
153
|
+
"@img/sharp-libvips-linux-x64": "1.1.0",
|
|
154
|
+
"@img/sharp-libvips-linuxmusl-arm64": "1.1.0",
|
|
155
|
+
"@img/sharp-libvips-linuxmusl-x64": "1.1.0",
|
|
156
|
+
"@img/sharp-linux-arm": "0.34.0",
|
|
157
|
+
"@img/sharp-linux-arm64": "0.34.0",
|
|
158
|
+
"@img/sharp-linux-s390x": "0.34.0",
|
|
159
|
+
"@img/sharp-linux-x64": "0.34.0",
|
|
160
|
+
"@img/sharp-linuxmusl-arm64": "0.34.0",
|
|
161
|
+
"@img/sharp-linuxmusl-x64": "0.34.0",
|
|
162
|
+
"@img/sharp-wasm32": "0.34.0",
|
|
163
|
+
"@img/sharp-win32-ia32": "0.34.0",
|
|
164
|
+
"@img/sharp-win32-x64": "0.34.0"
|
|
165
165
|
},
|
|
166
166
|
"devDependencies": {
|
|
167
|
-
"@emnapi/runtime": "^1.
|
|
168
|
-
"@img/sharp-libvips-dev": "1.1.0
|
|
169
|
-
"@img/sharp-libvips-dev-wasm32": "1.1.0
|
|
170
|
-
"@img/sharp-libvips-win32-ia32": "1.1.0
|
|
171
|
-
"@img/sharp-libvips-win32-x64": "1.1.0
|
|
167
|
+
"@emnapi/runtime": "^1.4.0",
|
|
168
|
+
"@img/sharp-libvips-dev": "1.1.0",
|
|
169
|
+
"@img/sharp-libvips-dev-wasm32": "1.1.0",
|
|
170
|
+
"@img/sharp-libvips-win32-ia32": "1.1.0",
|
|
171
|
+
"@img/sharp-libvips-win32-x64": "1.1.0",
|
|
172
172
|
"@types/node": "*",
|
|
173
173
|
"cc": "^3.0.1",
|
|
174
|
-
"emnapi": "^1.
|
|
174
|
+
"emnapi": "^1.4.0",
|
|
175
175
|
"exif-reader": "^2.0.2",
|
|
176
176
|
"extract-zip": "^2.0.1",
|
|
177
177
|
"icc": "^3.0.0",
|
package/src/binding.gyp
CHANGED
|
@@ -80,6 +80,9 @@
|
|
|
80
80
|
}, {
|
|
81
81
|
'target_name': 'sharp-<(platform_and_arch)',
|
|
82
82
|
'defines': [
|
|
83
|
+
'G_DISABLE_ASSERT',
|
|
84
|
+
'G_DISABLE_CAST_CHECKS',
|
|
85
|
+
'G_DISABLE_CHECKS',
|
|
83
86
|
'NAPI_VERSION=9',
|
|
84
87
|
'NODE_ADDON_API_DISABLE_DEPRECATED',
|
|
85
88
|
'NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS'
|
|
@@ -179,6 +182,7 @@
|
|
|
179
182
|
'-Wl,-s',
|
|
180
183
|
'-Wl,--disable-new-dtags',
|
|
181
184
|
'-Wl,-z,nodelete',
|
|
185
|
+
'-Wl,-Bsymbolic-functions',
|
|
182
186
|
'-Wl,-rpath=\'$$ORIGIN/../../sharp-libvips-<(platform_and_arch)/lib\'',
|
|
183
187
|
'-Wl,-rpath=\'$$ORIGIN/../../../sharp-libvips-<(platform_and_arch)/<(sharp_libvips_version)/lib\'',
|
|
184
188
|
'-Wl,-rpath=\'$$ORIGIN/../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'',
|
package/src/operations.cc
CHANGED
|
@@ -472,4 +472,26 @@ namespace sharp {
|
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
474
|
|
|
475
|
+
/*
|
|
476
|
+
* Dilate an image
|
|
477
|
+
*/
|
|
478
|
+
VImage Dilate(VImage image, int const width) {
|
|
479
|
+
int const maskWidth = 2 * width + 1;
|
|
480
|
+
VImage mask = VImage::new_matrix(maskWidth, maskWidth);
|
|
481
|
+
return image.morph(
|
|
482
|
+
mask,
|
|
483
|
+
VIPS_OPERATION_MORPHOLOGY_DILATE).invert();
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/*
|
|
487
|
+
* Erode an image
|
|
488
|
+
*/
|
|
489
|
+
VImage Erode(VImage image, int const width) {
|
|
490
|
+
int const maskWidth = 2 * width + 1;
|
|
491
|
+
VImage mask = VImage::new_matrix(maskWidth, maskWidth);
|
|
492
|
+
return image.morph(
|
|
493
|
+
mask,
|
|
494
|
+
VIPS_OPERATION_MORPHOLOGY_ERODE).invert();
|
|
495
|
+
}
|
|
496
|
+
|
|
475
497
|
} // namespace sharp
|
package/src/operations.h
CHANGED
|
@@ -120,6 +120,15 @@ namespace sharp {
|
|
|
120
120
|
VImage EmbedMultiPage(VImage image, int left, int top, int width, int height,
|
|
121
121
|
VipsExtend extendWith, std::vector<double> background, int nPages, int *pageHeight);
|
|
122
122
|
|
|
123
|
+
/*
|
|
124
|
+
* Dilate an image
|
|
125
|
+
*/
|
|
126
|
+
VImage Dilate(VImage image, int const maskWidth);
|
|
127
|
+
|
|
128
|
+
/*
|
|
129
|
+
* Erode an image
|
|
130
|
+
*/
|
|
131
|
+
VImage Erode(VImage image, int const maskWidth);
|
|
123
132
|
} // namespace sharp
|
|
124
133
|
|
|
125
134
|
#endif // SRC_OPERATIONS_H_
|
package/src/pipeline.cc
CHANGED
|
@@ -609,6 +609,16 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
609
609
|
image = sharp::Threshold(image, baton->threshold, baton->thresholdGrayscale);
|
|
610
610
|
}
|
|
611
611
|
|
|
612
|
+
// Dilate - must happen before blurring, due to the utility of dilating after thresholding
|
|
613
|
+
if (baton->dilateWidth != 0) {
|
|
614
|
+
image = sharp::Dilate(image, baton->dilateWidth);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// Erode - must happen before blurring, due to the utility of eroding after thresholding
|
|
618
|
+
if (baton->erodeWidth != 0) {
|
|
619
|
+
image = sharp::Erode(image, baton->erodeWidth);
|
|
620
|
+
}
|
|
621
|
+
|
|
612
622
|
// Blur
|
|
613
623
|
if (shouldBlur) {
|
|
614
624
|
image = sharp::Blur(image, baton->blurSigma, baton->precision, baton->minAmpl);
|
|
@@ -1032,7 +1042,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1032
1042
|
(baton->formatOut == "input" && inputImageType == sharp::ImageType::HEIF)) {
|
|
1033
1043
|
// Write HEIF to buffer
|
|
1034
1044
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::HEIF);
|
|
1035
|
-
image = sharp::RemoveAnimationProperties(image)
|
|
1045
|
+
image = sharp::RemoveAnimationProperties(image);
|
|
1036
1046
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.heifsave_buffer(VImage::option()
|
|
1037
1047
|
->set("keep", baton->keepMetadata)
|
|
1038
1048
|
->set("Q", baton->heifQuality)
|
|
@@ -1227,7 +1237,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1227
1237
|
(willMatchInput && inputImageType == sharp::ImageType::HEIF)) {
|
|
1228
1238
|
// Write HEIF to file
|
|
1229
1239
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::HEIF);
|
|
1230
|
-
image = sharp::RemoveAnimationProperties(image)
|
|
1240
|
+
image = sharp::RemoveAnimationProperties(image);
|
|
1231
1241
|
image.heifsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
|
1232
1242
|
->set("keep", baton->keepMetadata)
|
|
1233
1243
|
->set("Q", baton->heifQuality)
|
|
@@ -1621,6 +1631,8 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|
|
1621
1631
|
baton->gammaOut = sharp::AttrAsDouble(options, "gammaOut");
|
|
1622
1632
|
baton->linearA = sharp::AttrAsVectorOfDouble(options, "linearA");
|
|
1623
1633
|
baton->linearB = sharp::AttrAsVectorOfDouble(options, "linearB");
|
|
1634
|
+
baton->dilateWidth = sharp::AttrAsUint32(options, "dilateWidth");
|
|
1635
|
+
baton->erodeWidth = sharp::AttrAsUint32(options, "erodeWidth");
|
|
1624
1636
|
baton->greyscale = sharp::AttrAsBool(options, "greyscale");
|
|
1625
1637
|
baton->normalise = sharp::AttrAsBool(options, "normalise");
|
|
1626
1638
|
baton->normaliseLower = sharp::AttrAsUint32(options, "normaliseLower");
|
|
@@ -1705,6 +1717,8 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|
|
1705
1717
|
}
|
|
1706
1718
|
baton->withExifMerge = sharp::AttrAsBool(options, "withExifMerge");
|
|
1707
1719
|
baton->timeoutSeconds = sharp::AttrAsUint32(options, "timeoutSeconds");
|
|
1720
|
+
baton->loop = sharp::AttrAsUint32(options, "loop");
|
|
1721
|
+
baton->delay = sharp::AttrAsInt32Vector(options, "delay");
|
|
1708
1722
|
// Format-specific
|
|
1709
1723
|
baton->jpegQuality = sharp::AttrAsUint32(options, "jpegQuality");
|
|
1710
1724
|
baton->jpegProgressive = sharp::AttrAsBool(options, "jpegProgressive");
|
|
@@ -1774,13 +1788,6 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|
|
1774
1788
|
baton->jxlEffort = sharp::AttrAsUint32(options, "jxlEffort");
|
|
1775
1789
|
baton->jxlLossless = sharp::AttrAsBool(options, "jxlLossless");
|
|
1776
1790
|
baton->rawDepth = sharp::AttrAsEnum<VipsBandFormat>(options, "rawDepth", VIPS_TYPE_BAND_FORMAT);
|
|
1777
|
-
// Animated output properties
|
|
1778
|
-
if (sharp::HasAttr(options, "loop")) {
|
|
1779
|
-
baton->loop = sharp::AttrAsUint32(options, "loop");
|
|
1780
|
-
}
|
|
1781
|
-
if (sharp::HasAttr(options, "delay")) {
|
|
1782
|
-
baton->delay = sharp::AttrAsInt32Vector(options, "delay");
|
|
1783
|
-
}
|
|
1784
1791
|
baton->tileSize = sharp::AttrAsUint32(options, "tileSize");
|
|
1785
1792
|
baton->tileOverlap = sharp::AttrAsUint32(options, "tileOverlap");
|
|
1786
1793
|
baton->tileAngle = sharp::AttrAsInt32(options, "tileAngle");
|
package/src/pipeline.h
CHANGED
|
@@ -101,6 +101,8 @@ struct PipelineBaton {
|
|
|
101
101
|
int trimOffsetTop;
|
|
102
102
|
std::vector<double> linearA;
|
|
103
103
|
std::vector<double> linearB;
|
|
104
|
+
int dilateWidth;
|
|
105
|
+
int erodeWidth;
|
|
104
106
|
double gamma;
|
|
105
107
|
double gammaOut;
|
|
106
108
|
bool greyscale;
|
|
@@ -274,6 +276,8 @@ struct PipelineBaton {
|
|
|
274
276
|
trimOffsetTop(0),
|
|
275
277
|
linearA{},
|
|
276
278
|
linearB{},
|
|
279
|
+
dilateWidth(0),
|
|
280
|
+
erodeWidth(0),
|
|
277
281
|
gamma(0.0),
|
|
278
282
|
greyscale(false),
|
|
279
283
|
normalise(false),
|
|
@@ -380,7 +384,7 @@ struct PipelineBaton {
|
|
|
380
384
|
ensureAlpha(-1.0),
|
|
381
385
|
colourspacePipeline(VIPS_INTERPRETATION_LAST),
|
|
382
386
|
colourspace(VIPS_INTERPRETATION_LAST),
|
|
383
|
-
loop(
|
|
387
|
+
loop(1),
|
|
384
388
|
tileSize(256),
|
|
385
389
|
tileOverlap(0),
|
|
386
390
|
tileContainer(VIPS_FOREIGN_DZ_CONTAINER_FS),
|
package/src/sharp.cc
CHANGED
|
@@ -33,6 +33,7 @@ Napi::Object init(Napi::Env env, Napi::Object exports) {
|
|
|
33
33
|
exports.Set("block", Napi::Function::New(env, block));
|
|
34
34
|
exports.Set("_maxColourDistance", Napi::Function::New(env, _maxColourDistance));
|
|
35
35
|
exports.Set("_isUsingJemalloc", Napi::Function::New(env, _isUsingJemalloc));
|
|
36
|
+
exports.Set("_isUsingX64V2", Napi::Function::New(env, _isUsingX64V2));
|
|
36
37
|
exports.Set("stats", Napi::Function::New(env, stats));
|
|
37
38
|
return exports;
|
|
38
39
|
}
|
package/src/utilities.cc
CHANGED
|
@@ -267,3 +267,20 @@ Napi::Value _isUsingJemalloc(const Napi::CallbackInfo& info) {
|
|
|
267
267
|
return Napi::Boolean::New(env, false);
|
|
268
268
|
}
|
|
269
269
|
#endif
|
|
270
|
+
|
|
271
|
+
#if defined(__GNUC__) && defined(__x86_64__)
|
|
272
|
+
// Are SSE 4.2 intrinsics available at runtime?
|
|
273
|
+
Napi::Value _isUsingX64V2(const Napi::CallbackInfo& info) {
|
|
274
|
+
Napi::Env env = info.Env();
|
|
275
|
+
unsigned int eax, ebx, ecx, edx;
|
|
276
|
+
__asm__ __volatile__("cpuid"
|
|
277
|
+
: "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
|
|
278
|
+
: "a"(1));
|
|
279
|
+
return Napi::Boolean::New(env, (ecx & 1U << 20) != 0);
|
|
280
|
+
}
|
|
281
|
+
#else
|
|
282
|
+
Napi::Value _isUsingX64V2(const Napi::CallbackInfo& info) {
|
|
283
|
+
Napi::Env env = info.Env();
|
|
284
|
+
return Napi::Boolean::New(env, false);
|
|
285
|
+
}
|
|
286
|
+
#endif
|
package/src/utilities.h
CHANGED
|
@@ -15,5 +15,6 @@ Napi::Value format(const Napi::CallbackInfo& info);
|
|
|
15
15
|
void block(const Napi::CallbackInfo& info);
|
|
16
16
|
Napi::Value _maxColourDistance(const Napi::CallbackInfo& info);
|
|
17
17
|
Napi::Value _isUsingJemalloc(const Napi::CallbackInfo& info);
|
|
18
|
+
Napi::Value _isUsingX64V2(const Napi::CallbackInfo& info);
|
|
18
19
|
|
|
19
20
|
#endif // SRC_UTILITIES_H_
|