Skip to content

Add the unpackI16B_I16 unpacker to unpackers #7124

@FirefoxMetzger

Description

@FirefoxMetzger

I would like to propose to add a new unpacker to Unpack.c that can unpack big-endian 16-bit integer pixels (I;16B) into 16-bit integer pixels (I;16, I assume native or does it mean little-endian?).

At the moment, the following conversions are supported:

Pillow/src/libImaging/Unpack.c

Lines 1761 to 1773 in 139acc4

/* storage modes */
{"I;16", "I;16", 16, copy2},
{"I;16B", "I;16B", 16, copy2},
{"I;16L", "I;16L", 16, copy2},
{"I;16N", "I;16N", 16, copy2},
{"I;16", "I;16N", 16, unpackI16N_I16}, // LibTiff native->image endian.
{"I;16L", "I;16N", 16, unpackI16N_I16}, // LibTiff native->image endian.
{"I;16B", "I;16N", 16, unpackI16N_I16B},
{"I;16", "I;16R", 16, unpackI16R_I16},
{"I;16", "I;12", 12, unpackI12_I16}, // 12 bit Tiffs stored in 16bits.

and it would be really useful for me to also have I;16B->I;16 as well.

My use case is 16-bit PNGs, which I could then directly unpack into a 16-bit buffer. Currently, we can only unpack them into a 32-bit (I) buffer or a 16-bit big-endian buffer (I;16B), so I have to copy the data one more time from that buffer into I;16. With this small addition I could avoid/save this copy :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions