karlch/vimiv-qt

Support raw images

Closed this issue · 5 comments

There has been the request for supporting raw images, this should be rather simple according to
https://stackoverflow.com/questions/18637721/how-to-display-a-raw-image-file-in-a-qt-gui.

The file format would have to be detected by the load method in imutils/imfile_handler.py and a correct pixmap created from the data.

See this issue of the GTK version.

This is actually more difficult than I thought, there seem to be a phletora of different formats and reading any of them directly requires knowing width and height of the image in advance. Possibly simply reading the embedded jpeg is a solution as mention in the issue linked before, but I can only find the small thumbnail version of this which is rather small for displaying. @tobiasbrummer or @ninrod, could you comment on what you mean with the embedded jpeg, is it really simply the thumbnail?

I don’t know about all cameras as I only have access to my Sony A6300 at the moment. But I just tried to extract the embedded JPG image from a RAW file of the Sony A6300 with „dcraw -e“ and I get a JPG file with ~1600x1080px which I think is enough for preview purposes.

Thanks, that was the hint I needed 😄

With a quick and dirty hack I can get this working. For future reference, something along the lines of

output = subprocess.run(["dcraw", "-e", "-c", path], capture_output=True, check=True)
pixmap = QPixmap()
pixmap.loadFromData(output.stdout)
...

There are more pythonic solutions, e.g. using wand, but these seem significantly slower as they actually process the complete raw file.

As, in any case, this adds an additional dependency I think this could be a great plugin after #13 is in. Writing the actual API is currently my focus, a raw plugin could then be the next step.

I have recently learned about qt raw plugin. In principle this would provide full support for raw images. Issue with this is that the check we use to determine if a file is an image (utils.files.is_image) relies on imghdr which has no idea about raw images.

In principle, it is not too difficult to extend imghdr with new formats but every additional check impacts performance. As a compromise, there is now the imageformats plugin added in a1b8f42. It currently only supports "cr2", as that was the easiest proof-of-concept for me to implement.

It would be great if we could extend plugins.imageformats as needed, any help is very welcome :)

Solved via @jcjgraf's RawPrev plugin and, in principle, with qt raw. I don't think there is more we can or should do here.