strukturag / libheif

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

Handle HEIF images with missing file header (e.g. produced by Canon camera) #206

Open damonlynch opened 4 years ago

damonlynch commented 4 years ago

Canon CR3 images have an unusual attribute when the Canon camera is in HDR mode: according to Phil Harvey (ExifTool developer), "The embedded preview in these CR3 files are not JPG format.  They are instead basically HEIF format without the file header."

Is it is possible that libheif could be improved to be able to render these images even though they lack the file header? Alternatively, is it easy for the program calling libheif to programmatically add an appropriate file header before passing it to libheif? (I have no idea how to do that.)

The use case is to generate thumbnails from the extracted preview images of these CR3 files. (I suspect Canon's embedded HEIF previews have the same property, but I don't know how to extract them as ExifTool doesn't yet handle them).

It's likely that these type of embedded previews in Canon's CR3 files will be the "new normal" from now on. Canon tends to be pretty consistent with its file formats, in my experience.

The HEIF images are described in p. 223 of the EOS-1D X Mark II manual:

HDR PQ Settings

PQ in HDR PQ refers to the gamma curve of the input signal for displaying HDR images. HDR PQ settings enable the camera to produce HDR images conforming to the PQ specification defined in ITU-R BT.2100 and SMPTE ST.2084 (with actual display depending on monitor performance). Shots are captured as HEIF or RAW images.

  • HDR stands for High Dynamic Range.
  • PQ stands for Perceptual Quantization.
lclevy commented 4 years ago

Hi, for HDR CR3 files, HEIF metadata are inside THMB and main CRAW boxes. you can find Canon markers:

Laurent soon documented at https://github.com/lclevy/canon_cr3

I:\dev\canon_cr3>python parse_cr3.py -v 1 "d:\cr3_samples\1dx3\struktur 1D X Mark III HEIF samples\93FG5559.CR3" filesize 0x17dbc58 00000:ftyp: major_brand=b'crx ', minor_version=1, [b'crx ', b'isom'] (0x18) 00018:moov: (0xacf0) 00020: uuid: b'85c0b687820f11e08111f4ce462b6a48' (0xa310) 00038: CNCV: b'CanonCR3_002/00.10.00/00.00.00' (0x26) ... 03758: THMB: version=1, width=320, height=214, jpeg_size=0x6bc0 (0x6bd8) 03770: b'CISZ' b'000000000000014000000140' (0x14) 03784: b'hvcC' b'0104080000009d20000000003cf000fcfefafa00000f03a0' (0xaf) 03833: colr: b'nclx' 9 10 9 80 03846: pixi: 3, 10 10 10 03856: b'IMGD' b'00006ac000006abc2601ac18c0f9558525640207952fbd1c' (0x6acc) 0a330: b'mvhd' b'00000000da72f103da72f103000000010000000100010000' (0x6c) .... 0a491: b'stsd' b'000000000000000100000170435241570000000000000001' (0x180) 00010: CRAW: (0x170) width=5472, height=3648, bits=24 0005a: b'HEVC' b'000000010000001847524944000000000000000400000101' (0x10c) 0000c: b'GRID' b'00000000000000040000010115600e40' (0x18) 00024: b'CISZ' b'0000000000000ac000000740' (0x14) 00038: b'hvcC' b'0124080000009d200000000099f000fcfefafa00000f03a0' (0xb1) 000e9: colr: b'nclx' 9 10 9 80 000fc: pixi: 3, 10 10 10 00166: b'free' b'0000' (0xa)