internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: python-pillow/Pillow

Issue:
PSDraw.rectangle produces incorrect PostScript
This code should draw a rectangle, but it produces a blank page:

```python
from PIL import PSDraw

with open('output.ps', 'wb') as file:
    ps = PSDraw.PSDraw(file)
    ps.begin_document('TEST')
    ps.rectangle((1 * 72, 4 * 72, 3 * 72, 2 * 72))
    ps.end_document()
```
I inspected the PostScript that it produced and it didn't make a whole lot of sense to me (I've worked with it in the past) until I realised that the parameters on the PostScript stack were in the wrong order.

The PostScript says "72 288 M 216 144 0 Vr" when it should say "72 288 M 0 216 144 Vr", i.e. it's "`left` `top` M `width` `height` 0 Vr" instead of "`left` `top` M 0 `width` `height` Vr".

When I edited the PostScript, I got the expected result.



Discussion:

Resolving patch:
diff --git a/src/PIL/PSDraw.py b/src/PIL/PSDraw.py
--- a/src/PIL/PSDraw.py
+++ b/src/PIL/PSDraw.py
@@ -86,16 +86,10 @@ def rectangle(self, box):
         """
         Draws a rectangle.
 
-        :param box: A 4-tuple of integers whose order and function is currently
-                    undocumented.
-
-                    Hint: the tuple is passed into this format string:
-
-                    .. code-block:: python
-
-                        %d %d M %d %d 0 Vr\n
+        :param box: A tuple of four integers, specifying left, bottom, width and
+           height.
         """
-        self.fp.write(b"%d %d M %d %d 0 Vr\n" % box)
+        self.fp.write(b"%d %d M 0 %d %d Vr\n" % box)
 
     def text(self, xy, text):
         """
@@ -188,10 +182,10 @@ def image(self, box, im, dpi=None):
 /Vl { moveto lineto stroke } bind def
 /Vc { newpath 0 360 arc closepath } bind def
 /Vr {   exch dup 0 rlineto
-        exch dup neg 0 exch rlineto
+        exch dup 0 exch rlineto
         exch neg 0 rlineto
-        0 exch rlineto
-        100 div setgray fill 0 setgray } bind def
+        0 exch neg rlineto
+        setgray fill } bind def
 /Tm matrix def
 /Ve {   Tm currentmatrix pop
         translate scale newpath 0 0 .5 0 360 arc closepath


Test patch:
Repository: python-pillow/Pillow

Issue:
[PNG] IndexError is raised when the sRGB chunk is broken

### What did you do?

```python3

from PIL import Image
import io

# assumes the current directory is the root of this repository.
with open('Tests/images/imagedraw_polygon_1px_high.png', 'rb') as f:
    data = bytearray(f.read())

# insert the sRGB chunk after the IDAT chunk. Its length, chunk type and crc are valid, but the sRGB chunk should contain more data.
data[61:61] = b"\x00\x00\x00\x00sRGB\x10\x1c\xd3\xce"

# IndexError is raised
with Image.open(io.BytesIO(data)) as img:
    img.load()

```

### What did you expect to happen?

IndexError is a little conusing. Maybe ValueError is better.

### What actually happened?

```
Traceback (most recent call last):
  File "issue_index_error_simplified.py", line 14, in <module>
    img.load()
  File "/usr/local/lib/python3.8/dist-packages/PIL/ImageFile.py", line 268, in load
    self.load_end()
  File "/usr/local/lib/python3.8/dist-packages/PIL/PngImagePlugin.py", line 978, in load_end
    self.png.call(cid, pos, length)
  File "/usr/local/lib/python3.8/dist-packages/PIL/PngImagePlugin.py", line 202, in call
    return getattr(self, "chunk_" + cid.decode("ascii"))(pos, length)
  File "/usr/local/lib/python3.8/dist-packages/PIL/PngImagePlugin.py", line 512, in chunk_sRGB
    self.im_info["srgb"] = s[0]
IndexError: index out of range
```

### What are your OS, Python and Pillow versions?

* OS: ubuntu:focal-20220426
* Python: 3.8.10
* Pillow: 9.2.0



Discussion:

Resolving patch:
diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py
--- a/src/PIL/PngImagePlugin.py
+++ b/src/PIL/PngImagePlugin.py
@@ -509,6 +509,10 @@ def chunk_sRGB(self, pos, length):
         # 3 absolute colorimetric
 
         s = ImageFile._safe_read(self.fp, length)
+        if length < 1:
+            if ImageFile.LOAD_TRUNCATED_IMAGES:
+                return s
+            raise ValueError("Truncated sRGB chunk")
         self.im_info["srgb"] = s[0]
         return s
 


Test patch:
diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py
--- a/Tests/test_file_png.py
+++ b/Tests/test_file_png.py
@@ -635,7 +635,9 @@ def test_padded_idat(self):
 
             assert_image_equal_tofile(im, "Tests/images/bw_gradient.png")
 
-    @pytest.mark.parametrize("cid", (b"IHDR", b"pHYs", b"acTL", b"fcTL", b"fdAT"))
+    @pytest.mark.parametrize(
+        "cid", (b"IHDR", b"sRGB", b"pHYs", b"acTL", b"fcTL", b"fdAT")
+    )
     def test_truncated_chunks(self, cid):
         fp = BytesIO()
         with PngImagePlugin.PngStream(fp) as png:
Repository: python-pillow/Pillow

Issue:
Unsupported BMP bitfields layout error
I have a bitmap that can be opened by Ristretto Image Viewer (a Linux program), but it can't be opened by Pillow. I originally encountered this with Pillow version 5.1.0. I upgraded my package to v8.4.0 to see if the issue would resolve, but the same error is raised. In v8.4.0, this error is raised on line 203 of BmpImagePlugin.py.

Upon closer inspection, it seems that the bitmap file I was trying to open has `file_info['header_size'] == 124`, `file_info['compression'] == 3`, `file_info['bits'] == 32`, and `file_info['rgba_mask'] == (0xff000000, 0xff0000, 0xff00, 0xff)`.

Does my bmp file follow the BMP file format? If so, can it be supported in a future version? Thanks.


Discussion:
I can provide more information if needed.

Resolving patch:
diff --git a/src/PIL/BmpImagePlugin.py b/src/PIL/BmpImagePlugin.py
--- a/src/PIL/BmpImagePlugin.py
+++ b/src/PIL/BmpImagePlugin.py
@@ -172,10 +172,11 @@ def _bitmap(self, header=0, offset=0):
             SUPPORTED = {
                 32: [
                     (0xFF0000, 0xFF00, 0xFF, 0x0),
-                    (0xFF0000, 0xFF00, 0xFF, 0xFF000000),
+                    (0xFF000000, 0xFF0000, 0xFF00, 0x0),
+                    (0xFF000000, 0xFF0000, 0xFF00, 0xFF),
                     (0xFF, 0xFF00, 0xFF0000, 0xFF000000),
+                    (0xFF0000, 0xFF00, 0xFF, 0xFF000000),
                     (0x0, 0x0, 0x0, 0x0),
-                    (0xFF000000, 0xFF0000, 0xFF00, 0x0),
                 ],
                 24: [(0xFF0000, 0xFF00, 0xFF)],
                 16: [(0xF800, 0x7E0, 0x1F), (0x7C00, 0x3E0, 0x1F)],
@@ -183,6 +184,7 @@ def _bitmap(self, header=0, offset=0):
             MASK_MODES = {
                 (32, (0xFF0000, 0xFF00, 0xFF, 0x0)): "BGRX",
                 (32, (0xFF000000, 0xFF0000, 0xFF00, 0x0)): "XBGR",
+                (32, (0xFF000000, 0xFF0000, 0xFF00, 0xFF)): "ABGR",
                 (32, (0xFF, 0xFF00, 0xFF0000, 0xFF000000)): "RGBA",
                 (32, (0xFF0000, 0xFF00, 0xFF, 0xFF000000)): "BGRA",
                 (32, (0x0, 0x0, 0x0, 0x0)): "BGRA",


Test patch:
diff --git a/Tests/images/rgb32bf-abgr.bmp b/Tests/images/rgb32bf-abgr.bmp
new file mode 100644
Binary files /dev/null and b/Tests/images/rgb32bf-abgr.bmp differ
diff --git a/Tests/test_file_bmp.py b/Tests/test_file_bmp.py
--- a/Tests/test_file_bmp.py
+++ b/Tests/test_file_bmp.py
@@ -129,6 +129,13 @@ def test_rgba_bitfields():
 
     assert_image_equal_tofile(im, "Tests/images/bmp/q/rgb32bf-xbgr.bmp")
 
+    # This test image has been manually hexedited
+    # to change the bitfield compression in the header from XBGR to ABGR
+    with Image.open("Tests/images/rgb32bf-abgr.bmp") as im:
+        assert_image_equal_tofile(
+            im.convert("RGB"), "Tests/images/bmp/q/rgb32bf-xbgr.bmp"
+        )
+
 
 def test_rle8():
     with Image.open("Tests/images/hopper_rle8.bmp") as im:
Repository: python-pillow/Pillow

Issue:
PSD incorrectly loaded
### What did you do?
I opened the TIFF in Pillow and converted it to JPG.
### What did you expect to happen?
The JPG image to look the same as the original TIFF.
### What actually happened?
The converted JPG looks malformed and has messed up colors.
### What are your OS, Python and Pillow versions?

* OS: Linux
* Python: 3.10.5
* Pillow: 9.1.1 (also tested -git)

```python
>>> img = Image.open("3662b8bd397337482862ab1a06bf3366-OA_535_161_17_F_TE.tif")
>>> out_img = img.convert("RGB")
>>> out_img.save("converted.jpg", quality=95)
```
[original image](https://api.collectie.gent/storage/v1/download/3662b8bd397337482862ab1a06bf3366-OA_535_161_17_F_TE.tif) (beware, 274MB)
[converted image](https://api.collectie.gent/storage/v1/download/3a029a4f48b480211286486a6a1f0f0b-transcode-OA_535_161_17_F_TE.jpg)

Is it okay to report this here or should I report this to the appropriate library (libtiff, jpeg-turbo, ?)


Discussion:
Here is the right place to report it - taking a look, your file is actually not a TIFF, but a Photoshop file. The fact that we're not loading it correctly has nothing to do with those other libraries.
@radarhere My bad, I should have checked the mimetype...

Resolving patch:
diff --git a/src/PIL/PsdImagePlugin.py b/src/PIL/PsdImagePlugin.py
--- a/src/PIL/PsdImagePlugin.py
+++ b/src/PIL/PsdImagePlugin.py
@@ -75,6 +75,9 @@ def _open(self):
 
         if channels > psd_channels:
             raise OSError("not enough channels")
+        if mode == "RGB" and psd_channels == 4:
+            mode = "RGBA"
+            channels = 4
 
         self.mode = mode
         self._size = i32(s, 18), i32(s, 14)


Test patch:
diff --git a/Tests/images/rgba.psd b/Tests/images/rgba.psd
new file mode 100644
Binary files /dev/null and b/Tests/images/rgba.psd differ
diff --git a/Tests/test_file_psd.py b/Tests/test_file_psd.py
--- a/Tests/test_file_psd.py
+++ b/Tests/test_file_psd.py
@@ -4,7 +4,7 @@
 
 from PIL import Image, PsdImagePlugin
 
-from .helper import assert_image_similar, hopper, is_pypy
+from .helper import assert_image_equal_tofile, assert_image_similar, hopper, is_pypy
 
 test_file = "Tests/images/hopper.psd"
 
@@ -107,6 +107,11 @@ def test_open_after_exclusive_load():
         im.load()
 
 
+def test_rgba():
+    with Image.open("Tests/images/rgba.psd") as im:
+        assert_image_equal_tofile(im, "Tests/images/imagedraw_square.png")
+
+
 def test_icc_profile():
     with Image.open(test_file) as im:
         assert "icc_profile" in im.info
Repository: python-pillow/Pillow

Issue:
getexif().tobytes() throws 'bytes' object has no attribute 'encode'
This also indirectly breaks PIL.ImageOps.exif_transpose().

### What did you do?

```python
PIL.Image.open("x.jpg").getexif().tobytes()
```

The image is attached:

[x.jpg](https://user-images.githubusercontent.com/2303841/184104418-0eb54b27-50f1-4f3e-88f6-07329313faf2.jpg)

### What actually happened?

throws:

```
File .../.venv/lib/python3.10/site-packages/PIL/Image.py:3589, in Exif.tobytes(self, offset)
   3587             value[0xA005] = self.get_ifd(0xA005)
   3588     ifd[tag] = value
-> 3589 return b"Exif\x00\x00" + head + ifd.tobytes(offset)

File .../.venv/lib/python3.10/site-packages/PIL/TiffImagePlugin.py:876, in ImageFileDirectory_v2.tobytes(self, offset)
    874 else:
    875     values = value if isinstance(value, tuple) else (value,)
--> 876     data = self._write_dispatch[typ](self, *values)
    878 tagname = TiffTags.lookup(tag, self.group).name
    879 typname = "ifd" if is_ifd else TYPES.get(typ, "unknown")

File .../.venv/lib/python3.10/site-packages/PIL/TiffImagePlugin.py:730, in ImageFileDirectory_v2.write_string(self, value)
    727 @_register_writer(2)
    728 def write_string(self, value):
    729     # remerge of https://github.com/python-pillow/Pillow/pull/1416
--> 730     return b"" + value.encode("ascii", "replace") + b"\0"

AttributeError: 'bytes' object has no attribute 'encode'
```
### What are your OS, Python and Pillow versions?

* OS: Arch Linux
* Python: 3.10.5
* Pillow: 9.2.0



Discussion:

Resolving patch:
diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py
--- a/src/PIL/TiffImagePlugin.py
+++ b/src/PIL/TiffImagePlugin.py
@@ -727,7 +727,9 @@ def load_string(self, data, legacy_api=True):
     @_register_writer(2)
     def write_string(self, value):
         # remerge of https://github.com/python-pillow/Pillow/pull/1416
-        return b"" + value.encode("ascii", "replace") + b"\0"
+        if not isinstance(value, bytes):
+            value = value.encode("ascii", "replace")
+        return value + b"\0"
 
     @_register_loader(5, 8)
     def load_rational(self, data, legacy_api=True):


Test patch:
diff --git a/Tests/test_file_tiff_metadata.py b/Tests/test_file_tiff_metadata.py
--- a/Tests/test_file_tiff_metadata.py
+++ b/Tests/test_file_tiff_metadata.py
@@ -185,6 +185,22 @@ def test_iptc(tmp_path):
         im.save(out)
 
 
+def test_writing_bytes_to_ascii(tmp_path):
+    im = hopper()
+    info = TiffImagePlugin.ImageFileDirectory_v2()
+
+    tag = TiffTags.TAGS_V2[271]
+    assert tag.type == TiffTags.ASCII
+
+    info[271] = b"test"
+
+    out = str(tmp_path / "temp.tiff")
+    im.save(out, tiffinfo=info)
+
+    with Image.open(out) as reloaded:
+        assert reloaded.tag_v2[271] == "test"
+
+
 def test_undefined_zero(tmp_path):
     # Check that the tag has not been changed since this test was created
     tag = TiffTags.TAGS_V2[45059]
Repository: python-pillow/Pillow

Issue:
EXIF prefix saved in WebP
### What did you do?

I saved 2 copies of a webp file, one with exif=exif_bytes as shown, one without, then added the exif data by piexif.insert

### What did you expect to happen?

exif data to be the same

### What actually happened?

winmerge binary comparison reveals "Exif" is quoted one extra time in the Pillow image.save version indicating a coding error

### What are your OS, Python and Pillow versions?

* OS: Windows 10
* Python: 3.8
* Pillow: 9.2.0

<!--
Please include **code** that reproduces the issue and whenever possible, an **image** that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.

The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as Plone, Django, or Buildout, try to replicate the issue just using Pillow.
-->

```python


from PIL import Image
import piexif
import piexif.helper

info = "test data in User Comment"
fullfn = "sample_image.webp"

exif_bytes = piexif.dump({
		"Exif": {
			piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(info, encoding="unicode")
		},
	})

with Image.open(fullfn) as image:
	image.save(fullfn, quality=60, exif=exif_bytes)

	image.save("sample_image_inserted_exif.webp", "webp", quality=60)

piexif.insert(exif_bytes, "sample_image_inserted_exif.webp")

```



Discussion:

Resolving patch:
diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py
--- a/src/PIL/WebPImagePlugin.py
+++ b/src/PIL/WebPImagePlugin.py
@@ -311,9 +311,11 @@ def _save(im, fp, filename):
     lossless = im.encoderinfo.get("lossless", False)
     quality = im.encoderinfo.get("quality", 80)
     icc_profile = im.encoderinfo.get("icc_profile") or ""
-    exif = im.encoderinfo.get("exif", "")
+    exif = im.encoderinfo.get("exif", b"")
     if isinstance(exif, Image.Exif):
         exif = exif.tobytes()
+    if exif.startswith(b"Exif\x00\x00"):
+        exif = exif[6:]
     xmp = im.encoderinfo.get("xmp", "")
     method = im.encoderinfo.get("method", 4)
 


Test patch:
diff --git a/Tests/test_file_webp_metadata.py b/Tests/test_file_webp_metadata.py
--- a/Tests/test_file_webp_metadata.py
+++ b/Tests/test_file_webp_metadata.py
@@ -55,9 +55,7 @@ def test_write_exif_metadata():
     test_buffer.seek(0)
     with Image.open(test_buffer) as webp_image:
         webp_exif = webp_image.info.get("exif", None)
-    assert webp_exif
-    if webp_exif:
-        assert webp_exif == expected_exif, "WebP EXIF didn't match"
+    assert webp_exif == expected_exif[6:], "WebP EXIF didn't match"
 
 
 def test_read_icc_profile():
Repository: python-pillow/Pillow

Issue:
FliImagePlugin cannot get colours
The fli/flc plugin is unable to get the colours from a civ iii flc animation. The result of opening any civ iii animation is a black and white image. I apologize in advance for any issues in my reporting style.
Code is approximate, as I am working from memory on my smartphone.
```python
from PIL import Image
img = Image.load("attack.flc")
img.save("attack.gif", Save_all=True)
```


Discussion:
Could you upload a copy of attack.flc?
[imgs.zip](https://github.com/python-pillow/Pillow/files/9669463/imgs.zip)
Here are a few.

Resolving patch:
diff --git a/src/PIL/FliImagePlugin.py b/src/PIL/FliImagePlugin.py
--- a/src/PIL/FliImagePlugin.py
+++ b/src/PIL/FliImagePlugin.py
@@ -15,6 +15,7 @@
 # See the README file for information on usage and redistribution.
 #
 
+import os
 
 from . import Image, ImageFile, ImagePalette
 from ._binary import i16le as i16
@@ -80,11 +81,19 @@ def _open(self):
 
         if i16(s, 4) == 0xF1FA:
             # look for palette chunk
-            s = self.fp.read(6)
-            if i16(s, 4) == 11:
-                self._palette(palette, 2)
-            elif i16(s, 4) == 4:
-                self._palette(palette, 0)
+            number_of_subchunks = i16(s, 6)
+            chunk_size = None
+            for _ in range(number_of_subchunks):
+                if chunk_size is not None:
+                    self.fp.seek(chunk_size - 6, os.SEEK_CUR)
+                s = self.fp.read(6)
+                chunk_type = i16(s, 4)
+                if chunk_type in (4, 11):
+                    self._palette(palette, 2 if chunk_type == 11 else 0)
+                    break
+                chunk_size = i32(s)
+                if not chunk_size:
+                    break
 
         palette = [o8(r) + o8(g) + o8(b) for (r, g, b) in palette]
         self.palette = ImagePalette.raw("RGB", b"".join(palette))


Test patch:
diff --git a/Tests/images/hopper_palette_chunk_second.fli b/Tests/images/hopper_palette_chunk_second.fli
new file mode 100644
Binary files /dev/null and b/Tests/images/hopper_palette_chunk_second.fli differ
diff --git a/Tests/test_file_fli.py b/Tests/test_file_fli.py
--- a/Tests/test_file_fli.py
+++ b/Tests/test_file_fli.py
@@ -4,7 +4,7 @@
 
 from PIL import FliImagePlugin, Image
 
-from .helper import assert_image_equal_tofile, is_pypy
+from .helper import assert_image_equal, assert_image_equal_tofile, is_pypy
 
 # created as an export of a palette image from Gimp2.6
 # save as...-> hopper.fli, default options.
@@ -79,6 +79,12 @@ def test_invalid_file():
         FliImagePlugin.FliImageFile(invalid_file)
 
 
+def test_palette_chunk_second():
+    with Image.open("Tests/images/hopper_palette_chunk_second.fli") as im:
+        with Image.open(static_test_file) as expected:
+            assert_image_equal(im.convert("RGB"), expected.convert("RGB"))
+
+
 def test_n_frames():
     with Image.open(static_test_file) as im:
         assert im.n_frames == 1
Repository: python-pillow/Pillow

Issue:
convert("LAB") fails for RGB
### What did you do?

Called PIL.Image.Image.convert(mode='LAB') for an RGB image
```python
img = PIL.Image.open('filename.png').convert(mode='LAB')
```
### What did you expect to happen?

Conversion of data to LAB colourspace.

### What actually happened?

ValueError: conversion from RGB to LAB not supported

The following code did work:
```python
rgb_lab_transform = PIL.ImageCms.buildTransformFromOpenProfiles(PIL.ImageCms.createProfile('sRGB'), PIL.ImageCms.createProfile('LAB'), 'RGB', 'LAB')
img = PIL.ImageCms.applyTransform(Image.open('filename.png').convert(mode='RGB'), rgb_lab_transform)
```

### What are your OS, Python and Pillow versions?

* OS: Linux, kernel 5.15.32-gentoo-r1
* Python: 3.10.6
* Pillow: 9.2.0




Discussion:

Resolving patch:
diff --git a/src/PIL/Image.py b/src/PIL/Image.py
--- a/src/PIL/Image.py
+++ b/src/PIL/Image.py
@@ -1027,6 +1027,19 @@ def convert_transparency(m, v):
                     warnings.warn("Couldn't allocate palette entry for transparency")
             return new
 
+        if "LAB" in (self.mode, mode):
+            other_mode = mode if self.mode == "LAB" else self.mode
+            if other_mode in ("RGB", "RGBA", "RGBX"):
+                from . import ImageCms
+
+                srgb = ImageCms.createProfile("sRGB")
+                lab = ImageCms.createProfile("LAB")
+                profiles = [lab, srgb] if self.mode == "LAB" else [srgb, lab]
+                transform = ImageCms.buildTransform(
+                    profiles[0], profiles[1], self.mode, mode
+                )
+                return transform.apply(self)
+
         # colorspace conversion
         if dither is None:
             dither = Dither.FLOYDSTEINBERG


Test patch:
diff --git a/Tests/test_image_convert.py b/Tests/test_image_convert.py
--- a/Tests/test_image_convert.py
+++ b/Tests/test_image_convert.py
@@ -242,6 +242,17 @@ def test_p2pa_palette():
     assert im_pa.getpalette() == im.getpalette()
 
 
+@pytest.mark.parametrize("mode", ("RGB", "RGBA", "RGBX"))
+def test_rgb_lab(mode):
+    im = Image.new(mode, (1, 1))
+    converted_im = im.convert("LAB")
+    assert converted_im.getpixel((0, 0)) == (0, 128, 128)
+
+    im = Image.new("LAB", (1, 1), (255, 0, 0))
+    converted_im = im.convert(mode)
+    assert converted_im.getpixel((0, 0))[:3] == (0, 255, 255)
+
+
 def test_matrix_illegal_conversion():
     # Arrange
     im = hopper("CMYK")
Repository: python-pillow/Pillow

Issue:
Document alpha values of PA image with RGBA palette
I think the PA alpha is used regardless of any alpha values in the palette, but I'm not certain that's handled consistently, and I don't think it's documented anywhere.


Discussion:
> I'm not certain that's handled consistently

Are there any specific operations that you're concerned about? If not, ok.
Nothing specific. I don't think it's checked in very many places anyways.

Resolving patch:
diff --git a/src/PIL/Image.py b/src/PIL/Image.py
--- a/src/PIL/Image.py
+++ b/src/PIL/Image.py
@@ -880,7 +880,7 @@ def convert(
         and the palette can be represented without a palette.
 
         The current version supports all possible conversions between
-        "L", "RGB" and "CMYK." The ``matrix`` argument only supports "L"
+        "L", "RGB" and "CMYK". The ``matrix`` argument only supports "L"
         and "RGB".
 
         When translating a color image to greyscale (mode "L"),
@@ -899,6 +899,9 @@ def convert(
         this passes the operation to :py:meth:`~PIL.Image.Image.quantize`,
         and ``dither`` and ``palette`` are ignored.
 
+        When converting from "PA", if an "RGBA" palette is present, the alpha
+        channel from the image will be used instead of the values from the palette.
+
         :param mode: The requested mode. See: :ref:`concept-modes`.
         :param matrix: An optional conversion matrix.  If given, this
            should be 4- or 12-tuple containing floating point values.


Test patch: