Closed LucaCiucci closed 1 year ago
Yes I think this is a reasonable method to add.
On the topic of naming it, is flat a common way to describe such a method? It's definitely shorter than an explicit make_image_with_stride
.
I'm not sure if that's the best name to give this function. This was the first name that came to my mind because I was reading the FlatSamples
doc.
I don't know many other libraries, afaik Qt does not provide a similar function for images and pixmaps, Skia has MakeRasterData
that is undocumented but an example usage is shown here.
One idea might be to implement make_image_with_stride
and make the function to accept a stride
parameter so that the name make_image_flat
can be used in the future for more complex layouts. What do you think?
Yeah that sounds like a decent plan. Let's go with make_image_with_stride
for now. It's possible to deprecate it later if someone comes up with a better name.
I will try to implement this in a fork if you are ok with that
Yes that sounds good. Then open a pull request here and I can review.
I am trying to create a druid widget that renders a 3d scene using WGPU. To do this, I render the scene into a texture, get the data as a
&[u8]
and paint it using piet'sdraw_image
.Unfortunately, each row in the texture has a stride with an alignment of
COPY_BYTES_PER_ROW_ALIGNMENT
bytes so, in order to use it withmake_image
, I have to convert it first. This is quite annoying and feels unnecessary.I think this situation could be common in other situations such as showing images/videos from raw data. Maybe it could be useful to create another function, for example
RenderContext::make_image_flat
that accepts a row pitch, just likeimage::FlatSamples
that stores the layout information inSampleLayout