o removed waywars #endif
[asdcplib.git] / src / JP2K.cpp
index 14789f17f13b289bbedfb523d1e3efb2ce0a4b98..a0f2a8a124757cf59bcd2b7c6b59aa3343b558d7 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2005-2006, John Hurst
+Copyright (c) 2005-2014, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -102,7 +102,7 @@ ASDCP::JP2K::GetNextMarker(const byte_t** buf, JP2K::Marker& Marker)
 
 //
 void
-ASDCP::JP2K::Accessor::SIZ::ReadComponent(ui32_t index, ASDCP::JP2K::ImageComponent& IC)
+ASDCP::JP2K::Accessor::SIZ::ReadComponent(const ui32_t index, ASDCP::JP2K::ImageComponent_t& IC) const
 {
   assert ( index < Csize() );
   const byte_t* p = m_MarkerData + 36 + (index * 3);
@@ -113,7 +113,7 @@ ASDCP::JP2K::Accessor::SIZ::ReadComponent(ui32_t index, ASDCP::JP2K::ImageCompon
 
 //
 void
-ASDCP::JP2K::Accessor::SIZ::Dump(FILE* stream)
+ASDCP::JP2K::Accessor::SIZ::Dump(FILE* stream) const
 {
   if ( stream == 0 )
     stream = stderr;
@@ -121,11 +121,11 @@ ASDCP::JP2K::Accessor::SIZ::Dump(FILE* stream)
   fprintf(stream, "SIZ: \n");
   fprintf(stream, "  Rsize: %hu\n", Rsize());
   fprintf(stream, "  Xsize: %u\n",  Xsize());
-  fprintf(stream, "  Ysize: %u\n",  Xsize());
+  fprintf(stream, "  Ysize: %u\n",  Ysize());
   fprintf(stream, " XOsize: %u\n",  XOsize());
-  fprintf(stream, " YOsize: %u\n",  XOsize());
+  fprintf(stream, " YOsize: %u\n",  YOsize());
   fprintf(stream, " XTsize: %u\n",  XTsize());
-  fprintf(stream, " YTsize: %u\n",  XTsize());
+  fprintf(stream, " YTsize: %u\n",  YTsize());
   fprintf(stream, "XTOsize: %u\n",  XTOsize());
   fprintf(stream, "YTOsize: %u\n",  YTOsize());
   fprintf(stream, "  Csize: %u\n",  Csize());
@@ -136,7 +136,7 @@ ASDCP::JP2K::Accessor::SIZ::Dump(FILE* stream)
 
       for ( ui32_t i = 0; i < Csize(); i++ )
        {
-         ImageComponent TmpComp;
+         ImageComponent_t TmpComp;
          ReadComponent(i, TmpComp);
          fprintf(stream, "%u: ", i);
          fprintf(stream, "%u, %u, %u\n", TmpComp.Ssize, TmpComp.XRsize, TmpComp.YRsize);
@@ -146,22 +146,83 @@ ASDCP::JP2K::Accessor::SIZ::Dump(FILE* stream)
 
 //
 void
-ASDCP::JP2K::Accessor::COM::Dump(FILE* stream)
+ASDCP::JP2K::Accessor::COD::Dump(FILE* stream) const
+{
+  if ( stream == 0 )
+    stream = stderr;
+
+  fprintf(stream, "COD: \n");
+  const char* prog_order_str = "RESERVED";
+  const char* transformations_str = prog_order_str;
+
+  switch ( ProgOrder() )
+    {
+    case 0: prog_order_str = "LRCP"; break;
+    case 1: prog_order_str = "RLCP"; break;
+    case 2: prog_order_str = "RPCL"; break;
+    case 3: prog_order_str = "PCRL"; break;
+    case 4: prog_order_str = "CPRL"; break;
+    }
+
+  switch ( Transformation() )
+    {
+    case 0: transformations_str = "9/7"; break;
+    case 1: transformations_str = "5/3"; break;
+    }
+
+  fprintf(stream, "      ProgOrder: %s\n", prog_order_str);
+  fprintf(stream, "         Layers: %hu\n", Layers());
+  fprintf(stream, "   DecompLevels: %hhu\n", DecompLevels());
+  fprintf(stream, " CodeBlockWidth: %d\n", 1 << CodeBlockWidth());
+  fprintf(stream, "CodeBlockHeight: %d\n", 1 << CodeBlockHeight());
+  fprintf(stream, " CodeBlockStyle: %d\n", CodeBlockStyle());
+  fprintf(stream, " Transformation: %s\n", transformations_str);
+}
+
+//
+const char*
+ASDCP::JP2K::Accessor::GetQuantizationTypeString(const Accessor::QuantizationType_t t)
+{
+  switch ( t )
+    {
+    case QT_NONE: return "none";
+    case QT_DERIVED: return "scalar derived";
+    case QT_EXP: return "scalar expounded";
+    }
+
+  return "**UNKNOWN**";
+}
+
+//
+void
+ASDCP::JP2K::Accessor::QCD::Dump(FILE* stream) const
+{
+  if ( stream == 0 )
+    stream = stderr;
+
+  fprintf(stream, "QCD: \n");
+  fprintf(stream, "QuantizationType: %s\n", GetQuantizationTypeString(QuantizationType()));
+  fprintf(stream, "       GuardBits: %d\n", GuardBits());
+  fprintf(stream, "           SPqcd: %d\n", GuardBits());
+  Kumu::hexdump(m_MarkerData, m_DataSize, stream);
+}
+
+//
+void
+ASDCP::JP2K::Accessor::COM::Dump(FILE* stream) const
 {
   if ( stream == 0 )
     stream = stderr;
 
   if ( IsText() )
     {
-      char* t_str = (char*)malloc(CommentSize() + 1);
-      assert( t_str != 0 );
-      ui32_t cs = CommentSize();
-      memcpy(t_str, CommentData(), cs);
-      t_str[cs] = 0;
-      fprintf(stream, "COM:%s\n", t_str);
+      std::string tmp_str;
+      tmp_str.assign((char*)CommentData(), CommentSize());
+      fprintf(stream, "COM:%s\n", tmp_str.c_str());
     }
   else
     {
+      fprintf(stream, "COM:\n");
       Kumu::hexdump(CommentData(), CommentSize(), stream);
     }
 }