#ifdef USE_JPWL
fprintf(stdout,"-W : adoption of JPWL (Part 11) capabilities (-W params)\n");
fprintf(stdout," The parameters can be written and repeated in any order:\n");
- fprintf(stdout," [h<tile><=type>,s<tile><=method>,a=<addr>,z=<size>,g=<range>,...\n");
- fprintf(stdout," ...,p<tile:pack><=type>]\n");
+ fprintf(stdout," [h<tilepart><=type>,s<tilepart><=method>,a=<addr>,...\n");
+ fprintf(stdout," ...,z=<size>,g=<range>,p<tilepart:pack><=type>]\n");
fprintf(stdout,"\n");
fprintf(stdout," h selects the header error protection (EPB): 'type' can be\n");
fprintf(stdout," [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n");
- fprintf(stdout," if 'tile' is absent, it applies to main and tile headers\n");
- fprintf(stdout," if 'tile' is present, it applies from that tile\n");
- fprintf(stdout," onwards, up to the next h<tile> spec, or to the last tile\n");
+ fprintf(stdout," if 'tilepart' is absent, it is for main and tile headers\n");
+ fprintf(stdout," if 'tilepart' is present, it applies from that tile\n");
+ fprintf(stdout," onwards, up to the next h<> spec, or to the last tilepart\n");
fprintf(stdout," in the codestream (max. %d specs)\n", JPWL_MAX_NO_TILESPECS);
fprintf(stdout,"\n");
fprintf(stdout," p selects the packet error protection (EEP/UEP with EPBs)\n");
fprintf(stdout," to be applied to raw data: 'type' can be\n");
fprintf(stdout," [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n");
- fprintf(stdout," if 'tile:pack' is absent, it starts from tile 0, packet 0\n");
- fprintf(stdout," if 'tile:pack' is present, it applies from that tile\n");
+ fprintf(stdout," if 'tilepart:pack' is absent, it is from tile 0, packet 0\n");
+ fprintf(stdout," if 'tilepart:pack' is present, it applies from that tile\n");
fprintf(stdout," and that packet onwards, up to the next packet spec\n");
- fprintf(stdout," or to the last packet in the last tile in the codestream\n");
+ fprintf(stdout," or to the last packet in the last tilepart in the stream\n");
fprintf(stdout," (max. %d specs)\n", JPWL_MAX_NO_PACKSPECS);
fprintf(stdout,"\n");
fprintf(stdout," s enables sensitivity data insertion (ESD): 'method' can be\n");
fprintf(stdout," [-1=NO ESD 0=RELATIVE ERROR 1=MSE 2=MSE REDUCTION 3=PSNR\n");
fprintf(stdout," 4=PSNR INCREMENT 5=MAXERR 6=TSE 7=RESERVED]\n");
- fprintf(stdout," if 'tile' is absent, it applies to main header only\n");
- fprintf(stdout," if 'tile' is present, it applies from that tile\n");
- fprintf(stdout," onwards, up to the next s<tile> spec, or to the last tile\n");
+ fprintf(stdout," if 'tilepart' is absent, it is for main header only\n");
+ fprintf(stdout," if 'tilepart' is present, it applies from that tile\n");
+ fprintf(stdout," onwards, up to the next s<> spec, or to the last tilepart\n");
fprintf(stdout," in the codestream (max. %d specs)\n", JPWL_MAX_NO_TILESPECS);
fprintf(stdout,"\n");
fprintf(stdout," g determines the addressing mode: <range> can be\n");
fprintf(stdout," 1/2 bytes, for the transformed pseudo-floating point value\n");
fprintf(stdout,"\n");
fprintf(stdout," ex.:\n");
- fprintf(stdout," h,h0=64,h3=16,h5=32,p0=78,p0:24=56,p1,p3:0=0,p3:20=32,s=0,s0=6,s3=-1,a=0,g=1,z=1\n");
+ fprintf(stdout," h,h0=64,h3=16,h5=32,p0=78,p0:24=56,p1,p3:0=0,p3:20=32,s=0,\n");
+ fprintf(stdout," s0=6,s3=-1,a=0,g=1,z=1\n");
fprintf(stdout," means\n");
fprintf(stdout," predefined EPB in MH, rs(64,32) from TPH 0 to TPH 2,\n");
fprintf(stdout," CRC-16 in TPH 3 and TPH 4, CRC-32 in remaining TPHs,\n");
fprintf(stdout," UEP rs(78,32) for packets 0 to 23 of tile 0,\n");
- fprintf(stdout," UEP rs(56,32) for packets 24 to the last of tile 0,\n");
- fprintf(stdout," UEP rs default for packets of tile 1,\n");
- fprintf(stdout," no UEP for packets 0 to 19 of tile 3,\n");
- fprintf(stdout," UEP CRC-32 for packets 20 of tile 3 to last tile,\n");
+ fprintf(stdout," UEP rs(56,32) for packs. 24 to the last of tilepart 0,\n");
+ fprintf(stdout," UEP rs default for packets of tilepart 1,\n");
+ fprintf(stdout," no UEP for packets 0 to 19 of tilepart 3,\n");
+ fprintf(stdout," UEP CRC-32 for packs. 20 of tilepart 3 to last tilepart,\n");
fprintf(stdout," relative sensitivity ESD for MH,\n");
fprintf(stdout," TSE ESD from TPH 0 to TPH 2, byte range with automatic\n");
fprintf(stdout," size of addresses and 1 byte for each sensitivity value\n");
double total_disto = 0;
/* UniPG>> */
int tilepartno;
+
+#ifdef USE_JPWL
+ if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))
+ return 0;
+#endif /* USE_JPWL */
/* <<UniPG */
if (!cstr_info)
fprintf(stream, "\nTILE %d DETAILS\n", tileno);
/* UniPG>> */
- fprintf(stream, "part_nb tileno start_pos end_tph_pos end_pos\n");
+ fprintf(stream, "part_nb tileno pack_nb start_pos end_tph_pos end_pos\n");
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
- fprintf(stream, "%4d %9d %9d %11d %9d\n",
+ fprintf(stream, "%4d %9d %9d %9d %11d %9d\n",
tilepartno, tileno,
+ cstr_info->tile[tileno].tp_num[tilepartno],
cstr_info->tile[tileno].tp_start_pos[tilepartno],
cstr_info->tile[tileno].tp_end_header[tilepartno],
cstr_info->tile[tileno].tp_end_pos[tilepartno]
/* Tile part header, specified */
if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) ||
((hprot >= 37) && (hprot <= 128)))) {
- fprintf(stderr, "ERROR -> invalid tile header protection method h = %d\n", hprot);
+ fprintf(stderr, "ERROR -> invalid tile part header protection method h = %d\n", hprot);
return 1;
}
if (tile < 0) {
- fprintf(stderr, "ERROR -> invalid tile number on protection method t = %d\n", tile);
+ fprintf(stderr, "ERROR -> invalid tile part number on protection method t = %d\n", tile);
return 1;
}
if (tilespec < JPWL_MAX_NO_TILESPECS) {
} else if(sscanf(token, "h%d", &tile) == 1) {
/* Tile part header, unspecified */
if (tile < 0) {
- fprintf(stderr, "ERROR -> invalid tile number on protection method t = %d\n", tile);
+ fprintf(stderr, "ERROR -> invalid tile part number on protection method t = %d\n", tile);
return 1;
}
if (tilespec < JPWL_MAX_NO_TILESPECS) {
return 1;
}
if (tile < 0) {
- fprintf(stderr, "ERROR -> invalid tile number on protection method p = %d\n", tile);
+ fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile);
return 1;
}
if (packspec < JPWL_MAX_NO_PACKSPECS) {
return 1;
}
if (tile < 0) {
- fprintf(stderr, "ERROR -> invalid tile number on protection method p = %d\n", tile);
+ fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile);
return 1;
}
if (pack < 0) {
return 1;
}
if (tile < 0) {
- fprintf(stderr, "ERROR -> invalid tile number on protection method p = %d\n", tile);
+ fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile);
return 1;
}
if (pack < 0) {
} else if (sscanf(token, "p%d", &tile) == 1) {
/* default from a tile on */
if (tile < 0) {
- fprintf(stderr, "ERROR -> invalid tile number on protection method p = %d\n", tile);
+ fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile);
return 1;
}
if (packspec < JPWL_MAX_NO_PACKSPECS) {
} else if(sscanf(token, "s%d=%d", &tile, &sens) == 2) {
/* Tile part header, specified */
if ((sens < -1) || (sens > 7)) {
- fprintf(stderr, "ERROR -> invalid tile header sensitivity method s = %d\n", sens);
+ fprintf(stderr, "ERROR -> invalid tile part header sensitivity method s = %d\n", sens);
return 1;
}
if (tile < 0) {
- fprintf(stderr, "ERROR -> invalid tile number on sensitivity method t = %d\n", tile);
+ fprintf(stderr, "ERROR -> invalid tile part number on sensitivity method t = %d\n", tile);
return 1;
}
if (tilespec < JPWL_MAX_NO_TILESPECS) {
} else if(sscanf(token, "s%d", &tile) == 1) {
/* Tile part header, unspecified */
if (tile < 0) {
- fprintf(stderr, "ERROR -> invalid tile number on sensitivity method t = %d\n", tile);
+ fprintf(stderr, "ERROR -> invalid tile part number on sensitivity method t = %d\n", tile);
return 1;
}
if (tilespec < JPWL_MAX_NO_TILESPECS) {
void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {\r
\r
unsigned short int socsiz_len = 0;\r
- int ciopos = cio_tell(cio);\r
+ int ciopos = cio_tell(cio), soc_pos = j2k->cstr_info->main_head_start;\r
unsigned char *socp = NULL;\r
\r
- int tileno, tilespec, hprot, sens, pprot, packspec, lastileno, packno;\r
+ int tileno, acc_tpno, tpno, tilespec, hprot, sens, pprot, packspec, lastileno, packno;\r
\r
jpwl_epb_ms_t *epb_mark;\r
jpwl_epc_ms_t *epc_mark;\r
\r
/* find SOC + SIZ length */\r
/* I assume SIZ is always the first marker after SOC */\r
- cio_seek(cio, 4);\r
+ cio_seek(cio, soc_pos + 4);\r
socsiz_len = (unsigned short int) cio_read(cio, 2) + 4; /* add the 2 marks length itself */\r
- cio_seek(cio, 0);\r
+ cio_seek(cio, soc_pos + 0);\r
socp = cio_getbp(cio); /* pointer to SOC */\r
\r
/* \r
if (epc_mark) {\r
jwmarker[jwmarker_num].id = J2K_MS_EPC; /* its type */\r
jwmarker[jwmarker_num].epcmark = epc_mark; /* the EPC */\r
- jwmarker[jwmarker_num].pos = socsiz_len; /* after SIZ */\r
+ jwmarker[jwmarker_num].pos = soc_pos + socsiz_len; /* after SIZ */\r
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.1; /* not so first */\r
jwmarker[jwmarker_num].len = epc_mark->Lepc; /* its length */\r
jwmarker[jwmarker_num].len_ready = true; /* ready */\r
if (jwmarker_num < JPWL_MAX_NO_MARKERS) {\r
jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */\r
jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */\r
- jwmarker[jwmarker_num].pos = socsiz_len; /* we choose to place it after SIZ */\r
+ jwmarker[jwmarker_num].pos = soc_pos + socsiz_len; /* we choose to place it after SIZ */\r
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */\r
jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */\r
jwmarker[jwmarker_num].len_ready = true; /* not ready, yet */\r
/* \r
ESD MSs for Tile Part Headers \r
*/\r
- /* cycle through TPHs */\r
+ /* cycle through tiles */\r
sens = -1; /* default spec: no ESD */\r
tilespec = 0; /* first tile spec */\r
+ acc_tpno = 0;\r
for (tileno = 0; tileno < j2k->cstr_info->tw * j2k->cstr_info->th; tileno++) {\r
\r
- int sot_len, Psot, Psotp, mm;\r
- unsigned long sot_pos, post_sod_pos;\r
-\r
- unsigned long int left_THmarks_len;\r
-\r
- sot_pos = j2k->cstr_info->tile[tileno].start_pos;\r
- cio_seek(cio, sot_pos + 2); \r
- sot_len = cio_read(cio, 2); /* SOT Len */\r
- cio_skip(cio, 2);\r
- Psotp = cio_tell(cio);\r
- Psot = cio_read(cio, 4); /* tile length */\r
-\r
- post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1;\r
- left_THmarks_len = post_sod_pos - sot_pos;\r
+ opj_event_msg(j2k->cinfo, EVT_INFO,\r
+ "Tile %d has %d tile part(s)\n",\r
+ tileno, j2k->cstr_info->tile[tileno].num_tps\r
+ );\r
\r
- /* add all the lengths of the markers which are len-ready and stay within SOT and SOD */\r
- for (mm = 0; mm < jwmarker_num; mm++) {\r
- if ((jwmarker[mm].pos >= sot_pos) && (jwmarker[mm].pos < post_sod_pos)) {\r
- if (jwmarker[mm].len_ready)\r
- left_THmarks_len += jwmarker[mm].len + 2;\r
- else {\r
- opj_event_msg(j2k->cinfo, EVT_ERROR, "MS %x in %f is not len-ready: could not set up TH EPB\n",\r
- jwmarker[mm].id, jwmarker[mm].dpos); \r
- exit(1);\r
+ /* for every tile part in the tile */\r
+ for (tpno = 0; tpno < j2k->cstr_info->tile[tileno].num_tps; tpno++, acc_tpno++) {\r
+ \r
+ int sot_len, Psot, Psotp, mm;\r
+ unsigned long sot_pos, post_sod_pos;\r
+\r
+ unsigned long int left_THmarks_len;\r
+\r
+ /******* sot_pos = j2k->cstr_info->tile[tileno].start_pos; */\r
+ sot_pos = j2k->cstr_info->tile[tileno].tp_start_pos[tpno];\r
+ cio_seek(cio, sot_pos + 2); \r
+ sot_len = cio_read(cio, 2); /* SOT Len */\r
+ cio_skip(cio, 2);\r
+ Psotp = cio_tell(cio);\r
+ Psot = cio_read(cio, 4); /* tile length */\r
+\r
+ /******* post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1; */\r
+ post_sod_pos = j2k->cstr_info->tile[tileno].tp_end_header[tpno] + 1;\r
+ left_THmarks_len = post_sod_pos - sot_pos;\r
+\r
+ /* add all the lengths of the markers which are len-ready and stay within SOT and SOD */\r
+ for (mm = 0; mm < jwmarker_num; mm++) {\r
+ if ((jwmarker[mm].pos >= sot_pos) && (jwmarker[mm].pos < post_sod_pos)) {\r
+ if (jwmarker[mm].len_ready)\r
+ left_THmarks_len += jwmarker[mm].len + 2;\r
+ else {\r
+ opj_event_msg(j2k->cinfo, EVT_ERROR, "MS %x in %f is not len-ready: could not set up TH EPB\n",\r
+ jwmarker[mm].id, jwmarker[mm].dpos); \r
+ exit(1);\r
+ }\r
}\r
}\r
- }\r
\r
- if ((tilespec < JPWL_MAX_NO_TILESPECS) && (j2k->cp->sens_TPH_tileno[tilespec] == tileno))\r
- /* we got a specification from this tile onwards */\r
- sens = j2k->cp->sens_TPH[tilespec++];\r
- \r
- /* must this TPH have an ESD MS? */\r
- if (j2k->cp->esd_on && (sens >= 0)) {\r
-\r
- /* Create the ESD */\r
- if (esd_mark = jpwl_esd_create(\r
- j2k, /* this encoder handle */\r
- -1, /* we are averaging over all components */\r
- (unsigned char) j2k->cp->sens_range, /* range method */\r
- (unsigned char) j2k->cp->sens_addr, /* sensitivity addressing size */\r
- (unsigned char) sens, /* sensitivity method */\r
- j2k->cp->sens_size, /* sensitivity value size */\r
- tileno, /* this ESD is in a tile */\r
- 0, /* number of packets in codestream */\r
- NULL /* pointer to sensitivity data of packets */\r
- )) {\r
- \r
- /* Add this marker to the 'insertanda' list */\r
- if (jwmarker_num < JPWL_MAX_NO_MARKERS) {\r
- jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */\r
- jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */\r
- jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; /* after SOT */\r
- jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */\r
- jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */\r
- jwmarker[jwmarker_num].len_ready = true; /* ready, yet */\r
- jwmarker[jwmarker_num].pos_ready = true; /* ready */\r
- jwmarker[jwmarker_num].parms_ready = true; /* not ready */\r
- jwmarker[jwmarker_num].data_ready = false; /* ready */\r
- jwmarker_num++;\r
- }\r
+ /******* if ((tilespec < JPWL_MAX_NO_TILESPECS) && (j2k->cp->sens_TPH_tileno[tilespec] == tileno)) */\r
+ if ((tilespec < JPWL_MAX_NO_TILESPECS) && (j2k->cp->sens_TPH_tileno[tilespec] == acc_tpno))\r
+ /* we got a specification from this tile onwards */\r
+ sens = j2k->cp->sens_TPH[tilespec++];\r
+ \r
+ /* must this TPH have an ESD MS? */\r
+ if (j2k->cp->esd_on && (sens >= 0)) {\r
+\r
+ /* Create the ESD */\r
+ if (esd_mark = jpwl_esd_create(\r
+ j2k, /* this encoder handle */\r
+ -1, /* we are averaging over all components */\r
+ (unsigned char) j2k->cp->sens_range, /* range method */\r
+ (unsigned char) j2k->cp->sens_addr, /* sensitivity addressing size */\r
+ (unsigned char) sens, /* sensitivity method */\r
+ j2k->cp->sens_size, /* sensitivity value size */\r
+ tileno, /* this ESD is in a tile */\r
+ 0, /* number of packets in codestream */\r
+ NULL /* pointer to sensitivity data of packets */\r
+ )) {\r
+ \r
+ /* Add this marker to the 'insertanda' list */\r
+ if (jwmarker_num < JPWL_MAX_NO_MARKERS) {\r
+ jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */\r
+ jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */\r
+ /****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */\r
+ jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp_start_pos[tpno] + sot_len + 2; /* after SOT */\r
+ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */\r
+ jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */\r
+ jwmarker[jwmarker_num].len_ready = true; /* ready, yet */\r
+ jwmarker[jwmarker_num].pos_ready = true; /* ready */\r
+ jwmarker[jwmarker_num].parms_ready = true; /* not ready */\r
+ jwmarker[jwmarker_num].data_ready = false; /* ready */\r
+ jwmarker_num++;\r
+ }\r
\r
- /* update Psot of the tile */\r
- cio_seek(cio, Psotp);\r
- cio_write(cio, Psot + esd_mark->Lesd + 2, 4);\r
+ /* update Psot of the tile */\r
+ cio_seek(cio, Psotp);\r
+ cio_write(cio, Psot + esd_mark->Lesd + 2, 4);\r
\r
- opj_event_msg(j2k->cinfo, EVT_INFO,\r
- "TPH ESDs: tile %02d, method %d\n",\r
- tileno,\r
- sens\r
- );\r
+ opj_event_msg(j2k->cinfo, EVT_INFO,\r
+ /******* "TPH ESDs: tile %02d, method %d\n", */\r
+ "TPH ESDs: tile %02d, part %02d, method %d\n",\r
+ /******* tileno, */\r
+ tileno, tpno,\r
+ sens\r
+ );\r
\r
- } else {\r
- /* ooops, problems */\r
- opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH ESD #%d\n", tileno); \r
- };\r
+ } else {\r
+ /* ooops, problems */\r
+ /***** opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH ESD #%d\n", tileno); */\r
+ opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH ESD #%d,%d\n", tileno, tpno);\r
+ };\r
\r
- } \r
+ }\r
+ \r
+ }\r
\r
};\r
\r
if (jwmarker_num < JPWL_MAX_NO_MARKERS) {\r
jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */\r
jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */\r
- jwmarker[jwmarker_num].pos = socsiz_len; /* after SIZ */\r
+ jwmarker[jwmarker_num].pos = soc_pos + socsiz_len; /* after SIZ */\r
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */\r
jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */\r
jwmarker[jwmarker_num].len_ready = true; /* ready */\r
lastileno = 0;\r
packspec = 0;\r
pprot = -1;\r
+ acc_tpno = 0;\r
for (tileno = 0; tileno < j2k->cstr_info->tw * j2k->cstr_info->th; tileno++) {\r
\r
- int sot_len, Psot, Psotp, mm, epb_index = 0, prot_len = 0;\r
- unsigned long sot_pos, post_sod_pos;\r
- unsigned long int left_THmarks_len, epbs_len = 0;\r
- int startpack = 0, stoppack = j2k->cstr_info->num;\r
- jpwl_epb_ms_t *tph_epb = NULL;\r
-\r
- sot_pos = j2k->cstr_info->tile[tileno].start_pos;\r
- cio_seek(cio, sot_pos + 2); \r
- sot_len = cio_read(cio, 2); /* SOT Len */\r
- cio_skip(cio, 2);\r
- Psotp = cio_tell(cio);\r
- Psot = cio_read(cio, 4); /* tile length */\r
-\r
- /* a-priori length of the data dwelling between SOT and SOD */\r
- post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1;\r
- left_THmarks_len = post_sod_pos - (sot_pos + sot_len + 2);\r
+ opj_event_msg(j2k->cinfo, EVT_INFO,\r
+ "Tile %d has %d tile part(s)\n",\r
+ tileno, j2k->cstr_info->tile[tileno].num_tps\r
+ );\r
\r
- /* add all the lengths of the JPWL markers which are len-ready and stay within SOT and SOD */\r
- for (mm = 0; mm < jwmarker_num; mm++) {\r
- if ((jwmarker[mm].pos >= sot_pos) && (jwmarker[mm].pos < post_sod_pos)) {\r
- if (jwmarker[mm].len_ready)\r
- left_THmarks_len += jwmarker[mm].len + 2;\r
- else {\r
- opj_event_msg(j2k->cinfo, EVT_ERROR, "MS %x in %f is not len-ready: could not set up TH EPB\n",\r
- jwmarker[mm].id, jwmarker[mm].dpos); \r
- exit(1);\r
+ /* for every tile part in the tile */\r
+ for (tpno = 0; tpno < j2k->cstr_info->tile[tileno].num_tps; tpno++, acc_tpno++) { \r
+ \r
+ int sot_len, Psot, Psotp, mm, epb_index = 0, prot_len = 0;\r
+ unsigned long sot_pos, post_sod_pos;\r
+ unsigned long int left_THmarks_len, epbs_len = 0;\r
+ int startpack = 0, stoppack = j2k->cstr_info->num;\r
+ int first_tp_pack, last_tp_pack;\r
+ jpwl_epb_ms_t *tph_epb = NULL;\r
+\r
+ /****** sot_pos = j2k->cstr_info->tile[tileno].start_pos; */\r
+ sot_pos = j2k->cstr_info->tile[tileno].tp_start_pos[tpno];\r
+ cio_seek(cio, sot_pos + 2); \r
+ sot_len = cio_read(cio, 2); /* SOT Len */\r
+ cio_skip(cio, 2);\r
+ Psotp = cio_tell(cio);\r
+ Psot = cio_read(cio, 4); /* tile length */\r
+\r
+ /* a-priori length of the data dwelling between SOT and SOD */\r
+ /****** post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1; */\r
+ post_sod_pos = j2k->cstr_info->tile[tileno].tp_end_header[tpno] + 1;\r
+ left_THmarks_len = post_sod_pos - (sot_pos + sot_len + 2);\r
+\r
+ /* add all the lengths of the JPWL markers which are len-ready and stay within SOT and SOD */\r
+ for (mm = 0; mm < jwmarker_num; mm++) {\r
+ if ((jwmarker[mm].pos >= sot_pos) && (jwmarker[mm].pos < post_sod_pos)) {\r
+ if (jwmarker[mm].len_ready)\r
+ left_THmarks_len += jwmarker[mm].len + 2;\r
+ else {\r
+ opj_event_msg(j2k->cinfo, EVT_ERROR, "MS %x in %f is not len-ready: could not set up TH EPB\n",\r
+ jwmarker[mm].id, jwmarker[mm].dpos); \r
+ exit(1);\r
+ }\r
}\r
}\r
- }\r
-\r
- if ((tilespec < JPWL_MAX_NO_TILESPECS) && (j2k->cp->hprot_TPH_tileno[tilespec] == tileno))\r
- /* we got a specification from this tile onwards */\r
- hprot = j2k->cp->hprot_TPH[tilespec++];\r
- \r
- /* must this TPH have an EPB MS? */\r
- if (j2k->cp->epb_on && (hprot > 0)) {\r
-\r
- /* Create the EPB */\r
- if (epb_mark = jpwl_epb_create(\r
- j2k, /* this encoder handle */\r
- false, /* is it the latest? in TPH, no for now (if huge data size in TPH, we'd need more) */\r
- true, /* is it packed? yes for now */\r
- tileno, /* we are in TPH */\r
- epb_index++, /* its index is 0 (first) */\r
- hprot, /* protection type parameters of following data */\r
- sot_len + 2, /* pre-data length: only SOT */\r
- left_THmarks_len /* post-data length: from SOT end to SOD inclusive */\r
- )) {\r
- \r
- /* Add this marker to the 'insertanda' list */\r
- if (jwmarker_num < JPWL_MAX_NO_MARKERS) {\r
- jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */\r
- jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */\r
- jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; /* after SOT */\r
- jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */\r
- jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */\r
- jwmarker[jwmarker_num].len_ready = true; /* ready */\r
- jwmarker[jwmarker_num].pos_ready = true; /* ready */\r
- jwmarker[jwmarker_num].parms_ready = true; /* ready */\r
- jwmarker[jwmarker_num].data_ready = false; /* not ready */\r
- jwmarker_num++;\r
- }\r
\r
- /* update Psot of the tile */\r
- Psot += epb_mark->Lepb + 2;\r
+ /****** if ((tilespec < JPWL_MAX_NO_TILESPECS) && (j2k->cp->hprot_TPH_tileno[tilespec] == tileno)) */\r
+ if ((tilespec < JPWL_MAX_NO_TILESPECS) && (j2k->cp->hprot_TPH_tileno[tilespec] == acc_tpno))\r
+ /* we got a specification from this tile part onwards */\r
+ hprot = j2k->cp->hprot_TPH[tilespec++];\r
+ \r
+ /* must this TPH have an EPB MS? */\r
+ if (j2k->cp->epb_on && (hprot > 0)) {\r
+\r
+ /* Create the EPB */\r
+ if (epb_mark = jpwl_epb_create(\r
+ j2k, /* this encoder handle */\r
+ false, /* is it the latest? in TPH, no for now (if huge data size in TPH, we'd need more) */\r
+ true, /* is it packed? yes for now */\r
+ tileno, /* we are in TPH */\r
+ epb_index++, /* its index is 0 (first) */\r
+ hprot, /* protection type parameters of following data */\r
+ sot_len + 2, /* pre-data length: only SOT */\r
+ left_THmarks_len /* post-data length: from SOT end to SOD inclusive */\r
+ )) {\r
+ \r
+ /* Add this marker to the 'insertanda' list */\r
+ if (jwmarker_num < JPWL_MAX_NO_MARKERS) {\r
+ jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */\r
+ jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */\r
+ /****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */\r
+ jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp_start_pos[tpno] + sot_len + 2; /* after SOT */\r
+ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */\r
+ jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */\r
+ jwmarker[jwmarker_num].len_ready = true; /* ready */\r
+ jwmarker[jwmarker_num].pos_ready = true; /* ready */\r
+ jwmarker[jwmarker_num].parms_ready = true; /* ready */\r
+ jwmarker[jwmarker_num].data_ready = false; /* not ready */\r
+ jwmarker_num++;\r
+ }\r
\r
- opj_event_msg(j2k->cinfo, EVT_INFO,\r
- "TPH EPB : tile %02d, prot. %d\n",\r
- tileno,\r
- hprot\r
- );\r
+ /* update Psot of the tile */\r
+ Psot += epb_mark->Lepb + 2;\r
\r
- /* save this TPH EPB address */\r
- tph_epb = epb_mark;\r
+ opj_event_msg(j2k->cinfo, EVT_INFO,\r
+ /***** "TPH EPB : tile %02d, prot. %d\n", */\r
+ "TPH EPB : tile %02d, part %02d, prot. %d\n",\r
+ /***** tileno, */\r
+ tileno, tpno,\r
+ hprot\r
+ );\r
\r
- } else {\r
- /* ooops, problems */\r
- opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH EPB #%d\n", tileno); \r
- };\r
+ /* save this TPH EPB address */\r
+ tph_epb = epb_mark;\r
\r
- } \r
- \r
- startpack = 0;\r
- /* EPB MSs for UEP packet data protection in Tile Parts */\r
- for (packno = 0; packno < j2k->cstr_info->num; packno++) {\r
+ } else {\r
+ /* ooops, problems */\r
+ /****** opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH EPB #%d\n", tileno); */\r
+ opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH EPB in #%d,d\n", tileno, tpno);\r
+ };\r
\r
- if ((packspec < JPWL_MAX_NO_PACKSPECS) &&\r
- (j2k->cp->pprot_tileno[packspec] == tileno) && (j2k->cp->pprot_packno[packspec] == packno)) {\r
+ } \r
+ \r
+ startpack = 0;\r
+ /* EPB MSs for UEP packet data protection in Tile Parts */\r
+ /****** for (packno = 0; packno < j2k->cstr_info->num; packno++) { */\r
+ first_tp_pack = (tpno > 0) ? (first_tp_pack + j2k->cstr_info->tile[tileno].tp_num[tpno - 1]) : 0;\r
+ last_tp_pack = first_tp_pack + j2k->cstr_info->tile[tileno].tp_num[tpno] - 1;\r
+ for (packno = 0; packno < j2k->cstr_info->tile[tileno].tp_num[tpno]; packno++) {\r
+\r
+ /******** if ((packspec < JPWL_MAX_NO_PACKSPECS) &&\r
+ (j2k->cp->pprot_tileno[packspec] == tileno) && (j2k->cp->pprot_packno[packspec] == packno)) { */\r
+ if ((packspec < JPWL_MAX_NO_PACKSPECS) &&\r
+ (j2k->cp->pprot_tileno[packspec] == acc_tpno) && (j2k->cp->pprot_packno[packspec] == packno)) {\r
+\r
+ /* we got a specification from this tile and packet onwards */\r
+ /* print the previous spec */\r
+ if (packno > 0) {\r
+ stoppack = packno - 1; \r
+ opj_event_msg(j2k->cinfo, EVT_INFO,\r
+ /***** "UEP EPBs: tile %02d, packs. %02d-%02d (B %d-%d), prot. %d\n", */\r
+ "UEP EPBs: tile %02d, part %02d, packs. %02d-%02d (B %d-%d), prot. %d\n",\r
+ /***** tileno, */\r
+ tileno, tpno,\r
+ startpack,\r
+ stoppack,\r
+ /***** j2k->cstr_info->tile[tileno].packet[startpack].start_pos, */\r
+ j2k->cstr_info->tile[tileno].packet[first_tp_pack + startpack].start_pos,\r
+ /***** j2k->cstr_info->tile[tileno].packet[stoppack].end_pos, */\r
+ j2k->cstr_info->tile[tileno].packet[first_tp_pack + stoppack].end_pos,\r
+ pprot);\r
+\r
+ /***** prot_len = j2k->cstr_info->tile[tileno].packet[stoppack].end_pos + 1 -\r
+ j2k->cstr_info->tile[tileno].packet[startpack].start_pos; */\r
+ prot_len = j2k->cstr_info->tile[tileno].packet[first_tp_pack + stoppack].end_pos + 1 -\r
+ j2k->cstr_info->tile[tileno].packet[first_tp_pack + startpack].start_pos;\r
+\r
+ /*\r
+ particular case: if this is the last header and the last packet,\r
+ then it is better to protect even the EOC marker\r
+ */\r
+ /****** if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&\r
+ (stoppack == (j2k->cstr_info->num - 1))) */\r
+ if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&\r
+ (tpno == (j2k->cstr_info->tile[tileno].num_tps - 1)) &&\r
+ (stoppack == last_tp_pack))\r
+ /* add the EOC len */\r
+ prot_len += 2;\r
+\r
+ /* let's add the EPBs */\r
+ Psot += jpwl_epbs_add(\r
+ j2k, /* J2K handle */\r
+ jwmarker, /* pointer to JPWL markers list */\r
+ &jwmarker_num, /* pointer to the number of current markers */\r
+ false, /* latest */\r
+ true, /* packed */\r
+ false, /* inside MH */\r
+ &epb_index, /* pointer to EPB index */\r
+ pprot, /* protection type */\r
+ /****** (double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, */ /* position */\r
+ (double) (j2k->cstr_info->tile[tileno].tp_start_pos[tpno] + sot_len + 2) + 0.0001, /* position */\r
+ tileno, /* number of tile */\r
+ 0, /* length of pre-data */\r
+ prot_len /*4000*/ /* length of post-data */\r
+ );\r
+ }\r
\r
- /* we got a specification from this tile and packet onwards */\r
- /* print the previous spec */\r
- if (packno > 0) {\r
- stoppack = packno - 1; \r
- opj_event_msg(j2k->cinfo, EVT_INFO,\r
- "UEP EPBs: tile %02d, packs. %02d-%02d (B %d-%d), prot. %d\n",\r
- tileno,\r
- startpack,\r
- stoppack,\r
- j2k->cstr_info->tile[tileno].packet[startpack].start_pos,\r
- j2k->cstr_info->tile[tileno].packet[stoppack].end_pos,\r
- pprot);\r
-\r
- prot_len = j2k->cstr_info->tile[tileno].packet[stoppack].end_pos + 1 -\r
- j2k->cstr_info->tile[tileno].packet[startpack].start_pos;\r
-\r
- /*\r
- particular case: if this is the last header and the last packet,\r
- then it is better to protect even the EOC marker\r
- */\r
- if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&\r
- (stoppack == (j2k->cstr_info->num - 1)))\r
- /* add the EOC len */\r
- prot_len += 2;\r
-\r
- /* let's add the EPBs */\r
- Psot += jpwl_epbs_add(\r
- j2k, /* J2K handle */\r
- jwmarker, /* pointer to JPWL markers list */\r
- &jwmarker_num, /* pointer to the number of current markers */\r
- false, /* latest */\r
- true, /* packed */\r
- false, /* inside MH */\r
- &epb_index, /* pointer to EPB index */\r
- pprot, /* protection type */\r
- (double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, /* position */\r
- tileno, /* number of tile */\r
- 0, /* length of pre-data */\r
- prot_len /*4000*/ /* length of post-data */\r
- );\r
+ startpack = packno;\r
+ pprot = j2k->cp->pprot[packspec++];\r
}\r
\r
- startpack = packno;\r
- pprot = j2k->cp->pprot[packspec++];\r
+ //printf("Tile %02d, pack %02d ==> %d\n", tileno, packno, pprot);\r
+ \r
}\r
\r
- //printf("Tile %02d, pack %02d ==> %d\n", tileno, packno, pprot);\r
- \r
- }\r
+ /* we are at the end: print the remaining spec */\r
+ stoppack = packno - 1;\r
+ if (pprot >= 0) {\r
\r
- /* we are at the end: print the remaining spec */\r
- stoppack = packno - 1;\r
- if (pprot >= 0) {\r
+ opj_event_msg(j2k->cinfo, EVT_INFO,\r
+ /**** "UEP EPBs: tile %02d, packs. %02d-%02d (B %d-%d), prot. %d\n", */\r
+ "UEP EPBs: tile %02d, part %02d, packs. %02d-%02d (B %d-%d), prot. %d\n",\r
+ /**** tileno, */\r
+ tileno, tpno,\r
+ startpack,\r
+ stoppack,\r
+ /***** j2k->image_info->tile[tileno].packet[startpack].start_pos,\r
+ j2k->image_info->tile[tileno].packet[stoppack].end_pos, */\r
+ j2k->cstr_info->tile[tileno].packet[first_tp_pack + startpack].start_pos,\r
+ j2k->cstr_info->tile[tileno].packet[first_tp_pack + stoppack].end_pos,\r
+ pprot);\r
+\r
+ /***** prot_len = j2k->cstr_info->tile[tileno].packet[stoppack].end_pos + 1 -\r
+ j2k->cstr_info->tile[tileno].packet[startpack].start_pos; */\r
+ prot_len = j2k->cstr_info->tile[tileno].packet[first_tp_pack + stoppack].end_pos + 1 -\r
+ j2k->cstr_info->tile[tileno].packet[first_tp_pack + startpack].start_pos;\r
+\r
+ /*\r
+ particular case: if this is the last header and the last packet,\r
+ then it is better to protect even the EOC marker\r
+ */\r
+ /***** if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&\r
+ (stoppack == (j2k->cstr_info->num - 1))) */\r
+ if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&\r
+ (tpno == (j2k->cstr_info->tile[tileno].num_tps - 1)) &&\r
+ (stoppack == last_tp_pack))\r
+ /* add the EOC len */\r
+ prot_len += 2;\r
+\r
+ /* let's add the EPBs */\r
+ Psot += jpwl_epbs_add(\r
+ j2k, /* J2K handle */\r
+ jwmarker, /* pointer to JPWL markers list */\r
+ &jwmarker_num, /* pointer to the number of current markers */\r
+ true, /* latest */\r
+ true, /* packed */\r
+ false, /* inside MH */\r
+ &epb_index, /* pointer to EPB index */\r
+ pprot, /* protection type */\r
+ /***** (double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001,*/ /* position */\r
+ (double) (j2k->cstr_info->tile[tileno].tp_start_pos[tpno] + sot_len + 2) + 0.0001, /* position */\r
+ tileno, /* number of tile */\r
+ 0, /* length of pre-data */\r
+ prot_len /*4000*/ /* length of post-data */\r
+ );\r
+ }\r
\r
- opj_event_msg(j2k->cinfo, EVT_INFO,\r
- "UEP EPBs: tile %02d, packs. %02d-%02d (B %d-%d), prot. %d\n",\r
- tileno,\r
- startpack,\r
- stoppack,\r
- j2k->cstr_info->tile[tileno].packet[startpack].start_pos,\r
- j2k->cstr_info->tile[tileno].packet[stoppack].end_pos,\r
- pprot);\r
-\r
- prot_len = j2k->cstr_info->tile[tileno].packet[stoppack].end_pos + 1 -\r
- j2k->cstr_info->tile[tileno].packet[startpack].start_pos;\r
-\r
- /*\r
- particular case: if this is the last header and the last packet,\r
- then it is better to protect even the EOC marker\r
- */\r
- if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&\r
- (stoppack == (j2k->cstr_info->num - 1)))\r
- /* add the EOC len */\r
- prot_len += 2;\r
-\r
- /* let's add the EPBs */\r
- Psot += jpwl_epbs_add(\r
- j2k, /* J2K handle */\r
- jwmarker, /* pointer to JPWL markers list */\r
- &jwmarker_num, /* pointer to the number of current markers */\r
- true, /* latest */\r
- true, /* packed */\r
- false, /* inside MH */\r
- &epb_index, /* pointer to EPB index */\r
- pprot, /* protection type */\r
- (double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, /* position */\r
- tileno, /* number of tile */\r
- 0, /* length of pre-data */\r
- prot_len /*4000*/ /* length of post-data */\r
- );\r
- }\r
+ /* we can now check if the TPH EPB was really the last one */\r
+ if (tph_epb && (epb_index == 1)) {\r
+ /* set the TPH EPB to be the last one in current header */\r
+ tph_epb->Depb |= (unsigned char) ((true & 0x0001) << 6);\r
+ tph_epb = NULL;\r
+ }\r
\r
- /* we can now check if the TPH EPB was really the last one */\r
- if (tph_epb && (epb_index == 1)) {\r
- /* set the TPH EPB to be the last one in current header */\r
- tph_epb->Depb |= (unsigned char) ((true & 0x0001) << 6);\r
- tph_epb = NULL;\r
+ /* write back Psot */\r
+ cio_seek(cio, Psotp);\r
+ cio_write(cio, Psot, 4);\r
+ \r
}\r
\r
- /* write back Psot */\r
- cio_seek(cio, Psotp);\r
- cio_write(cio, Psot, 4);\r
-\r
};\r
\r
/* reset the position */\r
int mm;\r
unsigned long int old_size = j2k->cstr_info->codestream_size;\r
unsigned long int new_size = old_size;\r
- int ciopos = cio_tell(cio);\r
+ int ciopos = cio_tell(cio), soc_pos = j2k->cstr_info->main_head_start;\r
unsigned char *jpwl_buf, *orig_buf;\r
unsigned long int orig_pos;\r
double epbcoding_time = 0.0, esdcoding_time = 0.0;\r
opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for JPWL temp codestream buffer\n");\r
exit(1);\r
};\r
+\r
+ /* copy the jp2 part, if any */\r
+ memcpy(jpwl_buf, cio->buffer, soc_pos);\r
+\r
orig_buf = jpwl_buf;\r
\r
/* cycle through markers */\r
- orig_pos = 0; /* start from the beginning */\r
- cio_seek(cio, 0); /* rewind the original */\r
+ orig_pos = soc_pos + 0; /* start from the beginning */\r
+ cio_seek(cio, soc_pos + 0); /* rewind the original */\r
for (mm = 0; mm < jwmarker_num; mm++) {\r
\r
/*\r
}\r
\r
/* finish remaining original codestream */\r
- memcpy(jpwl_buf, cio_getbp(cio), old_size - orig_pos);\r
- jpwl_buf += old_size - orig_pos;\r
- cio_seek(cio, old_size);\r
+ memcpy(jpwl_buf, cio_getbp(cio), soc_pos + old_size - orig_pos);\r
+ jpwl_buf += soc_pos + old_size - orig_pos;\r
+ cio_seek(cio, soc_pos + old_size);\r
\r
/*\r
update info file based on added markers\r
opj_free(cio->buffer);\r
/*cio->cinfo;*/ /* no change */\r
/*cio->openmode;*/ /* no change */\r
- cio->buffer = jpwl_buf - new_size;\r
- cio->length = new_size;\r
- cio->start = jpwl_buf - new_size;\r
+ cio->buffer = jpwl_buf - new_size - soc_pos;\r
+ cio->length = new_size + soc_pos;\r
+ cio->start = jpwl_buf - new_size - soc_pos;\r
cio->end = jpwl_buf - 1;\r
- cio->bp = jpwl_buf - new_size;\r
- cio_seek(cio, new_size);\r
+ cio->bp = jpwl_buf - new_size - soc_pos;\r
+ cio_seek(cio, soc_pos + new_size);\r
\r
}\r
\r