-
-
Notifications
You must be signed in to change notification settings - Fork 11
More public items #51
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
Conversation
rfuest
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just making the constructors of the iterators public isn't the correct way to implement this. A user could, for example, create a Rle4Pixels iterator for a non RLE compressed image.
It's also more common to have a method, in this case inside RawBmp, to create the iterator than to use a constructor.
I would suggest to add methods like fn try_rle8_pixels(&self) -> Result<Rle8Pixels<'_'>, SomeErrorType> to RawBmp to only allow the creation of the iterators if the format of the BMP file matches.
|
What if instead make If they want to remain generic, they will call |
That's a good idea. But I would still prefer to have it constructed via a The only issue with exposing By having all variants of |
|
commit "feat: RawBmp::colors" has a question in the description, please read it. In short, maybe remove that assertion that the line wrapped? |
9f76701 to
d809be2
Compare
d809be2 to
9fbaff9
Compare
`header_type` is never read and `DibHeader` is private, so the compiler emits a warning. I added `#[expect(unused)]` so if it gets used at some point, compiler will ask you to remove it. `#[allow(dead_code)]` is worse because it will itself become a dead code if `header_type` gets used.
In preparation of remove that logic from them and moving it up.
Additional work that was required by `RawBmp::colors`:
- Making `DynamicRawColors` public.
- Making `DynamicRawColors` implement iterator.
- Refactoring logic.
- Rename `Rle{4,8}Pixels` to `Rle{4,8}Colors`
- Due to removal of position handling in `Rle{4,8}Pixels`, they can no
longer assert the the new line corresponds with the width. I left the
assertion functionally the same, but with slightly different approach.
Personally, I don't think it is necessary that that assert there at
all - like, either way the image would be broken and developer will
have to fix the `bmp` file, that assertion isn't helpful at all.
fc09f4b to
04991b7
Compare
rfuest
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having all DynamicRawColors variants behave the same now is a nice improvement.
I haven't had time to look at all of the code changes in detail yet, but here is a review that primarily focuses on docs and coding style.
src/raw_iter.rs
Outdated
| DynamicRawColors::Bpp1(_) | ||
| | DynamicRawColors::Bpp4(_) | ||
| | DynamicRawColors::Bpp8(_) | ||
| | DynamicRawColors::Bpp16(_) | ||
| | DynamicRawColors::Bpp24(_) | ||
| | DynamicRawColors::Bpp32(_) => RowOrder::TopDown, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uncompressed BMP files can be top down or bottom up. It should be enough to return the value in Header::row_order for both, uncompressed and RLE files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this context I don't see access to the header. Uncompressed ones have row_order inside the struct, but not RLE. For now I will return the value from uncompressed and BottomUp for compressed.
| /// Indicate that a new line is starting. Required for correct RLE decoding. | ||
| pub fn start_a_line(&mut self) { | ||
| self.start_of_line = true; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked into this yet, but I guess that this is an internal method that isn't supposed be called by a user. If that is the case it shouldn't be public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this method should be present, it should be public - if user matches on colors and uses rle4colors, they must call that method at the start of a line too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I believe the better way would be to just not assert 😄
src/raw_iter.rs
Outdated
| } | ||
| old_position | ||
| /// Indicate that a new line is starting. Required for correct RLE decoding. | ||
| pub fn start_a_line(&mut self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment about the other start_a_line method.
fa951aa to
016e3ad
Compare
|
Uhm, this is strange. DynamicRawColors::Bpp16(colors) => colors.row_order,But passes with DynamicRawColors::Bpp16(colors) => RowOrder::TopDown,Test expects It seems to me that either image or header parsing has an error, but it was not visible before. Should I do something with it? It seems like a separate PR needed. |
016e3ad to
e3c6a72
Compare
|
By the way, I implemented |
Seems like the test is invalid. The header information, which is tested in |
Drawing repeated pixels by using |
854d6b1 to
0ca058f
Compare
0ca058f to
efe1fc2
Compare
rfuest
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thank you for helping out with tinybmp development! Please:
CHANGELOG.mdentry in the Unreleased section under the appropriate heading (Added, Fixed, etc) if your changes affect the public APIrustfmton the projectPR description
Raw API that was exposed by that crate is not really enough. You already have RLE implemented, so why not just expose it? I of course can rewrite it and use
image_datathat is provided byRawBmp, but why if you already have an implementation?raw_pixelsmethod goes through the dynamic dispatch and introduces unnecessary work, alternative is just make a couple of methods public.