kornia/kornia-rs

[Feature]: Expand `read_image_any_rgb8` to support more image formats

Open

#856 opened on Mar 27, 2026

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Rust (188 forks)auto 404
enhancementhelp wantedtriage

Repository metrics

Stars
 (675 stars)
PR merge metrics
 (PR metrics pending)

Description

Extend the extension-based dispatch in read_image_any_rgb8 so more common still-image formats are accepted, with clear errors and tests.

Motivation

Today only jpeg/jpg, png, and tiff are handled; anything else returns IoError::InvalidFileExtension. Users with WebP, BMP, GIF, etc. must call format-specific APIs manually, which hurts ergonomics and discoverability for “read any RGB8” workflows.

Proposed solution

  • Add dispatch branches (or a small registry) for additional formats already supported elsewhere in the crate/workspace where applicable.
  • Keep behavior explicit: decode to RGB8 (Rgb8) as the function name promises.
  • Add unit/integration tests using small fixtures under tests/data (or reuse existing assets).
  • Document supported extensions in the public rustdoc for read_image_any_rgb8.

Expected outcome

One-call loading works for a broader set of file types; errors remain typed (IoError) and documented.

✅ Acceptance criteria

  • read_image_any_rgb8 handles at least the newly agreed format set (listed in doc comment).
  • Tests cover each new extension (or magic-byte path if added).
  • No breaking change to existing call sites without a semver-appropriate path (or document breaking change if API must change).
  • cargo test -p kornia-io (with relevant features) passes.

Additional context

Separate from GStreamer video codecs (issue 9): this is file-based still image I/O. For a roadmap epic, link a parent issue “kornia-io format coverage.”

Code reference

pub fn read_image_any_rgb8(file_path: impl AsRef<Path>) -> Result<Rgb8<CpuAllocator>, IoError> {
    let file_path = file_path.as_ref().to_owned();

    // verify the file exists
    if !file_path.exists() {
        return Err(IoError::FileDoesNotExist(file_path.to_path_buf()));
    }

    // try to read the image from the file path
    // TODO: handle more image formats
    if let Some(extension) = file_path.extension() {
        match extension.to_string_lossy().to_lowercase().as_ref() {
            "jpeg" | "jpg" => read_image_jpeg_rgb8(file_path),
            "png" => read_image_png_rgb8(file_path),
            "tiff" => read_image_tiff_rgb8(file_path),
            _ => Err(IoError::InvalidFileExtension(file_path)),
        }
    } else {
        Err(IoError::InvalidFileExtension(file_path))
    }
}

Contribution Intent

  • I plan to submit a PR to implement this feature.
  • I'm requesting this feature but not planning to implement it.

Contributor guide