Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TIFF Predictor 2 #1057

Open
helpmefindaname opened this issue Oct 29, 2024 · 1 comment · May be fixed by #1058
Open

Implement TIFF Predictor 2 #1057

helpmefindaname opened this issue Oct 29, 2024 · 1 comment · May be fixed by #1058

Comments

@helpmefindaname
Copy link

Currently, the TIFF Predictor 2 is not implemented, so you cannot read the image stream out of the PDF attached below.

The tiff predictor 2 is specified in the TIFF Revision 6.0 (Section 14, page 64) and referenced as part of the PDF reference 1.7 (Section 3.3, page 75)

In my pdf-corpus I have so far only encountered the TIFF Predictor with exactly 8 bitspercomponent. For that the following code represents a valid implementation:

def apply_tiff_predictor(colors: int, columns: int, bitspercomponent: int, data: bytes) -> bytes:
    if bitspercomponent != 8:
        error_msg = f"Unsupported `bitspercomponent': {bitspercomponent}"
        raise ValueError(error_msg)
    bpp = colors * (bitspercomponent // 8)
    nbytes = columns * bpp
    buf: list[int] = []
    for scanline_i in range(0, len(data), nbytes + 1):
        raw: list[int] = []
        for i in range(nbytes):
            new_value = data[scanline_i + i]
            if i >= bpp:
                new_value += raw[i - bpp]
                new_value %= 256
            raw.append(new_value)
        buf.extend(raw)

    return bytes(buf)

test_pdf_with_tiff_predictor.pdf

@helpmefindaname helpmefindaname linked a pull request Oct 29, 2024 that will close this issue
5 tasks
@dhdaines
Copy link
Contributor

Fixed in PLAYA-PDF: dhdaines/playa#18 (but it may be less useful to you as it doesn't save images at the moment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@dhdaines @helpmefindaname and others