From 2f1e9f7d3b5cdd5319c31111daa7e56c6df43c0a Mon Sep 17 00:00:00 2001 From: jhurst Date: Thu, 25 May 2017 00:16:56 +0000 Subject: [PATCH] o Added options -c -n, -q to as-02-wrap (IMF "color system") o Fixed a bug in the MXF reader that caused an assert when reading a partial (i.e.truncated) input file --- configure.ac | 2 +- src/MDD.cpp | 8 ++++ src/MDD.h | 3 +- src/MXF.cpp | 9 +++- src/as-02-wrap.cpp | 113 +++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 122 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 5d795f9..fa3aadb 100644 --- a/configure.ac +++ b/configure.ac @@ -37,7 +37,7 @@ AC_PREREQ([2.59]) # For example, if asdcplib version 1.0.0 were modified to accomodate changes # in file format, and if no changes were made to AS_DCP.h, the new version would be # 1.0.1. If changes were also required in AS_DCP.h, the new version would be 1.1.1. -AC_INIT([asdcplib], [2.7.20], [asdcplib@cinecert.com]) +AC_INIT([asdcplib], [2.7.22], [asdcplib@cinecert.com]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_SRCDIR([src/KM_error.h]) diff --git a/src/MDD.cpp b/src/MDD.cpp index 5a96592..1b4984f 100644 --- a/src/MDD.cpp +++ b/src/MDD.cpp @@ -1453,6 +1453,14 @@ static const ASDCP::MDDEntry s_MDD_Table[] = { 0x0e, 0x09, 0x06, 0x07, 0x01, 0x01, 0x13, 0x00 }, {0}, false, "PIMFDynamicMetadataDescriptor_GlobalPayloadSID" }, + // back to regularly defined UL values + { { 0x06, 0x0e, 0x2b, 0x34, 0x04, 0x01, 0x01, 0x06, // 468 + 0x04, 0x01, 0x01, 0x01, 0x03, 0x02, 0x00, 0x00 }, + {0}, false, "ColorPrimaries_ITU470_PAL" }, + { { 0x06, 0x0e, 0x2b, 0x34, 0x04, 0x01, 0x01, 0x06, // 469 + 0x04, 0x01, 0x01, 0x01, 0x03, 0x01, 0x00, 0x00 }, + {0}, false, "ColorPrimaries_SMPTE170M" }, + { {0}, {0}, false, 0 } }; diff --git a/src/MDD.h b/src/MDD.h index 2f5f4f0..06fc968 100755 --- a/src/MDD.h +++ b/src/MDD.h @@ -503,7 +503,8 @@ namespace ASDCP { MDD_PIMFDynamicMetadataEssence, // 465 MDD_PIMFDynamicMetadataDescriptor, // 466 MDD_PIMFDynamicMetadataDescriptor_GlobalPayloadSID, // 467 - + MDD_ColorPrimaries_ITU470_PAL, // 468 + MDD_ColorPrimaries_SMPTE170M, // 469 MDD_Max }; // enum MDD_t diff --git a/src/MXF.cpp b/src/MXF.cpp index 45b0298..cd7dfb1 100755 --- a/src/MXF.cpp +++ b/src/MXF.cpp @@ -713,7 +713,12 @@ ASDCP::MXF::OP1aHeader::InitFromFile(const Kumu::FileReader& Reader) } // slurp up the remainder of the header - if ( HeaderByteCount < 1024 ) + if ( HeaderByteCount == 0 ) + { + DefaultLogSink().Warn("MXF file contents incomplete.\n"); + return RESULT_KLV_CODING(__LINE__, __FILE__); + } + else if ( HeaderByteCount < 1024 ) { DefaultLogSink().Warn("Improbably small HeaderByteCount value: %qu\n", HeaderByteCount); } @@ -731,7 +736,7 @@ ASDCP::MXF::OP1aHeader::InitFromFile(const Kumu::FileReader& Reader) if ( ASDCP_FAILURE(result) ) { - DefaultLogSink().Error("OP1aHeader::InitFromFile, Read failed\n"); + DefaultLogSink().Error("OP1aHeader::InitFromFile, read failed.\n"); return result; } diff --git a/src/as-02-wrap.cpp b/src/as-02-wrap.cpp index 8f5507d..8a32d71 100755 --- a/src/as-02-wrap.cpp +++ b/src/as-02-wrap.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2011-2016, Robert Scheler, Heiko Sparenberg Fraunhofer IIS, +Copyright (c) 2011-2017, Robert Scheler, Heiko Sparenberg Fraunhofer IIS, John Hurst All rights reserved. @@ -105,7 +105,7 @@ banner(FILE* stream = stdout) { fprintf(stream, "\n\ %s (asdcplib %s)\n\n\ -Copyright (c) 2011-2016, Robert Scheler, Heiko Sparenberg Fraunhofer IIS, John Hurst\n\n\ +Copyright (c) 2011-2017, Robert Scheler, Heiko Sparenberg Fraunhofer IIS, John Hurst\n\n\ asdcplib may be copied only under the terms of the license found at\n\ the top of every file in the asdcplib distribution kit.\n\n\ Specify the -h (help) option for further information about %s\n\n", @@ -130,6 +130,10 @@ Options:\n\ -A / - Set aspect ratio for image (default 4/3)\n\ -b - Specify size in bytes of picture frame buffer\n\ Defaults to 4,194,304 (4MB)\n\ + -c - Select the IMF color system to be signaled:\n\ + Application 2 (2067-20): 1, 2, or 3\n\ + Application 2e (2067-21): 4 or 5\n\ + All color system values assume YCbCr; also use -R for RGB\n\ -C
    - Set ChannelAssignment UL value\n\ -d - Number of frames to process, default all\n\ -D - Component depth for YCbCr images (default: 10)\n\ @@ -145,23 +149,25 @@ Options:\n\ -M - Do not create HMAC values when writing\n\ -m - Write MCA labels using . Example:\n\ 51(L,R,C,LFE,Ls,Rs,),HI,VIN\n\ + -n
      - Set the TransferCharacteristic UL\n\ -o , - Mastering Display luminance, cd*m*m, e.g., \".05,100\"\n\ -O ,,,,,,,\n\ - Mastering Display Color Primaries and white point\n\ e.g., \".64,.33,.3,.6,.15,.06,.3457,.3585\"\n\ -P - Set NamespaceURI property when creating timed text MXF\n\ -p
        - Set broadcast profile\n\ + -q
          - Set the CodingEquations UL\n\ -r / - Edit Rate of the output file. 24/1 is the default\n\ - -R - Indicates RGB image essence (default)\n\ + -R - Indicates RGB image essence (default except with -c)\n\ -s - Duration of a frame-wrapped partition (default 60)\n\ -t - Set RGB component minimum code value (default: 0)\n\ -T - Set RGB component maximum code value (default: 1023)\n\ - -u - Print UL catalog to stderr\n\ + -u - Print UL catalog to stdout\n\ -v - Verbose, prints informative messages to stderr\n\ -W - Read input file only, do not write source file\n\ -x - Horizontal subsampling degree (default: 2)\n\ -X - Vertical subsampling degree (default: 2)\n\ - -Y - Indicates YCbCr image essence (default: RGB), uses\n\ + -Y - Indicates YCbCr image essence (default with -c), uses\n\ default values for White Ref, Black Ref and Color Range,\n\ 940,64,897, indicating 10 bit standard Video Range\n\ -y [,[,]]\n\ @@ -241,10 +247,9 @@ public: bool show_ul_values_flag; /// if true, dump the UL table before going tp work. Kumu::PathList_t filenames; // list of filenames to be processed - UL channel_assignment; + UL channel_assignment, picture_coding, transfer_characteristic, color_primaries, coding_equations; ASDCP::MXF::AS02_MCAConfigParser mca_config; - UL picture_coding; ui32_t rgba_MaxRef; ui32_t rgba_MinRef; @@ -357,6 +362,58 @@ public: return true; } + // + bool set_color_system_from_arg(const char* arg) + { + assert(arg); + + switch ( *arg ) + { + // Application 2 (ST 2067-20) + case '1': + coding_equations = g_dict->ul(MDD_CodingEquations_601); + transfer_characteristic = g_dict->ul(MDD_TransferCharacteristics_709); + color_primaries = g_dict->ul(MDD_ColorPrimaries_ITU470_PAL); + use_cdci_descriptor = true; + break; + + case '2': + coding_equations = g_dict->ul(MDD_CodingEquations_601); + transfer_characteristic = g_dict->ul(MDD_TransferCharacteristics_709); + color_primaries = g_dict->ul(MDD_ColorPrimaries_SMPTE170M); + use_cdci_descriptor = true; + break; + + case '3': + coding_equations = g_dict->ul(MDD_CodingEquations_709); + transfer_characteristic = g_dict->ul(MDD_TransferCharacteristics_709); + color_primaries = g_dict->ul(MDD_ColorPrimaries_BT709); + use_cdci_descriptor = true; + break; + + // Application 2e (ST 2067-21) + case '4': + coding_equations = g_dict->ul(MDD_CodingEquations_709); + transfer_characteristic = g_dict->ul(MDD_TransferCharacteristics_xvYCC); + color_primaries = g_dict->ul(MDD_ColorPrimaries_BT709); + use_cdci_descriptor = true; + break; + + case '5': + coding_equations = g_dict->ul(MDD_CodingEquations_709); + transfer_characteristic = g_dict->ul(MDD_TransferCharacteristics_2020); + color_primaries = g_dict->ul(MDD_ColorPrimaries_BT2020); + use_cdci_descriptor = true; + break; + + default: + fprintf(stderr, "Unrecognized color system number, expecting one of 1-5.\n"); + return false; + } + + return true; + } + CommandOptions(int argc, const char** argv) : error_flag(true), key_flag(false), key_id_flag(false), asset_id_flag(false), encrypt_header_flag(true), write_hmac(true), verbose_flag(false), fb_dump_size(0), @@ -373,6 +430,10 @@ public: memset(key_value, 0, KeyLen); memset(key_id_value, 0, UUIDlen); + coding_equations = g_dict->ul(MDD_CodingEquations_709); + color_primaries = g_dict->ul(MDD_ColorPrimaries_BT709); + transfer_characteristic = g_dict->ul(MDD_TransferCharacteristics_709); + for ( int i = 1; i < argc; i++ ) { @@ -420,6 +481,15 @@ public: fprintf(stderr, "Frame Buffer size: %u bytes.\n", fb_size); break; + + case 'c': + TEST_EXTRA_ARG(i, 'c'); + if ( ! set_color_system_from_arg(argv[i]) ) + { + return; + } + break; + case 'C': TEST_EXTRA_ARG(i, 'C'); if ( ! channel_assignment.DecodeHex(argv[i]) ) @@ -506,8 +576,17 @@ public: } break; + case 'n': + TEST_EXTRA_ARG(i, 'n'); + if ( ! transfer_characteristic.DecodeHex(argv[i]) ) + { + fprintf(stderr, "Error decoding TransferCharacteristic UL value: %s\n", argv[i]); + return; + } + break; + case 'O': - TEST_EXTRA_ARG(i, ')'); + TEST_EXTRA_ARG(i, 'O'); if ( ! set_display_primaries(argv[i]) ) { return; @@ -536,6 +615,15 @@ public: } break; + case 'q': + TEST_EXTRA_ARG(i, 'q'); + if ( ! coding_equations.DecodeHex(argv[i]) ) + { + fprintf(stderr, "Error decoding CodingEquations UL value: %s\n", argv[i]); + return; + } + break; + case 'r': TEST_EXTRA_ARG(i, 'r'); if ( ! DecodeRational(argv[i], edit_rate) ) @@ -587,7 +675,7 @@ public: break; case 'y': - // Use values provded as argument, sharp tool, be careful + // Use values provided as argument, sharp tool, be careful use_cdci_descriptor = true; TEST_EXTRA_ARG(i, 'y'); if ( ! set_video_ref(argv[i]) ) @@ -698,6 +786,9 @@ write_JP2K_file(CommandOptions& Options) if ( ASDCP_SUCCESS(result) ) { + tmp_dscr->CodingEquations = Options.coding_equations; + tmp_dscr->TransferCharacteristic = Options.transfer_characteristic; + tmp_dscr->ColorPrimaries = Options.color_primaries; tmp_dscr->PictureEssenceCoding = Options.picture_coding; tmp_dscr->HorizontalSubsampling = Options.horizontal_subsampling; tmp_dscr->VerticalSubsampling = Options.vertical_subsampling; @@ -736,6 +827,10 @@ write_JP2K_file(CommandOptions& Options) if ( ASDCP_SUCCESS(result) ) { + tmp_dscr->CodingEquations = Options.coding_equations; + tmp_dscr->TransferCharacteristic = Options.transfer_characteristic; + tmp_dscr->ColorPrimaries = Options.color_primaries; + tmp_dscr->ScanningDirection = 0; tmp_dscr->PictureEssenceCoding = Options.picture_coding; tmp_dscr->ComponentMaxRef = Options.rgba_MaxRef; tmp_dscr->ComponentMinRef = Options.rgba_MinRef; -- 2.30.2