strukturag / libheif

libheif is an HEIF and AVIF file format decoder and encoder.
Other
1.7k stars 298 forks source link

Handle Canon .HIF files (from 1Dx III) #219

Open revk opened 4 years ago

revk commented 4 years ago

The Canon 1Dx III produces HEIF files (extension .HIF). They work fine on a MAC (once I change file extension tot .heic) , but heif-convert does not work.

Testing on linux.

Initially with the package installed,I got the error about not supporting HEIC, but built from latest git clone I now get an error saying JPEG cannot encode >8 bpp.

I don't know if I have missed something obvious, I hope so, but it would be nice if it can handle these files. Let me know if anything else I can do to help.

AJKL0035.zip

farindk commented 4 years ago

That Canon camera writes HDR images (>8 bit). JPEG can only handle 8 bit, hence you get the error. If you output to PNG, it should work.

On the other hand, check out the 'all-rgb' branch of libheif. There is already code in heif-convert to convert this down to 8 bit for JPEG. Just tried with your image and it works.

I'll try to finish the work in this branch next week and merge it to master.

lclevy commented 4 years ago

FYI: https://github.com/lclevy/canon_cr3/blob/master/heif.md

farindk commented 4 years ago

@lclevy Thank you.

lclevy commented 4 years ago

Please tell me if Canon files can be viewed or converted, on which platform, so that I can add libheif in links / tools sections

revk commented 4 years ago

The canon has a feature to convert to jpeg on a picture by picture basis, and I can view on anything Mac or iPhone with no problem (they look really good). It would be nice if the heif-convert could reduce to 8 bit for jpeg, for example as I want to use to make web page index images for my stored photos (which I would them download as HEIC anyway), if that makes sense. I'll try PNG though.

revk commented 4 years ago

I'll try the all-rib branch anyway

revk commented 4 years ago

Good, the all-rgb branch works - the JPG output looks really dull for some reason, but that is a good start, thanks.

farindk commented 4 years ago

It looks dull because of the PQ color profile used by Canon. That will have to be handled by a color-profile management system.

revk commented 4 years ago

OK two more issues related to this - one if that the orientation is not right on the JPEG for some reason. The other is that the colour is extremely dull, so probably needs some adjustment as part of the conversion to get remotely close. If anything I can do to help, do let me know. Excellent tool, thank you.

farindk commented 4 years ago

If you could upload an image with wrong orientation, that would help, as I don't have such a camera. Thank you.

revk commented 4 years ago

OK attached is a zip that includes:-

  1. The original HIF from the camera
  2. A JPG of the same image as converted from HEIF by the camera
  3. A JPG as converted using heif-convert (all-rgb branch cloned yesterday)

From what I have been reading, it should not be hard to sort orientation, let me know if I can assist in any way.

As for the colour, I assume it is a result of the image being a HDR, so even some option on heif-convert to brighten it up a bit would be helpful :-)

I hope that helps.

Ha, cannot upload the ZIP as too big, LOL, so here... https://www.me.uk/Canon1DxIIIExamples.zip

revk commented 4 years ago

The colour issue is interesting - converting on a mac by exporting from preview I get a JPEG that has a colour profile of Rec. ITU-R BT.2020; SMPTE ST 2084 PQ. The JPEG itself then breaks if I send it to twitter, etc, but there are tools I can use to convert the colour profile separately. It sounds like the conversion to JPEG is not saving the original colour profile from the HEIF.

lclevy commented 4 years ago

hi @revk could you please send me a craw + jpeg from your 1dxm3 ? maybe 1 second with dust removal info ?

revk commented 4 years ago

More than happy to do any test images.

Do these help... https://www.me.uk/AJKL0637.HIF https://www.me.uk/AJKL0637.CR3 https://www.me.uk/AJKL0638.HIF https://www.me.uk/AJKC0638.CR3 https://www.me.uk/AJKL0639.JPG https://www.me.uk/AJKL0640.JPG

That should be RAW and CRAW with HIF, and final two are on-camera HIF->JPG for first two.

farindk commented 4 years ago

Concerning the HEIF->JPEG image rotation problem. I have opened a separate task for that (#227). The rotation is in fact correctly handled by libheif, but since the Exif data is copied to the JPEG output, the JPEG will be rotated again in the viewer. We should remove the Orientation tag from the Exif data, but need an Exif-parser for that.

towhee commented 4 years ago

I could use a little help with this if possible. I have been using libheif/libde265 in an image browser I have written in Qt/c++ and it has worked for iphone heic images. However it is not accepting the CR3 images. I get the error "Unsupported file-type: Unspecified: File does not support the 'heic' brand.".

I am using the latest master branch of libheif and the frame-parallel branch of libde265.

Here is a code snip:

heif_context* ctx = heif_context_alloc(); auto error = heif_context_read_from_file(ctx, fPath.toLatin1().data(), nullptr); // error generated error.mesage = Unsupported file-type: Unspecified: File does not support the 'heic' brand.

Here is the test image 1DX3

Thanks for all the work you have done on this excellent library!

Regards Rory

ted-gould commented 3 years ago

Recently got a Canon R5 and I think that I'm seeing a similar problem with the HIF files that it generates. I noticed above that the all-rgb branch works, but it is fairly behind main at this point. Is that the best option? Thanks.