It has a lot of functions to 'draw' a map completely or partially to another map in different ways.
My Bitmap structure is one implementation of this map: Map2d<Rgba>.
Now my wish has arisen to rewrite this struct for owned data (as above) or borrowed data.
To be detailed: I need to avoid copying a fullscreen bitmap buffer. A fullscreen can be a lot of megabytes.
To avoid copying I need a direct reference to borrowed data.
I know I can achieve it with a Trait but it would produce a lot of duplicated implementation code for the owned and borrowed version.
Would it be possible to somehow declare the struct as.
image::ImageBuffer and imgref::Img are both already-existing “2D image wrapper” types that are generic over the kind of storage, with slightly different approaches.
The code in ImageBuffer does something similar I see.
I actually do not want to change my bitmap. it is simple and straightforward.
The only thing I want is avoiding 1 extra copy of my pixels to softbuffer's pixels.
Ideal would be if softbuffer took my pixels as a source, but that is not possible.
Apart from the syntax which I cannot yet read very well, I have to rewrite the whole thing and replace it with something much more abstract and probably have to rewrite every function.
But it is probably the only way.
This looks like a nice solution. Though I have to change all inner functions for accessing stuff as pointers, slices, pixels etc. On top of that I am unable to read the syntax.
How would a function look for fn new(w: i32, h: i32) -> Self {}
and fn new_borrowed_data(w: i32, h: i32, refdata: ??) -> Self {}
Still not convinced...
I have this implementation which is 'perfect' on its own. Containing all logic and access for a simple Vec.
Just to avoid copying data from my Bitmap to softbuffers pixelbuffer, I have to rewrite this Bitmap.
Making it less clear and filled with less clear code.
Philosophically stuck... Or lazy?
Maybe I can 'borrow' some logic from this img or image crate to see how they solve it there.
edit: the problem is insolvable with readable code. I don't like the code of - for example - imagebuffer. or maybe it is because I am not good enough with the language.