libheif icon indicating copy to clipboard operation
libheif copied to clipboard

Monochrome HDR

Open dukesook opened this issue 4 months ago • 3 comments

I interested in writing 10/12/14/16-bit monochrome HEIFs. Is the existing heif_chroma_monochrome suited for this? Or would new chromas be requried:

enum heif_chroma
{
  heif_chroma_undefined = 99,
  heif_chroma_monochrome = 0,
  ...
  ...
  ...
  heif_chroma_monochrome_HDR_BE = 16,
  heif_chroma_monochrome_HDR_LE = 17,

};

dukesook avatar Aug 24 '25 16:08 dukesook

You can simply process 16bit monochrome by using heif_chroma_monochrome and adding a single heif_channel_Y with 10-16 bits. The plane then points to uint16_t.

It works out of the box with PNG 16bit input (use -b # to specify the output bit depth). JPEG2000 works up to 16 bit, H.265 with 10 and 12 bits (because of encoder limitations). I just tested with ISO23001-17, but it does not work correctly. There seems to be a bug.

Another bug seems to be in the 16bit PNG writer. I got a

libpng error: profile 'unknown': 'GRAY': Gray color space not permitted on RGB PNG

farindk avatar Aug 24 '25 16:08 farindk

Sounds good, I'll see if I can find the ISO23001-17 bug.

dukesook avatar Aug 24 '25 17:08 dukesook

Here is the relevant code: https://github.com/strukturag/libheif/blob/a5c6d3a972e5a43eeb2c0a971911fd69885eec62/libheif/image-items/unc_image.cc#L254-L259

It simply does not seem to consider bytes per pixel and only works with 8 bit. Looks like the same problem is also in the planar RGB writer. Interleaved RGB seems to be ok.

I'll reopen the issue until this and the PNG writer is fixed.

farindk avatar Aug 24 '25 17:08 farindk