mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Ensure background metadata can be parsed #4090
This commit is contained in:
parent
3796dd8a87
commit
04e7f58cea
@ -31,7 +31,7 @@ A `Promise` is returned when `callback` is not provided.
|
|||||||
- `pagePrimary`: Number of the primary page in a HEIF image
|
- `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
|
- `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
|
- `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)
|
- `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
|
- `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
||||||
- `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
- `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
||||||
|
@ -10,6 +10,9 @@ Requires libvips v8.16.0-rc2
|
|||||||
|
|
||||||
* Expose WebP `smartDeblock` output option.
|
* 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.
|
* TypeScript: Ensure channel counts use the correct range.
|
||||||
[#4197](https://github.com/lovell/sharp/pull/4197)
|
[#4197](https://github.com/lovell/sharp/pull/4197)
|
||||||
[@DavidVaness](https://github.com/DavidVaness)
|
[@DavidVaness](https://github.com/DavidVaness)
|
||||||
|
4
lib/index.d.ts
vendored
4
lib/index.d.ts
vendored
@ -1106,8 +1106,8 @@ declare namespace sharp {
|
|||||||
tifftagPhotoshop?: Buffer | undefined;
|
tifftagPhotoshop?: Buffer | undefined;
|
||||||
/** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
|
/** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
|
||||||
compression?: 'av1' | 'hevc';
|
compression?: 'av1' | 'hevc';
|
||||||
/** Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value */
|
/** Default background colour, if present, for PNG (bKGD) and GIF images */
|
||||||
background?: { r: number; g: number; b: number } | number;
|
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 */
|
/** 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;
|
levels?: LevelMetadata[] | undefined;
|
||||||
/** Number of Sub Image File Directories in an OME-TIFF image */
|
/** Number of Sub Image File Directories in an OME-TIFF image */
|
||||||
|
@ -443,7 +443,7 @@ function _isStreamInput () {
|
|||||||
* - `pagePrimary`: Number of the primary page in a HEIF image
|
* - `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
|
* - `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
|
* - `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)
|
* - `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
|
* - `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
||||||
* - `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
* - `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
@ -226,15 +227,15 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
info.Set("subifds", baton->subifds);
|
info.Set("subifds", baton->subifds);
|
||||||
}
|
}
|
||||||
if (!baton->background.empty()) {
|
if (!baton->background.empty()) {
|
||||||
if (baton->background.size() == 3) {
|
|
||||||
Napi::Object background = Napi::Object::New(env);
|
Napi::Object background = Napi::Object::New(env);
|
||||||
|
if (baton->background.size() == 3) {
|
||||||
background.Set("r", baton->background[0]);
|
background.Set("r", baton->background[0]);
|
||||||
background.Set("g", baton->background[1]);
|
background.Set("g", baton->background[1]);
|
||||||
background.Set("b", baton->background[2]);
|
background.Set("b", baton->background[2]);
|
||||||
info.Set("background", background);
|
|
||||||
} else {
|
} 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("hasProfile", baton->hasProfile);
|
||||||
info.Set("hasAlpha", baton->hasAlpha);
|
info.Set("hasAlpha", baton->hasAlpha);
|
||||||
|
BIN
test/fixtures/bgbn4a08.png
vendored
Normal file
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
BIN
test/fixtures/bggn4a16.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
2
test/fixtures/index.js
vendored
2
test/fixtures/index.js
vendored
@ -80,6 +80,8 @@ module.exports = {
|
|||||||
inputPngWithGreyAlpha: getPath('grey-8bit-alpha.png'),
|
inputPngWithGreyAlpha: getPath('grey-8bit-alpha.png'),
|
||||||
inputPngWithOneColor: getPath('2x2_fdcce6.png'),
|
inputPngWithOneColor: getPath('2x2_fdcce6.png'),
|
||||||
inputPngWithTransparency16bit: getPath('tbgn2c16.png'), // http://www.schaik.com/pngsuite/tbgn2c16.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
|
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'),
|
inputPngOverlayLayer0: getPath('alpha-layer-0-background.png'),
|
||||||
inputPngOverlayLayer1: getPath('alpha-layer-1-fill.png'),
|
inputPngOverlayLayer1: getPath('alpha-layer-1-fill.png'),
|
||||||
|
@ -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) {
|
it('WebP', function (done) {
|
||||||
sharp(fixtures.inputWebP).metadata(function (err, metadata) {
|
sharp(fixtures.inputWebP).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user