-
Notifications
You must be signed in to change notification settings - Fork 6
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
Implement encoding for more types #14
base: trunk
Are you sure you want to change the base?
Conversation
0e9edd5
to
5fdabb5
Compare
5fdabb5
to
9c534c4
Compare
pub texel_block_dimensions: [u32; 4], //: 8 x 4; | ||
pub bytes_planes: [u32; 8], //: 8 x 8; | ||
pub flags: DataFormatFlags, //: 8; | ||
pub texel_block_dimensions: [NonZeroU8; 4], //: 8 x 4; |
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.
Is NonZeroU8
here useful enough to justify the ergonomic overhead compared to a plain u8
?
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 think it's worthwhile. The value must be non-zero or we can't encode the struct, and I think it's helpful to keep as_bytes
non-fallible.
pub bit_length: u32, //: 8; | ||
pub channel_type: u32, //: 4; | ||
pub bit_offset: u16, //: 16; | ||
pub bit_length: NonZeroU8, //: 8; |
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.
Same ergonomic question as above.
I've gotten some good results from some initial attempts to apply |
Review feedback should be addressed. |
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.
Still ambivalent about the NonZero
stuff, but not inclined to block on it.
Hey! Not blocked on this, but anything else I can do to help move this towards merging? |
This PR is based on #11. This PR enables users to write ktx2 images using the crate without having to manually encode core data structures. It still requires a lot of code even with this PR, so I'd like to follow it up with another PR that includes a higher-level API without sacrificing performance or simplicity.
I extended
pseudo_enum
to enable configurable integer sizes. I also hid the inner value in favor of exposing avalue
method as it makes consuming code a bit cleaner. This was necessary because many of these types are narrower than 32 bits.I made the
LENGTH
associated constant public on a couple of types and implementedas_bytes
for them. ForDataFormatDescriptorHeader::as_bytes
, I added an argument of the DFD block size because it's not part of the type. I think it maybe should be part of the type.I changed some members that have invariants about being non-zero from their primitive types to
NonZero*
types. In addition, I changed the relevant cases doing arithmetic on those values to handle incorrect cases to prevent panics or silent incorrect values.I put the one existing test into a
mod test
block as is convention and started adding round-trip tests for encoding and decoding. This helped uncover a couple bugs as I was working on the implementation. I think that this should use property-based testing if we can, but I have no experience with it in Rust.Here is a GitHub gist containing the code to write a single layer RGBA8 sRGB image using this crate after this PR: https://gist.github.com/LPGhatguy/a42ccf5bed9c7a099d2ee7a169d03c80
This shows that there is still a lot of nontrivial code required to encode a KTX2 image. I am interested in exploring APIs to make this much easier and I think it's important to do that in this crate.
Checklist
cargo clippy
reports no issuescargo doc
reports no issuescargo deny
issues have been fixed or added todeny.toml
cargo test
shows all tests passingAdded new functionality @githubname
.Description
Related Issues