Skip to content

Commit

Permalink
revert e432c4d partially
Browse files Browse the repository at this point in the history
upon discussions, it was indicated that some of the apis that were
introduced in the commit e432c4d are not required. Leaving this behind
can misguide users in their configurations. Best course of action is to
remove them and introduce in the future if necessary.

also, minor fixes in error checking and documentation

Test: ./ultrahdr_unit_test
  • Loading branch information
ram-mohan authored and DichenZhang1 committed Oct 30, 2024
1 parent a034ec5 commit 6b85f33
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 248 deletions.
2 changes: 1 addition & 1 deletion docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). <ul><li> If `BUILD_SHARED_LIBS` is **OFF**, in the linking phase, static versions of dependencies are chosen. However, the executable targets are not purely static because the system libraries used are still dynamic. </li></ul> |
| `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. <ul><li> Benchmark tests are not supported on Windows and this parameter is forced to **OFF** internally while building on **WIN32** platforms. </li></ul>|
| `UHDR_BUILD_FUZZERS` | OFF | Build Fuzz Test Applications. Mostly for Devs. <ul><li> Fuzz applications are built by instrumenting the entire software suite. This includes dependency libraries. This is done by forcing `UHDR_BUILD_DEPS` to **ON** internally. </li></ul> |
Expand Down
38 changes: 10 additions & 28 deletions examples/ultrahdr_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -286,7 +285,6 @@ class UltraHdrAppInput {
mEncPreset(encPreset),
mMinContentBoost(minContentBoost),
mMaxContentBoost(maxContentBoost),
mMasteringDispPeakBrightness(masteringDispPeakBrightness),
mTargetDispPeakBrightness(targetDispPeakBrightness),
mMode(0){};

Expand Down Expand Up @@ -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){};

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
23 changes: 3 additions & 20 deletions java/UltraHdrApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -112,7 +110,6 @@ public UltraHdrApp(String hdrIntentRawFile, String sdrIntentRawFile,
mEncPreset = encPreset;
mMinContentBoost = minContentBoost;
mMaxContentBoost = maxContentBoost;
mMasteringDispPeakBrightness = masteringDispPeakBrightness;
mTargetDispPeakBrightness = targetDispPeakBrightness;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 :");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
33 changes: 7 additions & 26 deletions java/com/google/media/codecs/ultrahdr/UltraHDREncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* 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]
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions java/jni/com_google_media_codecs_ultrahdr_UltraHDREncoder.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions java/jni/ultrahdr-jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions lib/include/ultrahdr/gainmapmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 6b85f33

Please sign in to comment.