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

Image colour spaces are handled inconsistently from graphics state colour spaces #1063

Open
dhdaines opened this issue Nov 21, 2024 · 0 comments

Comments

@dhdaines
Copy link
Contributor

dhdaines commented Nov 21, 2024

Currently pdfminer.six does this for colour spaces in images (inline or XObject) when creating LTImage

        self.colorspace = stream.get_any(("CS", "ColorSpace"))
        if not isinstance(self.colorspace, list):
            self.colorspace = [self.colorspace]

This is not at all the same as the way the non-stroking colour space (which, for some reason, is the only one pdfminer.six seems to care about, and even then only barely) is handled in LTChar, where it is an actual PDFColorSpace object.

Instead, pdfminer.six should apply the same logic as get_colorspace in PDFPageInterpreter.init_resources (which could just be a standalone utility function):

        def get_colorspace(spec: object) -> Optional[PDFColorSpace]:
            if isinstance(spec, list):
                name = literal_name(spec[0])
            else:
                name = literal_name(spec)
            if name == "ICCBased" and isinstance(spec, list) and len(spec) >= 2:
                return PDFColorSpace(name, stream_value(spec[1])["N"])
            elif name == "DeviceN" and isinstance(spec, list) and len(spec) >= 2:
                return PDFColorSpace(name, len(list_value(spec[1])))
            else:
                return PREDEFINED_COLORSPACE.get(name)

Gratuitous self-promotion, this is fixed in PLAYA 😉 dhdaines/playa@96f7628

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

No branches or pull requests

1 participant