Add support for miniswhite when using TIFF output

This commit is contained in:
Dennis Beatty 2023-09-26 14:38:34 +01:00 committed by Lovell Fuller
parent 0f24f0f214
commit 28aa176957
9 changed files with 29 additions and 2 deletions

View File

@ -466,6 +466,7 @@ instead of providing `xres` and `yres` in pixels/mm.
| [options.yres] | <code>number</code> | <code>1.0</code> | vertical resolution in pixels/mm |
| [options.resolutionUnit] | <code>string</code> | <code>&quot;&#x27;inch&#x27;&quot;</code> | resolution unit options: inch, cm |
| [options.bitdepth] | <code>number</code> | <code>8</code> | reduce bitdepth to 1, 2 or 4 bit |
| [options.miniswhite] | <code>boolean</code> | <code>false</code> | write 1-bit images as miniswhite |
**Example**
```js

File diff suppressed because one or more lines are too long

View File

@ -305,6 +305,7 @@ const Sharp = function (input, options) {
tiffCompression: 'jpeg',
tiffPredictor: 'horizontal',
tiffPyramid: false,
tiffMiniswhite: false,
tiffBitdepth: 8,
tiffTile: false,
tiffTileHeight: 256,

2
lib/index.d.ts vendored
View File

@ -1234,6 +1234,8 @@ declare namespace sharp {
yres?: number | undefined;
/** Reduce bitdepth to 1, 2 or 4 bit (optional, default 8) */
bitdepth?: 1 | 2 | 4 | 8 | undefined;
/** Write 1-bit images as miniswhite (optional, default false) */
miniswhite?: boolean | undefined;
/** Resolution unit options: inch, cm (optional, default 'inch') */
resolutionUnit?: 'inch' | 'cm' | undefined;
}

View File

@ -782,6 +782,7 @@ function trySetAnimationOptions (source, target) {
* @param {number} [options.yres=1.0] - vertical resolution in pixels/mm
* @param {string} [options.resolutionUnit='inch'] - resolution unit options: inch, cm
* @param {number} [options.bitdepth=8] - reduce bitdepth to 1, 2 or 4 bit
* @param {boolean} [options.miniswhite=false] - write 1-bit images as miniswhite
* @returns {Sharp}
* @throws {Error} Invalid options
*/
@ -819,6 +820,10 @@ function tiff (options) {
throw is.invalidParameterError('tileHeight', 'integer greater than zero', options.tileHeight);
}
}
// miniswhite
if (is.defined(options.miniswhite)) {
this._setBooleanOption('tiffMiniswhite', options.miniswhite);
}
// pyramid
if (is.defined(options.pyramid)) {
this._setBooleanOption('tiffPyramid', options.pyramid);

View File

@ -86,7 +86,8 @@
"Ankur Parihar <ankur.github@gmail.com>",
"Brahim Ait elhaj <brahima@gmail.com>",
"Mart Jansink <m.jansink@gmail.com>",
"Lachlan Newman <lachnewman007@gmail.com>"
"Lachlan Newman <lachnewman007@gmail.com>",
"Dennis Beatty <dennis@dcbeatty.com>"
],
"scripts": {
"install": "node install/check",

View File

@ -940,6 +940,7 @@ class PipelineWorker : public Napi::AsyncWorker {
->set("Q", baton->tiffQuality)
->set("bitdepth", baton->tiffBitdepth)
->set("compression", baton->tiffCompression)
->set("miniswhite", baton->tiffMiniswhite)
->set("predictor", baton->tiffPredictor)
->set("pyramid", baton->tiffPyramid)
->set("tile", baton->tiffTile)
@ -1136,6 +1137,7 @@ class PipelineWorker : public Napi::AsyncWorker {
->set("Q", baton->tiffQuality)
->set("bitdepth", baton->tiffBitdepth)
->set("compression", baton->tiffCompression)
->set("miniswhite", baton->tiffMiniswhite)
->set("predictor", baton->tiffPredictor)
->set("pyramid", baton->tiffPyramid)
->set("tile", baton->tiffTile)
@ -1647,6 +1649,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
baton->gifProgressive = sharp::AttrAsBool(options, "gifProgressive");
baton->tiffQuality = sharp::AttrAsUint32(options, "tiffQuality");
baton->tiffPyramid = sharp::AttrAsBool(options, "tiffPyramid");
baton->tiffMiniswhite = sharp::AttrAsBool(options, "tiffMiniswhite");
baton->tiffBitdepth = sharp::AttrAsUint32(options, "tiffBitdepth");
baton->tiffTile = sharp::AttrAsBool(options, "tiffTile");
baton->tiffTileWidth = sharp::AttrAsUint32(options, "tiffTileWidth");

View File

@ -169,6 +169,7 @@ struct PipelineBaton {
VipsForeignTiffPredictor tiffPredictor;
bool tiffPyramid;
int tiffBitdepth;
bool tiffMiniswhite;
bool tiffTile;
int tiffTileHeight;
int tiffTileWidth;
@ -335,6 +336,7 @@ struct PipelineBaton {
tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
tiffPyramid(false),
tiffBitdepth(8),
tiffMiniswhite(false),
tiffTile(false),
tiffTileHeight(256),
tiffTileWidth(256),

View File

@ -462,6 +462,18 @@ describe('TIFF', function () {
});
});
it('TIFF miniswhite true value does not throw error', function () {
assert.doesNotThrow(function () {
sharp().tiff({ miniswhite: true });
});
});
it('Invalid TIFF miniswhite value throws error', function () {
assert.throws(function () {
sharp().tiff({ miniswhite: 'true' });
});
});
it('Invalid TIFF tile value throws error', function () {
assert.throws(function () {
sharp().tiff({ tile: 'true' });