Skip to content

Interoperability issue with pycairo for ImageSurface.create_for_data and numpy data #223

@FriedrichFroebel

Description

@FriedrichFroebel

I am currently trying to understand why my code works with pycairo, but fails for cairocffi.

Let's take the script at https://github.com/FriedrichFroebel/python-djvulibre/blob/b6c68a3496a244403488034b30c8de4b935b02b5/examples/djvu2png and call it with djvu2png --foreground ../tests/images/test1.djvu out.png. With a regular pycairo installation, everything works fine. But as soon as I replace import cairo with import cairocffi as cairo, I get an error:

ValueError: Got a 3072 bytes buffer, needs at least 12288.

Simply removing the offending lines from the cairocffi source code at

if length < stride * height:
raise ValueError('Got a %d bytes buffer, needs at least %d.'
% (length, stride * height))
appears to generate the correct output without any error message. For this reason, it seems like the condition is superfluous or wrong.

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