-
-
Notifications
You must be signed in to change notification settings - Fork 174
Description
π Describe the bug
decode_gray8() (line 166) in crates/kornia-io/src/jpegturbo.rs returns Image<u8, 3> but should return Image<u8, 1>, as it decodes with PixelFormat::GRAY (1 byte per pixel) and the docstring already says it should return Image<u8, 1>.
Meanwhile the pitch (line 188) is hardcoded to 3 * image_size.width instead of C * image_size.width, which works for decode_rgb8 but breaks decode_gray8.
π Steps to Reproduce
1. Create a JpegTurboDecoder and call `decode_gray8` with any valid JPEG
2. Check num_channels() on the result, which returns 3 instead of 1π» Minimal Code Example
use kornia_io::jpegturbo::JpegTurboDecoder;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let decoder = JpegTurboDecoder::new()?;
let jpeg_data = std::fs::read("path/to/dog.jpeg")?;
let image = decoder.decode_gray8(&jpeg_data)?;
// Returns 3, should be 1
println!("channels: {}", image.num_channels());
Ok(())
}β Expected behavior
decode_gray8 should return Image<u8, 1> with 1 channel and correct pixel layout, consistent with its docstring and PixelFormat::GRAY.
β Actual behavior
decode_gray8 returns Image<u8, 3> with 3 channels. The buffer is 3x too large and the pitch is wrong, resulting in incorrect grayscale data.
π§ Environment
- kornia-rs version: 0.1.11 (workspace)
- Rust version (`rustc -V`): rustc 1.94.0 (4a4ef493e 2026-03-02)
- Cargo version (`cargo -V`): cargo 1.94.0 (85eff7c80 2026-01-15)
- OS (e.g., Linux, macOS, Windows): Linuxπ Additional context
The fix should be really simple by changing the return type of decode_gray8 from Image<u8, 3> to Image<u8, 1> and change pitch: 3 * image_size.width to pitch: C * image_size.width in decode<C>.
Happy to submit a PR if approved!
π€ Contribution Intent
- I plan to submit a PR to fix this bug
- I'm reporting this bug but not planning to fix it