mirror of
https://github.com/lovell/sharp.git
synced 2025-07-10 11:00:14 +02:00
Ensure RGBA LZW TIFF info.channel count #2064
This commit is contained in:
parent
1717173f17
commit
a2314c4aa0
@ -9,6 +9,9 @@ Requires libvips v8.9.0.
|
|||||||
* Prevent use of sequentialRead for EXIF-based rotate operation.
|
* Prevent use of sequentialRead for EXIF-based rotate operation.
|
||||||
[#2042](https://github.com/lovell/sharp/issues/2042)
|
[#2042](https://github.com/lovell/sharp/issues/2042)
|
||||||
|
|
||||||
|
* Ensure RGBA LZW TIFF returns correct channel count.
|
||||||
|
[#2064](https://github.com/lovell/sharp/issues/2064)
|
||||||
|
|
||||||
### v0.24.0 - 16<sup>th</sup> January 2020
|
### v0.24.0 - 16<sup>th</sup> January 2020
|
||||||
|
|
||||||
* Drop support for Node.js 8.
|
* Drop support for Node.js 8.
|
||||||
|
@ -764,6 +764,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
// Write TIFF to buffer
|
// Write TIFF to buffer
|
||||||
if (baton->tiffCompression == VIPS_FOREIGN_TIFF_COMPRESSION_JPEG) {
|
if (baton->tiffCompression == VIPS_FOREIGN_TIFF_COMPRESSION_JPEG) {
|
||||||
sharp::AssertImageTypeDimensions(image, ImageType::JPEG);
|
sharp::AssertImageTypeDimensions(image, ImageType::JPEG);
|
||||||
|
baton->channels = std::min(baton->channels, 3);
|
||||||
}
|
}
|
||||||
// Cast pixel values to float, if required
|
// Cast pixel values to float, if required
|
||||||
if (baton->tiffPredictor == VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT) {
|
if (baton->tiffPredictor == VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT) {
|
||||||
@ -786,7 +787,6 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
area->free_fn = nullptr;
|
area->free_fn = nullptr;
|
||||||
vips_area_unref(area);
|
vips_area_unref(area);
|
||||||
baton->formatOut = "tiff";
|
baton->formatOut = "tiff";
|
||||||
baton->channels = std::min(baton->channels, 3);
|
|
||||||
} else if (baton->formatOut == "heif" || (baton->formatOut == "input" && inputImageType == ImageType::HEIF)) {
|
} else if (baton->formatOut == "heif" || (baton->formatOut == "input" && inputImageType == ImageType::HEIF)) {
|
||||||
// Write HEIF to buffer
|
// Write HEIF to buffer
|
||||||
VipsArea *area = VIPS_AREA(image.heifsave_buffer(VImage::option()
|
VipsArea *area = VIPS_AREA(image.heifsave_buffer(VImage::option()
|
||||||
@ -887,6 +887,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
// Write TIFF to file
|
// Write TIFF to file
|
||||||
if (baton->tiffCompression == VIPS_FOREIGN_TIFF_COMPRESSION_JPEG) {
|
if (baton->tiffCompression == VIPS_FOREIGN_TIFF_COMPRESSION_JPEG) {
|
||||||
sharp::AssertImageTypeDimensions(image, ImageType::JPEG);
|
sharp::AssertImageTypeDimensions(image, ImageType::JPEG);
|
||||||
|
baton->channels = std::min(baton->channels, 3);
|
||||||
}
|
}
|
||||||
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)
|
||||||
@ -901,7 +902,6 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("xres", baton->tiffXres)
|
->set("xres", baton->tiffXres)
|
||||||
->set("yres", baton->tiffYres));
|
->set("yres", baton->tiffYres));
|
||||||
baton->formatOut = "tiff";
|
baton->formatOut = "tiff";
|
||||||
baton->channels = std::min(baton->channels, 3);
|
|
||||||
} else if (baton->formatOut == "heif" || (mightMatchInput && isHeif) ||
|
} else if (baton->formatOut == "heif" || (mightMatchInput && isHeif) ||
|
||||||
(willMatchInput && inputImageType == ImageType::HEIF)) {
|
(willMatchInput && inputImageType == ImageType::HEIF)) {
|
||||||
// Write HEIF to file
|
// Write HEIF to file
|
||||||
|
@ -208,11 +208,48 @@ 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.strictEqual(3, info.channels);
|
||||||
assert(info.size < startSize);
|
assert(info.size < startSize);
|
||||||
rimraf(fixtures.outputTiff, done);
|
rimraf(fixtures.outputTiff, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('TIFF LZW RGBA toFile', () =>
|
||||||
|
sharp({
|
||||||
|
create: {
|
||||||
|
width: 1,
|
||||||
|
height: 1,
|
||||||
|
channels: 4,
|
||||||
|
background: 'red'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.tiff({
|
||||||
|
compression: 'lzw'
|
||||||
|
})
|
||||||
|
.toFile(fixtures.outputTiff)
|
||||||
|
.then(info => {
|
||||||
|
assert.strictEqual(4, info.channels);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
it('TIFF LZW RGBA toBuffer', () =>
|
||||||
|
sharp({
|
||||||
|
create: {
|
||||||
|
width: 1,
|
||||||
|
height: 1,
|
||||||
|
channels: 4,
|
||||||
|
background: 'red'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.tiff({
|
||||||
|
compression: 'lzw'
|
||||||
|
})
|
||||||
|
.toBuffer({ resolveWithObject: true })
|
||||||
|
.then(({ info }) => {
|
||||||
|
assert.strictEqual(4, info.channels);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
it('TIFF ccittfax4 compression shrinks b-w test file', function (done) {
|
it('TIFF ccittfax4 compression shrinks b-w test file', function (done) {
|
||||||
const startSize = fs.statSync(fixtures.inputTiff).size;
|
const startSize = fs.statSync(fixtures.inputTiff).size;
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user