mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add support for squashing TIFF output to 1-bit (#783)
This commit is contained in:
BIN
test/fixtures/8bit_depth.tiff
vendored
Normal file
BIN
test/fixtures/8bit_depth.tiff
vendored
Normal file
Binary file not shown.
1
test/fixtures/index.js
vendored
1
test/fixtures/index.js
vendored
@@ -85,6 +85,7 @@ module.exports = {
|
||||
inputTiff: getPath('G31D.TIF'), // http://www.fileformat.info/format/tiff/sample/e6c9a6e5253348f4aef6d17b534360ab/index.htm
|
||||
inputTiffCielab: getPath('cielab-dagams.tiff'), // https://github.com/lovell/sharp/issues/646
|
||||
inputTiffUncompressed: getPath('uncompressed_tiff.tiff'), // https://code.google.com/archive/p/imagetestsuite/wikis/TIFFTestSuite.wiki file: 0c84d07e1b22b76f24cccc70d8788e4a.tif
|
||||
inputTiff8BitDepth: getPath('8bit_depth.tiff'),
|
||||
inputGif: getPath('Crash_test.gif'), // http://upload.wikimedia.org/wikipedia/commons/e/e3/Crash_test.gif
|
||||
inputGifGreyPlusAlpha: getPath('grey-plus-alpha.gif'), // http://i.imgur.com/gZ5jlmE.gif
|
||||
inputSvg: getPath('check.svg'), // http://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg
|
||||
|
||||
@@ -861,6 +861,44 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Not squashing TIFF to a bit depth of 1 should not change the file size', function (done) {
|
||||
const startSize = fs.statSync(fixtures.inputTiff8BitDepth).size;
|
||||
sharp(fixtures.inputTiff8BitDepth)
|
||||
.toColourspace('b-w') // can only squash 1 band uchar images
|
||||
.tiff({
|
||||
squash: false,
|
||||
compression: 'none'
|
||||
})
|
||||
.toFile(fixtures.outputTiff, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('tiff', info.format);
|
||||
assert(info.size === startSize);
|
||||
fs.unlink(fixtures.outputTiff, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('Squashing TIFF to a bit depth of 1 should significantly reduce file size', function (done) {
|
||||
const startSize = fs.statSync(fixtures.inputTiff8BitDepth).size;
|
||||
sharp(fixtures.inputTiff8BitDepth)
|
||||
.toColourspace('b-w') // can only squash 1 band uchar images
|
||||
.tiff({
|
||||
squash: true,
|
||||
compression: 'none'
|
||||
})
|
||||
.toFile(fixtures.outputTiff, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('tiff', info.format);
|
||||
assert(info.size < (startSize / 2));
|
||||
fs.unlink(fixtures.outputTiff, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid TIFF squash value throws error', function () {
|
||||
assert.throws(function () {
|
||||
sharp().tiff({ squash: 'true' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF lzw compression with horizontal predictor shrinks test file', function (done) {
|
||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||
sharp(fixtures.inputTiffUncompressed)
|
||||
|
||||
Reference in New Issue
Block a user