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 do I create a PixelFormat to pass to Surface.from() ? #63

Open
avrame opened this issue Dec 20, 2024 · 4 comments
Open

How do I create a PixelFormat to pass to Surface.from() ? #63

avrame opened this issue Dec 20, 2024 · 4 comments

Comments

@avrame
Copy link

avrame commented Dec 20, 2024

I'm trying to render an image that I created with Blend2d.cr. I passed in the bytes of the image in the first argument, the width, and height next. But I don't know how to create a PixelFormat instance to pass in as the fourth argument.

@ysbaddaden
Copy link
Owner

You can use SDL::Image.load to load an image as a SDL::Surface or directly render it to a SDL::Renderer.

The alternative would be to decode the image into a flat byte buffer and respect one of the pixel format or create a specific one so SDL can know where each pixel is in the buffer and how to interpret the bytes as pixel colors (too much hassle).

@avrame
Copy link
Author

avrame commented Dec 20, 2024

Thanks for the quick response @ysbaddaden I'm trying to work with the raw pixel data from the Blend2D rendering as creating an image and then loading it is too slow. I want it fast enough to run at 60+ fps. Is there a different way to do this with SDL or should I try a library more suited to this?

@ysbaddaden
Copy link
Owner

Oh, then you need to know the byte format for a Blend2D::Image buffer (preferably) or a mean to translate to a known format (RGBA32).

Most of the pixels related C functions don't have a binding, but you may write some. I noticed LibC::SDL_PixelFormatEnum has a RGBA32 member (for example) then I found
https://stackoverflow.com/a/32000743 that reports that we can use LibC::SDL_AllocFormat to get a LibC::SDL_PixelFormat* for a given enum!

Toying with this, you should eventually be able to render from blend2d to sdl.

@avrame
Copy link
Author

avrame commented Dec 22, 2024

That worked great - thanks! I forked this library and made a few updates to get it working. I can make a PR later - maybe after the holidays.

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