Registry Mirror
Skip to content

Conversation

@rfuest

@rfuest rfuest commented Sep 29, 2022

Copy link
Copy Markdown
Member

This PR adds pixel getters to Bmp and RawBmp. It doesn't yet implement the new ImagePixelGetter trait (embedded-graphics/embedded-graphics#612) to stay compatible with e-g 0.7.

Comment thread src/raw_bmp.rs
match self.header.bpp {
Bpp::Bits1 => RawDataSlice::<RawU1, LittleEndian>::new(row)
.into_iter()
.nth(p.x as usize)

@mbuesch mbuesch Sep 29, 2022 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a specialized implementation of nth which is O(1).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RawDataSlice and the iterators are included in embedded-graphics: https://github.com/embedded-graphics/embedded-graphics/blob/master/src/iterator/raw.rs

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Does that also count for the nth in line 100?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice. Looks good to me then.

@jamwaffles jamwaffles left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beat me to it! Looks good to me, although perhaps adding a (not doc) comment to explain the performance in nth().

@rfuest
rfuest merged commit 58c8e3f into embedded-graphics:master Sep 29, 2022
@rfuest
rfuest deleted the pixel-getter branch September 29, 2022 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants