Ensure TIFF is cast when using float predictor (#2502)

This commit is contained in:
Randy Ridge 2020-12-29 09:29:51 -05:00 committed by Lovell Fuller
parent 98349bde28
commit 0bb8cb9203
3 changed files with 10 additions and 2 deletions

View File

@ -6,6 +6,10 @@ Requires libvips v8.10.5
### v0.27.1 - TBD ### 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. * Add support for Uint8Array and Uint8ClampedArray input.
[#2511](https://github.com/lovell/sharp/pull/2511) [#2511](https://github.com/lovell/sharp/pull/2511)
[@leon](https://github.com/leon) [@leon](https://github.com/leon)

View File

@ -955,6 +955,10 @@ class PipelineWorker : public Napi::AsyncWorker {
sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG); sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
baton->channels = std::min(baton->channels, 3); 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<char*>(baton->fileOut.data()), VImage::option() image.tiffsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
->set("strip", !baton->withMetadata) ->set("strip", !baton->withMetadata)
->set("Q", baton->tiffQuality) ->set("Q", baton->tiffQuality)

View File

@ -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; const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
sharp(fixtures.inputTiffUncompressed) sharp(fixtures.inputTiffUncompressed)
.tiff({ .tiff({
@ -287,7 +287,7 @@ describe('TIFF', function () {
.toFile(fixtures.outputTiff, (err, info) => { .toFile(fixtures.outputTiff, (err, info) => {
if (err) throw err; if (err) throw err;
assert.strictEqual('tiff', info.format); assert.strictEqual('tiff', info.format);
assert(info.size < startSize); assert(info.size > startSize);
rimraf(fixtures.outputTiff, done); rimraf(fixtures.outputTiff, done);
}); });
}); });