diff --git a/docs/building.md b/docs/building.md index 9a64a5e0..27e4b374 100644 --- a/docs/building.md +++ b/docs/building.md @@ -52,7 +52,7 @@ Following is a list of available options: |:-------------|:--------------|:-----| | `CMAKE_BUILD_TYPE` | Release | See CMake documentation [here](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html). | | `BUILD_SHARED_LIBS` | ON | See CMake documentation [here](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html). | -| `UHDR_BUILD_EXAMPLES` | ON | Build sample application. This application demonstrates how to use [ultrahdr_api.h](ultrahdr_api.h). | +| `UHDR_BUILD_EXAMPLES` | ON | Build sample application. This application demonstrates how to use [ultrahdr_api.h](../ultrahdr_api.h). | | `UHDR_BUILD_TESTS` | OFF | Build Unit Tests. Mostly for Devs. During development, different modules of libuhdr library are validated using GoogleTest framework. Developers after making changes to library are expected to run these tests to ensure every thing is functional. | | `UHDR_BUILD_BENCHMARK` | OFF | Build Benchmark Tests. These are for profiling libuhdr encode/decode API. Resources used by benchmark tests are shared [here](https://storage.googleapis.com/android_media/external/libultrahdr/benchmark/UltrahdrBenchmarkTestRes-1.1.zip). These are downloaded and extracted automatically during the build process for later benchmarking. | | `UHDR_BUILD_FUZZERS` | OFF | Build Fuzz Test Applications. Mostly for Devs. | diff --git a/examples/ultrahdr_app.cpp b/examples/ultrahdr_app.cpp index 4653e6aa..bff0adc8 100644 --- a/examples/ultrahdr_app.cpp +++ b/examples/ultrahdr_app.cpp @@ -257,8 +257,7 @@ class UltraHdrAppInput { bool isHdrCrFull = false, int gainmapScaleFactor = 1, int gainmapQuality = 95, bool enableMultiChannelGainMap = true, float gamma = 1.0f, bool enableGLES = false, uhdr_enc_preset_t encPreset = UHDR_USAGE_BEST_QUALITY, float minContentBoost = FLT_MIN, - float maxContentBoost = FLT_MAX, float masteringDispPeakBrightness = -1.0f, - float targetDispPeakBrightness = -1.0f) + float maxContentBoost = FLT_MAX, float targetDispPeakBrightness = -1.0f) : mHdrIntentRawFile(hdrIntentRawFile), mSdrIntentRawFile(sdrIntentRawFile), mSdrIntentCompressedFile(sdrIntentCompressedFile), @@ -286,7 +285,6 @@ class UltraHdrAppInput { mEncPreset(encPreset), mMinContentBoost(minContentBoost), mMaxContentBoost(maxContentBoost), - mMasteringDispPeakBrightness(masteringDispPeakBrightness), mTargetDispPeakBrightness(targetDispPeakBrightness), mMode(0){}; @@ -320,7 +318,6 @@ class UltraHdrAppInput { mEncPreset(UHDR_USAGE_BEST_QUALITY), mMinContentBoost(FLT_MIN), mMaxContentBoost(FLT_MAX), - mMasteringDispPeakBrightness(-1.0f), mTargetDispPeakBrightness(-1.0f), mMode(1){}; @@ -404,7 +401,6 @@ class UltraHdrAppInput { const uhdr_enc_preset_t mEncPreset; const float mMinContentBoost; const float mMaxContentBoost; - const float mMasteringDispPeakBrightness; const float mTargetDispPeakBrightness; const int mMode; @@ -706,9 +702,6 @@ bool UltraHdrAppInput::encode() { if (mMinContentBoost != FLT_MIN || mMaxContentBoost != FLT_MAX) { RET_IF_ERR(uhdr_enc_set_min_max_content_boost(handle, mMinContentBoost, mMaxContentBoost)) } - if (mMasteringDispPeakBrightness != -1.0f) { - RET_IF_ERR(uhdr_enc_set_mastering_display_peak_brightness(handle, mMasteringDispPeakBrightness)) - } if (mTargetDispPeakBrightness != -1.0f) { RET_IF_ERR(uhdr_enc_set_target_display_peak_brightness(handle, mTargetDispPeakBrightness)) } @@ -1388,16 +1381,10 @@ static void usage(const char* name) { " -K max content boost recommendation, must be in linear scale, optional.[any " "positive real number] \n"); fprintf(stderr, - " -N set mastering display peak brightness in nits. \n" - " required, if the input color transfer is linear. \n" - " optional, if the input color transfer is HLG or PQ. \n" + " -L set target display peak brightness in nits, optional. \n" " For HLG content, this defaults to 1000 nits. \n" " For PQ content, this defaults to 10000 nits. \n" " any real number in range [203, 10000]. \n"); - fprintf(stderr, - " -L set target display peak brightness in nits. \n" - " optional, defaults to mastering display peak brightness setting. \n" - " any real number in range [203, 10000]. \n"); fprintf(stderr, " -x binary input resource containing exif data to insert, optional. \n"); fprintf(stderr, "\n## decoder options : \n"); fprintf(stderr, " -j ultra hdr compressed input resource, required. \n"); @@ -1485,7 +1472,7 @@ static void usage(const char* name) { } int main(int argc, char* argv[]) { - char opt_string[] = "p:y:i:g:f:w:h:C:c:t:q:o:O:m:j:e:a:b:z:R:s:M:Q:G:x:u:D:k:K:N:L:"; + char opt_string[] = "p:y:i:g:f:w:h:C:c:t:q:o:O:m:j:e:a:b:z:R:s:M:Q:G:x:u:D:k:K:L:"; char *hdr_intent_raw_file = nullptr, *sdr_intent_raw_file = nullptr, *uhdr_file = nullptr, *sdr_intent_compressed_file = nullptr, *gainmap_compressed_file = nullptr, *gainmap_metadata_cfg_file = nullptr, *output_file = nullptr, *exif_file = nullptr; @@ -1509,7 +1496,6 @@ int main(int argc, char* argv[]) { uhdr_enc_preset_t enc_preset = UHDR_USAGE_BEST_QUALITY; float min_content_boost = FLT_MIN; float max_content_boost = FLT_MAX; - float mastering_disp_peak_brightness = -1.0f; float target_disp_peak_brightness = -1.0f; int ch; while ((ch = getopt_s(argc, argv, opt_string)) != -1) { @@ -1605,9 +1591,6 @@ int main(int argc, char* argv[]) { case 'K': max_content_boost = atof(optarg_s); break; - case 'N': - mastering_disp_peak_brightness = atof(optarg_s); - break; case 'L': target_disp_peak_brightness = atof(optarg_s); break; @@ -1633,14 +1616,13 @@ int main(int argc, char* argv[]) { std::cerr << "did not receive raw resources for encoding." << std::endl; return -1; } - UltraHdrAppInput appInput(hdr_intent_raw_file, sdr_intent_raw_file, sdr_intent_compressed_file, - gainmap_compressed_file, gainmap_metadata_cfg_file, exif_file, - output_file ? output_file : "out.jpeg", width, height, hdr_cf, sdr_cf, - hdr_cg, sdr_cg, hdr_tf, quality, out_tf, out_cf, - use_full_range_color_hdr, gainmap_scale_factor, - gainmap_compression_quality, use_multi_channel_gainmap, gamma, - enable_gles, enc_preset, min_content_boost, max_content_boost, - mastering_disp_peak_brightness, target_disp_peak_brightness); + UltraHdrAppInput appInput( + hdr_intent_raw_file, sdr_intent_raw_file, sdr_intent_compressed_file, + gainmap_compressed_file, gainmap_metadata_cfg_file, exif_file, + output_file ? output_file : "out.jpeg", width, height, hdr_cf, sdr_cf, hdr_cg, sdr_cg, + hdr_tf, quality, out_tf, out_cf, use_full_range_color_hdr, gainmap_scale_factor, + gainmap_compression_quality, use_multi_channel_gainmap, gamma, enable_gles, enc_preset, + min_content_boost, max_content_boost, target_disp_peak_brightness); if (!appInput.encode()) return -1; if (compute_psnr == 1) { if (!appInput.decode()) return -1; diff --git a/java/UltraHdrApp.java b/java/UltraHdrApp.java index 64d3d356..e76c4b69 100644 --- a/java/UltraHdrApp.java +++ b/java/UltraHdrApp.java @@ -64,7 +64,6 @@ public class UltraHdrApp { private final int mEncPreset; private final float mMinContentBoost; private final float mMaxContentBoost; - private final float mMasteringDispPeakBrightness; private final float mTargetDispPeakBrightness; byte[] mYuv420YData, mYuv420CbData, mYuv420CrData; @@ -83,8 +82,7 @@ public UltraHdrApp(String hdrIntentRawFile, String sdrIntentRawFile, int height, int hdrCf, int sdrCf, int hdrCg, int sdrCg, int hdrTf, int quality, int oTf, int oFmt, boolean isHdrCrFull, int gainmapScaleFactor, int gainmapQuality, boolean enableMultiChannelGainMap, float gamma, int encPreset, float minContentBoost, - float maxContentBoost, float masteringDispPeakBrightness, - float targetDispPeakBrightness) { + float maxContentBoost, float targetDispPeakBrightness) { mHdrIntentRawFile = hdrIntentRawFile; mSdrIntentRawFile = sdrIntentRawFile; mSdrIntentCompressedFile = sdrIntentCompressedFile; @@ -112,7 +110,6 @@ public UltraHdrApp(String hdrIntentRawFile, String sdrIntentRawFile, mEncPreset = encPreset; mMinContentBoost = minContentBoost; mMaxContentBoost = maxContentBoost; - mMasteringDispPeakBrightness = masteringDispPeakBrightness; mTargetDispPeakBrightness = targetDispPeakBrightness; } @@ -145,7 +142,6 @@ public UltraHdrApp(String gainmapMetadataCfgFile, String uhdrFile, String output mEncPreset = UHDR_USAGE_BEST_QUALITY; mMinContentBoost = Float.MIN_VALUE; mMaxContentBoost = Float.MAX_VALUE; - mMasteringDispPeakBrightness = -1.0f; mTargetDispPeakBrightness = -1.0f; } @@ -394,9 +390,6 @@ public void encode() throws Exception { if (mMinContentBoost != Float.MIN_VALUE || mMaxContentBoost != Float.MAX_VALUE) { handle.setMinMaxContentBoost(mMinContentBoost, mMaxContentBoost); } - if (mMasteringDispPeakBrightness != -1.0f) { - handle.setMasteringDisplayPeakBrightness(mMasteringDispPeakBrightness); - } if (mTargetDispPeakBrightness != -1.0f) { handle.setTargetDisplayPeakBrightness(mTargetDispPeakBrightness); } @@ -472,16 +465,10 @@ public static void usage() { + " optional. any positive real number"); System.out.println(" -K max content boost recommendation, must be in linear scale," + " optional. any positive real number"); - System.out.println(" -N set mastering display peak brightness in nits."); - System.out.println(" required if the input color transfer is linear."); - System.out.println(" optional if the input color transfer is HLG or PQ."); + System.out.println(" -L set target display peak brightness in nits, optional"); System.out.println(" For HLG content, this defaults to 1000 nits."); System.out.println(" For PQ content, this defaults to 10000 nits."); System.out.println(" any real number in range [203, 10000]."); - System.out.println(" -L set target display peak brightness in nits."); - System.out.println( - " optional, defaults to mastering display peak brightness setting."); - System.out.println(" any real number in range [203, 10000]."); System.out.println(" -x binary input resource containing exif data to insert, " + "optional."); System.out.println("\n## decoder options :"); @@ -591,7 +578,6 @@ public static void main(String[] args) throws Exception { boolean enable_gles = false; float min_content_boost = Float.MIN_VALUE; float max_content_boost = Float.MAX_VALUE; - float mastering_disp_max_brightness = -1.0f; float target_disp_max_brightness = -1.0f; boolean use_full_range_color_hdr = false; boolean use_multi_channel_gainmap = true; @@ -683,9 +669,6 @@ public static void main(String[] args) throws Exception { case 'K': max_content_boost = Float.parseFloat(args[++i]); break; - case 'N': - mastering_disp_max_brightness = Float.parseFloat(args[++i]); - break; case 'L': target_disp_max_brightness = Float.parseFloat(args[++i]); break; @@ -722,7 +705,7 @@ public static void main(String[] args) throws Exception { hdr_cf, sdr_cf, hdr_cg, sdr_cg, hdr_tf, quality, out_tf, out_cf, use_full_range_color_hdr, gain_map_scale_factor, gainmap_compression_quality, use_multi_channel_gainmap, gamma, enc_preset, min_content_boost, - max_content_boost, mastering_disp_max_brightness, target_disp_max_brightness); + max_content_boost, target_disp_max_brightness); appInput.encode(); } else if (mode == 1) { if (uhdr_file == null) { diff --git a/java/com/google/media/codecs/ultrahdr/UltraHDREncoder.java b/java/com/google/media/codecs/ultrahdr/UltraHDREncoder.java index 45271941..463eada7 100644 --- a/java/com/google/media/codecs/ultrahdr/UltraHDREncoder.java +++ b/java/com/google/media/codecs/ultrahdr/UltraHDREncoder.java @@ -415,30 +415,13 @@ public void setMinMaxContentBoost(float minContentBoost, float maxContentBoost) } /** - * Set peak brightness of the reference display used during content mastering. For - * {@link UltraHDRCommon#UHDR_CT_HLG}, {@link UltraHDRCommon#UHDR_CT_LINEAR} inputs, this - * corresponds to the brightness level of the maximum code value 1.0. - *

- * For {@link UltraHDRCommon#UHDR_CT_HLG}, default mastering display peak luminance is 1000 - * nits. For {@link UltraHDRCommon#UHDR_CT_LINEAR} content, there is no default value, needs - * to be configured, otherwise, error is thrown during encoding. For - * {@link UltraHDRCommon#UHDR_CT_PQ} content, default mastering display peak luminance is - * 10000 nits. - * - * @param nits mastering display peak brightness in nits. Any positive real number in range - * [203, 10000]. - * @throws IOException If parameters are not valid or current encoder instance - * is not valid or current encoder instance is not suitable - * for configuration exception is thrown - */ - public void setMasteringDisplayPeakBrightness(float nits) throws IOException { - setMasteringDisplayPeakBrightnessNative(nits); - } - - /** - * Set target display peak brightness in nits. This value determines the weight by which the - * gain map coefficients are scaled during decode. If this is not configured, then mastering - * display peak brightness setting is used. + * Set target display peak brightness in nits. This is used for configuring + * {@link UltraHDRDecoder.GainMapMetadata#hdrCapacityMax}. This value determines the weight + * by which the gain map coefficients are scaled during decode. If this is not configured, + * then default peak luminance of HDR intent's color transfer under test is used. For + * {@link UltraHDRCommon#UHDR_CT_HLG} input, this corresponds to 1000 nits and for + * {@link UltraHDRCommon#UHDR_CT_LINEAR} and {@link UltraHDRCommon#UHDR_CT_PQ} inputs, this + * corresponds to 10000 nits. * * @param nits target display peak brightness in nits. Any positive real number in range * [203, 10000] @@ -525,8 +508,6 @@ private native void setGainMapImageInfoNative(byte[] data, int size, float maxCo private native void setMinMaxContentBoostNative(float minContentBoost, float maxContentBoost) throws IOException; - private native void setMasteringDisplayPeakBrightnessNative(float nits) throws IOException; - private native void setTargetDisplayPeakBrightnessNative(float nits) throws IOException; private native void encodeNative() throws IOException; diff --git a/java/jni/com_google_media_codecs_ultrahdr_UltraHDREncoder.h b/java/jni/com_google_media_codecs_ultrahdr_UltraHDREncoder.h index 31a6c9b1..7c27643d 100644 --- a/java/jni/com_google_media_codecs_ultrahdr_UltraHDREncoder.h +++ b/java/jni/com_google_media_codecs_ultrahdr_UltraHDREncoder.h @@ -137,14 +137,6 @@ JNIEXPORT void JNICALL Java_com_google_media_codecs_ultrahdr_UltraHDREncoder_set JNIEXPORT void JNICALL Java_com_google_media_codecs_ultrahdr_UltraHDREncoder_setMinMaxContentBoostNative (JNIEnv *, jobject, jfloat, jfloat); -/* - * Class: com_google_media_codecs_ultrahdr_UltraHDREncoder - * Method: setMasteringDisplayPeakBrightnessNative - * Signature: (F)V - */ -JNIEXPORT void JNICALL Java_com_google_media_codecs_ultrahdr_UltraHDREncoder_setMasteringDisplayPeakBrightnessNative - (JNIEnv *, jobject, jfloat); - /* * Class: com_google_media_codecs_ultrahdr_UltraHDREncoder * Method: setTargetDisplayPeakBrightnessNative diff --git a/java/jni/ultrahdr-jni.cpp b/java/jni/ultrahdr-jni.cpp index c542a37c..64db9af1 100644 --- a/java/jni/ultrahdr-jni.cpp +++ b/java/jni/ultrahdr-jni.cpp @@ -333,19 +333,6 @@ Java_com_google_media_codecs_ultrahdr_UltraHDREncoder_setMinMaxContentBoostNativ : "uhdr_enc_set_min_max_content_boost() returned with error") } -extern "C" JNIEXPORT void JNICALL -Java_com_google_media_codecs_ultrahdr_UltraHDREncoder_setMasteringDisplayPeakBrightnessNative( - JNIEnv *env, jobject thiz, jfloat nits) { - GET_HANDLE() - RET_IF_TRUE(handle == 0, "java/io/IOException", "invalid encoder instance") - auto status = - uhdr_enc_set_mastering_display_peak_brightness((uhdr_codec_private_t *)handle, nits); - RET_IF_TRUE(status.error_code != UHDR_CODEC_OK, "java/io/IOException", - status.has_detail - ? status.detail - : "uhdr_enc_set_mastering_display_peak_brightness() returned with error") -} - extern "C" JNIEXPORT void JNICALL Java_com_google_media_codecs_ultrahdr_UltraHDREncoder_setTargetDisplayPeakBrightnessNative( JNIEnv *env, jobject thiz, jfloat nits) { diff --git a/lib/include/ultrahdr/gainmapmath.h b/lib/include/ultrahdr/gainmapmath.h index 53c4dda3..ca6bf6e2 100644 --- a/lib/include/ultrahdr/gainmapmath.h +++ b/lib/include/ultrahdr/gainmapmath.h @@ -53,6 +53,8 @@ static const float kHlgMaxNits = 1000.0f; // pq peak white. 58% of pq peak white maps to reference diffuse white static const float kPqMaxNits = 10000.0f; +float getReferenceDisplayPeakLuminanceInNits(uhdr_color_transfer_t transfer); + // Image pixel descriptor struct Color { union { diff --git a/lib/include/ultrahdr/jpegr.h b/lib/include/ultrahdr/jpegr.h index a1f067c4..a899da60 100644 --- a/lib/include/ultrahdr/jpegr.h +++ b/lib/include/ultrahdr/jpegr.h @@ -89,8 +89,7 @@ class JpegR { bool useMultiChannelGainMap = kUseMultiChannelGainMapAndroidDefault, float gamma = kGainMapGammaDefault, uhdr_enc_preset_t preset = kEncSpeedPresetAndroidDefault, float minContentBoost = FLT_MIN, - float maxContentBoost = FLT_MAX, float masteringDispPeakBrightness = -1.0f, - float targetDispPeakBrightness = -1.0f); + float maxContentBoost = FLT_MAX, float targetDispPeakBrightness = -1.0f); /*!\brief Encode API-0. * @@ -560,22 +559,6 @@ class JpegR { uhdr_error_info_t convertYuv(uhdr_raw_image_t* image, uhdr_color_gamut_t src_encoding, uhdr_color_gamut_t dst_encoding); - /*!\brief Get mastering display peak brightness in nits - * - * \param[in] transfer intent's color transfer characteristics - * - * \return max display brightness in nits - */ - float getMasteringDisplayMaxLuminance(uhdr_color_transfer_t transfer); - - /*!\brief Get brightness corresponding to maximum code value - * - * \param[in] transfer intent's color transfer characteristics - * - * \return brightness corresponding to 1.0 - */ - float getLuminanceForMaxCodeValue(uhdr_color_transfer_t transfer); - /* * This method will check the validity of the input arguments. * @@ -614,16 +597,15 @@ class JpegR { int quality); // Configurations - void* mUhdrGLESCtxt; // opengl es context - size_t mMapDimensionScaleFactor; // gain map scale factor - int mMapCompressQuality; // gain map quality factor - bool mUseMultiChannelGainMap; // enable multichannel gain map - float mGamma; // gain map gamma parameter - uhdr_enc_preset_t mEncPreset; // encoding speed preset - float mMinContentBoost; // min content boost recommendation - float mMaxContentBoost; // max content boost recommendation - float mMasteringDispPeakBrightness; // mastering display max luminance in nits - float mTargetDispPeakBrightness; // target display max luminance in nits + void* mUhdrGLESCtxt; // opengl es context + size_t mMapDimensionScaleFactor; // gain map scale factor + int mMapCompressQuality; // gain map quality factor + bool mUseMultiChannelGainMap; // enable multichannel gain map + float mGamma; // gain map gamma parameter + uhdr_enc_preset_t mEncPreset; // encoding speed preset + float mMinContentBoost; // min content boost recommendation + float mMaxContentBoost; // max content boost recommendation + float mTargetDispPeakBrightness; // target display max luminance in nits }; struct GlobalTonemapOutputs { diff --git a/lib/include/ultrahdr/ultrahdr.h b/lib/include/ultrahdr/ultrahdr.h index 2bd016c7..941850f5 100644 --- a/lib/include/ultrahdr/ultrahdr.h +++ b/lib/include/ultrahdr/ultrahdr.h @@ -48,8 +48,7 @@ typedef enum { ERROR_JPEGR_INVALID_CROPPING_PARAMETERS = JPEGR_IO_ERROR_BASE - 11, ERROR_JPEGR_INVALID_GAMMA = JPEGR_IO_ERROR_BASE - 12, ERROR_JPEGR_INVALID_ENC_PRESET = JPEGR_IO_ERROR_BASE - 13, - ERROR_JPEGR_INVALID_MASTER_DISP_PEAK_BRIGHTNESS = JPEGR_IO_ERROR_BASE - 14, - ERROR_JPEGR_INVALID_TARGET_DISP_PEAK_BRIGHTNESS = JPEGR_IO_ERROR_BASE - 15, + ERROR_JPEGR_INVALID_TARGET_DISP_PEAK_BRIGHTNESS = JPEGR_IO_ERROR_BASE - 14, JPEGR_RUNTIME_ERROR_BASE = -20000, ERROR_JPEGR_ENCODE_ERROR = JPEGR_RUNTIME_ERROR_BASE - 1, diff --git a/lib/include/ultrahdr/ultrahdrcommon.h b/lib/include/ultrahdr/ultrahdrcommon.h index 6180439c..1c146053 100644 --- a/lib/include/ultrahdr/ultrahdrcommon.h +++ b/lib/include/ultrahdr/ultrahdrcommon.h @@ -375,7 +375,6 @@ struct uhdr_encoder_private : uhdr_codec_private { uhdr_enc_preset_t m_enc_preset; float m_min_content_boost; float m_max_content_boost; - float m_mastering_disp_max_brightness; float m_target_disp_max_brightness; // internal data diff --git a/lib/src/gainmapmath.cpp b/lib/src/gainmapmath.cpp index ccc21a6f..25e7ffd5 100644 --- a/lib/src/gainmapmath.cpp +++ b/lib/src/gainmapmath.cpp @@ -20,6 +20,25 @@ namespace ultrahdr { +//////////////////////////////////////////////////////////////////////////////// +// Framework + +float getReferenceDisplayPeakLuminanceInNits(uhdr_color_transfer_t transfer) { + switch (transfer) { + case UHDR_CT_LINEAR: + return kPqMaxNits; + case UHDR_CT_HLG: + return kHlgMaxNits; + case UHDR_CT_PQ: + return kPqMaxNits; + case UHDR_CT_SRGB: + return kSdrWhiteNits; + case UHDR_CT_UNSPECIFIED: + return -1.0f; + } + return -1.0f; +} + //////////////////////////////////////////////////////////////////////////////// // Use Shepard's method for inverse distance weighting. diff --git a/lib/src/jpegr.cpp b/lib/src/jpegr.cpp index a868e035..bf4f3d82 100644 --- a/lib/src/jpegr.cpp +++ b/lib/src/jpegr.cpp @@ -147,8 +147,7 @@ int GetCPUCoreCount() { JpegR::JpegR(void* uhdrGLESCtxt, size_t mapDimensionScaleFactor, int mapCompressQuality, bool useMultiChannelGainMap, float gamma, uhdr_enc_preset_t preset, - float minContentBoost, float maxContentBoost, float masteringDispPeakBrightness, - float targetDispPeakBrightness) { + float minContentBoost, float maxContentBoost, float targetDispPeakBrightness) { mUhdrGLESCtxt = uhdrGLESCtxt; mMapDimensionScaleFactor = mapDimensionScaleFactor; mMapCompressQuality = mapCompressQuality; @@ -157,7 +156,6 @@ JpegR::JpegR(void* uhdrGLESCtxt, size_t mapDimensionScaleFactor, int mapCompress mEncPreset = preset; mMinContentBoost = minContentBoost; mMaxContentBoost = maxContentBoost; - mMasteringDispPeakBrightness = masteringDispPeakBrightness; mTargetDispPeakBrightness = targetDispPeakBrightness; } @@ -501,34 +499,6 @@ uhdr_error_info_t JpegR::convertYuv(uhdr_raw_image_t* image, uhdr_color_gamut_t return status; } -float JpegR::getMasteringDisplayMaxLuminance(uhdr_color_transfer_t transfer) { - switch (transfer) { - case UHDR_CT_LINEAR: - return mMasteringDispPeakBrightness; - case UHDR_CT_HLG: - return mMasteringDispPeakBrightness != -1.0f ? mMasteringDispPeakBrightness : kHlgMaxNits; - case UHDR_CT_PQ: - return mMasteringDispPeakBrightness != -1.0f ? mMasteringDispPeakBrightness : kPqMaxNits; - case UHDR_CT_SRGB: - return kSdrWhiteNits; - case UHDR_CT_UNSPECIFIED: - return -1.0f; - } - return -1.0f; -} - -float JpegR::getLuminanceForMaxCodeValue(uhdr_color_transfer_t transfer) { - switch (transfer) { - case UHDR_CT_PQ: - // In PQ, the maximum code value(1.0) always corresponds to 10000 nits, regardless of the - // mastering display's capabilities. - return kPqMaxNits; - default: - return getMasteringDisplayMaxLuminance(transfer); - } - return -1.0f; -} - uhdr_error_info_t JpegR::compressGainMap(uhdr_raw_image_t* gainmap_img, JpegEncoderHelper* jpeg_enc_obj) { return jpeg_enc_obj->compressImage(gainmap_img, mMapCompressQuality, nullptr, 0); @@ -586,14 +556,14 @@ uhdr_error_info_t JpegR::generateGainMap(uhdr_raw_image_t* sdr_intent, uhdr_raw_ return status; } - float hdr_white_nits = getLuminanceForMaxCodeValue(hdr_intent->ct); + float hdr_white_nits = getReferenceDisplayPeakLuminanceInNits(hdr_intent->ct); if (hdr_white_nits == -1.0f) { status.error_code = UHDR_CODEC_UNSUPPORTED_FEATURE; status.has_detail = 1; snprintf(status.detail, sizeof status.detail, - "maximum code value 1.0 of hdr intent with color transfer %d is mapped to a luminance " - "nits of %f, bad", - hdr_intent->ct, hdr_white_nits); + "received invalid peak brightness %f nits for hdr reference display with color " + "transfer %d ", + hdr_white_nits, hdr_intent->ct); return status; } @@ -693,8 +663,7 @@ uhdr_error_info_t JpegR::generateGainMap(uhdr_raw_image_t* sdr_intent, uhdr_raw_ if (this->mTargetDispPeakBrightness != -1.0f) { gainmap_metadata->hdr_capacity_max = this->mTargetDispPeakBrightness / kSdrWhiteNits; } else { - gainmap_metadata->hdr_capacity_max = - this->getMasteringDisplayMaxLuminance(hdr_intent->ct) / kSdrWhiteNits; + gainmap_metadata->hdr_capacity_max = hdr_white_nits / kSdrWhiteNits; } float log2MinBoost = log2(gainmap_metadata->min_content_boost); @@ -977,8 +946,7 @@ uhdr_error_info_t JpegR::generateGainMap(uhdr_raw_image_t* sdr_intent, uhdr_raw_ if (this->mTargetDispPeakBrightness != -1.0f) { gainmap_metadata->hdr_capacity_max = this->mTargetDispPeakBrightness / kSdrWhiteNits; } else { - gainmap_metadata->hdr_capacity_max = - this->getMasteringDisplayMaxLuminance(hdr_intent->ct) / kSdrWhiteNits; + gainmap_metadata->hdr_capacity_max = hdr_white_nits / kSdrWhiteNits; } }; @@ -1831,15 +1799,15 @@ uhdr_error_info_t JpegR::toneMap(uhdr_raw_image_t* hdr_intent, uhdr_raw_image_t* return status; } - float hdr_white_nits = getLuminanceForMaxCodeValue(hdr_intent->ct); + float hdr_white_nits = getReferenceDisplayPeakLuminanceInNits(hdr_intent->ct); if (hdr_white_nits == -1.0f) { uhdr_error_info_t status; status.error_code = UHDR_CODEC_UNSUPPORTED_FEATURE; status.has_detail = 1; snprintf(status.detail, sizeof status.detail, - "maximum code value 1.0 of hdr intent with color transfer %d is mapped to a luminance " - "nits of %f, bad", - hdr_intent->ct, hdr_white_nits); + "received invalid peak brightness %f nits for hdr reference display with color " + "transfer %d ", + hdr_white_nits, hdr_intent->ct); return status; } @@ -2042,18 +2010,10 @@ status_t JpegR::areInputArgumentsValid(jr_uncompressed_ptr p010_image_ptr, mMaxContentBoost, mMinContentBoost); return ERROR_JPEGR_INVALID_DISPLAY_BOOST; } - if (mMasteringDispPeakBrightness != -1.0f && - (!std::isfinite(mMasteringDispPeakBrightness) || - mMasteringDispPeakBrightness < ultrahdr::kSdrWhiteNits || - mMasteringDispPeakBrightness > ultrahdr::kPqMaxNits)) { - ALOGE( - "unexpected mastering display peak brightness nits %f, expects to be with in range [%f %f]", - mMasteringDispPeakBrightness, ultrahdr::kSdrWhiteNits, ultrahdr::kPqMaxNits); - return ERROR_JPEGR_INVALID_MASTER_DISP_PEAK_BRIGHTNESS; - } - if (mTargetDispPeakBrightness != -1.0f && (!std::isfinite(mTargetDispPeakBrightness) || - mTargetDispPeakBrightness < ultrahdr::kSdrWhiteNits || - mTargetDispPeakBrightness > ultrahdr::kPqMaxNits)) { + if ((!std::isfinite(mTargetDispPeakBrightness) || + mTargetDispPeakBrightness < ultrahdr::kSdrWhiteNits || + mTargetDispPeakBrightness > ultrahdr::kPqMaxNits) && + mTargetDispPeakBrightness != -1.0f) { ALOGE("unexpected target display peak brightness nits %f, expects to be with in range [%f %f]", mTargetDispPeakBrightness, ultrahdr::kSdrWhiteNits, ultrahdr::kPqMaxNits); return ERROR_JPEGR_INVALID_TARGET_DISP_PEAK_BRIGHTNESS; diff --git a/lib/src/ultrahdr_api.cpp b/lib/src/ultrahdr_api.cpp index 8ec40b51..f05718ec 100644 --- a/lib/src/ultrahdr_api.cpp +++ b/lib/src/ultrahdr_api.cpp @@ -772,42 +772,6 @@ uhdr_error_info_t uhdr_enc_set_min_max_content_boost(uhdr_codec_private_t* enc, return status; } -uhdr_error_info_t uhdr_enc_set_mastering_display_peak_brightness(uhdr_codec_private_t* enc, - float nits) { - uhdr_error_info_t status = g_no_error; - - if (dynamic_cast(enc) == nullptr) { - status.error_code = UHDR_CODEC_INVALID_PARAM; - status.has_detail = 1; - snprintf(status.detail, sizeof status.detail, "received nullptr for uhdr codec instance"); - return status; - } - - if (!std::isfinite(nits) || nits < ultrahdr::kSdrWhiteNits || nits > ultrahdr::kPqMaxNits) { - status.error_code = UHDR_CODEC_INVALID_PARAM; - status.has_detail = 1; - snprintf(status.detail, sizeof status.detail, - "unexpected mastering display peak brightness nits %f, expects to be with in range " - "[%f, %f]", - nits, ultrahdr::kSdrWhiteNits, ultrahdr::kPqMaxNits); - } - - uhdr_encoder_private* handle = dynamic_cast(enc); - - if (handle->m_sailed) { - status.error_code = UHDR_CODEC_INVALID_OPERATION; - status.has_detail = 1; - snprintf(status.detail, sizeof status.detail, - "An earlier call to uhdr_encode() has switched the context from configurable state to " - "end state. The context is no longer configurable. To reuse, call reset()"); - return status; - } - - handle->m_mastering_disp_max_brightness = nits; - - return status; -} - uhdr_error_info_t uhdr_enc_set_target_display_peak_brightness(uhdr_codec_private_t* enc, float nits) { uhdr_error_info_t status = g_no_error; @@ -1262,11 +1226,11 @@ uhdr_error_info_t uhdr_encode(uhdr_codec_private_t* enc) { exif.capacity = exif.data_sz = handle->m_exif.size(); } - ultrahdr::JpegR jpegr( - nullptr, handle->m_gainmap_scale_factor, handle->m_quality.find(UHDR_GAIN_MAP_IMG)->second, - handle->m_use_multi_channel_gainmap, handle->m_gamma, handle->m_enc_preset, - handle->m_min_content_boost, handle->m_max_content_boost, - handle->m_mastering_disp_max_brightness, handle->m_target_disp_max_brightness); + ultrahdr::JpegR jpegr(nullptr, handle->m_gainmap_scale_factor, + handle->m_quality.find(UHDR_GAIN_MAP_IMG)->second, + handle->m_use_multi_channel_gainmap, handle->m_gamma, + handle->m_enc_preset, handle->m_min_content_boost, + handle->m_max_content_boost, handle->m_target_disp_max_brightness); if (handle->m_compressed_images.find(UHDR_BASE_IMG) != handle->m_compressed_images.end() && handle->m_compressed_images.find(UHDR_GAIN_MAP_IMG) != handle->m_compressed_images.end()) { auto& base_entry = handle->m_compressed_images.find(UHDR_BASE_IMG)->second; @@ -1369,7 +1333,6 @@ void uhdr_reset_encoder(uhdr_codec_private_t* enc) { handle->m_enc_preset = ultrahdr::kEncSpeedPresetDefault; handle->m_min_content_boost = FLT_MIN; handle->m_max_content_boost = FLT_MAX; - handle->m_mastering_disp_max_brightness = -1.0f; handle->m_target_disp_max_brightness = -1.0f; handle->m_compressed_output_buffer.reset(); diff --git a/ultrahdr_api.h b/ultrahdr_api.h index c4987e04..b715602e 100644 --- a/ultrahdr_api.h +++ b/ultrahdr_api.h @@ -386,24 +386,6 @@ UHDR_EXTERN uhdr_error_info_t uhdr_enc_set_quality(uhdr_codec_private_t* enc, in UHDR_EXTERN uhdr_error_info_t uhdr_enc_set_exif_data(uhdr_codec_private_t* enc, uhdr_mem_block_t* exif); -/*!\brief Set peak brightness of the reference display used during content mastering. For - * #UHDR_CT_HLG, #UHDR_CT_LINEAR inputs, this corresponds to the brightness level of the maximum - * code value 1.0. - * - * For #UHDR_CT_HLG, default mastering display peak luminance is 1000 nits. For #UHDR_CT_LINEAR - * content, there is no default value, needs to be configured, otherwise, error is thrown during - * encoding. For #UHDR_CT_PQ content, default mastering display peak luminance is 10000 nits. - * - * \param[in] enc encoder instance. - * \param[in] nits mastering display peak brightness in nits. Any positive real number in range - * [203, 10000]. - * - * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, - * #UHDR_CODEC_INVALID_PARAM otherwise. - */ -UHDR_EXTERN uhdr_error_info_t -uhdr_enc_set_mastering_display_peak_brightness(uhdr_codec_private_t* enc, float nits); - /*!\brief Enable/Disable multi-channel gainmap. By default multi-channel gainmap is enabled. * * \param[in] enc encoder instance. @@ -459,9 +441,11 @@ UHDR_EXTERN uhdr_error_info_t uhdr_enc_set_gainmap_gamma(uhdr_codec_private_t* e UHDR_EXTERN uhdr_error_info_t uhdr_enc_set_min_max_content_boost(uhdr_codec_private_t* enc, float min_boost, float max_boost); -/*!\brief Set target display peak brightness in nits. This value determines the weight by which - * the gain map coefficients are scaled during decode. If this is not configured, then mastering - * display peak brightness setting is used. +/*!\brief Set target display peak brightness in nits. This is used for configuring #hdr_capacity_max + * of gainmap metadata. This value determines the weight by which the gain map coefficients are + * scaled during decode. If this is not configured, then default peak luminance of HDR intent's + * color transfer under test is used. For #UHDR_CT_HLG, this corresponds to 1000 nits and for + * #UHDR_CT_LINEAR and #UHDR_CT_PQ, this corresponds to 10000 nits. * * \param[in] enc encoder instance. * \param[in] nits target display peak brightness in nits. Any positive real number in range @@ -514,8 +498,6 @@ UHDR_EXTERN uhdr_error_info_t uhdr_enc_set_output_format(uhdr_codec_private_t* e * - uhdr_enc_set_quality() * - If the application wants to insert exif data * - uhdr_enc_set_exif_data() - * - If the application wants to set reference display peak brightness - * - uhdr_enc_set_mastering_display_peak_brightness() * - If the application wants to set gainmap scale factor * - uhdr_enc_set_gainmap_scale_factor() * - If the application wants to enable multi channel gain map @@ -567,7 +549,6 @@ UHDR_EXTERN uhdr_error_info_t uhdr_enc_set_output_format(uhdr_codec_private_t* e * - uhdr_enc_set_quality() // optional * - uhdr_enc_set_exif_data() // optional * - uhdr_enc_set_output_format() // optional - * - uhdr_enc_set_mastering_display_peak_brightness() // optional * - uhdr_enc_set_gainmap_scale_factor() // optional * - uhdr_enc_set_using_multi_channel_gainmap() // optional * - uhdr_enc_set_gainmap_gamma() // optional