+ if (l_num_band > OPJ_J2K_MAXBANDS) {
+ opj_event_msg(p_manager, EVT_WARNING,
+ "While reading CCP_QNTSTY element inside QCD or QCC marker segment, "
+ "number of subbands (%d) is greater to OPJ_J2K_MAXBANDS (%d). So we limit the number of elements stored to "
+ "OPJ_J2K_MAXBANDS (%d) and skip the rest. \n", l_num_band, OPJ_J2K_MAXBANDS,
+ OPJ_J2K_MAXBANDS);
+ /*return OPJ_FALSE;*/
+ }
+ }
+
+#ifdef USE_JPWL
+ if (l_cp->correct) {
+
+ /* if JPWL is on, we check whether there are too many subbands */
+ if (/*(l_num_band < 0) ||*/ (l_num_band >= OPJ_J2K_MAXBANDS)) {
+ opj_event_msg(p_manager, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
+ "JPWL: bad number of subbands in Sqcx (%d)\n",
+ l_num_band);
+ if (!JPWL_ASSUME) {
+ opj_event_msg(p_manager, EVT_ERROR, "JPWL: giving up\n");
+ return OPJ_FALSE;
+ }
+ /* we try to correct */
+ l_num_band = 1;
+ opj_event_msg(p_manager, EVT_WARNING, "- trying to adjust them\n"
+ "- setting number of bands to %d => HYPOTHESIS!!!\n",
+ l_num_band);
+ };
+
+ };
+#endif /* USE_JPWL */
+
+ if (l_tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) {
+ for (l_band_no = 0; l_band_no < l_num_band; l_band_no++) {
+ opj_read_bytes(l_current_ptr, &l_tmp, 1); /* SPqcx_i */
+ ++l_current_ptr;
+ if (l_band_no < OPJ_J2K_MAXBANDS) {
+ l_tccp->stepsizes[l_band_no].expn = (OPJ_INT32)(l_tmp >> 3);
+ l_tccp->stepsizes[l_band_no].mant = 0;
+ }
+ }
+ *p_header_size = *p_header_size - l_num_band;
+ } else {
+ for (l_band_no = 0; l_band_no < l_num_band; l_band_no++) {
+ opj_read_bytes(l_current_ptr, &l_tmp, 2); /* SPqcx_i */
+ l_current_ptr += 2;
+ if (l_band_no < OPJ_J2K_MAXBANDS) {
+ l_tccp->stepsizes[l_band_no].expn = (OPJ_INT32)(l_tmp >> 11);
+ l_tccp->stepsizes[l_band_no].mant = l_tmp & 0x7ff;
+ }
+ }
+ *p_header_size = *p_header_size - 2 * l_num_band;
+ }
+
+ /* Add Antonin : if scalar_derived -> compute other stepsizes */
+ if (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) {
+ for (l_band_no = 1; l_band_no < OPJ_J2K_MAXBANDS; l_band_no++) {
+ l_tccp->stepsizes[l_band_no].expn =
+ ((OPJ_INT32)(l_tccp->stepsizes[0].expn) - (OPJ_INT32)((l_band_no - 1) / 3) > 0)
+ ?
+ (OPJ_INT32)(l_tccp->stepsizes[0].expn) - (OPJ_INT32)((l_band_no - 1) / 3) : 0;
+ l_tccp->stepsizes[l_band_no].mant = l_tccp->stepsizes[0].mant;
+ }
+ }
+
+ return OPJ_TRUE;
+}
+
+static void opj_j2k_copy_tile_quantization_parameters(opj_j2k_t *p_j2k)
+{
+ OPJ_UINT32 i;
+ opj_cp_t *l_cp = NULL;
+ opj_tcp_t *l_tcp = NULL;
+ opj_tccp_t *l_ref_tccp = NULL;
+ opj_tccp_t *l_copied_tccp = NULL;
+ OPJ_UINT32 l_size;
+
+ /* preconditions */
+ assert(p_j2k != 00);
+
+ l_cp = &(p_j2k->m_cp);
+ l_tcp = p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_TPH ?
+ &l_cp->tcps[p_j2k->m_current_tile_number] :
+ p_j2k->m_specific_param.m_decoder.m_default_tcp;
+
+ l_ref_tccp = &l_tcp->tccps[0];
+ l_copied_tccp = l_ref_tccp + 1;
+ l_size = OPJ_J2K_MAXBANDS * sizeof(opj_stepsize_t);
+
+ for (i = 1; i < p_j2k->m_private_image->numcomps; ++i) {
+ l_copied_tccp->qntsty = l_ref_tccp->qntsty;
+ l_copied_tccp->numgbits = l_ref_tccp->numgbits;
+ memcpy(l_copied_tccp->stepsizes, l_ref_tccp->stepsizes, l_size);
+ ++l_copied_tccp;
+ }
+}
+
+static void opj_j2k_dump_tile_info(opj_tcp_t * l_default_tile,
+ OPJ_INT32 numcomps, FILE* out_stream)
+{
+ if (l_default_tile) {
+ OPJ_INT32 compno;
+
+ fprintf(out_stream, "\t default tile {\n");
+ fprintf(out_stream, "\t\t csty=%#x\n", l_default_tile->csty);
+ fprintf(out_stream, "\t\t prg=%#x\n", l_default_tile->prg);
+ fprintf(out_stream, "\t\t numlayers=%d\n", l_default_tile->numlayers);
+ fprintf(out_stream, "\t\t mct=%x\n", l_default_tile->mct);
+
+ for (compno = 0; compno < numcomps; compno++) {
+ opj_tccp_t *l_tccp = &(l_default_tile->tccps[compno]);
+ OPJ_UINT32 resno;
+ OPJ_INT32 bandno, numbands;
+
+ /* coding style*/
+ fprintf(out_stream, "\t\t comp %d {\n", compno);
+ fprintf(out_stream, "\t\t\t csty=%#x\n", l_tccp->csty);
+ fprintf(out_stream, "\t\t\t numresolutions=%d\n", l_tccp->numresolutions);
+ fprintf(out_stream, "\t\t\t cblkw=2^%d\n", l_tccp->cblkw);
+ fprintf(out_stream, "\t\t\t cblkh=2^%d\n", l_tccp->cblkh);
+ fprintf(out_stream, "\t\t\t cblksty=%#x\n", l_tccp->cblksty);
+ fprintf(out_stream, "\t\t\t qmfbid=%d\n", l_tccp->qmfbid);
+
+ fprintf(out_stream, "\t\t\t preccintsize (w,h)=");
+ for (resno = 0; resno < l_tccp->numresolutions; resno++) {
+ fprintf(out_stream, "(%d,%d) ", l_tccp->prcw[resno], l_tccp->prch[resno]);
+ }
+ fprintf(out_stream, "\n");
+
+ /* quantization style*/
+ fprintf(out_stream, "\t\t\t qntsty=%d\n", l_tccp->qntsty);
+ fprintf(out_stream, "\t\t\t numgbits=%d\n", l_tccp->numgbits);
+ fprintf(out_stream, "\t\t\t stepsizes (m,e)=");
+ numbands = (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ? 1 :
+ (OPJ_INT32)l_tccp->numresolutions * 3 - 2;
+ for (bandno = 0; bandno < numbands; bandno++) {
+ fprintf(out_stream, "(%d,%d) ", l_tccp->stepsizes[bandno].mant,
+ l_tccp->stepsizes[bandno].expn);
+ }
+ fprintf(out_stream, "\n");
+
+ /* RGN value*/
+ fprintf(out_stream, "\t\t\t roishift=%d\n", l_tccp->roishift);
+
+ fprintf(out_stream, "\t\t }\n");
+ } /*end of component of default tile*/
+ fprintf(out_stream, "\t }\n"); /*end of default tile*/
+ }
+}
+
+void j2k_dump(opj_j2k_t* p_j2k, OPJ_INT32 flag, FILE* out_stream)
+{
+ /* Check if the flag is compatible with j2k file*/
+ if ((flag & OPJ_JP2_INFO) || (flag & OPJ_JP2_IND)) {
+ fprintf(out_stream, "Wrong flag\n");
+ return;
+ }
+
+ /* Dump the image_header */
+ if (flag & OPJ_IMG_INFO) {
+ if (p_j2k->m_private_image) {
+ j2k_dump_image_header(p_j2k->m_private_image, 0, out_stream);
+ }
+ }
+
+ /* Dump the codestream info from main header */
+ if (flag & OPJ_J2K_MH_INFO) {
+ if (p_j2k->m_private_image) {
+ opj_j2k_dump_MH_info(p_j2k, out_stream);
+ }
+ }
+ /* Dump all tile/codestream info */
+ if (flag & OPJ_J2K_TCH_INFO) {
+ OPJ_UINT32 l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw;
+ OPJ_UINT32 i;
+ opj_tcp_t * l_tcp = p_j2k->m_cp.tcps;
+ if (p_j2k->m_private_image) {
+ for (i = 0; i < l_nb_tiles; ++i) {
+ opj_j2k_dump_tile_info(l_tcp, (OPJ_INT32)p_j2k->m_private_image->numcomps,
+ out_stream);
+ ++l_tcp;
+ }
+ }
+ }
+
+ /* Dump the codestream info of the current tile */
+ if (flag & OPJ_J2K_TH_INFO) {
+
+ }
+
+ /* Dump the codestream index from main header */
+ if (flag & OPJ_J2K_MH_IND) {
+ opj_j2k_dump_MH_index(p_j2k, out_stream);
+ }
+
+ /* Dump the codestream index of the current tile */
+ if (flag & OPJ_J2K_TH_IND) {
+
+ }
+
+}
+
+static void opj_j2k_dump_MH_index(opj_j2k_t* p_j2k, FILE* out_stream)
+{
+ opj_codestream_index_t* cstr_index = p_j2k->cstr_index;
+ OPJ_UINT32 it_marker, it_tile, it_tile_part;
+
+ fprintf(out_stream, "Codestream index from main header: {\n");
+
+ fprintf(out_stream, "\t Main header start position=%" PRIi64 "\n"
+ "\t Main header end position=%" PRIi64 "\n",
+ cstr_index->main_head_start, cstr_index->main_head_end);
+
+ fprintf(out_stream, "\t Marker list: {\n");
+
+ if (cstr_index->marker) {
+ for (it_marker = 0; it_marker < cstr_index->marknum ; it_marker++) {
+ fprintf(out_stream, "\t\t type=%#x, pos=%" PRIi64 ", len=%d\n",
+ cstr_index->marker[it_marker].type,
+ cstr_index->marker[it_marker].pos,
+ cstr_index->marker[it_marker].len);
+ }
+ }
+
+ fprintf(out_stream, "\t }\n");
+
+ if (cstr_index->tile_index) {
+
+ /* Simple test to avoid to write empty information*/
+ OPJ_UINT32 l_acc_nb_of_tile_part = 0;
+ for (it_tile = 0; it_tile < cstr_index->nb_of_tiles ; it_tile++) {
+ l_acc_nb_of_tile_part += cstr_index->tile_index[it_tile].nb_tps;
+ }
+
+ if (l_acc_nb_of_tile_part) {
+ fprintf(out_stream, "\t Tile index: {\n");
+
+ for (it_tile = 0; it_tile < cstr_index->nb_of_tiles ; it_tile++) {
+ OPJ_UINT32 nb_of_tile_part = cstr_index->tile_index[it_tile].nb_tps;
+
+ fprintf(out_stream, "\t\t nb of tile-part in tile [%d]=%d\n", it_tile,
+ nb_of_tile_part);
+
+ if (cstr_index->tile_index[it_tile].tp_index) {
+ for (it_tile_part = 0; it_tile_part < nb_of_tile_part; it_tile_part++) {
+ fprintf(out_stream, "\t\t\t tile-part[%d]: star_pos=%" PRIi64 ", end_header=%"
+ PRIi64 ", end_pos=%" PRIi64 ".\n",
+ it_tile_part,
+ cstr_index->tile_index[it_tile].tp_index[it_tile_part].start_pos,
+ cstr_index->tile_index[it_tile].tp_index[it_tile_part].end_header,
+ cstr_index->tile_index[it_tile].tp_index[it_tile_part].end_pos);
+ }