Extend PNG encoding and decoding support#332
Merged
edgarriba merged 5 commits intokornia:mainfrom Apr 2, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request extends the PNG module by adding support for 16‑bit RGB and RGBA encoding and decoding, along with additional write functions for various color types. Key changes include:
- New read functions for 16‑bit RGB and RGBA images.
- New write functions for PNG images including 8‑bit (RGB, RGBA, grayscale) and 16‑bit (RGB, RGBA, grayscale) formats.
- Updated error messages in the error module to improve clarity around PNG encoding/decoding.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/kornia-io/src/png.rs | Added 16‑bit read/write functions and updated PNG encoding implementation; documentation inconsistencies noted. |
| crates/kornia-io/src/error.rs | Modified error messages for PNG encoding/decoding errors. |
Comments suppressed due to low confidence (3)
crates/kornia-io/src/png.rs:213
- The function 'write_image_png_rgba16' should accept an image with 4 channels (Image<u16, 4>) for proper RGBA support rather than an image with 3 channels.
pub fn write_image_png_rgba16(file_path: impl AsRef<Path>, image: &Image<u16, 3>) -> Result<(), IoError> {
crates/kornia-io/src/png.rs:196
- [nitpick] Consider renaming 'bug_be' to 'be_bytes' to more clearly reflect the conversion being performed.
let bug_be = buf.to_be_bytes();
crates/kornia-io/src/png.rs:219
- [nitpick] Rename 'bug_be' to 'be_bytes' here as well to maintain consistency and clarity in the code.
let bug_be = buf.to_be_bytes();
edgarriba
reviewed
Apr 2, 2025
…again from the buffer in encoding
|
edgarriba
approved these changes
Apr 2, 2025
andrew-shc
pushed a commit
to andrew-shc/kornia-rs
that referenced
this pull request
Aug 2, 2025
* Extend PNG encoding and decoding support * Make png encoding error similar to png decoding error * Fix typos * Add test for rgb16 and reduce memory footprint by not creating image again from the buffer in encoding * Fix typo [no ci]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #252
Fixes #253
Also, I have added rgb16 and rgba16 support in both read and write functions. With this PR
pngmodule now supports every conversion.I was thinking that
kornia_image::Imageshould have a function for converting e.b.Image<u16, 1>toImage<u8, 1>and vice-versa, while maintain the same data using functions likeu16::from_be_bytes