{
    "file_diffs": [
        {
            "old_file_content": "from helper import unittest, PillowTestCase, hopper\n\nfrom PIL import Image, SgiImagePlugin\n\n\nclass TestFileSgi(PillowTestCase):\n\n    def test_rgb(self):\n        # Created with ImageMagick then renamed:\n        # convert hopper.ppm -compress None sgi:hopper.rgb\n        test_file = \"Tests/images/hopper.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_rgb16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_l(self):\n        # Created with ImageMagick\n        # convert hopper.ppm -monochrome -compress None sgi:hopper.bw\n        test_file = \"Tests/images/hopper.bw\"\n\n        im = Image.open(test_file)\n        self.assert_image_similar(im, hopper('L'), 2)\n\n    def test_rgba(self):\n        # Created with ImageMagick:\n        # convert transparent.png -compress None transparent.sgi\n        test_file = \"Tests/images/transparent.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/transparent.png')\n        self.assert_image_equal(im, target)\n\n    def test_rle(self):\n        # Created with ImageMagick:\n        # convert hopper.ppm  hopper.sgi\n        test_file = \"Tests/images/hopper.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/hopper.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_rle16(self):\n        test_file = \"Tests/images/tv16.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/tv.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_invalid_file(self):\n        invalid_file = \"Tests/images/flower.jpg\"\n\n        self.assertRaises(ValueError,\n                          SgiImagePlugin.SgiImageFile, invalid_file)\n\n    def test_write(self):\n        def roundtrip(img):\n            out = self.tempfile('temp.sgi')\n            img.save(out, format='sgi')\n            reloaded = Image.open(out)\n            self.assert_image_equal(img, reloaded)\n\n        for mode in ('L', 'RGB', 'RGBA'):\n            roundtrip(hopper(mode))\n\n        # Test 1 dimension for an L mode image\n        roundtrip(Image.new('L', (10, 1)))\n\n    def test_write16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        out = self.tempfile('temp.sgi')\n        im.save(out, format='sgi', bpc=2)\n\n        reloaded = Image.open(out)\n        self.assert_image_equal(im, reloaded)\n\n    def test_unsupported_mode(self):\n        im = hopper('LA')\n        out = self.tempfile('temp.sgi')\n\n        self.assertRaises(ValueError, im.save, out, format='sgi')\n\n\nif __name__ == '__main__':\n    unittest.main()\n",
            "new_file_content": "from helper import unittest, PillowTestCase, hopper\n\nfrom PIL import Image, SgiImagePlugin\n\n\nclass TestFileSgi(PillowTestCase):\n\n    def test_rgb(self):\n        # Created with ImageMagick then renamed:\n        # convert hopper.ppm -compress None sgi:hopper.rgb\n        test_file = \"Tests/images/hopper.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n        self.assertEqual(im.get_format_mimetype(), 'image/rgb')\n\n    def test_rgb16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_l(self):\n        # Created with ImageMagick\n        # convert hopper.ppm -monochrome -compress None sgi:hopper.bw\n        test_file = \"Tests/images/hopper.bw\"\n\n        im = Image.open(test_file)\n        self.assert_image_similar(im, hopper('L'), 2)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rgba(self):\n        # Created with ImageMagick:\n        # convert transparent.png -compress None transparent.sgi\n        test_file = \"Tests/images/transparent.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/transparent.png')\n        self.assert_image_equal(im, target)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rle(self):\n        # Created with ImageMagick:\n        # convert hopper.ppm  hopper.sgi\n        test_file = \"Tests/images/hopper.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/hopper.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_rle16(self):\n        test_file = \"Tests/images/tv16.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/tv.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_invalid_file(self):\n        invalid_file = \"Tests/images/flower.jpg\"\n\n        self.assertRaises(ValueError,\n                          SgiImagePlugin.SgiImageFile, invalid_file)\n\n    def test_write(self):\n        def roundtrip(img):\n            out = self.tempfile('temp.sgi')\n            img.save(out, format='sgi')\n            reloaded = Image.open(out)\n            self.assert_image_equal(img, reloaded)\n\n        for mode in ('L', 'RGB', 'RGBA'):\n            roundtrip(hopper(mode))\n\n        # Test 1 dimension for an L mode image\n        roundtrip(Image.new('L', (10, 1)))\n\n    def test_write16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        out = self.tempfile('temp.sgi')\n        im.save(out, format='sgi', bpc=2)\n\n        reloaded = Image.open(out)\n        self.assert_image_equal(im, reloaded)\n\n    def test_unsupported_mode(self):\n        im = hopper('LA')\n        out = self.tempfile('temp.sgi')\n\n        self.assertRaises(ValueError, im.save, out, format='sgi')\n\n\nif __name__ == '__main__':\n    unittest.main()\n",
            "header": {
                "file": {
                    "path": "Tests/test_file_sgi.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "aa33c9d93",
                "new_commit_hash": "76f8a3841",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/Tests/test_file_sgi.py"
            },
            "plus_file": {
                "path": "b/Tests/test_file_sgi.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 12,
                            "length": 6
                        },
                        "new_range": {
                            "start": 12,
                            "length": 7
                        },
                        "section": "class TestFileSgi(PillowTestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        im = Image.open(test_file)",
                                "type": "context"
                            },
                            {
                                "content": "        self.assert_image_equal(im, hopper())",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual(im.get_format_mimetype(), 'image/rgb')",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def test_rgb16(self):",
                                "type": "context"
                            },
                            {
                                "content": "        test_file = \"Tests/images/hopper16.rgb\"",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Tests/test_file_sgi.py",
                            "type": "class",
                            "name": "TestFileSgi",
                            "content": "class TestFileSgi(PillowTestCase):\n\n    def test_rgb(self):\n        # Created with ImageMagick then renamed:\n        # convert hopper.ppm -compress None sgi:hopper.rgb\n        test_file = \"Tests/images/hopper.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n        self.assertEqual(im.get_format_mimetype(), 'image/rgb')\n\n    def test_rgb16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_l(self):\n        # Created with ImageMagick\n        # convert hopper.ppm -monochrome -compress None sgi:hopper.bw\n        test_file = \"Tests/images/hopper.bw\"\n\n        im = Image.open(test_file)\n        self.assert_image_similar(im, hopper('L'), 2)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rgba(self):\n        # Created with ImageMagick:\n        # convert transparent.png -compress None transparent.sgi\n        test_file = \"Tests/images/transparent.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/transparent.png')\n        self.assert_image_equal(im, target)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rle(self):\n        # Created with ImageMagick:\n        # convert hopper.ppm  hopper.sgi\n        test_file = \"Tests/images/hopper.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/hopper.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_rle16(self):\n        test_file = \"Tests/images/tv16.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/tv.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_invalid_file(self):\n        invalid_file = \"Tests/images/flower.jpg\"\n\n        self.assertRaises(ValueError,\n                          SgiImagePlugin.SgiImageFile, invalid_file)\n\n    def test_write(self):\n        def roundtrip(img):\n            out = self.tempfile('temp.sgi')\n            img.save(out, format='sgi')\n            reloaded = Image.open(out)\n            self.assert_image_equal(img, reloaded)\n\n        for mode in ('L', 'RGB', 'RGBA'):\n            roundtrip(hopper(mode))\n\n        # Test 1 dimension for an L mode image\n        roundtrip(Image.new('L', (10, 1)))\n\n    def test_write16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        out = self.tempfile('temp.sgi')\n        im.save(out, format='sgi', bpc=2)\n\n        reloaded = Image.open(out)\n        self.assert_image_equal(im, reloaded)\n\n    def test_unsupported_mode(self):\n        im = hopper('LA')\n        out = self.tempfile('temp.sgi')\n\n        self.assertRaises(ValueError, im.save, out, format='sgi')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 6,
                            "end_lineno": 91,
                            "parent": null
                        },
                        {
                            "file_name": "Tests/test_file_sgi.py",
                            "type": "method",
                            "name": "TestFileSgi.test_rgb",
                            "content": "class TestFileSgi(PillowTestCase):\n\n    def test_rgb(self):\n        # Created with ImageMagick then renamed:\n        # convert hopper.ppm -compress None sgi:hopper.rgb\n        test_file = \"Tests/images/hopper.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n        self.assertEqual(im.get_format_mimetype(), 'image/rgb')\n\n    def test_rgb16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_l(self):\n        # Created with ImageMagick\n        # convert hopper.ppm -monochrome -compress None sgi:hopper.bw\n        test_file = \"Tests/images/hopper.bw\"\n\n        im = Image.open(test_file)\n        self.assert_image_similar(im, hopper('L'), 2)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rgba(self):\n        # Created with ImageMagick:\n        # convert transparent.png -compress None transparent.sgi\n        test_file = \"Tests/images/transparent.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/transparent.png')\n        self.assert_image_equal(im, target)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rle(self):\n        # Created with ImageMagick:\n        # convert hopper.ppm  hopper.sgi\n        test_file = \"Tests/images/hopper.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/hopper.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_rle16(self):\n        test_file = \"Tests/images/tv16.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/tv.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_invalid_file(self):\n        invalid_file = \"Tests/images/flower.jpg\"\n\n        self.assertRaises(ValueError,\n                          SgiImagePlugin.SgiImageFile, invalid_file)\n\n    def test_write(self):\n        def roundtrip(img):\n            out = self.tempfile('temp.sgi')\n            img.save(out, format='sgi')\n            reloaded = Image.open(out)\n            self.assert_image_equal(img, reloaded)\n\n        for mode in ('L', 'RGB', 'RGBA'):\n            roundtrip(hopper(mode))\n\n        # Test 1 dimension for an L mode image\n        roundtrip(Image.new('L', (10, 1)))\n\n    def test_write16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        out = self.tempfile('temp.sgi')\n        im.save(out, format='sgi', bpc=2)\n\n        reloaded = Image.open(out)\n        self.assert_image_equal(im, reloaded)\n\n    def test_unsupported_mode(self):\n        im = hopper('LA')\n        out = self.tempfile('temp.sgi')\n\n        self.assertRaises(ValueError, im.save, out, format='sgi')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 8,
                            "end_lineno": 15,
                            "parent": {
                                "file_name": "Tests/test_file_sgi.py",
                                "type": "class",
                                "name": "TestFileSgi",
                                "content": "class TestFileSgi(PillowTestCase):\n\n    def test_rgb(self):\n        # Created with ImageMagick then renamed:\n        # convert hopper.ppm -compress None sgi:hopper.rgb\n        test_file = \"Tests/images/hopper.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n        self.assertEqual(im.get_format_mimetype(), 'image/rgb')\n\n    def test_rgb16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_l(self):\n        # Created with ImageMagick\n        # convert hopper.ppm -monochrome -compress None sgi:hopper.bw\n        test_file = \"Tests/images/hopper.bw\"\n\n        im = Image.open(test_file)\n        self.assert_image_similar(im, hopper('L'), 2)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rgba(self):\n        # Created with ImageMagick:\n        # convert transparent.png -compress None transparent.sgi\n        test_file = \"Tests/images/transparent.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/transparent.png')\n        self.assert_image_equal(im, target)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rle(self):\n        # Created with ImageMagick:\n        # convert hopper.ppm  hopper.sgi\n        test_file = \"Tests/images/hopper.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/hopper.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_rle16(self):\n        test_file = \"Tests/images/tv16.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/tv.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_invalid_file(self):\n        invalid_file = \"Tests/images/flower.jpg\"\n\n        self.assertRaises(ValueError,\n                          SgiImagePlugin.SgiImageFile, invalid_file)\n\n    def test_write(self):\n        def roundtrip(img):\n            out = self.tempfile('temp.sgi')\n            img.save(out, format='sgi')\n            reloaded = Image.open(out)\n            self.assert_image_equal(img, reloaded)\n\n        for mode in ('L', 'RGB', 'RGBA'):\n            roundtrip(hopper(mode))\n\n        # Test 1 dimension for an L mode image\n        roundtrip(Image.new('L', (10, 1)))\n\n    def test_write16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        out = self.tempfile('temp.sgi')\n        im.save(out, format='sgi', bpc=2)\n\n        reloaded = Image.open(out)\n        self.assert_image_equal(im, reloaded)\n\n    def test_unsupported_mode(self):\n        im = hopper('LA')\n        out = self.tempfile('temp.sgi')\n\n        self.assertRaises(ValueError, im.save, out, format='sgi')",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 6,
                                "end_lineno": 91,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 26,
                            "length": 6
                        },
                        "new_range": {
                            "start": 27,
                            "length": 7
                        },
                        "section": "class TestFileSgi(PillowTestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        im = Image.open(test_file)",
                                "type": "context"
                            },
                            {
                                "content": "        self.assert_image_similar(im, hopper('L'), 2)",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual(im.get_format_mimetype(), 'image/sgi')",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def test_rgba(self):",
                                "type": "context"
                            },
                            {
                                "content": "        # Created with ImageMagick:",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Tests/test_file_sgi.py",
                            "type": "class",
                            "name": "TestFileSgi",
                            "content": "class TestFileSgi(PillowTestCase):\n\n    def test_rgb(self):\n        # Created with ImageMagick then renamed:\n        # convert hopper.ppm -compress None sgi:hopper.rgb\n        test_file = \"Tests/images/hopper.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n        self.assertEqual(im.get_format_mimetype(), 'image/rgb')\n\n    def test_rgb16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_l(self):\n        # Created with ImageMagick\n        # convert hopper.ppm -monochrome -compress None sgi:hopper.bw\n        test_file = \"Tests/images/hopper.bw\"\n\n        im = Image.open(test_file)\n        self.assert_image_similar(im, hopper('L'), 2)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rgba(self):\n        # Created with ImageMagick:\n        # convert transparent.png -compress None transparent.sgi\n        test_file = \"Tests/images/transparent.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/transparent.png')\n        self.assert_image_equal(im, target)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rle(self):\n        # Created with ImageMagick:\n        # convert hopper.ppm  hopper.sgi\n        test_file = \"Tests/images/hopper.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/hopper.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_rle16(self):\n        test_file = \"Tests/images/tv16.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/tv.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_invalid_file(self):\n        invalid_file = \"Tests/images/flower.jpg\"\n\n        self.assertRaises(ValueError,\n                          SgiImagePlugin.SgiImageFile, invalid_file)\n\n    def test_write(self):\n        def roundtrip(img):\n            out = self.tempfile('temp.sgi')\n            img.save(out, format='sgi')\n            reloaded = Image.open(out)\n            self.assert_image_equal(img, reloaded)\n\n        for mode in ('L', 'RGB', 'RGBA'):\n            roundtrip(hopper(mode))\n\n        # Test 1 dimension for an L mode image\n        roundtrip(Image.new('L', (10, 1)))\n\n    def test_write16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        out = self.tempfile('temp.sgi')\n        im.save(out, format='sgi', bpc=2)\n\n        reloaded = Image.open(out)\n        self.assert_image_equal(im, reloaded)\n\n    def test_unsupported_mode(self):\n        im = hopper('LA')\n        out = self.tempfile('temp.sgi')\n\n        self.assertRaises(ValueError, im.save, out, format='sgi')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 6,
                            "end_lineno": 91,
                            "parent": null
                        },
                        {
                            "file_name": "Tests/test_file_sgi.py",
                            "type": "method",
                            "name": "TestFileSgi.test_l",
                            "content": "class TestFileSgi(PillowTestCase):\n\n    def test_rgb(self):\n        # Created with ImageMagick then renamed:\n        # convert hopper.ppm -compress None sgi:hopper.rgb\n        test_file = \"Tests/images/hopper.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n        self.assertEqual(im.get_format_mimetype(), 'image/rgb')\n\n    def test_rgb16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_l(self):\n        # Created with ImageMagick\n        # convert hopper.ppm -monochrome -compress None sgi:hopper.bw\n        test_file = \"Tests/images/hopper.bw\"\n\n        im = Image.open(test_file)\n        self.assert_image_similar(im, hopper('L'), 2)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rgba(self):\n        # Created with ImageMagick:\n        # convert transparent.png -compress None transparent.sgi\n        test_file = \"Tests/images/transparent.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/transparent.png')\n        self.assert_image_equal(im, target)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rle(self):\n        # Created with ImageMagick:\n        # convert hopper.ppm  hopper.sgi\n        test_file = \"Tests/images/hopper.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/hopper.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_rle16(self):\n        test_file = \"Tests/images/tv16.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/tv.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_invalid_file(self):\n        invalid_file = \"Tests/images/flower.jpg\"\n\n        self.assertRaises(ValueError,\n                          SgiImagePlugin.SgiImageFile, invalid_file)\n\n    def test_write(self):\n        def roundtrip(img):\n            out = self.tempfile('temp.sgi')\n            img.save(out, format='sgi')\n            reloaded = Image.open(out)\n            self.assert_image_equal(img, reloaded)\n\n        for mode in ('L', 'RGB', 'RGBA'):\n            roundtrip(hopper(mode))\n\n        # Test 1 dimension for an L mode image\n        roundtrip(Image.new('L', (10, 1)))\n\n    def test_write16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        out = self.tempfile('temp.sgi')\n        im.save(out, format='sgi', bpc=2)\n\n        reloaded = Image.open(out)\n        self.assert_image_equal(im, reloaded)\n\n    def test_unsupported_mode(self):\n        im = hopper('LA')\n        out = self.tempfile('temp.sgi')\n\n        self.assertRaises(ValueError, im.save, out, format='sgi')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 23,
                            "end_lineno": 30,
                            "parent": {
                                "file_name": "Tests/test_file_sgi.py",
                                "type": "class",
                                "name": "TestFileSgi",
                                "content": "class TestFileSgi(PillowTestCase):\n\n    def test_rgb(self):\n        # Created with ImageMagick then renamed:\n        # convert hopper.ppm -compress None sgi:hopper.rgb\n        test_file = \"Tests/images/hopper.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n        self.assertEqual(im.get_format_mimetype(), 'image/rgb')\n\n    def test_rgb16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_l(self):\n        # Created with ImageMagick\n        # convert hopper.ppm -monochrome -compress None sgi:hopper.bw\n        test_file = \"Tests/images/hopper.bw\"\n\n        im = Image.open(test_file)\n        self.assert_image_similar(im, hopper('L'), 2)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rgba(self):\n        # Created with ImageMagick:\n        # convert transparent.png -compress None transparent.sgi\n        test_file = \"Tests/images/transparent.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/transparent.png')\n        self.assert_image_equal(im, target)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rle(self):\n        # Created with ImageMagick:\n        # convert hopper.ppm  hopper.sgi\n        test_file = \"Tests/images/hopper.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/hopper.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_rle16(self):\n        test_file = \"Tests/images/tv16.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/tv.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_invalid_file(self):\n        invalid_file = \"Tests/images/flower.jpg\"\n\n        self.assertRaises(ValueError,\n                          SgiImagePlugin.SgiImageFile, invalid_file)\n\n    def test_write(self):\n        def roundtrip(img):\n            out = self.tempfile('temp.sgi')\n            img.save(out, format='sgi')\n            reloaded = Image.open(out)\n            self.assert_image_equal(img, reloaded)\n\n        for mode in ('L', 'RGB', 'RGBA'):\n            roundtrip(hopper(mode))\n\n        # Test 1 dimension for an L mode image\n        roundtrip(Image.new('L', (10, 1)))\n\n    def test_write16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        out = self.tempfile('temp.sgi')\n        im.save(out, format='sgi', bpc=2)\n\n        reloaded = Image.open(out)\n        self.assert_image_equal(im, reloaded)\n\n    def test_unsupported_mode(self):\n        im = hopper('LA')\n        out = self.tempfile('temp.sgi')\n\n        self.assertRaises(ValueError, im.save, out, format='sgi')",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 6,
                                "end_lineno": 91,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 35,
                            "length": 6
                        },
                        "new_range": {
                            "start": 37,
                            "length": 7
                        },
                        "section": "class TestFileSgi(PillowTestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        im = Image.open(test_file)",
                                "type": "context"
                            },
                            {
                                "content": "        target = Image.open('Tests/images/transparent.png')",
                                "type": "context"
                            },
                            {
                                "content": "        self.assert_image_equal(im, target)",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual(im.get_format_mimetype(), 'image/sgi')",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def test_rle(self):",
                                "type": "context"
                            },
                            {
                                "content": "        # Created with ImageMagick:",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Tests/test_file_sgi.py",
                            "type": "method",
                            "name": "TestFileSgi.test_rgba",
                            "content": "class TestFileSgi(PillowTestCase):\n\n    def test_rgb(self):\n        # Created with ImageMagick then renamed:\n        # convert hopper.ppm -compress None sgi:hopper.rgb\n        test_file = \"Tests/images/hopper.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n        self.assertEqual(im.get_format_mimetype(), 'image/rgb')\n\n    def test_rgb16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_l(self):\n        # Created with ImageMagick\n        # convert hopper.ppm -monochrome -compress None sgi:hopper.bw\n        test_file = \"Tests/images/hopper.bw\"\n\n        im = Image.open(test_file)\n        self.assert_image_similar(im, hopper('L'), 2)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rgba(self):\n        # Created with ImageMagick:\n        # convert transparent.png -compress None transparent.sgi\n        test_file = \"Tests/images/transparent.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/transparent.png')\n        self.assert_image_equal(im, target)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rle(self):\n        # Created with ImageMagick:\n        # convert hopper.ppm  hopper.sgi\n        test_file = \"Tests/images/hopper.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/hopper.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_rle16(self):\n        test_file = \"Tests/images/tv16.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/tv.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_invalid_file(self):\n        invalid_file = \"Tests/images/flower.jpg\"\n\n        self.assertRaises(ValueError,\n                          SgiImagePlugin.SgiImageFile, invalid_file)\n\n    def test_write(self):\n        def roundtrip(img):\n            out = self.tempfile('temp.sgi')\n            img.save(out, format='sgi')\n            reloaded = Image.open(out)\n            self.assert_image_equal(img, reloaded)\n\n        for mode in ('L', 'RGB', 'RGBA'):\n            roundtrip(hopper(mode))\n\n        # Test 1 dimension for an L mode image\n        roundtrip(Image.new('L', (10, 1)))\n\n    def test_write16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        out = self.tempfile('temp.sgi')\n        im.save(out, format='sgi', bpc=2)\n\n        reloaded = Image.open(out)\n        self.assert_image_equal(im, reloaded)\n\n    def test_unsupported_mode(self):\n        im = hopper('LA')\n        out = self.tempfile('temp.sgi')\n\n        self.assertRaises(ValueError, im.save, out, format='sgi')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 32,
                            "end_lineno": 40,
                            "parent": {
                                "file_name": "Tests/test_file_sgi.py",
                                "type": "class",
                                "name": "TestFileSgi",
                                "content": "class TestFileSgi(PillowTestCase):\n\n    def test_rgb(self):\n        # Created with ImageMagick then renamed:\n        # convert hopper.ppm -compress None sgi:hopper.rgb\n        test_file = \"Tests/images/hopper.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n        self.assertEqual(im.get_format_mimetype(), 'image/rgb')\n\n    def test_rgb16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_l(self):\n        # Created with ImageMagick\n        # convert hopper.ppm -monochrome -compress None sgi:hopper.bw\n        test_file = \"Tests/images/hopper.bw\"\n\n        im = Image.open(test_file)\n        self.assert_image_similar(im, hopper('L'), 2)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rgba(self):\n        # Created with ImageMagick:\n        # convert transparent.png -compress None transparent.sgi\n        test_file = \"Tests/images/transparent.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/transparent.png')\n        self.assert_image_equal(im, target)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rle(self):\n        # Created with ImageMagick:\n        # convert hopper.ppm  hopper.sgi\n        test_file = \"Tests/images/hopper.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/hopper.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_rle16(self):\n        test_file = \"Tests/images/tv16.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/tv.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_invalid_file(self):\n        invalid_file = \"Tests/images/flower.jpg\"\n\n        self.assertRaises(ValueError,\n                          SgiImagePlugin.SgiImageFile, invalid_file)\n\n    def test_write(self):\n        def roundtrip(img):\n            out = self.tempfile('temp.sgi')\n            img.save(out, format='sgi')\n            reloaded = Image.open(out)\n            self.assert_image_equal(img, reloaded)\n\n        for mode in ('L', 'RGB', 'RGBA'):\n            roundtrip(hopper(mode))\n\n        # Test 1 dimension for an L mode image\n        roundtrip(Image.new('L', (10, 1)))\n\n    def test_write16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        out = self.tempfile('temp.sgi')\n        im.save(out, format='sgi', bpc=2)\n\n        reloaded = Image.open(out)\n        self.assert_image_equal(im, reloaded)\n\n    def test_unsupported_mode(self):\n        im = hopper('LA')\n        out = self.tempfile('temp.sgi')\n\n        self.assertRaises(ValueError, im.save, out, format='sgi')",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 6,
                                "end_lineno": 91,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "Tests/test_file_sgi.py",
                            "type": "class",
                            "name": "TestFileSgi",
                            "content": "class TestFileSgi(PillowTestCase):\n\n    def test_rgb(self):\n        # Created with ImageMagick then renamed:\n        # convert hopper.ppm -compress None sgi:hopper.rgb\n        test_file = \"Tests/images/hopper.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n        self.assertEqual(im.get_format_mimetype(), 'image/rgb')\n\n    def test_rgb16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_l(self):\n        # Created with ImageMagick\n        # convert hopper.ppm -monochrome -compress None sgi:hopper.bw\n        test_file = \"Tests/images/hopper.bw\"\n\n        im = Image.open(test_file)\n        self.assert_image_similar(im, hopper('L'), 2)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rgba(self):\n        # Created with ImageMagick:\n        # convert transparent.png -compress None transparent.sgi\n        test_file = \"Tests/images/transparent.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/transparent.png')\n        self.assert_image_equal(im, target)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rle(self):\n        # Created with ImageMagick:\n        # convert hopper.ppm  hopper.sgi\n        test_file = \"Tests/images/hopper.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/hopper.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_rle16(self):\n        test_file = \"Tests/images/tv16.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/tv.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_invalid_file(self):\n        invalid_file = \"Tests/images/flower.jpg\"\n\n        self.assertRaises(ValueError,\n                          SgiImagePlugin.SgiImageFile, invalid_file)\n\n    def test_write(self):\n        def roundtrip(img):\n            out = self.tempfile('temp.sgi')\n            img.save(out, format='sgi')\n            reloaded = Image.open(out)\n            self.assert_image_equal(img, reloaded)\n\n        for mode in ('L', 'RGB', 'RGBA'):\n            roundtrip(hopper(mode))\n\n        # Test 1 dimension for an L mode image\n        roundtrip(Image.new('L', (10, 1)))\n\n    def test_write16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        out = self.tempfile('temp.sgi')\n        im.save(out, format='sgi', bpc=2)\n\n        reloaded = Image.open(out)\n        self.assert_image_equal(im, reloaded)\n\n    def test_unsupported_mode(self):\n        im = hopper('LA')\n        out = self.tempfile('temp.sgi')\n\n        self.assertRaises(ValueError, im.save, out, format='sgi')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 6,
                            "end_lineno": 91,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# SGI image file handling\n#\n# See \"The SGI Image File Format (Draft version 0.97)\", Paul Haeberli.\n# <ftp://ftp.sgi.com/graphics/SGIIMAGESPEC>\n#\n#\n# History:\n# 2017-22-07 mb   Add RLE decompression\n# 2016-16-10 mb   Add save method without compression\n# 1995-09-10 fl   Created\n#\n# Copyright (c) 2016 by Mickael Bonfill.\n# Copyright (c) 2008 by Karsten Hiddemann.\n# Copyright (c) 1997 by Secret Labs AB.\n# Copyright (c) 1995 by Fredrik Lundh.\n#\n# See the README file for information on usage and redistribution.\n#\n\n\nfrom . import Image, ImageFile\nfrom ._binary import i8, o8, i16be as i16\nfrom ._util import py3\nimport struct\nimport os\n\n\n__version__ = \"0.3\"\n\n\ndef _accept(prefix):\n    return len(prefix) >= 2 and i16(prefix) == 474\n\n\nMODES = {\n    (1, 1, 1): \"L\",\n    (1, 2, 1): \"L\",\n    (2, 1, 1): \"L;16B\",\n    (2, 2, 1): \"L;16B\",\n    (1, 3, 3): \"RGB\",\n    (2, 3, 3): \"RGB;16B\",\n    (1, 3, 4): \"RGBA\",\n    (2, 3, 4): \"RGBA;16B\"\n}\n\n\n##\n# Image plugin for SGI images.\nclass SgiImageFile(ImageFile.ImageFile):\n\n    format = \"SGI\"\n    format_description = \"SGI Image File Format\"\n\n    def _open(self):\n\n        # HEAD\n        headlen = 512\n        s = self.fp.read(headlen)\n\n        # magic number : 474\n        if i16(s) != 474:\n            raise ValueError(\"Not an SGI image file\")\n\n        # compression : verbatim or RLE\n        compression = i8(s[2])\n\n        # bpc : 1 or 2 bytes (8bits or 16bits)\n        bpc = i8(s[3])\n\n        # dimension : 1, 2 or 3 (depending on xsize, ysize and zsize)\n        dimension = i16(s[4:])\n\n        # xsize : width\n        xsize = i16(s[6:])\n\n        # ysize : height\n        ysize = i16(s[8:])\n\n        # zsize : channels count\n        zsize = i16(s[10:])\n\n        # layout\n        layout = bpc, dimension, zsize\n\n        # determine mode from bits/zsize\n        rawmode = \"\"\n        try:\n            rawmode = MODES[layout]\n        except KeyError:\n            pass\n\n        if rawmode == \"\":\n            raise ValueError(\"Unsupported SGI image mode\")\n\n        self._size = xsize, ysize\n        self.mode = rawmode.split(\";\")[0]\n\n        # orientation -1 : scanlines begins at the bottom-left corner\n        orientation = -1\n\n        # decoder info\n        if compression == 0:\n            pagesize = xsize * ysize * bpc\n            if bpc == 2:\n                self.tile = [(\"SGI16\", (0, 0) + self.size,\n                              headlen, (self.mode, 0, orientation))]\n            else:\n                self.tile = []\n                offset = headlen\n                for layer in self.mode:\n                    self.tile.append(\n                        (\"raw\", (0, 0) + self.size,\n                            offset, (layer, 0, orientation)))\n                    offset += pagesize\n        elif compression == 1:\n            self.tile = [(\"sgi_rle\", (0, 0) + self.size,\n                          headlen, (rawmode, orientation, bpc))]\n\n\ndef _save(im, fp, filename):\n    if im.mode != \"RGB\" and im.mode != \"RGBA\" and im.mode != \"L\":\n        raise ValueError(\"Unsupported SGI image mode\")\n\n    # Get the keyword arguments\n    info = im.encoderinfo\n\n    # Byte-per-pixel precision, 1 = 8bits per pixel\n    bpc = info.get(\"bpc\", 1)\n\n    if bpc not in (1, 2):\n        raise ValueError(\"Unsupported number of bytes per pixel\")\n\n    # Flip the image, since the origin of SGI file is the bottom-left corner\n    orientation = -1\n    # Define the file as SGI File Format\n    magicNumber = 474\n    # Run-Length Encoding Compression - Unsupported at this time\n    rle = 0\n\n    # Number of dimensions (x,y,z)\n    dim = 3\n    # X Dimension = width / Y Dimension = height\n    x, y = im.size\n    if im.mode == \"L\" and y == 1:\n        dim = 1\n    elif im.mode == \"L\":\n        dim = 2\n    # Z Dimension: Number of channels\n    z = len(im.mode)\n\n    if dim == 1 or dim == 2:\n        z = 1\n\n    # assert we've got the right number of bands.\n    if len(im.getbands()) != z:\n        raise ValueError(\"incorrect number of bands in SGI write: %s vs %s\" %\n                         (z, len(im.getbands())))\n\n    # Minimum Byte value\n    pinmin = 0\n    # Maximum Byte value (255 = 8bits per pixel)\n    pinmax = 255\n    # Image name (79 characters max, truncated below in write)\n    imgName = os.path.splitext(os.path.basename(filename))[0]\n    if py3:\n        imgName = imgName.encode('ascii', 'ignore')\n    # Standard representation of pixel in the file\n    colormap = 0\n    fp.write(struct.pack('>h', magicNumber))\n    fp.write(o8(rle))\n    fp.write(o8(bpc))\n    fp.write(struct.pack('>H', dim))\n    fp.write(struct.pack('>H', x))\n    fp.write(struct.pack('>H', y))\n    fp.write(struct.pack('>H', z))\n    fp.write(struct.pack('>l', pinmin))\n    fp.write(struct.pack('>l', pinmax))\n    fp.write(struct.pack('4s', b''))  # dummy\n    fp.write(struct.pack('79s', imgName))  # truncates to 79 chars\n    fp.write(struct.pack('s', b''))  # force null byte after imgname\n    fp.write(struct.pack('>l', colormap))\n    fp.write(struct.pack('404s', b''))  # dummy\n\n    rawmode = 'L'\n    if bpc == 2:\n        rawmode = 'L;16B'\n\n    for channel in im.split():\n        fp.write(channel.tobytes('raw', rawmode, 0, orientation))\n\n    fp.close()\n\n\nclass SGI16Decoder(ImageFile.PyDecoder):\n    _pulls_fd = True\n\n    def decode(self, buffer):\n        rawmode, stride, orientation = self.args\n        pagesize = self.state.xsize * self.state.ysize\n        zsize = len(self.mode)\n        self.fd.seek(512)\n\n        for band in range(zsize):\n            channel = Image.new('L', (self.state.xsize, self.state.ysize))\n            channel.frombytes(self.fd.read(2 * pagesize), 'raw',\n                              'L;16B', stride, orientation)\n            self.im.putband(channel.im, band)\n\n        return -1, 0\n\n#\n# registry\n\n\nImage.register_decoder(\"SGI16\", SGI16Decoder)\nImage.register_open(SgiImageFile.format, SgiImageFile, _accept)\nImage.register_save(SgiImageFile.format, _save)\nImage.register_mime(SgiImageFile.format, \"image/sgi\")\nImage.register_mime(SgiImageFile.format, \"image/rgb\")\n\nImage.register_extensions(SgiImageFile.format,\n                          [\".bw\", \".rgb\", \".rgba\", \".sgi\"])\n\n# End of file\n",
            "new_file_content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# SGI image file handling\n#\n# See \"The SGI Image File Format (Draft version 0.97)\", Paul Haeberli.\n# <ftp://ftp.sgi.com/graphics/SGIIMAGESPEC>\n#\n#\n# History:\n# 2017-22-07 mb   Add RLE decompression\n# 2016-16-10 mb   Add save method without compression\n# 1995-09-10 fl   Created\n#\n# Copyright (c) 2016 by Mickael Bonfill.\n# Copyright (c) 2008 by Karsten Hiddemann.\n# Copyright (c) 1997 by Secret Labs AB.\n# Copyright (c) 1995 by Fredrik Lundh.\n#\n# See the README file for information on usage and redistribution.\n#\n\n\nfrom . import Image, ImageFile\nfrom ._binary import i8, o8, i16be as i16\nfrom ._util import py3\nimport struct\nimport os\n\n\n__version__ = \"0.3\"\n\n\ndef _accept(prefix):\n    return len(prefix) >= 2 and i16(prefix) == 474\n\n\nMODES = {\n    (1, 1, 1): \"L\",\n    (1, 2, 1): \"L\",\n    (2, 1, 1): \"L;16B\",\n    (2, 2, 1): \"L;16B\",\n    (1, 3, 3): \"RGB\",\n    (2, 3, 3): \"RGB;16B\",\n    (1, 3, 4): \"RGBA\",\n    (2, 3, 4): \"RGBA;16B\"\n}\n\n\n##\n# Image plugin for SGI images.\nclass SgiImageFile(ImageFile.ImageFile):\n\n    format = \"SGI\"\n    format_description = \"SGI Image File Format\"\n\n    def _open(self):\n\n        # HEAD\n        headlen = 512\n        s = self.fp.read(headlen)\n\n        # magic number : 474\n        if i16(s) != 474:\n            raise ValueError(\"Not an SGI image file\")\n\n        # compression : verbatim or RLE\n        compression = i8(s[2])\n\n        # bpc : 1 or 2 bytes (8bits or 16bits)\n        bpc = i8(s[3])\n\n        # dimension : 1, 2 or 3 (depending on xsize, ysize and zsize)\n        dimension = i16(s[4:])\n\n        # xsize : width\n        xsize = i16(s[6:])\n\n        # ysize : height\n        ysize = i16(s[8:])\n\n        # zsize : channels count\n        zsize = i16(s[10:])\n\n        # layout\n        layout = bpc, dimension, zsize\n\n        # determine mode from bits/zsize\n        rawmode = \"\"\n        try:\n            rawmode = MODES[layout]\n        except KeyError:\n            pass\n\n        if rawmode == \"\":\n            raise ValueError(\"Unsupported SGI image mode\")\n\n        self._size = xsize, ysize\n        self.mode = rawmode.split(\";\")[0]\n        if self.mode == 'RGB':\n            self.custom_mimetype = 'image/rgb'\n\n        # orientation -1 : scanlines begins at the bottom-left corner\n        orientation = -1\n\n        # decoder info\n        if compression == 0:\n            pagesize = xsize * ysize * bpc\n            if bpc == 2:\n                self.tile = [(\"SGI16\", (0, 0) + self.size,\n                              headlen, (self.mode, 0, orientation))]\n            else:\n                self.tile = []\n                offset = headlen\n                for layer in self.mode:\n                    self.tile.append(\n                        (\"raw\", (0, 0) + self.size,\n                            offset, (layer, 0, orientation)))\n                    offset += pagesize\n        elif compression == 1:\n            self.tile = [(\"sgi_rle\", (0, 0) + self.size,\n                          headlen, (rawmode, orientation, bpc))]\n\n\ndef _save(im, fp, filename):\n    if im.mode != \"RGB\" and im.mode != \"RGBA\" and im.mode != \"L\":\n        raise ValueError(\"Unsupported SGI image mode\")\n\n    # Get the keyword arguments\n    info = im.encoderinfo\n\n    # Byte-per-pixel precision, 1 = 8bits per pixel\n    bpc = info.get(\"bpc\", 1)\n\n    if bpc not in (1, 2):\n        raise ValueError(\"Unsupported number of bytes per pixel\")\n\n    # Flip the image, since the origin of SGI file is the bottom-left corner\n    orientation = -1\n    # Define the file as SGI File Format\n    magicNumber = 474\n    # Run-Length Encoding Compression - Unsupported at this time\n    rle = 0\n\n    # Number of dimensions (x,y,z)\n    dim = 3\n    # X Dimension = width / Y Dimension = height\n    x, y = im.size\n    if im.mode == \"L\" and y == 1:\n        dim = 1\n    elif im.mode == \"L\":\n        dim = 2\n    # Z Dimension: Number of channels\n    z = len(im.mode)\n\n    if dim == 1 or dim == 2:\n        z = 1\n\n    # assert we've got the right number of bands.\n    if len(im.getbands()) != z:\n        raise ValueError(\"incorrect number of bands in SGI write: %s vs %s\" %\n                         (z, len(im.getbands())))\n\n    # Minimum Byte value\n    pinmin = 0\n    # Maximum Byte value (255 = 8bits per pixel)\n    pinmax = 255\n    # Image name (79 characters max, truncated below in write)\n    imgName = os.path.splitext(os.path.basename(filename))[0]\n    if py3:\n        imgName = imgName.encode('ascii', 'ignore')\n    # Standard representation of pixel in the file\n    colormap = 0\n    fp.write(struct.pack('>h', magicNumber))\n    fp.write(o8(rle))\n    fp.write(o8(bpc))\n    fp.write(struct.pack('>H', dim))\n    fp.write(struct.pack('>H', x))\n    fp.write(struct.pack('>H', y))\n    fp.write(struct.pack('>H', z))\n    fp.write(struct.pack('>l', pinmin))\n    fp.write(struct.pack('>l', pinmax))\n    fp.write(struct.pack('4s', b''))  # dummy\n    fp.write(struct.pack('79s', imgName))  # truncates to 79 chars\n    fp.write(struct.pack('s', b''))  # force null byte after imgname\n    fp.write(struct.pack('>l', colormap))\n    fp.write(struct.pack('404s', b''))  # dummy\n\n    rawmode = 'L'\n    if bpc == 2:\n        rawmode = 'L;16B'\n\n    for channel in im.split():\n        fp.write(channel.tobytes('raw', rawmode, 0, orientation))\n\n    fp.close()\n\n\nclass SGI16Decoder(ImageFile.PyDecoder):\n    _pulls_fd = True\n\n    def decode(self, buffer):\n        rawmode, stride, orientation = self.args\n        pagesize = self.state.xsize * self.state.ysize\n        zsize = len(self.mode)\n        self.fd.seek(512)\n\n        for band in range(zsize):\n            channel = Image.new('L', (self.state.xsize, self.state.ysize))\n            channel.frombytes(self.fd.read(2 * pagesize), 'raw',\n                              'L;16B', stride, orientation)\n            self.im.putband(channel.im, band)\n\n        return -1, 0\n\n#\n# registry\n\n\nImage.register_decoder(\"SGI16\", SGI16Decoder)\nImage.register_open(SgiImageFile.format, SgiImageFile, _accept)\nImage.register_save(SgiImageFile.format, _save)\nImage.register_mime(SgiImageFile.format, \"image/sgi\")\n\nImage.register_extensions(SgiImageFile.format,\n                          [\".bw\", \".rgb\", \".rgba\", \".sgi\"])\n\n# End of file\n",
            "header": {
                "file": {
                    "path": "src/PIL/SgiImagePlugin.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "88df35135",
                "new_commit_hash": "91753380d",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/src/PIL/SgiImagePlugin.py"
            },
            "plus_file": {
                "path": "b/src/PIL/SgiImagePlugin.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 98,
                            "length": 6
                        },
                        "new_range": {
                            "start": 98,
                            "length": 8
                        },
                        "section": "class SgiImageFile(ImageFile.ImageFile):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        self._size = xsize, ysize",
                                "type": "context"
                            },
                            {
                                "content": "        self.mode = rawmode.split(\";\")[0]",
                                "type": "context"
                            },
                            {
                                "content": "        if self.mode == 'RGB':",
                                "type": "added"
                            },
                            {
                                "content": "            self.custom_mimetype = 'image/rgb'",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        # orientation -1 : scanlines begins at the bottom-left corner",
                                "type": "context"
                            },
                            {
                                "content": "        orientation = -1",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "src/PIL/SgiImagePlugin.py",
                            "type": "method",
                            "name": "SgiImageFile._open",
                            "content": "class SgiImageFile(ImageFile.ImageFile):\n\n    format = \"SGI\"\n    format_description = \"SGI Image File Format\"\n\n    def _open(self):\n\n        # HEAD\n        headlen = 512\n        s = self.fp.read(headlen)\n\n        # magic number : 474\n        if i16(s) != 474:\n            raise ValueError(\"Not an SGI image file\")\n\n        # compression : verbatim or RLE\n        compression = i8(s[2])\n\n        # bpc : 1 or 2 bytes (8bits or 16bits)\n        bpc = i8(s[3])\n\n        # dimension : 1, 2 or 3 (depending on xsize, ysize and zsize)\n        dimension = i16(s[4:])\n\n        # xsize : width\n        xsize = i16(s[6:])\n\n        # ysize : height\n        ysize = i16(s[8:])\n\n        # zsize : channels count\n        zsize = i16(s[10:])\n\n        # layout\n        layout = bpc, dimension, zsize\n\n        # determine mode from bits/zsize\n        rawmode = \"\"\n        try:\n            rawmode = MODES[layout]\n        except KeyError:\n            pass\n\n        if rawmode == \"\":\n            raise ValueError(\"Unsupported SGI image mode\")\n\n        self._size = xsize, ysize\n        self.mode = rawmode.split(\";\")[0]\n        if self.mode == 'RGB':\n            self.custom_mimetype = 'image/rgb'\n\n        # orientation -1 : scanlines begins at the bottom-left corner\n        orientation = -1\n\n        # decoder info\n        if compression == 0:\n            pagesize = xsize * ysize * bpc\n            if bpc == 2:\n                self.tile = [(\"SGI16\", (0, 0) + self.size,\n                              headlen, (self.mode, 0, orientation))]\n            else:\n                self.tile = []\n                offset = headlen\n                for layer in self.mode:\n                    self.tile.append(\n                        (\"raw\", (0, 0) + self.size,\n                            offset, (layer, 0, orientation)))\n                    offset += pagesize\n        elif compression == 1:\n            self.tile = [(\"sgi_rle\", (0, 0) + self.size,\n                          headlen, (rawmode, orientation, bpc))]",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 58,
                            "end_lineno": 123,
                            "parent": {
                                "file_name": "src/PIL/SgiImagePlugin.py",
                                "type": "class",
                                "name": "SgiImageFile",
                                "content": "class SgiImageFile(ImageFile.ImageFile):\n\n    format = \"SGI\"\n    format_description = \"SGI Image File Format\"\n\n    def _open(self):\n\n        # HEAD\n        headlen = 512\n        s = self.fp.read(headlen)\n\n        # magic number : 474\n        if i16(s) != 474:\n            raise ValueError(\"Not an SGI image file\")\n\n        # compression : verbatim or RLE\n        compression = i8(s[2])\n\n        # bpc : 1 or 2 bytes (8bits or 16bits)\n        bpc = i8(s[3])\n\n        # dimension : 1, 2 or 3 (depending on xsize, ysize and zsize)\n        dimension = i16(s[4:])\n\n        # xsize : width\n        xsize = i16(s[6:])\n\n        # ysize : height\n        ysize = i16(s[8:])\n\n        # zsize : channels count\n        zsize = i16(s[10:])\n\n        # layout\n        layout = bpc, dimension, zsize\n\n        # determine mode from bits/zsize\n        rawmode = \"\"\n        try:\n            rawmode = MODES[layout]\n        except KeyError:\n            pass\n\n        if rawmode == \"\":\n            raise ValueError(\"Unsupported SGI image mode\")\n\n        self._size = xsize, ysize\n        self.mode = rawmode.split(\";\")[0]\n        if self.mode == 'RGB':\n            self.custom_mimetype = 'image/rgb'\n\n        # orientation -1 : scanlines begins at the bottom-left corner\n        orientation = -1\n\n        # decoder info\n        if compression == 0:\n            pagesize = xsize * ysize * bpc\n            if bpc == 2:\n                self.tile = [(\"SGI16\", (0, 0) + self.size,\n                              headlen, (self.mode, 0, orientation))]\n            else:\n                self.tile = []\n                offset = headlen\n                for layer in self.mode:\n                    self.tile.append(\n                        (\"raw\", (0, 0) + self.size,\n                            offset, (layer, 0, orientation)))\n                    offset += pagesize\n        elif compression == 1:\n            self.tile = [(\"sgi_rle\", (0, 0) + self.size,\n                          headlen, (rawmode, orientation, bpc))]",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 53,
                                "end_lineno": 123,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "src/PIL/SgiImagePlugin.py",
                            "type": "class",
                            "name": "SgiImageFile",
                            "content": "class SgiImageFile(ImageFile.ImageFile):\n\n    format = \"SGI\"\n    format_description = \"SGI Image File Format\"\n\n    def _open(self):\n\n        # HEAD\n        headlen = 512\n        s = self.fp.read(headlen)\n\n        # magic number : 474\n        if i16(s) != 474:\n            raise ValueError(\"Not an SGI image file\")\n\n        # compression : verbatim or RLE\n        compression = i8(s[2])\n\n        # bpc : 1 or 2 bytes (8bits or 16bits)\n        bpc = i8(s[3])\n\n        # dimension : 1, 2 or 3 (depending on xsize, ysize and zsize)\n        dimension = i16(s[4:])\n\n        # xsize : width\n        xsize = i16(s[6:])\n\n        # ysize : height\n        ysize = i16(s[8:])\n\n        # zsize : channels count\n        zsize = i16(s[10:])\n\n        # layout\n        layout = bpc, dimension, zsize\n\n        # determine mode from bits/zsize\n        rawmode = \"\"\n        try:\n            rawmode = MODES[layout]\n        except KeyError:\n            pass\n\n        if rawmode == \"\":\n            raise ValueError(\"Unsupported SGI image mode\")\n\n        self._size = xsize, ysize\n        self.mode = rawmode.split(\";\")[0]\n        if self.mode == 'RGB':\n            self.custom_mimetype = 'image/rgb'\n\n        # orientation -1 : scanlines begins at the bottom-left corner\n        orientation = -1\n\n        # decoder info\n        if compression == 0:\n            pagesize = xsize * ysize * bpc\n            if bpc == 2:\n                self.tile = [(\"SGI16\", (0, 0) + self.size,\n                              headlen, (self.mode, 0, orientation))]\n            else:\n                self.tile = []\n                offset = headlen\n                for layer in self.mode:\n                    self.tile.append(\n                        (\"raw\", (0, 0) + self.size,\n                            offset, (layer, 0, orientation)))\n                    offset += pagesize\n        elif compression == 1:\n            self.tile = [(\"sgi_rle\", (0, 0) + self.size,\n                          headlen, (rawmode, orientation, bpc))]",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 53,
                            "end_lineno": 123,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 220,
                            "length": 7
                        },
                        "new_range": {
                            "start": 222,
                            "length": 6
                        },
                        "section": "Image.register_decoder(\"SGI16\", SGI16Decoder)"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "Image.register_open(SgiImageFile.format, SgiImageFile, _accept)",
                                "type": "context"
                            },
                            {
                                "content": "Image.register_save(SgiImageFile.format, _save)",
                                "type": "context"
                            },
                            {
                                "content": "Image.register_mime(SgiImageFile.format, \"image/sgi\")",
                                "type": "context"
                            },
                            {
                                "content": "Image.register_mime(SgiImageFile.format, \"image/rgb\")",
                                "type": "deleted"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "Image.register_extensions(SgiImageFile.format,",
                                "type": "context"
                            },
                            {
                                "content": "                          [\".bw\", \".rgb\", \".rgba\", \".sgi\"])",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [],
                    "added_entities": [],
                    "deleted_entities": [
                        {
                            "file_name": "src/PIL/SgiImagePlugin.py",
                            "type": "statement",
                            "name": "",
                            "content": "Image.register_mime(SgiImageFile.format, \"image/rgb\")",
                            "ast_type_str": "Expr",
                            "start_lineno": 223,
                            "end_lineno": 223,
                            "parent": null
                        }
                    ]
                }
            ]
        }
    ],
    "old_commit_hash": "42e2bed4a6a35b140352eba13b2e695023ca66e4^",
    "new_commit_hash": "42e2bed4a6a35b140352eba13b2e695023ca66e4",
    "commit_message": "If SGI image is RGB mode, then apply image/rgb mimetype",
    "commit_date": "2019-01-02T14:13:37+11:00",
    "metadata": {}
}
{
    "repo_name": "pillow",
    "new_commit_hash": "42e2bed4a6a35b140352eba13b2e695023ca66e4",
    "test_file_codes": [
        "from helper import unittest, PillowTestCase, hopper\n\nfrom PIL import Image, SgiImagePlugin\n\n\nclass TestFileSgi(PillowTestCase):\n\n    def test_rgb(self):\n        # Created with ImageMagick then renamed:\n        # convert hopper.ppm -compress None sgi:hopper.rgb\n        test_file = \"Tests/images/hopper.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n        self.assertEqual(im.get_format_mimetype(), 'image/rgb')\n\n    def test_rgb16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        self.assert_image_equal(im, hopper())\n\n    def test_l(self):\n        # Created with ImageMagick\n        # convert hopper.ppm -monochrome -compress None sgi:hopper.bw\n        test_file = \"Tests/images/hopper.bw\"\n\n        im = Image.open(test_file)\n        self.assert_image_similar(im, hopper('L'), 2)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rgba(self):\n        # Created with ImageMagick:\n        # convert transparent.png -compress None transparent.sgi\n        test_file = \"Tests/images/transparent.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/transparent.png')\n        self.assert_image_equal(im, target)\n        self.assertEqual(im.get_format_mimetype(), 'image/sgi')\n\n    def test_rle(self):\n        # Created with ImageMagick:\n        # convert hopper.ppm  hopper.sgi\n        test_file = \"Tests/images/hopper.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/hopper.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_rle16(self):\n        test_file = \"Tests/images/tv16.sgi\"\n\n        im = Image.open(test_file)\n        target = Image.open('Tests/images/tv.rgb')\n        self.assert_image_equal(im, target)\n\n    def test_invalid_file(self):\n        invalid_file = \"Tests/images/flower.jpg\"\n\n        self.assertRaises(ValueError,\n                          SgiImagePlugin.SgiImageFile, invalid_file)\n\n    def test_write(self):\n        def roundtrip(img):\n            out = self.tempfile('temp.sgi')\n            img.save(out, format='sgi')\n            reloaded = Image.open(out)\n            self.assert_image_equal(img, reloaded)\n\n        for mode in ('L', 'RGB', 'RGBA'):\n            roundtrip(hopper(mode))\n\n        # Test 1 dimension for an L mode image\n        roundtrip(Image.new('L', (10, 1)))\n\n    def test_write16(self):\n        test_file = \"Tests/images/hopper16.rgb\"\n\n        im = Image.open(test_file)\n        out = self.tempfile('temp.sgi')\n        im.save(out, format='sgi', bpc=2)\n\n        reloaded = Image.open(out)\n        self.assert_image_equal(im, reloaded)\n\n    def test_unsupported_mode(self):\n        im = hopper('LA')\n        out = self.tempfile('temp.sgi')\n\n        self.assertRaises(ValueError, im.save, out, format='sgi')\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 13ms\nInstalled 12 packages in 110ms\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 786ms\nPrepared 1 package in 31.77s\nInstalled 1 package in 1ms\n + pillow==5.5.0.dev0 (from file:///home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_42e2bed4a6a35b140352eba13b2e695023ca66e4)\n",
    "new_commit_res_code": 0,
    "new_commit_res_stdout": "============================= test session starts =============================\nplatform linux -- Python 3.9.21\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_42e2bed4a6a35b140352eba13b2e695023ca66e4\n..........\ncollected 10 items\n\n==================== short test summary info ====================\nPASSED test_1::TestFileSgi::test_invalid_file\nPASSED test_1::TestFileSgi::test_l\nPASSED test_1::TestFileSgi::test_rgb\nPASSED test_1::TestFileSgi::test_rgb16\nPASSED test_1::TestFileSgi::test_rgba\nPASSED test_1::TestFileSgi::test_rle\nPASSED test_1::TestFileSgi::test_rle16\nPASSED test_1::TestFileSgi::test_unsupported_mode\nPASSED test_1::TestFileSgi::test_write\nPASSED test_1::TestFileSgi::test_write16\n=================== 10 passed in 0.15s ===================\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_42e2bed4a6a35b140352eba13b2e695023ca66e4\n........=== orphaned temp file: /tmp/temp5qwd6mr4.sgi\n.=== orphaned temp file: /tmp/temp8xiu02mh.sgi\n=== orphaned temp file: /tmp/temphyytb3kt.sgi\n=== orphaned temp file: /tmp/temp_ce6di5l.sgi\n=== orphaned temp file: /tmp/tempd19vzbnp.sgi\n.=== orphaned temp file: /tmp/tempswk_szz9.sgi\n\ncollected 10 items\n\n=================================== FAILURES ===================================\n__________ TestFileSgi.test_l __________\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_42e2bed4a6a35b140352eba13b2e695023ca66e4/r2e_tests/test_1.py\", line 30, in test_l\n    self.assertEqual(im.get_format_mimetype(), 'image/sgi')\nAssertionError: 'image/rgb' != 'image/sgi'\n- image/rgb\n?       ^ ^\n+ image/sgi\n?       ^ ^\n\n__________ TestFileSgi.test_rgba __________\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_42e2bed4a6a35b140352eba13b2e695023ca66e4/r2e_tests/test_1.py\", line 40, in test_rgba\n    self.assertEqual(im.get_format_mimetype(), 'image/sgi')\nAssertionError: 'image/rgb' != 'image/sgi'\n- image/rgb\n?       ^ ^\n+ image/sgi\n?       ^ ^\n\n\n==================== short test summary info ====================\nPASSED test_1::TestFileSgi::test_invalid_file\nFAILED test_1::TestFileSgi::test_l\nPASSED test_1::TestFileSgi::test_rgb\nPASSED test_1::TestFileSgi::test_rgb16\nFAILED test_1::TestFileSgi::test_rgba\nPASSED test_1::TestFileSgi::test_rle\nPASSED test_1::TestFileSgi::test_rle16\nPASSED test_1::TestFileSgi::test_unsupported_mode\nPASSED test_1::TestFileSgi::test_write\nPASSED test_1::TestFileSgi::test_write16\n=================== 2 failed, 8 passed in 0.11s ===================\n",
    "old_commit_res_stderr": ""
}
Tests/test_file_sgi.py src/PIL/SgiImagePlugin.py
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** SGI Images in Non-RGB Mode Incorrectly Assigned 'image/rgb' MIME Type

**Description:**
When processing SGI images that are not in RGB mode, the MIME type is incorrectly set to `'image/rgb'` instead of `'image/sgi'`. This leads to unexpected behavior in functionalities that depend on the correct MIME type.

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

# Open a black and white SGI image
im = Image.open('Tests/images/hopper.bw')
mimetype = im.get_format_mimetype()
print(mimetype)  # Outputs: 'image/rgb'
```

**Expected Behavior:**
For SGI images that are not in RGB mode, the `get_format_mimetype()` method should return `'image/sgi'`.

**Actual Behavior:**
The `get_format_mimetype()` method returns `'image/rgb'`, causing misinterpretation of the image format.
[/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/SgiImagePlugin.py
#
# The Python Imaging Library.
# $Id$
#
# SGI image file handling
#
# See "The SGI Image File Format (Draft version 0.97)", Paul Haeberli.
# <ftp://ftp.sgi.com/graphics/SGIIMAGESPEC>
#
#
# History:
# 2017-22-07 mb   Add RLE decompression
# 2016-16-10 mb   Add save method without compression
# 1995-09-10 fl   Created
#
# Copyright (c) 2016 by Mickael Bonfill.
# Copyright (c) 2008 by Karsten Hiddemann.
# Copyright (c) 1997 by Secret Labs AB.
# Copyright (c) 1995 by Fredrik Lundh.
#
# See the README file for information on usage and redistribution.
#


from . import Image, ImageFile
from ._binary import i8, o8, i16be as i16
from ._util import py3
import struct
import os


__version__ = "0.3"


def _accept(prefix):
    return len(prefix) >= 2 and i16(prefix) == 474


MODES = {
    (1, 1, 1): "L",
    (1, 2, 1): "L",
    (2, 1, 1): "L;16B",
    (2, 2, 1): "L;16B",
    (1, 3, 3): "RGB",
    (2, 3, 3): "RGB;16B",
    (1, 3, 4): "RGBA",
    (2, 3, 4): "RGBA;16B"
}


##
# Image plugin for SGI images.
class SgiImageFile(ImageFile.ImageFile):

    format = "SGI"
    format_description = "SGI Image File Format"

    def _open(self):

        # HEAD
        headlen = 512
        s = self.fp.read(headlen)

        # magic number : 474
        if i16(s) != 474:
            raise ValueError("Not an SGI image file")

        # compression : verbatim or RLE
        compression = i8(s[2])

        # bpc : 1 or 2 bytes (8bits or 16bits)
        bpc = i8(s[3])

        # dimension : 1, 2 or 3 (depending on xsize, ysize and zsize)
        dimension = i16(s[4:])

        # xsize : width
        xsize = i16(s[6:])

        # ysize : height
        ysize = i16(s[8:])

        # zsize : channels count
        zsize = i16(s[10:])

        # layout
        layout = bpc, dimension, zsize

        # determine mode from bits/zsize
        rawmode = ""
        try:
            rawmode = MODES[layout]
        except KeyError:
            pass

        if rawmode == "":
            raise ValueError("Unsupported SGI image mode")

        self._size = xsize, ysize
        self.mode = rawmode.split(";")[0]

        # orientation -1 : scanlines begins at the bottom-left corner
        orientation = -1

        # decoder info
        if compression == 0:
            pagesize = xsize * ysize * bpc
            if bpc == 2:
                self.tile = [("SGI16", (0, 0) + self.size,
                              headlen, (self.mode, 0, orientation))]
            else:
                self.tile = []
                offset = headlen
                for layer in self.mode:
                    self.tile.append(
                        ("raw", (0, 0) + self.size,
                            offset, (layer, 0, orientation)))
                    offset += pagesize
        elif compression == 1:
            self.tile = [("sgi_rle", (0, 0) + self.size,
                          headlen, (rawmode, orientation, bpc))]


def _save(im, fp, filename):
    if im.mode != "RGB" and im.mode != "RGBA" and im.mode != "L":
        raise ValueError("Unsupported SGI image mode")

    # Get the keyword arguments
    info = im.encoderinfo

    # Byte-per-pixel precision, 1 = 8bits per pixel
    bpc = info.get("bpc", 1)

    if bpc not in (1, 2):
        raise ValueError("Unsupported number of bytes per pixel")

    # Flip the image, since the origin of SGI file is the bottom-left corner
    orientation = -1
    # Define the file as SGI File Format
    magicNumber = 474
    # Run-Length Encoding Compression - Unsupported at this time
    rle = 0

    # Number of dimensions (x,y,z)
    dim = 3
    # X Dimension = width / Y Dimension = height
    x, y = im.size
    if im.mode == "L" and y == 1:
        dim = 1
    elif im.mode == "L":
        dim = 2
    # Z Dimension: Number of channels
    z = len(im.mode)

    if dim == 1 or dim == 2:
        z = 1

    # assert we've got the right number of bands.
    if len(im.getbands()) != z:
        raise ValueError("incorrect number of bands in SGI write: %s vs %s" %
                         (z, len(im.getbands())))

    # Minimum Byte value
    pinmin = 0
    # Maximum Byte value (255 = 8bits per pixel)
    pinmax = 255
    # Image name (79 characters max, truncated below in write)
    imgName = os.path.splitext(os.path.basename(filename))[0]
    if py3:
        imgName = imgName.encode('ascii', 'ignore')
    # Standard representation of pixel in the file
    colormap = 0
    fp.write(struct.pack('>h', magicNumber))
    fp.write(o8(rle))
    fp.write(o8(bpc))
    fp.write(struct.pack('>H', dim))
    fp.write(struct.pack('>H', x))
    fp.write(struct.pack('>H', y))
    fp.write(struct.pack('>H', z))
    fp.write(struct.pack('>l', pinmin))
    fp.write(struct.pack('>l', pinmax))
    fp.write(struct.pack('4s', b''))  # dummy
    fp.write(struct.pack('79s', imgName))  # truncates to 79 chars
    fp.write(struct.pack('s', b''))  # force null byte after imgname
    fp.write(struct.pack('>l', colormap))
    fp.write(struct.pack('404s', b''))  # dummy

    rawmode = 'L'
    if bpc == 2:
        rawmode = 'L;16B'

    for channel in im.split():
        fp.write(channel.tobytes('raw', rawmode, 0, orientation))

    fp.close()


class SGI16Decoder(ImageFile.PyDecoder):
    _pulls_fd = True

    def decode(self, buffer):
        rawmode, stride, orientation = self.args
        pagesize = self.state.xsize * self.state.ysize
        zsize = len(self.mode)
        self.fd.seek(512)

        for band in range(zsize):
            channel = Image.new('L', (self.state.xsize, self.state.ysize))
            channel.frombytes(self.fd.read(2 * pagesize), 'raw',
                              'L;16B', stride, orientation)
            self.im.putband(channel.im, band)

        return -1, 0

#
# registry


Image.register_decoder("SGI16", SGI16Decoder)
Image.register_open(SgiImageFile.format, SgiImageFile, _accept)
Image.register_save(SgiImageFile.format, _save)
Image.register_mime(SgiImageFile.format, "image/sgi")
Image.register_mime(SgiImageFile.format, "image/rgb")

Image.register_extensions(SgiImageFile.format,
                          [".bw", ".rgb", ".rgba", ".sgi"])

# End of file

```
--- 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:** SGI Images in Non-RGB Mode Incorrectly Assigned 'image/rgb' MIME Type

**Description:**
When processing SGI images that are not in RGB mode, the MIME type is incorrectly set to `'image/rgb'` instead of `'image/sgi'`. This leads to unexpected behavior in functionalities that depend on the correct MIME type.

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

# Open a black and white SGI image
im = Image.open('Tests/images/hopper.bw')
mimetype = im.get_format_mimetype()
print(mimetype)  # Outputs: 'image/rgb'
```

**Expected Behavior:**
For SGI images that are not in RGB mode, the `get_format_mimetype()` method should return `'image/sgi'`.

**Actual Behavior:**
The `get_format_mimetype()` method returns `'image/rgb'`, causing misinterpretation of the image format.
[/ISSUE]
{
    "TestFileSgi.test_invalid_file": "PASSED",
    "TestFileSgi.test_l": "PASSED",
    "TestFileSgi.test_rgb": "PASSED",
    "TestFileSgi.test_rgb16": "PASSED",
    "TestFileSgi.test_rgba": "PASSED",
    "TestFileSgi.test_rle": "PASSED",
    "TestFileSgi.test_rle16": "PASSED",
    "TestFileSgi.test_unsupported_mode": "PASSED",
    "TestFileSgi.test_write": "PASSED",
    "TestFileSgi.test_write16": "PASSED"
}
diff --git a/src/PIL/SgiImagePlugin.py b/src/PIL/SgiImagePlugin.py
index 88df35135..91753380d 100644
--- a/src/PIL/SgiImagePlugin.py
+++ b/src/PIL/SgiImagePlugin.py
@@ -98,6 +98,8 @@ class SgiImageFile(ImageFile.ImageFile):
 
         self._size = xsize, ysize
         self.mode = rawmode.split(";")[0]
+        if self.mode == 'RGB':
+            self.custom_mimetype = 'image/rgb'
 
         # orientation -1 : scanlines begins at the bottom-left corner
         orientation = -1
@@ -220,7 +222,6 @@ Image.register_decoder("SGI16", SGI16Decoder)
 Image.register_open(SgiImageFile.format, SgiImageFile, _accept)
 Image.register_save(SgiImageFile.format, _save)
 Image.register_mime(SgiImageFile.format, "image/sgi")
-Image.register_mime(SgiImageFile.format, "image/rgb")
 
 Image.register_extensions(SgiImageFile.format,
                           [".bw", ".rgb", ".rgba", ".sgi"])
 

{"src/PIL/SgiImagePlugin.py": "#\n# The Python Imaging Library.\n# $Id$\n#\n# SGI image file handling\n#\n# See \"The SGI Image File Format (Draft version 0.97)\", Paul Haeberli.\n# <ftp://ftp.sgi.com/graphics/SGIIMAGESPEC>\n#\n#\n# History:\n# 2017-22-07 mb   Add RLE decompression\n# 2016-16-10 mb   Add save method without compression\n# 1995-09-10 fl   Created\n#\n# Copyright (c) 2016 by Mickael Bonfill.\n# Copyright (c) 2008 by Karsten Hiddemann.\n# Copyright (c) 1997 by Secret Labs AB.\n# Copyright (c) 1995 by Fredrik Lundh.\n#\n# See the README file for information on usage and redistribution.\n#\n\n\nfrom . import Image, ImageFile\nfrom ._binary import i8, o8, i16be as i16\nfrom ._util import py3\nimport struct\nimport os\n\n\n__version__ = \"0.3\"\n\n\ndef _accept(prefix):\n    return len(prefix) >= 2 and i16(prefix) == 474\n\n\nMODES = {\n    (1, 1, 1): \"L\",\n    (1, 2, 1): \"L\",\n    (2, 1, 1): \"L;16B\",\n    (2, 2, 1): \"L;16B\",\n    (1, 3, 3): \"RGB\",\n    (2, 3, 3): \"RGB;16B\",\n    (1, 3, 4): \"RGBA\",\n    (2, 3, 4): \"RGBA;16B\"\n}\n\n\n##\n# Image plugin for SGI images.\nclass SgiImageFile(ImageFile.ImageFile):\n\n    format = \"SGI\"\n    format_description = \"SGI Image File Format\"\n\n    def _open(self):\n\n        # HEAD\n        headlen = 512\n        s = self.fp.read(headlen)\n\n        # magic number : 474\n        if i16(s) != 474:\n            raise ValueError(\"Not an SGI image file\")\n\n        # compression : verbatim or RLE\n        compression = i8(s[2])\n\n        # bpc : 1 or 2 bytes (8bits or 16bits)\n        bpc = i8(s[3])\n\n        # dimension : 1, 2 or 3 (depending on xsize, ysize and zsize)\n        dimension = i16(s[4:])\n\n        # xsize : width\n        xsize = i16(s[6:])\n\n        # ysize : height\n        ysize = i16(s[8:])\n\n        # zsize : channels count\n        zsize = i16(s[10:])\n\n        # layout\n        layout = bpc, dimension, zsize\n\n        # determine mode from bits/zsize\n        rawmode = \"\"\n        try:\n            rawmode = MODES[layout]\n        except KeyError:\n            pass\n\n        if rawmode == \"\":\n            raise ValueError(\"Unsupported SGI image mode\")\n\n        self._size = xsize, ysize\n        self.mode = rawmode.split(\";\")[0]\n\n        # orientation -1 : scanlines begins at the bottom-left corner\n        orientation = -1\n\n        # decoder info\n        if compression == 0:\n            pagesize = xsize * ysize * bpc\n            if bpc == 2:\n                self.tile = [(\"SGI16\", (0, 0) + self.size,\n                              headlen, (self.mode, 0, orientation))]\n            else:\n                self.tile = []\n                offset = headlen\n                for layer in self.mode:\n                    self.tile.append(\n                        (\"raw\", (0, 0) + self.size,\n                            offset, (layer, 0, orientation)))\n                    offset += pagesize\n        elif compression == 1:\n            self.tile = [(\"sgi_rle\", (0, 0) + self.size,\n                          headlen, (rawmode, orientation, bpc))]\n\n\ndef _save(im, fp, filename):\n    if im.mode != \"RGB\" and im.mode != \"RGBA\" and im.mode != \"L\":\n        raise ValueError(\"Unsupported SGI image mode\")\n\n    # Get the keyword arguments\n    info = im.encoderinfo\n\n    # Byte-per-pixel precision, 1 = 8bits per pixel\n    bpc = info.get(\"bpc\", 1)\n\n    if bpc not in (1, 2):\n        raise ValueError(\"Unsupported number of bytes per pixel\")\n\n    # Flip the image, since the origin of SGI file is the bottom-left corner\n    orientation = -1\n    # Define the file as SGI File Format\n    magicNumber = 474\n    # Run-Length Encoding Compression - Unsupported at this time\n    rle = 0\n\n    # Number of dimensions (x,y,z)\n    dim = 3\n    # X Dimension = width / Y Dimension = height\n    x, y = im.size\n    if im.mode == \"L\" and y == 1:\n        dim = 1\n    elif im.mode == \"L\":\n        dim = 2\n    # Z Dimension: Number of channels\n    z = len(im.mode)\n\n    if dim == 1 or dim == 2:\n        z = 1\n\n    # assert we've got the right number of bands.\n    if len(im.getbands()) != z:\n        raise ValueError(\"incorrect number of bands in SGI write: %s vs %s\" %\n                         (z, len(im.getbands())))\n\n    # Minimum Byte value\n    pinmin = 0\n    # Maximum Byte value (255 = 8bits per pixel)\n    pinmax = 255\n    # Image name (79 characters max, truncated below in write)\n    imgName = os.path.splitext(os.path.basename(filename))[0]\n    if py3:\n        imgName = imgName.encode('ascii', 'ignore')\n    # Standard representation of pixel in the file\n    colormap = 0\n    fp.write(struct.pack('>h', magicNumber))\n    fp.write(o8(rle))\n    fp.write(o8(bpc))\n    fp.write(struct.pack('>H', dim))\n    fp.write(struct.pack('>H', x))\n    fp.write(struct.pack('>H', y))\n    fp.write(struct.pack('>H', z))\n    fp.write(struct.pack('>l', pinmin))\n    fp.write(struct.pack('>l', pinmax))\n    fp.write(struct.pack('4s', b''))  # dummy\n    fp.write(struct.pack('79s', imgName))  # truncates to 79 chars\n    fp.write(struct.pack('s', b''))  # force null byte after imgname\n    fp.write(struct.pack('>l', colormap))\n    fp.write(struct.pack('404s', b''))  # dummy\n\n    rawmode = 'L'\n    if bpc == 2:\n        rawmode = 'L;16B'\n\n    for channel in im.split():\n        fp.write(channel.tobytes('raw', rawmode, 0, orientation))\n\n    fp.close()\n\n\nclass SGI16Decoder(ImageFile.PyDecoder):\n    _pulls_fd = True\n\n    def decode(self, buffer):\n        rawmode, stride, orientation = self.args\n        pagesize = self.state.xsize * self.state.ysize\n        zsize = len(self.mode)\n        self.fd.seek(512)\n\n        for band in range(zsize):\n            channel = Image.new('L', (self.state.xsize, self.state.ysize))\n            channel.frombytes(self.fd.read(2 * pagesize), 'raw',\n                              'L;16B', stride, orientation)\n            self.im.putband(channel.im, band)\n\n        return -1, 0\n\n#\n# registry\n\n\nImage.register_decoder(\"SGI16\", SGI16Decoder)\nImage.register_open(SgiImageFile.format, SgiImageFile, _accept)\nImage.register_save(SgiImageFile.format, _save)\nImage.register_mime(SgiImageFile.format, \"image/sgi\")\nImage.register_mime(SgiImageFile.format, \"image/rgb\")\n\nImage.register_extensions(SgiImageFile.format,\n                          [\".bw\", \".rgb\", \".rgba\", \".sgi\"])\n\n# End of file\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:** SGI Images in Non-RGB Mode Incorrectly Assigned 'image/rgb' MIME Type

**Description:**
When processing SGI images that are not in RGB mode, the MIME type is incorrectly set to `'image/rgb'` instead of `'image/sgi'`. This leads to unexpected behavior in functionalities that depend on the correct MIME type.

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

# Open a black and white SGI image
im = Image.open('Tests/images/hopper.bw')
mimetype = im.get_format_mimetype()
print(mimetype)  # Outputs: 'image/rgb'
```

**Expected Behavior:**
For SGI images that are not in RGB mode, the `get_format_mimetype()` method should return `'image/sgi'`.

**Actual Behavior:**
The `get_format_mimetype()` method returns `'image/rgb'`, causing misinterpretation of the image format.
[/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/SgiImagePlugin.py
#
# The Python Imaging Library.
# $Id$
#
# SGI image file handling
#
# See "The SGI Image File Format (Draft version 0.97)", Paul Haeberli.
# <ftp://ftp.sgi.com/graphics/SGIIMAGESPEC>
#
#
# History:
# 2017-22-07 mb   Add RLE decompression
# 2016-16-10 mb   Add save method without compression
# 1995-09-10 fl   Created
#
# Copyright (c) 2016 by Mickael Bonfill.
# Copyright (c) 2008 by Karsten Hiddemann.
# Copyright (c) 1997 by Secret Labs AB.
# Copyright (c) 1995 by Fredrik Lundh.
#
# See the README file for information on usage and redistribution.
#


from . import Image, ImageFile
from ._binary import i8, o8, i16be as i16
from ._util import py3
import struct
import os


__version__ = "0.3"


def _accept(prefix):
    return len(prefix) >= 2 and i16(prefix) == 474


MODES = {
    (1, 1, 1): "L",
    (1, 2, 1): "L",
    (2, 1, 1): "L;16B",
    (2, 2, 1): "L;16B",
    (1, 3, 3): "RGB",
    (2, 3, 3): "RGB;16B",
    (1, 3, 4): "RGBA",
    (2, 3, 4): "RGBA;16B"
}


##
# Image plugin for SGI images.
class SgiImageFile(ImageFile.ImageFile):

    format = "SGI"
    format_description = "SGI Image File Format"

    def _open(self):

        # HEAD
        headlen = 512
        s = self.fp.read(headlen)

        # magic number : 474
        if i16(s) != 474:
            raise ValueError("Not an SGI image file")

        # compression : verbatim or RLE
        compression = i8(s[2])

        # bpc : 1 or 2 bytes (8bits or 16bits)
        bpc = i8(s[3])

        # dimension : 1, 2 or 3 (depending on xsize, ysize and zsize)
        dimension = i16(s[4:])

        # xsize : width
        xsize = i16(s[6:])

        # ysize : height
        ysize = i16(s[8:])

        # zsize : channels count
        zsize = i16(s[10:])

        # layout
        layout = bpc, dimension, zsize

        # determine mode from bits/zsize
        rawmode = ""
        try:
            rawmode = MODES[layout]
        except KeyError:
            pass

        if rawmode == "":
            raise ValueError("Unsupported SGI image mode")

        self._size = xsize, ysize
        self.mode = rawmode.split(";")[0]

        # orientation -1 : scanlines begins at the bottom-left corner
        orientation = -1

        # decoder info
        if compression == 0:
            pagesize = xsize * ysize * bpc
            if bpc == 2:
                self.tile = [("SGI16", (0, 0) + self.size,
                              headlen, (self.mode, 0, orientation))]
            else:
                self.tile = []
                offset = headlen
                for layer in self.mode:
                    self.tile.append(
                        ("raw", (0, 0) + self.size,
                            offset, (layer, 0, orientation)))
                    offset += pagesize
        elif compression == 1:
            self.tile = [("sgi_rle", (0, 0) + self.size,
                          headlen, (rawmode, orientation, bpc))]


def _save(im, fp, filename):
    if im.mode != "RGB" and im.mode != "RGBA" and im.mode != "L":
        raise ValueError("Unsupported SGI image mode")

    # Get the keyword arguments
    info = im.encoderinfo

    # Byte-per-pixel precision, 1 = 8bits per pixel
    bpc = info.get("bpc", 1)

    if bpc not in (1, 2):
        raise ValueError("Unsupported number of bytes per pixel")

    # Flip the image, since the origin of SGI file is the bottom-left corner
    orientation = -1
    # Define the file as SGI File Format
    magicNumber = 474
    # Run-Length Encoding Compression - Unsupported at this time
    rle = 0

    # Number of dimensions (x,y,z)
    dim = 3
    # X Dimension = width / Y Dimension = height
    x, y = im.size
    if im.mode == "L" and y == 1:
        dim = 1
    elif im.mode == "L":
        dim = 2
    # Z Dimension: Number of channels
    z = len(im.mode)

    if dim == 1 or dim == 2:
        z = 1

    # assert we've got the right number of bands.
    if len(im.getbands()) != z:
        raise ValueError("incorrect number of bands in SGI write: %s vs %s" %
                         (z, len(im.getbands())))

    # Minimum Byte value
    pinmin = 0
    # Maximum Byte value (255 = 8bits per pixel)
    pinmax = 255
    # Image name (79 characters max, truncated below in write)
    imgName = os.path.splitext(os.path.basename(filename))[0]
    if py3:
        imgName = imgName.encode('ascii', 'ignore')
    # Standard representation of pixel in the file
    colormap = 0
    fp.write(struct.pack('>h', magicNumber))
    fp.write(o8(rle))
    fp.write(o8(bpc))
    fp.write(struct.pack('>H', dim))
    fp.write(struct.pack('>H', x))
    fp.write(struct.pack('>H', y))
    fp.write(struct.pack('>H', z))
    fp.write(struct.pack('>l', pinmin))
    fp.write(struct.pack('>l', pinmax))
    fp.write(struct.pack('4s', b''))  # dummy
    fp.write(struct.pack('79s', imgName))  # truncates to 79 chars
    fp.write(struct.pack('s', b''))  # force null byte after imgname
    fp.write(struct.pack('>l', colormap))
    fp.write(struct.pack('404s', b''))  # dummy

    rawmode = 'L'
    if bpc == 2:
        rawmode = 'L;16B'

    for channel in im.split():
        fp.write(channel.tobytes('raw', rawmode, 0, orientation))

    fp.close()


class SGI16Decoder(ImageFile.PyDecoder):
    _pulls_fd = True

    def decode(self, buffer):
        rawmode, stride, orientation = self.args
        pagesize = self.state.xsize * self.state.ysize
        zsize = len(self.mode)
        self.fd.seek(512)

        for band in range(zsize):
            channel = Image.new('L', (self.state.xsize, self.state.ysize))
            channel.frombytes(self.fd.read(2 * pagesize), 'raw',
                              'L;16B', stride, orientation)
            self.im.putband(channel.im, band)

        return -1, 0

#
# registry


Image.register_decoder("SGI16", SGI16Decoder)
Image.register_open(SgiImageFile.format, SgiImageFile, _accept)
Image.register_save(SgiImageFile.format, _save)
Image.register_mime(SgiImageFile.format, "image/sgi")
Image.register_mime(SgiImageFile.format, "image/rgb")

Image.register_extensions(SgiImageFile.format,
                          [".bw", ".rgb", ".rgba", ".sgi"])

# End of file

```
--- 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