Skip to content

Add pure-Rust PNG encoding (encode_png / save_image) and 16-bit / palette PNG decoding #4

Done

Description

@voidstackloop

Difficulty: Easy (good first issue)
Mentorship: Yes — comment on this issue or start a thread in GitHub Discussions for guidance and code review.
Contribution Guidelines: Please see CONTRIBUTING.md (dual-licensed under MIT OR Apache-2.0, no CLA required).

What Is Asked

crates/oxideon-core/src/image_codec.rs already provides zero-dependency pure-Rust PNG and JPEG decoding (decode_png, decode_jpeg, decode_image_tensor, load_image) so core tensor code does not depend on external image crates or Pillow.

We want to add:

  1. Pure-Rust PNG encoding (encode_png and save_image).
  2. Indexed-palette (color_type = 3 with PLTE + optional tRNS) and 16-bit PNG support in decode_png.

Expected Outcome

  • encode_png(pixels: &[u8], width: usize, height: usize, channels: usize) -> Result<Vec<u8>> produces valid PNG files (Grayscale, Grayscale+Alpha, RGB, RGBA).
  • save_image(tensor: &Tensor, path: impl AsRef<Path>) -> Result<()> writes [C, H, W] u8 tensors cleanly to .png.
  • decode_png decodes palette (PLTE) and 16-bit PNGs without errors.
  • Round-trip unit tests (encode_png -> decode_png) pass in cargo test -p oxideon-core --lib image_codec.

Implementation Guidance

  • image_codec.rs already has CRC-32 and Adler-32 helpers in its test module (crc32, adler32) that can be promoted for shared use by the encoder.
  • For initial PNG encoding, stored DEFLATE blocks or a simple zlib wrapper + PNG IHDR / IDAT / IEND chunk writer keeps the implementation clean, zero-dependency, and fast to verify.
  • For palette PNGs (color_type = 3), parse the PLTE chunk (3 * N RGB bytes) and map each index byte cleanly in the scanline pass.

Activity

  1. added
    enhancement
    help wanted
    good first issue
    easy
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    easyenhancementgood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions