@@ -91,6 +91,7 @@ int getopt_s(int argc, char* const argv[], char* ostr) {
9191 }
9292 if (oindex[1 ] != ' :' ) {
9393 optarg_s = nullptr ;
94+ ++optind_s;
9495 return optopt_s;
9596 }
9697
@@ -304,11 +305,13 @@ class UltraHdrAppInput {
304305 mMinContentBoost(minContentBoost),
305306 mMaxContentBoost(maxContentBoost),
306307 mTargetDispPeakBrightness(targetDispPeakBrightness),
308+ mProbe(false ),
307309 mMode(0 ){};
308310
309311 UltraHdrAppInput (const char * gainmapMetadataCfgFile, const char * uhdrFile, const char * outputFile,
310312 uhdr_color_transfer_t oTf = UHDR_CT_HLG ,
311- uhdr_img_fmt_t oFmt = UHDR_IMG_FMT_32bppRGBA1010102, bool enableGLES = false )
313+ uhdr_img_fmt_t oFmt = UHDR_IMG_FMT_32bppRGBA1010102, bool enableGLES = false ,
314+ bool probe = false )
312315 : mHdrIntentRawFile(nullptr ),
313316 mSdrIntentRawFile(nullptr ),
314317 mSdrIntentCompressedFile(nullptr ),
@@ -337,6 +340,7 @@ class UltraHdrAppInput {
337340 mMinContentBoost(FLT_MIN ),
338341 mMaxContentBoost(FLT_MAX ),
339342 mTargetDispPeakBrightness(-1 .0f ),
343+ mProbe(probe),
340344 mMode(1 ){};
341345
342346 ~UltraHdrAppInput () {
@@ -387,7 +391,7 @@ class UltraHdrAppInput {
387391 bool fillGainMapCompressedImageHandle ();
388392 bool fillGainMapMetadataDescriptor ();
389393 bool fillExifMemoryBlock ();
390- bool writeGainMapMetadataToFile (uhdr_gainmap_metadata_t * metadata);
394+ void writeGainMapMetadataToFile (uhdr_gainmap_metadata_t * metadata, std::ostream& file );
391395 bool convertRgba8888ToYUV444Image ();
392396 bool convertRgba1010102ToYUV444Image ();
393397 bool encode ();
@@ -425,6 +429,7 @@ class UltraHdrAppInput {
425429 const float mMinContentBoost ;
426430 const float mMaxContentBoost ;
427431 const float mTargetDispPeakBrightness ;
432+ const bool mProbe ;
428433 const int mMode ;
429434
430435 uhdr_raw_image_t mRawP010Image {};
@@ -615,11 +620,8 @@ bool UltraHdrAppInput::fillExifMemoryBlock() {
615620 return false ;
616621}
617622
618- bool UltraHdrAppInput::writeGainMapMetadataToFile (uhdr_gainmap_metadata_t * metadata) {
619- std::ofstream file (mGainMapMetadataCfgFile );
620- if (!file.is_open ()) {
621- return false ;
622- }
623+ void UltraHdrAppInput::writeGainMapMetadataToFile (uhdr_gainmap_metadata_t * metadata,
624+ std::ostream& file) {
623625 bool allChannelsIdentical = metadata->max_content_boost [0 ] == metadata->max_content_boost [1 ] &&
624626 metadata->max_content_boost [0 ] == metadata->max_content_boost [2 ] &&
625627 metadata->min_content_boost [0 ] == metadata->min_content_boost [1 ] &&
@@ -651,8 +653,6 @@ bool UltraHdrAppInput::writeGainMapMetadataToFile(uhdr_gainmap_metadata_t* metad
651653 file << " --hdrCapacityMin " << metadata->hdr_capacity_min << std::endl;
652654 file << " --hdrCapacityMax " << metadata->hdr_capacity_max << std::endl;
653655 file << " --useBaseColorSpace " << metadata->use_base_cg << std::endl;
654- file.close ();
655- return true ;
656656}
657657
658658bool UltraHdrAppInput::fillUhdrImageHandle () {
@@ -841,11 +841,20 @@ bool UltraHdrAppInput::decode() {
841841 RET_IF_ERR (uhdr_enable_gpu_acceleration (handle, mEnableGLES ))
842842 }
843843 RET_IF_ERR (uhdr_dec_probe (handle))
844- if (mGainMapMetadataCfgFile != nullptr ) {
844+ if (mGainMapMetadataCfgFile != nullptr || mProbe ) {
845845 uhdr_gainmap_metadata_t * metadata = uhdr_dec_get_gainmap_metadata (handle);
846- if (!writeGainMapMetadataToFile (metadata)) {
847- std::cerr << " failed to write gainmap metadata to file: " << mGainMapMetadataCfgFile
848- << std::endl;
846+ if (mProbe ) {
847+ std::cout << " Ultra HDR Image: Yes \n GainMap Metadata: " << std::endl;
848+ writeGainMapMetadataToFile (metadata, std::cout);
849+ uhdr_release_decoder (handle);
850+ return true ;
851+ }
852+ std::ofstream file (mGainMapMetadataCfgFile );
853+ if (file.is_open ()) {
854+ writeGainMapMetadataToFile (metadata, file);
855+ file.close ();
856+ } else {
857+ std::cerr << " failed to open gainmap metadata file: " << mGainMapMetadataCfgFile << std::endl;
849858 }
850859 }
851860
@@ -1484,6 +1493,11 @@ static void usage(const char* name) {
14841493 fprintf (stderr, " -x binary input resource containing exif data to insert, optional. \n " );
14851494 fprintf (stderr, " \n ## decoder options : \n " );
14861495 fprintf (stderr, " -j ultra hdr compressed input resource, required. \n " );
1496+ fprintf (stderr,
1497+ " -P Probe mode. Probes input uhdr resource for gainmap metadata. \n "
1498+ " For valid uhdr images, gainmap metadata is displayed. no options required. \n "
1499+ " For invalid uhdr images, error is indicated. no options required. \n "
1500+ " No options required. \n " );
14871501 fprintf (
14881502 stderr,
14891503 " -o output transfer function, optional. [0:linear, 1:hlg (default), 2:pq, 3:srgb] \n " );
@@ -1568,7 +1582,7 @@ static void usage(const char* name) {
15681582}
15691583
15701584int main (int argc, char * argv[]) {
1571- 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:" ;
1585+ 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:P " ;
15721586 char *hdr_intent_raw_file = nullptr , *sdr_intent_raw_file = nullptr , *uhdr_file = nullptr ,
15731587 *sdr_intent_compressed_file = nullptr , *gainmap_compressed_file = nullptr ,
15741588 *gainmap_metadata_cfg_file = nullptr , *output_file = nullptr , *exif_file = nullptr ;
@@ -1593,6 +1607,7 @@ int main(int argc, char* argv[]) {
15931607 float min_content_boost = FLT_MIN ;
15941608 float max_content_boost = FLT_MAX ;
15951609 float target_disp_peak_brightness = -1 .0f ;
1610+ bool probe = false ;
15961611 int ch;
15971612 while ((ch = getopt_s (argc, argv, opt_string)) != -1 ) {
15981613 switch (ch) {
@@ -1690,6 +1705,9 @@ int main(int argc, char* argv[]) {
16901705 case ' L' :
16911706 target_disp_peak_brightness = (float )atof (optarg_s);
16921707 break ;
1708+ case ' P' :
1709+ probe = true ;
1710+ break ;
16931711 default :
16941712 usage (argv[0 ]);
16951713 return -1 ;
@@ -1751,8 +1769,8 @@ int main(int argc, char* argv[]) {
17511769 return -1 ;
17521770 }
17531771 UltraHdrAppInput appInput (gainmap_metadata_cfg_file, uhdr_file,
1754- output_file ? output_file : " outrgb.raw" , out_tf, out_cf,
1755- enable_gles );
1772+ output_file ? output_file : " outrgb.raw" , out_tf, out_cf, enable_gles,
1773+ probe );
17561774 if (!appInput.decode ()) return -1 ;
17571775 } else {
17581776 if (argc > 1 ) std::cerr << " did not receive valid mode of operation " << mode << std::endl;
0 commit comments