google / libultrahdr

Ultra HDR is a true HDR image format, and is backcompatible. libultrahdr is the reference codec for the Ultra HDR format. The codecs that support the format can render the HDR intent of the image on HDR displays; other codecs can still decode and display the SDR intent of the image.
https://developer.android.com/guide/topics/media/platform/hdr-image-format
Apache License 2.0
142 stars 24 forks source link

Encode Scenario 4 Does not replace gain map if input jpeg already contains a gain map. #166

Closed pmonck closed 1 month ago

pmonck commented 2 months ago

When using ultrahdr_app to encode in scenario 4, if the input jpeg file contains a gain map, then the command simply copies the input file to the output without raising an error condition. The supplied gain map is ignored and not applied to the image.

For example, when using the command : ultrahdr_app -m 0 -i jpegR.jpg -g gainmap.jpg -f metadata.cfg -z UltraHDR.jpg

UltraHDR.jpg is the same as jpegR.jpg if jpegR.jpg already contains a gain map.

I propose that the command should either: a) ignore the gain map in the input file and apply the gain map supplied in the command line to the base image, i.e. UltraHDR.jpg contains the gain map found in gainmap.jpg, not the one found in jpegR.jpg.

Or b) report an error stating that a gain map was found in the input file and that gainmap.jpg has not been applied.

I prefer a) as it provides the useful function of allowing the user to replace an existing gain map with another.

ram-mohan commented 1 month ago

This seemed to be a useful addition to api-4, but i am having second thoughts now. Because there are other apis (api-2, api-3) that accept jpeg as input, should they be checked as well (if it is sdr intent jpeg image or ultrahdr image). The documentation clearly states that sdr intent jpeg is to be given as input.

pmonck commented 1 month ago

I see what you mean.

However, if there is no warning/error condition raised, I think it would be quite easy for users to unknowingly supply an ultrahdr image as input where an sdr intent jpeg image is required.

Furthermore, without indication to the contrary, my expectation would be for api-4 to replace the gain map from the original ultrahdr input with the one supplied.

Currently, api-4 simply does nothing when the input file contains a gain map and doesn't warn the user that the supplied gain map and metadata have not been applied.

What I'm after is a way to replace existing gain maps and metadata with a new ones. Perhaps we could add a command line option to ignore any existing gain maps in input files? I still think there should be a warning given when the supplied gain map hasn't been applied.