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

Make DynamicImage serializable via serde #1381

Open
fintelia opened this issue Nov 28, 2020 · 4 comments
Open

Make DynamicImage serializable via serde #1381

fintelia opened this issue Nov 28, 2020 · 4 comments

Comments

@fintelia
Copy link
Contributor

Requested by @GalAster in this comment:

I really need serde features, I'm using bincode to transfer textures.

My current solution is to convert as bytes with img.write_to(&mut buf, ImageOutputFormat::Png) before transmission.

Then import bytes with image::load_from_memory_with_format(buf, ImageFormat::Png) after the transfer is complete.

In most cases, this is lossless, but I hope there is a better solution, and we can experiment with a feature flag that is turned off by default.

@slackers123
Copy link

Are there any plans to continue this?

@oovm
Copy link

oovm commented Apr 10, 2023

I added a basic support in #1903.

Png is not always available, so I added a type field to safely convert the byte stream to the corresponding type

@oovm
Copy link

oovm commented Apr 10, 2023

I'm not familiar with bytemuck, is there an interface to cast Vec<u8> as Option<Vec16>>?

@fintelia
Copy link
Contributor Author

Nope. Even if the Vec<u8> is properly aligned, the allocator may treat [u8] and [u16] differently so dropping the Vec<u16> may misbehave (because the slice was allocated with type u8 but freed via the u16 codepath).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants