mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Add isPalette and bitsPerSample metadata, deprecate paletteBitDepth
This commit is contained in:
parent
6480a94181
commit
3154af776e
@ -22,9 +22,10 @@ A `Promise` is returned when `callback` is not provided.
|
|||||||
- `density`: Number of pixels per inch (DPI), if present
|
- `density`: Number of pixels per inch (DPI), if present
|
||||||
- `chromaSubsampling`: 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
|
- `chromaSubsampling`: 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
|
||||||
- `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
- `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
||||||
|
- `isPalette`: Boolean indicating whether the image is palette-based (GIF, PNG).
|
||||||
|
- `bitsPerSample`: Number of bits per sample for each channel (GIF, PNG, HEIF).
|
||||||
- `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
- `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
||||||
- `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
- `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
||||||
- `paletteBitDepth`: Bit depth of palette-based image (GIF, PNG).
|
|
||||||
- `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
- `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
||||||
- `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
- `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
||||||
- `pagePrimary`: Number of the primary page in a HEIF image
|
- `pagePrimary`: Number of the primary page in a HEIF image
|
||||||
|
@ -6,6 +6,8 @@ Requires libvips v8.16.0-rc2
|
|||||||
|
|
||||||
### v0.33.6 - TBD
|
### v0.33.6 - TBD
|
||||||
|
|
||||||
|
* Add `isPalette` and `bitsPerSample` to metadata, deprecate `paletteBitDepth`.
|
||||||
|
|
||||||
* 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
@ -1076,6 +1076,10 @@ declare namespace sharp {
|
|||||||
chromaSubsampling?: string | undefined;
|
chromaSubsampling?: string | undefined;
|
||||||
/** Boolean indicating whether the image is interlaced using a progressive scan */
|
/** Boolean indicating whether the image is interlaced using a progressive scan */
|
||||||
isProgressive?: boolean | undefined;
|
isProgressive?: boolean | undefined;
|
||||||
|
/** Boolean indicating whether the image is palette-based (GIF, PNG). */
|
||||||
|
isPalette?: boolean | undefined;
|
||||||
|
/** Number of bits per sample for each channel (GIF, PNG). */
|
||||||
|
bitsPerSample?: number | undefined;
|
||||||
/** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */
|
/** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */
|
||||||
pages?: number | undefined;
|
pages?: number | undefined;
|
||||||
/** Number of pixels high each page in a multi-page image will be. */
|
/** Number of pixels high each page in a multi-page image will be. */
|
||||||
|
@ -434,9 +434,10 @@ function _isStreamInput () {
|
|||||||
* - `density`: Number of pixels per inch (DPI), if present
|
* - `density`: Number of pixels per inch (DPI), if present
|
||||||
* - `chromaSubsampling`: 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
|
* - `chromaSubsampling`: 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
|
||||||
* - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
* - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
||||||
|
* - `isPalette`: Boolean indicating whether the image is palette-based (GIF, PNG).
|
||||||
|
* - `bitsPerSample`: Number of bits per sample for each channel (GIF, PNG, HEIF).
|
||||||
* - `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
* - `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
||||||
* - `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
* - `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
||||||
* - `paletteBitDepth`: Bit depth of palette-based image (GIF, PNG).
|
|
||||||
* - `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
* - `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
||||||
* - `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
* - `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
||||||
* - `pagePrimary`: Number of the primary page in a HEIF image
|
* - `pagePrimary`: Number of the primary page in a HEIF image
|
||||||
|
@ -47,8 +47,11 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
if (image.get_typeof("interlaced") == G_TYPE_INT) {
|
if (image.get_typeof("interlaced") == G_TYPE_INT) {
|
||||||
baton->isProgressive = image.get_int("interlaced") == 1;
|
baton->isProgressive = image.get_int("interlaced") == 1;
|
||||||
}
|
}
|
||||||
if (image.get_typeof("palette-bit-depth") == G_TYPE_INT) {
|
if (image.get_typeof(VIPS_META_PALETTE) == G_TYPE_INT) {
|
||||||
baton->paletteBitDepth = image.get_int("palette-bit-depth");
|
baton->isPalette = image.get_int(VIPS_META_PALETTE);
|
||||||
|
}
|
||||||
|
if (image.get_typeof(VIPS_META_BITS_PER_SAMPLE) == G_TYPE_INT) {
|
||||||
|
baton->bitsPerSample = image.get_int(VIPS_META_BITS_PER_SAMPLE);
|
||||||
}
|
}
|
||||||
if (image.get_typeof(VIPS_META_N_PAGES) == G_TYPE_INT) {
|
if (image.get_typeof(VIPS_META_N_PAGES) == G_TYPE_INT) {
|
||||||
baton->pages = image.get_int(VIPS_META_N_PAGES);
|
baton->pages = image.get_int(VIPS_META_N_PAGES);
|
||||||
@ -171,8 +174,13 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
info.Set("chromaSubsampling", baton->chromaSubsampling);
|
info.Set("chromaSubsampling", baton->chromaSubsampling);
|
||||||
}
|
}
|
||||||
info.Set("isProgressive", baton->isProgressive);
|
info.Set("isProgressive", baton->isProgressive);
|
||||||
if (baton->paletteBitDepth > 0) {
|
info.Set("isPalette", baton->isPalette);
|
||||||
info.Set("paletteBitDepth", baton->paletteBitDepth);
|
if (baton->bitsPerSample > 0) {
|
||||||
|
info.Set("bitsPerSample", baton->bitsPerSample);
|
||||||
|
if (baton->isPalette) {
|
||||||
|
// Deprecated, remove with libvips 8.17.0
|
||||||
|
info.Set("paletteBitDepth", baton->bitsPerSample);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (baton->pages > 0) {
|
if (baton->pages > 0) {
|
||||||
info.Set("pages", baton->pages);
|
info.Set("pages", baton->pages);
|
||||||
|
@ -24,7 +24,8 @@ struct MetadataBaton {
|
|||||||
int density;
|
int density;
|
||||||
std::string chromaSubsampling;
|
std::string chromaSubsampling;
|
||||||
bool isProgressive;
|
bool isProgressive;
|
||||||
int paletteBitDepth;
|
bool isPalette;
|
||||||
|
int bitsPerSample;
|
||||||
int pages;
|
int pages;
|
||||||
int pageHeight;
|
int pageHeight;
|
||||||
int loop;
|
int loop;
|
||||||
@ -59,7 +60,8 @@ struct MetadataBaton {
|
|||||||
channels(0),
|
channels(0),
|
||||||
density(0),
|
density(0),
|
||||||
isProgressive(false),
|
isProgressive(false),
|
||||||
paletteBitDepth(0),
|
isPalette(false),
|
||||||
|
bitsPerSample(0),
|
||||||
pages(0),
|
pages(0),
|
||||||
pageHeight(0),
|
pageHeight(0),
|
||||||
loop(-1),
|
loop(-1),
|
||||||
|
@ -34,6 +34,7 @@ describe('AVIF', () => {
|
|||||||
// Math.round(13.40625) = 13
|
// Math.round(13.40625) = 13
|
||||||
height: 13,
|
height: 13,
|
||||||
isProgressive: false,
|
isProgressive: false,
|
||||||
|
isPalette: false,
|
||||||
space: 'srgb',
|
space: 'srgb',
|
||||||
width: 32
|
width: 32
|
||||||
});
|
});
|
||||||
@ -55,6 +56,8 @@ describe('AVIF', () => {
|
|||||||
hasProfile: false,
|
hasProfile: false,
|
||||||
height: 26,
|
height: 26,
|
||||||
isProgressive: false,
|
isProgressive: false,
|
||||||
|
isPalette: false,
|
||||||
|
bitsPerSample: 8,
|
||||||
pagePrimary: 0,
|
pagePrimary: 0,
|
||||||
pages: 1,
|
pages: 1,
|
||||||
space: 'srgb',
|
space: 'srgb',
|
||||||
@ -77,6 +80,8 @@ describe('AVIF', () => {
|
|||||||
hasProfile: false,
|
hasProfile: false,
|
||||||
height: 13,
|
height: 13,
|
||||||
isProgressive: false,
|
isProgressive: false,
|
||||||
|
isPalette: false,
|
||||||
|
bitsPerSample: 8,
|
||||||
pagePrimary: 0,
|
pagePrimary: 0,
|
||||||
pages: 1,
|
pages: 1,
|
||||||
space: 'srgb',
|
space: 'srgb',
|
||||||
@ -100,6 +105,8 @@ describe('AVIF', () => {
|
|||||||
hasProfile: false,
|
hasProfile: false,
|
||||||
height: 300,
|
height: 300,
|
||||||
isProgressive: false,
|
isProgressive: false,
|
||||||
|
isPalette: false,
|
||||||
|
bitsPerSample: 8,
|
||||||
pagePrimary: 0,
|
pagePrimary: 0,
|
||||||
pages: 1,
|
pages: 1,
|
||||||
space: 'srgb',
|
space: 'srgb',
|
||||||
@ -124,6 +131,8 @@ describe('AVIF', () => {
|
|||||||
hasProfile: false,
|
hasProfile: false,
|
||||||
height: 26,
|
height: 26,
|
||||||
isProgressive: false,
|
isProgressive: false,
|
||||||
|
isPalette: false,
|
||||||
|
bitsPerSample: 8,
|
||||||
pagePrimary: 0,
|
pagePrimary: 0,
|
||||||
pages: 1,
|
pages: 1,
|
||||||
space: 'srgb',
|
space: 'srgb',
|
||||||
|
@ -878,6 +878,8 @@ describe('Image metadata', function () {
|
|||||||
channels: 3,
|
channels: 3,
|
||||||
depth: 'uchar',
|
depth: 'uchar',
|
||||||
isProgressive: false,
|
isProgressive: false,
|
||||||
|
isPalette: false,
|
||||||
|
bitsPerSample: 8,
|
||||||
pages: 1,
|
pages: 1,
|
||||||
pagePrimary: 0,
|
pagePrimary: 0,
|
||||||
compression: 'av1',
|
compression: 'av1',
|
||||||
|
@ -146,6 +146,8 @@ describe('PNG', function () {
|
|||||||
density: 72,
|
density: 72,
|
||||||
depth: 'uchar',
|
depth: 'uchar',
|
||||||
isProgressive: false,
|
isProgressive: false,
|
||||||
|
isPalette: true,
|
||||||
|
bitsPerSample: 8,
|
||||||
paletteBitDepth: 8,
|
paletteBitDepth: 8,
|
||||||
hasProfile: false,
|
hasProfile: false,
|
||||||
hasAlpha: false
|
hasAlpha: false
|
||||||
@ -218,8 +220,10 @@ describe('PNG', function () {
|
|||||||
.png({ colours: 2, palette: false })
|
.png({ colours: 2, palette: false })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
|
|
||||||
const { channels, paletteBitDepth, size, space } = await sharp(data).metadata();
|
const { channels, isPalette, bitsPerSample, paletteBitDepth, size, space } = await sharp(data).metadata();
|
||||||
assert.strictEqual(channels, 1);
|
assert.strictEqual(channels, 1);
|
||||||
|
assert.strictEqual(isPalette, false);
|
||||||
|
assert.strictEqual(bitsPerSample, 1);
|
||||||
assert.strictEqual(paletteBitDepth, undefined);
|
assert.strictEqual(paletteBitDepth, undefined);
|
||||||
assert.strictEqual(size, 89);
|
assert.strictEqual(size, 89);
|
||||||
assert.strictEqual(space, 'b-w');
|
assert.strictEqual(space, 'b-w');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user