X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=jpwl%2Fjpwl.c;h=07ca796adfd54a1103b1bb4afecdeec5bd7750d4;hb=a1b6f1e0966b33197ee02c952b806b8a0bc7d51f;hp=f97331d4be7f7d62f37b66dbe66f28298fcda69f;hpb=dfcacb82476411105ff7b0726bd8f3f8212ae1c2;p=openjpeg.git diff --git a/jpwl/jpwl.c b/jpwl/jpwl.c index f97331d4..07ca796a 100644 --- a/jpwl/jpwl.c +++ b/jpwl/jpwl.c @@ -39,10 +39,10 @@ /** @name Local static variables */ /*@{*/ -/** position of markers to insert */ -static jpwl_marker_t jwmarker[JPWL_MAX_NO_MARKERS]; -/** number of prepared markers */ +/** number of JPWL prepared markers */ static int jwmarker_num; +/** properties of JPWL markers to insert */ +static jpwl_marker_t jwmarker[JPWL_MAX_NO_MARKERS]; /*@}*/ @@ -88,25 +88,97 @@ their relevant wishlist position int jpwl_markcomp(const void *arg1, const void *arg2); /** write an EPB MS to a buffer +@param j2k J2K compressor handle @param epbmark pointer to the EPB MS @param buf pointer to the memory buffer */ -void jpwl_epb_write(jpwl_epb_ms_t *epbmark, unsigned char *buf); +void jpwl_epb_write(opj_j2k_t *j2k, jpwl_epb_ms_t *epbmark, unsigned char *buf); /** write an EPC MS to a buffer +@param j2k J2K compressor handle @param epcmark pointer to the EPC MS @param buf pointer to the memory buffer */ -void jpwl_epc_write(jpwl_epc_ms_t *epcmark, unsigned char *buf); +void jpwl_epc_write(opj_j2k_t *j2k, jpwl_epc_ms_t *epcmark, unsigned char *buf); /** write an ESD MS to a buffer +@param j2k J2K compressor handle @param esdmark pointer to the ESD MS @param buf pointer to the memory buffer */ -void jpwl_esd_write(jpwl_esd_ms_t *esdmark, unsigned char *buf); +void jpwl_esd_write(opj_j2k_t *j2k, jpwl_esd_ms_t *esdmark, unsigned char *buf); /*-----------------------------------------------------------------*/ +void jpwl_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { + + int mm; + + /* let's reset some settings */ + + /* clear the existing markers */ + for (mm = 0; mm < jwmarker_num; mm++) { + + switch (jwmarker[mm].id) { + + case J2K_MS_EPB: + opj_free(jwmarker[mm].m.epbmark); + break; + + case J2K_MS_EPC: + opj_free(jwmarker[mm].m.epcmark); + break; + + case J2K_MS_ESD: + opj_free(jwmarker[mm].m.esdmark); + break; + + case J2K_MS_RED: + opj_free(jwmarker[mm].m.redmark); + break; + + default: + break; + } + } + + /* clear the marker structure array */ + memset(jwmarker, 0, sizeof(jpwl_marker_t) * JPWL_MAX_NO_MARKERS); + + /* no more markers in the list */ + jwmarker_num = 0; + + /* let's begin creating a marker list, according to user wishes */ + jpwl_prepare_marks(j2k, cio, image); + + /* now we dump the JPWL markers on the codestream */ + jpwl_dump_marks(j2k, cio, image); + + /* do not know exactly what is this for, + but it gets called during index creation */ + j2k->pos_correction = 0; + +} + +void j2k_add_marker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len) { + + if (!cstr_info) + return; + + /* expand the list? */ + if ((cstr_info->marknum + 1) > cstr_info->maxmarknum) { + cstr_info->maxmarknum = 100 + (int) ((float) cstr_info->maxmarknum * 1.0F); + cstr_info->marker = opj_realloc(cstr_info->marker, cstr_info->maxmarknum); + } + + /* add the marker */ + cstr_info->marker[cstr_info->marknum].type = type; + cstr_info->marker[cstr_info->marknum].pos = pos; + cstr_info->marker[cstr_info->marknum].len = len; + cstr_info->marknum++; + +} + void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { unsigned short int socsiz_len = 0; @@ -119,7 +191,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { jpwl_epc_ms_t *epc_mark; jpwl_esd_ms_t *esd_mark; - /* find SOC + SIZ length */ + /* find (SOC + SIZ) length */ /* I assume SIZ is always the first marker after SOC */ cio_seek(cio, soc_pos + 4); socsiz_len = (unsigned short int) cio_read(cio, 2) + 4; /* add the 2 marks length itself */ @@ -130,18 +202,18 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { EPC MS for Main Header: if we are here it's required */ /* create the EPC */ - if (epc_mark = jpwl_epc_create( + if ((epc_mark = jpwl_epc_create( j2k, j2k->cp->esd_on, /* is ESD present? */ j2k->cp->red_on, /* is RED present? */ j2k->cp->epb_on, /* is EPB present? */ false /* are informative techniques present? */ - )) { + ))) { /* Add this marker to the 'insertanda' list */ if (epc_mark) { jwmarker[jwmarker_num].id = J2K_MS_EPC; /* its type */ - jwmarker[jwmarker_num].epcmark = epc_mark; /* the EPC */ + jwmarker[jwmarker_num].m.epcmark = epc_mark; /* the EPC */ jwmarker[jwmarker_num].pos = soc_pos + socsiz_len; /* after SIZ */ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.1; /* not so first */ jwmarker[jwmarker_num].len = epc_mark->Lepc; /* its length */ @@ -171,7 +243,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { if (j2k->cp->esd_on && (j2k->cp->sens_MH >= 0)) { /* Create the ESD */ - if (esd_mark = jpwl_esd_create( + if ((esd_mark = jpwl_esd_create( j2k, /* this encoder handle */ -1, /* we are averaging over all components */ (unsigned char) j2k->cp->sens_range, /* range method */ @@ -181,12 +253,12 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { -1, /* this ESD is in main header */ 0 /*j2k->cstr_info->num*/, /* number of packets in codestream */ NULL /*sensval*/ /* pointer to sensitivity data of packets */ - )) { + ))) { /* Add this marker to the 'insertanda' list */ if (jwmarker_num < JPWL_MAX_NO_MARKERS) { jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */ - jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */ + jwmarker[jwmarker_num].m.esdmark = esd_mark; /* the EPB */ jwmarker[jwmarker_num].pos = soc_pos + socsiz_len; /* we choose to place it after SIZ */ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */ jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */ @@ -232,7 +304,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { unsigned long int left_THmarks_len; /******* sot_pos = j2k->cstr_info->tile[tileno].start_pos; */ - sot_pos = j2k->cstr_info->tile[tileno].tp_start_pos[tpno]; + sot_pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos; cio_seek(cio, sot_pos + 2); sot_len = cio_read(cio, 2); /* SOT Len */ cio_skip(cio, 2); @@ -240,7 +312,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { Psot = cio_read(cio, 4); /* tile length */ /******* post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1; */ - post_sod_pos = j2k->cstr_info->tile[tileno].tp_end_header[tpno] + 1; + post_sod_pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_end_header + 1; left_THmarks_len = post_sod_pos - sot_pos; /* add all the lengths of the markers which are len-ready and stay within SOT and SOD */ @@ -265,7 +337,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { if (j2k->cp->esd_on && (sens >= 0)) { /* Create the ESD */ - if (esd_mark = jpwl_esd_create( + if ((esd_mark = jpwl_esd_create( j2k, /* this encoder handle */ -1, /* we are averaging over all components */ (unsigned char) j2k->cp->sens_range, /* range method */ @@ -275,14 +347,14 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { tileno, /* this ESD is in a tile */ 0, /* number of packets in codestream */ NULL /* pointer to sensitivity data of packets */ - )) { + ))) { /* Add this marker to the 'insertanda' list */ if (jwmarker_num < JPWL_MAX_NO_MARKERS) { jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */ - jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */ + jwmarker[jwmarker_num].m.esdmark = esd_mark; /* the EPB */ /****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */ - jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp_start_pos[tpno] + sot_len + 2; /* after SOT */ + jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */ jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */ jwmarker[jwmarker_num].len_ready = true; /* ready, yet */ @@ -344,7 +416,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { } /* Create the EPB */ - if (epb_mark = jpwl_epb_create( + if ((epb_mark = jpwl_epb_create( j2k, /* this encoder handle */ true, /* is it the latest? */ true, /* is it packed? not for now */ @@ -353,12 +425,12 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { j2k->cp->hprot_MH, /* protection type parameters of data */ socsiz_len, /* pre-data: only SOC+SIZ */ left_MHmarks_len /* post-data: from SOC to SOT, and all JPWL markers within */ - )) { + ))) { /* Add this marker to the 'insertanda' list */ if (jwmarker_num < JPWL_MAX_NO_MARKERS) { jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */ - jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */ + jwmarker[jwmarker_num].m.epbmark = epb_mark; /* the EPB */ jwmarker[jwmarker_num].pos = soc_pos + socsiz_len; /* after SIZ */ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */ jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */ @@ -402,13 +474,13 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { int sot_len, Psot, Psotp, mm, epb_index = 0, prot_len = 0; unsigned long sot_pos, post_sod_pos; - unsigned long int left_THmarks_len, epbs_len = 0; - int startpack = 0, stoppack = j2k->cstr_info->num; + unsigned long int left_THmarks_len/*, epbs_len = 0*/; + int startpack = 0, stoppack = j2k->cstr_info->packno; int first_tp_pack, last_tp_pack; jpwl_epb_ms_t *tph_epb = NULL; /****** sot_pos = j2k->cstr_info->tile[tileno].start_pos; */ - sot_pos = j2k->cstr_info->tile[tileno].tp_start_pos[tpno]; + sot_pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos; cio_seek(cio, sot_pos + 2); sot_len = cio_read(cio, 2); /* SOT Len */ cio_skip(cio, 2); @@ -417,7 +489,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { /* a-priori length of the data dwelling between SOT and SOD */ /****** post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1; */ - post_sod_pos = j2k->cstr_info->tile[tileno].tp_end_header[tpno] + 1; + post_sod_pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_end_header + 1; left_THmarks_len = post_sod_pos - (sot_pos + sot_len + 2); /* add all the lengths of the JPWL markers which are len-ready and stay within SOT and SOD */ @@ -442,7 +514,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { if (j2k->cp->epb_on && (hprot > 0)) { /* Create the EPB */ - if (epb_mark = jpwl_epb_create( + if ((epb_mark = jpwl_epb_create( j2k, /* this encoder handle */ false, /* is it the latest? in TPH, no for now (if huge data size in TPH, we'd need more) */ true, /* is it packed? yes for now */ @@ -451,14 +523,14 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { hprot, /* protection type parameters of following data */ sot_len + 2, /* pre-data length: only SOT */ left_THmarks_len /* post-data length: from SOT end to SOD inclusive */ - )) { + ))) { /* Add this marker to the 'insertanda' list */ if (jwmarker_num < JPWL_MAX_NO_MARKERS) { jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */ - jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */ + jwmarker[jwmarker_num].m.epbmark = epb_mark; /* the EPB */ /****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */ - jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp_start_pos[tpno] + sot_len + 2; /* after SOT */ + jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */ jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */ jwmarker[jwmarker_num].len_ready = true; /* ready */ @@ -493,9 +565,10 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { startpack = 0; /* EPB MSs for UEP packet data protection in Tile Parts */ /****** for (packno = 0; packno < j2k->cstr_info->num; packno++) { */ - first_tp_pack = (tpno > 0) ? (first_tp_pack + j2k->cstr_info->tile[tileno].tp_num[tpno - 1]) : 0; - last_tp_pack = first_tp_pack + j2k->cstr_info->tile[tileno].tp_num[tpno] - 1; - for (packno = 0; packno < j2k->cstr_info->tile[tileno].tp_num[tpno]; packno++) { + /*first_tp_pack = (tpno > 0) ? (first_tp_pack + j2k->cstr_info->tile[tileno].tp[tpno - 1].tp_numpacks) : 0;*/ + first_tp_pack = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pack; + last_tp_pack = first_tp_pack + j2k->cstr_info->tile[tileno].tp[tpno].tp_numpacks - 1; + for (packno = 0; packno < j2k->cstr_info->tile[tileno].tp[tpno].tp_numpacks; packno++) { /******** if ((packspec < JPWL_MAX_NO_PACKSPECS) && (j2k->cp->pprot_tileno[packspec] == tileno) && (j2k->cp->pprot_packno[packspec] == packno)) { */ @@ -547,7 +620,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { &epb_index, /* pointer to EPB index */ pprot, /* protection type */ /****** (double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, */ /* position */ - (double) (j2k->cstr_info->tile[tileno].tp_start_pos[tpno] + sot_len + 2) + 0.0001, /* position */ + (double) (j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2) + 0.0001, /* position */ tileno, /* number of tile */ 0, /* length of pre-data */ prot_len /*4000*/ /* length of post-data */ @@ -607,7 +680,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { &epb_index, /* pointer to EPB index */ pprot, /* protection type */ /***** (double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001,*/ /* position */ - (double) (j2k->cstr_info->tile[tileno].tp_start_pos[tpno] + sot_len + 2) + 0.0001, /* position */ + (double) (j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2) + 0.0001, /* position */ tileno, /* number of tile */ 0, /* length of pre-data */ prot_len /*4000*/ /* length of post-data */ @@ -639,7 +712,7 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { int mm; unsigned long int old_size = j2k->cstr_info->codestream_size; unsigned long int new_size = old_size; - int ciopos = cio_tell(cio), soc_pos = j2k->cstr_info->main_head_start; + int /*ciopos = cio_tell(cio),*/ soc_pos = j2k->cstr_info->main_head_start; unsigned char *jpwl_buf, *orig_buf; unsigned long int orig_pos; double epbcoding_time = 0.0, esdcoding_time = 0.0; @@ -647,23 +720,23 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { /* Order JPWL markers according to their wishlist position */ qsort((void *) jwmarker, (size_t) jwmarker_num, sizeof (jpwl_marker_t), jpwl_markcomp); - /* compute markers total size */ + /* compute markers total size */ for (mm = 0; mm < jwmarker_num; mm++) { /*printf("%x, %d, %.10f, %d long\n", jwmarker[mm].id, jwmarker[mm].pos, jwmarker[mm].dpos, jwmarker[mm].len);*/ new_size += jwmarker[mm].len + 2; } - /* allocate a temporary buffer of proper size */ - if (!(jpwl_buf = (unsigned char *) opj_malloc((size_t) new_size * sizeof (unsigned char)))) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for JPWL temp codestream buffer\n"); + /* allocate a new buffer of proper size */ + if (!(jpwl_buf = (unsigned char *) opj_malloc((size_t) (new_size + soc_pos) * sizeof(unsigned char)))) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for JPWL codestream buffer\n"); exit(1); }; /* copy the jp2 part, if any */ - memcpy(jpwl_buf, cio->buffer, soc_pos); - orig_buf = jpwl_buf; + memcpy(jpwl_buf, cio->buffer, soc_pos); + jpwl_buf += soc_pos; /* cycle through markers */ orig_pos = soc_pos + 0; /* start from the beginning */ @@ -685,15 +758,15 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { switch (jwmarker[mm].id) { case J2K_MS_EPB: - jpwl_epb_write(jwmarker[mm].epbmark, jpwl_buf); + jpwl_epb_write(j2k, jwmarker[mm].m.epbmark, jpwl_buf); break; case J2K_MS_EPC: - jpwl_epc_write(jwmarker[mm].epcmark, jpwl_buf); + jpwl_epc_write(j2k, jwmarker[mm].m.epcmark, jpwl_buf); break; case J2K_MS_ESD: - jpwl_esd_write(jwmarker[mm].esdmark, jpwl_buf); + jpwl_esd_write(j2k, jwmarker[mm].m.esdmark, jpwl_buf); break; case J2K_MS_RED: @@ -704,6 +777,10 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { break; }; + /* we update the markers struct */ + if (j2k->cstr_info) + j2k->cstr_info->marker[j2k->cstr_info->marknum - 1].pos = (jpwl_buf - orig_buf); + /* we set the marker dpos to the new position in the JPWL codestream */ jwmarker[mm].dpos = (double) (jpwl_buf - orig_buf); @@ -713,8 +790,8 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { } /* finish remaining original codestream */ - memcpy(jpwl_buf, cio_getbp(cio), soc_pos + old_size - orig_pos); - jpwl_buf += soc_pos + old_size - orig_pos; + memcpy(jpwl_buf, cio_getbp(cio), old_size - (orig_pos - soc_pos)); + jpwl_buf += old_size - (orig_pos - soc_pos); cio_seek(cio, soc_pos + old_size); /* @@ -735,11 +812,11 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { unsigned short int mycrc = 0x0000; /* fix and fill the DL field */ - jwmarker[mm].epcmark->DL = new_size; - orig_buf[epc_pos + 6] = (unsigned char) (jwmarker[mm].epcmark->DL >> 24); - orig_buf[epc_pos + 7] = (unsigned char) (jwmarker[mm].epcmark->DL >> 16); - orig_buf[epc_pos + 8] = (unsigned char) (jwmarker[mm].epcmark->DL >> 8); - orig_buf[epc_pos + 9] = (unsigned char) (jwmarker[mm].epcmark->DL >> 0); + jwmarker[mm].m.epcmark->DL = new_size; + orig_buf[epc_pos + 6] = (unsigned char) (jwmarker[mm].m.epcmark->DL >> 24); + orig_buf[epc_pos + 7] = (unsigned char) (jwmarker[mm].m.epcmark->DL >> 16); + orig_buf[epc_pos + 8] = (unsigned char) (jwmarker[mm].m.epcmark->DL >> 8); + orig_buf[epc_pos + 9] = (unsigned char) (jwmarker[mm].m.epcmark->DL >> 0); /* compute the CRC field (excluding itself) */ for (pp = 0; pp < 4; pp++) @@ -748,9 +825,9 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { jpwl_updateCRC16(&mycrc, orig_buf[epc_pos + pp]); /* fix and fill the CRC */ - jwmarker[mm].epcmark->Pcrc = mycrc; - orig_buf[epc_pos + 4] = (unsigned char) (jwmarker[mm].epcmark->Pcrc >> 8); - orig_buf[epc_pos + 5] = (unsigned char) (jwmarker[mm].epcmark->Pcrc >> 0); + jwmarker[mm].m.epcmark->Pcrc = mycrc; + orig_buf[epc_pos + 4] = (unsigned char) (jwmarker[mm].m.epcmark->Pcrc >> 8); + orig_buf[epc_pos + 5] = (unsigned char) (jwmarker[mm].m.epcmark->Pcrc >> 0); } } @@ -765,7 +842,7 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { /* remember that they are now in a new position (dpos) */ int esd_pos = (int) jwmarker[mm].dpos; - jpwl_esd_fill(j2k, jwmarker[mm].esdmark, &orig_buf[esd_pos]); + jpwl_esd_fill(j2k, jwmarker[mm].m.esdmark, &orig_buf[esd_pos]); } @@ -790,16 +867,16 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { accum_len = 0; for (nn = mm; (nn < jwmarker_num) && (jwmarker[nn].id == J2K_MS_EPB) && (jwmarker[nn].pos == jwmarker[mm].pos); nn++) - accum_len += jwmarker[nn].epbmark->Lepb + 2; + accum_len += jwmarker[nn].m.epbmark->Lepb + 2; /* fill the current (first) EPB with post-data starting from the computed position */ - jpwl_epb_fill(j2k, jwmarker[mm].epbmark, &orig_buf[(int) jwmarker[mm].dpos], + jpwl_epb_fill(j2k, jwmarker[mm].m.epbmark, &orig_buf[(int) jwmarker[mm].dpos], &orig_buf[(int) jwmarker[mm].dpos + accum_len]); /* fill the remaining EPBs in the header with post-data starting from the last position */ for (nn = mm + 1; (nn < jwmarker_num) && (jwmarker[nn].id == J2K_MS_EPB) && (jwmarker[nn].pos == jwmarker[mm].pos); nn++) - jpwl_epb_fill(j2k, jwmarker[nn].epbmark, &orig_buf[(int) jwmarker[nn].dpos], NULL); + jpwl_epb_fill(j2k, jwmarker[nn].m.epbmark, &orig_buf[(int) jwmarker[nn].dpos], NULL); /* skip all the processed EPBs */ mm = nn - 1; @@ -812,13 +889,13 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { /* free original cio buffer and set it to the JPWL one */ opj_free(cio->buffer); - /*cio->cinfo;*/ /* no change */ - /*cio->openmode;*/ /* no change */ - cio->buffer = jpwl_buf - new_size - soc_pos; + cio->cinfo = cio->cinfo; /* no change */ + cio->openmode = cio->openmode; /* no change */ + cio->buffer = orig_buf; cio->length = new_size + soc_pos; - cio->start = jpwl_buf - new_size - soc_pos; - cio->end = jpwl_buf - 1; - cio->bp = jpwl_buf - new_size - soc_pos; + cio->start = cio->buffer; + cio->end = cio->buffer + cio->length; + cio->bp = cio->buffer; cio_seek(cio, soc_pos + new_size); } @@ -930,6 +1007,10 @@ void j2k_write_epc(opj_j2k_t *j2k) { cio_write(cio, Pcrc, 2); cio_seek(cio, Lepcp + Lepc); + + /* marker struct update */ + j2k_add_marker(j2k->cstr_info, J2K_MS_EPC, Lepcp - 2, Lepc + 2); + } void j2k_read_epb(opj_j2k_t *j2k) { @@ -1025,9 +1106,9 @@ void j2k_read_epb(opj_j2k_t *j2k) { if (((Pepb & 0xF0000000) >> 28) == 0) sprintf(str1, "pred"); /* predefined */ else if (((Pepb & 0xF0000000) >> 28) == 1) - sprintf(str1, "crc-%d", 16 * ((Pepb & 0x00000001) + 1)); /* CRC mode */ + sprintf(str1, "crc-%lu", 16 * ((Pepb & 0x00000001) + 1)); /* CRC mode */ else if (((Pepb & 0xF0000000) >> 28) == 2) - sprintf(str1, "rs(%d,32)", (Pepb & 0x0000FF00) >> 8); /* RS mode */ + sprintf(str1, "rs(%lu,32)", (Pepb & 0x0000FF00) >> 8); /* RS mode */ else if (Pepb == 0xFFFFFFFF) sprintf(str1, "nometh"); /* RS mode */ else @@ -1078,6 +1159,9 @@ void j2k_write_epb(opj_j2k_t *j2k) { cio_write(cio, Lepb, 2); /* Lepb */ cio_seek(cio, Lepbp + Lepb); + + /* marker struct update */ + j2k_add_marker(j2k->cstr_info, J2K_MS_EPB, Lepbp - 2, Lepb + 2); } void j2k_read_esd(opj_j2k_t *j2k) { @@ -1135,6 +1219,7 @@ void j2k_read_red(opj_j2k_t *j2k) { bool jpwl_check_tile(opj_j2k_t *j2k, opj_tcd_t *tcd, int tileno) { +#ifdef oerhgierhgvhreit4u /* we navigate through the tile and find possible invalid parameters: this saves a lot of crashes!!!!! @@ -1196,6 +1281,8 @@ bool jpwl_check_tile(opj_j2k_t *j2k, opj_tcd_t *tcd, int tileno) { } } +#endif + return true; }