Compare commits

..

11 Commits

Author SHA1 Message Date
Lovell Fuller
a9aa7339ce Prerelease 0.33.0-alpha.3 2023-10-06 09:48:44 +01:00
Lovell Fuller
08108f5fad Use std::once for vips_init call 2023-10-06 09:44:57 +01:00
Lovell Fuller
58e3c4c70e Ensure all package files make use of commonjs explicit 2023-10-05 20:00:32 +01:00
Lovell Fuller
f8cf25ca56 Ensure correct interp of 16-bit raw input #3808 2023-10-05 14:05:36 +01:00
Lovell Fuller
ca95979ecc Prefix node builtins, skips cache lookup 2023-10-05 12:09:19 +01:00
Lovell Fuller
392f6afb5e Commit fcc7e84 but do it properly this time 2023-10-04 21:30:05 +01:00
Lovell Fuller
7c97aabaf8 Ensure win32 packages contain version/notice files 2023-10-04 21:12:16 +01:00
Lovell Fuller
fcc7e84bee Revert target names as these are used for DLLs 2023-10-04 20:46:25 +01:00
Lovell Fuller
226a9a13ef Packaging: prerelease version bump 2023-10-04 15:48:23 +01:00
Lovell Fuller
4d3c9ae3d1 Packaging: clear existing lib directories 2023-10-04 15:47:57 +01:00
Lovell Fuller
f31011d759 CI: increase linux-arm timeout 2023-10-04 15:47:35 +01:00
21 changed files with 103 additions and 51 deletions

View File

@@ -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:

View File

@@ -10,7 +10,7 @@
'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,7 +81,7 @@
], ],
'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': [
@@ -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)'

View File

@@ -13,6 +13,9 @@ Requires libvips v8.14.5
* 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

View File

@@ -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');

View File

@@ -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');

View File

@@ -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');

View File

@@ -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');

View File

@@ -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.3",
"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": {
@@ -22,6 +22,7 @@
"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"

View File

@@ -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.3",
"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": {
@@ -22,6 +22,7 @@
"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"

View File

@@ -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`);

View File

@@ -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.3",
"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": {
@@ -22,6 +22,7 @@
"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"

View File

@@ -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.3",
"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": {
@@ -22,6 +22,7 @@
"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"

View File

@@ -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.3",
"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": {
@@ -22,6 +22,7 @@
"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"

View File

@@ -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.3",
"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": {
@@ -22,6 +22,7 @@
"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"

View File

@@ -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.3",
"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": {
@@ -22,6 +22,7 @@
"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"

View File

@@ -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.3",
"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",

View File

@@ -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.3",
"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"

View File

@@ -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.3",
"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": [
@@ -103,13 +103,14 @@
"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", "binding.gyp",
"install/**", "install",
"lib/**", "lib",
"src/**" "src"
], ],
"repository": { "repository": {
"type": "git", "type": "git",
@@ -140,15 +141,15 @@
"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.3",
"@sharpen/sharp-darwin-x64": "0.0.1-alpha.2", "@sharpen/sharp-darwin-x64": "0.0.1-alpha.3",
"@sharpen/sharp-linux-arm": "0.0.1-alpha.2", "@sharpen/sharp-linux-arm": "0.0.1-alpha.3",
"@sharpen/sharp-linux-arm64": "0.0.1-alpha.2", "@sharpen/sharp-linux-arm64": "0.0.1-alpha.3",
"@sharpen/sharp-linux-x64": "0.0.1-alpha.2", "@sharpen/sharp-linux-x64": "0.0.1-alpha.3",
"@sharpen/sharp-linuxmusl-arm64": "0.0.1-alpha.2", "@sharpen/sharp-linuxmusl-arm64": "0.0.1-alpha.3",
"@sharpen/sharp-linuxmusl-x64": "0.0.1-alpha.2", "@sharpen/sharp-linuxmusl-x64": "0.0.1-alpha.3",
"@sharpen/sharp-win32-ia32": "0.0.1-alpha.2", "@sharpen/sharp-win32-ia32": "0.0.1-alpha.3",
"@sharpen/sharp-win32-x64": "0.0.1-alpha.2" "@sharpen/sharp-win32-x64": "0.0.1-alpha.3"
}, },
"devDependencies": { "devDependencies": {
"@sharpen/sharp-libvips-darwin-arm64": "0.0.1-alpha.1", "@sharpen/sharp-libvips-darwin-arm64": "0.0.1-alpha.1",

View File

@@ -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();

View File

@@ -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);

View File

@@ -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]);
});
});
}); });