From 0bb8cb9203e134e77cd0e4dc0bb091da6ff63541 Mon Sep 17 00:00:00 2001 From: Randy Ridge Date: Tue, 29 Dec 2020 09:29:51 -0500 Subject: [PATCH] Ensure TIFF is cast when using float predictor (#2502) --- docs/changelog.md | 4 ++++ src/pipeline.cc | 4 ++++ test/unit/tiff.js | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 4122804b..378a6612 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,6 +6,10 @@ Requires libvips v8.10.5 ### v0.27.1 - TBD +* Ensure TIFF is cast when using float predictor. + [#2502](https://github.com/lovell/sharp/pull/2502) + [@randyridge](https://github.com/randyridge) + * Add support for Uint8Array and Uint8ClampedArray input. [#2511](https://github.com/lovell/sharp/pull/2511) [@leon](https://github.com/leon) diff --git a/src/pipeline.cc b/src/pipeline.cc index 70609396..da4b87f6 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -955,6 +955,10 @@ class PipelineWorker : public Napi::AsyncWorker { sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG); baton->channels = std::min(baton->channels, 3); } + // Cast pixel values to float, if required + if (baton->tiffPredictor == VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT) { + image = image.cast(VIPS_FORMAT_FLOAT); + } image.tiffsave(const_cast(baton->fileOut.data()), VImage::option() ->set("strip", !baton->withMetadata) ->set("Q", baton->tiffQuality) diff --git a/test/unit/tiff.js b/test/unit/tiff.js index 3facb275..7bd21330 100644 --- a/test/unit/tiff.js +++ b/test/unit/tiff.js @@ -277,7 +277,7 @@ describe('TIFF', function () { }); }); - it('TIFF deflate compression with float predictor shrinks test file', function (done) { + it('TIFF deflate compression of integral input with float predictor increases file size', function (done) { const startSize = fs.statSync(fixtures.inputTiffUncompressed).size; sharp(fixtures.inputTiffUncompressed) .tiff({ @@ -287,7 +287,7 @@ describe('TIFF', function () { .toFile(fixtures.outputTiff, (err, info) => { if (err) throw err; assert.strictEqual('tiff', info.format); - assert(info.size < startSize); + assert(info.size > startSize); rimraf(fixtures.outputTiff, done); }); });