image-rs / image

Encoding and decoding images in Rust
Apache License 2.0
4.99k stars 620 forks source link

Support for opening raw image formats(cr2, nef etc.) #1630

Open qarmin opened 2 years ago

qarmin commented 2 years ago

Frequently requested feature in my app is to be able to find similar images for raw formats like nef or cr2.

To be able to do this I use img_hash crate which uses this library to hash content of each supported image(jpg, png, tiff).

Since I don't know much about internals this formats, I don't know if it is possible to implement them.

I can open such images in default image viewer(Eye of Gnome) so I suspect that image can be used in same way as jpg or png are handled.

HeroicKatora commented 2 years ago

Do you have a clearer list of formats, maybe even statistics of how often they are encountered? In terms of prioritization or developers that know one of them and seeing the demand represented and rewarded it can be valuable.

We're pretty open to accepting any new sort of format but the contributor bandwidth for writing and maintaining the same quantity of decoders as EoG honestly does not seem to be there (yet?).

fintelia commented 2 years ago

According to Wikipedia, cr2 files are valid TIFF files. They may actually just work with our current TIFF decoder

johannesvollmer commented 2 years ago

Raw files are difficult, as they do not obey any Standard, and change often. The Rust crate rawloader supports a lot of raw formats and has the goal to keep up with the changes

Would you consider using both crates in parallel?

qarmin commented 2 years ago

It looks like this library is that what I'm looking for, but I can't find example how could I decode image inside rawloader and pass it to image-rs(img_hash library which I use, needs image struct from image-rs crate)

johannesvollmer commented 2 years ago

Raw is difficult because it's basically just a sensor dump. There's a large amount of processing required to obtain the RGBA pixels, such as demosaicing. The rawloader library is just for loading the image, as I understand it. Maybe a different crate also provided the conversion from raw to RGB, or maybe this exact conversion would be a nice feature for image-rs

johannesvollmer commented 2 years ago

I scanned the dependents of the rawloader create and found this crate from the same author: https://crates.io/crates/imagepipe

Promising?

qarmin commented 2 years ago

I already added support for raw files in https://github.com/qarmin/czkawka/commit/0f0e7a338fe5459a90f3e9c6eea024599961df1c

This code showed me how to convert raw file to DynamicImage(use both imagepipe and rawloader) https://github.com/Kl4rry/simp/blob/09c732097546ef77d6e1f1fce81cac40ddaddacf/src/image_io/load.rs#L124-L159 (I have a problem with hashing dark raw images, but probably with normal images problem also occurs )

paolobarbolini commented 2 years ago

FYI there's also https://github.com/paolobarbolini/libraw-rs/tree/master/libraw. It's passively maintained in the sense that I won't add bindings to the remaining libraw APIs, but I use it myself and try to keep it alive and updated

qarmin commented 1 year ago

Rawloader seems to be abandoned by library author(last author activity > 1 year ago). Quite sad, since it was probably the only full rust raw loader solution, but quite slow(at least converting decoded files to image-rs DynamicImage format)