mirror of
https://github.com/lovell/sharp.git
synced 2026-02-05 14:16:17 +01:00
Compare commits
15 Commits
v0.33.0-al
...
v0.33.0-al
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d033ae341 | ||
|
|
f7da2e5970 | ||
|
|
51e56f994c | ||
|
|
68ac12292c | ||
|
|
a9aa7339ce | ||
|
|
08108f5fad | ||
|
|
58e3c4c70e | ||
|
|
f8cf25ca56 | ||
|
|
ca95979ecc | ||
|
|
392f6afb5e | ||
|
|
7c97aabaf8 | ||
|
|
fcc7e84bee | ||
|
|
226a9a13ef | ||
|
|
4d3c9ae3d1 | ||
|
|
f31011d759 |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -141,7 +141,7 @@ jobs:
|
|||||||
npm pkg set "optionalDependencies.@sharpen/sharp-linux-arm=file:./npm/linux-arm"
|
npm pkg set "optionalDependencies.@sharpen/sharp-linux-arm=file:./npm/linux-arm"
|
||||||
npm run clean
|
npm run clean
|
||||||
npm install --ignore-scripts
|
npm install --ignore-scripts
|
||||||
npx mocha --no-config --spec=test/unit/io.js
|
npx mocha --no-config --spec=test/unit/io.js --timeout=30000
|
||||||
[[ -n $prebuild_upload ]] && npx prebuild || true
|
[[ -n $prebuild_upload ]] && npx prebuild || true
|
||||||
macstadium-runner:
|
macstadium-runner:
|
||||||
permissions:
|
permissions:
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
build
|
src/build
|
||||||
|
src/node_modules
|
||||||
node_modules
|
node_modules
|
||||||
/coverage
|
/coverage
|
||||||
npm/*/*
|
npm/*/*
|
||||||
|
|||||||
@@ -8,11 +8,18 @@ Requires libvips v8.14.5
|
|||||||
|
|
||||||
* Drop support for Node.js 14 and 16, now requires Node.js >= 18.17.0
|
* Drop support for Node.js 14 and 16, now requires Node.js >= 18.17.0
|
||||||
|
|
||||||
|
* Prebuilt binaries distributed via npm registry and installed via package manager.
|
||||||
|
|
||||||
|
* Building from source requires dependency on `node-addon-api`.
|
||||||
|
|
||||||
* Remove `sharp.vendor`.
|
* Remove `sharp.vendor`.
|
||||||
|
|
||||||
* Make `compression` option of `heif` mandatory to help reduce HEIF vs HEIC confusion.
|
* Make `compression` option of `heif` mandatory to help reduce HEIF vs HEIC confusion.
|
||||||
[#3740](https://github.com/lovell/sharp/issues/3740)
|
[#3740](https://github.com/lovell/sharp/issues/3740)
|
||||||
|
|
||||||
|
* Ensure correct interpretation of 16-bit raw input.
|
||||||
|
[#3808](https://github.com/lovell/sharp/issues/3808)
|
||||||
|
|
||||||
## v0.32 - *flow*
|
## v0.32 - *flow*
|
||||||
|
|
||||||
Requires libvips v8.14.5
|
Requires libvips v8.14.5
|
||||||
|
|||||||
@@ -53,9 +53,15 @@ This module will be compiled from source at `npm install` time when:
|
|||||||
Building from source requires:
|
Building from source requires:
|
||||||
|
|
||||||
* C++11 compiler
|
* C++11 compiler
|
||||||
|
* [node-addon-api](https://www.npmjs.com/package/node-addon-api)
|
||||||
* [node-gyp](https://github.com/nodejs/node-gyp#installation) and its dependencies
|
* [node-gyp](https://github.com/nodejs/node-gyp#installation) and its dependencies
|
||||||
|
|
||||||
If `node-gyp` cannot be found, try adding it to `devDependencies`.
|
There is an install-time check for these dependencies.
|
||||||
|
If `node-addon-api` or `node-gyp` cannot be found, try adding them via:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --save node-addon-api node-gyp
|
||||||
|
```
|
||||||
|
|
||||||
For cross-compiling, the `--platform`, `--arch` and `--libc` npm flags
|
For cross-compiling, the `--platform`, `--arch` and `--libc` npm flags
|
||||||
(or the `npm_config_platform`, `npm_config_arch` and `npm_config_libc` environment variables)
|
(or the `npm_config_platform`, `npm_config_arch` and `npm_config_libc` environment variables)
|
||||||
|
|||||||
@@ -3,18 +3,27 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { useGlobalLibvips, globalLibvipsVersion, log, gypRebuild } = require('../lib/libvips');
|
const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips');
|
||||||
|
|
||||||
const buildFromSource = (msg) => {
|
const buildFromSource = (msg) => {
|
||||||
log(msg);
|
log(msg);
|
||||||
log('Attempting to build from source via node-gyp');
|
log('Attempting to build from source via node-gyp');
|
||||||
try {
|
try {
|
||||||
require('node-gyp');
|
require('node-addon-api');
|
||||||
|
log('Found node-addon-api');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('You might need to install node-gyp');
|
log('Please add node-addon-api to your dependencies');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const gyp = require('node-gyp');
|
||||||
|
log(`Found node-gyp version ${gyp().version}`);
|
||||||
|
} catch (err) {
|
||||||
|
log('Please add node-gyp to your dependencies');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
log('See https://sharp.pixelplumbing.com/install#building-from-source');
|
log('See https://sharp.pixelplumbing.com/install#building-from-source');
|
||||||
const status = gypRebuild();
|
const status = spawnRebuild();
|
||||||
if (status !== 0) {
|
if (status !== 0) {
|
||||||
process.exit(status);
|
process.exit(status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const util = require('util');
|
const util = require('node:util');
|
||||||
const stream = require('stream');
|
const stream = require('node:stream');
|
||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
|
|
||||||
require('./sharp');
|
require('./sharp');
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const spawnSync = require('child_process').spawnSync;
|
const { spawnSync } = require('node:child_process');
|
||||||
const semverCoerce = require('semver/functions/coerce');
|
const semverCoerce = require('semver/functions/coerce');
|
||||||
const semverGreaterThanOrEqualTo = require('semver/functions/gte');
|
const semverGreaterThanOrEqualTo = require('semver/functions/gte');
|
||||||
const detectLibc = require('detect-libc');
|
const detectLibc = require('detect-libc');
|
||||||
@@ -80,8 +80,8 @@ const isRosetta = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
const gypRebuild = () =>
|
const spawnRebuild = () =>
|
||||||
spawnSync('node-gyp rebuild', {
|
spawnSync('node-gyp rebuild --directory=src', {
|
||||||
...spawnSyncOptions,
|
...spawnSyncOptions,
|
||||||
stdio: 'inherit'
|
stdio: 'inherit'
|
||||||
}).status;
|
}).status;
|
||||||
@@ -146,7 +146,7 @@ module.exports = {
|
|||||||
buildSharpLibvipsLibDir,
|
buildSharpLibvipsLibDir,
|
||||||
runtimePlatformArch,
|
runtimePlatformArch,
|
||||||
log,
|
log,
|
||||||
gypRebuild,
|
spawnRebuild,
|
||||||
globalLibvipsVersion,
|
globalLibvipsVersion,
|
||||||
pkgConfigPath,
|
pkgConfigPath,
|
||||||
useGlobalLibvips
|
useGlobalLibvips
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('node:path');
|
||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
const sharp = require('./sharp');
|
const sharp = require('./sharp');
|
||||||
|
|
||||||
|
|||||||
20
lib/sharp.js
20
lib/sharp.js
@@ -9,11 +9,12 @@ const { familySync, versionSync } = require('detect-libc');
|
|||||||
|
|
||||||
const { runtimePlatformArch, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
|
const { runtimePlatformArch, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
|
||||||
const runtimePlatform = runtimePlatformArch();
|
const runtimePlatform = runtimePlatformArch();
|
||||||
|
const [isLinux, isMacOs, isWindows] = ['linux', 'darwin', 'win32'].map(os => runtimePlatform.startsWith(os));
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
try {
|
try {
|
||||||
// Check for local build
|
// Check for local build
|
||||||
module.exports = require(`../build/Release/sharp-${runtimePlatform}.node`);
|
module.exports = require(`../src/build/Release/sharp-${runtimePlatform}.node`);
|
||||||
} catch (errLocal) {
|
} catch (errLocal) {
|
||||||
try {
|
try {
|
||||||
// Check for runtime package
|
// Check for runtime package
|
||||||
@@ -29,11 +30,15 @@ try {
|
|||||||
help.push('Possible solutions:');
|
help.push('Possible solutions:');
|
||||||
// Common error messages
|
// Common error messages
|
||||||
if (prebuiltPlatforms.includes(runtimePlatform)) {
|
if (prebuiltPlatforms.includes(runtimePlatform)) {
|
||||||
help.push(`- Add an explicit dependency for the runtime platform: "npm install --force @sharpen/sharp-${runtimePlatform}"`);
|
help.push('- Add explicit dependencies for the runtime platform:');
|
||||||
|
help.push(` npm install --force @sharpen/sharp-${runtimePlatform}`);
|
||||||
|
if (!isWindows) {
|
||||||
|
help.push(` npm install --force @sharpen/sharp-libvips-${runtimePlatform}`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
help.push(`- The ${runtimePlatform} platform requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
help.push(`- The ${runtimePlatform} platform requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
}
|
}
|
||||||
if (runtimePlatform.startsWith('linux') && /symbol not found/i.test(errPackage)) {
|
if (isLinux && /symbol not found/i.test(errPackage)) {
|
||||||
try {
|
try {
|
||||||
const { engines } = require(`@sharpen/sharp-libvips-${runtimePlatform}/package`);
|
const { engines } = require(`@sharpen/sharp-libvips-${runtimePlatform}/package`);
|
||||||
const libcFound = `${familySync()} ${versionSync()}`;
|
const libcFound = `${familySync()} ${versionSync()}`;
|
||||||
@@ -41,16 +46,17 @@ try {
|
|||||||
help.push(`- Update your OS: found ${libcFound}, requires ${libcRequires}`);
|
help.push(`- Update your OS: found ${libcFound}, requires ${libcRequires}`);
|
||||||
} catch (errEngines) {}
|
} catch (errEngines) {}
|
||||||
}
|
}
|
||||||
if (runtimePlatform.startsWith('darwin') && /Incompatible library version/.test(errLocal.message)) {
|
if (isMacOs && /Incompatible library version/.test(errLocal.message)) {
|
||||||
help.push('- Update Homebrew: "brew update && brew upgrade vips"');
|
help.push('- Update Homebrew:');
|
||||||
|
help.push(' brew update && brew upgrade vips');
|
||||||
}
|
}
|
||||||
if (errPackage.code === 'ERR_DLOPEN_DISABLED') {
|
if (errPackage.code === 'ERR_DLOPEN_DISABLED') {
|
||||||
help.push('- Run Node.js without using the --no-addons flag');
|
help.push('- Run Node.js without using the --no-addons flag');
|
||||||
}
|
}
|
||||||
// Link to installation docs
|
// Link to installation docs
|
||||||
if (runtimePlatform.startsWith('linux') && /Module did not self-register/.test(errLocal.message + errPackage.message)) {
|
if (isLinux && /Module did not self-register/.test(errLocal.message + errPackage.message)) {
|
||||||
help.push('- Using worker threads on Linux? See https://sharp.pixelplumbing.com/install#worker-threads');
|
help.push('- Using worker threads on Linux? See https://sharp.pixelplumbing.com/install#worker-threads');
|
||||||
} else if (runtimePlatform.startsWith('win32') && /The specified procedure could not be found/.test(errPackage.message)) {
|
} else if (isWindows && /The specified procedure could not be found/.test(errPackage.message)) {
|
||||||
help.push('- Using the canvas package on Windows? See https://sharp.pixelplumbing.com/install#canvas-and-windows');
|
help.push('- Using the canvas package on Windows? See https://sharp.pixelplumbing.com/install#canvas-and-windows');
|
||||||
} else {
|
} else {
|
||||||
help.push('- Consult the installation documentation: https://sharp.pixelplumbing.com/install');
|
help.push('- Consult the installation documentation: https://sharp.pixelplumbing.com/install');
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const events = require('events');
|
const events = require('node:events');
|
||||||
const detectLibc = require('detect-libc');
|
const detectLibc = require('detect-libc');
|
||||||
|
|
||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-darwin-arm64",
|
"name": "@sharpen/sharp-darwin-arm64",
|
||||||
"version": "0.0.1-alpha.1",
|
"version": "0.0.1-alpha.5",
|
||||||
"description": "Prebuilt sharp for use with macOS ARM64",
|
"description": "Prebuilt sharp for use with macOS ARM64",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -13,15 +13,13 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
|
||||||
"@sharpen/sharp-libvips-darwin-arm64": "0.0.1-alpha.1"
|
|
||||||
},
|
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
"type": "commonjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./sharp.node": "./lib/sharp-darwin-arm64.node",
|
"./sharp.node": "./lib/sharp-darwin-arm64.node",
|
||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-darwin-x64",
|
"name": "@sharpen/sharp-darwin-x64",
|
||||||
"version": "0.0.1-alpha.1",
|
"version": "0.0.1-alpha.5",
|
||||||
"description": "Prebuilt sharp for use with macOS x64",
|
"description": "Prebuilt sharp for use with macOS x64",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -13,15 +13,13 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
|
||||||
"@sharpen/sharp-libvips-darwin-x64": "0.0.1-alpha.1"
|
|
||||||
},
|
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
"type": "commonjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./sharp.node": "./lib/sharp-darwin-x64.node",
|
"./sharp.node": "./lib/sharp-darwin-x64.node",
|
||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
// Populate contents of all packages with the current GitHub release
|
// Populate contents of all packages with the current GitHub release
|
||||||
|
|
||||||
const { writeFile, copyFile } = require('node:fs/promises');
|
const { writeFile, copyFile, rm } = require('node:fs/promises');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const { Readable } = require('node:stream');
|
const { Readable } = require('node:stream');
|
||||||
const { pipeline } = require('node:stream/promises');
|
const { pipeline } = require('node:stream/promises');
|
||||||
@@ -46,10 +46,12 @@ workspaces.map(async platform => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Extract prebuild tarball
|
// Extract prebuild tarball
|
||||||
|
const lib = path.join(dir, 'lib');
|
||||||
|
await rm(lib, { recursive: true });
|
||||||
await pipeline(
|
await pipeline(
|
||||||
Readable.fromWeb(response.body),
|
Readable.fromWeb(response.body),
|
||||||
createGunzip(),
|
createGunzip(),
|
||||||
extract(path.join(dir, 'lib'), { map: mapTarballEntry })
|
extract(lib, { map: mapTarballEntry })
|
||||||
);
|
);
|
||||||
// Generate README
|
// Generate README
|
||||||
const { name, description } = require(`./${platform}/package.json`);
|
const { name, description } = require(`./${platform}/package.json`);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const platform = buildPlatformArch();
|
|||||||
const dest = path.join(__dirname, platform);
|
const dest = path.join(__dirname, platform);
|
||||||
|
|
||||||
// Use same config as prebuild to copy binary files
|
// Use same config as prebuild to copy binary files
|
||||||
const release = path.join(__dirname, '..', 'build', 'Release');
|
const release = path.join(__dirname, '..', 'src', 'build', 'Release');
|
||||||
const prebuildrc = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '.prebuildrc'), 'utf8'));
|
const prebuildrc = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '.prebuildrc'), 'utf8'));
|
||||||
const include = new RegExp(prebuildrc['include-regex'], 'i');
|
const include = new RegExp(prebuildrc['include-regex'], 'i');
|
||||||
fs.cpSync(release, path.join(dest, 'lib'), {
|
fs.cpSync(release, path.join(dest, 'lib'), {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-linux-arm",
|
"name": "@sharpen/sharp-linux-arm",
|
||||||
"version": "0.0.1-alpha.1",
|
"version": "0.0.1-alpha.5",
|
||||||
"description": "Prebuilt sharp for use with Linux (glibc) ARM (32-bit)",
|
"description": "Prebuilt sharp for use with Linux (glibc) ARM (32-bit)",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -13,15 +13,13 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
|
||||||
"@sharpen/sharp-libvips-linux-arm": "0.0.1-alpha.1"
|
|
||||||
},
|
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
"type": "commonjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./sharp.node": "./lib/sharp-linux-arm.node",
|
"./sharp.node": "./lib/sharp-linux-arm.node",
|
||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-linux-arm64",
|
"name": "@sharpen/sharp-linux-arm64",
|
||||||
"version": "0.0.1-alpha.1",
|
"version": "0.0.1-alpha.5",
|
||||||
"description": "Prebuilt sharp for use with Linux (glibc) ARM64",
|
"description": "Prebuilt sharp for use with Linux (glibc) ARM64",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -13,15 +13,13 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
|
||||||
"@sharpen/sharp-libvips-linux-arm64": "0.0.1-alpha.1"
|
|
||||||
},
|
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
"type": "commonjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./sharp.node": "./lib/sharp-linux-arm64.node",
|
"./sharp.node": "./lib/sharp-linux-arm64.node",
|
||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-linux-x64",
|
"name": "@sharpen/sharp-linux-x64",
|
||||||
"version": "0.0.1-alpha.1",
|
"version": "0.0.1-alpha.5",
|
||||||
"description": "Prebuilt sharp for use with Linux (glibc) x64",
|
"description": "Prebuilt sharp for use with Linux (glibc) x64",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -13,15 +13,13 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
|
||||||
"@sharpen/sharp-libvips-linux-x64": "0.0.1-alpha.1"
|
|
||||||
},
|
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
"type": "commonjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./sharp.node": "./lib/sharp-linux-x64.node",
|
"./sharp.node": "./lib/sharp-linux-x64.node",
|
||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-linuxmusl-arm64",
|
"name": "@sharpen/sharp-linuxmusl-arm64",
|
||||||
"version": "0.0.1-alpha.1",
|
"version": "0.0.1-alpha.5",
|
||||||
"description": "Prebuilt sharp for use with Linux (musl) ARM64",
|
"description": "Prebuilt sharp for use with Linux (musl) ARM64",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -13,15 +13,13 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
|
||||||
"@sharpen/sharp-libvips-linuxmusl-arm64": "0.0.1-alpha.1"
|
|
||||||
},
|
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
"type": "commonjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./sharp.node": "./lib/sharp-linuxmusl-arm64.node",
|
"./sharp.node": "./lib/sharp-linuxmusl-arm64.node",
|
||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-linuxmusl-x64",
|
"name": "@sharpen/sharp-linuxmusl-x64",
|
||||||
"version": "0.0.1-alpha.1",
|
"version": "0.0.1-alpha.5",
|
||||||
"description": "Prebuilt sharp for use with Linux (musl) x64",
|
"description": "Prebuilt sharp for use with Linux (musl) x64",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -13,15 +13,13 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
|
||||||
"@sharpen/sharp-libvips-linuxmusl-x64": "0.0.1-alpha.1"
|
|
||||||
},
|
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
"type": "commonjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./sharp.node": "./lib/sharp-linuxmusl-x64.node",
|
"./sharp.node": "./lib/sharp-linuxmusl-x64.node",
|
||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-win32-ia32",
|
"name": "@sharpen/sharp-win32-ia32",
|
||||||
"version": "0.0.1-alpha.1",
|
"version": "0.0.1-alpha.5",
|
||||||
"description": "Prebuilt sharp for use with Windows x86 (32-bit)",
|
"description": "Prebuilt sharp for use with Windows x86 (32-bit)",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -13,18 +13,19 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
|
||||||
"@sharpen/sharp-libvips-win32-ia32": "0.0.1-alpha.1"
|
|
||||||
},
|
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib",
|
||||||
|
"versions.json",
|
||||||
|
"THIRD-PARTY-NOTICES.md"
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
"type": "commonjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./sharp.node": "./lib/sharp-win32-ia32.node",
|
"./sharp.node": "./lib/sharp-win32-ia32.node",
|
||||||
"./package": "./package.json"
|
"./package": "./package.json",
|
||||||
|
"./versions": "./versions.json"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-win32-x64",
|
"name": "@sharpen/sharp-win32-x64",
|
||||||
"version": "0.0.1-alpha.1",
|
"version": "0.0.1-alpha.5",
|
||||||
"description": "Prebuilt sharp for use with Windows x64",
|
"description": "Prebuilt sharp for use with Windows x64",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -13,15 +13,15 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
|
||||||
"@sharpen/sharp-libvips-win32-x64": "0.0.1-alpha.1"
|
|
||||||
},
|
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib",
|
||||||
|
"versions.json",
|
||||||
|
"THIRD-PARTY-NOTICES.md"
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
"type": "commonjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./sharp.node": "./lib/sharp-win32-x64.node",
|
"./sharp.node": "./lib/sharp-win32-x64.node",
|
||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
|
|||||||
52
package.json
52
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "sharp",
|
"name": "sharp",
|
||||||
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
|
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
|
||||||
"version": "0.33.0-alpha.2",
|
"version": "0.33.0-alpha.5",
|
||||||
"author": "Lovell Fuller <npm@lovell.info>",
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://github.com/lovell/sharp",
|
"homepage": "https://github.com/lovell/sharp",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
@@ -90,7 +90,7 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "node install/check",
|
"install": "node install/check",
|
||||||
"clean": "rm -rf build/ .nyc_output/ coverage/ test/fixtures/output.*",
|
"clean": "rm -rf src/build/ .nyc_output/ coverage/ test/fixtures/output.*",
|
||||||
"test": "npm run test-lint && npm run test-unit && npm run test-licensing && npm run test-types",
|
"test": "npm run test-lint && npm run test-unit && npm run test-licensing && npm run test-types",
|
||||||
"test-lint": "semistandard && cpplint",
|
"test-lint": "semistandard && cpplint",
|
||||||
"test-unit": "nyc --reporter=lcov --reporter=text --check-coverage --branches=100 mocha",
|
"test-unit": "nyc --reporter=lcov --reporter=text --check-coverage --branches=100 mocha",
|
||||||
@@ -103,13 +103,13 @@
|
|||||||
"docs-serve": "cd docs && npx serve",
|
"docs-serve": "cd docs && npx serve",
|
||||||
"docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
|
"docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
|
||||||
},
|
},
|
||||||
|
"type": "commonjs",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"binding.gyp",
|
"install",
|
||||||
"install/**",
|
"lib",
|
||||||
"lib/**",
|
"src/*.{cc,h,gyp}"
|
||||||
"src/**"
|
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -136,31 +136,30 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"color": "^4.2.3",
|
"color": "^4.2.3",
|
||||||
"detect-libc": "^2.0.2",
|
"detect-libc": "^2.0.2",
|
||||||
"node-addon-api": "^7.0.0",
|
|
||||||
"semver": "^7.5.4"
|
"semver": "^7.5.4"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@sharpen/sharp-darwin-arm64": "0.0.1-alpha.2",
|
"@sharpen/sharp-darwin-arm64": "0.0.1-alpha.5",
|
||||||
"@sharpen/sharp-darwin-x64": "0.0.1-alpha.2",
|
"@sharpen/sharp-darwin-x64": "0.0.1-alpha.5",
|
||||||
"@sharpen/sharp-linux-arm": "0.0.1-alpha.2",
|
"@sharpen/sharp-libvips-darwin-arm64": "0.0.1-alpha.2",
|
||||||
"@sharpen/sharp-linux-arm64": "0.0.1-alpha.2",
|
"@sharpen/sharp-libvips-darwin-x64": "0.0.1-alpha.2",
|
||||||
"@sharpen/sharp-linux-x64": "0.0.1-alpha.2",
|
"@sharpen/sharp-libvips-linux-arm": "0.0.1-alpha.2",
|
||||||
"@sharpen/sharp-linuxmusl-arm64": "0.0.1-alpha.2",
|
"@sharpen/sharp-libvips-linux-arm64": "0.0.1-alpha.2",
|
||||||
"@sharpen/sharp-linuxmusl-x64": "0.0.1-alpha.2",
|
"@sharpen/sharp-libvips-linux-x64": "0.0.1-alpha.2",
|
||||||
"@sharpen/sharp-win32-ia32": "0.0.1-alpha.2",
|
"@sharpen/sharp-libvips-linuxmusl-arm64": "0.0.1-alpha.2",
|
||||||
"@sharpen/sharp-win32-x64": "0.0.1-alpha.2"
|
"@sharpen/sharp-libvips-linuxmusl-x64": "0.0.1-alpha.2",
|
||||||
|
"@sharpen/sharp-linux-arm": "0.0.1-alpha.5",
|
||||||
|
"@sharpen/sharp-linux-arm64": "0.0.1-alpha.5",
|
||||||
|
"@sharpen/sharp-linux-x64": "0.0.1-alpha.5",
|
||||||
|
"@sharpen/sharp-linuxmusl-arm64": "0.0.1-alpha.5",
|
||||||
|
"@sharpen/sharp-linuxmusl-x64": "0.0.1-alpha.5",
|
||||||
|
"@sharpen/sharp-win32-ia32": "0.0.1-alpha.5",
|
||||||
|
"@sharpen/sharp-win32-x64": "0.0.1-alpha.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sharpen/sharp-libvips-darwin-arm64": "0.0.1-alpha.1",
|
"@sharpen/sharp-libvips-dev": "0.0.1-alpha.2",
|
||||||
"@sharpen/sharp-libvips-darwin-x64": "0.0.1-alpha.1",
|
"@sharpen/sharp-libvips-win32-ia32": "0.0.1-alpha.2",
|
||||||
"@sharpen/sharp-libvips-dev": "0.0.1-alpha.1",
|
"@sharpen/sharp-libvips-win32-x64": "0.0.1-alpha.2",
|
||||||
"@sharpen/sharp-libvips-linux-arm": "0.0.1-alpha.1",
|
|
||||||
"@sharpen/sharp-libvips-linux-arm64": "0.0.1-alpha.1",
|
|
||||||
"@sharpen/sharp-libvips-linux-x64": "0.0.1-alpha.1",
|
|
||||||
"@sharpen/sharp-libvips-linuxmusl-arm64": "0.0.1-alpha.1",
|
|
||||||
"@sharpen/sharp-libvips-linuxmusl-x64": "0.0.1-alpha.1",
|
|
||||||
"@sharpen/sharp-libvips-win32-ia32": "0.0.1-alpha.1",
|
|
||||||
"@sharpen/sharp-libvips-win32-x64": "0.0.1-alpha.1",
|
|
||||||
"@types/node": "*",
|
"@types/node": "*",
|
||||||
"async": "^3.2.4",
|
"async": "^3.2.4",
|
||||||
"cc": "^3.0.1",
|
"cc": "^3.0.1",
|
||||||
@@ -170,6 +169,7 @@
|
|||||||
"jsdoc-to-markdown": "^8.0.0",
|
"jsdoc-to-markdown": "^8.0.0",
|
||||||
"license-checker": "^25.0.1",
|
"license-checker": "^25.0.1",
|
||||||
"mocha": "^10.2.0",
|
"mocha": "^10.2.0",
|
||||||
|
"node-addon-api": "^7.0.0",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"prebuild": "^12.1.0",
|
"prebuild": "^12.1.0",
|
||||||
"semistandard": "^17.0.0",
|
"semistandard": "^17.0.0",
|
||||||
|
|||||||
@@ -3,14 +3,14 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
'variables': {
|
'variables': {
|
||||||
'vips_version': '<!(node -p "require(\'./lib/libvips\').minimumLibvipsVersion")',
|
'vips_version': '<!(node -p "require(\'../lib/libvips\').minimumLibvipsVersion")',
|
||||||
'platform_and_arch': '<!(node -p "require(\'./lib/libvips\').buildPlatformArch()")',
|
'platform_and_arch': '<!(node -p "require(\'../lib/libvips\').buildPlatformArch()")',
|
||||||
'sharp_libvips_include_dir': '<!(node -p "require(\'./lib/libvips\').buildSharpLibvipsIncludeDir()")',
|
'sharp_libvips_include_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsIncludeDir()")',
|
||||||
'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'./lib/libvips\').buildSharpLibvipsCPlusPlusDir()")',
|
'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsCPlusPlusDir()")',
|
||||||
'sharp_libvips_lib_dir': '<!(node -p "require(\'./lib/libvips\').buildSharpLibvipsLibDir()")'
|
'sharp_libvips_lib_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsLibDir()")'
|
||||||
},
|
},
|
||||||
'targets': [{
|
'targets': [{
|
||||||
'target_name': 'win-libvips-cpp',
|
'target_name': 'libvips-cpp',
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS == "win"', {
|
['OS == "win"', {
|
||||||
# Build libvips C++ binding for Windows due to MSVC std library ABI changes
|
# Build libvips C++ binding for Windows due to MSVC std library ABI changes
|
||||||
@@ -81,13 +81,13 @@
|
|||||||
],
|
],
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'<!(node -p "require(\'node-addon-api\').gyp")',
|
'<!(node -p "require(\'node-addon-api\').gyp")',
|
||||||
'win-libvips-cpp'
|
'libvips-cpp'
|
||||||
],
|
],
|
||||||
'variables': {
|
'variables': {
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS != "win"', {
|
['OS != "win"', {
|
||||||
'pkg_config_path': '<!(node -p "require(\'./lib/libvips\').pkgConfigPath()")',
|
'pkg_config_path': '<!(node -p "require(\'../lib/libvips\').pkgConfigPath()")',
|
||||||
'use_global_libvips': '<!(node -p "Boolean(require(\'./lib/libvips\').useGlobalLibvips()).toString()")'
|
'use_global_libvips': '<!(node -p "Boolean(require(\'../lib/libvips\').useGlobalLibvips()).toString()")'
|
||||||
}, {
|
}, {
|
||||||
'pkg_config_path': '',
|
'pkg_config_path': '',
|
||||||
'use_global_libvips': ''
|
'use_global_libvips': ''
|
||||||
@@ -95,13 +95,13 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
'sources': [
|
'sources': [
|
||||||
'src/common.cc',
|
'common.cc',
|
||||||
'src/metadata.cc',
|
'metadata.cc',
|
||||||
'src/stats.cc',
|
'stats.cc',
|
||||||
'src/operations.cc',
|
'operations.cc',
|
||||||
'src/pipeline.cc',
|
'pipeline.cc',
|
||||||
'src/utilities.cc',
|
'utilities.cc',
|
||||||
'src/sharp.cc'
|
'sharp.cc'
|
||||||
],
|
],
|
||||||
'include_dirs': [
|
'include_dirs': [
|
||||||
'<!(node -p "require(\'node-addon-api\').include_dir")',
|
'<!(node -p "require(\'node-addon-api\').include_dir")',
|
||||||
@@ -243,7 +243,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
'target_name': 'win-copy-dlls',
|
'target_name': 'copy-dll',
|
||||||
'type': 'none',
|
'type': 'none',
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'sharp-<(platform_and_arch)'
|
'sharp-<(platform_and_arch)'
|
||||||
@@ -363,12 +363,13 @@ namespace sharp {
|
|||||||
if (descriptor->isBuffer) {
|
if (descriptor->isBuffer) {
|
||||||
if (descriptor->rawChannels > 0) {
|
if (descriptor->rawChannels > 0) {
|
||||||
// Raw, uncompressed pixel data
|
// Raw, uncompressed pixel data
|
||||||
|
bool const is8bit = vips_band_format_is8bit(descriptor->rawDepth);
|
||||||
image = VImage::new_from_memory(descriptor->buffer, descriptor->bufferLength,
|
image = VImage::new_from_memory(descriptor->buffer, descriptor->bufferLength,
|
||||||
descriptor->rawWidth, descriptor->rawHeight, descriptor->rawChannels, descriptor->rawDepth);
|
descriptor->rawWidth, descriptor->rawHeight, descriptor->rawChannels, descriptor->rawDepth);
|
||||||
if (descriptor->rawChannels < 3) {
|
if (descriptor->rawChannels < 3) {
|
||||||
image.get_image()->Type = VIPS_INTERPRETATION_B_W;
|
image.get_image()->Type = is8bit ? VIPS_INTERPRETATION_B_W : VIPS_INTERPRETATION_GREY16;
|
||||||
} else {
|
} else {
|
||||||
image.get_image()->Type = VIPS_INTERPRETATION_sRGB;
|
image.get_image()->Type = is8bit ? VIPS_INTERPRETATION_sRGB : VIPS_INTERPRETATION_RGB16;
|
||||||
}
|
}
|
||||||
if (descriptor->rawPremultiplied) {
|
if (descriptor->rawPremultiplied) {
|
||||||
image = image.unpremultiply();
|
image = image.unpremultiply();
|
||||||
|
|||||||
13
src/sharp.cc
13
src/sharp.cc
@@ -1,6 +1,8 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
#include <mutex> // NOLINT(build/c++11)
|
||||||
|
|
||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
|
|
||||||
@@ -10,14 +12,11 @@
|
|||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
|
|
||||||
static void* sharp_vips_init(void*) {
|
|
||||||
vips_init("sharp");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Napi::Object init(Napi::Env env, Napi::Object exports) {
|
Napi::Object init(Napi::Env env, Napi::Object exports) {
|
||||||
static GOnce sharp_vips_init_once = G_ONCE_INIT;
|
static std::once_flag sharp_vips_init_once;
|
||||||
g_once(&sharp_vips_init_once, static_cast<GThreadFunc>(sharp_vips_init), nullptr);
|
std::call_once(sharp_vips_init_once, []() {
|
||||||
|
vips_init("sharp");
|
||||||
|
});
|
||||||
|
|
||||||
g_log_set_handler("VIPS", static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING),
|
g_log_set_handler("VIPS", static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING),
|
||||||
static_cast<GLogFunc>(sharp::VipsWarningCallback), nullptr);
|
static_cast<GLogFunc>(sharp::VipsWarningCallback), nullptr);
|
||||||
|
|||||||
@@ -284,4 +284,42 @@ describe('Raw pixel data', function () {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('16-bit roundtrip', () => {
|
||||||
|
it('grey', async () => {
|
||||||
|
const grey = 42000;
|
||||||
|
const png = await sharp(
|
||||||
|
Uint16Array.from([grey]),
|
||||||
|
{ raw: { width: 1, height: 1, channels: 1 } }
|
||||||
|
)
|
||||||
|
.toColourspace('grey16')
|
||||||
|
.png({ compressionLevel: 0 })
|
||||||
|
.toBuffer();
|
||||||
|
const raw = await sharp(png)
|
||||||
|
.toColourspace('grey16')
|
||||||
|
.raw({ depth: 'ushort' })
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
assert.strictEqual(raw.readUint16LE(0), grey);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('RGB', async () => {
|
||||||
|
const rgb = [10946, 28657, 46368];
|
||||||
|
const png = await sharp(
|
||||||
|
Uint16Array.from(rgb),
|
||||||
|
{ raw: { width: 1, height: 1, channels: 3 } }
|
||||||
|
)
|
||||||
|
.toColourspace('rgb16')
|
||||||
|
.png({ compressionLevel: 0 })
|
||||||
|
.toBuffer();
|
||||||
|
const raw = await sharp(png)
|
||||||
|
.toColourspace('rgb16')
|
||||||
|
.raw({ depth: 'ushort' })
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
assert.strictEqual(raw.readUint16LE(0), rgb[0]);
|
||||||
|
assert.strictEqual(raw.readUint16LE(2), rgb[1]);
|
||||||
|
assert.strictEqual(raw.readUint16LE(4), rgb[2]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user