Skip to content

Commit

Permalink
Add support for miniswhite when using TIFF output
Browse files Browse the repository at this point in the history
  • Loading branch information
dnsbty authored and lovell committed Nov 3, 2023
1 parent 0f24f0f commit 28aa176
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/api-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/search-index.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ const Sharp = function (input, options) {
tiffCompression: 'jpeg',
tiffPredictor: 'horizontal',
tiffPyramid: false,
tiffMiniswhite: false,
tiffBitdepth: 8,
tiffTile: false,
tiffTileHeight: 256,
Expand Down
2 changes: 2 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"Ankur Parihar <[email protected]>",
"Brahim Ait elhaj <[email protected]>",
"Mart Jansink <[email protected]>",
"Lachlan Newman <[email protected]>"
"Lachlan Newman <[email protected]>",
"Dennis Beatty <[email protected]>"
],
"scripts": {
"install": "node install/check",
Expand Down
3 changes: 3 additions & 0 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions src/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ struct PipelineBaton {
VipsForeignTiffPredictor tiffPredictor;
bool tiffPyramid;
int tiffBitdepth;
bool tiffMiniswhite;
bool tiffTile;
int tiffTileHeight;
int tiffTileWidth;
Expand Down Expand Up @@ -335,6 +336,7 @@ struct PipelineBaton {
tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
tiffPyramid(false),
tiffBitdepth(8),
tiffMiniswhite(false),
tiffTile(false),
tiffTileHeight(256),
tiffTileWidth(256),
Expand Down
12 changes: 12 additions & 0 deletions test/unit/tiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down

0 comments on commit 28aa176

Please sign in to comment.