One more field in the codestream_info struct for recording the number of packets per tile part; JPWL now distributes the EPBs in all the tile part headers
This commit is contained in:
parent
cf95a80be6
commit
dfcacb8247
|
@ -12,9 +12,11 @@ September 6, 2007
|
|||
* [Mathieu Malaterre] OpenJPEG.rc update copyright year
|
||||
* [Mathieu Malaterre] CMake: add Java j2kviewer but do not compile it using cmake since cmake has too poor support for Java. Should create a custom command running ant instead.
|
||||
* [Mathieu Malaterre] CMake: Add doxygen output
|
||||
+ [GB] One more field in the codestream_info struct for recording the number of packets per tile part; JPWL now distributes the EPBs in all the tile part headers
|
||||
|
||||
September 4, 2007
|
||||
+ [GB] Added some fields in the codestream_info structure: they are used to record the position of single tile parts. Changed also the write_index function in the codec, to reflect the presence of this new information.
|
||||
|
||||
September 3, 2007
|
||||
+ [GB] Added the knowledge of JPSEC SEC and INSEC markers (you have to compile the JPWL project). Management of these markers is limited to skipping them without crashing: no real security function at this stage. Deprecated USE_JPSEC will be removed next
|
||||
|
||||
|
|
|
@ -209,31 +209,31 @@ void encode_help_display() {
|
|||
#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");
|
||||
|
@ -246,15 +246,16 @@ void encode_help_display() {
|
|||
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");
|
||||
|
@ -561,6 +562,11 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
|
|||
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)
|
||||
|
@ -621,10 +627,11 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
|
|||
|
||||
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]
|
||||
|
@ -1326,11 +1333,11 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
|||
/* 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) {
|
||||
|
@ -1341,7 +1348,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
|||
} 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) {
|
||||
|
@ -1387,7 +1394,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
|||
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) {
|
||||
|
@ -1404,7 +1411,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
|||
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) {
|
||||
|
@ -1425,7 +1432,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
|||
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) {
|
||||
|
@ -1441,7 +1448,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
|||
} 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) {
|
||||
|
@ -1482,11 +1489,11 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
|||
} 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) {
|
||||
|
@ -1497,7 +1504,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
|||
} 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) {
|
||||
|
|
594
jpwl/jpwl.c
594
jpwl/jpwl.c
|
@ -110,10 +110,10 @@ void jpwl_esd_write(jpwl_esd_ms_t *esdmark, unsigned char *buf);
|
|||
void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
||||
|
||||
unsigned short int socsiz_len = 0;
|
||||
int ciopos = cio_tell(cio);
|
||||
int ciopos = cio_tell(cio), soc_pos = j2k->cstr_info->main_head_start;
|
||||
unsigned char *socp = NULL;
|
||||
|
||||
int tileno, tilespec, hprot, sens, pprot, packspec, lastileno, packno;
|
||||
int tileno, acc_tpno, tpno, tilespec, hprot, sens, pprot, packspec, lastileno, packno;
|
||||
|
||||
jpwl_epb_ms_t *epb_mark;
|
||||
jpwl_epc_ms_t *epc_mark;
|
||||
|
@ -121,9 +121,9 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
|
||||
/* find SOC + SIZ length */
|
||||
/* I assume SIZ is always the first marker after SOC */
|
||||
cio_seek(cio, 4);
|
||||
cio_seek(cio, soc_pos + 4);
|
||||
socsiz_len = (unsigned short int) cio_read(cio, 2) + 4; /* add the 2 marks length itself */
|
||||
cio_seek(cio, 0);
|
||||
cio_seek(cio, soc_pos + 0);
|
||||
socp = cio_getbp(cio); /* pointer to SOC */
|
||||
|
||||
/*
|
||||
|
@ -142,7 +142,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
if (epc_mark) {
|
||||
jwmarker[jwmarker_num].id = J2K_MS_EPC; /* its type */
|
||||
jwmarker[jwmarker_num].epcmark = epc_mark; /* the EPC */
|
||||
jwmarker[jwmarker_num].pos = socsiz_len; /* after SIZ */
|
||||
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 */
|
||||
jwmarker[jwmarker_num].len_ready = true; /* ready */
|
||||
|
@ -187,7 +187,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
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].pos = socsiz_len; /* we choose to place it after SIZ */
|
||||
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 */
|
||||
jwmarker[jwmarker_num].len_ready = true; /* not ready, yet */
|
||||
|
@ -212,89 +212,107 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
/*
|
||||
ESD MSs for Tile Part Headers
|
||||
*/
|
||||
/* cycle through TPHs */
|
||||
/* cycle through tiles */
|
||||
sens = -1; /* default spec: no ESD */
|
||||
tilespec = 0; /* first tile spec */
|
||||
acc_tpno = 0;
|
||||
for (tileno = 0; tileno < j2k->cstr_info->tw * j2k->cstr_info->th; tileno++) {
|
||||
|
||||
int sot_len, Psot, Psotp, mm;
|
||||
unsigned long sot_pos, post_sod_pos;
|
||||
opj_event_msg(j2k->cinfo, EVT_INFO,
|
||||
"Tile %d has %d tile part(s)\n",
|
||||
tileno, j2k->cstr_info->tile[tileno].num_tps
|
||||
);
|
||||
|
||||
unsigned long int left_THmarks_len;
|
||||
/* for every tile part in the tile */
|
||||
for (tpno = 0; tpno < j2k->cstr_info->tile[tileno].num_tps; tpno++, acc_tpno++) {
|
||||
|
||||
int sot_len, Psot, Psotp, mm;
|
||||
unsigned long sot_pos, post_sod_pos;
|
||||
|
||||
sot_pos = j2k->cstr_info->tile[tileno].start_pos;
|
||||
cio_seek(cio, sot_pos + 2);
|
||||
sot_len = cio_read(cio, 2); /* SOT Len */
|
||||
cio_skip(cio, 2);
|
||||
Psotp = cio_tell(cio);
|
||||
Psot = cio_read(cio, 4); /* tile length */
|
||||
unsigned long int left_THmarks_len;
|
||||
|
||||
post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1;
|
||||
left_THmarks_len = post_sod_pos - sot_pos;
|
||||
/******* sot_pos = j2k->cstr_info->tile[tileno].start_pos; */
|
||||
sot_pos = j2k->cstr_info->tile[tileno].tp_start_pos[tpno];
|
||||
cio_seek(cio, sot_pos + 2);
|
||||
sot_len = cio_read(cio, 2); /* SOT Len */
|
||||
cio_skip(cio, 2);
|
||||
Psotp = cio_tell(cio);
|
||||
Psot = cio_read(cio, 4); /* tile length */
|
||||
|
||||
/* add all the lengths of the markers which are len-ready and stay within SOT and SOD */
|
||||
for (mm = 0; mm < jwmarker_num; mm++) {
|
||||
if ((jwmarker[mm].pos >= sot_pos) && (jwmarker[mm].pos < post_sod_pos)) {
|
||||
if (jwmarker[mm].len_ready)
|
||||
left_THmarks_len += jwmarker[mm].len + 2;
|
||||
else {
|
||||
opj_event_msg(j2k->cinfo, EVT_ERROR, "MS %x in %f is not len-ready: could not set up TH EPB\n",
|
||||
jwmarker[mm].id, jwmarker[mm].dpos);
|
||||
exit(1);
|
||||
/******* post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1; */
|
||||
post_sod_pos = j2k->cstr_info->tile[tileno].tp_end_header[tpno] + 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 */
|
||||
for (mm = 0; mm < jwmarker_num; mm++) {
|
||||
if ((jwmarker[mm].pos >= sot_pos) && (jwmarker[mm].pos < post_sod_pos)) {
|
||||
if (jwmarker[mm].len_ready)
|
||||
left_THmarks_len += jwmarker[mm].len + 2;
|
||||
else {
|
||||
opj_event_msg(j2k->cinfo, EVT_ERROR, "MS %x in %f is not len-ready: could not set up TH EPB\n",
|
||||
jwmarker[mm].id, jwmarker[mm].dpos);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******* if ((tilespec < JPWL_MAX_NO_TILESPECS) && (j2k->cp->sens_TPH_tileno[tilespec] == tileno)) */
|
||||
if ((tilespec < JPWL_MAX_NO_TILESPECS) && (j2k->cp->sens_TPH_tileno[tilespec] == acc_tpno))
|
||||
/* we got a specification from this tile onwards */
|
||||
sens = j2k->cp->sens_TPH[tilespec++];
|
||||
|
||||
/* must this TPH have an ESD MS? */
|
||||
if (j2k->cp->esd_on && (sens >= 0)) {
|
||||
|
||||
/* Create the ESD */
|
||||
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 */
|
||||
(unsigned char) j2k->cp->sens_addr, /* sensitivity addressing size */
|
||||
(unsigned char) sens, /* sensitivity method */
|
||||
j2k->cp->sens_size, /* sensitivity value size */
|
||||
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].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].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 */
|
||||
jwmarker[jwmarker_num].pos_ready = true; /* ready */
|
||||
jwmarker[jwmarker_num].parms_ready = true; /* not ready */
|
||||
jwmarker[jwmarker_num].data_ready = false; /* ready */
|
||||
jwmarker_num++;
|
||||
}
|
||||
|
||||
/* update Psot of the tile */
|
||||
cio_seek(cio, Psotp);
|
||||
cio_write(cio, Psot + esd_mark->Lesd + 2, 4);
|
||||
|
||||
opj_event_msg(j2k->cinfo, EVT_INFO,
|
||||
/******* "TPH ESDs: tile %02d, method %d\n", */
|
||||
"TPH ESDs: tile %02d, part %02d, method %d\n",
|
||||
/******* tileno, */
|
||||
tileno, tpno,
|
||||
sens
|
||||
);
|
||||
|
||||
} else {
|
||||
/* ooops, problems */
|
||||
/***** opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH ESD #%d\n", tileno); */
|
||||
opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH ESD #%d,%d\n", tileno, tpno);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ((tilespec < JPWL_MAX_NO_TILESPECS) && (j2k->cp->sens_TPH_tileno[tilespec] == tileno))
|
||||
/* we got a specification from this tile onwards */
|
||||
sens = j2k->cp->sens_TPH[tilespec++];
|
||||
|
||||
/* must this TPH have an ESD MS? */
|
||||
if (j2k->cp->esd_on && (sens >= 0)) {
|
||||
|
||||
/* Create the ESD */
|
||||
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 */
|
||||
(unsigned char) j2k->cp->sens_addr, /* sensitivity addressing size */
|
||||
(unsigned char) sens, /* sensitivity method */
|
||||
j2k->cp->sens_size, /* sensitivity value size */
|
||||
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].pos = j2k->cstr_info->tile[tileno].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 */
|
||||
jwmarker[jwmarker_num].pos_ready = true; /* ready */
|
||||
jwmarker[jwmarker_num].parms_ready = true; /* not ready */
|
||||
jwmarker[jwmarker_num].data_ready = false; /* ready */
|
||||
jwmarker_num++;
|
||||
}
|
||||
|
||||
/* update Psot of the tile */
|
||||
cio_seek(cio, Psotp);
|
||||
cio_write(cio, Psot + esd_mark->Lesd + 2, 4);
|
||||
|
||||
opj_event_msg(j2k->cinfo, EVT_INFO,
|
||||
"TPH ESDs: tile %02d, method %d\n",
|
||||
tileno,
|
||||
sens
|
||||
);
|
||||
|
||||
} else {
|
||||
/* ooops, problems */
|
||||
opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH ESD #%d\n", tileno);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -341,7 +359,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
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].pos = socsiz_len; /* after SIZ */
|
||||
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 */
|
||||
jwmarker[jwmarker_num].len_ready = true; /* ready */
|
||||
|
@ -371,200 +389,244 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
lastileno = 0;
|
||||
packspec = 0;
|
||||
pprot = -1;
|
||||
acc_tpno = 0;
|
||||
for (tileno = 0; tileno < j2k->cstr_info->tw * j2k->cstr_info->th; tileno++) {
|
||||
|
||||
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;
|
||||
jpwl_epb_ms_t *tph_epb = NULL;
|
||||
opj_event_msg(j2k->cinfo, EVT_INFO,
|
||||
"Tile %d has %d tile part(s)\n",
|
||||
tileno, j2k->cstr_info->tile[tileno].num_tps
|
||||
);
|
||||
|
||||
sot_pos = j2k->cstr_info->tile[tileno].start_pos;
|
||||
cio_seek(cio, sot_pos + 2);
|
||||
sot_len = cio_read(cio, 2); /* SOT Len */
|
||||
cio_skip(cio, 2);
|
||||
Psotp = cio_tell(cio);
|
||||
Psot = cio_read(cio, 4); /* tile length */
|
||||
/* for every tile part in the tile */
|
||||
for (tpno = 0; tpno < j2k->cstr_info->tile[tileno].num_tps; tpno++, acc_tpno++) {
|
||||
|
||||
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 first_tp_pack, last_tp_pack;
|
||||
jpwl_epb_ms_t *tph_epb = NULL;
|
||||
|
||||
/* a-priori length of the data dwelling between SOT and SOD */
|
||||
post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1;
|
||||
left_THmarks_len = post_sod_pos - (sot_pos + sot_len + 2);
|
||||
/****** sot_pos = j2k->cstr_info->tile[tileno].start_pos; */
|
||||
sot_pos = j2k->cstr_info->tile[tileno].tp_start_pos[tpno];
|
||||
cio_seek(cio, sot_pos + 2);
|
||||
sot_len = cio_read(cio, 2); /* SOT Len */
|
||||
cio_skip(cio, 2);
|
||||
Psotp = cio_tell(cio);
|
||||
Psot = cio_read(cio, 4); /* tile length */
|
||||
|
||||
/* add all the lengths of the JPWL markers which are len-ready and stay within SOT and SOD */
|
||||
for (mm = 0; mm < jwmarker_num; mm++) {
|
||||
if ((jwmarker[mm].pos >= sot_pos) && (jwmarker[mm].pos < post_sod_pos)) {
|
||||
if (jwmarker[mm].len_ready)
|
||||
left_THmarks_len += jwmarker[mm].len + 2;
|
||||
else {
|
||||
opj_event_msg(j2k->cinfo, EVT_ERROR, "MS %x in %f is not len-ready: could not set up TH EPB\n",
|
||||
jwmarker[mm].id, jwmarker[mm].dpos);
|
||||
exit(1);
|
||||
/* 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;
|
||||
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 */
|
||||
for (mm = 0; mm < jwmarker_num; mm++) {
|
||||
if ((jwmarker[mm].pos >= sot_pos) && (jwmarker[mm].pos < post_sod_pos)) {
|
||||
if (jwmarker[mm].len_ready)
|
||||
left_THmarks_len += jwmarker[mm].len + 2;
|
||||
else {
|
||||
opj_event_msg(j2k->cinfo, EVT_ERROR, "MS %x in %f is not len-ready: could not set up TH EPB\n",
|
||||
jwmarker[mm].id, jwmarker[mm].dpos);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((tilespec < JPWL_MAX_NO_TILESPECS) && (j2k->cp->hprot_TPH_tileno[tilespec] == tileno))
|
||||
/* we got a specification from this tile onwards */
|
||||
hprot = j2k->cp->hprot_TPH[tilespec++];
|
||||
|
||||
/* must this TPH have an EPB MS? */
|
||||
if (j2k->cp->epb_on && (hprot > 0)) {
|
||||
/****** if ((tilespec < JPWL_MAX_NO_TILESPECS) && (j2k->cp->hprot_TPH_tileno[tilespec] == tileno)) */
|
||||
if ((tilespec < JPWL_MAX_NO_TILESPECS) && (j2k->cp->hprot_TPH_tileno[tilespec] == acc_tpno))
|
||||
/* we got a specification from this tile part onwards */
|
||||
hprot = j2k->cp->hprot_TPH[tilespec++];
|
||||
|
||||
/* must this TPH have an EPB MS? */
|
||||
if (j2k->cp->epb_on && (hprot > 0)) {
|
||||
|
||||
/* Create the EPB */
|
||||
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 */
|
||||
tileno, /* we are in TPH */
|
||||
epb_index++, /* its index is 0 (first) */
|
||||
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].pos = j2k->cstr_info->tile[tileno].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 */
|
||||
jwmarker[jwmarker_num].pos_ready = true; /* ready */
|
||||
jwmarker[jwmarker_num].parms_ready = true; /* ready */
|
||||
jwmarker[jwmarker_num].data_ready = false; /* not ready */
|
||||
jwmarker_num++;
|
||||
/* Create the EPB */
|
||||
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 */
|
||||
tileno, /* we are in TPH */
|
||||
epb_index++, /* its index is 0 (first) */
|
||||
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].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].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 */
|
||||
jwmarker[jwmarker_num].pos_ready = true; /* ready */
|
||||
jwmarker[jwmarker_num].parms_ready = true; /* ready */
|
||||
jwmarker[jwmarker_num].data_ready = false; /* not ready */
|
||||
jwmarker_num++;
|
||||
}
|
||||
|
||||
/* update Psot of the tile */
|
||||
Psot += epb_mark->Lepb + 2;
|
||||
|
||||
opj_event_msg(j2k->cinfo, EVT_INFO,
|
||||
/***** "TPH EPB : tile %02d, prot. %d\n", */
|
||||
"TPH EPB : tile %02d, part %02d, prot. %d\n",
|
||||
/***** tileno, */
|
||||
tileno, tpno,
|
||||
hprot
|
||||
);
|
||||
|
||||
/* save this TPH EPB address */
|
||||
tph_epb = epb_mark;
|
||||
|
||||
} else {
|
||||
/* ooops, problems */
|
||||
/****** opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH EPB #%d\n", tileno); */
|
||||
opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH EPB in #%d,d\n", tileno, tpno);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
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++) {
|
||||
|
||||
/******** if ((packspec < JPWL_MAX_NO_PACKSPECS) &&
|
||||
(j2k->cp->pprot_tileno[packspec] == tileno) && (j2k->cp->pprot_packno[packspec] == packno)) { */
|
||||
if ((packspec < JPWL_MAX_NO_PACKSPECS) &&
|
||||
(j2k->cp->pprot_tileno[packspec] == acc_tpno) && (j2k->cp->pprot_packno[packspec] == packno)) {
|
||||
|
||||
/* we got a specification from this tile and packet onwards */
|
||||
/* print the previous spec */
|
||||
if (packno > 0) {
|
||||
stoppack = packno - 1;
|
||||
opj_event_msg(j2k->cinfo, EVT_INFO,
|
||||
/***** "UEP EPBs: tile %02d, packs. %02d-%02d (B %d-%d), prot. %d\n", */
|
||||
"UEP EPBs: tile %02d, part %02d, packs. %02d-%02d (B %d-%d), prot. %d\n",
|
||||
/***** tileno, */
|
||||
tileno, tpno,
|
||||
startpack,
|
||||
stoppack,
|
||||
/***** j2k->cstr_info->tile[tileno].packet[startpack].start_pos, */
|
||||
j2k->cstr_info->tile[tileno].packet[first_tp_pack + startpack].start_pos,
|
||||
/***** j2k->cstr_info->tile[tileno].packet[stoppack].end_pos, */
|
||||
j2k->cstr_info->tile[tileno].packet[first_tp_pack + stoppack].end_pos,
|
||||
pprot);
|
||||
|
||||
/***** prot_len = j2k->cstr_info->tile[tileno].packet[stoppack].end_pos + 1 -
|
||||
j2k->cstr_info->tile[tileno].packet[startpack].start_pos; */
|
||||
prot_len = j2k->cstr_info->tile[tileno].packet[first_tp_pack + stoppack].end_pos + 1 -
|
||||
j2k->cstr_info->tile[tileno].packet[first_tp_pack + startpack].start_pos;
|
||||
|
||||
/*
|
||||
particular case: if this is the last header and the last packet,
|
||||
then it is better to protect even the EOC marker
|
||||
*/
|
||||
/****** if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&
|
||||
(stoppack == (j2k->cstr_info->num - 1))) */
|
||||
if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&
|
||||
(tpno == (j2k->cstr_info->tile[tileno].num_tps - 1)) &&
|
||||
(stoppack == last_tp_pack))
|
||||
/* add the EOC len */
|
||||
prot_len += 2;
|
||||
|
||||
/* let's add the EPBs */
|
||||
Psot += jpwl_epbs_add(
|
||||
j2k, /* J2K handle */
|
||||
jwmarker, /* pointer to JPWL markers list */
|
||||
&jwmarker_num, /* pointer to the number of current markers */
|
||||
false, /* latest */
|
||||
true, /* packed */
|
||||
false, /* inside MH */
|
||||
&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 */
|
||||
tileno, /* number of tile */
|
||||
0, /* length of pre-data */
|
||||
prot_len /*4000*/ /* length of post-data */
|
||||
);
|
||||
}
|
||||
|
||||
startpack = packno;
|
||||
pprot = j2k->cp->pprot[packspec++];
|
||||
}
|
||||
|
||||
/* update Psot of the tile */
|
||||
Psot += epb_mark->Lepb + 2;
|
||||
//printf("Tile %02d, pack %02d ==> %d\n", tileno, packno, pprot);
|
||||
|
||||
}
|
||||
|
||||
/* we are at the end: print the remaining spec */
|
||||
stoppack = packno - 1;
|
||||
if (pprot >= 0) {
|
||||
|
||||
opj_event_msg(j2k->cinfo, EVT_INFO,
|
||||
"TPH EPB : tile %02d, prot. %d\n",
|
||||
tileno,
|
||||
hprot
|
||||
);
|
||||
/**** "UEP EPBs: tile %02d, packs. %02d-%02d (B %d-%d), prot. %d\n", */
|
||||
"UEP EPBs: tile %02d, part %02d, packs. %02d-%02d (B %d-%d), prot. %d\n",
|
||||
/**** tileno, */
|
||||
tileno, tpno,
|
||||
startpack,
|
||||
stoppack,
|
||||
/***** j2k->image_info->tile[tileno].packet[startpack].start_pos,
|
||||
j2k->image_info->tile[tileno].packet[stoppack].end_pos, */
|
||||
j2k->cstr_info->tile[tileno].packet[first_tp_pack + startpack].start_pos,
|
||||
j2k->cstr_info->tile[tileno].packet[first_tp_pack + stoppack].end_pos,
|
||||
pprot);
|
||||
|
||||
/* save this TPH EPB address */
|
||||
tph_epb = epb_mark;
|
||||
/***** prot_len = j2k->cstr_info->tile[tileno].packet[stoppack].end_pos + 1 -
|
||||
j2k->cstr_info->tile[tileno].packet[startpack].start_pos; */
|
||||
prot_len = j2k->cstr_info->tile[tileno].packet[first_tp_pack + stoppack].end_pos + 1 -
|
||||
j2k->cstr_info->tile[tileno].packet[first_tp_pack + startpack].start_pos;
|
||||
|
||||
} else {
|
||||
/* ooops, problems */
|
||||
opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not create TPH EPB #%d\n", tileno);
|
||||
};
|
||||
/*
|
||||
particular case: if this is the last header and the last packet,
|
||||
then it is better to protect even the EOC marker
|
||||
*/
|
||||
/***** if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&
|
||||
(stoppack == (j2k->cstr_info->num - 1))) */
|
||||
if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&
|
||||
(tpno == (j2k->cstr_info->tile[tileno].num_tps - 1)) &&
|
||||
(stoppack == last_tp_pack))
|
||||
/* add the EOC len */
|
||||
prot_len += 2;
|
||||
|
||||
}
|
||||
|
||||
startpack = 0;
|
||||
/* EPB MSs for UEP packet data protection in Tile Parts */
|
||||
for (packno = 0; packno < j2k->cstr_info->num; packno++) {
|
||||
|
||||
if ((packspec < JPWL_MAX_NO_PACKSPECS) &&
|
||||
(j2k->cp->pprot_tileno[packspec] == tileno) && (j2k->cp->pprot_packno[packspec] == packno)) {
|
||||
|
||||
/* we got a specification from this tile and packet onwards */
|
||||
/* print the previous spec */
|
||||
if (packno > 0) {
|
||||
stoppack = packno - 1;
|
||||
opj_event_msg(j2k->cinfo, EVT_INFO,
|
||||
"UEP EPBs: tile %02d, packs. %02d-%02d (B %d-%d), prot. %d\n",
|
||||
tileno,
|
||||
startpack,
|
||||
stoppack,
|
||||
j2k->cstr_info->tile[tileno].packet[startpack].start_pos,
|
||||
j2k->cstr_info->tile[tileno].packet[stoppack].end_pos,
|
||||
pprot);
|
||||
|
||||
prot_len = j2k->cstr_info->tile[tileno].packet[stoppack].end_pos + 1 -
|
||||
j2k->cstr_info->tile[tileno].packet[startpack].start_pos;
|
||||
|
||||
/*
|
||||
particular case: if this is the last header and the last packet,
|
||||
then it is better to protect even the EOC marker
|
||||
*/
|
||||
if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&
|
||||
(stoppack == (j2k->cstr_info->num - 1)))
|
||||
/* add the EOC len */
|
||||
prot_len += 2;
|
||||
|
||||
/* let's add the EPBs */
|
||||
Psot += jpwl_epbs_add(
|
||||
j2k, /* J2K handle */
|
||||
jwmarker, /* pointer to JPWL markers list */
|
||||
&jwmarker_num, /* pointer to the number of current markers */
|
||||
false, /* latest */
|
||||
true, /* packed */
|
||||
false, /* inside MH */
|
||||
&epb_index, /* pointer to EPB index */
|
||||
pprot, /* protection type */
|
||||
(double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, /* position */
|
||||
tileno, /* number of tile */
|
||||
0, /* length of pre-data */
|
||||
prot_len /*4000*/ /* length of post-data */
|
||||
);
|
||||
}
|
||||
|
||||
startpack = packno;
|
||||
pprot = j2k->cp->pprot[packspec++];
|
||||
/* let's add the EPBs */
|
||||
Psot += jpwl_epbs_add(
|
||||
j2k, /* J2K handle */
|
||||
jwmarker, /* pointer to JPWL markers list */
|
||||
&jwmarker_num, /* pointer to the number of current markers */
|
||||
true, /* latest */
|
||||
true, /* packed */
|
||||
false, /* inside MH */
|
||||
&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 */
|
||||
tileno, /* number of tile */
|
||||
0, /* length of pre-data */
|
||||
prot_len /*4000*/ /* length of post-data */
|
||||
);
|
||||
}
|
||||
|
||||
//printf("Tile %02d, pack %02d ==> %d\n", tileno, packno, pprot);
|
||||
|
||||
/* we can now check if the TPH EPB was really the last one */
|
||||
if (tph_epb && (epb_index == 1)) {
|
||||
/* set the TPH EPB to be the last one in current header */
|
||||
tph_epb->Depb |= (unsigned char) ((true & 0x0001) << 6);
|
||||
tph_epb = NULL;
|
||||
}
|
||||
|
||||
/* write back Psot */
|
||||
cio_seek(cio, Psotp);
|
||||
cio_write(cio, Psot, 4);
|
||||
|
||||
}
|
||||
|
||||
/* we are at the end: print the remaining spec */
|
||||
stoppack = packno - 1;
|
||||
if (pprot >= 0) {
|
||||
|
||||
opj_event_msg(j2k->cinfo, EVT_INFO,
|
||||
"UEP EPBs: tile %02d, packs. %02d-%02d (B %d-%d), prot. %d\n",
|
||||
tileno,
|
||||
startpack,
|
||||
stoppack,
|
||||
j2k->cstr_info->tile[tileno].packet[startpack].start_pos,
|
||||
j2k->cstr_info->tile[tileno].packet[stoppack].end_pos,
|
||||
pprot);
|
||||
|
||||
prot_len = j2k->cstr_info->tile[tileno].packet[stoppack].end_pos + 1 -
|
||||
j2k->cstr_info->tile[tileno].packet[startpack].start_pos;
|
||||
|
||||
/*
|
||||
particular case: if this is the last header and the last packet,
|
||||
then it is better to protect even the EOC marker
|
||||
*/
|
||||
if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&
|
||||
(stoppack == (j2k->cstr_info->num - 1)))
|
||||
/* add the EOC len */
|
||||
prot_len += 2;
|
||||
|
||||
/* let's add the EPBs */
|
||||
Psot += jpwl_epbs_add(
|
||||
j2k, /* J2K handle */
|
||||
jwmarker, /* pointer to JPWL markers list */
|
||||
&jwmarker_num, /* pointer to the number of current markers */
|
||||
true, /* latest */
|
||||
true, /* packed */
|
||||
false, /* inside MH */
|
||||
&epb_index, /* pointer to EPB index */
|
||||
pprot, /* protection type */
|
||||
(double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, /* position */
|
||||
tileno, /* number of tile */
|
||||
0, /* length of pre-data */
|
||||
prot_len /*4000*/ /* length of post-data */
|
||||
);
|
||||
}
|
||||
|
||||
/* we can now check if the TPH EPB was really the last one */
|
||||
if (tph_epb && (epb_index == 1)) {
|
||||
/* set the TPH EPB to be the last one in current header */
|
||||
tph_epb->Depb |= (unsigned char) ((true & 0x0001) << 6);
|
||||
tph_epb = NULL;
|
||||
}
|
||||
|
||||
/* write back Psot */
|
||||
cio_seek(cio, Psotp);
|
||||
cio_write(cio, Psot, 4);
|
||||
|
||||
};
|
||||
|
||||
/* reset the position */
|
||||
|
@ -577,7 +639,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);
|
||||
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;
|
||||
|
@ -597,11 +659,15 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for JPWL temp codestream buffer\n");
|
||||
exit(1);
|
||||
};
|
||||
|
||||
/* copy the jp2 part, if any */
|
||||
memcpy(jpwl_buf, cio->buffer, soc_pos);
|
||||
|
||||
orig_buf = jpwl_buf;
|
||||
|
||||
/* cycle through markers */
|
||||
orig_pos = 0; /* start from the beginning */
|
||||
cio_seek(cio, 0); /* rewind the original */
|
||||
orig_pos = soc_pos + 0; /* start from the beginning */
|
||||
cio_seek(cio, soc_pos + 0); /* rewind the original */
|
||||
for (mm = 0; mm < jwmarker_num; mm++) {
|
||||
|
||||
/*
|
||||
|
@ -647,9 +713,9 @@ 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), old_size - orig_pos);
|
||||
jpwl_buf += old_size - orig_pos;
|
||||
cio_seek(cio, old_size);
|
||||
memcpy(jpwl_buf, cio_getbp(cio), soc_pos + old_size - orig_pos);
|
||||
jpwl_buf += soc_pos + old_size - orig_pos;
|
||||
cio_seek(cio, soc_pos + old_size);
|
||||
|
||||
/*
|
||||
update info file based on added markers
|
||||
|
@ -748,12 +814,12 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
opj_free(cio->buffer);
|
||||
/*cio->cinfo;*/ /* no change */
|
||||
/*cio->openmode;*/ /* no change */
|
||||
cio->buffer = jpwl_buf - new_size;
|
||||
cio->length = new_size;
|
||||
cio->start = jpwl_buf - new_size;
|
||||
cio->buffer = jpwl_buf - new_size - soc_pos;
|
||||
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;
|
||||
cio_seek(cio, new_size);
|
||||
cio->bp = jpwl_buf - new_size - soc_pos;
|
||||
cio_seek(cio, soc_pos + new_size);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1658,7 +1658,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, packno, numtiles = info->th * info->tw, numpacks = info->num;
|
||||
int tileno, tpno, packno, numtiles = info->th * info->tw, numpacks = info->num;
|
||||
|
||||
if (!j2k || !jwmarker ) {
|
||||
opj_event_msg(j2k->cinfo, EVT_ERROR, "J2K handle or JPWL markers list badly allocated\n");
|
||||
|
@ -1703,6 +1703,32 @@ bool jpwl_update_info(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int jwmarker_num)
|
|||
addlen += jwmarker[mm].len + 2;*/
|
||||
info->tile[tileno].end_pos += addlen;
|
||||
|
||||
/* navigate through all the tile parts */
|
||||
for (tpno = 0; tpno < info->tile[tileno].num_tps; tpno++) {
|
||||
|
||||
/* 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])
|
||||
addlen += jwmarker[mm].len + 2;
|
||||
info->tile[tileno].tp_start_pos[tpno] += 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])
|
||||
addlen += jwmarker[mm].len + 2;
|
||||
info->tile[tileno].tp_end_header[tpno] += 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])
|
||||
addlen += jwmarker[mm].len + 2;
|
||||
info->tile[tileno].tp_end_pos[tpno] += addlen;
|
||||
|
||||
}
|
||||
|
||||
/* navigate through all the packets in this tile */
|
||||
for (packno = 0; packno < numpacks; packno++) {
|
||||
|
||||
|
|
|
@ -428,6 +428,7 @@ int j2k_calculate_tp(opj_cp_t *cp,int img_numcomp,opj_image_t *image,opj_j2k_t *
|
|||
j2k->cstr_info->tile[tileno].tp_start_pos = (int *) opj_malloc(cur_totnum_tp * sizeof(int));
|
||||
j2k->cstr_info->tile[tileno].tp_end_header = (int *) opj_malloc(cur_totnum_tp * sizeof(int));
|
||||
j2k->cstr_info->tile[tileno].tp_end_pos = (int *) opj_malloc(cur_totnum_tp * sizeof(int));
|
||||
j2k->cstr_info->tile[tileno].tp_num = (int *) opj_malloc(cur_totnum_tp * sizeof(int));
|
||||
}
|
||||
/* << INDEX */
|
||||
/* <<UniPG */
|
||||
|
@ -1928,6 +1929,7 @@ void j2k_destroy_compress(opj_j2k_t *j2k) {
|
|||
opj_free(tile_info->tp_start_pos);
|
||||
opj_free(tile_info->tp_end_header);
|
||||
opj_free(tile_info->tp_end_pos);
|
||||
opj_free(tile_info->tp_num);
|
||||
/* << INDEX */
|
||||
/* <<UniPG */
|
||||
}
|
||||
|
@ -2221,6 +2223,10 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
|
|||
|
||||
opj_tcd_t *tcd = NULL; /* TCD component */
|
||||
|
||||
/* UniPG>> */
|
||||
int acc_pack_num = 0;
|
||||
/* <<UniPG */
|
||||
|
||||
j2k->cio = cio;
|
||||
j2k->image = image;
|
||||
|
||||
|
@ -2362,9 +2368,13 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
|
|||
j2k_write_sod(j2k, tcd);
|
||||
/* UniPG>> */
|
||||
/* INDEX >> */
|
||||
if(cstr_info && cstr_info->index_on)
|
||||
if(cstr_info && cstr_info->index_on) {
|
||||
cstr_info->tile[j2k->curtileno].tp_end_pos[j2k->cur_tp_num] =
|
||||
cio_tell(cio) + j2k->pos_correction - 1;
|
||||
cstr_info->tile[j2k->curtileno].tp_num[j2k->cur_tp_num] =
|
||||
cstr_info->num - acc_pack_num;
|
||||
acc_pack_num = cstr_info->num;
|
||||
}
|
||||
/* << INDEX */
|
||||
/* <<UniPG */
|
||||
j2k->cur_tp_num ++;
|
||||
|
@ -2409,7 +2419,7 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
|
|||
/* UniPG>> */
|
||||
/* The following adjustment is done to adjust the codestream size */
|
||||
/* if SOD is not at 0 in the buffer. Useful in case of JP2, where */
|
||||
/* the first unch of bytes is not in the codestream */
|
||||
/* the first bunch of bytes is not in the codestream */
|
||||
cstr_info->codestream_size -= cstr_info->main_head_start;
|
||||
/* <<UniPG */
|
||||
}
|
||||
|
@ -2419,7 +2429,7 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
|
|||
preparation of JPWL marker segments: can be finalized only when the whole
|
||||
codestream is known
|
||||
*/
|
||||
if(cstr_info && cstr_info->index_on && cp->epc_on) {
|
||||
if(cp->epc_on) {
|
||||
|
||||
/* let's begin creating a marker list, according to user wishes */
|
||||
jpwl_prepare_marks(j2k, cio, image);
|
||||
|
@ -2430,6 +2440,7 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
|
|||
/* do not know exactly what is this for,
|
||||
but it gets called during index creation */
|
||||
j2k->pos_correction = 0;
|
||||
|
||||
}
|
||||
#endif /* USE_JPWL */
|
||||
|
||||
|
|
|
@ -628,7 +628,7 @@ typedef struct opj_tile_info {
|
|||
int nbpix;
|
||||
/** add fixed_quality */
|
||||
double distotile;
|
||||
/* UniPG>> */
|
||||
/* UniPG>> */
|
||||
/** number of tile parts */
|
||||
int num_tps;
|
||||
/** start position of tile part */
|
||||
|
@ -637,7 +637,9 @@ typedef struct opj_tile_info {
|
|||
int *tp_end_header;
|
||||
/** end position of tile part */
|
||||
int *tp_end_pos;
|
||||
/* << UniPG */
|
||||
/** number of packets of tile part */
|
||||
int *tp_num;
|
||||
/* << UniPG */
|
||||
} opj_tile_info_t;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue