+ fprintf(out_stream, "}\n");
+
+}
+
+
+static void opj_j2k_dump_MH_info(opj_j2k_t* p_j2k, FILE* out_stream)
+{
+
+ fprintf(out_stream, "Codestream info from main header: {\n");
+
+ fprintf(out_stream, "\t tx0=%d, ty0=%d\n", p_j2k->m_cp.tx0, p_j2k->m_cp.ty0);
+ fprintf(out_stream, "\t tdx=%d, tdy=%d\n", p_j2k->m_cp.tdx, p_j2k->m_cp.tdy);
+ fprintf(out_stream, "\t tw=%d, th=%d\n", p_j2k->m_cp.tw, p_j2k->m_cp.th);
+ opj_j2k_dump_tile_info(p_j2k->m_specific_param.m_decoder.m_default_tcp,
+ (OPJ_INT32)p_j2k->m_private_image->numcomps, out_stream);
+ fprintf(out_stream, "}\n");
+}
+
+void j2k_dump_image_header(opj_image_t* img_header, OPJ_BOOL dev_dump_flag,
+ FILE* out_stream)
+{
+ char tab[2];
+
+ if (dev_dump_flag) {
+ fprintf(stdout, "[DEV] Dump an image_header struct {\n");
+ tab[0] = '\0';
+ } else {
+ fprintf(out_stream, "Image info {\n");
+ tab[0] = '\t';
+ tab[1] = '\0';
+ }
+
+ fprintf(out_stream, "%s x0=%d, y0=%d\n", tab, img_header->x0, img_header->y0);
+ fprintf(out_stream, "%s x1=%d, y1=%d\n", tab, img_header->x1,
+ img_header->y1);
+ fprintf(out_stream, "%s numcomps=%d\n", tab, img_header->numcomps);
+
+ if (img_header->comps) {
+ OPJ_UINT32 compno;
+ for (compno = 0; compno < img_header->numcomps; compno++) {
+ fprintf(out_stream, "%s\t component %d {\n", tab, compno);
+ j2k_dump_image_comp_header(&(img_header->comps[compno]), dev_dump_flag,
+ out_stream);
+ fprintf(out_stream, "%s}\n", tab);
+ }
+ }
+
+ fprintf(out_stream, "}\n");
+}
+
+void j2k_dump_image_comp_header(opj_image_comp_t* comp_header,
+ OPJ_BOOL dev_dump_flag, FILE* out_stream)
+{
+ char tab[3];
+
+ if (dev_dump_flag) {
+ fprintf(stdout, "[DEV] Dump an image_comp_header struct {\n");
+ tab[0] = '\0';
+ } else {
+ tab[0] = '\t';
+ tab[1] = '\t';
+ tab[2] = '\0';
+ }
+
+ fprintf(out_stream, "%s dx=%d, dy=%d\n", tab, comp_header->dx, comp_header->dy);
+ fprintf(out_stream, "%s prec=%d\n", tab, comp_header->prec);
+ fprintf(out_stream, "%s sgnd=%d\n", tab, comp_header->sgnd);
+
+ if (dev_dump_flag) {
+ fprintf(out_stream, "}\n");
+ }
+}
+
+opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_t* p_j2k)
+{
+ OPJ_UINT32 compno;
+ OPJ_UINT32 numcomps = p_j2k->m_private_image->numcomps;
+ opj_tcp_t *l_default_tile;
+ opj_codestream_info_v2_t* cstr_info = (opj_codestream_info_v2_t*) opj_calloc(1,
+ sizeof(opj_codestream_info_v2_t));
+ if (!cstr_info) {
+ return NULL;
+ }
+
+ cstr_info->nbcomps = p_j2k->m_private_image->numcomps;
+
+ cstr_info->tx0 = p_j2k->m_cp.tx0;
+ cstr_info->ty0 = p_j2k->m_cp.ty0;
+ cstr_info->tdx = p_j2k->m_cp.tdx;
+ cstr_info->tdy = p_j2k->m_cp.tdy;
+ cstr_info->tw = p_j2k->m_cp.tw;
+ cstr_info->th = p_j2k->m_cp.th;
+
+ cstr_info->tile_info = NULL; /* Not fill from the main header*/
+
+ l_default_tile = p_j2k->m_specific_param.m_decoder.m_default_tcp;
+
+ cstr_info->m_default_tile_info.csty = l_default_tile->csty;
+ cstr_info->m_default_tile_info.prg = l_default_tile->prg;
+ cstr_info->m_default_tile_info.numlayers = l_default_tile->numlayers;
+ cstr_info->m_default_tile_info.mct = l_default_tile->mct;
+
+ cstr_info->m_default_tile_info.tccp_info = (opj_tccp_info_t*) opj_calloc(
+ cstr_info->nbcomps, sizeof(opj_tccp_info_t));
+ if (!cstr_info->m_default_tile_info.tccp_info) {
+ opj_destroy_cstr_info(&cstr_info);
+ return NULL;
+ }
+
+ for (compno = 0; compno < numcomps; compno++) {
+ opj_tccp_t *l_tccp = &(l_default_tile->tccps[compno]);
+ opj_tccp_info_t *l_tccp_info = &
+ (cstr_info->m_default_tile_info.tccp_info[compno]);
+ OPJ_INT32 bandno, numbands;
+
+ /* coding style*/
+ l_tccp_info->csty = l_tccp->csty;
+ l_tccp_info->numresolutions = l_tccp->numresolutions;
+ l_tccp_info->cblkw = l_tccp->cblkw;
+ l_tccp_info->cblkh = l_tccp->cblkh;
+ l_tccp_info->cblksty = l_tccp->cblksty;
+ l_tccp_info->qmfbid = l_tccp->qmfbid;
+ if (l_tccp->numresolutions < OPJ_J2K_MAXRLVLS) {
+ memcpy(l_tccp_info->prch, l_tccp->prch, l_tccp->numresolutions);
+ memcpy(l_tccp_info->prcw, l_tccp->prcw, l_tccp->numresolutions);
+ }
+
+ /* quantization style*/
+ l_tccp_info->qntsty = l_tccp->qntsty;
+ l_tccp_info->numgbits = l_tccp->numgbits;
+
+ numbands = (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ? 1 :
+ (OPJ_INT32)l_tccp->numresolutions * 3 - 2;
+ if (numbands < OPJ_J2K_MAXBANDS) {
+ for (bandno = 0; bandno < numbands; bandno++) {
+ l_tccp_info->stepsizes_mant[bandno] = (OPJ_UINT32)
+ l_tccp->stepsizes[bandno].mant;
+ l_tccp_info->stepsizes_expn[bandno] = (OPJ_UINT32)
+ l_tccp->stepsizes[bandno].expn;
+ }
+ }
+
+ /* RGN value*/
+ l_tccp_info->roishift = l_tccp->roishift;
+ }
+
+ return cstr_info;
+}
+
+opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k)
+{
+ opj_codestream_index_t* l_cstr_index = (opj_codestream_index_t*)
+ opj_calloc(1, sizeof(opj_codestream_index_t));
+ if (!l_cstr_index) {
+ return NULL;
+ }
+
+ l_cstr_index->main_head_start = p_j2k->cstr_index->main_head_start;
+ l_cstr_index->main_head_end = p_j2k->cstr_index->main_head_end;
+ l_cstr_index->codestream_size = p_j2k->cstr_index->codestream_size;
+
+ l_cstr_index->marknum = p_j2k->cstr_index->marknum;
+ l_cstr_index->marker = (opj_marker_info_t*)opj_malloc(l_cstr_index->marknum *
+ sizeof(opj_marker_info_t));
+ if (!l_cstr_index->marker) {
+ opj_free(l_cstr_index);
+ return NULL;
+ }
+
+ if (p_j2k->cstr_index->marker) {
+ memcpy(l_cstr_index->marker, p_j2k->cstr_index->marker,
+ l_cstr_index->marknum * sizeof(opj_marker_info_t));
+ } else {
+ opj_free(l_cstr_index->marker);
+ l_cstr_index->marker = NULL;
+ }
+
+ l_cstr_index->nb_of_tiles = p_j2k->cstr_index->nb_of_tiles;
+ l_cstr_index->tile_index = (opj_tile_index_t*)opj_calloc(
+ l_cstr_index->nb_of_tiles, sizeof(opj_tile_index_t));
+ if (!l_cstr_index->tile_index) {
+ opj_free(l_cstr_index->marker);
+ opj_free(l_cstr_index);
+ return NULL;
+ }
+
+ if (!p_j2k->cstr_index->tile_index) {
+ opj_free(l_cstr_index->tile_index);
+ l_cstr_index->tile_index = NULL;
+ } else {
+ OPJ_UINT32 it_tile = 0;
+ for (it_tile = 0; it_tile < l_cstr_index->nb_of_tiles; it_tile++) {
+
+ /* Tile Marker*/
+ l_cstr_index->tile_index[it_tile].marknum =
+ p_j2k->cstr_index->tile_index[it_tile].marknum;
+
+ l_cstr_index->tile_index[it_tile].marker =
+ (opj_marker_info_t*)opj_malloc(l_cstr_index->tile_index[it_tile].marknum *
+ sizeof(opj_marker_info_t));
+
+ if (!l_cstr_index->tile_index[it_tile].marker) {
+ OPJ_UINT32 it_tile_free;
+
+ for (it_tile_free = 0; it_tile_free < it_tile; it_tile_free++) {
+ opj_free(l_cstr_index->tile_index[it_tile_free].marker);