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).
- * 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