Compare commits

..

2 Commits

Author SHA1 Message Date
Lovell Fuller
04e7f58cea Ensure background metadata can be parsed #4090 2024-11-02 13:03:58 +00:00
Lovell Fuller
3796dd8a87 Expose new libvips/libjxl features (animation, EXIF)
Requires libvips compiled with support for libjxl
2024-10-29 15:04:14 +00:00
12 changed files with 65 additions and 16 deletions

View File

@ -31,7 +31,7 @@ A `Promise` is returned when `callback` is not provided.
- `pagePrimary`: Number of the primary page in a HEIF image
- `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
- `subifds`: Number of Sub Image File Directories in an OME-TIFF image
- `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
- `background`: Default background colour, if present, for PNG (bKGD) and GIF images
- `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
- `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
- `hasProfile`: Boolean indicating the presence of an embedded ICC profile

View File

@ -695,8 +695,6 @@ Requires libvips compiled with support for libjxl.
The prebuilt binaries do not include this - see
[installing a custom libvips](https://sharp.pixelplumbing.com/install#custom-libvips).
Image metadata (EXIF, XMP) is unsupported.
**Throws**:
@ -711,7 +709,9 @@ Image metadata (EXIF, XMP) is unsupported.
| [options.quality] | <code>number</code> | | calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified |
| [options.decodingTier] | <code>number</code> | <code>0</code> | target decode speed tier, between 0 (highest quality) and 4 (lowest quality) |
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
| [options.effort] | <code>number</code> | <code>7</code> | CPU effort, between 3 (fastest) and 9 (slowest) |
| [options.effort] | <code>number</code> | <code>7</code> | CPU effort, between 1 (fastest) and 9 (slowest) |
| [options.loop] | <code>number</code> | <code>0</code> | number of animation iterations, use 0 for infinite animation |
| [options.delay] | <code>number</code> \| <code>Array.&lt;number&gt;</code> | | delay(s) between animation frames (in milliseconds) |

View File

@ -10,6 +10,9 @@ Requires libvips v8.16.0-rc2
* Expose WebP `smartDeblock` output option.
* Ensure `background` metadata can be parsed by `color` package.
[#4090](https://github.com/lovell/sharp/issues/4090)
* TypeScript: Ensure channel counts use the correct range.
[#4197](https://github.com/lovell/sharp/pull/4197)
[@DavidVaness](https://github.com/DavidVaness)

File diff suppressed because one or more lines are too long

4
lib/index.d.ts vendored
View File

@ -1106,8 +1106,8 @@ declare namespace sharp {
tifftagPhotoshop?: Buffer | undefined;
/** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
compression?: 'av1' | 'hevc';
/** Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value */
background?: { r: number; g: number; b: number } | number;
/** Default background colour, if present, for PNG (bKGD) and GIF images */
background?: { r: number; g: number; b: number } | { gray: number };
/** Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide */
levels?: LevelMetadata[] | undefined;
/** Number of Sub Image File Directories in an OME-TIFF image */

View File

@ -443,7 +443,7 @@ function _isStreamInput () {
* - `pagePrimary`: Number of the primary page in a HEIF image
* - `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
* - `subifds`: Number of Sub Image File Directories in an OME-TIFF image
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images
* - `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
* - `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
* - `hasProfile`: Boolean indicating the presence of an embedded ICC profile

View File

@ -1127,8 +1127,6 @@ function heif (options) {
* The prebuilt binaries do not include this - see
* {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
*
* Image metadata (EXIF, XMP) is unsupported.
*
* @since 0.31.3
*
* @param {Object} [options] - output options
@ -1136,7 +1134,9 @@ function heif (options) {
* @param {number} [options.quality] - calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified
* @param {number} [options.decodingTier=0] - target decode speed tier, between 0 (highest quality) and 4 (lowest quality)
* @param {boolean} [options.lossless=false] - use lossless compression
* @param {number} [options.effort=7] - CPU effort, between 3 (fastest) and 9 (slowest)
* @param {number} [options.effort=7] - CPU effort, between 1 (fastest) and 9 (slowest)
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
* @param {number|number[]} [options.delay] - delay(s) between animation frames (in milliseconds)
* @returns {Sharp}
* @throws {Error} Invalid options
*/
@ -1173,13 +1173,14 @@ function jxl (options) {
}
}
if (is.defined(options.effort)) {
if (is.integer(options.effort) && is.inRange(options.effort, 3, 9)) {
if (is.integer(options.effort) && is.inRange(options.effort, 1, 9)) {
this.options.jxlEffort = options.effort;
} else {
throw is.invalidParameterError('effort', 'integer between 3 and 9', options.effort);
throw is.invalidParameterError('effort', 'integer between 1 and 9', options.effort);
}
}
}
trySetAnimationOptions(options, this.options);
return this._updateFormatOut('jxl', options);
}

View File

@ -3,6 +3,7 @@
#include <numeric>
#include <vector>
#include <cmath>
#include <napi.h>
#include <vips/vips8>
@ -226,15 +227,15 @@ class MetadataWorker : public Napi::AsyncWorker {
info.Set("subifds", baton->subifds);
}
if (!baton->background.empty()) {
Napi::Object background = Napi::Object::New(env);
if (baton->background.size() == 3) {
Napi::Object background = Napi::Object::New(env);
background.Set("r", baton->background[0]);
background.Set("g", baton->background[1]);
background.Set("b", baton->background[2]);
info.Set("background", background);
} else {
info.Set("background", baton->background[0]);
background.Set("gray", round(baton->background[0] * 100 / 255));
}
info.Set("background", background);
}
info.Set("hasProfile", baton->hasProfile);
info.Set("hasAlpha", baton->hasAlpha);

BIN
test/fixtures/bgbn4a08.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

BIN
test/fixtures/bggn4a16.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -80,6 +80,8 @@ module.exports = {
inputPngWithGreyAlpha: getPath('grey-8bit-alpha.png'),
inputPngWithOneColor: getPath('2x2_fdcce6.png'),
inputPngWithTransparency16bit: getPath('tbgn2c16.png'), // http://www.schaik.com/pngsuite/tbgn2c16.png
inputPng8BitGreyBackground: getPath('bgbn4a08.png'), // http://www.schaik.com/pngsuite/bgbn4a08.png
inputPng16BitGreyBackground: getPath('bggn4a16.png'), // http://www.schaik.com/pngsuite/bggn4a16.png
inputPng16BitGreyAlpha: getPath('16-bit-grey-alpha.png'), // CC-BY-NC-SA florc http://www.colourlovers.com/pattern/50713/pat
inputPngOverlayLayer0: getPath('alpha-layer-0-background.png'),
inputPngOverlayLayer1: getPath('alpha-layer-1-fill.png'),

View File

@ -201,6 +201,48 @@ describe('Image metadata', function () {
});
});
it('PNG with greyscale bKGD chunk - 8 bit', async () => {
const data = await sharp(fixtures.inputPng8BitGreyBackground).metadata();
assert.deepStrictEqual(data, {
background: {
gray: 0
},
bitsPerSample: 8,
channels: 2,
density: 72,
depth: 'uchar',
format: 'png',
hasAlpha: true,
hasProfile: false,
height: 32,
isPalette: false,
isProgressive: false,
space: 'b-w',
width: 32
});
});
it('PNG with greyscale bKGD chunk - 16 bit', async () => {
const data = await sharp(fixtures.inputPng16BitGreyBackground).metadata();
assert.deepStrictEqual(data, {
background: {
gray: 67
},
bitsPerSample: 16,
channels: 2,
density: 72,
depth: 'ushort',
format: 'png',
hasAlpha: true,
hasProfile: false,
height: 32,
isPalette: false,
isProgressive: false,
space: 'grey16',
width: 32
});
});
it('WebP', function (done) {
sharp(fixtures.inputWebP).metadata(function (err, metadata) {
if (err) throw err;