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

faster cairo paint: avoid copying pixels whenever possible #4270

Closed
totaam opened this issue Jun 30, 2024 · 2 comments
Closed

faster cairo paint: avoid copying pixels whenever possible #4270

totaam opened this issue Jun 30, 2024 · 2 comments
Labels
client encoding enhancement New feature or request

Comments

@totaam
Copy link
Collaborator

totaam commented Jun 30, 2024

We can use ImageSurface.create_for_data if the pixel data stride satisfies stride_for_width
Another undocumented constraint is that the memory must not be read-only..

@totaam totaam added enhancement New feature or request client encoding labels Jun 30, 2024
totaam added a commit that referenced this issue Jun 30, 2024
totaam added a commit that referenced this issue Jul 1, 2024
since create_for_data won't do any byte-swapping
totaam added a commit that referenced this issue Jul 1, 2024
also support more pixel formats and pad output with zeroes when the rowstride is larger than the input
@totaam
Copy link
Collaborator Author

totaam commented Jul 1, 2024

With the latest test, we report the performance of each call to make_image_surface.
Unsuprisingly, the zero-copy options are way faster:

RGBA to cairo.ARGB32 :   162 MPixels/s
RGBX to cairo.ARGB32 :   156 MPixels/s
BGRA to cairo.ARGB32 :  4543 MPixels/s
BGRX to cairo.ARGB32 :   179 MPixels/s
RGB  to cairo.ARGB32 :   170 MPixels/s
BGR  to cairo.ARGB32 :   152 MPixels/s
RGBA to cairo.RGB24  :   192 MPixels/s
RGBX to cairo.RGB24  :   193 MPixels/s
BGRA to cairo.RGB24  :  4529 MPixels/s
BGRX to cairo.RGB24  :  4535 MPixels/s
RGB  to cairo.RGB24  :   192 MPixels/s
BGR  to cairo.RGB24  :   171 MPixels/s

So we should really make sure that the cairo backend tells the decoder modules to provide BGRA or BGRX, not RGB or BGR even if they take up less space..
(the OpenGL backend doesn't care - the pixel upload functions support every format)

totaam added a commit that referenced this issue Jul 1, 2024
totaam added a commit that referenced this issue Jul 1, 2024
and simplify output rgb format selection
@totaam
Copy link
Collaborator Author

totaam commented Jul 1, 2024

Changing the decoders to prefer BGRX / BGRA:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client encoding enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant