Skip to content

PA mode handling is wonky #1600

Description

@wiredfool

Or. half baked.

We 'support' a mode called PA which is palette with alpha, stored in 4 bytes per pixel. (FWIW, I think this all applies to LA as well)

Image.putpalette (https://github.com/python-pillow/Pillow/blob/master/PIL/Image.py#L1447) only allows for L or P images when adding a palette:

        if self.mode not in ("L", "P"):
            raise ValueError("illegal image mode")

_imaging.c:_putpalette Also only accepts* L and P. This code was in PIL:

    if (strcmp(self->image->mode, "L") != 0 && strcmp(self->image->mode, "P")) {
        PyErr_SetString(PyExc_ValueError, wrong_mode);
        return NULL;

* or rather, it looks like it should but only actually accepts if mode ==Pand mode !='L'

TiffImagePlugin:_setup (https://github.com/python-pillow/Pillow/blob/master/PIL/TiffImagePlugin.py#L1137) only includes the palette for P images.

        if self.mode == "P":
            palette = [o8(b // 256) for b in self.tag_v2[COLORMAP]]
            self.palette = ImagePalette.raw("RGB;L", b"".join(palette))

All of this found while checking out #1597.

Activity

  1. added
    BugAny unexpected behavior, until confirmed feature.
    on Dec 17, 2015
  2. changed the title [-]PA mode handling is wonky.[/-] [+]PA mode handling is wonky[/+] on May 31, 2018
  3. radarhere commented on Mar 19, 2019

    @radarhere
    Member

    I've created PR #3728 to help this.

    While I don't understand this comment, it does pass tests.

    _imaging.c:_putpalette Also only accepts* L and P. This code was in PIL:

    if (strcmp(self->image->mode, "L") != 0 && strcmp(self->image->mode, "P")) {
        PyErr_SetString(PyExc_ValueError, wrong_mode);
        return NULL;
    
    • or rather, it looks like it should but only actually accepts if mode ==Pand mode !='L'
  4. radarhere commented on May 18, 2019

    @radarhere
    Member

    I've created PR #3848 to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugAny unexpected behavior, until confirmed feature.Palette

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions