Conversation
| match self.header.bpp { | ||
| Bpp::Bits1 => RawDataSlice::<RawU1, LittleEndian>::new(row) | ||
| .into_iter() | ||
| .nth(p.x as usize) |
There was a problem hiding this comment.
Using nth() seems to be rather expensive for random pixel lookup.
In Bmp format it should be possible to lookup pixels in the raw data block in O(1) time.
There was a problem hiding this comment.
There is a specialized implementation of nth which is O(1).
There was a problem hiding this comment.
RawDataSlice and the iterators are included in embedded-graphics: https://github.com/embedded-graphics/embedded-graphics/blob/master/src/iterator/raw.rs
There was a problem hiding this comment.
Cool. Does that also count for the nth in line 100?
There was a problem hiding this comment.
Yes, Chunks does also implements nth: https://doc.rust-lang.org/src/core/slice/iter.rs.html#1501
There might be some performance gain by not using Chunks, but that could be explored later. My focus for this PR was getting a working implementation not necessarily the fastest.
jamwaffles
left a comment
There was a problem hiding this comment.
Beat me to it! Looks good to me, although perhaps adding a (not doc) comment to explain the performance in nth().
This PR adds pixel getters to
BmpandRawBmp. It doesn't yet implement the newImagePixelGettertrait (embedded-graphics/embedded-graphics#612) to stay compatible with e-g0.7.