sharp 0.34.0 → 0.34.2-rc.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/README.md +1 -1
- package/lib/colour.js +22 -11
- package/lib/constructor.js +1 -1
- package/lib/index.d.ts +48 -13
- package/lib/input.js +3 -16
- package/lib/libvips.js +2 -2
- package/lib/operation.js +1 -8
- package/lib/resize.js +1 -1
- package/package.json +20 -18
- package/src/binding.gyp +4 -1
- package/src/common.cc +15 -26
- package/src/common.h +0 -6
- package/src/pipeline.cc +2 -1
- package/src/pipeline.h +1 -1
- package/src/stats.cc +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# sharp
|
|
2
2
|
|
|
3
|
-
<img src="https://
|
|
3
|
+
<img src="https://sharp.pixelplumbing.com/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right">
|
|
4
4
|
|
|
5
5
|
The typical use case for this high speed Node-API module
|
|
6
6
|
is to convert large images in common formats to
|
package/lib/colour.js
CHANGED
|
@@ -134,6 +134,26 @@ function toColorspace (colorspace) {
|
|
|
134
134
|
return this.toColourspace(colorspace);
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Create a RGBA colour array from a given value.
|
|
139
|
+
* @private
|
|
140
|
+
* @param {string|Object} value
|
|
141
|
+
* @throws {Error} Invalid value
|
|
142
|
+
*/
|
|
143
|
+
function _getBackgroundColourOption (value) {
|
|
144
|
+
if (is.object(value) || is.string(value)) {
|
|
145
|
+
const colour = color(value);
|
|
146
|
+
return [
|
|
147
|
+
colour.red(),
|
|
148
|
+
colour.green(),
|
|
149
|
+
colour.blue(),
|
|
150
|
+
Math.round(colour.alpha() * 255)
|
|
151
|
+
];
|
|
152
|
+
} else {
|
|
153
|
+
throw is.invalidParameterError('background', 'object or string', value);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
137
157
|
/**
|
|
138
158
|
* Update a colour attribute of the this.options Object.
|
|
139
159
|
* @private
|
|
@@ -143,17 +163,7 @@ function toColorspace (colorspace) {
|
|
|
143
163
|
*/
|
|
144
164
|
function _setBackgroundColourOption (key, value) {
|
|
145
165
|
if (is.defined(value)) {
|
|
146
|
-
|
|
147
|
-
const colour = color(value);
|
|
148
|
-
this.options[key] = [
|
|
149
|
-
colour.red(),
|
|
150
|
-
colour.green(),
|
|
151
|
-
colour.blue(),
|
|
152
|
-
Math.round(colour.alpha() * 255)
|
|
153
|
-
];
|
|
154
|
-
} else {
|
|
155
|
-
throw is.invalidParameterError('background', 'object or string', value);
|
|
156
|
-
}
|
|
166
|
+
this.options[key] = _getBackgroundColourOption(value);
|
|
157
167
|
}
|
|
158
168
|
}
|
|
159
169
|
|
|
@@ -173,6 +183,7 @@ module.exports = function (Sharp) {
|
|
|
173
183
|
toColourspace,
|
|
174
184
|
toColorspace,
|
|
175
185
|
// Private
|
|
186
|
+
_getBackgroundColourOption,
|
|
176
187
|
_setBackgroundColourOption
|
|
177
188
|
});
|
|
178
189
|
// Class attributes
|
package/lib/constructor.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -971,7 +971,7 @@ declare namespace sharp {
|
|
|
971
971
|
*
|
|
972
972
|
* Using this option will remove the EXIF `Orientation` tag, if any.
|
|
973
973
|
*/
|
|
974
|
-
autoOrient?: boolean;
|
|
974
|
+
autoOrient?: boolean | undefined;
|
|
975
975
|
/**
|
|
976
976
|
* When to abort processing of invalid pixel data, one of (in order of sensitivity):
|
|
977
977
|
* 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. (optional, default 'warning')
|
|
@@ -1146,13 +1146,13 @@ declare namespace sharp {
|
|
|
1146
1146
|
/** Number value of the EXIF Orientation header, if present */
|
|
1147
1147
|
orientation?: number | undefined;
|
|
1148
1148
|
/** Name of decoder used to decompress image data e.g. jpeg, png, webp, gif, svg */
|
|
1149
|
-
format
|
|
1149
|
+
format: keyof FormatEnum;
|
|
1150
1150
|
/** Total size of image in bytes, for Stream and Buffer input only */
|
|
1151
1151
|
size?: number | undefined;
|
|
1152
1152
|
/** Number of pixels wide (EXIF orientation is not taken into consideration) */
|
|
1153
|
-
width
|
|
1153
|
+
width: number;
|
|
1154
1154
|
/** Number of pixels high (EXIF orientation is not taken into consideration) */
|
|
1155
|
-
height
|
|
1155
|
+
height: number;
|
|
1156
1156
|
/** Any changed metadata after the image orientation is applied. */
|
|
1157
1157
|
autoOrient: {
|
|
1158
1158
|
/** Number of pixels wide (EXIF orientation is taken into consideration) */
|
|
@@ -1161,19 +1161,19 @@ declare namespace sharp {
|
|
|
1161
1161
|
height: number;
|
|
1162
1162
|
};
|
|
1163
1163
|
/** Name of colour space interpretation */
|
|
1164
|
-
space
|
|
1164
|
+
space: keyof ColourspaceEnum;
|
|
1165
1165
|
/** Number of bands e.g. 3 for sRGB, 4 for CMYK */
|
|
1166
|
-
channels
|
|
1166
|
+
channels: Channels;
|
|
1167
1167
|
/** Name of pixel depth format e.g. uchar, char, ushort, float ... */
|
|
1168
|
-
depth
|
|
1168
|
+
depth: keyof DepthEnum;
|
|
1169
1169
|
/** Number of pixels per inch (DPI), if present */
|
|
1170
1170
|
density?: number | undefined;
|
|
1171
1171
|
/** String containing JPEG chroma subsampling, 4:2:0 or 4:4:4 for RGB, 4:2:0:4 or 4:4:4:4 for CMYK */
|
|
1172
1172
|
chromaSubsampling?: string | undefined;
|
|
1173
1173
|
/** Boolean indicating whether the image is interlaced using a progressive scan */
|
|
1174
|
-
isProgressive
|
|
1174
|
+
isProgressive: boolean;
|
|
1175
1175
|
/** Boolean indicating whether the image is palette-based (GIF, PNG). */
|
|
1176
|
-
isPalette
|
|
1176
|
+
isPalette: boolean;
|
|
1177
1177
|
/** Number of bits per sample for each channel (GIF, PNG). */
|
|
1178
1178
|
bitsPerSample?: number | undefined;
|
|
1179
1179
|
/** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */
|
|
@@ -1187,9 +1187,9 @@ declare namespace sharp {
|
|
|
1187
1187
|
/** Number of the primary page in a HEIF image */
|
|
1188
1188
|
pagePrimary?: number | undefined;
|
|
1189
1189
|
/** Boolean indicating the presence of an embedded ICC profile */
|
|
1190
|
-
hasProfile
|
|
1190
|
+
hasProfile: boolean;
|
|
1191
1191
|
/** Boolean indicating the presence of an alpha transparency channel */
|
|
1192
|
-
hasAlpha
|
|
1192
|
+
hasAlpha: boolean;
|
|
1193
1193
|
/** Buffer containing raw EXIF data, if present */
|
|
1194
1194
|
exif?: Buffer | undefined;
|
|
1195
1195
|
/** Buffer containing raw ICC profile data, if present */
|
|
@@ -1336,6 +1336,8 @@ declare namespace sharp {
|
|
|
1336
1336
|
nearLossless?: boolean | undefined;
|
|
1337
1337
|
/** Use high quality chroma subsampling (optional, default false) */
|
|
1338
1338
|
smartSubsample?: boolean | undefined;
|
|
1339
|
+
/** Auto-adjust the deblocking filter, slow but can improve low contrast edges (optional, default false) */
|
|
1340
|
+
smartDeblock?: boolean | undefined;
|
|
1339
1341
|
/** Level of CPU effort to reduce file size, integer 0-6 (optional, default 4) */
|
|
1340
1342
|
effort?: number | undefined;
|
|
1341
1343
|
/** Prevent use of animation key frames to minimise file size (slow) (optional, default false) */
|
|
@@ -1699,6 +1701,10 @@ declare namespace sharp {
|
|
|
1699
1701
|
/** When using the attention crop strategy, the focal point of the cropped region */
|
|
1700
1702
|
attentionX?: number | undefined;
|
|
1701
1703
|
attentionY?: number | undefined;
|
|
1704
|
+
/** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */
|
|
1705
|
+
pages?: number | undefined;
|
|
1706
|
+
/** Number of pixels high each page in a multi-page image will be. */
|
|
1707
|
+
pageHeight?: number | undefined;
|
|
1702
1708
|
}
|
|
1703
1709
|
|
|
1704
1710
|
interface AvailableFormatInfo {
|
|
@@ -1739,11 +1745,38 @@ declare namespace sharp {
|
|
|
1739
1745
|
}
|
|
1740
1746
|
|
|
1741
1747
|
interface ColourspaceEnum {
|
|
1742
|
-
multiband: string;
|
|
1743
1748
|
'b-w': string;
|
|
1744
|
-
|
|
1749
|
+
cmc: string;
|
|
1745
1750
|
cmyk: string;
|
|
1751
|
+
fourier: string;
|
|
1752
|
+
grey16: string;
|
|
1753
|
+
histogram: string;
|
|
1754
|
+
hsv: string;
|
|
1755
|
+
lab: string;
|
|
1756
|
+
labq: string;
|
|
1757
|
+
labs: string;
|
|
1758
|
+
lch: string;
|
|
1759
|
+
matrix: string;
|
|
1760
|
+
multiband: string;
|
|
1761
|
+
rgb: string;
|
|
1762
|
+
rgb16: string;
|
|
1763
|
+
scrgb: string;
|
|
1746
1764
|
srgb: string;
|
|
1765
|
+
xyz: string;
|
|
1766
|
+
yxy: string;
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
interface DepthEnum {
|
|
1770
|
+
char: string;
|
|
1771
|
+
complex: string;
|
|
1772
|
+
double: string;
|
|
1773
|
+
dpcomplex: string;
|
|
1774
|
+
float: string;
|
|
1775
|
+
int: string;
|
|
1776
|
+
short: string;
|
|
1777
|
+
uchar: string;
|
|
1778
|
+
uint: string;
|
|
1779
|
+
ushort: string;
|
|
1747
1780
|
}
|
|
1748
1781
|
|
|
1749
1782
|
type FailOnOptions = 'none' | 'truncated' | 'error' | 'warning';
|
|
@@ -1812,6 +1845,7 @@ declare namespace sharp {
|
|
|
1812
1845
|
interface FormatEnum {
|
|
1813
1846
|
avif: AvailableFormatInfo;
|
|
1814
1847
|
dz: AvailableFormatInfo;
|
|
1848
|
+
exr: AvailableFormatInfo;
|
|
1815
1849
|
fits: AvailableFormatInfo;
|
|
1816
1850
|
gif: AvailableFormatInfo;
|
|
1817
1851
|
heif: AvailableFormatInfo;
|
|
@@ -1825,6 +1859,7 @@ declare namespace sharp {
|
|
|
1825
1859
|
pdf: AvailableFormatInfo;
|
|
1826
1860
|
png: AvailableFormatInfo;
|
|
1827
1861
|
ppm: AvailableFormatInfo;
|
|
1862
|
+
rad: AvailableFormatInfo;
|
|
1828
1863
|
raw: AvailableFormatInfo;
|
|
1829
1864
|
svg: AvailableFormatInfo;
|
|
1830
1865
|
tiff: AvailableFormatInfo;
|
package/lib/input.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
const color = require('color');
|
|
7
6
|
const is = require('./is');
|
|
8
7
|
const sharp = require('./sharp');
|
|
9
8
|
|
|
@@ -249,7 +248,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|
|
249
248
|
}
|
|
250
249
|
// PDF background colour
|
|
251
250
|
if (is.defined(inputOptions.pdfBackground)) {
|
|
252
|
-
this.
|
|
251
|
+
inputDescriptor.pdfBackground = this._getBackgroundColourOption(inputOptions.pdfBackground);
|
|
253
252
|
}
|
|
254
253
|
// Create new image
|
|
255
254
|
if (is.defined(inputOptions.create)) {
|
|
@@ -288,13 +287,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|
|
288
287
|
if (!is.inRange(inputOptions.create.channels, 3, 4)) {
|
|
289
288
|
throw is.invalidParameterError('create.channels', 'number between 3 and 4', inputOptions.create.channels);
|
|
290
289
|
}
|
|
291
|
-
|
|
292
|
-
inputDescriptor.createBackground = [
|
|
293
|
-
background.red(),
|
|
294
|
-
background.green(),
|
|
295
|
-
background.blue(),
|
|
296
|
-
Math.round(background.alpha() * 255)
|
|
297
|
-
];
|
|
290
|
+
inputDescriptor.createBackground = this._getBackgroundColourOption(inputOptions.create.background);
|
|
298
291
|
} else {
|
|
299
292
|
throw new Error('Expected valid noise or background to create a new input image');
|
|
300
293
|
}
|
|
@@ -410,13 +403,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|
|
410
403
|
}
|
|
411
404
|
}
|
|
412
405
|
if (is.defined(inputOptions.join.background)) {
|
|
413
|
-
|
|
414
|
-
inputDescriptor.joinBackground = [
|
|
415
|
-
background.red(),
|
|
416
|
-
background.green(),
|
|
417
|
-
background.blue(),
|
|
418
|
-
Math.round(background.alpha() * 255)
|
|
419
|
-
];
|
|
406
|
+
inputDescriptor.joinBackground = this._getBackgroundColourOption(inputOptions.join.background);
|
|
420
407
|
}
|
|
421
408
|
if (is.defined(inputOptions.join.halign)) {
|
|
422
409
|
if (is.string(inputOptions.join.halign) && is.string(this.constructor.align[inputOptions.join.halign])) {
|
package/lib/libvips.js
CHANGED
|
@@ -18,9 +18,9 @@ const minimumLibvipsVersion = semverCoerce(minimumLibvipsVersionLabelled).versio
|
|
|
18
18
|
|
|
19
19
|
const prebuiltPlatforms = [
|
|
20
20
|
'darwin-arm64', 'darwin-x64',
|
|
21
|
-
'linux-arm', 'linux-arm64', 'linux-s390x', 'linux-x64',
|
|
21
|
+
'linux-arm', 'linux-arm64', 'linux-ppc64', 'linux-s390x', 'linux-x64',
|
|
22
22
|
'linuxmusl-arm64', 'linuxmusl-x64',
|
|
23
|
-
'win32-ia32', 'win32-x64'
|
|
23
|
+
'win32-arm64', 'win32-ia32', 'win32-x64'
|
|
24
24
|
];
|
|
25
25
|
|
|
26
26
|
const spawnSyncOptions = {
|
package/lib/operation.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
const color = require('color');
|
|
7
6
|
const is = require('./is');
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -67,13 +66,7 @@ function rotate (angle, options) {
|
|
|
67
66
|
} else if (is.number(angle)) {
|
|
68
67
|
this.options.rotationAngle = angle;
|
|
69
68
|
if (is.object(options) && options.background) {
|
|
70
|
-
|
|
71
|
-
this.options.rotationBackground = [
|
|
72
|
-
backgroundColour.red(),
|
|
73
|
-
backgroundColour.green(),
|
|
74
|
-
backgroundColour.blue(),
|
|
75
|
-
Math.round(backgroundColour.alpha() * 255)
|
|
76
|
-
];
|
|
69
|
+
this._setBackgroundColourOption('rotationBackground', options.background);
|
|
77
70
|
}
|
|
78
71
|
} else {
|
|
79
72
|
throw is.invalidParameterError('angle', 'numeric', angle);
|
package/lib/resize.js
CHANGED
|
@@ -129,7 +129,7 @@ function isResizeExpected (options) {
|
|
|
129
129
|
*
|
|
130
130
|
* Some of these values are based on the [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) CSS property.
|
|
131
131
|
*
|
|
132
|
-
* <img alt="Examples of various values for the fit property when resizing" width="100%" style="aspect-ratio: 998/243" src="
|
|
132
|
+
* <img alt="Examples of various values for the fit property when resizing" width="100%" style="aspect-ratio: 998/243" src="/api-resize-fit.svg">
|
|
133
133
|
*
|
|
134
134
|
* When using a **fit** of `cover` or `contain`, the default **position** is `centre`. Other options are:
|
|
135
135
|
* - `sharp.position`: `top`, `right top`, `right`, `right bottom`, `bottom`, `left bottom`, `left`, `left top`.
|
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.2-rc.0",
|
|
5
5
|
"author": "Lovell Fuller <npm@lovell.info>",
|
|
6
6
|
"homepage": "https://sharp.pixelplumbing.com",
|
|
7
7
|
"contributors": [
|
|
@@ -138,12 +138,12 @@
|
|
|
138
138
|
],
|
|
139
139
|
"dependencies": {
|
|
140
140
|
"color": "^4.2.3",
|
|
141
|
-
"detect-libc": "^2.0.
|
|
142
|
-
"semver": "^7.7.
|
|
141
|
+
"detect-libc": "^2.0.4",
|
|
142
|
+
"semver": "^7.7.2"
|
|
143
143
|
},
|
|
144
144
|
"optionalDependencies": {
|
|
145
|
-
"@img/sharp-darwin-arm64": "0.34.0",
|
|
146
|
-
"@img/sharp-darwin-x64": "0.34.0",
|
|
145
|
+
"@img/sharp-darwin-arm64": "0.34.2-rc.0",
|
|
146
|
+
"@img/sharp-darwin-x64": "0.34.2-rc.0",
|
|
147
147
|
"@img/sharp-libvips-darwin-arm64": "1.1.0",
|
|
148
148
|
"@img/sharp-libvips-darwin-x64": "1.1.0",
|
|
149
149
|
"@img/sharp-libvips-linux-arm": "1.1.0",
|
|
@@ -153,37 +153,39 @@
|
|
|
153
153
|
"@img/sharp-libvips-linux-x64": "1.1.0",
|
|
154
154
|
"@img/sharp-libvips-linuxmusl-arm64": "1.1.0",
|
|
155
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-
|
|
164
|
-
"@img/sharp-win32-
|
|
156
|
+
"@img/sharp-linux-arm": "0.34.2-rc.0",
|
|
157
|
+
"@img/sharp-linux-arm64": "0.34.2-rc.0",
|
|
158
|
+
"@img/sharp-linux-s390x": "0.34.2-rc.0",
|
|
159
|
+
"@img/sharp-linux-x64": "0.34.2-rc.0",
|
|
160
|
+
"@img/sharp-linuxmusl-arm64": "0.34.2-rc.0",
|
|
161
|
+
"@img/sharp-linuxmusl-x64": "0.34.2-rc.0",
|
|
162
|
+
"@img/sharp-wasm32": "0.34.2-rc.0",
|
|
163
|
+
"@img/sharp-win32-arm64": "0.34.2-rc.0",
|
|
164
|
+
"@img/sharp-win32-ia32": "0.34.2-rc.0",
|
|
165
|
+
"@img/sharp-win32-x64": "0.34.2-rc.0"
|
|
165
166
|
},
|
|
166
167
|
"devDependencies": {
|
|
167
|
-
"@emnapi/runtime": "^1.4.
|
|
168
|
+
"@emnapi/runtime": "^1.4.3",
|
|
168
169
|
"@img/sharp-libvips-dev": "1.1.0",
|
|
169
170
|
"@img/sharp-libvips-dev-wasm32": "1.1.0",
|
|
171
|
+
"@img/sharp-libvips-win32-arm64": "1.1.0",
|
|
170
172
|
"@img/sharp-libvips-win32-ia32": "1.1.0",
|
|
171
173
|
"@img/sharp-libvips-win32-x64": "1.1.0",
|
|
172
174
|
"@types/node": "*",
|
|
173
175
|
"cc": "^3.0.1",
|
|
174
|
-
"emnapi": "^1.4.
|
|
176
|
+
"emnapi": "^1.4.3",
|
|
175
177
|
"exif-reader": "^2.0.2",
|
|
176
178
|
"extract-zip": "^2.0.1",
|
|
177
179
|
"icc": "^3.0.0",
|
|
178
180
|
"jsdoc-to-markdown": "^9.1.1",
|
|
179
181
|
"license-checker": "^25.0.1",
|
|
180
|
-
"mocha": "^11.
|
|
182
|
+
"mocha": "^11.2.2",
|
|
181
183
|
"node-addon-api": "^8.3.1",
|
|
182
184
|
"nyc": "^17.1.0",
|
|
183
185
|
"prebuild": "^13.0.1",
|
|
184
186
|
"semistandard": "^17.0.0",
|
|
185
187
|
"tar-fs": "^3.0.8",
|
|
186
|
-
"tsd": "^0.
|
|
188
|
+
"tsd": "^0.32.0"
|
|
187
189
|
},
|
|
188
190
|
"license": "Apache-2.0",
|
|
189
191
|
"engines": {
|
package/src/binding.gyp
CHANGED
|
@@ -19,7 +19,10 @@
|
|
|
19
19
|
'type': 'shared_library',
|
|
20
20
|
'defines': [
|
|
21
21
|
'_VIPS_PUBLIC=__declspec(dllexport)',
|
|
22
|
-
'_ALLOW_KEYWORD_MACROS'
|
|
22
|
+
'_ALLOW_KEYWORD_MACROS',
|
|
23
|
+
'G_DISABLE_ASSERT',
|
|
24
|
+
'G_DISABLE_CAST_CHECKS',
|
|
25
|
+
'G_DISABLE_CHECKS'
|
|
23
26
|
],
|
|
24
27
|
'sources': [
|
|
25
28
|
'<(sharp_libvips_cplusplus_dir)/VConnection.cpp',
|
package/src/common.cc
CHANGED
|
@@ -651,22 +651,21 @@ namespace sharp {
|
|
|
651
651
|
*/
|
|
652
652
|
VImage SetAnimationProperties(VImage image, int nPages, int pageHeight, std::vector<int> delay, int loop) {
|
|
653
653
|
bool hasDelay = !delay.empty();
|
|
654
|
-
|
|
655
|
-
// Avoid a copy if none of the animation properties are needed.
|
|
656
|
-
if (nPages == 1 && !hasDelay && loop == -1) return image;
|
|
657
|
-
|
|
658
|
-
if (delay.size() == 1) {
|
|
659
|
-
// We have just one delay, repeat that value for all frames.
|
|
660
|
-
delay.insert(delay.end(), nPages - 1, delay[0]);
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
// Attaching metadata, need to copy the image.
|
|
664
654
|
VImage copy = image.copy();
|
|
665
655
|
|
|
666
656
|
// Only set page-height if we have more than one page, or this could
|
|
667
657
|
// accidentally turn into an animated image later.
|
|
668
658
|
if (nPages > 1) copy.set(VIPS_META_PAGE_HEIGHT, pageHeight);
|
|
669
|
-
if (hasDelay)
|
|
659
|
+
if (hasDelay) {
|
|
660
|
+
if (delay.size() == 1) {
|
|
661
|
+
// We have just one delay, repeat that value for all frames.
|
|
662
|
+
delay.insert(delay.end(), nPages - 1, delay[0]);
|
|
663
|
+
}
|
|
664
|
+
copy.set("delay", delay);
|
|
665
|
+
}
|
|
666
|
+
if (nPages == 1 && !hasDelay && loop == -1) {
|
|
667
|
+
loop = 1;
|
|
668
|
+
}
|
|
670
669
|
if (loop != -1) copy.set("loop", loop);
|
|
671
670
|
|
|
672
671
|
return copy;
|
|
@@ -952,14 +951,6 @@ namespace sharp {
|
|
|
952
951
|
return interpretation == VIPS_INTERPRETATION_RGB16 || interpretation == VIPS_INTERPRETATION_GREY16;
|
|
953
952
|
}
|
|
954
953
|
|
|
955
|
-
/*
|
|
956
|
-
Return the image alpha maximum. Useful for combining alpha bands. scRGB
|
|
957
|
-
images are 0 - 1 for image data, but the alpha is 0 - 255.
|
|
958
|
-
*/
|
|
959
|
-
double MaximumImageAlpha(VipsInterpretation const interpretation) {
|
|
960
|
-
return Is16Bit(interpretation) ? 65535.0 : 255.0;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
954
|
/*
|
|
964
955
|
Convert RGBA value to another colourspace
|
|
965
956
|
*/
|
|
@@ -1002,16 +993,16 @@ namespace sharp {
|
|
|
1002
993
|
0.0722 * colour[2])
|
|
1003
994
|
};
|
|
1004
995
|
}
|
|
1005
|
-
// Add alpha channel to alphaColour colour
|
|
996
|
+
// Add alpha channel(s) to alphaColour colour
|
|
1006
997
|
if (colour[3] < 255.0 || image.has_alpha()) {
|
|
1007
|
-
|
|
998
|
+
int extraBands = image.bands() > 4 ? image.bands() - 3 : 1;
|
|
999
|
+
alphaColour.insert(alphaColour.end(), extraBands, colour[3] * multiplier);
|
|
1008
1000
|
}
|
|
1009
1001
|
// Ensure alphaColour colour uses correct colourspace
|
|
1010
1002
|
alphaColour = sharp::GetRgbaAsColourspace(alphaColour, image.interpretation(), premultiply);
|
|
1011
1003
|
// Add non-transparent alpha channel, if required
|
|
1012
1004
|
if (colour[3] < 255.0 && !image.has_alpha()) {
|
|
1013
|
-
image = image.
|
|
1014
|
-
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier).cast(image.format()));
|
|
1005
|
+
image = image.bandjoin_const({ 255 * multiplier });
|
|
1015
1006
|
}
|
|
1016
1007
|
return std::make_tuple(image, alphaColour);
|
|
1017
1008
|
}
|
|
@@ -1031,9 +1022,7 @@ namespace sharp {
|
|
|
1031
1022
|
*/
|
|
1032
1023
|
VImage EnsureAlpha(VImage image, double const value) {
|
|
1033
1024
|
if (!image.has_alpha()) {
|
|
1034
|
-
|
|
1035
|
-
alpha.push_back(value * sharp::MaximumImageAlpha(image.interpretation()));
|
|
1036
|
-
image = image.bandjoin_const(alpha);
|
|
1025
|
+
image = image.bandjoin_const({ value * vips_interpretation_max_alpha(image.interpretation()) });
|
|
1037
1026
|
}
|
|
1038
1027
|
return image;
|
|
1039
1028
|
}
|
package/src/common.h
CHANGED
|
@@ -357,12 +357,6 @@ namespace sharp {
|
|
|
357
357
|
*/
|
|
358
358
|
bool Is16Bit(VipsInterpretation const interpretation);
|
|
359
359
|
|
|
360
|
-
/*
|
|
361
|
-
Return the image alpha maximum. Useful for combining alpha bands. scRGB
|
|
362
|
-
images are 0 - 1 for image data, but the alpha is 0 - 255.
|
|
363
|
-
*/
|
|
364
|
-
double MaximumImageAlpha(VipsInterpretation const interpretation);
|
|
365
|
-
|
|
366
360
|
/*
|
|
367
361
|
Convert RGBA value to another colourspace
|
|
368
362
|
*/
|
package/src/pipeline.cc
CHANGED
|
@@ -1359,7 +1359,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1359
1359
|
// Add file size to info
|
|
1360
1360
|
if (baton->formatOut != "dz" || sharp::IsDzZip(baton->fileOut)) {
|
|
1361
1361
|
try {
|
|
1362
|
-
uint32_t const size = static_cast<uint32_t>(
|
|
1362
|
+
uint32_t const size = static_cast<uint32_t>(
|
|
1363
|
+
std::filesystem::file_size(std::filesystem::u8path(baton->fileOut)));
|
|
1363
1364
|
info.Set("size", size);
|
|
1364
1365
|
} catch (...) {}
|
|
1365
1366
|
}
|
package/src/pipeline.h
CHANGED
|
@@ -384,7 +384,7 @@ struct PipelineBaton {
|
|
|
384
384
|
ensureAlpha(-1.0),
|
|
385
385
|
colourspacePipeline(VIPS_INTERPRETATION_LAST),
|
|
386
386
|
colourspace(VIPS_INTERPRETATION_LAST),
|
|
387
|
-
loop(1),
|
|
387
|
+
loop(-1),
|
|
388
388
|
tileSize(256),
|
|
389
389
|
tileOverlap(0),
|
|
390
390
|
tileContainer(VIPS_FOREIGN_DZ_CONTAINER_FS),
|
package/src/stats.cc
CHANGED
|
@@ -60,7 +60,7 @@ class StatsWorker : public Napi::AsyncWorker {
|
|
|
60
60
|
// Image is not opaque when alpha layer is present and contains a non-mamixa value
|
|
61
61
|
if (image.has_alpha()) {
|
|
62
62
|
double const minAlpha = static_cast<double>(stats.getpoint(STAT_MIN_INDEX, bands).front());
|
|
63
|
-
if (minAlpha !=
|
|
63
|
+
if (minAlpha != vips_interpretation_max_alpha(image.interpretation())) {
|
|
64
64
|
baton->isOpaque = false;
|
|
65
65
|
}
|
|
66
66
|
}
|