Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JP2K Quantization unpacking and QCD data checks #109

Open
ChrisRalph opened this issue Jul 20, 2022 · 2 comments · May be fixed by #126
Open

JP2K Quantization unpacking and QCD data checks #109

ChrisRalph opened this issue Jul 20, 2022 · 2 comments · May be fixed by #126

Comments

@ChrisRalph
Copy link

ChrisRalph commented Jul 20, 2022

Hi all,

We are seeing that the GuardBit value determined with j2c-test is incorrect. Proposing the following changes to unpack the correct bytes for determining GuardBits:

JP2K.h around lines 164 to 200

      const int SqcdOFST = 0;
      const int SPqcdOFST = 1;

      enum QuantizationType_t
      {
	QT_NONE,
	QT_DERIVED,
	QT_EXP
      };

      const char* GetQuantizationTypeString(const QuantizationType_t m);

      // Quantization default
      class QCD
        {
	  const byte_t* m_MarkerSqcd;
	  const byte_t* m_MarkerData;
	  ui32_t m_DataSize;

	  KM_NO_COPY_CONSTRUCT(QCD);
	  QCD();

	public:
	  QCD(const Marker& M)
	    {
	      assert(M.m_Type == MRK_QCD);
              m_MarkerSqcd = M.m_Data;
	      m_MarkerData = M.m_Data + SPqcdOFST;
	      m_DataSize = M.m_DataSize - SPqcdOFST;
	    }

	  ~QCD() {}
	  inline QuantizationType_t QuantizationType() const { return static_cast<QuantizationType_t>(*(m_MarkerSqcd) & 0x03); }
	  inline ui8_t  GuardBits() const { return (*(m_MarkerSqcd) & 0xe0) >> 5; }
	  void Dump(FILE* stream = 0) const;
	};

Additionally, does anyone know if there is a specific requirement for the QCD Data to match between frames aswell as GuardBits matching, as per the pedantic checks? Different JP2K Encoders potentially use different values here and the pedantic checks prevent these from wrapping frames which have differing values in a single MXF.

Proposing the following changes to highlight a difference of QCD Data (with matching GuardBits), but not to fail the pedantic checks:

JP2K_Sequence_Parser.cpp line ~209 to 226:

//
bool
operator==(const ASDCP::JP2K::QuantizationDefault_t& lhs, const ASDCP::JP2K::QuantizationDefault_t& rhs)
{
  if ( lhs.Sqcd != rhs.Sqcd ) return false;
  if ( lhs.SPqcdLength != rhs.SPqcdLength ) return false;
  
  for ( ui32_t i = 0; i < JP2K::MaxDefaults; i++ )
    {
      if ( lhs.SPqcd[i] != rhs.SPqcd[i]  ){
        printf("SPqcd Component mismatch.\n");
        // TODO: Bypassing this check until we know if it is appropriate
        // return false;
      }
    }

  return true;
}

@michaeldsmith
Copy link

Confirming that it appears that ascdplib tool j2c-test output is not correct for QCD marker info.

Specifically, j2c-test lists 4 guard bits for the JPEG2000 codestreams in the attached zip files that are 2K and 4K files using 1 and 2 guard bits as indicated in the filename. Also, the SPqcd field information looks incorrect.

ascdplib tool j2c-test shows this QCD incorrect information for the 2K files:

QCD: 
QuantizationType: scalar expounded
       GuardBits: 4
           SPqcd: 4
  000000: 1e 96 ea 96 ea 96 bc 8f 00 8f 00 8e e2 87 4c 87 ..............L.
  000001: 4c 87 64 70 03 70 03 70 45 77 d2 77 d2 77 61    L.dp.p.pEw.w.wa

asdcplib tool j2c-test shows this QCD incorrect information for the 4K files:

QCD: 
QuantizationType: scalar expounded
       GuardBits: 4
           SPqcd: 4
  000000: 1e 9e ea 9e ea 9e bc 96 ea 96 ea 96 bc 8f 00 8f ................
  000001: 00 8e e2 87 4c 87 4c 87 64 70 03 70 03 70 45 77 ....L.L.dp.p.pEw

OpenJPEG tool opj_dump shows the correct guard bit information for the 1 guard bit files:
numgbits=1

OpenJPEG tool opj_dump shows the correct guard bit information for the 2 guard bit files:
numgbits=2

Here are zip files containing the analyzed codestreams:
2KCINEMA_guardbits1.zip
2KCINEMA_guardbits2.zip
4KCINEMA_guardbits1.zip
4KCINEMA_guardbits2.zip

Here is full asdcplib tool j2c-test output:
2KCINEMA_guardbits1.j2c.j2c-test.txt
2KCINEMA_guardbits2.j2c.j2c-test.txt
4KCINEMA_guardbits1.j2c.j2c-test.txt
4KCINEMA_guardbits2.j2c.j2c-test.txt

Here is the full OpenJPEG tool opj_dump output:
2KCINEMA_guardbits1.j2c.opj_dump.txt
2KCINEMA_guardbits2.j2c.opj_dump.txt
4KCINEMA_guardbits1.j2c.opj_dump.txt
4KCINEMA_guardbits2.j2c.opj_dump.txt

@hmachefe
Copy link

Thanks for the update Michael. Have you planned to apply the code change suggested by Chris above ? Any ETA about it ?

@palemieux palemieux linked a pull request Aug 11, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants