Skip to content

Extend PNG encoding and decoding support#332

Merged
edgarriba merged 5 commits intokornia:mainfrom
as1100k-forks:issue-252
Apr 2, 2025
Merged

Extend PNG encoding and decoding support#332
edgarriba merged 5 commits intokornia:mainfrom
as1100k-forks:issue-252

Conversation

@AS1100K
Copy link
Copy Markdown
Member

@AS1100K AS1100K commented Apr 2, 2025

Fixes #252
Fixes #253

Also, I have added rgb16 and rgba16 support in both read and write functions. With this PR png module now supports every conversion.

I was thinking that kornia_image::Image should have a function for converting e.b. Image<u16, 1> to Image<u8, 1> and vice-versa, while maintain the same data using functions like u16::from_be_bytes

@edgarriba edgarriba requested a review from Copilot April 2, 2025 10:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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();

Comment thread crates/kornia-io/src/png.rs Outdated
Comment thread crates/kornia-io/src/png.rs Outdated
Comment thread crates/kornia-io/src/png.rs Outdated
Comment thread crates/kornia-io/src/png.rs Outdated
Comment thread crates/kornia-io/src/png.rs
Comment thread crates/kornia-io/src/png.rs Outdated
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 2, 2025

@edgarriba edgarriba merged commit 75220b4 into kornia:main Apr 2, 2025
1 check passed
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]
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.

implement write_image_png_rgb8 implement write_image_png_gray8

3 participants