Skip to content

Commit 4d1f7e0

Browse files
authored
Support composite op with non-sRGB pipeline colourspace (#4412)
1 parent 91f1b58 commit 4d1f7e0

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/pipeline.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,6 @@ class PipelineWorker : public Napi::AsyncWorker {
669669
sharp::ImageType compositeImageType = sharp::ImageType::UNKNOWN;
670670
composite->input->access = access;
671671
std::tie(compositeImage, compositeImageType) = sharp::OpenInput(composite->input);
672-
compositeImage = sharp::EnsureColourspace(compositeImage, baton->colourspacePipeline);
673672

674673
if (composite->input->autoOrient) {
675674
// Respect EXIF Orientation
@@ -734,8 +733,7 @@ class PipelineWorker : public Napi::AsyncWorker {
734733
// gravity was used for extract_area, set it back to its default value of 0
735734
composite->gravity = 0;
736735
}
737-
// Ensure image to composite is sRGB with unpremultiplied alpha
738-
compositeImage = compositeImage.colourspace(VIPS_INTERPRETATION_sRGB);
736+
// Ensure image to composite is with unpremultiplied alpha
739737
compositeImage = sharp::EnsureAlpha(compositeImage, 1);
740738
if (composite->premultiplied) compositeImage = compositeImage.unpremultiply();
741739
// Calculate position
@@ -760,7 +758,12 @@ class PipelineWorker : public Napi::AsyncWorker {
760758
xs.push_back(left);
761759
ys.push_back(top);
762760
}
763-
image = VImage::composite(images, modes, VImage::option()->set("x", xs)->set("y", ys));
761+
image = VImage::composite(images, modes, VImage::option()
762+
->set("compositing_space", baton->colourspacePipeline == VIPS_INTERPRETATION_LAST
763+
? VIPS_INTERPRETATION_sRGB
764+
: baton->colourspacePipeline)
765+
->set("x", xs)
766+
->set("y", ys));
764767
image = sharp::RemoveGifPalette(image);
765768
}
766769

1.67 KB
Loading

test/unit/composite.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ describe('composite', () => {
122122
});
123123
});
124124

125+
it('scrgb pipeline', () => {
126+
const filename = 'composite-red-scrgb.png';
127+
const actual = fixtures.path(`output.${filename}`);
128+
const expected = fixtures.expected(filename);
129+
return sharp({
130+
create: {
131+
width: 32, height: 32, channels: 4, background: red
132+
}
133+
})
134+
.pipelineColourspace('scrgb')
135+
.composite([{
136+
input: fixtures.inputPngWithTransparency16bit,
137+
blend: 'color-burn'
138+
}])
139+
.toFile(actual)
140+
.then(() => {
141+
fixtures.assertMaxColourDistance(actual, expected);
142+
});
143+
});
144+
125145
it('multiple', async () => {
126146
const filename = 'composite-multiple.png';
127147
const actual = fixtures.path(`output.${filename}`);

0 commit comments

Comments
 (0)