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

How to use with numpy #286

Open
page200 opened this issue Nov 6, 2022 · 3 comments
Open

How to use with numpy #286

page200 opened this issue Nov 6, 2022 · 3 comments

Comments

@page200
Copy link

page200 commented Nov 6, 2022

Here in tests/test_surface_numpy.py, shape should be (h, w) rather than (w, h). It currenlty works correctly only because w and h are equal.

An older version of this code used to be shape=(h, w, 4), dtype=np.uint8, that seemed clearer for cairo.FORMAT_RGBA32 and cairo.FORMAT_RGB24 images than shape=(h, w), dtype=numpy.uint32

The filename of that script is mentioned somewhere in the documentation as far as I recall, but not linked.

Overall, it would be nice to provide examples how to "unpack" the bits (for example in the case of cairo.FORMAT_RGB30), so that individual users don't have to code that (with np.right_shift etc.) every time like here:
https://community.mypaint.org/t/color-management-and-linear-light/944/17

Usage with numpy seems quite important, but quite hidden.

@lazka
Copy link
Member

lazka commented Nov 11, 2022

We have some docs here: https://pycairo.readthedocs.io/en/latest/integration.html

I'm fine with creating a separate sub-page there for specific libraries and providing more examples there.

lazka added a commit that referenced this issue Nov 29, 2022
@lazka
Copy link
Member

lazka commented Nov 29, 2022

Here in tests/test_surface_numpy.py, shape should be (h, w) rather than (w, h). It currenlty works correctly only because w and h are equal.

fixed in 809a93c

An older version of this code used to be shape=(h, w, 4), dtype=np.uint8, that seemed clearer for cairo.FORMAT_RGBA32 and cairo.FORMAT_RGB24 images than shape=(h, w), dtype=numpy.uint32

Would that work with cairo using native-endian there?

@lazka
Copy link
Member

lazka commented Nov 29, 2022

I'm fine with creating a separate sub-page there for specific libraries and providing more examples there.

I started this now in 8e2ef6f

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

2 participants