{
    "file_diffs": [
        {
            "old_file_content": "from __future__ import division\nfrom helper import unittest, PillowTestCase\n\nfrom PIL import Image, ImageFilter\n\n\nclass TestColorLut3DCoreAPI(PillowTestCase):\n    def generate_unit_table(self, channels, size):\n        if isinstance(size, tuple):\n            size1D, size2D, size3D = size\n        else:\n            size1D, size2D, size3D = (size, size, size)\n\n        table = [\n            [\n                r / float(size1D-1) if size1D != 1 else 0,\n                g / float(size2D-1) if size2D != 1 else 0,\n                b / float(size3D-1) if size3D != 1 else 0,\n                r / float(size1D-1) if size1D != 1 else 0,\n                g / float(size2D-1) if size2D != 1 else 0,\n            ][:channels]\n            for b in range(size3D)\n                for g in range(size2D)\n                    for r in range(size1D)\n        ]\n        return (\n            channels, size1D, size2D, size3D,\n            [item for sublist in table for item in sublist])\n\n    def test_wrong_args(self):\n        im = Image.new('RGB', (10, 10), 0)\n\n        with self.assertRaisesRegexp(ValueError, \"filter\"):\n            im.im.color_lut_3d('RGB', Image.CUBIC,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"image mode\"):\n            im.im.color_lut_3d('wrong', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"table_channels\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(5, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"table_channels\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(1, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"table_channels\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(2, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"Table size\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(3, (1, 3, 3)))\n\n        with self.assertRaisesRegexp(ValueError, \"Table size\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(3, (66, 3, 3)))\n\n        with self.assertRaisesRegexp(ValueError, r\"size1D \\* size2D \\* size3D\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2, [0, 0, 0] * 7)\n\n        with self.assertRaisesRegexp(ValueError, r\"size1D \\* size2D \\* size3D\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2, [0, 0, 0] * 9)\n\n    def test_correct_args(self):\n        im = Image.new('RGB', (10, 10), 0)\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, 3))\n\n        im.im.color_lut_3d('CMYK', Image.LINEAR,\n            *self.generate_unit_table(4, 3))\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, (2, 3, 3)))\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, (65, 3, 3)))\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, (3, 65, 3)))\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, (3, 3, 65)))\n\n    def test_wrong_mode(self):\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('L', (10, 10), 0)\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('RGB', (10, 10), 0)\n            im.im.color_lut_3d('L', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('L', (10, 10), 0)\n            im.im.color_lut_3d('L', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('RGB', (10, 10), 0)\n            im.im.color_lut_3d('RGBA', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('RGB', (10, 10), 0)\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(4, 3))\n\n    def test_correct_mode(self):\n        im = Image.new('RGBA', (10, 10), 0)\n        im.im.color_lut_3d('RGBA', Image.LINEAR,\n            *self.generate_unit_table(3, 3))\n\n        im = Image.new('RGBA', (10, 10), 0)\n        im.im.color_lut_3d('RGBA', Image.LINEAR,\n            *self.generate_unit_table(4, 3))\n\n        im = Image.new('RGB', (10, 10), 0)\n        im.im.color_lut_3d('HSV', Image.LINEAR,\n            *self.generate_unit_table(3, 3))\n\n        im = Image.new('RGB', (10, 10), 0)\n        im.im.color_lut_3d('RGBA', Image.LINEAR,\n            *self.generate_unit_table(4, 3))\n\n    def test_units(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n\n        # Fast test with small cubes\n        for size in [2, 3, 5, 7, 11, 16, 17]:\n            self.assert_image_equal(im, im._new(\n                im.im.color_lut_3d('RGB', Image.LINEAR,\n                    *self.generate_unit_table(3, size))))\n\n        # Not so fast\n        self.assert_image_equal(im, im._new(\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(3, (2, 2, 65)))))\n\n    def test_units_4channels(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n\n        # Red channel copied to alpha\n        self.assert_image_equal(\n            Image.merge('RGBA', (im.split()*2)[:4]),\n            im._new(im.im.color_lut_3d('RGBA', Image.LINEAR,\n                *self.generate_unit_table(4, 17))))\n\n    def test_copy_alpha_channel(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGBA', [g, g.transpose(Image.ROTATE_90),\n                                  g.transpose(Image.ROTATE_180),\n                                  g.transpose(Image.ROTATE_270)])\n\n        self.assert_image_equal(im, im._new(\n            im.im.color_lut_3d('RGBA', Image.LINEAR,\n                *self.generate_unit_table(3, 17))))\n\n    def test_channels_order(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n\n        # Reverse channels by splitting and using table\n        self.assert_image_equal(\n            Image.merge('RGB', im.split()[::-1]),\n            im._new(im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2, [\n                    0, 0, 0,  0, 0, 1,\n                    0, 1, 0,  0, 1, 1,\n\n                    1, 0, 0,  1, 0, 1,\n                    1, 1, 0,  1, 1, 1,\n                ])))\n\n    def test_overflow(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n\n        transformed = im._new(im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2,\n                [\n                    -1, -1, -1,   2, -1, -1,\n                    -1,  2, -1,   2,  2, -1,\n\n                    -1, -1,  2,   2, -1,  2,\n                    -1,  2,  2,   2,  2,  2,\n                ])).load()\n        self.assertEqual(transformed[0, 0], (0, 0, 255))\n        self.assertEqual(transformed[50, 50], (0, 0, 255))\n        self.assertEqual(transformed[255, 0], (0, 255, 255))\n        self.assertEqual(transformed[205, 50], (0, 255, 255))\n        self.assertEqual(transformed[0, 255], (255, 0, 0))\n        self.assertEqual(transformed[50, 205], (255, 0, 0))\n        self.assertEqual(transformed[255, 255], (255, 255, 0))\n        self.assertEqual(transformed[205, 205], (255, 255, 0))\n\n        transformed = im._new(im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2,\n                [\n                    -3, -3, -3,   5, -3, -3,\n                    -3,  5, -3,   5,  5, -3,\n\n                    -3, -3,  5,   5, -3,  5,\n                    -3,  5,  5,   5,  5,  5,\n                ])).load()\n        self.assertEqual(transformed[0, 0], (0, 0, 255))\n        self.assertEqual(transformed[50, 50], (0, 0, 255))\n        self.assertEqual(transformed[255, 0], (0, 255, 255))\n        self.assertEqual(transformed[205, 50], (0, 255, 255))\n        self.assertEqual(transformed[0, 255], (255, 0, 0))\n        self.assertEqual(transformed[50, 205], (255, 0, 0))\n        self.assertEqual(transformed[255, 255], (255, 255, 0))\n        self.assertEqual(transformed[205, 205], (255, 255, 0))\n\n\nclass TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"LUT_3D_SIZE 2 3 4\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])\n\n\nif __name__ == '__main__':\n    unittest.main()\n",
            "new_file_content": "from __future__ import division\nfrom tempfile import NamedTemporaryFile\nfrom helper import unittest, PillowTestCase\n\nfrom PIL import Image, ImageFilter\n\n\nclass TestColorLut3DCoreAPI(PillowTestCase):\n    def generate_unit_table(self, channels, size):\n        if isinstance(size, tuple):\n            size1D, size2D, size3D = size\n        else:\n            size1D, size2D, size3D = (size, size, size)\n\n        table = [\n            [\n                r / float(size1D-1) if size1D != 1 else 0,\n                g / float(size2D-1) if size2D != 1 else 0,\n                b / float(size3D-1) if size3D != 1 else 0,\n                r / float(size1D-1) if size1D != 1 else 0,\n                g / float(size2D-1) if size2D != 1 else 0,\n            ][:channels]\n            for b in range(size3D)\n                for g in range(size2D)\n                    for r in range(size1D)\n        ]\n        return (\n            channels, size1D, size2D, size3D,\n            [item for sublist in table for item in sublist])\n\n    def test_wrong_args(self):\n        im = Image.new('RGB', (10, 10), 0)\n\n        with self.assertRaisesRegexp(ValueError, \"filter\"):\n            im.im.color_lut_3d('RGB', Image.CUBIC,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"image mode\"):\n            im.im.color_lut_3d('wrong', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"table_channels\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(5, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"table_channels\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(1, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"table_channels\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(2, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"Table size\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(3, (1, 3, 3)))\n\n        with self.assertRaisesRegexp(ValueError, \"Table size\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(3, (66, 3, 3)))\n\n        with self.assertRaisesRegexp(ValueError, r\"size1D \\* size2D \\* size3D\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2, [0, 0, 0] * 7)\n\n        with self.assertRaisesRegexp(ValueError, r\"size1D \\* size2D \\* size3D\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2, [0, 0, 0] * 9)\n\n    def test_correct_args(self):\n        im = Image.new('RGB', (10, 10), 0)\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, 3))\n\n        im.im.color_lut_3d('CMYK', Image.LINEAR,\n            *self.generate_unit_table(4, 3))\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, (2, 3, 3)))\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, (65, 3, 3)))\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, (3, 65, 3)))\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, (3, 3, 65)))\n\n    def test_wrong_mode(self):\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('L', (10, 10), 0)\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('RGB', (10, 10), 0)\n            im.im.color_lut_3d('L', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('L', (10, 10), 0)\n            im.im.color_lut_3d('L', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('RGB', (10, 10), 0)\n            im.im.color_lut_3d('RGBA', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('RGB', (10, 10), 0)\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(4, 3))\n\n    def test_correct_mode(self):\n        im = Image.new('RGBA', (10, 10), 0)\n        im.im.color_lut_3d('RGBA', Image.LINEAR,\n            *self.generate_unit_table(3, 3))\n\n        im = Image.new('RGBA', (10, 10), 0)\n        im.im.color_lut_3d('RGBA', Image.LINEAR,\n            *self.generate_unit_table(4, 3))\n\n        im = Image.new('RGB', (10, 10), 0)\n        im.im.color_lut_3d('HSV', Image.LINEAR,\n            *self.generate_unit_table(3, 3))\n\n        im = Image.new('RGB', (10, 10), 0)\n        im.im.color_lut_3d('RGBA', Image.LINEAR,\n            *self.generate_unit_table(4, 3))\n\n    def test_units(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n\n        # Fast test with small cubes\n        for size in [2, 3, 5, 7, 11, 16, 17]:\n            self.assert_image_equal(im, im._new(\n                im.im.color_lut_3d('RGB', Image.LINEAR,\n                    *self.generate_unit_table(3, size))))\n\n        # Not so fast\n        self.assert_image_equal(im, im._new(\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(3, (2, 2, 65)))))\n\n    def test_units_4channels(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n\n        # Red channel copied to alpha\n        self.assert_image_equal(\n            Image.merge('RGBA', (im.split()*2)[:4]),\n            im._new(im.im.color_lut_3d('RGBA', Image.LINEAR,\n                *self.generate_unit_table(4, 17))))\n\n    def test_copy_alpha_channel(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGBA', [g, g.transpose(Image.ROTATE_90),\n                                  g.transpose(Image.ROTATE_180),\n                                  g.transpose(Image.ROTATE_270)])\n\n        self.assert_image_equal(im, im._new(\n            im.im.color_lut_3d('RGBA', Image.LINEAR,\n                *self.generate_unit_table(3, 17))))\n\n    def test_channels_order(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n\n        # Reverse channels by splitting and using table\n        self.assert_image_equal(\n            Image.merge('RGB', im.split()[::-1]),\n            im._new(im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2, [\n                    0, 0, 0,  0, 0, 1,\n                    0, 1, 0,  0, 1, 1,\n\n                    1, 0, 0,  1, 0, 1,\n                    1, 1, 0,  1, 1, 1,\n                ])))\n\n    def test_overflow(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n\n        transformed = im._new(im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2,\n                [\n                    -1, -1, -1,   2, -1, -1,\n                    -1,  2, -1,   2,  2, -1,\n\n                    -1, -1,  2,   2, -1,  2,\n                    -1,  2,  2,   2,  2,  2,\n                ])).load()\n        self.assertEqual(transformed[0, 0], (0, 0, 255))\n        self.assertEqual(transformed[50, 50], (0, 0, 255))\n        self.assertEqual(transformed[255, 0], (0, 255, 255))\n        self.assertEqual(transformed[205, 50], (0, 255, 255))\n        self.assertEqual(transformed[0, 255], (255, 0, 0))\n        self.assertEqual(transformed[50, 205], (255, 0, 0))\n        self.assertEqual(transformed[255, 255], (255, 255, 0))\n        self.assertEqual(transformed[205, 205], (255, 255, 0))\n\n        transformed = im._new(im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2,\n                [\n                    -3, -3, -3,   5, -3, -3,\n                    -3,  5, -3,   5,  5, -3,\n\n                    -3, -3,  5,   5, -3,  5,\n                    -3,  5,  5,   5,  5,  5,\n                ])).load()\n        self.assertEqual(transformed[0, 0], (0, 0, 255))\n        self.assertEqual(transformed[50, 50], (0, 0, 255))\n        self.assertEqual(transformed[255, 0], (0, 255, 255))\n        self.assertEqual(transformed[205, 50], (0, 255, 255))\n        self.assertEqual(transformed[0, 255], (255, 0, 0))\n        self.assertEqual(transformed[50, 205], (255, 0, 0))\n        self.assertEqual(transformed[255, 255], (255, 255, 0))\n        self.assertEqual(transformed[205, 205], (255, 255, 0))\n\n\nclass TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"  LUT_3D_SIZE 2 3 4\",\n            \" SKIP THIS\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])\n\n    def test_from_cube_file_errors(self):\n        with self.assertRaisesRegexp(ValueError, \"No size found\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'TITLE \"LUT name from file\"',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"number of colors on line 4\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031 1\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"Not a number on line 3\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0  green 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n    def test_from_cube_file_filename(self):\n        with NamedTemporaryFile() as f:\n            f.write(\n                \"LUT_3D_SIZE 2\\n\"\n                \"\\n\"\n                \"0    0 0.031\\n\"\n                \"0.96 0 0.031\\n\"\n                \"0    1 0.031\\n\"\n                \"0.96 1 0.031\\n\"\n                \"0    0 0.931\\n\"\n                \"0.96 0 0.931\\n\"\n                \"0    1 0.931\\n\"\n                \"0.96 1 0.931\\n\"\n            )\n            f.flush()\n            lut = ImageFilter.Color3DLUT.from_cube_file(f.name)\n            self.assertEqual(tuple(lut.size), (2, 2, 2))\n            self.assertEqual(lut.name, \"Color 3D LUT\")\n            self.assertEqual(lut.table[:12], [\n                0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n\nif __name__ == '__main__':\n    unittest.main()\n",
            "header": {
                "file": {
                    "path": "Tests/test_color_lut.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "6d1cb2373",
                "new_commit_hash": "96050c6fb",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/Tests/test_color_lut.py"
            },
            "plus_file": {
                "path": "b/Tests/test_color_lut.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 1,
                            "length": 4
                        },
                        "new_range": {
                            "start": 1,
                            "length": 5
                        },
                        "section": ""
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "from __future__ import division",
                                "type": "context"
                            },
                            {
                                "content": "from tempfile import NamedTemporaryFile",
                                "type": "added"
                            },
                            {
                                "content": "from helper import unittest, PillowTestCase",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "from PIL import Image, ImageFilter",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [],
                    "added_entities": [
                        {
                            "file_name": "Tests/test_color_lut.py",
                            "type": "statement",
                            "name": "",
                            "content": "from tempfile import NamedTemporaryFile",
                            "ast_type_str": "ImportFrom",
                            "start_lineno": 2,
                            "end_lineno": 2,
                            "parent": null
                        }
                    ],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 228,
                            "length": 10
                        },
                        "new_range": {
                            "start": 229,
                            "length": 10
                        },
                        "section": "class TestColorLut3DCoreAPI(PillowTestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "class TestColorLut3DFilter(PillowTestCase):",
                                "type": "context"
                            },
                            {
                                "content": "    def test_wrong_args(self):",
                                "type": "context"
                            },
                            {
                                "content": "        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):",
                                "type": "deleted"
                            },
                            {
                                "content": "        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):",
                                "type": "added"
                            },
                            {
                                "content": "            ImageFilter.Color3DLUT(\"small\", [1])",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):",
                                "type": "deleted"
                            },
                            {
                                "content": "        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):",
                                "type": "added"
                            },
                            {
                                "content": "            ImageFilter.Color3DLUT((11, 11), [1])",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Tests/test_color_lut.py",
                            "type": "method",
                            "name": "TestColorLut3DFilter.test_wrong_args",
                            "content": "class TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"LUT_3D_SIZE 2 3 4\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 230,
                            "end_lineno": 253,
                            "parent": {
                                "file_name": "Tests/test_color_lut.py",
                                "type": "class",
                                "name": "TestColorLut3DFilter",
                                "content": "class TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"LUT_3D_SIZE 2 3 4\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 229,
                                "end_lineno": 336,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "Tests/test_color_lut.py",
                            "type": "class",
                            "name": "TestColorLut3DFilter",
                            "content": "class TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"LUT_3D_SIZE 2 3 4\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 229,
                            "end_lineno": 336,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 316,
                            "length": 7
                        },
                        "new_range": {
                            "start": 317,
                            "length": 8
                        },
                        "section": "class TestColorLut3DFilter(PillowTestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        lut = ImageFilter.Color3DLUT.from_cube_file([",
                                "type": "context"
                            },
                            {
                                "content": "            \" # Comment\",",
                                "type": "context"
                            },
                            {
                                "content": "            'TITLE \"LUT name from file\"',",
                                "type": "context"
                            },
                            {
                                "content": "            \"LUT_3D_SIZE 2 3 4\",",
                                "type": "deleted"
                            },
                            {
                                "content": "            \"  LUT_3D_SIZE 2 3 4\",",
                                "type": "added"
                            },
                            {
                                "content": "            \" SKIP THIS\",",
                                "type": "added"
                            },
                            {
                                "content": "            \" # Comment\",",
                                "type": "context"
                            },
                            {
                                "content": "            \"CHANNELS 4\",",
                                "type": "context"
                            },
                            {
                                "content": "            \"\",",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Tests/test_color_lut.py",
                            "type": "class",
                            "name": "TestColorLut3DFilter",
                            "content": "class TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"LUT_3D_SIZE 2 3 4\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 229,
                            "end_lineno": 336,
                            "parent": null
                        },
                        {
                            "file_name": "Tests/test_color_lut.py",
                            "type": "method",
                            "name": "TestColorLut3DFilter.test_from_cube_file_parser",
                            "content": "class TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"LUT_3D_SIZE 2 3 4\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 315,
                            "end_lineno": 336,
                            "parent": {
                                "file_name": "Tests/test_color_lut.py",
                                "type": "class",
                                "name": "TestColorLut3DFilter",
                                "content": "class TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"LUT_3D_SIZE 2 3 4\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 229,
                                "end_lineno": 336,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 335,
                            "length": 6
                        },
                        "new_range": {
                            "start": 337,
                            "length": 55
                        },
                        "section": "class TestColorLut3DFilter(PillowTestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        self.assertEqual(lut.table[:12], [",
                                "type": "context"
                            },
                            {
                                "content": "            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def test_from_cube_file_errors(self):",
                                "type": "added"
                            },
                            {
                                "content": "        with self.assertRaisesRegexp(ValueError, \"No size found\"):",
                                "type": "added"
                            },
                            {
                                "content": "            lut = ImageFilter.Color3DLUT.from_cube_file([",
                                "type": "added"
                            },
                            {
                                "content": "                'TITLE \"LUT name from file\"',",
                                "type": "added"
                            },
                            {
                                "content": "                \"\",",
                                "type": "added"
                            },
                            {
                                "content": "            ] + [",
                                "type": "added"
                            },
                            {
                                "content": "                \"0    0 0.031\",",
                                "type": "added"
                            },
                            {
                                "content": "                \"0.96 0 0.031\",",
                                "type": "added"
                            },
                            {
                                "content": "            ] * 3)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "        with self.assertRaisesRegexp(ValueError, \"number of colors on line 4\"):",
                                "type": "added"
                            },
                            {
                                "content": "            lut = ImageFilter.Color3DLUT.from_cube_file([",
                                "type": "added"
                            },
                            {
                                "content": "                'LUT_3D_SIZE 2',",
                                "type": "added"
                            },
                            {
                                "content": "                \"\",",
                                "type": "added"
                            },
                            {
                                "content": "            ] + [",
                                "type": "added"
                            },
                            {
                                "content": "                \"0    0 0.031\",",
                                "type": "added"
                            },
                            {
                                "content": "                \"0.96 0 0.031 1\",",
                                "type": "added"
                            },
                            {
                                "content": "            ] * 3)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "        with self.assertRaisesRegexp(ValueError, \"Not a number on line 3\"):",
                                "type": "added"
                            },
                            {
                                "content": "            lut = ImageFilter.Color3DLUT.from_cube_file([",
                                "type": "added"
                            },
                            {
                                "content": "                'LUT_3D_SIZE 2',",
                                "type": "added"
                            },
                            {
                                "content": "                \"\",",
                                "type": "added"
                            },
                            {
                                "content": "            ] + [",
                                "type": "added"
                            },
                            {
                                "content": "                \"0  green 0.031\",",
                                "type": "added"
                            },
                            {
                                "content": "                \"0.96 0 0.031\",",
                                "type": "added"
                            },
                            {
                                "content": "            ] * 3)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "    def test_from_cube_file_filename(self):",
                                "type": "added"
                            },
                            {
                                "content": "        with NamedTemporaryFile() as f:",
                                "type": "added"
                            },
                            {
                                "content": "            f.write(",
                                "type": "added"
                            },
                            {
                                "content": "                \"LUT_3D_SIZE 2\\n\"",
                                "type": "added"
                            },
                            {
                                "content": "                \"\\n\"",
                                "type": "added"
                            },
                            {
                                "content": "                \"0    0 0.031\\n\"",
                                "type": "added"
                            },
                            {
                                "content": "                \"0.96 0 0.031\\n\"",
                                "type": "added"
                            },
                            {
                                "content": "                \"0    1 0.031\\n\"",
                                "type": "added"
                            },
                            {
                                "content": "                \"0.96 1 0.031\\n\"",
                                "type": "added"
                            },
                            {
                                "content": "                \"0    0 0.931\\n\"",
                                "type": "added"
                            },
                            {
                                "content": "                \"0.96 0 0.931\\n\"",
                                "type": "added"
                            },
                            {
                                "content": "                \"0    1 0.931\\n\"",
                                "type": "added"
                            },
                            {
                                "content": "                \"0.96 1 0.931\\n\"",
                                "type": "added"
                            },
                            {
                                "content": "            )",
                                "type": "added"
                            },
                            {
                                "content": "            f.flush()",
                                "type": "added"
                            },
                            {
                                "content": "            lut = ImageFilter.Color3DLUT.from_cube_file(f.name)",
                                "type": "added"
                            },
                            {
                                "content": "            self.assertEqual(tuple(lut.size), (2, 2, 2))",
                                "type": "added"
                            },
                            {
                                "content": "            self.assertEqual(lut.name, \"Color 3D LUT\")",
                                "type": "added"
                            },
                            {
                                "content": "            self.assertEqual(lut.table[:12], [",
                                "type": "added"
                            },
                            {
                                "content": "                0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "if __name__ == '__main__':",
                                "type": "context"
                            },
                            {
                                "content": "    unittest.main()",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Tests/test_color_lut.py",
                            "type": "class",
                            "name": "TestColorLut3DFilter",
                            "content": "class TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"  LUT_3D_SIZE 2 3 4\",\n            \" SKIP THIS\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])\n\n    def test_from_cube_file_errors(self):\n        with self.assertRaisesRegexp(ValueError, \"No size found\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'TITLE \"LUT name from file\"',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"number of colors on line 4\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031 1\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"Not a number on line 3\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0  green 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n    def test_from_cube_file_filename(self):\n        with NamedTemporaryFile() as f:\n            f.write(\n                \"LUT_3D_SIZE 2\\n\"\n                \"\\n\"\n                \"0    0 0.031\\n\"\n                \"0.96 0 0.031\\n\"\n                \"0    1 0.031\\n\"\n                \"0.96 1 0.031\\n\"\n                \"0    0 0.931\\n\"\n                \"0.96 0 0.931\\n\"\n                \"0    1 0.931\\n\"\n                \"0.96 1 0.931\\n\"\n            )\n            f.flush()\n            lut = ImageFilter.Color3DLUT.from_cube_file(f.name)\n            self.assertEqual(tuple(lut.size), (2, 2, 2))\n            self.assertEqual(lut.name, \"Color 3D LUT\")\n            self.assertEqual(lut.table[:12], [\n                0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 230,
                            "end_lineno": 387,
                            "parent": null
                        }
                    ],
                    "added_entities": [
                        {
                            "file_name": "Tests/test_color_lut.py",
                            "type": "method",
                            "name": "TestColorLut3DFilter.test_from_cube_file_filename",
                            "content": "class TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"  LUT_3D_SIZE 2 3 4\",\n            \" SKIP THIS\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])\n\n    def test_from_cube_file_errors(self):\n        with self.assertRaisesRegexp(ValueError, \"No size found\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'TITLE \"LUT name from file\"',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"number of colors on line 4\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031 1\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"Not a number on line 3\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0  green 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n    def test_from_cube_file_filename(self):\n        with NamedTemporaryFile() as f:\n            f.write(\n                \"LUT_3D_SIZE 2\\n\"\n                \"\\n\"\n                \"0    0 0.031\\n\"\n                \"0.96 0 0.031\\n\"\n                \"0    1 0.031\\n\"\n                \"0.96 1 0.031\\n\"\n                \"0    0 0.931\\n\"\n                \"0.96 0 0.931\\n\"\n                \"0    1 0.931\\n\"\n                \"0.96 1 0.931\\n\"\n            )\n            f.flush()\n            lut = ImageFilter.Color3DLUT.from_cube_file(f.name)\n            self.assertEqual(tuple(lut.size), (2, 2, 2))\n            self.assertEqual(lut.name, \"Color 3D LUT\")\n            self.assertEqual(lut.table[:12], [\n                0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 368,
                            "end_lineno": 387,
                            "parent": {
                                "file_name": "Tests/test_color_lut.py",
                                "type": "class",
                                "name": "TestColorLut3DFilter",
                                "content": "class TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"  LUT_3D_SIZE 2 3 4\",\n            \" SKIP THIS\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])\n\n    def test_from_cube_file_errors(self):\n        with self.assertRaisesRegexp(ValueError, \"No size found\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'TITLE \"LUT name from file\"',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"number of colors on line 4\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031 1\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"Not a number on line 3\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0  green 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n    def test_from_cube_file_filename(self):\n        with NamedTemporaryFile() as f:\n            f.write(\n                \"LUT_3D_SIZE 2\\n\"\n                \"\\n\"\n                \"0    0 0.031\\n\"\n                \"0.96 0 0.031\\n\"\n                \"0    1 0.031\\n\"\n                \"0.96 1 0.031\\n\"\n                \"0    0 0.931\\n\"\n                \"0.96 0 0.931\\n\"\n                \"0    1 0.931\\n\"\n                \"0.96 1 0.931\\n\"\n            )\n            f.flush()\n            lut = ImageFilter.Color3DLUT.from_cube_file(f.name)\n            self.assertEqual(tuple(lut.size), (2, 2, 2))\n            self.assertEqual(lut.name, \"Color 3D LUT\")\n            self.assertEqual(lut.table[:12], [\n                0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 230,
                                "end_lineno": 387,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "Tests/test_color_lut.py",
                            "type": "method",
                            "name": "TestColorLut3DFilter.test_from_cube_file_errors",
                            "content": "class TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"  LUT_3D_SIZE 2 3 4\",\n            \" SKIP THIS\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])\n\n    def test_from_cube_file_errors(self):\n        with self.assertRaisesRegexp(ValueError, \"No size found\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'TITLE \"LUT name from file\"',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"number of colors on line 4\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031 1\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"Not a number on line 3\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0  green 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n    def test_from_cube_file_filename(self):\n        with NamedTemporaryFile() as f:\n            f.write(\n                \"LUT_3D_SIZE 2\\n\"\n                \"\\n\"\n                \"0    0 0.031\\n\"\n                \"0.96 0 0.031\\n\"\n                \"0    1 0.031\\n\"\n                \"0.96 1 0.031\\n\"\n                \"0    0 0.931\\n\"\n                \"0.96 0 0.931\\n\"\n                \"0    1 0.931\\n\"\n                \"0.96 1 0.931\\n\"\n            )\n            f.flush()\n            lut = ImageFilter.Color3DLUT.from_cube_file(f.name)\n            self.assertEqual(tuple(lut.size), (2, 2, 2))\n            self.assertEqual(lut.name, \"Color 3D LUT\")\n            self.assertEqual(lut.table[:12], [\n                0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 340,
                            "end_lineno": 366,
                            "parent": {
                                "file_name": "Tests/test_color_lut.py",
                                "type": "class",
                                "name": "TestColorLut3DFilter",
                                "content": "class TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"  LUT_3D_SIZE 2 3 4\",\n            \" SKIP THIS\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])\n\n    def test_from_cube_file_errors(self):\n        with self.assertRaisesRegexp(ValueError, \"No size found\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'TITLE \"LUT name from file\"',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"number of colors on line 4\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031 1\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"Not a number on line 3\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0  green 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n    def test_from_cube_file_filename(self):\n        with NamedTemporaryFile() as f:\n            f.write(\n                \"LUT_3D_SIZE 2\\n\"\n                \"\\n\"\n                \"0    0 0.031\\n\"\n                \"0.96 0 0.031\\n\"\n                \"0    1 0.031\\n\"\n                \"0.96 1 0.031\\n\"\n                \"0    0 0.931\\n\"\n                \"0.96 0 0.931\\n\"\n                \"0    1 0.931\\n\"\n                \"0.96 1 0.931\\n\"\n            )\n            f.flush()\n            lut = ImageFilter.Color3DLUT.from_cube_file(f.name)\n            self.assertEqual(tuple(lut.size), (2, 2, 2))\n            self.assertEqual(lut.name, \"Color 3D LUT\")\n            self.assertEqual(lut.table[:12], [\n                0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 230,
                                "end_lineno": 387,
                                "parent": null
                            }
                        }
                    ],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# standard filters\n#\n# History:\n# 1995-11-27 fl   Created\n# 2002-06-08 fl   Added rank and mode filters\n# 2003-09-15 fl   Fixed rank calculation in rank filter; added expand call\n#\n# Copyright (c) 1997-2003 by Secret Labs AB.\n# Copyright (c) 1995-2002 by Fredrik Lundh.\n#\n# See the README file for information on usage and redistribution.\n#\n\nimport functools\n\nfrom ._util import isPath\n\n\nclass Filter(object):\n    pass\n\n\nclass MultibandFilter(Filter):\n    pass\n\n\nclass Kernel(MultibandFilter):\n    \"\"\"\n    Create a convolution kernel.  The current version only\n    supports 3x3 and 5x5 integer and floating point kernels.\n\n    In the current version, kernels can only be applied to\n    \"L\" and \"RGB\" images.\n\n    :param size: Kernel size, given as (width, height). In the current\n                    version, this must be (3,3) or (5,5).\n    :param kernel: A sequence containing kernel weights.\n    :param scale: Scale factor. If given, the result for each pixel is\n                    divided by this value.  the default is the sum of the\n                    kernel weights.\n    :param offset: Offset. If given, this value is added to the result,\n                    after it has been divided by the scale factor.\n    \"\"\"\n    name = \"Kernel\"\n\n    def __init__(self, size, kernel, scale=None, offset=0):\n        if scale is None:\n            # default scale is sum of kernel\n            scale = functools.reduce(lambda a, b: a+b, kernel)\n        if size[0] * size[1] != len(kernel):\n            raise ValueError(\"not enough coefficients in kernel\")\n        self.filterargs = size, scale, offset, kernel\n\n    def filter(self, image):\n        if image.mode == \"P\":\n            raise ValueError(\"cannot filter palette images\")\n        return image.filter(*self.filterargs)\n\n\nclass BuiltinFilter(Kernel):\n    def __init__(self):\n        pass\n\n\nclass RankFilter(Filter):\n    \"\"\"\n    Create a rank filter.  The rank filter sorts all pixels in\n    a window of the given size, and returns the **rank**'th value.\n\n    :param size: The kernel size, in pixels.\n    :param rank: What pixel value to pick.  Use 0 for a min filter,\n                 ``size * size / 2`` for a median filter, ``size * size - 1``\n                 for a max filter, etc.\n    \"\"\"\n    name = \"Rank\"\n\n    def __init__(self, size, rank):\n        self.size = size\n        self.rank = rank\n\n    def filter(self, image):\n        if image.mode == \"P\":\n            raise ValueError(\"cannot filter palette images\")\n        image = image.expand(self.size//2, self.size//2)\n        return image.rankfilter(self.size, self.rank)\n\n\nclass MedianFilter(RankFilter):\n    \"\"\"\n    Create a median filter. Picks the median pixel value in a window with the\n    given size.\n\n    :param size: The kernel size, in pixels.\n    \"\"\"\n    name = \"Median\"\n\n    def __init__(self, size=3):\n        self.size = size\n        self.rank = size*size//2\n\n\nclass MinFilter(RankFilter):\n    \"\"\"\n    Create a min filter.  Picks the lowest pixel value in a window with the\n    given size.\n\n    :param size: The kernel size, in pixels.\n    \"\"\"\n    name = \"Min\"\n\n    def __init__(self, size=3):\n        self.size = size\n        self.rank = 0\n\n\nclass MaxFilter(RankFilter):\n    \"\"\"\n    Create a max filter.  Picks the largest pixel value in a window with the\n    given size.\n\n    :param size: The kernel size, in pixels.\n    \"\"\"\n    name = \"Max\"\n\n    def __init__(self, size=3):\n        self.size = size\n        self.rank = size*size-1\n\n\nclass ModeFilter(Filter):\n    \"\"\"\n    Create a mode filter. Picks the most frequent pixel value in a box with the\n    given size.  Pixel values that occur only once or twice are ignored; if no\n    pixel value occurs more than twice, the original pixel value is preserved.\n\n    :param size: The kernel size, in pixels.\n    \"\"\"\n    name = \"Mode\"\n\n    def __init__(self, size=3):\n        self.size = size\n\n    def filter(self, image):\n        return image.modefilter(self.size)\n\n\nclass GaussianBlur(MultibandFilter):\n    \"\"\"Gaussian blur filter.\n\n    :param radius: Blur radius.\n    \"\"\"\n    name = \"GaussianBlur\"\n\n    def __init__(self, radius=2):\n        self.radius = radius\n\n    def filter(self, image):\n        return image.gaussian_blur(self.radius)\n\n\nclass BoxBlur(MultibandFilter):\n    \"\"\"Blurs the image by setting each pixel to the average value of the pixels\n    in a square box extending radius pixels in each direction.\n    Supports float radius of arbitrary size. Uses an optimized implementation\n    which runs in linear time relative to the size of the image\n    for any radius value.\n\n    :param radius: Size of the box in one direction. Radius 0 does not blur,\n                   returns an identical image. Radius 1 takes 1 pixel\n                   in each direction, i.e. 9 pixels in total.\n    \"\"\"\n    name = \"BoxBlur\"\n\n    def __init__(self, radius):\n        self.radius = radius\n\n    def filter(self, image):\n        return image.box_blur(self.radius)\n\n\nclass UnsharpMask(MultibandFilter):\n    \"\"\"Unsharp mask filter.\n\n    See Wikipedia's entry on `digital unsharp masking`_ for an explanation of\n    the parameters.\n\n    :param radius: Blur Radius\n    :param percent: Unsharp strength, in percent\n    :param threshold: Threshold controls the minimum brightness change that\n      will be sharpened\n\n    .. _digital unsharp masking: https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking\n\n    \"\"\"\n    name = \"UnsharpMask\"\n\n    def __init__(self, radius=2, percent=150, threshold=3):\n        self.radius = radius\n        self.percent = percent\n        self.threshold = threshold\n\n    def filter(self, image):\n        return image.unsharp_mask(self.radius, self.percent, self.threshold)\n\n\nclass BLUR(BuiltinFilter):\n    name = \"Blur\"\n    filterargs = (5, 5), 16, 0, (\n        1,  1,  1,  1,  1,\n        1,  0,  0,  0,  1,\n        1,  0,  0,  0,  1,\n        1,  0,  0,  0,  1,\n        1,  1,  1,  1,  1\n        )\n\n\nclass CONTOUR(BuiltinFilter):\n    name = \"Contour\"\n    filterargs = (3, 3), 1, 255, (\n        -1, -1, -1,\n        -1,  8, -1,\n        -1, -1, -1\n        )\n\n\nclass DETAIL(BuiltinFilter):\n    name = \"Detail\"\n    filterargs = (3, 3), 6, 0, (\n        0, -1,  0,\n        -1, 10, -1,\n        0, -1,  0\n        )\n\n\nclass EDGE_ENHANCE(BuiltinFilter):\n    name = \"Edge-enhance\"\n    filterargs = (3, 3), 2, 0, (\n        -1, -1, -1,\n        -1, 10, -1,\n        -1, -1, -1\n        )\n\n\nclass EDGE_ENHANCE_MORE(BuiltinFilter):\n    name = \"Edge-enhance More\"\n    filterargs = (3, 3), 1, 0, (\n        -1, -1, -1,\n        -1,  9, -1,\n        -1, -1, -1\n        )\n\n\nclass EMBOSS(BuiltinFilter):\n    name = \"Emboss\"\n    filterargs = (3, 3), 1, 128, (\n        -1,  0,  0,\n        0,  1,  0,\n        0,  0,  0\n        )\n\n\nclass FIND_EDGES(BuiltinFilter):\n    name = \"Find Edges\"\n    filterargs = (3, 3), 1, 0, (\n        -1, -1, -1,\n        -1,  8, -1,\n        -1, -1, -1\n        )\n\n\nclass SHARPEN(BuiltinFilter):\n    name = \"Sharpen\"\n    filterargs = (3, 3), 16, 0, (\n        -2, -2, -2,\n        -2, 32, -2,\n        -2, -2, -2\n        )\n\n\nclass SMOOTH(BuiltinFilter):\n    name = \"Smooth\"\n    filterargs = (3, 3), 13, 0, (\n        1,  1,  1,\n        1,  5,  1,\n        1,  1,  1\n        )\n\n\nclass SMOOTH_MORE(BuiltinFilter):\n    name = \"Smooth More\"\n    filterargs = (5, 5), 100, 0, (\n        1,  1,  1,  1,  1,\n        1,  5,  5,  5,  1,\n        1,  5, 44,  5,  1,\n        1,  5,  5,  5,  1,\n        1,  1,  1,  1,  1\n        )\n\n\nclass Color3DLUT(MultibandFilter):\n    \"\"\"Three-dimensional color lookup table.\n\n    Transforms 3-channel pixels using the values of the channels as coordinates\n    in the 3D lookup table and interpolating the nearest elements.\n\n    This method allows you to apply almost any color transformation\n    in constant time by using pre-calculated decimated tables.\n\n    :param size: Size of the table. One int or tuple of (int, int, int).\n                 Minimal size in any dimension is 2, maximum is 65.\n    :param table: Flat lookup table. A list of ``channels * size**3``\n                  float elements or a list of ``size**3`` channels-sized\n                  tuples with floats. Channels are changed first,\n                  then first dimension, then second, then third.\n                  Value 0.0 corresponds lowest value of output, 1.0 highest.\n    :param channels: Number of channels in the table. Could be 3 or 4.\n                     Default is 3.\n    :param target_mode: A mode for the result image. Should have not less\n                        than ``channels`` channels. Default is ``None``,\n                        which means that mode wouldn't be changed.\n    \"\"\"\n    name = \"Color 3D LUT\"\n\n    def __init__(self, size, table, channels=3, target_mode=None):\n        self.size = size = self._check_size(size)\n        self.channels = channels\n        self.mode = target_mode\n\n        table = list(table)\n        # Convert to a flat list\n        if table and isinstance(table[0], (list, tuple)):\n            table, raw_table = [], table\n            for pixel in raw_table:\n                if len(pixel) != channels:\n                    raise ValueError(\"The elements of the table should have \"\n                                     \"a length of {}.\".format(channels))\n                for color in pixel:\n                    table.append(color)\n\n        if len(table) != channels * size[0] * size[1] * size[2]:\n            raise ValueError(\n                \"The table should have channels * size**3 float items \"\n                \"either size**3 items of channels-sized tuples with floats. \"\n                \"Table size: {}x{}x{}. Table length: {}\".format(\n                    size[0], size[1], size[2], len(table)))\n        self.table = table\n\n    @staticmethod\n    def _check_size(size):\n        try:\n            _, _, _ = size\n        except ValueError:\n            raise ValueError(\"Size should be an integer either \"\n                             \"tuple of three integers.\")\n        except TypeError:\n            size = (size, size, size)\n        size = [int(x) for x in size]\n        for size1D in size:\n            if not 2 <= size1D <= 65:\n                raise ValueError(\"Size should be in [2, 65] range.\")\n        return size\n\n    @classmethod\n    def generate(cls, size, callback, channels=3, target_mode=None):\n        \"\"\"Generates new LUT using provided callback.\n\n        :param size: Size of the table. Passed to the constructor.\n        :param callback: Function with three parameters which correspond\n                         three color channels. Will be called ``size**3``\n                         times with values from 0.0 to 1.0 and should return\n                         a tuple with ``channels`` elements.\n        :param channels: Passed to the constructor.\n        :param target_mode: Passed to the constructor.\n        \"\"\"\n        size1D, size2D, size3D = cls._check_size(size)\n        table = []\n        for b in range(size3D):\n            for g in range(size2D):\n                for r in range(size1D):\n                    table.append(callback(\n                        r / float(size1D-1),\n                        g / float(size2D-1),\n                        b / float(size3D-1)))\n\n        return cls((size1D, size2D, size3D), table, channels, target_mode)\n\n    @classmethod\n    def from_cube_file(cls, lines, target_mode=None):\n        name, size = None, None\n        channels = 3\n        file = None\n\n        if isPath(lines):\n            file = lines = open(lines, 'rt')\n\n        try:\n            iterator = iter(lines)\n\n            for i, line in enumerate(iterator, 1):\n                line = line.strip()\n                if not line:\n                    break\n                if line.startswith('TITLE \"'):\n                    name = line.split('\"')[1]\n                    continue\n                if line.startswith('LUT_3D_SIZE '):\n                    size = [int(x) for x in line.split()[1:]]\n                    if len(size) == 1:\n                        size = size[0]\n                    continue\n                if line.startswith('CHANNELS '):\n                    channels = int(line.split()[1])\n\n            if size is None:\n                raise ValueError('No size found in the file')\n\n            table = []\n            for i, line in enumerate(iterator, i + 1):\n                line = line.strip()\n                if not line or line.startswith('#'):\n                    continue\n                try:\n                    pixel = [float(x) for x in line.split()]\n                except ValueError:\n                    raise ValueError(\"Not a number on line {}\".format(i))\n                if len(pixel) != channels:\n                    raise ValueError(\n                        \"Wrong number of colors on line {}\".format(i))\n                table.append(tuple(pixel))\n        finally:\n            if file is not None:\n                file.close()\n\n        instance = cls(size, table, channels, target_mode)\n        if name is not None:\n            instance.name = name\n        return instance\n\n    def filter(self, image):\n        from . import Image\n\n        return image.color_lut_3d(\n            self.mode or image.mode, Image.LINEAR, self.channels,\n            self.size[0], self.size[1], self.size[2], self.table)\n",
            "new_file_content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# standard filters\n#\n# History:\n# 1995-11-27 fl   Created\n# 2002-06-08 fl   Added rank and mode filters\n# 2003-09-15 fl   Fixed rank calculation in rank filter; added expand call\n#\n# Copyright (c) 1997-2003 by Secret Labs AB.\n# Copyright (c) 1995-2002 by Fredrik Lundh.\n#\n# See the README file for information on usage and redistribution.\n#\n\nimport functools\n\nfrom ._util import isPath\n\n\nclass Filter(object):\n    pass\n\n\nclass MultibandFilter(Filter):\n    pass\n\n\nclass Kernel(MultibandFilter):\n    \"\"\"\n    Create a convolution kernel.  The current version only\n    supports 3x3 and 5x5 integer and floating point kernels.\n\n    In the current version, kernels can only be applied to\n    \"L\" and \"RGB\" images.\n\n    :param size: Kernel size, given as (width, height). In the current\n                    version, this must be (3,3) or (5,5).\n    :param kernel: A sequence containing kernel weights.\n    :param scale: Scale factor. If given, the result for each pixel is\n                    divided by this value.  the default is the sum of the\n                    kernel weights.\n    :param offset: Offset. If given, this value is added to the result,\n                    after it has been divided by the scale factor.\n    \"\"\"\n    name = \"Kernel\"\n\n    def __init__(self, size, kernel, scale=None, offset=0):\n        if scale is None:\n            # default scale is sum of kernel\n            scale = functools.reduce(lambda a, b: a+b, kernel)\n        if size[0] * size[1] != len(kernel):\n            raise ValueError(\"not enough coefficients in kernel\")\n        self.filterargs = size, scale, offset, kernel\n\n    def filter(self, image):\n        if image.mode == \"P\":\n            raise ValueError(\"cannot filter palette images\")\n        return image.filter(*self.filterargs)\n\n\nclass BuiltinFilter(Kernel):\n    def __init__(self):\n        pass\n\n\nclass RankFilter(Filter):\n    \"\"\"\n    Create a rank filter.  The rank filter sorts all pixels in\n    a window of the given size, and returns the **rank**'th value.\n\n    :param size: The kernel size, in pixels.\n    :param rank: What pixel value to pick.  Use 0 for a min filter,\n                 ``size * size / 2`` for a median filter, ``size * size - 1``\n                 for a max filter, etc.\n    \"\"\"\n    name = \"Rank\"\n\n    def __init__(self, size, rank):\n        self.size = size\n        self.rank = rank\n\n    def filter(self, image):\n        if image.mode == \"P\":\n            raise ValueError(\"cannot filter palette images\")\n        image = image.expand(self.size//2, self.size//2)\n        return image.rankfilter(self.size, self.rank)\n\n\nclass MedianFilter(RankFilter):\n    \"\"\"\n    Create a median filter. Picks the median pixel value in a window with the\n    given size.\n\n    :param size: The kernel size, in pixels.\n    \"\"\"\n    name = \"Median\"\n\n    def __init__(self, size=3):\n        self.size = size\n        self.rank = size*size//2\n\n\nclass MinFilter(RankFilter):\n    \"\"\"\n    Create a min filter.  Picks the lowest pixel value in a window with the\n    given size.\n\n    :param size: The kernel size, in pixels.\n    \"\"\"\n    name = \"Min\"\n\n    def __init__(self, size=3):\n        self.size = size\n        self.rank = 0\n\n\nclass MaxFilter(RankFilter):\n    \"\"\"\n    Create a max filter.  Picks the largest pixel value in a window with the\n    given size.\n\n    :param size: The kernel size, in pixels.\n    \"\"\"\n    name = \"Max\"\n\n    def __init__(self, size=3):\n        self.size = size\n        self.rank = size*size-1\n\n\nclass ModeFilter(Filter):\n    \"\"\"\n    Create a mode filter. Picks the most frequent pixel value in a box with the\n    given size.  Pixel values that occur only once or twice are ignored; if no\n    pixel value occurs more than twice, the original pixel value is preserved.\n\n    :param size: The kernel size, in pixels.\n    \"\"\"\n    name = \"Mode\"\n\n    def __init__(self, size=3):\n        self.size = size\n\n    def filter(self, image):\n        return image.modefilter(self.size)\n\n\nclass GaussianBlur(MultibandFilter):\n    \"\"\"Gaussian blur filter.\n\n    :param radius: Blur radius.\n    \"\"\"\n    name = \"GaussianBlur\"\n\n    def __init__(self, radius=2):\n        self.radius = radius\n\n    def filter(self, image):\n        return image.gaussian_blur(self.radius)\n\n\nclass BoxBlur(MultibandFilter):\n    \"\"\"Blurs the image by setting each pixel to the average value of the pixels\n    in a square box extending radius pixels in each direction.\n    Supports float radius of arbitrary size. Uses an optimized implementation\n    which runs in linear time relative to the size of the image\n    for any radius value.\n\n    :param radius: Size of the box in one direction. Radius 0 does not blur,\n                   returns an identical image. Radius 1 takes 1 pixel\n                   in each direction, i.e. 9 pixels in total.\n    \"\"\"\n    name = \"BoxBlur\"\n\n    def __init__(self, radius):\n        self.radius = radius\n\n    def filter(self, image):\n        return image.box_blur(self.radius)\n\n\nclass UnsharpMask(MultibandFilter):\n    \"\"\"Unsharp mask filter.\n\n    See Wikipedia's entry on `digital unsharp masking`_ for an explanation of\n    the parameters.\n\n    :param radius: Blur Radius\n    :param percent: Unsharp strength, in percent\n    :param threshold: Threshold controls the minimum brightness change that\n      will be sharpened\n\n    .. _digital unsharp masking: https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking\n\n    \"\"\"\n    name = \"UnsharpMask\"\n\n    def __init__(self, radius=2, percent=150, threshold=3):\n        self.radius = radius\n        self.percent = percent\n        self.threshold = threshold\n\n    def filter(self, image):\n        return image.unsharp_mask(self.radius, self.percent, self.threshold)\n\n\nclass BLUR(BuiltinFilter):\n    name = \"Blur\"\n    filterargs = (5, 5), 16, 0, (\n        1,  1,  1,  1,  1,\n        1,  0,  0,  0,  1,\n        1,  0,  0,  0,  1,\n        1,  0,  0,  0,  1,\n        1,  1,  1,  1,  1\n        )\n\n\nclass CONTOUR(BuiltinFilter):\n    name = \"Contour\"\n    filterargs = (3, 3), 1, 255, (\n        -1, -1, -1,\n        -1,  8, -1,\n        -1, -1, -1\n        )\n\n\nclass DETAIL(BuiltinFilter):\n    name = \"Detail\"\n    filterargs = (3, 3), 6, 0, (\n        0, -1,  0,\n        -1, 10, -1,\n        0, -1,  0\n        )\n\n\nclass EDGE_ENHANCE(BuiltinFilter):\n    name = \"Edge-enhance\"\n    filterargs = (3, 3), 2, 0, (\n        -1, -1, -1,\n        -1, 10, -1,\n        -1, -1, -1\n        )\n\n\nclass EDGE_ENHANCE_MORE(BuiltinFilter):\n    name = \"Edge-enhance More\"\n    filterargs = (3, 3), 1, 0, (\n        -1, -1, -1,\n        -1,  9, -1,\n        -1, -1, -1\n        )\n\n\nclass EMBOSS(BuiltinFilter):\n    name = \"Emboss\"\n    filterargs = (3, 3), 1, 128, (\n        -1,  0,  0,\n        0,  1,  0,\n        0,  0,  0\n        )\n\n\nclass FIND_EDGES(BuiltinFilter):\n    name = \"Find Edges\"\n    filterargs = (3, 3), 1, 0, (\n        -1, -1, -1,\n        -1,  8, -1,\n        -1, -1, -1\n        )\n\n\nclass SHARPEN(BuiltinFilter):\n    name = \"Sharpen\"\n    filterargs = (3, 3), 16, 0, (\n        -2, -2, -2,\n        -2, 32, -2,\n        -2, -2, -2\n        )\n\n\nclass SMOOTH(BuiltinFilter):\n    name = \"Smooth\"\n    filterargs = (3, 3), 13, 0, (\n        1,  1,  1,\n        1,  5,  1,\n        1,  1,  1\n        )\n\n\nclass SMOOTH_MORE(BuiltinFilter):\n    name = \"Smooth More\"\n    filterargs = (5, 5), 100, 0, (\n        1,  1,  1,  1,  1,\n        1,  5,  5,  5,  1,\n        1,  5, 44,  5,  1,\n        1,  5,  5,  5,  1,\n        1,  1,  1,  1,  1\n        )\n\n\nclass Color3DLUT(MultibandFilter):\n    \"\"\"Three-dimensional color lookup table.\n\n    Transforms 3-channel pixels using the values of the channels as coordinates\n    in the 3D lookup table and interpolating the nearest elements.\n\n    This method allows you to apply almost any color transformation\n    in constant time by using pre-calculated decimated tables.\n\n    :param size: Size of the table. One int or tuple of (int, int, int).\n                 Minimal size in any dimension is 2, maximum is 65.\n    :param table: Flat lookup table. A list of ``channels * size**3``\n                  float elements or a list of ``size**3`` channels-sized\n                  tuples with floats. Channels are changed first,\n                  then first dimension, then second, then third.\n                  Value 0.0 corresponds lowest value of output, 1.0 highest.\n    :param channels: Number of channels in the table. Could be 3 or 4.\n                     Default is 3.\n    :param target_mode: A mode for the result image. Should have not less\n                        than ``channels`` channels. Default is ``None``,\n                        which means that mode wouldn't be changed.\n    \"\"\"\n    name = \"Color 3D LUT\"\n\n    def __init__(self, size, table, channels=3, target_mode=None):\n        self.size = size = self._check_size(size)\n        self.channels = channels\n        self.mode = target_mode\n\n        table = list(table)\n        # Convert to a flat list\n        if table and isinstance(table[0], (list, tuple)):\n            table, raw_table = [], table\n            for pixel in raw_table:\n                if len(pixel) != channels:\n                    raise ValueError(\"The elements of the table should have \"\n                                     \"a length of {}.\".format(channels))\n                for color in pixel:\n                    table.append(color)\n\n        if len(table) != channels * size[0] * size[1] * size[2]:\n            raise ValueError(\n                \"The table should have either channels * size**3 float items \"\n                \"or size**3 items of channels-sized tuples with floats. \"\n                \"Table size: {}x{}x{}. Table length: {}\".format(\n                    size[0], size[1], size[2], len(table)))\n        self.table = table\n\n    @staticmethod\n    def _check_size(size):\n        try:\n            _, _, _ = size\n        except ValueError:\n            raise ValueError(\"Size should be either an integer or \"\n                             \"a tuple of three integers.\")\n        except TypeError:\n            size = (size, size, size)\n        size = [int(x) for x in size]\n        for size1D in size:\n            if not 2 <= size1D <= 65:\n                raise ValueError(\"Size should be in [2, 65] range.\")\n        return size\n\n    @classmethod\n    def generate(cls, size, callback, channels=3, target_mode=None):\n        \"\"\"Generates new LUT using provided callback.\n\n        :param size: Size of the table. Passed to the constructor.\n        :param callback: Function with three parameters which correspond\n                         three color channels. Will be called ``size**3``\n                         times with values from 0.0 to 1.0 and should return\n                         a tuple with ``channels`` elements.\n        :param channels: Passed to the constructor.\n        :param target_mode: Passed to the constructor.\n        \"\"\"\n        size1D, size2D, size3D = cls._check_size(size)\n        table = []\n        for b in range(size3D):\n            for g in range(size2D):\n                for r in range(size1D):\n                    table.append(callback(\n                        r / float(size1D-1),\n                        g / float(size2D-1),\n                        b / float(size3D-1)))\n\n        return cls((size1D, size2D, size3D), table, channels, target_mode)\n\n    @classmethod\n    def from_cube_file(cls, lines, target_mode=None):\n        name, size = None, None\n        channels = 3\n        file = None\n\n        if isPath(lines):\n            file = lines = open(lines, 'rt')\n\n        try:\n            iterator = iter(lines)\n\n            for i, line in enumerate(iterator, 1):\n                line = line.strip()\n                if not line:\n                    break\n                if line.startswith('TITLE \"'):\n                    name = line.split('\"')[1]\n                    continue\n                if line.startswith('LUT_3D_SIZE '):\n                    size = [int(x) for x in line.split()[1:]]\n                    if len(size) == 1:\n                        size = size[0]\n                    continue\n                if line.startswith('CHANNELS '):\n                    channels = int(line.split()[1])\n\n            if size is None:\n                raise ValueError('No size found in the file')\n\n            table = []\n            for i, line in enumerate(iterator, i + 1):\n                line = line.strip()\n                if not line or line.startswith('#'):\n                    continue\n                try:\n                    pixel = [float(x) for x in line.split()]\n                except ValueError:\n                    raise ValueError(\"Not a number on line {}\".format(i))\n                if len(pixel) != channels:\n                    raise ValueError(\n                        \"Wrong number of colors on line {}\".format(i))\n                table.append(tuple(pixel))\n        finally:\n            if file is not None:\n                file.close()\n\n        instance = cls(size, table, channels, target_mode)\n        if name is not None:\n            instance.name = name\n        return instance\n\n    def filter(self, image):\n        from . import Image\n\n        return image.color_lut_3d(\n            self.mode or image.mode, Image.LINEAR, self.channels,\n            self.size[0], self.size[1], self.size[2], self.table)\n",
            "header": {
                "file": {
                    "path": "src/PIL/ImageFilter.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "916c24cae",
                "new_commit_hash": "4fb3db381",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/src/PIL/ImageFilter.py"
            },
            "plus_file": {
                "path": "b/src/PIL/ImageFilter.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 343,
                            "length": 8
                        },
                        "new_range": {
                            "start": 343,
                            "length": 8
                        },
                        "section": "class Color3DLUT(MultibandFilter):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        if len(table) != channels * size[0] * size[1] * size[2]:",
                                "type": "context"
                            },
                            {
                                "content": "            raise ValueError(",
                                "type": "context"
                            },
                            {
                                "content": "                \"The table should have channels * size**3 float items \"",
                                "type": "deleted"
                            },
                            {
                                "content": "                \"either size**3 items of channels-sized tuples with floats. \"",
                                "type": "deleted"
                            },
                            {
                                "content": "                \"The table should have either channels * size**3 float items \"",
                                "type": "added"
                            },
                            {
                                "content": "                \"or size**3 items of channels-sized tuples with floats. \"",
                                "type": "added"
                            },
                            {
                                "content": "                \"Table size: {}x{}x{}. Table length: {}\".format(",
                                "type": "context"
                            },
                            {
                                "content": "                    size[0], size[1], size[2], len(table)))",
                                "type": "context"
                            },
                            {
                                "content": "        self.table = table",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "src/PIL/ImageFilter.py",
                            "type": "method",
                            "name": "Color3DLUT.__init__",
                            "content": "class Color3DLUT(MultibandFilter):\n    \"\"\"Three-dimensional color lookup table.\n\n    Transforms 3-channel pixels using the values of the channels as coordinates\n    in the 3D lookup table and interpolating the nearest elements.\n\n    This method allows you to apply almost any color transformation\n    in constant time by using pre-calculated decimated tables.\n\n    :param size: Size of the table. One int or tuple of (int, int, int).\n                 Minimal size in any dimension is 2, maximum is 65.\n    :param table: Flat lookup table. A list of ``channels * size**3``\n                  float elements or a list of ``size**3`` channels-sized\n                  tuples with floats. Channels are changed first,\n                  then first dimension, then second, then third.\n                  Value 0.0 corresponds lowest value of output, 1.0 highest.\n    :param channels: Number of channels in the table. Could be 3 or 4.\n                     Default is 3.\n    :param target_mode: A mode for the result image. Should have not less\n                        than ``channels`` channels. Default is ``None``,\n                        which means that mode wouldn't be changed.\n    \"\"\"\n    name = \"Color 3D LUT\"\n\n    def __init__(self, size, table, channels=3, target_mode=None):\n        self.size = size = self._check_size(size)\n        self.channels = channels\n        self.mode = target_mode\n\n        table = list(table)\n        # Convert to a flat list\n        if table and isinstance(table[0], (list, tuple)):\n            table, raw_table = [], table\n            for pixel in raw_table:\n                if len(pixel) != channels:\n                    raise ValueError(\"The elements of the table should have \"\n                                     \"a length of {}.\".format(channels))\n                for color in pixel:\n                    table.append(color)\n\n        if len(table) != channels * size[0] * size[1] * size[2]:\n            raise ValueError(\n                \"The table should have channels * size**3 float items \"\n                \"either size**3 items of channels-sized tuples with floats. \"\n                \"Table size: {}x{}x{}. Table length: {}\".format(\n                    size[0], size[1], size[2], len(table)))\n        self.table = table\n\n    @staticmethod\n    def _check_size(size):\n        try:\n            _, _, _ = size\n        except ValueError:\n            raise ValueError(\"Size should be an integer either \"\n                             \"tuple of three integers.\")\n        except TypeError:\n            size = (size, size, size)\n        size = [int(x) for x in size]\n        for size1D in size:\n            if not 2 <= size1D <= 65:\n                raise ValueError(\"Size should be in [2, 65] range.\")\n        return size\n\n    @classmethod\n    def generate(cls, size, callback, channels=3, target_mode=None):\n        \"\"\"Generates new LUT using provided callback.\n\n        :param size: Size of the table. Passed to the constructor.\n        :param callback: Function with three parameters which correspond\n                         three color channels. Will be called ``size**3``\n                         times with values from 0.0 to 1.0 and should return\n                         a tuple with ``channels`` elements.\n        :param channels: Passed to the constructor.\n        :param target_mode: Passed to the constructor.\n        \"\"\"\n        size1D, size2D, size3D = cls._check_size(size)\n        table = []\n        for b in range(size3D):\n            for g in range(size2D):\n                for r in range(size1D):\n                    table.append(callback(\n                        r / float(size1D-1),\n                        g / float(size2D-1),\n                        b / float(size3D-1)))\n\n        return cls((size1D, size2D, size3D), table, channels, target_mode)\n\n    @classmethod\n    def from_cube_file(cls, lines, target_mode=None):\n        name, size = None, None\n        channels = 3\n        file = None\n\n        if isPath(lines):\n            file = lines = open(lines, 'rt')\n\n        try:\n            iterator = iter(lines)\n\n            for i, line in enumerate(iterator, 1):\n                line = line.strip()\n                if not line:\n                    break\n                if line.startswith('TITLE \"'):\n                    name = line.split('\"')[1]\n                    continue\n                if line.startswith('LUT_3D_SIZE '):\n                    size = [int(x) for x in line.split()[1:]]\n                    if len(size) == 1:\n                        size = size[0]\n                    continue\n                if line.startswith('CHANNELS '):\n                    channels = int(line.split()[1])\n\n            if size is None:\n                raise ValueError('No size found in the file')\n\n            table = []\n            for i, line in enumerate(iterator, i + 1):\n                line = line.strip()\n                if not line or line.startswith('#'):\n                    continue\n                try:\n                    pixel = [float(x) for x in line.split()]\n                except ValueError:\n                    raise ValueError(\"Not a number on line {}\".format(i))\n                if len(pixel) != channels:\n                    raise ValueError(\n                        \"Wrong number of colors on line {}\".format(i))\n                table.append(tuple(pixel))\n        finally:\n            if file is not None:\n                file.close()\n\n        instance = cls(size, table, channels, target_mode)\n        if name is not None:\n            instance.name = name\n        return instance\n\n    def filter(self, image):\n        from . import Image\n\n        return image.color_lut_3d(\n            self.mode or image.mode, Image.LINEAR, self.channels,\n            self.size[0], self.size[1], self.size[2], self.table)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 328,
                            "end_lineno": 350,
                            "parent": {
                                "file_name": "src/PIL/ImageFilter.py",
                                "type": "class",
                                "name": "Color3DLUT",
                                "content": "class Color3DLUT(MultibandFilter):\n    \"\"\"Three-dimensional color lookup table.\n\n    Transforms 3-channel pixels using the values of the channels as coordinates\n    in the 3D lookup table and interpolating the nearest elements.\n\n    This method allows you to apply almost any color transformation\n    in constant time by using pre-calculated decimated tables.\n\n    :param size: Size of the table. One int or tuple of (int, int, int).\n                 Minimal size in any dimension is 2, maximum is 65.\n    :param table: Flat lookup table. A list of ``channels * size**3``\n                  float elements or a list of ``size**3`` channels-sized\n                  tuples with floats. Channels are changed first,\n                  then first dimension, then second, then third.\n                  Value 0.0 corresponds lowest value of output, 1.0 highest.\n    :param channels: Number of channels in the table. Could be 3 or 4.\n                     Default is 3.\n    :param target_mode: A mode for the result image. Should have not less\n                        than ``channels`` channels. Default is ``None``,\n                        which means that mode wouldn't be changed.\n    \"\"\"\n    name = \"Color 3D LUT\"\n\n    def __init__(self, size, table, channels=3, target_mode=None):\n        self.size = size = self._check_size(size)\n        self.channels = channels\n        self.mode = target_mode\n\n        table = list(table)\n        # Convert to a flat list\n        if table and isinstance(table[0], (list, tuple)):\n            table, raw_table = [], table\n            for pixel in raw_table:\n                if len(pixel) != channels:\n                    raise ValueError(\"The elements of the table should have \"\n                                     \"a length of {}.\".format(channels))\n                for color in pixel:\n                    table.append(color)\n\n        if len(table) != channels * size[0] * size[1] * size[2]:\n            raise ValueError(\n                \"The table should have channels * size**3 float items \"\n                \"either size**3 items of channels-sized tuples with floats. \"\n                \"Table size: {}x{}x{}. Table length: {}\".format(\n                    size[0], size[1], size[2], len(table)))\n        self.table = table\n\n    @staticmethod\n    def _check_size(size):\n        try:\n            _, _, _ = size\n        except ValueError:\n            raise ValueError(\"Size should be an integer either \"\n                             \"tuple of three integers.\")\n        except TypeError:\n            size = (size, size, size)\n        size = [int(x) for x in size]\n        for size1D in size:\n            if not 2 <= size1D <= 65:\n                raise ValueError(\"Size should be in [2, 65] range.\")\n        return size\n\n    @classmethod\n    def generate(cls, size, callback, channels=3, target_mode=None):\n        \"\"\"Generates new LUT using provided callback.\n\n        :param size: Size of the table. Passed to the constructor.\n        :param callback: Function with three parameters which correspond\n                         three color channels. Will be called ``size**3``\n                         times with values from 0.0 to 1.0 and should return\n                         a tuple with ``channels`` elements.\n        :param channels: Passed to the constructor.\n        :param target_mode: Passed to the constructor.\n        \"\"\"\n        size1D, size2D, size3D = cls._check_size(size)\n        table = []\n        for b in range(size3D):\n            for g in range(size2D):\n                for r in range(size1D):\n                    table.append(callback(\n                        r / float(size1D-1),\n                        g / float(size2D-1),\n                        b / float(size3D-1)))\n\n        return cls((size1D, size2D, size3D), table, channels, target_mode)\n\n    @classmethod\n    def from_cube_file(cls, lines, target_mode=None):\n        name, size = None, None\n        channels = 3\n        file = None\n\n        if isPath(lines):\n            file = lines = open(lines, 'rt')\n\n        try:\n            iterator = iter(lines)\n\n            for i, line in enumerate(iterator, 1):\n                line = line.strip()\n                if not line:\n                    break\n                if line.startswith('TITLE \"'):\n                    name = line.split('\"')[1]\n                    continue\n                if line.startswith('LUT_3D_SIZE '):\n                    size = [int(x) for x in line.split()[1:]]\n                    if len(size) == 1:\n                        size = size[0]\n                    continue\n                if line.startswith('CHANNELS '):\n                    channels = int(line.split()[1])\n\n            if size is None:\n                raise ValueError('No size found in the file')\n\n            table = []\n            for i, line in enumerate(iterator, i + 1):\n                line = line.strip()\n                if not line or line.startswith('#'):\n                    continue\n                try:\n                    pixel = [float(x) for x in line.split()]\n                except ValueError:\n                    raise ValueError(\"Not a number on line {}\".format(i))\n                if len(pixel) != channels:\n                    raise ValueError(\n                        \"Wrong number of colors on line {}\".format(i))\n                table.append(tuple(pixel))\n        finally:\n            if file is not None:\n                file.close()\n\n        instance = cls(size, table, channels, target_mode)\n        if name is not None:\n            instance.name = name\n        return instance\n\n    def filter(self, image):\n        from . import Image\n\n        return image.color_lut_3d(\n            self.mode or image.mode, Image.LINEAR, self.channels,\n            self.size[0], self.size[1], self.size[2], self.table)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 304,
                                "end_lineno": 448,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "src/PIL/ImageFilter.py",
                            "type": "class",
                            "name": "Color3DLUT",
                            "content": "class Color3DLUT(MultibandFilter):\n    \"\"\"Three-dimensional color lookup table.\n\n    Transforms 3-channel pixels using the values of the channels as coordinates\n    in the 3D lookup table and interpolating the nearest elements.\n\n    This method allows you to apply almost any color transformation\n    in constant time by using pre-calculated decimated tables.\n\n    :param size: Size of the table. One int or tuple of (int, int, int).\n                 Minimal size in any dimension is 2, maximum is 65.\n    :param table: Flat lookup table. A list of ``channels * size**3``\n                  float elements or a list of ``size**3`` channels-sized\n                  tuples with floats. Channels are changed first,\n                  then first dimension, then second, then third.\n                  Value 0.0 corresponds lowest value of output, 1.0 highest.\n    :param channels: Number of channels in the table. Could be 3 or 4.\n                     Default is 3.\n    :param target_mode: A mode for the result image. Should have not less\n                        than ``channels`` channels. Default is ``None``,\n                        which means that mode wouldn't be changed.\n    \"\"\"\n    name = \"Color 3D LUT\"\n\n    def __init__(self, size, table, channels=3, target_mode=None):\n        self.size = size = self._check_size(size)\n        self.channels = channels\n        self.mode = target_mode\n\n        table = list(table)\n        # Convert to a flat list\n        if table and isinstance(table[0], (list, tuple)):\n            table, raw_table = [], table\n            for pixel in raw_table:\n                if len(pixel) != channels:\n                    raise ValueError(\"The elements of the table should have \"\n                                     \"a length of {}.\".format(channels))\n                for color in pixel:\n                    table.append(color)\n\n        if len(table) != channels * size[0] * size[1] * size[2]:\n            raise ValueError(\n                \"The table should have channels * size**3 float items \"\n                \"either size**3 items of channels-sized tuples with floats. \"\n                \"Table size: {}x{}x{}. Table length: {}\".format(\n                    size[0], size[1], size[2], len(table)))\n        self.table = table\n\n    @staticmethod\n    def _check_size(size):\n        try:\n            _, _, _ = size\n        except ValueError:\n            raise ValueError(\"Size should be an integer either \"\n                             \"tuple of three integers.\")\n        except TypeError:\n            size = (size, size, size)\n        size = [int(x) for x in size]\n        for size1D in size:\n            if not 2 <= size1D <= 65:\n                raise ValueError(\"Size should be in [2, 65] range.\")\n        return size\n\n    @classmethod\n    def generate(cls, size, callback, channels=3, target_mode=None):\n        \"\"\"Generates new LUT using provided callback.\n\n        :param size: Size of the table. Passed to the constructor.\n        :param callback: Function with three parameters which correspond\n                         three color channels. Will be called ``size**3``\n                         times with values from 0.0 to 1.0 and should return\n                         a tuple with ``channels`` elements.\n        :param channels: Passed to the constructor.\n        :param target_mode: Passed to the constructor.\n        \"\"\"\n        size1D, size2D, size3D = cls._check_size(size)\n        table = []\n        for b in range(size3D):\n            for g in range(size2D):\n                for r in range(size1D):\n                    table.append(callback(\n                        r / float(size1D-1),\n                        g / float(size2D-1),\n                        b / float(size3D-1)))\n\n        return cls((size1D, size2D, size3D), table, channels, target_mode)\n\n    @classmethod\n    def from_cube_file(cls, lines, target_mode=None):\n        name, size = None, None\n        channels = 3\n        file = None\n\n        if isPath(lines):\n            file = lines = open(lines, 'rt')\n\n        try:\n            iterator = iter(lines)\n\n            for i, line in enumerate(iterator, 1):\n                line = line.strip()\n                if not line:\n                    break\n                if line.startswith('TITLE \"'):\n                    name = line.split('\"')[1]\n                    continue\n                if line.startswith('LUT_3D_SIZE '):\n                    size = [int(x) for x in line.split()[1:]]\n                    if len(size) == 1:\n                        size = size[0]\n                    continue\n                if line.startswith('CHANNELS '):\n                    channels = int(line.split()[1])\n\n            if size is None:\n                raise ValueError('No size found in the file')\n\n            table = []\n            for i, line in enumerate(iterator, i + 1):\n                line = line.strip()\n                if not line or line.startswith('#'):\n                    continue\n                try:\n                    pixel = [float(x) for x in line.split()]\n                except ValueError:\n                    raise ValueError(\"Not a number on line {}\".format(i))\n                if len(pixel) != channels:\n                    raise ValueError(\n                        \"Wrong number of colors on line {}\".format(i))\n                table.append(tuple(pixel))\n        finally:\n            if file is not None:\n                file.close()\n\n        instance = cls(size, table, channels, target_mode)\n        if name is not None:\n            instance.name = name\n        return instance\n\n    def filter(self, image):\n        from . import Image\n\n        return image.color_lut_3d(\n            self.mode or image.mode, Image.LINEAR, self.channels,\n            self.size[0], self.size[1], self.size[2], self.table)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 304,
                            "end_lineno": 448,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 354,
                            "length": 8
                        },
                        "new_range": {
                            "start": 354,
                            "length": 8
                        },
                        "section": "class Color3DLUT(MultibandFilter):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        try:",
                                "type": "context"
                            },
                            {
                                "content": "            _, _, _ = size",
                                "type": "context"
                            },
                            {
                                "content": "        except ValueError:",
                                "type": "context"
                            },
                            {
                                "content": "            raise ValueError(\"Size should be an integer either \"",
                                "type": "deleted"
                            },
                            {
                                "content": "                             \"tuple of three integers.\")",
                                "type": "deleted"
                            },
                            {
                                "content": "            raise ValueError(\"Size should be either an integer or \"",
                                "type": "added"
                            },
                            {
                                "content": "                             \"a tuple of three integers.\")",
                                "type": "added"
                            },
                            {
                                "content": "        except TypeError:",
                                "type": "context"
                            },
                            {
                                "content": "            size = (size, size, size)",
                                "type": "context"
                            },
                            {
                                "content": "        size = [int(x) for x in size]",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "src/PIL/ImageFilter.py",
                            "type": "method",
                            "name": "Color3DLUT._check_size",
                            "content": "class Color3DLUT(MultibandFilter):\n    \"\"\"Three-dimensional color lookup table.\n\n    Transforms 3-channel pixels using the values of the channels as coordinates\n    in the 3D lookup table and interpolating the nearest elements.\n\n    This method allows you to apply almost any color transformation\n    in constant time by using pre-calculated decimated tables.\n\n    :param size: Size of the table. One int or tuple of (int, int, int).\n                 Minimal size in any dimension is 2, maximum is 65.\n    :param table: Flat lookup table. A list of ``channels * size**3``\n                  float elements or a list of ``size**3`` channels-sized\n                  tuples with floats. Channels are changed first,\n                  then first dimension, then second, then third.\n                  Value 0.0 corresponds lowest value of output, 1.0 highest.\n    :param channels: Number of channels in the table. Could be 3 or 4.\n                     Default is 3.\n    :param target_mode: A mode for the result image. Should have not less\n                        than ``channels`` channels. Default is ``None``,\n                        which means that mode wouldn't be changed.\n    \"\"\"\n    name = \"Color 3D LUT\"\n\n    def __init__(self, size, table, channels=3, target_mode=None):\n        self.size = size = self._check_size(size)\n        self.channels = channels\n        self.mode = target_mode\n\n        table = list(table)\n        # Convert to a flat list\n        if table and isinstance(table[0], (list, tuple)):\n            table, raw_table = [], table\n            for pixel in raw_table:\n                if len(pixel) != channels:\n                    raise ValueError(\"The elements of the table should have \"\n                                     \"a length of {}.\".format(channels))\n                for color in pixel:\n                    table.append(color)\n\n        if len(table) != channels * size[0] * size[1] * size[2]:\n            raise ValueError(\n                \"The table should have channels * size**3 float items \"\n                \"either size**3 items of channels-sized tuples with floats. \"\n                \"Table size: {}x{}x{}. Table length: {}\".format(\n                    size[0], size[1], size[2], len(table)))\n        self.table = table\n\n    @staticmethod\n    def _check_size(size):\n        try:\n            _, _, _ = size\n        except ValueError:\n            raise ValueError(\"Size should be an integer either \"\n                             \"tuple of three integers.\")\n        except TypeError:\n            size = (size, size, size)\n        size = [int(x) for x in size]\n        for size1D in size:\n            if not 2 <= size1D <= 65:\n                raise ValueError(\"Size should be in [2, 65] range.\")\n        return size\n\n    @classmethod\n    def generate(cls, size, callback, channels=3, target_mode=None):\n        \"\"\"Generates new LUT using provided callback.\n\n        :param size: Size of the table. Passed to the constructor.\n        :param callback: Function with three parameters which correspond\n                         three color channels. Will be called ``size**3``\n                         times with values from 0.0 to 1.0 and should return\n                         a tuple with ``channels`` elements.\n        :param channels: Passed to the constructor.\n        :param target_mode: Passed to the constructor.\n        \"\"\"\n        size1D, size2D, size3D = cls._check_size(size)\n        table = []\n        for b in range(size3D):\n            for g in range(size2D):\n                for r in range(size1D):\n                    table.append(callback(\n                        r / float(size1D-1),\n                        g / float(size2D-1),\n                        b / float(size3D-1)))\n\n        return cls((size1D, size2D, size3D), table, channels, target_mode)\n\n    @classmethod\n    def from_cube_file(cls, lines, target_mode=None):\n        name, size = None, None\n        channels = 3\n        file = None\n\n        if isPath(lines):\n            file = lines = open(lines, 'rt')\n\n        try:\n            iterator = iter(lines)\n\n            for i, line in enumerate(iterator, 1):\n                line = line.strip()\n                if not line:\n                    break\n                if line.startswith('TITLE \"'):\n                    name = line.split('\"')[1]\n                    continue\n                if line.startswith('LUT_3D_SIZE '):\n                    size = [int(x) for x in line.split()[1:]]\n                    if len(size) == 1:\n                        size = size[0]\n                    continue\n                if line.startswith('CHANNELS '):\n                    channels = int(line.split()[1])\n\n            if size is None:\n                raise ValueError('No size found in the file')\n\n            table = []\n            for i, line in enumerate(iterator, i + 1):\n                line = line.strip()\n                if not line or line.startswith('#'):\n                    continue\n                try:\n                    pixel = [float(x) for x in line.split()]\n                except ValueError:\n                    raise ValueError(\"Not a number on line {}\".format(i))\n                if len(pixel) != channels:\n                    raise ValueError(\n                        \"Wrong number of colors on line {}\".format(i))\n                table.append(tuple(pixel))\n        finally:\n            if file is not None:\n                file.close()\n\n        instance = cls(size, table, channels, target_mode)\n        if name is not None:\n            instance.name = name\n        return instance\n\n    def filter(self, image):\n        from . import Image\n\n        return image.color_lut_3d(\n            self.mode or image.mode, Image.LINEAR, self.channels,\n            self.size[0], self.size[1], self.size[2], self.table)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 353,
                            "end_lineno": 365,
                            "parent": {
                                "file_name": "src/PIL/ImageFilter.py",
                                "type": "class",
                                "name": "Color3DLUT",
                                "content": "class Color3DLUT(MultibandFilter):\n    \"\"\"Three-dimensional color lookup table.\n\n    Transforms 3-channel pixels using the values of the channels as coordinates\n    in the 3D lookup table and interpolating the nearest elements.\n\n    This method allows you to apply almost any color transformation\n    in constant time by using pre-calculated decimated tables.\n\n    :param size: Size of the table. One int or tuple of (int, int, int).\n                 Minimal size in any dimension is 2, maximum is 65.\n    :param table: Flat lookup table. A list of ``channels * size**3``\n                  float elements or a list of ``size**3`` channels-sized\n                  tuples with floats. Channels are changed first,\n                  then first dimension, then second, then third.\n                  Value 0.0 corresponds lowest value of output, 1.0 highest.\n    :param channels: Number of channels in the table. Could be 3 or 4.\n                     Default is 3.\n    :param target_mode: A mode for the result image. Should have not less\n                        than ``channels`` channels. Default is ``None``,\n                        which means that mode wouldn't be changed.\n    \"\"\"\n    name = \"Color 3D LUT\"\n\n    def __init__(self, size, table, channels=3, target_mode=None):\n        self.size = size = self._check_size(size)\n        self.channels = channels\n        self.mode = target_mode\n\n        table = list(table)\n        # Convert to a flat list\n        if table and isinstance(table[0], (list, tuple)):\n            table, raw_table = [], table\n            for pixel in raw_table:\n                if len(pixel) != channels:\n                    raise ValueError(\"The elements of the table should have \"\n                                     \"a length of {}.\".format(channels))\n                for color in pixel:\n                    table.append(color)\n\n        if len(table) != channels * size[0] * size[1] * size[2]:\n            raise ValueError(\n                \"The table should have channels * size**3 float items \"\n                \"either size**3 items of channels-sized tuples with floats. \"\n                \"Table size: {}x{}x{}. Table length: {}\".format(\n                    size[0], size[1], size[2], len(table)))\n        self.table = table\n\n    @staticmethod\n    def _check_size(size):\n        try:\n            _, _, _ = size\n        except ValueError:\n            raise ValueError(\"Size should be an integer either \"\n                             \"tuple of three integers.\")\n        except TypeError:\n            size = (size, size, size)\n        size = [int(x) for x in size]\n        for size1D in size:\n            if not 2 <= size1D <= 65:\n                raise ValueError(\"Size should be in [2, 65] range.\")\n        return size\n\n    @classmethod\n    def generate(cls, size, callback, channels=3, target_mode=None):\n        \"\"\"Generates new LUT using provided callback.\n\n        :param size: Size of the table. Passed to the constructor.\n        :param callback: Function with three parameters which correspond\n                         three color channels. Will be called ``size**3``\n                         times with values from 0.0 to 1.0 and should return\n                         a tuple with ``channels`` elements.\n        :param channels: Passed to the constructor.\n        :param target_mode: Passed to the constructor.\n        \"\"\"\n        size1D, size2D, size3D = cls._check_size(size)\n        table = []\n        for b in range(size3D):\n            for g in range(size2D):\n                for r in range(size1D):\n                    table.append(callback(\n                        r / float(size1D-1),\n                        g / float(size2D-1),\n                        b / float(size3D-1)))\n\n        return cls((size1D, size2D, size3D), table, channels, target_mode)\n\n    @classmethod\n    def from_cube_file(cls, lines, target_mode=None):\n        name, size = None, None\n        channels = 3\n        file = None\n\n        if isPath(lines):\n            file = lines = open(lines, 'rt')\n\n        try:\n            iterator = iter(lines)\n\n            for i, line in enumerate(iterator, 1):\n                line = line.strip()\n                if not line:\n                    break\n                if line.startswith('TITLE \"'):\n                    name = line.split('\"')[1]\n                    continue\n                if line.startswith('LUT_3D_SIZE '):\n                    size = [int(x) for x in line.split()[1:]]\n                    if len(size) == 1:\n                        size = size[0]\n                    continue\n                if line.startswith('CHANNELS '):\n                    channels = int(line.split()[1])\n\n            if size is None:\n                raise ValueError('No size found in the file')\n\n            table = []\n            for i, line in enumerate(iterator, i + 1):\n                line = line.strip()\n                if not line or line.startswith('#'):\n                    continue\n                try:\n                    pixel = [float(x) for x in line.split()]\n                except ValueError:\n                    raise ValueError(\"Not a number on line {}\".format(i))\n                if len(pixel) != channels:\n                    raise ValueError(\n                        \"Wrong number of colors on line {}\".format(i))\n                table.append(tuple(pixel))\n        finally:\n            if file is not None:\n                file.close()\n\n        instance = cls(size, table, channels, target_mode)\n        if name is not None:\n            instance.name = name\n        return instance\n\n    def filter(self, image):\n        from . import Image\n\n        return image.color_lut_3d(\n            self.mode or image.mode, Image.LINEAR, self.channels,\n            self.size[0], self.size[1], self.size[2], self.table)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 304,
                                "end_lineno": 448,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "src/PIL/ImageFilter.py",
                            "type": "class",
                            "name": "Color3DLUT",
                            "content": "class Color3DLUT(MultibandFilter):\n    \"\"\"Three-dimensional color lookup table.\n\n    Transforms 3-channel pixels using the values of the channels as coordinates\n    in the 3D lookup table and interpolating the nearest elements.\n\n    This method allows you to apply almost any color transformation\n    in constant time by using pre-calculated decimated tables.\n\n    :param size: Size of the table. One int or tuple of (int, int, int).\n                 Minimal size in any dimension is 2, maximum is 65.\n    :param table: Flat lookup table. A list of ``channels * size**3``\n                  float elements or a list of ``size**3`` channels-sized\n                  tuples with floats. Channels are changed first,\n                  then first dimension, then second, then third.\n                  Value 0.0 corresponds lowest value of output, 1.0 highest.\n    :param channels: Number of channels in the table. Could be 3 or 4.\n                     Default is 3.\n    :param target_mode: A mode for the result image. Should have not less\n                        than ``channels`` channels. Default is ``None``,\n                        which means that mode wouldn't be changed.\n    \"\"\"\n    name = \"Color 3D LUT\"\n\n    def __init__(self, size, table, channels=3, target_mode=None):\n        self.size = size = self._check_size(size)\n        self.channels = channels\n        self.mode = target_mode\n\n        table = list(table)\n        # Convert to a flat list\n        if table and isinstance(table[0], (list, tuple)):\n            table, raw_table = [], table\n            for pixel in raw_table:\n                if len(pixel) != channels:\n                    raise ValueError(\"The elements of the table should have \"\n                                     \"a length of {}.\".format(channels))\n                for color in pixel:\n                    table.append(color)\n\n        if len(table) != channels * size[0] * size[1] * size[2]:\n            raise ValueError(\n                \"The table should have channels * size**3 float items \"\n                \"either size**3 items of channels-sized tuples with floats. \"\n                \"Table size: {}x{}x{}. Table length: {}\".format(\n                    size[0], size[1], size[2], len(table)))\n        self.table = table\n\n    @staticmethod\n    def _check_size(size):\n        try:\n            _, _, _ = size\n        except ValueError:\n            raise ValueError(\"Size should be an integer either \"\n                             \"tuple of three integers.\")\n        except TypeError:\n            size = (size, size, size)\n        size = [int(x) for x in size]\n        for size1D in size:\n            if not 2 <= size1D <= 65:\n                raise ValueError(\"Size should be in [2, 65] range.\")\n        return size\n\n    @classmethod\n    def generate(cls, size, callback, channels=3, target_mode=None):\n        \"\"\"Generates new LUT using provided callback.\n\n        :param size: Size of the table. Passed to the constructor.\n        :param callback: Function with three parameters which correspond\n                         three color channels. Will be called ``size**3``\n                         times with values from 0.0 to 1.0 and should return\n                         a tuple with ``channels`` elements.\n        :param channels: Passed to the constructor.\n        :param target_mode: Passed to the constructor.\n        \"\"\"\n        size1D, size2D, size3D = cls._check_size(size)\n        table = []\n        for b in range(size3D):\n            for g in range(size2D):\n                for r in range(size1D):\n                    table.append(callback(\n                        r / float(size1D-1),\n                        g / float(size2D-1),\n                        b / float(size3D-1)))\n\n        return cls((size1D, size2D, size3D), table, channels, target_mode)\n\n    @classmethod\n    def from_cube_file(cls, lines, target_mode=None):\n        name, size = None, None\n        channels = 3\n        file = None\n\n        if isPath(lines):\n            file = lines = open(lines, 'rt')\n\n        try:\n            iterator = iter(lines)\n\n            for i, line in enumerate(iterator, 1):\n                line = line.strip()\n                if not line:\n                    break\n                if line.startswith('TITLE \"'):\n                    name = line.split('\"')[1]\n                    continue\n                if line.startswith('LUT_3D_SIZE '):\n                    size = [int(x) for x in line.split()[1:]]\n                    if len(size) == 1:\n                        size = size[0]\n                    continue\n                if line.startswith('CHANNELS '):\n                    channels = int(line.split()[1])\n\n            if size is None:\n                raise ValueError('No size found in the file')\n\n            table = []\n            for i, line in enumerate(iterator, i + 1):\n                line = line.strip()\n                if not line or line.startswith('#'):\n                    continue\n                try:\n                    pixel = [float(x) for x in line.split()]\n                except ValueError:\n                    raise ValueError(\"Not a number on line {}\".format(i))\n                if len(pixel) != channels:\n                    raise ValueError(\n                        \"Wrong number of colors on line {}\".format(i))\n                table.append(tuple(pixel))\n        finally:\n            if file is not None:\n                file.close()\n\n        instance = cls(size, table, channels, target_mode)\n        if name is not None:\n            instance.name = name\n        return instance\n\n    def filter(self, image):\n        from . import Image\n\n        return image.color_lut_3d(\n            self.mode or image.mode, Image.LINEAR, self.channels,\n            self.size[0], self.size[1], self.size[2], self.table)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 304,
                            "end_lineno": 448,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        }
    ],
    "old_commit_hash": "e304a0d501315b95c71ea16c532216f391db240f^",
    "new_commit_hash": "e304a0d501315b95c71ea16c532216f391db240f",
    "commit_message": "add tests, fix error messages",
    "commit_date": "2018-03-30T09:57:54+03:00",
    "metadata": {}
}
{
    "repo_name": "pillow",
    "new_commit_hash": "e304a0d501315b95c71ea16c532216f391db240f",
    "test_file_codes": [
        "from __future__ import division\nfrom tempfile import NamedTemporaryFile\nfrom helper import unittest, PillowTestCase\n\nfrom PIL import Image, ImageFilter\n\n\nclass TestColorLut3DCoreAPI(PillowTestCase):\n    def generate_unit_table(self, channels, size):\n        if isinstance(size, tuple):\n            size1D, size2D, size3D = size\n        else:\n            size1D, size2D, size3D = (size, size, size)\n\n        table = [\n            [\n                r / float(size1D-1) if size1D != 1 else 0,\n                g / float(size2D-1) if size2D != 1 else 0,\n                b / float(size3D-1) if size3D != 1 else 0,\n                r / float(size1D-1) if size1D != 1 else 0,\n                g / float(size2D-1) if size2D != 1 else 0,\n            ][:channels]\n            for b in range(size3D)\n                for g in range(size2D)\n                    for r in range(size1D)\n        ]\n        return (\n            channels, size1D, size2D, size3D,\n            [item for sublist in table for item in sublist])\n\n    def test_wrong_args(self):\n        im = Image.new('RGB', (10, 10), 0)\n\n        with self.assertRaisesRegexp(ValueError, \"filter\"):\n            im.im.color_lut_3d('RGB', Image.CUBIC,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"image mode\"):\n            im.im.color_lut_3d('wrong', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"table_channels\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(5, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"table_channels\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(1, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"table_channels\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(2, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"Table size\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(3, (1, 3, 3)))\n\n        with self.assertRaisesRegexp(ValueError, \"Table size\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(3, (66, 3, 3)))\n\n        with self.assertRaisesRegexp(ValueError, r\"size1D \\* size2D \\* size3D\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2, [0, 0, 0] * 7)\n\n        with self.assertRaisesRegexp(ValueError, r\"size1D \\* size2D \\* size3D\"):\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2, [0, 0, 0] * 9)\n\n    def test_correct_args(self):\n        im = Image.new('RGB', (10, 10), 0)\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, 3))\n\n        im.im.color_lut_3d('CMYK', Image.LINEAR,\n            *self.generate_unit_table(4, 3))\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, (2, 3, 3)))\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, (65, 3, 3)))\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, (3, 65, 3)))\n\n        im.im.color_lut_3d('RGB', Image.LINEAR,\n            *self.generate_unit_table(3, (3, 3, 65)))\n\n    def test_wrong_mode(self):\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('L', (10, 10), 0)\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('RGB', (10, 10), 0)\n            im.im.color_lut_3d('L', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('L', (10, 10), 0)\n            im.im.color_lut_3d('L', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('RGB', (10, 10), 0)\n            im.im.color_lut_3d('RGBA', Image.LINEAR,\n                *self.generate_unit_table(3, 3))\n\n        with self.assertRaisesRegexp(ValueError, \"wrong mode\"):\n            im = Image.new('RGB', (10, 10), 0)\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(4, 3))\n\n    def test_correct_mode(self):\n        im = Image.new('RGBA', (10, 10), 0)\n        im.im.color_lut_3d('RGBA', Image.LINEAR,\n            *self.generate_unit_table(3, 3))\n\n        im = Image.new('RGBA', (10, 10), 0)\n        im.im.color_lut_3d('RGBA', Image.LINEAR,\n            *self.generate_unit_table(4, 3))\n\n        im = Image.new('RGB', (10, 10), 0)\n        im.im.color_lut_3d('HSV', Image.LINEAR,\n            *self.generate_unit_table(3, 3))\n\n        im = Image.new('RGB', (10, 10), 0)\n        im.im.color_lut_3d('RGBA', Image.LINEAR,\n            *self.generate_unit_table(4, 3))\n\n    def test_units(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n\n        # Fast test with small cubes\n        for size in [2, 3, 5, 7, 11, 16, 17]:\n            self.assert_image_equal(im, im._new(\n                im.im.color_lut_3d('RGB', Image.LINEAR,\n                    *self.generate_unit_table(3, size))))\n\n        # Not so fast\n        self.assert_image_equal(im, im._new(\n            im.im.color_lut_3d('RGB', Image.LINEAR,\n                *self.generate_unit_table(3, (2, 2, 65)))))\n\n    def test_units_4channels(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n\n        # Red channel copied to alpha\n        self.assert_image_equal(\n            Image.merge('RGBA', (im.split()*2)[:4]),\n            im._new(im.im.color_lut_3d('RGBA', Image.LINEAR,\n                *self.generate_unit_table(4, 17))))\n\n    def test_copy_alpha_channel(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGBA', [g, g.transpose(Image.ROTATE_90),\n                                  g.transpose(Image.ROTATE_180),\n                                  g.transpose(Image.ROTATE_270)])\n\n        self.assert_image_equal(im, im._new(\n            im.im.color_lut_3d('RGBA', Image.LINEAR,\n                *self.generate_unit_table(3, 17))))\n\n    def test_channels_order(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n\n        # Reverse channels by splitting and using table\n        self.assert_image_equal(\n            Image.merge('RGB', im.split()[::-1]),\n            im._new(im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2, [\n                    0, 0, 0,  0, 0, 1,\n                    0, 1, 0,  0, 1, 1,\n\n                    1, 0, 0,  1, 0, 1,\n                    1, 1, 0,  1, 1, 1,\n                ])))\n\n    def test_overflow(self):\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n\n        transformed = im._new(im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2,\n                [\n                    -1, -1, -1,   2, -1, -1,\n                    -1,  2, -1,   2,  2, -1,\n\n                    -1, -1,  2,   2, -1,  2,\n                    -1,  2,  2,   2,  2,  2,\n                ])).load()\n        self.assertEqual(transformed[0, 0], (0, 0, 255))\n        self.assertEqual(transformed[50, 50], (0, 0, 255))\n        self.assertEqual(transformed[255, 0], (0, 255, 255))\n        self.assertEqual(transformed[205, 50], (0, 255, 255))\n        self.assertEqual(transformed[0, 255], (255, 0, 0))\n        self.assertEqual(transformed[50, 205], (255, 0, 0))\n        self.assertEqual(transformed[255, 255], (255, 255, 0))\n        self.assertEqual(transformed[205, 205], (255, 255, 0))\n\n        transformed = im._new(im.im.color_lut_3d('RGB', Image.LINEAR,\n                3, 2, 2, 2,\n                [\n                    -3, -3, -3,   5, -3, -3,\n                    -3,  5, -3,   5,  5, -3,\n\n                    -3, -3,  5,   5, -3,  5,\n                    -3,  5,  5,   5,  5,  5,\n                ])).load()\n        self.assertEqual(transformed[0, 0], (0, 0, 255))\n        self.assertEqual(transformed[50, 50], (0, 0, 255))\n        self.assertEqual(transformed[255, 0], (0, 255, 255))\n        self.assertEqual(transformed[205, 50], (0, 255, 255))\n        self.assertEqual(transformed[0, 255], (255, 0, 0))\n        self.assertEqual(transformed[50, 205], (255, 0, 0))\n        self.assertEqual(transformed[255, 255], (255, 255, 0))\n        self.assertEqual(transformed[205, 205], (255, 255, 0))\n\n\nclass TestColorLut3DFilter(PillowTestCase):\n    def test_wrong_args(self):\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT(\"small\", [1])\n\n        with self.assertRaisesRegexp(ValueError, \"should be either an integer\"):\n            ImageFilter.Color3DLUT((11, 11), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 1), [1])\n\n        with self.assertRaisesRegexp(ValueError, r\"in \\[2, 65\\] range\"):\n            ImageFilter.Color3DLUT((11, 11, 66), [1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])\n\n        with self.assertRaisesRegexp(ValueError, \"table should have .+ items\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)\n\n    def test_convert_table(self):\n        lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [\n            (0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),\n            (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.table, list(range(24)))\n\n        lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,\n            channels=4)\n\n    def test_generate(self):\n        lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0,  0.25, 0.0, 0.0,  0.5, 0.0, 0.0,  0.75, 0.0, 0.0,\n            1.0, 0.0, 0.0,  0.0, 0.25, 0.0,  0.25, 0.25, 0.0,  0.5, 0.25, 0.0])\n\n        g = Image.linear_gradient('L')\n        im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),\n                                 g.transpose(Image.ROTATE_180)])\n        self.assertEqual(im, im.filter(lut))\n\n        lut = ImageFilter.Color3DLUT.generate(5, channels=4,\n            callback=lambda r, g, b: (b, r, g, (r+g+b) / 2))\n        self.assertEqual(tuple(lut.size), (5, 5, 5))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:24], [\n            0.0, 0.0, 0.0, 0.0,  0.0, 0.25, 0.0, 0.125,  0.0, 0.5, 0.0, 0.25,\n            0.0, 0.75, 0.0, 0.375,  0.0, 1.0, 0.0, 0.5,  0.0, 0.0, 0.25, 0.125])\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 3\"):\n            ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))\n\n        with self.assertRaisesRegexp(ValueError, \"should have a length of 4\"):\n            ImageFilter.Color3DLUT.generate(5, channels=4,\n                callback=lambda r, g, b: (r, g, b))\n\n    def test_from_cube_file_minimal(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \"LUT_3D_SIZE 2\",\n            \"\",\n            \"0    0 0.031\",\n            \"0.96 0 0.031\",\n            \"0    1 0.031\",\n            \"0.96 1 0.031\",\n            \"0    0 0.931\",\n            \"0.96 0 0.931\",\n            \"0    1 0.931\",\n            \"0.96 1 0.931\",\n        ])\n        self.assertEqual(tuple(lut.size), (2, 2, 2))\n        self.assertEqual(lut.name, \"Color 3D LUT\")\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n    def test_from_cube_file_parser(self):\n        lut = ImageFilter.Color3DLUT.from_cube_file([\n            \" # Comment\",\n            'TITLE \"LUT name from file\"',\n            \"  LUT_3D_SIZE 2 3 4\",\n            \" SKIP THIS\",\n            \" # Comment\",\n            \"CHANNELS 4\",\n            \"\",\n        ] + [\n            \" # Comment\",\n            \"0    0 0.031 1\",\n            \"0.96 0 0.031 1\",\n            \"\",\n            \"0    1 0.031 1\",\n            \"0.96 1 0.031 1\",\n        ] * 6, target_mode='HSV')\n        self.assertEqual(tuple(lut.size), (2, 3, 4))\n        self.assertEqual(lut.channels, 4)\n        self.assertEqual(lut.name, \"LUT name from file\")\n        self.assertEqual(lut.mode, 'HSV')\n        self.assertEqual(lut.table[:12], [\n            0, 0, 0.031, 1,  0.96, 0, 0.031, 1,  0, 1, 0.031, 1])\n\n    def test_from_cube_file_errors(self):\n        with self.assertRaisesRegexp(ValueError, \"No size found\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'TITLE \"LUT name from file\"',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"number of colors on line 4\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0    0 0.031\",\n                \"0.96 0 0.031 1\",\n            ] * 3)\n\n        with self.assertRaisesRegexp(ValueError, \"Not a number on line 3\"):\n            lut = ImageFilter.Color3DLUT.from_cube_file([\n                'LUT_3D_SIZE 2',\n                \"\",\n            ] + [\n                \"0  green 0.031\",\n                \"0.96 0 0.031\",\n            ] * 3)\n\n    def test_from_cube_file_filename(self):\n        with NamedTemporaryFile() as f:\n            f.write(\n                \"LUT_3D_SIZE 2\\n\"\n                \"\\n\"\n                \"0    0 0.031\\n\"\n                \"0.96 0 0.031\\n\"\n                \"0    1 0.031\\n\"\n                \"0.96 1 0.031\\n\"\n                \"0    0 0.931\\n\"\n                \"0.96 0 0.931\\n\"\n                \"0    1 0.931\\n\"\n                \"0.96 1 0.931\\n\"\n            )\n            f.flush()\n            lut = ImageFilter.Color3DLUT.from_cube_file(f.name)\n            self.assertEqual(tuple(lut.size), (2, 2, 2))\n            self.assertEqual(lut.name, \"Color 3D LUT\")\n            self.assertEqual(lut.table[:12], [\n                0, 0, 0.031,  0.96, 0, 0.031,  0, 1, 0.031,  0.96, 1, 0.031])\n\n\nif __name__ == '__main__':\n    unittest.main()\n",
        "#!/usr/bin/env python\nimport unittest\nimport sys\nimport time\nimport traceback\nimport platform\nimport os\n\n\nclass PytestLikeResult(unittest.TestResult):\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.start_time = None\n        # Store (test, outcome, info) for each test:\n        #   outcome ∈ { \"passed\", \"failed\", \"error\", \"skipped\" }\n        #   info can hold the exception or skip reason, etc.\n        self.results = []\n\n    def startTestRun(self):\n        \"\"\"Called once before all tests.\"\"\"\n        self.start_time = time.time()\n        # Print a header similar to pytest\n        print(\"=\" * 29 + \" test session starts \" + \"=\" * 29)\n        # You can customize the platform/versions/paths as you like:\n        print(\n            f\"platform {platform.system().lower()} -- Python {platform.python_version()}\"\n        )\n        print(f\"rootdir: {os.path.abspath(os.curdir)}\")\n\n    def stopTestRun(self):\n        \"\"\"Called once after all tests are done.\"\"\"\n        elapsed = time.time() - self.start_time\n        print()  # blank line after final dot\n\n        # Summarize\n        ntests = len(self.results)\n        print(f\"collected {ntests} items\")\n\n        # Show details of failures/errors\n        failures = [r for r in self.results if r[1] == \"failed\"]\n        errors = [r for r in self.results if r[1] == \"error\"]\n\n        if failures:\n            print(\"\\n\" + \"=\" * 35 + \" FAILURES \" + \"=\" * 35)\n            for test, outcome, err_info in failures:\n                test = test.split(\"::\")\n                if len(test) == 3:\n                    test = f\"{test[1]}.{test[2]}\"\n                else:\n                    test = f\"{test[1]}\"\n                print(f\"__________ {test} __________\")\n                self._print_traceback(err_info)\n        if errors:\n            print(\"\\n\" + \"=\" * 35 + \" ERRORS \" + \"=\" * 37)\n            for test, outcome, err_info in errors:\n                test = test.split(\"::\")\n                if len(test) == 3:\n                    test = f\"{test[1]}.{test[2]}\"\n                else:\n                    test = f\"{test[1]}\"\n                print(f\"__________ {test} __________\")\n                self._print_traceback(err_info)\n\n        # Optional short summary lines for passes/fails/skips\n        print(\"\\n==================== short test summary info ====================\")\n        for test, outcome, info in self.results:\n            if outcome in (\"passed\", \"failed\", \"error\", \"skipped\"):\n                print(f\"{outcome.upper()} {test}\")\n\n        # Final one-line summary: “1 failed, 1 errors, 10 passed in 2.04s”\n        passed_count = sum(1 for r in self.results if r[1] == \"passed\")\n        failed_count = len(failures)\n        error_count = len(errors)\n        skipped_count = sum(1 for r in self.results if r[1] == \"skipped\")\n\n        summary_bits = []\n        if failed_count:\n            summary_bits.append(f\"{failed_count} failed\")\n        if error_count:\n            summary_bits.append(f\"{error_count} error{'s' if error_count != 1 else ''}\")\n        if passed_count:\n            summary_bits.append(f\"{passed_count} passed\")\n        if skipped_count:\n            summary_bits.append(f\"{skipped_count} skipped\")\n\n        summary_str = \", \".join(summary_bits) if summary_bits else \"no tests run\"\n        print(\n            f\"=================== {summary_str} in {elapsed:.2f}s ===================\"\n        )\n\n    def startTest(self, test):\n        \"\"\"Called right before each test method.\"\"\"\n        super().startTest(test)\n        # Print a dot or some indicator\n        print(\".\", end=\"\", flush=True)\n\n    def addSuccess(self, test):\n        super().addSuccess(test)\n        self.results.append((self._test_id(test), \"passed\", None))\n\n    def addFailure(self, test, err):\n        super().addFailure(test, err)\n        self.results.append((self._test_id(test), \"failed\", err))\n\n    def addError(self, test, err):\n        super().addError(test, err)\n        self.results.append((self._test_id(test), \"error\", err))\n\n    def addSkip(self, test, reason):\n        super().addSkip(test, reason)\n        self.results.append((self._test_id(test), \"skipped\", reason))\n\n    def _print_traceback(self, err_info):\n        \"\"\"Helper to print the traceback like pytest does.\"\"\"\n        if isinstance(err_info, tuple) and len(err_info) == 3:\n            exc_type, exc_value, tb = err_info\n            traceback.print_exception(exc_type, exc_value, tb, file=sys.stdout)\n        else:\n            print(str(err_info))\n\n    def _test_id(self, test):\n        try:\n            return f\"{test.__class__.__module__}::{test.__class__.__name__}::{test._testMethodName}\"\n        except AttributeError:\n            # Fallback for _ErrorHolder objects\n            return f\"{test.__class__.__module__}::{test.__class__.__name__}\"\n\n\nclass PytestLikeRunner(unittest.TextTestRunner):\n    \"\"\"A custom TextTestRunner that uses the PytestLikeResult.\"\"\"\n\n    resultclass = PytestLikeResult\n\n    def run(self, test):\n        result = self._makeResult()\n        # Overriding run to ensure we call startTestRun/stopTestRun\n        result.startTestRun()\n        test(result)\n        result.stopTestRun()\n        return result\n\n\ndef main():\n    loader = unittest.TestLoader()\n    suite = loader.discover(\"r2e_tests\")  # discover tests in r2e_tests/\n    runner = PytestLikeRunner(verbosity=0)\n    result = runner.run(suite)\n    # Exit with code 0 if all tests passed/skipped, 1 if there were fails/errors\n    sys.exit(not result.wasSuccessful())\n\n\nif __name__ == \"__main__\":\n    main()\n"
    ],
    "test_file_names": [
        "test_1.py",
        "unittest_custom_runner.py"
    ],
    "setup_res_code": 0,
    "setup_res_stdout": "Starting Pillow installation attempts...\nVerifying Pillow installation...\n✅ Pillow installation successful!\nSuccessfully installed Pillow\n",
    "setup_res_stderr": "Using CPython 3.9.21\nCreating virtual environment at: .venv\nActivate with: source .venv/bin/activate\nResolved 12 packages in 10ms\nInstalled 12 packages in 93ms\n + coverage==7.6.10\n + exceptiongroup==1.2.2\n + iniconfig==2.0.0\n + packaging==24.2\n + pluggy==1.5.0\n + pyqt5==5.15.11\n + pyqt5-qt5==5.15.16\n + pyqt5-sip==12.16.1\n + pytest==8.3.4\n + pytest-cov==6.0.0\n + setuptools==75.8.0\n + tomli==2.2.1\nResolved 1 package in 1.06s\nPrepared 1 package in 14.97s\nInstalled 1 package in 1ms\n + pillow==5.1.0.dev0 (from file:///home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_e304a0d501315b95c71ea16c532216f391db240f)\n",
    "new_commit_res_code": 1,
    "new_commit_res_stdout": "============================= test session starts =============================\nplatform linux -- Python 3.9.21\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_e304a0d501315b95c71ea16c532216f391db240f\n................\ncollected 16 items\n\n=================================== ERRORS =====================================\n__________ TestColorLut3DFilter.test_from_cube_file_filename __________\nTraceback (most recent call last):\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/case.py\", line 59, in testPartExecutor\n    yield\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/case.py\", line 592, in run\n    self._callTestMethod(testMethod)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/case.py\", line 550, in _callTestMethod\n    method()\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_e304a0d501315b95c71ea16c532216f391db240f/r2e_tests/test_1.py\", line 370, in test_from_cube_file_filename\n    f.write(\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/tempfile.py\", line 494, in func_wrapper\n    return func(*args, **kwargs)\nTypeError: a bytes-like object is required, not 'str'\n\n==================== short test summary info ====================\nPASSED test_1::TestColorLut3DCoreAPI::test_channels_order\nPASSED test_1::TestColorLut3DCoreAPI::test_copy_alpha_channel\nPASSED test_1::TestColorLut3DCoreAPI::test_correct_args\nPASSED test_1::TestColorLut3DCoreAPI::test_correct_mode\nPASSED test_1::TestColorLut3DCoreAPI::test_overflow\nPASSED test_1::TestColorLut3DCoreAPI::test_units\nPASSED test_1::TestColorLut3DCoreAPI::test_units_4channels\nPASSED test_1::TestColorLut3DCoreAPI::test_wrong_args\nPASSED test_1::TestColorLut3DCoreAPI::test_wrong_mode\nPASSED test_1::TestColorLut3DFilter::test_convert_table\nPASSED test_1::TestColorLut3DFilter::test_from_cube_file_errors\nERROR test_1::TestColorLut3DFilter::test_from_cube_file_filename\nPASSED test_1::TestColorLut3DFilter::test_from_cube_file_minimal\nPASSED test_1::TestColorLut3DFilter::test_from_cube_file_parser\nPASSED test_1::TestColorLut3DFilter::test_generate\nPASSED test_1::TestColorLut3DFilter::test_wrong_args\n=================== 1 error, 15 passed in 0.11s ===================\n",
    "new_commit_res_stderr": "",
    "old_commit_res_code": 1,
    "old_commit_res_stdout": "============================= test session starts =============================\nplatform linux -- Python 3.9.21\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_e304a0d501315b95c71ea16c532216f391db240f\n................\ncollected 16 items\n\n=================================== FAILURES ===================================\n__________ TestColorLut3DFilter.test_wrong_args __________\nTraceback (most recent call last):\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_e304a0d501315b95c71ea16c532216f391db240f/src/PIL/ImageFilter.py\", line 355, in _check_size\n    _, _, _ = size\nValueError: too many values to unpack (expected 3)\n\nDuring handling of the above exception, another exception occurred:\n\nValueError: Size should be an integer either tuple of three integers.\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/case.py\", line 59, in testPartExecutor\n    yield\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/case.py\", line 592, in run\n    self._callTestMethod(testMethod)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/case.py\", line 550, in _callTestMethod\n    method()\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_e304a0d501315b95c71ea16c532216f391db240f/r2e_tests/test_1.py\", line 233, in test_wrong_args\n    ImageFilter.Color3DLUT(\"small\", [1])\nAssertionError: \"should be either an integer\" does not match \"Size should be an integer either tuple of three integers.\"\n\n=================================== ERRORS =====================================\n__________ TestColorLut3DFilter.test_from_cube_file_filename __________\nTraceback (most recent call last):\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/case.py\", line 59, in testPartExecutor\n    yield\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/case.py\", line 592, in run\n    self._callTestMethod(testMethod)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/case.py\", line 550, in _callTestMethod\n    method()\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_e304a0d501315b95c71ea16c532216f391db240f/r2e_tests/test_1.py\", line 370, in test_from_cube_file_filename\n    f.write(\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/tempfile.py\", line 494, in func_wrapper\n    return func(*args, **kwargs)\nTypeError: a bytes-like object is required, not 'str'\n\n==================== short test summary info ====================\nPASSED test_1::TestColorLut3DCoreAPI::test_channels_order\nPASSED test_1::TestColorLut3DCoreAPI::test_copy_alpha_channel\nPASSED test_1::TestColorLut3DCoreAPI::test_correct_args\nPASSED test_1::TestColorLut3DCoreAPI::test_correct_mode\nPASSED test_1::TestColorLut3DCoreAPI::test_overflow\nPASSED test_1::TestColorLut3DCoreAPI::test_units\nPASSED test_1::TestColorLut3DCoreAPI::test_units_4channels\nPASSED test_1::TestColorLut3DCoreAPI::test_wrong_args\nPASSED test_1::TestColorLut3DCoreAPI::test_wrong_mode\nPASSED test_1::TestColorLut3DFilter::test_convert_table\nPASSED test_1::TestColorLut3DFilter::test_from_cube_file_errors\nERROR test_1::TestColorLut3DFilter::test_from_cube_file_filename\nPASSED test_1::TestColorLut3DFilter::test_from_cube_file_minimal\nPASSED test_1::TestColorLut3DFilter::test_from_cube_file_parser\nPASSED test_1::TestColorLut3DFilter::test_generate\nFAILED test_1::TestColorLut3DFilter::test_wrong_args\n=================== 1 failed, 1 error, 14 passed in 0.10s ===================\n",
    "old_commit_res_stderr": ""
}
Tests/test_color_lut.py src/PIL/ImageFilter.py
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]

**Title:** Unclear error message for invalid size parameter in Color3DLUT

**Description:**
When initializing the `Color3DLUT` class with an invalid `size` parameter, the raised `ValueError` message is unclear and does not accurately describe the expected input format. Providing a `size` that is neither an integer nor a tuple of three integers results in a confusing error message.

**Example Code:**
```python
from PIL import ImageFilter

# Attempt to create Color3DLUT with invalid size
lut = ImageFilter.Color3DLUT("small", [1])
```

**Expected Behavior:**
A `ValueError` should be raised with a clear message indicating that the `size` must be either an integer or a tuple of three integers.

**Actual Behavior:**
A `ValueError` is raised with the message:
```
ValueError: Size should be an integer either tuple of three integers.
```
The absence of the word "or" between the options makes the message unclear.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### src/PIL/ImageFilter.py
#
# The Python Imaging Library.
# $Id$
#
# standard filters
#
# History:
# 1995-11-27 fl   Created
# 2002-06-08 fl   Added rank and mode filters
# 2003-09-15 fl   Fixed rank calculation in rank filter; added expand call
#
# Copyright (c) 1997-2003 by Secret Labs AB.
# Copyright (c) 1995-2002 by Fredrik Lundh.
#
# See the README file for information on usage and redistribution.
#

import functools

from ._util import isPath


class Filter(object):
    pass


class MultibandFilter(Filter):
    pass


class Kernel(MultibandFilter):
    """
    Create a convolution kernel.  The current version only
    supports 3x3 and 5x5 integer and floating point kernels.

    In the current version, kernels can only be applied to
    "L" and "RGB" images.

    :param size: Kernel size, given as (width, height). In the current
                    version, this must be (3,3) or (5,5).
    :param kernel: A sequence containing kernel weights.
    :param scale: Scale factor. If given, the result for each pixel is
                    divided by this value.  the default is the sum of the
                    kernel weights.
    :param offset: Offset. If given, this value is added to the result,
                    after it has been divided by the scale factor.
    """
    name = "Kernel"

    def __init__(self, size, kernel, scale=None, offset=0):
        if scale is None:
            # default scale is sum of kernel
            scale = functools.reduce(lambda a, b: a+b, kernel)
        if size[0] * size[1] != len(kernel):
            raise ValueError("not enough coefficients in kernel")
        self.filterargs = size, scale, offset, kernel

    def filter(self, image):
        if image.mode == "P":
            raise ValueError("cannot filter palette images")
        return image.filter(*self.filterargs)


class BuiltinFilter(Kernel):
    def __init__(self):
        pass


class RankFilter(Filter):
    """
    Create a rank filter.  The rank filter sorts all pixels in
    a window of the given size, and returns the **rank**'th value.

    :param size: The kernel size, in pixels.
    :param rank: What pixel value to pick.  Use 0 for a min filter,
                 ``size * size / 2`` for a median filter, ``size * size - 1``
                 for a max filter, etc.
    """
    name = "Rank"

    def __init__(self, size, rank):
        self.size = size
        self.rank = rank

    def filter(self, image):
        if image.mode == "P":
            raise ValueError("cannot filter palette images")
        image = image.expand(self.size//2, self.size//2)
        return image.rankfilter(self.size, self.rank)


class MedianFilter(RankFilter):
    """
    Create a median filter. Picks the median pixel value in a window with the
    given size.

    :param size: The kernel size, in pixels.
    """
    name = "Median"

    def __init__(self, size=3):
        self.size = size
        self.rank = size*size//2


class MinFilter(RankFilter):
    """
    Create a min filter.  Picks the lowest pixel value in a window with the
    given size.

    :param size: The kernel size, in pixels.
    """
    name = "Min"

    def __init__(self, size=3):
        self.size = size
        self.rank = 0


class MaxFilter(RankFilter):
    """
    Create a max filter.  Picks the largest pixel value in a window with the
    given size.

    :param size: The kernel size, in pixels.
    """
    name = "Max"

    def __init__(self, size=3):
        self.size = size
        self.rank = size*size-1


class ModeFilter(Filter):
    """
    Create a mode filter. Picks the most frequent pixel value in a box with the
    given size.  Pixel values that occur only once or twice are ignored; if no
    pixel value occurs more than twice, the original pixel value is preserved.

    :param size: The kernel size, in pixels.
    """
    name = "Mode"

    def __init__(self, size=3):
        self.size = size

    def filter(self, image):
        return image.modefilter(self.size)


class GaussianBlur(MultibandFilter):
    """Gaussian blur filter.

    :param radius: Blur radius.
    """
    name = "GaussianBlur"

    def __init__(self, radius=2):
        self.radius = radius

    def filter(self, image):
        return image.gaussian_blur(self.radius)


class BoxBlur(MultibandFilter):
    """Blurs the image by setting each pixel to the average value of the pixels
    in a square box extending radius pixels in each direction.
    Supports float radius of arbitrary size. Uses an optimized implementation
    which runs in linear time relative to the size of the image
    for any radius value.

    :param radius: Size of the box in one direction. Radius 0 does not blur,
                   returns an identical image. Radius 1 takes 1 pixel
                   in each direction, i.e. 9 pixels in total.
    """
    name = "BoxBlur"

    def __init__(self, radius):
        self.radius = radius

    def filter(self, image):
        return image.box_blur(self.radius)


class UnsharpMask(MultibandFilter):
    """Unsharp mask filter.

    See Wikipedia's entry on `digital unsharp masking`_ for an explanation of
    the parameters.

    :param radius: Blur Radius
    :param percent: Unsharp strength, in percent
    :param threshold: Threshold controls the minimum brightness change that
      will be sharpened

    .. _digital unsharp masking: https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking

    """
    name = "UnsharpMask"

    def __init__(self, radius=2, percent=150, threshold=3):
        self.radius = radius
        self.percent = percent
        self.threshold = threshold

    def filter(self, image):
        return image.unsharp_mask(self.radius, self.percent, self.threshold)


class BLUR(BuiltinFilter):
    name = "Blur"
    filterargs = (5, 5), 16, 0, (
        1,  1,  1,  1,  1,
        1,  0,  0,  0,  1,
        1,  0,  0,  0,  1,
        1,  0,  0,  0,  1,
        1,  1,  1,  1,  1
        )


class CONTOUR(BuiltinFilter):
    name = "Contour"
    filterargs = (3, 3), 1, 255, (
        -1, -1, -1,
        -1,  8, -1,
        -1, -1, -1
        )


class DETAIL(BuiltinFilter):
    name = "Detail"
    filterargs = (3, 3), 6, 0, (
        0, -1,  0,
        -1, 10, -1,
        0, -1,  0
        )


class EDGE_ENHANCE(BuiltinFilter):
    name = "Edge-enhance"
    filterargs = (3, 3), 2, 0, (
        -1, -1, -1,
        -1, 10, -1,
        -1, -1, -1
        )


class EDGE_ENHANCE_MORE(BuiltinFilter):
    name = "Edge-enhance More"
    filterargs = (3, 3), 1, 0, (
        -1, -1, -1,
        -1,  9, -1,
        -1, -1, -1
        )


class EMBOSS(BuiltinFilter):
    name = "Emboss"
    filterargs = (3, 3), 1, 128, (
        -1,  0,  0,
        0,  1,  0,
        0,  0,  0
        )


class FIND_EDGES(BuiltinFilter):
    name = "Find Edges"
    filterargs = (3, 3), 1, 0, (
        -1, -1, -1,
        -1,  8, -1,
        -1, -1, -1
        )


class SHARPEN(BuiltinFilter):
    name = "Sharpen"
    filterargs = (3, 3), 16, 0, (
        -2, -2, -2,
        -2, 32, -2,
        -2, -2, -2
        )


class SMOOTH(BuiltinFilter):
    name = "Smooth"
    filterargs = (3, 3), 13, 0, (
        1,  1,  1,
        1,  5,  1,
        1,  1,  1
        )


class SMOOTH_MORE(BuiltinFilter):
    name = "Smooth More"
    filterargs = (5, 5), 100, 0, (
        1,  1,  1,  1,  1,
        1,  5,  5,  5,  1,
        1,  5, 44,  5,  1,
        1,  5,  5,  5,  1,
        1,  1,  1,  1,  1
        )


class Color3DLUT(MultibandFilter):
    """Three-dimensional color lookup table.

    Transforms 3-channel pixels using the values of the channels as coordinates
    in the 3D lookup table and interpolating the nearest elements.

    This method allows you to apply almost any color transformation
    in constant time by using pre-calculated decimated tables.

    :param size: Size of the table. One int or tuple of (int, int, int).
                 Minimal size in any dimension is 2, maximum is 65.
    :param table: Flat lookup table. A list of ``channels * size**3``
                  float elements or a list of ``size**3`` channels-sized
                  tuples with floats. Channels are changed first,
                  then first dimension, then second, then third.
                  Value 0.0 corresponds lowest value of output, 1.0 highest.
    :param channels: Number of channels in the table. Could be 3 or 4.
                     Default is 3.
    :param target_mode: A mode for the result image. Should have not less
                        than ``channels`` channels. Default is ``None``,
                        which means that mode wouldn't be changed.
    """
    name = "Color 3D LUT"

    def __init__(self, size, table, channels=3, target_mode=None):
        self.size = size = self._check_size(size)
        self.channels = channels
        self.mode = target_mode

        table = list(table)
        # Convert to a flat list
        if table and isinstance(table[0], (list, tuple)):
            table, raw_table = [], table
            for pixel in raw_table:
                if len(pixel) != channels:
                    raise ValueError("The elements of the table should have "
                                     "a length of {}.".format(channels))
                for color in pixel:
                    table.append(color)

        if len(table) != channels * size[0] * size[1] * size[2]:
            raise ValueError(
                "The table should have channels * size**3 float items "
                "either size**3 items of channels-sized tuples with floats. "
                "Table size: {}x{}x{}. Table length: {}".format(
                    size[0], size[1], size[2], len(table)))
        self.table = table

    @staticmethod
    def _check_size(size):
        try:
            _, _, _ = size
        except ValueError:
            raise ValueError("Size should be an integer either "
                             "tuple of three integers.")
        except TypeError:
            size = (size, size, size)
        size = [int(x) for x in size]
        for size1D in size:
            if not 2 <= size1D <= 65:
                raise ValueError("Size should be in [2, 65] range.")
        return size

    @classmethod
    def generate(cls, size, callback, channels=3, target_mode=None):
        """Generates new LUT using provided callback.

        :param size: Size of the table. Passed to the constructor.
        :param callback: Function with three parameters which correspond
                         three color channels. Will be called ``size**3``
                         times with values from 0.0 to 1.0 and should return
                         a tuple with ``channels`` elements.
        :param channels: Passed to the constructor.
        :param target_mode: Passed to the constructor.
        """
        size1D, size2D, size3D = cls._check_size(size)
        table = []
        for b in range(size3D):
            for g in range(size2D):
                for r in range(size1D):
                    table.append(callback(
                        r / float(size1D-1),
                        g / float(size2D-1),
                        b / float(size3D-1)))

        return cls((size1D, size2D, size3D), table, channels, target_mode)

    @classmethod
    def from_cube_file(cls, lines, target_mode=None):
        name, size = None, None
        channels = 3
        file = None

        if isPath(lines):
            file = lines = open(lines, 'rt')

        try:
            iterator = iter(lines)

            for i, line in enumerate(iterator, 1):
                line = line.strip()
                if not line:
                    break
                if line.startswith('TITLE "'):
                    name = line.split('"')[1]
                    continue
                if line.startswith('LUT_3D_SIZE '):
                    size = [int(x) for x in line.split()[1:]]
                    if len(size) == 1:
                        size = size[0]
                    continue
                if line.startswith('CHANNELS '):
                    channels = int(line.split()[1])

            if size is None:
                raise ValueError('No size found in the file')

            table = []
            for i, line in enumerate(iterator, i + 1):
                line = line.strip()
                if not line or line.startswith('#'):
                    continue
                try:
                    pixel = [float(x) for x in line.split()]
                except ValueError:
                    raise ValueError("Not a number on line {}".format(i))
                if len(pixel) != channels:
                    raise ValueError(
                        "Wrong number of colors on line {}".format(i))
                table.append(tuple(pixel))
        finally:
            if file is not None:
                file.close()

        instance = cls(size, table, channels, target_mode)
        if name is not None:
            instance.name = name
        return instance

    def filter(self, image):
        from . import Image

        return image.color_lut_3d(
            self.mode or image.mode, Image.LINEAR, self.channels,
            self.size[0], self.size[1], self.size[2], self.table)

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
[ISSUE]

**Title:** Unclear error message for invalid size parameter in Color3DLUT

**Description:**
When initializing the `Color3DLUT` class with an invalid `size` parameter, the raised `ValueError` message is unclear and does not accurately describe the expected input format. Providing a `size` that is neither an integer nor a tuple of three integers results in a confusing error message.

**Example Code:**
```python
from PIL import ImageFilter

# Attempt to create Color3DLUT with invalid size
lut = ImageFilter.Color3DLUT("small", [1])
```

**Expected Behavior:**
A `ValueError` should be raised with a clear message indicating that the `size` must be either an integer or a tuple of three integers.

**Actual Behavior:**
A `ValueError` is raised with the message:
```
ValueError: Size should be an integer either tuple of three integers.
```
The absence of the word "or" between the options makes the message unclear.

[/ISSUE]
{
    "TestColorLut3DCoreAPI.test_channels_order": "PASSED",
    "TestColorLut3DCoreAPI.test_copy_alpha_channel": "PASSED",
    "TestColorLut3DCoreAPI.test_correct_args": "PASSED",
    "TestColorLut3DCoreAPI.test_correct_mode": "PASSED",
    "TestColorLut3DCoreAPI.test_overflow": "PASSED",
    "TestColorLut3DCoreAPI.test_units": "PASSED",
    "TestColorLut3DCoreAPI.test_units_4channels": "PASSED",
    "TestColorLut3DCoreAPI.test_wrong_args": "PASSED",
    "TestColorLut3DCoreAPI.test_wrong_mode": "PASSED",
    "TestColorLut3DFilter.test_convert_table": "PASSED",
    "TestColorLut3DFilter.test_from_cube_file_errors": "PASSED",
    "TestColorLut3DFilter.test_from_cube_file_filename": "ERROR",
    "TestColorLut3DFilter.test_from_cube_file_minimal": "PASSED",
    "TestColorLut3DFilter.test_from_cube_file_parser": "PASSED",
    "TestColorLut3DFilter.test_generate": "PASSED",
    "TestColorLut3DFilter.test_wrong_args": "PASSED"
}
diff --git a/src/PIL/ImageFilter.py b/src/PIL/ImageFilter.py
index 916c24cae..4fb3db381 100644
--- a/src/PIL/ImageFilter.py
+++ b/src/PIL/ImageFilter.py
@@ -343,8 +343,8 @@ class Color3DLUT(MultibandFilter):
 
         if len(table) != channels * size[0] * size[1] * size[2]:
             raise ValueError(
-                "The table should have channels * size**3 float items "
-                "either size**3 items of channels-sized tuples with floats. "
+                "The table should have either channels * size**3 float items "
+                "or size**3 items of channels-sized tuples with floats. "
                 "Table size: {}x{}x{}. Table length: {}".format(
                     size[0], size[1], size[2], len(table)))
         self.table = table
@@ -354,8 +354,8 @@ class Color3DLUT(MultibandFilter):
         try:
             _, _, _ = size
         except ValueError:
-            raise ValueError("Size should be an integer either "
-                             "tuple of three integers.")
+            raise ValueError("Size should be either an integer or "
+                             "a tuple of three integers.")
         except TypeError:
             size = (size, size, size)
         size = [int(x) for x in size]
 

{"src/PIL/ImageFilter.py": "#\n# The Python Imaging Library.\n# $Id$\n#\n# standard filters\n#\n# History:\n# 1995-11-27 fl   Created\n# 2002-06-08 fl   Added rank and mode filters\n# 2003-09-15 fl   Fixed rank calculation in rank filter; added expand call\n#\n# Copyright (c) 1997-2003 by Secret Labs AB.\n# Copyright (c) 1995-2002 by Fredrik Lundh.\n#\n# See the README file for information on usage and redistribution.\n#\n\nimport functools\n\nfrom ._util import isPath\n\n\nclass Filter(object):\n    pass\n\n\nclass MultibandFilter(Filter):\n    pass\n\n\nclass Kernel(MultibandFilter):\n    \"\"\"\n    Create a convolution kernel.  The current version only\n    supports 3x3 and 5x5 integer and floating point kernels.\n\n    In the current version, kernels can only be applied to\n    \"L\" and \"RGB\" images.\n\n    :param size: Kernel size, given as (width, height). In the current\n                    version, this must be (3,3) or (5,5).\n    :param kernel: A sequence containing kernel weights.\n    :param scale: Scale factor. If given, the result for each pixel is\n                    divided by this value.  the default is the sum of the\n                    kernel weights.\n    :param offset: Offset. If given, this value is added to the result,\n                    after it has been divided by the scale factor.\n    \"\"\"\n    name = \"Kernel\"\n\n    def __init__(self, size, kernel, scale=None, offset=0):\n        if scale is None:\n            # default scale is sum of kernel\n            scale = functools.reduce(lambda a, b: a+b, kernel)\n        if size[0] * size[1] != len(kernel):\n            raise ValueError(\"not enough coefficients in kernel\")\n        self.filterargs = size, scale, offset, kernel\n\n    def filter(self, image):\n        if image.mode == \"P\":\n            raise ValueError(\"cannot filter palette images\")\n        return image.filter(*self.filterargs)\n\n\nclass BuiltinFilter(Kernel):\n    def __init__(self):\n        pass\n\n\nclass RankFilter(Filter):\n    \"\"\"\n    Create a rank filter.  The rank filter sorts all pixels in\n    a window of the given size, and returns the **rank**'th value.\n\n    :param size: The kernel size, in pixels.\n    :param rank: What pixel value to pick.  Use 0 for a min filter,\n                 ``size * size / 2`` for a median filter, ``size * size - 1``\n                 for a max filter, etc.\n    \"\"\"\n    name = \"Rank\"\n\n    def __init__(self, size, rank):\n        self.size = size\n        self.rank = rank\n\n    def filter(self, image):\n        if image.mode == \"P\":\n            raise ValueError(\"cannot filter palette images\")\n        image = image.expand(self.size//2, self.size//2)\n        return image.rankfilter(self.size, self.rank)\n\n\nclass MedianFilter(RankFilter):\n    \"\"\"\n    Create a median filter. Picks the median pixel value in a window with the\n    given size.\n\n    :param size: The kernel size, in pixels.\n    \"\"\"\n    name = \"Median\"\n\n    def __init__(self, size=3):\n        self.size = size\n        self.rank = size*size//2\n\n\nclass MinFilter(RankFilter):\n    \"\"\"\n    Create a min filter.  Picks the lowest pixel value in a window with the\n    given size.\n\n    :param size: The kernel size, in pixels.\n    \"\"\"\n    name = \"Min\"\n\n    def __init__(self, size=3):\n        self.size = size\n        self.rank = 0\n\n\nclass MaxFilter(RankFilter):\n    \"\"\"\n    Create a max filter.  Picks the largest pixel value in a window with the\n    given size.\n\n    :param size: The kernel size, in pixels.\n    \"\"\"\n    name = \"Max\"\n\n    def __init__(self, size=3):\n        self.size = size\n        self.rank = size*size-1\n\n\nclass ModeFilter(Filter):\n    \"\"\"\n    Create a mode filter. Picks the most frequent pixel value in a box with the\n    given size.  Pixel values that occur only once or twice are ignored; if no\n    pixel value occurs more than twice, the original pixel value is preserved.\n\n    :param size: The kernel size, in pixels.\n    \"\"\"\n    name = \"Mode\"\n\n    def __init__(self, size=3):\n        self.size = size\n\n    def filter(self, image):\n        return image.modefilter(self.size)\n\n\nclass GaussianBlur(MultibandFilter):\n    \"\"\"Gaussian blur filter.\n\n    :param radius: Blur radius.\n    \"\"\"\n    name = \"GaussianBlur\"\n\n    def __init__(self, radius=2):\n        self.radius = radius\n\n    def filter(self, image):\n        return image.gaussian_blur(self.radius)\n\n\nclass BoxBlur(MultibandFilter):\n    \"\"\"Blurs the image by setting each pixel to the average value of the pixels\n    in a square box extending radius pixels in each direction.\n    Supports float radius of arbitrary size. Uses an optimized implementation\n    which runs in linear time relative to the size of the image\n    for any radius value.\n\n    :param radius: Size of the box in one direction. Radius 0 does not blur,\n                   returns an identical image. Radius 1 takes 1 pixel\n                   in each direction, i.e. 9 pixels in total.\n    \"\"\"\n    name = \"BoxBlur\"\n\n    def __init__(self, radius):\n        self.radius = radius\n\n    def filter(self, image):\n        return image.box_blur(self.radius)\n\n\nclass UnsharpMask(MultibandFilter):\n    \"\"\"Unsharp mask filter.\n\n    See Wikipedia's entry on `digital unsharp masking`_ for an explanation of\n    the parameters.\n\n    :param radius: Blur Radius\n    :param percent: Unsharp strength, in percent\n    :param threshold: Threshold controls the minimum brightness change that\n      will be sharpened\n\n    .. _digital unsharp masking: https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking\n\n    \"\"\"\n    name = \"UnsharpMask\"\n\n    def __init__(self, radius=2, percent=150, threshold=3):\n        self.radius = radius\n        self.percent = percent\n        self.threshold = threshold\n\n    def filter(self, image):\n        return image.unsharp_mask(self.radius, self.percent, self.threshold)\n\n\nclass BLUR(BuiltinFilter):\n    name = \"Blur\"\n    filterargs = (5, 5), 16, 0, (\n        1,  1,  1,  1,  1,\n        1,  0,  0,  0,  1,\n        1,  0,  0,  0,  1,\n        1,  0,  0,  0,  1,\n        1,  1,  1,  1,  1\n        )\n\n\nclass CONTOUR(BuiltinFilter):\n    name = \"Contour\"\n    filterargs = (3, 3), 1, 255, (\n        -1, -1, -1,\n        -1,  8, -1,\n        -1, -1, -1\n        )\n\n\nclass DETAIL(BuiltinFilter):\n    name = \"Detail\"\n    filterargs = (3, 3), 6, 0, (\n        0, -1,  0,\n        -1, 10, -1,\n        0, -1,  0\n        )\n\n\nclass EDGE_ENHANCE(BuiltinFilter):\n    name = \"Edge-enhance\"\n    filterargs = (3, 3), 2, 0, (\n        -1, -1, -1,\n        -1, 10, -1,\n        -1, -1, -1\n        )\n\n\nclass EDGE_ENHANCE_MORE(BuiltinFilter):\n    name = \"Edge-enhance More\"\n    filterargs = (3, 3), 1, 0, (\n        -1, -1, -1,\n        -1,  9, -1,\n        -1, -1, -1\n        )\n\n\nclass EMBOSS(BuiltinFilter):\n    name = \"Emboss\"\n    filterargs = (3, 3), 1, 128, (\n        -1,  0,  0,\n        0,  1,  0,\n        0,  0,  0\n        )\n\n\nclass FIND_EDGES(BuiltinFilter):\n    name = \"Find Edges\"\n    filterargs = (3, 3), 1, 0, (\n        -1, -1, -1,\n        -1,  8, -1,\n        -1, -1, -1\n        )\n\n\nclass SHARPEN(BuiltinFilter):\n    name = \"Sharpen\"\n    filterargs = (3, 3), 16, 0, (\n        -2, -2, -2,\n        -2, 32, -2,\n        -2, -2, -2\n        )\n\n\nclass SMOOTH(BuiltinFilter):\n    name = \"Smooth\"\n    filterargs = (3, 3), 13, 0, (\n        1,  1,  1,\n        1,  5,  1,\n        1,  1,  1\n        )\n\n\nclass SMOOTH_MORE(BuiltinFilter):\n    name = \"Smooth More\"\n    filterargs = (5, 5), 100, 0, (\n        1,  1,  1,  1,  1,\n        1,  5,  5,  5,  1,\n        1,  5, 44,  5,  1,\n        1,  5,  5,  5,  1,\n        1,  1,  1,  1,  1\n        )\n\n\nclass Color3DLUT(MultibandFilter):\n    \"\"\"Three-dimensional color lookup table.\n\n    Transforms 3-channel pixels using the values of the channels as coordinates\n    in the 3D lookup table and interpolating the nearest elements.\n\n    This method allows you to apply almost any color transformation\n    in constant time by using pre-calculated decimated tables.\n\n    :param size: Size of the table. One int or tuple of (int, int, int).\n                 Minimal size in any dimension is 2, maximum is 65.\n    :param table: Flat lookup table. A list of ``channels * size**3``\n                  float elements or a list of ``size**3`` channels-sized\n                  tuples with floats. Channels are changed first,\n                  then first dimension, then second, then third.\n                  Value 0.0 corresponds lowest value of output, 1.0 highest.\n    :param channels: Number of channels in the table. Could be 3 or 4.\n                     Default is 3.\n    :param target_mode: A mode for the result image. Should have not less\n                        than ``channels`` channels. Default is ``None``,\n                        which means that mode wouldn't be changed.\n    \"\"\"\n    name = \"Color 3D LUT\"\n\n    def __init__(self, size, table, channels=3, target_mode=None):\n        self.size = size = self._check_size(size)\n        self.channels = channels\n        self.mode = target_mode\n\n        table = list(table)\n        # Convert to a flat list\n        if table and isinstance(table[0], (list, tuple)):\n            table, raw_table = [], table\n            for pixel in raw_table:\n                if len(pixel) != channels:\n                    raise ValueError(\"The elements of the table should have \"\n                                     \"a length of {}.\".format(channels))\n                for color in pixel:\n                    table.append(color)\n\n        if len(table) != channels * size[0] * size[1] * size[2]:\n            raise ValueError(\n                \"The table should have channels * size**3 float items \"\n                \"either size**3 items of channels-sized tuples with floats. \"\n                \"Table size: {}x{}x{}. Table length: {}\".format(\n                    size[0], size[1], size[2], len(table)))\n        self.table = table\n\n    @staticmethod\n    def _check_size(size):\n        try:\n            _, _, _ = size\n        except ValueError:\n            raise ValueError(\"Size should be an integer either \"\n                             \"tuple of three integers.\")\n        except TypeError:\n            size = (size, size, size)\n        size = [int(x) for x in size]\n        for size1D in size:\n            if not 2 <= size1D <= 65:\n                raise ValueError(\"Size should be in [2, 65] range.\")\n        return size\n\n    @classmethod\n    def generate(cls, size, callback, channels=3, target_mode=None):\n        \"\"\"Generates new LUT using provided callback.\n\n        :param size: Size of the table. Passed to the constructor.\n        :param callback: Function with three parameters which correspond\n                         three color channels. Will be called ``size**3``\n                         times with values from 0.0 to 1.0 and should return\n                         a tuple with ``channels`` elements.\n        :param channels: Passed to the constructor.\n        :param target_mode: Passed to the constructor.\n        \"\"\"\n        size1D, size2D, size3D = cls._check_size(size)\n        table = []\n        for b in range(size3D):\n            for g in range(size2D):\n                for r in range(size1D):\n                    table.append(callback(\n                        r / float(size1D-1),\n                        g / float(size2D-1),\n                        b / float(size3D-1)))\n\n        return cls((size1D, size2D, size3D), table, channels, target_mode)\n\n    @classmethod\n    def from_cube_file(cls, lines, target_mode=None):\n        name, size = None, None\n        channels = 3\n        file = None\n\n        if isPath(lines):\n            file = lines = open(lines, 'rt')\n\n        try:\n            iterator = iter(lines)\n\n            for i, line in enumerate(iterator, 1):\n                line = line.strip()\n                if not line:\n                    break\n                if line.startswith('TITLE \"'):\n                    name = line.split('\"')[1]\n                    continue\n                if line.startswith('LUT_3D_SIZE '):\n                    size = [int(x) for x in line.split()[1:]]\n                    if len(size) == 1:\n                        size = size[0]\n                    continue\n                if line.startswith('CHANNELS '):\n                    channels = int(line.split()[1])\n\n            if size is None:\n                raise ValueError('No size found in the file')\n\n            table = []\n            for i, line in enumerate(iterator, i + 1):\n                line = line.strip()\n                if not line or line.startswith('#'):\n                    continue\n                try:\n                    pixel = [float(x) for x in line.split()]\n                except ValueError:\n                    raise ValueError(\"Not a number on line {}\".format(i))\n                if len(pixel) != channels:\n                    raise ValueError(\n                        \"Wrong number of colors on line {}\".format(i))\n                table.append(tuple(pixel))\n        finally:\n            if file is not None:\n                file.close()\n\n        instance = cls(size, table, channels, target_mode)\n        if name is not None:\n            instance.name = name\n        return instance\n\n    def filter(self, image):\n        from . import Image\n\n        return image.color_lut_3d(\n            self.mode or image.mode, Image.LINEAR, self.channels,\n            self.size[0], self.size[1], self.size[2], self.table)\n"}
A user will ask you to solve a task. You should first draft your thinking process (inner monologue). Then, generate the solution.

Your response format must follow the template below:
<think>
Your thoughts or/and draft, like working through an exercise on scratch paper. Be as casual and as long as you want until you are confident to generate a correct solution.
</think>
<solution>
Final solution presented to the user.
</solution>
system
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]

**Title:** Unclear error message for invalid size parameter in Color3DLUT

**Description:**
When initializing the `Color3DLUT` class with an invalid `size` parameter, the raised `ValueError` message is unclear and does not accurately describe the expected input format. Providing a `size` that is neither an integer nor a tuple of three integers results in a confusing error message.

**Example Code:**
```python
from PIL import ImageFilter

# Attempt to create Color3DLUT with invalid size
lut = ImageFilter.Color3DLUT("small", [1])
```

**Expected Behavior:**
A `ValueError` should be raised with a clear message indicating that the `size` must be either an integer or a tuple of three integers.

**Actual Behavior:**
A `ValueError` is raised with the message:
```
ValueError: Size should be an integer either tuple of three integers.
```
The absence of the word "or" between the options makes the message unclear.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### src/PIL/ImageFilter.py
#
# The Python Imaging Library.
# $Id$
#
# standard filters
#
# History:
# 1995-11-27 fl   Created
# 2002-06-08 fl   Added rank and mode filters
# 2003-09-15 fl   Fixed rank calculation in rank filter; added expand call
#
# Copyright (c) 1997-2003 by Secret Labs AB.
# Copyright (c) 1995-2002 by Fredrik Lundh.
#
# See the README file for information on usage and redistribution.
#

import functools

from ._util import isPath


class Filter(object):
    pass


class MultibandFilter(Filter):
    pass


class Kernel(MultibandFilter):
    """
    Create a convolution kernel.  The current version only
    supports 3x3 and 5x5 integer and floating point kernels.

    In the current version, kernels can only be applied to
    "L" and "RGB" images.

    :param size: Kernel size, given as (width, height). In the current
                    version, this must be (3,3) or (5,5).
    :param kernel: A sequence containing kernel weights.
    :param scale: Scale factor. If given, the result for each pixel is
                    divided by this value.  the default is the sum of the
                    kernel weights.
    :param offset: Offset. If given, this value is added to the result,
                    after it has been divided by the scale factor.
    """
    name = "Kernel"

    def __init__(self, size, kernel, scale=None, offset=0):
        if scale is None:
            # default scale is sum of kernel
            scale = functools.reduce(lambda a, b: a+b, kernel)
        if size[0] * size[1] != len(kernel):
            raise ValueError("not enough coefficients in kernel")
        self.filterargs = size, scale, offset, kernel

    def filter(self, image):
        if image.mode == "P":
            raise ValueError("cannot filter palette images")
        return image.filter(*self.filterargs)


class BuiltinFilter(Kernel):
    def __init__(self):
        pass


class RankFilter(Filter):
    """
    Create a rank filter.  The rank filter sorts all pixels in
    a window of the given size, and returns the **rank**'th value.

    :param size: The kernel size, in pixels.
    :param rank: What pixel value to pick.  Use 0 for a min filter,
                 ``size * size / 2`` for a median filter, ``size * size - 1``
                 for a max filter, etc.
    """
    name = "Rank"

    def __init__(self, size, rank):
        self.size = size
        self.rank = rank

    def filter(self, image):
        if image.mode == "P":
            raise ValueError("cannot filter palette images")
        image = image.expand(self.size//2, self.size//2)
        return image.rankfilter(self.size, self.rank)


class MedianFilter(RankFilter):
    """
    Create a median filter. Picks the median pixel value in a window with the
    given size.

    :param size: The kernel size, in pixels.
    """
    name = "Median"

    def __init__(self, size=3):
        self.size = size
        self.rank = size*size//2


class MinFilter(RankFilter):
    """
    Create a min filter.  Picks the lowest pixel value in a window with the
    given size.

    :param size: The kernel size, in pixels.
    """
    name = "Min"

    def __init__(self, size=3):
        self.size = size
        self.rank = 0


class MaxFilter(RankFilter):
    """
    Create a max filter.  Picks the largest pixel value in a window with the
    given size.

    :param size: The kernel size, in pixels.
    """
    name = "Max"

    def __init__(self, size=3):
        self.size = size
        self.rank = size*size-1


class ModeFilter(Filter):
    """
    Create a mode filter. Picks the most frequent pixel value in a box with the
    given size.  Pixel values that occur only once or twice are ignored; if no
    pixel value occurs more than twice, the original pixel value is preserved.

    :param size: The kernel size, in pixels.
    """
    name = "Mode"

    def __init__(self, size=3):
        self.size = size

    def filter(self, image):
        return image.modefilter(self.size)


class GaussianBlur(MultibandFilter):
    """Gaussian blur filter.

    :param radius: Blur radius.
    """
    name = "GaussianBlur"

    def __init__(self, radius=2):
        self.radius = radius

    def filter(self, image):
        return image.gaussian_blur(self.radius)


class BoxBlur(MultibandFilter):
    """Blurs the image by setting each pixel to the average value of the pixels
    in a square box extending radius pixels in each direction.
    Supports float radius of arbitrary size. Uses an optimized implementation
    which runs in linear time relative to the size of the image
    for any radius value.

    :param radius: Size of the box in one direction. Radius 0 does not blur,
                   returns an identical image. Radius 1 takes 1 pixel
                   in each direction, i.e. 9 pixels in total.
    """
    name = "BoxBlur"

    def __init__(self, radius):
        self.radius = radius

    def filter(self, image):
        return image.box_blur(self.radius)


class UnsharpMask(MultibandFilter):
    """Unsharp mask filter.

    See Wikipedia's entry on `digital unsharp masking`_ for an explanation of
    the parameters.

    :param radius: Blur Radius
    :param percent: Unsharp strength, in percent
    :param threshold: Threshold controls the minimum brightness change that
      will be sharpened

    .. _digital unsharp masking: https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking

    """
    name = "UnsharpMask"

    def __init__(self, radius=2, percent=150, threshold=3):
        self.radius = radius
        self.percent = percent
        self.threshold = threshold

    def filter(self, image):
        return image.unsharp_mask(self.radius, self.percent, self.threshold)


class BLUR(BuiltinFilter):
    name = "Blur"
    filterargs = (5, 5), 16, 0, (
        1,  1,  1,  1,  1,
        1,  0,  0,  0,  1,
        1,  0,  0,  0,  1,
        1,  0,  0,  0,  1,
        1,  1,  1,  1,  1
        )


class CONTOUR(BuiltinFilter):
    name = "Contour"
    filterargs = (3, 3), 1, 255, (
        -1, -1, -1,
        -1,  8, -1,
        -1, -1, -1
        )


class DETAIL(BuiltinFilter):
    name = "Detail"
    filterargs = (3, 3), 6, 0, (
        0, -1,  0,
        -1, 10, -1,
        0, -1,  0
        )


class EDGE_ENHANCE(BuiltinFilter):
    name = "Edge-enhance"
    filterargs = (3, 3), 2, 0, (
        -1, -1, -1,
        -1, 10, -1,
        -1, -1, -1
        )


class EDGE_ENHANCE_MORE(BuiltinFilter):
    name = "Edge-enhance More"
    filterargs = (3, 3), 1, 0, (
        -1, -1, -1,
        -1,  9, -1,
        -1, -1, -1
        )


class EMBOSS(BuiltinFilter):
    name = "Emboss"
    filterargs = (3, 3), 1, 128, (
        -1,  0,  0,
        0,  1,  0,
        0,  0,  0
        )


class FIND_EDGES(BuiltinFilter):
    name = "Find Edges"
    filterargs = (3, 3), 1, 0, (
        -1, -1, -1,
        -1,  8, -1,
        -1, -1, -1
        )


class SHARPEN(BuiltinFilter):
    name = "Sharpen"
    filterargs = (3, 3), 16, 0, (
        -2, -2, -2,
        -2, 32, -2,
        -2, -2, -2
        )


class SMOOTH(BuiltinFilter):
    name = "Smooth"
    filterargs = (3, 3), 13, 0, (
        1,  1,  1,
        1,  5,  1,
        1,  1,  1
        )


class SMOOTH_MORE(BuiltinFilter):
    name = "Smooth More"
    filterargs = (5, 5), 100, 0, (
        1,  1,  1,  1,  1,
        1,  5,  5,  5,  1,
        1,  5, 44,  5,  1,
        1,  5,  5,  5,  1,
        1,  1,  1,  1,  1
        )


class Color3DLUT(MultibandFilter):
    """Three-dimensional color lookup table.

    Transforms 3-channel pixels using the values of the channels as coordinates
    in the 3D lookup table and interpolating the nearest elements.

    This method allows you to apply almost any color transformation
    in constant time by using pre-calculated decimated tables.

    :param size: Size of the table. One int or tuple of (int, int, int).
                 Minimal size in any dimension is 2, maximum is 65.
    :param table: Flat lookup table. A list of ``channels * size**3``
                  float elements or a list of ``size**3`` channels-sized
                  tuples with floats. Channels are changed first,
                  then first dimension, then second, then third.
                  Value 0.0 corresponds lowest value of output, 1.0 highest.
    :param channels: Number of channels in the table. Could be 3 or 4.
                     Default is 3.
    :param target_mode: A mode for the result image. Should have not less
                        than ``channels`` channels. Default is ``None``,
                        which means that mode wouldn't be changed.
    """
    name = "Color 3D LUT"

    def __init__(self, size, table, channels=3, target_mode=None):
        self.size = size = self._check_size(size)
        self.channels = channels
        self.mode = target_mode

        table = list(table)
        # Convert to a flat list
        if table and isinstance(table[0], (list, tuple)):
            table, raw_table = [], table
            for pixel in raw_table:
                if len(pixel) != channels:
                    raise ValueError("The elements of the table should have "
                                     "a length of {}.".format(channels))
                for color in pixel:
                    table.append(color)

        if len(table) != channels * size[0] * size[1] * size[2]:
            raise ValueError(
                "The table should have channels * size**3 float items "
                "either size**3 items of channels-sized tuples with floats. "
                "Table size: {}x{}x{}. Table length: {}".format(
                    size[0], size[1], size[2], len(table)))
        self.table = table

    @staticmethod
    def _check_size(size):
        try:
            _, _, _ = size
        except ValueError:
            raise ValueError("Size should be an integer either "
                             "tuple of three integers.")
        except TypeError:
            size = (size, size, size)
        size = [int(x) for x in size]
        for size1D in size:
            if not 2 <= size1D <= 65:
                raise ValueError("Size should be in [2, 65] range.")
        return size

    @classmethod
    def generate(cls, size, callback, channels=3, target_mode=None):
        """Generates new LUT using provided callback.

        :param size: Size of the table. Passed to the constructor.
        :param callback: Function with three parameters which correspond
                         three color channels. Will be called ``size**3``
                         times with values from 0.0 to 1.0 and should return
                         a tuple with ``channels`` elements.
        :param channels: Passed to the constructor.
        :param target_mode: Passed to the constructor.
        """
        size1D, size2D, size3D = cls._check_size(size)
        table = []
        for b in range(size3D):
            for g in range(size2D):
                for r in range(size1D):
                    table.append(callback(
                        r / float(size1D-1),
                        g / float(size2D-1),
                        b / float(size3D-1)))

        return cls((size1D, size2D, size3D), table, channels, target_mode)

    @classmethod
    def from_cube_file(cls, lines, target_mode=None):
        name, size = None, None
        channels = 3
        file = None

        if isPath(lines):
            file = lines = open(lines, 'rt')

        try:
            iterator = iter(lines)

            for i, line in enumerate(iterator, 1):
                line = line.strip()
                if not line:
                    break
                if line.startswith('TITLE "'):
                    name = line.split('"')[1]
                    continue
                if line.startswith('LUT_3D_SIZE '):
                    size = [int(x) for x in line.split()[1:]]
                    if len(size) == 1:
                        size = size[0]
                    continue
                if line.startswith('CHANNELS '):
                    channels = int(line.split()[1])

            if size is None:
                raise ValueError('No size found in the file')

            table = []
            for i, line in enumerate(iterator, i + 1):
                line = line.strip()
                if not line or line.startswith('#'):
                    continue
                try:
                    pixel = [float(x) for x in line.split()]
                except ValueError:
                    raise ValueError("Not a number on line {}".format(i))
                if len(pixel) != channels:
                    raise ValueError(
                        "Wrong number of colors on line {}".format(i))
                table.append(tuple(pixel))
        finally:
            if file is not None:
                file.close()

        instance = cls(size, table, channels, target_mode)
        if name is not None:
            instance.name = name
        return instance

    def filter(self, image):
        from . import Image

        return image.color_lut_3d(
            self.mode or image.mode, Image.LINEAR, self.channels,
            self.size[0], self.size[1], self.size[2], self.table)

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
user