-
Notifications
You must be signed in to change notification settings - Fork 5
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
Trait for bitmaps with arbitrary impl #2
Comments
I was hoping to iterate on GdkPixbufs easily with imgref, but they do not guarantee that the stride is a multiple of the pixel size (by default rows are aligned to 32 bits even for packed RGB pixels; stride there can in fact be arbitrary). I can hack around this by making my own iterator and the rgb crate, to cast What kind of trait were you envisioning? I may be able to work on this. |
Currently I see two ways around it:
Maybe you could experiment with your own implementation. Lessons I've learned with this one:
In this issue I floated idea of making it a trait, like: trait ImgLike {
fn width(&self) -> usize;
fn rows(&self) -> Self::RowsIter;
type RowsIter;
} because I was annoyed that But in practice having a concrete |
OK, maybe I was thinking about this incorrectly. My first thought was, "OK, I have a buffer allocated by GdkPixbuf with whatever weird stride; imgref can help me turn it into something slice-like so I can operate on it safely". A few weird things about GdkPixbuf:
I've solved the thing I wanted to solve in librsvg by just using the rgb crate and (I guess this question is, do you intend imgref to be a "wrap me an I do want to move librsvg away from depending on GdkPixbuf for image loading, and cairo ImageSurface for image operations, so imgref may come in handy with its owned images. We'll see. |
The third point is inherent to the problem, and imgref already has to deal with it. If you take a large bitmap where stride=width, and then make a sub image that is a view of its bottom right corner, you will have an image with stride>width, but the last row won't have any space for the full stride. Fortunately RGB/RGBA is byte-aligned, so its fine to cast any buffer to it. It's only byte-based stride that makes it tricky to express the whole image as a slice. This crate is supposed to be a Rusty type-safe |
Currently the struct is tied to a particular layout/implementation and doesn't support:
So perhaps this should be a trait first and foremost.
The text was updated successfully, but these errors were encountered: