Skip to content

Remove DynamicTga #16

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

Merged
merged 16 commits into from
Sep 24, 2022
Merged

Conversation

rfuest
Copy link
Member

@rfuest rfuest commented Mar 31, 2022

This draft PR is a possible solution to the color type problems we encountered in tinybmp. I didn't want to experiment with that project until the open PRs are merged.

The fundamental change in this PR is that Tga no longer accepts any C which has the same BPP as the image. Allowing any color type didn't make sense, because the color format is defined in the header. A C with the same BPP could represent completely different colors, e.g. Rgb888 and Bgr888.

Tga now behaves very similar to the removed DynamicTga. The C type parameter no longer specifies the format the image is stored in and is instead equal to the DrawTarget color type. The required bounds are changed to C: PixelColor + From<Gray8> + From<Rgb555> + From<Rgb888>, which is valid for all e-g color types and isn't hard to implement for custom color types. Tga will now be easier to use, because it's no longer necessary to specify the color type explicitly, when a Tga object is created.

The ImageDrawable impl is centered around a modified Pixels iterator. The iterator does now have two type parameters, one for the image color type and one for the target color type. This makes it possible to move the match statement over the image color type outside the iterator. By converting the colors in the iterator it isn't necessary to use color_converted draw targets, which should help with binary size.

To keep the Tga::pixels method working a pseudo color type Dynamic is used. It uses a different implementation of the iterator, which includes the match over the color type in the next method.

TODO:

  • Test impact on performance and binary size
  • Remove color table lookup from RawPixels

@rfuest
Copy link
Member Author

rfuest commented Mar 31, 2022

@jamwaffles It would be too early to review this code in detail, but I would appreciate some initial feedback if you think this is going in the right direction.

@rfuest rfuest mentioned this pull request Apr 16, 2022
4 tasks
Copy link
Member

@jamwaffles jamwaffles left a comment

Choose a reason for hiding this comment

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

I like where this is going so far. The removeal of DynamicTga is a welcome change to make the API simpler.

src/lib.rs Outdated
(Bpp::Bits16, false) => ColorType::Rgb555,
(Bpp::Bits24, false) => ColorType::Rgb888,
_ => {
return Err(ParseError::UnsupportedDynamicTgaType(
Copy link
Member

Choose a reason for hiding this comment

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

More a note to self when I review this proper: This error variant would need renaming too.

@rfuest rfuest marked this pull request as ready for review September 22, 2022 19:14
@rfuest
Copy link
Member Author

rfuest commented Sep 22, 2022

The docs could still use some work and they will also need to be updated to intra-doc links, but that could be handled in another PR.

I didn't do any thorough benchmarks or binary size comparisons with the old version, but at least compared to DynamicTga I did get -15% to -65% runtime reduction. The binary size will have increased, because there are now optimized drawing routines for every TGA variant. If this becomes a problem in the future I would suggest that we add cargo features to disable uncommon formats like top right and bottom right image origins.

@rfuest rfuest requested a review from jamwaffles September 22, 2022 19:31
@rfuest
Copy link
Member Author

rfuest commented Sep 22, 2022

@jamwaffles Could you also fix the required CI checks when you review this PR?

Copy link
Member

@jamwaffles jamwaffles left a comment

Choose a reason for hiding this comment

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

Looks good, just one small nit in the changelog.

CHANGELOG.md Outdated
@@ -6,6 +6,23 @@

## [Unreleased] - ReleaseDate

### Added

- [#16](https://github.com/embedded-graphics/tinybmp/pull/16) Added `display` example to display TGA images using the embedded-graphics simulator.
Copy link
Member

Choose a reason for hiding this comment

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

Did we discuss long ago in the e-g repo that changes like this don't make much sense in the changelog?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we did and I removed the entry from the changelog.

@rfuest rfuest merged commit a64a00e into embedded-graphics:master Sep 24, 2022
@rfuest rfuest deleted the remove-dynamic-tga branch September 24, 2022 18:40
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.

2 participants