Implemented J2K desc to/from MD
[asdcplib.git] / src / MXFTypes.h
index c2121101b36a5b531cac2b06277071fc24f218a1..39f75d5caceb3b01e55086a98a05ac2b7cea9c4c 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2005-2016, John Hurst
+Copyright (c) 2005-2019, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -33,6 +33,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #define _MXFTYPES_H_
 
 #include "KLV.h"
+#include "AS_DCP.h"
 #include <list>
 #include <vector>
 #include <set>
@@ -112,12 +113,12 @@ namespace ASDCP
          bool HasValue() const { return ! this->empty(); }
 
          ui32_t ArchiveLength() const {
-           return ( sizeof(ui32_t) * 2 ) +  ( this->size() * this->ItemSize() );
+           return ( sizeof(ui32_t) * 2 ) +  ( (ui32_t)this->size() * this->ItemSize() );
          }
 
          bool Archive(Kumu::MemIOWriter* Writer) const {
-           if ( ! Writer->WriteUi32BE(this->size()) ) return false;
-           if ( ! Writer->WriteUi32BE(this->ItemSize()) ) return false;
+           if ( ! Writer->WriteUi32BE((ui32_t)this->size()) ) return false;
+           if ( ! Writer->WriteUi32BE((ui32_t)this->ItemSize()) ) return false;
            if ( this->empty() ) return true;
            
            typename ContainerType::const_iterator i;
@@ -277,7 +278,7 @@ namespace ASDCP
 
          const char* EncodeString(char* str_buf, ui32_t buf_len) const;
          inline virtual bool HasValue() const { return ! empty(); }
-         inline virtual ui32_t ArchiveLength() const { return sizeof(ui32_t) + size(); }
+         inline virtual ui32_t ArchiveLength() const { return (ui32_t)(sizeof(ui32_t) + size()); }
          virtual bool Unarchive(Kumu::MemIOReader* Reader);
          virtual bool Archive(Kumu::MemIOWriter* Writer) const;
        };
@@ -296,7 +297,7 @@ namespace ASDCP
 
          const char* EncodeString(char* str_buf, ui32_t buf_len) const;
          inline virtual bool HasValue() const { return ! empty(); }
-         inline virtual ui32_t ArchiveLength() const { return sizeof(ui32_t) + size(); }
+         inline virtual ui32_t ArchiveLength() const { return (ui32_t)(sizeof(ui32_t) + size()); }
          virtual bool Unarchive(Kumu::MemIOReader* Reader);
          virtual bool Archive(Kumu::MemIOWriter* Writer) const;
        };
@@ -359,7 +360,7 @@ namespace ASDCP
          ui32_t First;
          ui32_t Second;
 
-         LineMapPair() {}
+       LineMapPair() : First(0), Second() {}
          ~LineMapPair() {}
 
        LineMapPair(const ui32_t& first, const ui32_t& second) : IArchive() {
@@ -407,6 +408,102 @@ namespace ASDCP
          }
        };
 
+      //
+      class ColorPrimary : public Kumu::IArchive
+       {
+       public:
+         ui16_t X;
+         ui16_t Y;
+
+       ColorPrimary() : X(0), Y(0) {}
+         ~ColorPrimary() {}
+
+         ColorPrimary(const ui16_t& x, const ui16_t& y) : X(x), Y(y) {}
+
+         ColorPrimary(const ColorPrimary& rhs) { Copy(rhs); }
+         const ColorPrimary& operator=(const ColorPrimary& rhs) { Copy(rhs); return *this; }
+         
+         void Copy(const ColorPrimary& rhs) {
+           X = rhs.X;
+           Y = rhs.Y;
+         }
+
+         //
+         inline const char* EncodeString(char* str_buf, ui32_t buf_len) const {
+           snprintf(str_buf, buf_len, "%d,%d", X, Y);
+           return str_buf;
+         }
+
+         inline virtual bool Unarchive(Kumu::MemIOReader* Reader) {
+           if ( ! Reader->ReadUi16BE((ui16_t*)&X) ) return false;
+           if ( ! Reader->ReadUi16BE((ui16_t*)&Y) ) return false;
+           return true;
+         }
+
+         inline virtual bool HasValue() const { return X || Y; }
+         inline virtual ui32_t ArchiveLength() const { return sizeof(ui16_t)*2; }
+
+         inline virtual bool Archive(Kumu::MemIOWriter* Writer) const {
+           if ( ! Writer->WriteUi16BE((ui16_t)X) ) return false;
+           if ( ! Writer->WriteUi16BE((ui16_t)Y) ) return false;
+           return true;
+         }
+       };
+
+      //
+      class ThreeColorPrimaries : public Kumu::IArchive
+       {
+       public:
+         ColorPrimary First;
+         ColorPrimary Second;
+         ColorPrimary Third;
+
+         ThreeColorPrimaries() {}
+         ~ThreeColorPrimaries() {}
+
+         ThreeColorPrimaries(const ColorPrimary& first, const ColorPrimary& second, const ColorPrimary& third) :
+           First(first), Second(second), Third(third) {}
+
+         ThreeColorPrimaries(const ThreeColorPrimaries& rhs) { Copy(rhs); }
+         const ThreeColorPrimaries& operator=(const ThreeColorPrimaries& rhs) { Copy(rhs); return *this; }
+         
+         void Copy(const ThreeColorPrimaries& rhs) {
+           First = rhs.First;
+           Second = rhs.Second;
+           Third = rhs.Third;
+         }
+
+         //
+         inline const char* EncodeString(char* str_buf, ui32_t buf_len) const {
+           snprintf(str_buf, buf_len, "%d,%d;%d,%d;%d,%d", First.X, First.Y, Second.X, Second.Y, Third.X, Third.Y);
+           return str_buf;
+         }
+
+         inline virtual bool Unarchive(Kumu::MemIOReader* Reader) {
+           First.Unarchive(Reader);
+           Second.Unarchive(Reader);
+           Third.Unarchive(Reader);
+           return true;
+         }
+
+         inline virtual bool HasValue() const {
+           return First.HasValue() || Second.HasValue() || Third.HasValue();
+         }
+
+         inline virtual ui32_t ArchiveLength() const {
+           return First.ArchiveLength()
+             + Second.ArchiveLength()
+             + Third.ArchiveLength();
+         }
+
+         inline virtual bool Archive(Kumu::MemIOWriter* Writer) const {
+           First.Archive(Writer);
+           Second.Archive(Writer);
+           Third.Archive(Writer);
+           return true;
+         }
+       };
+
       //
       class VersionType : public Kumu::IArchive
        {
@@ -592,6 +689,21 @@ namespace ASDCP
          const char* EncodeString(char* str_buf, ui32_t buf_len) const;
        };
 
+      //
+      class J2KExtendedCapabilities : public Kumu::IArchive
+        {
+        public:
+         ui32_t Pcap;
+         ui16_t Ccap[JP2K::MaxCapabilities];
+       
+         bool HasValue() const { return true; }
+         ui32_t ArchiveLength() const { return 0; }
+
+         bool Archive(Kumu::MemIOWriter* Writer) const;
+         bool Unarchive(Kumu::MemIOReader* Reader);
+         const char* EncodeString(char* str_buf, ui32_t buf_len) const;
+      };
+
     } // namespace MXF
 } // namespace ASDCP