Skip to content

Commit 86fa875

Browse files
authored
composite: transform to compositing space only if necessary (#4547)
After PR #4516, the colourspace operation would enforce the image format, which is undesirable for composite operations. For example, casting a float image back to uchar leads to precision loss.
1 parent 8fb205d commit 86fa875

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

libvips/conversion/composite.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,12 +1396,20 @@ vips_composite_base_build(VipsObject *object)
13961396
: VIPS_INTERPRETATION_sRGB);
13971397
}
13981398

1399-
compositing = (VipsImage **)
1400-
vips_object_local_array(object, n);
1399+
compositing = (VipsImage **) vips_object_local_array(object, n);
14011400
for (int i = 0; i < n; i++)
1402-
if (vips_colourspace(in[i], &compositing[i],
1401+
if (in[i]->Type == composite->compositing_space) {
1402+
/* Already the right type ... just copy the image pointer
1403+
* and add a ref.
1404+
*/
1405+
compositing[i] = in[i];
1406+
g_object_ref(in[i]);
1407+
}
1408+
else {
1409+
if (vips_colourspace(in[i], &compositing[i],
14031410
composite->compositing_space, nullptr))
14041411
return -1;
1412+
}
14051413
in = compositing;
14061414

14071415
/* Check that they all now match in bands. This can fail for some

test/test-suite/test_conversion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def test_composite(self):
438438
comp = base.composite(overlay, "over")
439439

440440
assert_almost_equal_objects(comp(0, 0), [51.8, 52.8, 53.8, 255],
441-
threshold=1)
441+
threshold=0.1)
442442

443443
def test_unpremultiply(self):
444444
for fmt in unsigned_formats + [pyvips.BandFormat.SHORT,

0 commit comments

Comments
 (0)