Change copyright date.
[asdcplib.git] / src / AS_DCP_JP2K.cpp
index bd0bc33a307b08044763d93f3eed8a7f3cf653a6..9a334a6ac6013c1c32bdc409a98ecd31c010742d 100755 (executable)
@@ -30,6 +30,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #include "AS_DCP_internal.h"
+#include <iostream>
+#include <iomanip>
 
 using namespace ASDCP::JP2K;
 using Kumu::GenRandomValue;
@@ -42,6 +44,71 @@ static std::string PICT_DEF_LABEL = "Picture Track";
 
 int s_exp_lookup[16] = { 0, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,2048, 4096, 8192, 16384, 32768 };
 
+//
+std::ostream&
+ASDCP::JP2K::operator << (std::ostream& strm, const PictureDescriptor& PDesc)
+{
+  strm << "       AspectRatio: " << PDesc.AspectRatio.Numerator << "/" << PDesc.AspectRatio.Denominator << std::endl;
+  strm << "          EditRate: " << PDesc.EditRate.Numerator << "/" << PDesc.EditRate.Denominator << std::endl;
+  strm << "        SampleRate: " << PDesc.SampleRate.Numerator << "/" << PDesc.SampleRate.Denominator << std::endl;
+  strm << "       StoredWidth: " << (unsigned) PDesc.StoredWidth << std::endl;
+  strm << "      StoredHeight: " << (unsigned) PDesc.StoredHeight << std::endl;
+  strm << "             Rsize: " << (unsigned) PDesc.Rsize << std::endl;
+  strm << "             Xsize: " << (unsigned) PDesc.Xsize << std::endl;
+  strm << "             Ysize: " << (unsigned) PDesc.Ysize << std::endl;
+  strm << "            XOsize: " << (unsigned) PDesc.XOsize << std::endl;
+  strm << "            YOsize: " << (unsigned) PDesc.YOsize << std::endl;
+  strm << "            XTsize: " << (unsigned) PDesc.XTsize << std::endl;
+  strm << "            YTsize: " << (unsigned) PDesc.YTsize << std::endl;
+  strm << "           XTOsize: " << (unsigned) PDesc.XTOsize << std::endl;
+  strm << "           YTOsize: " << (unsigned) PDesc.YTOsize << std::endl;
+  strm << " ContainerDuration: " << (unsigned) PDesc.ContainerDuration << std::endl;
+
+  strm << "-- JPEG 2000 Metadata --" << std::endl;
+  strm << "    ImageComponents:" << std::endl;
+  strm << "  bits  h-sep v-sep" << std::endl;
+
+  ui32_t i;
+  for ( i = 0; i < PDesc.Csize; i++ )
+    {
+      strm << "  " << std::setw(4) << PDesc.ImageComponents[i].Ssize + 1 /* See ISO 15444-1, Table A11, for the origin of '+1' */
+          << "  " << std::setw(5) << PDesc.ImageComponents[i].XRsize
+          << " " << std::setw(5) << PDesc.ImageComponents[i].YRsize
+          << std::endl;
+    }
+
+  strm << "               Scod: " << (short) PDesc.CodingStyleDefault.Scod << std::endl;
+  strm << "   ProgressionOrder: " << (short) PDesc.CodingStyleDefault.SGcod.ProgressionOrder << std::endl;
+  strm << "     NumberOfLayers: " << (short) KM_i16_BE(Kumu::cp2i<ui16_t>(PDesc.CodingStyleDefault.SGcod.NumberOfLayers)) << std::endl;
+  strm << " MultiCompTransform: " << (short) PDesc.CodingStyleDefault.SGcod.MultiCompTransform << std::endl;
+  strm << "DecompositionLevels: " << (short) PDesc.CodingStyleDefault.SPcod.DecompositionLevels << std::endl;
+  strm << "     CodeblockWidth: " << (short) PDesc.CodingStyleDefault.SPcod.CodeblockWidth << std::endl;
+  strm << "    CodeblockHeight: " << (short) PDesc.CodingStyleDefault.SPcod.CodeblockHeight << std::endl;
+  strm << "     CodeblockStyle: " << (short) PDesc.CodingStyleDefault.SPcod.CodeblockStyle << std::endl;
+  strm << "     Transformation: " << (short) PDesc.CodingStyleDefault.SPcod.Transformation << std::endl;
+
+
+  ui32_t precinct_set_size = 0;
+
+  for ( i = 0; PDesc.CodingStyleDefault.SPcod.PrecinctSize[i] != 0 && i < MaxPrecincts; i++ )
+    precinct_set_size++;
+
+  strm << "          Precincts: " << (short) precinct_set_size << std::endl;
+  strm << "precinct dimensions:" << std::endl;
+
+  for ( i = 0; i < precinct_set_size; i++ )
+    strm << "    " << i + 1 << ": " << s_exp_lookup[PDesc.CodingStyleDefault.SPcod.PrecinctSize[i]&0x0f] << " x "
+        << s_exp_lookup[(PDesc.CodingStyleDefault.SPcod.PrecinctSize[i]>>4)&0x0f] << std::endl;
+
+  strm << "               Sqcd: " << (short) PDesc.QuantizationDefault.Sqcd << std::endl;
+
+  char tmp_buf[MaxDefaults*2];
+  strm << "              SPqcd: " << Kumu::bin2hex(PDesc.QuantizationDefault.SPqcd, PDesc.QuantizationDefault.SPqcdLength, tmp_buf, MaxDefaults*2)
+       << std::endl;
+
+  return strm;
+}
+
 //
 void
 ASDCP::JP2K::PictureDescriptorDump(const PictureDescriptor& PDesc, FILE* stream)
@@ -52,6 +119,7 @@ ASDCP::JP2K::PictureDescriptorDump(const PictureDescriptor& PDesc, FILE* stream)
   fprintf(stream, "\
        AspectRatio: %d/%d\n\
           EditRate: %d/%d\n\
+        SampleRate: %d/%d\n\
        StoredWidth: %u\n\
       StoredHeight: %u\n\
              Rsize: %u\n\
@@ -66,6 +134,7 @@ ASDCP::JP2K::PictureDescriptorDump(const PictureDescriptor& PDesc, FILE* stream)
  ContainerDuration: %u\n",
          PDesc.AspectRatio.Numerator, PDesc.AspectRatio.Denominator,
          PDesc.EditRate.Numerator, PDesc.EditRate.Denominator,
+         PDesc.SampleRate.Numerator, PDesc.SampleRate.Denominator,
          PDesc.StoredWidth,
          PDesc.StoredHeight,
          PDesc.Rsize,
@@ -130,6 +199,7 @@ ASDCP::JP2K::PictureDescriptorDump(const PictureDescriptor& PDesc, FILE* stream)
          );
 }
 
+
 //------------------------------------------------------------------------------------------
 //
 // hidden, internal implementation of JPEG 2000 reader
@@ -139,6 +209,7 @@ class lh__Reader : public ASDCP::h__Reader
   RGBAEssenceDescriptor*        m_EssenceDescriptor;
   JPEG2000PictureSubDescriptor* m_EssenceSubDescriptor;
   ASDCP::Rational               m_EditRate;
+  ASDCP::Rational               m_SampleRate;
   EssenceType_t                 m_Format;
 
   ASDCP_NO_COPY_CONSTRUCT(lh__Reader);
@@ -160,7 +231,9 @@ lh__Reader::MD_to_JP2K_PDesc(JP2K::PictureDescriptor& PDesc)
   MXF::RGBAEssenceDescriptor* PDescObj = (MXF::RGBAEssenceDescriptor*)m_EssenceDescriptor;
 
   PDesc.EditRate           = m_EditRate;
-  PDesc.ContainerDuration  = PDescObj->ContainerDuration;
+  PDesc.SampleRate         = m_SampleRate;
+  assert(PDescObj->ContainerDuration <= 0xFFFFFFFFL);
+  PDesc.ContainerDuration  = (ui32_t) PDescObj->ContainerDuration;
   PDesc.StoredWidth        = PDescObj->StoredWidth;
   PDesc.StoredHeight       = PDescObj->StoredHeight;
   PDesc.AspectRatio        = PDescObj->AspectRatio;
@@ -231,17 +304,18 @@ lh__Reader::OpenRead(const char* filename, EssenceType_t type)
        }
 
       m_EditRate = ((Track*)ObjectList.front())->EditRate;
+      m_SampleRate = m_EssenceDescriptor->SampleRate;
 
       if ( type == ASDCP::ESS_JPEG_2000 )
        {
-         if ( m_EditRate != m_EssenceDescriptor->SampleRate )
+         if ( m_EditRate != m_SampleRate )
            {
              DefaultLogSink().Error("EditRate and SampleRate do not match (%.03f, %.03f).\n",
-                                    m_EditRate.Quotient(), m_EssenceDescriptor->SampleRate.Quotient());
+                                    m_EditRate.Quotient(), m_SampleRate.Quotient());
              
-             if ( m_EditRate == EditRate_24 && m_EssenceDescriptor->SampleRate == EditRate_48 )
+             if ( m_EditRate == EditRate_24 && m_SampleRate == EditRate_48 )
                {
-                 DefaultLogSink().Error("File may contain JPEG Interop stereoscopic images.\n");
+                 DefaultLogSink().Debug("File may contain JPEG Interop stereoscopic images.\n");
                  return RESULT_SFORMAT;
                }
 
@@ -250,7 +324,7 @@ lh__Reader::OpenRead(const char* filename, EssenceType_t type)
        }
       else if ( type == ASDCP::ESS_JPEG_2000_S )
        {
-         if ( ! ( m_EditRate == EditRate_24 && m_EssenceDescriptor->SampleRate == EditRate_48 ) )
+         if ( ! ( m_EditRate == EditRate_24 && m_SampleRate == EditRate_48 ) )
            {
              DefaultLogSink().Error("EditRate and SampleRate not correct for 24/48 stereoscopic essence.\n");
              return RESULT_FORMAT;