diff options
| author | Giuseppe Baruffa <gbaruffa@users.noreply.github.com> | 2007-09-07 23:16:31 +0000 |
|---|---|---|
| committer | Giuseppe Baruffa <gbaruffa@users.noreply.github.com> | 2007-09-07 23:16:31 +0000 |
| commit | d70a0415b910cc5a3550fea1d777ded84d4cdfa0 (patch) | |
| tree | 9d73e44534b437db7144bff8b64653bc42a07302 /jpwl | |
| parent | 3816e0edf40b766ab78cdbf3ba5634b684630d0f (diff) | |
Adapted the JPWL and OPJViewer code to new interface; fixed a samll bug in JPWL which created large EPBs even when null protection was specified
Diffstat (limited to 'jpwl')
| -rw-r--r-- | jpwl/jpwl.c | 24 | ||||
| -rw-r--r-- | jpwl/jpwl_lib.c | 40 |
2 files changed, 35 insertions, 29 deletions
diff --git a/jpwl/jpwl.c b/jpwl/jpwl.c index f97331d4..7a307839 100644 --- a/jpwl/jpwl.c +++ b/jpwl/jpwl.c @@ -232,7 +232,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 +240,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 */
@@ -282,7 +282,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */
jwmarker[jwmarker_num].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 = soc_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 */
@@ -403,12 +403,12 @@ 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;
+ 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 +417,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 */
@@ -458,7 +458,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */
jwmarker[jwmarker_num].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 = soc_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 +493,9 @@ 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;
+ 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 +547,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 +607,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 */
diff --git a/jpwl/jpwl_lib.c b/jpwl/jpwl_lib.c index 7ebe236f..7839249c 100644 --- a/jpwl/jpwl_lib.c +++ b/jpwl/jpwl_lib.c @@ -32,6 +32,7 @@ #ifdef USE_JPWL #include "../libopenjpeg/opj_includes.h" +#include <limits.h> /** Minimum and maximum values for the double->pfp conversion */ #define MIN_V1 0.0 @@ -143,6 +144,11 @@ int jpwl_epbs_add(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int *jwmarker_num, /* (message word size) * (number of containable parity words) */ max_postlen = k_post * (unsigned long int) floor((double) JPWL_MAXIMUM_EPB_ROOM / (double) (n_post - k_post)); + /* null protection case */ + /* the max post length can be as large as the LDPepb field can host */ + if (hprot == 0) + max_postlen = INT_MAX; + /* length to use */ dL4 = min(max_postlen, post_len); @@ -651,7 +657,7 @@ bool jpwl_correct(opj_j2k_t *j2k) { j2k->state = J2K_STATE_MHSOC; /* cycle all over the markers */ - while (cio_tell(cio) < cio->length) { + while ((unsigned int) cio_tell(cio) < cio->length) { /* read the marker */ mark_pos = cio_tell(cio); @@ -1225,7 +1231,7 @@ jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comp, unsigned char addrm, un /* auto sense address size */ if (ad_size == 0) /* if there are more than 2^16 - 1 packets, switch to 4 bytes */ - ad_size = (j2k->cstr_info->num > 65535) ? 4 : 2; + ad_size = (j2k->cstr_info->packno > 65535) ? 4 : 2; esd->sensval_size = ad_size + ad_size + se_size; break; @@ -1246,17 +1252,17 @@ jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comp, unsigned char addrm, un /* just based on the portions of a codestream */ case (0): /* MH + no. of THs + no. of packets */ - svalnum = 1 + (j2k->cstr_info->tw * j2k->cstr_info->th) * (1 + j2k->cstr_info->num); + svalnum = 1 + (j2k->cstr_info->tw * j2k->cstr_info->th) * (1 + j2k->cstr_info->packno); break; /* all the ones that are based on the packets */ default: if (tileno < 0) /* MH: all the packets and all the tiles info is written */ - svalnum = j2k->cstr_info->tw * j2k->cstr_info->th * j2k->cstr_info->num; + svalnum = j2k->cstr_info->tw * j2k->cstr_info->th * j2k->cstr_info->packno; else /* TPH: only that tile info is written */ - svalnum = j2k->cstr_info->num; + svalnum = j2k->cstr_info->packno; break; } @@ -1356,9 +1362,9 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) { buf += 7; /* let's fill the data fields */ - for (vv = (esd->tileno < 0) ? 0 : (j2k->cstr_info->num * esd->tileno); vv < esd->svalnum; vv++) { + for (vv = (esd->tileno < 0) ? 0 : (j2k->cstr_info->packno * esd->tileno); vv < esd->svalnum; vv++) { - int thistile = vv / j2k->cstr_info->num, thispacket = vv % j2k->cstr_info->num; + int thistile = vv / j2k->cstr_info->packno, thispacket = vv % j2k->cstr_info->packno; /* skip for the hack some lines below */ if (thistile == j2k->cstr_info->tw * j2k->cstr_info->th) @@ -1367,7 +1373,7 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) { /* starting tile distortion */ if (thispacket == 0) { TSE = j2k->cstr_info->tile[thistile].distotile; - oldMSE = TSE / j2k->cstr_info->tile[thistile].nbpix; + oldMSE = TSE / j2k->cstr_info->tile[thistile].numpix; oldPSNR = 10.0 * log10(Omax2 / oldMSE); } @@ -1375,7 +1381,7 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) { TSE -= j2k->cstr_info->tile[thistile].packet[thispacket].disto; /* MSE */ - MSE = TSE / j2k->cstr_info->tile[thistile].nbpix; + MSE = TSE / j2k->cstr_info->tile[thistile].numpix; /* PSNR */ PSNR = 10.0 * log10(Omax2 / MSE); @@ -1484,7 +1490,7 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) { else /* packet: first is most important, and then in decreasing order down to the last, which counts for 1 */ - dvalue = jpwl_pfp_to_double((unsigned short) (j2k->cstr_info->num - thispacket), esd->se_size); + dvalue = jpwl_pfp_to_double((unsigned short) (j2k->cstr_info->packno - thispacket), esd->se_size); break; /* MSE */ @@ -1658,7 +1664,7 @@ bool jpwl_update_info(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int jwmarker_num) unsigned long int addlen; opj_codestream_info_t *info = j2k->cstr_info; - int tileno, tpno, packno, numtiles = info->th * info->tw, numpacks = info->num; + int tileno, tpno, packno, numtiles = info->th * info->tw, numpacks = info->packno; if (!j2k || !jwmarker ) { opj_event_msg(j2k->cinfo, EVT_ERROR, "J2K handle or JPWL markers list badly allocated\n"); @@ -1709,23 +1715,23 @@ bool jpwl_update_info(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int jwmarker_num) /* start_pos: increment with markers before SOT */ addlen = 0; for (mm = 0; mm < jwmarker_num; mm++) - if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].tp_start_pos[tpno]) + if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].tp[tpno].tp_start_pos) addlen += jwmarker[mm].len + 2; - info->tile[tileno].tp_start_pos[tpno] += addlen; + info->tile[tileno].tp[tpno].tp_start_pos += addlen; /* end_header: increment with markers before of it */ addlen = 0; for (mm = 0; mm < jwmarker_num; mm++) - if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].tp_end_header[tpno]) + if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].tp[tpno].tp_end_header) addlen += jwmarker[mm].len + 2; - info->tile[tileno].tp_end_header[tpno] += addlen; + info->tile[tileno].tp[tpno].tp_end_header += addlen; /* end_pos: increment with markers before the end of this tile part */ addlen = 0; for (mm = 0; mm < jwmarker_num; mm++) - if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].tp_end_pos[tpno]) + if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].tp[tpno].tp_end_pos) addlen += jwmarker[mm].len + 2; - info->tile[tileno].tp_end_pos[tpno] += addlen; + info->tile[tileno].tp[tpno].tp_end_pos += addlen; } |
