@@ -79,8 +79,6 @@ namespace ojph {
7979
8080 precinct_scratch_needed_bytes = 0 ;
8181
82- used_qcc_fields = 0 ;
83- qcc = qcc_store;
8482 used_coc_fields = 0 ;
8583 coc = coc_store;
8684
@@ -100,8 +98,6 @@ namespace ojph {
10098 // //////////////////////////////////////////////////////////////////////////
10199 codestream::~codestream ()
102100 {
103- if (qcc_store != qcc)
104- delete[] qcc;
105101 if (allocator)
106102 delete allocator;
107103 if (elastic_alloc)
@@ -633,6 +629,9 @@ namespace ojph {
633629 if (!qcd.write (file))
634630 OJPH_ERROR (0x00030026 , " Error writing to file" );
635631
632+ if (!qcd.write_qcc (file, num_comps))
633+ OJPH_ERROR (0x0003002D , " Error writing to file" );
634+
636635 if (!nlt.write (file))
637636 OJPH_ERROR (0x00030027 , " Error writing to file" );
638637
@@ -766,9 +765,7 @@ namespace ojph {
766765 ui32 num_comps = siz.get_num_components ();
767766 if (coc == coc_store &&
768767 num_comps * sizeof (param_cod) > sizeof (coc_store))
769- {
770768 coc = new param_cod[num_comps];
771- }
772769 coc[used_coc_fields++].read (
773770 file, param_cod::COC_MAIN, num_comps, &cod);
774771 }
@@ -779,13 +776,18 @@ namespace ojph {
779776 }
780777 else if (marker_idx == 6 )
781778 {
782- ui32 num_comps = siz.get_num_components ();
783- if (qcc == qcc_store &&
784- num_comps * sizeof (param_qcc) > sizeof (qcc_store))
785- {
786- qcc = new param_qcc[num_comps];
787- }
788- qcc[used_qcc_fields++].read (file, num_comps);
779+ param_qcd* p = qcd.add_qcc_object (param_qcd::OJPH_QCD_UNKNOWN);
780+ p->read_qcc (file, siz.get_num_components ());
781+ if (p->get_comp_idx () >= siz.get_num_components ())
782+ OJPH_ERROR (0x00030054 , " The codestream carries a QCC narker "
783+ " segment for a component indexed by %d, which is more than the "
784+ " allowed index number, since the codestream has %d components" ,
785+ p->get_comp_idx (), num_comps);
786+ param_qcd *q = qcd.get_qcc (p->get_comp_idx ());
787+ if (p != q && p->get_comp_idx () == q->get_comp_idx ())
788+ OJPH_ERROR (0x00030055 , " The codestream has two QCC marker "
789+ " segments for one component of index %d" ,
790+ p->get_comp_idx ());
789791 }
790792 else if (marker_idx == 7 )
791793 skip_marker (file, " RGN" , " RGN is not supported yet" ,
0 commit comments