From 838a5cffe77c645e7f77b4228a4db26e7f546cf5 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 26 Mar 2018 23:17:17 +0300 Subject: [PATCH] more tests and fixed bug for interpolate4 --- Tests/test_color_lut.py | 21 +++++++++++++++++++++ src/libImaging/ColorLUT.c | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Tests/test_color_lut.py b/Tests/test_color_lut.py index 2da59b115..65b5c5127 100644 --- a/Tests/test_color_lut.py +++ b/Tests/test_color_lut.py @@ -146,6 +146,27 @@ class TestColorLut3DCoreAPI(PillowTestCase): im.im.color_lut_3d('RGB', Image.LINEAR, *self.generate_unit_table(3, (2, 2, 65))))) + def test_units_4channels(self): + g = Image.linear_gradient('L') + im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90), + g.transpose(Image.ROTATE_180)]) + + # Red channel copied to alpha + self.assert_image_equal( + Image.merge('RGBA', (im.split()*2)[:4]), + im._new(im.im.color_lut_3d('RGBA', Image.LINEAR, + *self.generate_unit_table(4, 17)))) + + def test_copy_alpha_channel(self): + g = Image.linear_gradient('L') + im = Image.merge('RGBA', [g, g.transpose(Image.ROTATE_90), + g.transpose(Image.ROTATE_180), + g.transpose(Image.ROTATE_270)]) + + self.assert_image_equal(im, im._new( + im.im.color_lut_3d('RGBA', Image.LINEAR, + *self.generate_unit_table(3, 17)))) + def test_channels_order(self): g = Image.linear_gradient('L') im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90), diff --git a/src/libImaging/ColorLUT.c b/src/libImaging/ColorLUT.c index f9dd91cb8..3f930c3ee 100644 --- a/src/libImaging/ColorLUT.c +++ b/src/libImaging/ColorLUT.c @@ -111,7 +111,7 @@ ImagingColorLUT3D_linear(Imaging imOut, Imaging imIn, int table_channels, INT16 shift1D = (SCALE_MASK & index1D) >> (SCALE_BITS - SHIFT_BITS); INT16 shift2D = (SCALE_MASK & index2D) >> (SCALE_BITS - SHIFT_BITS); INT16 shift3D = (SCALE_MASK & index3D) >> (SCALE_BITS - SHIFT_BITS); - int idx = 3 * table_index3D( + int idx = table_channels * table_index3D( index1D >> SCALE_BITS, index2D >> SCALE_BITS, index3D >> SCALE_BITS, size1D, size1D_2D); INT16 result[4], left[4], right[4];