summaryrefslogtreecommitdiff
path: root/libopenjpeg
diff options
context:
space:
mode:
authorFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>2007-08-30 09:51:20 +0000
committerFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>2007-08-30 09:51:20 +0000
commitacfe0ad6458db913aac469804d4d17bea671682a (patch)
tree3a8d4afee950198a5f8fa1c3acff2f96d0cdd7e5 /libopenjpeg
parentd07fa5d9d0b5f3452831e4c0c9da1f03d30a1299 (diff)
Changed the OpenJPEG library interface to enable users to access information regarding the codestream (also called index).
Diffstat (limited to 'libopenjpeg')
-rw-r--r--libopenjpeg/cio.c2
-rw-r--r--libopenjpeg/j2k.c348
-rw-r--r--libopenjpeg/j2k.h93
-rw-r--r--libopenjpeg/j2k_lib.h13
-rw-r--r--libopenjpeg/jp2.c10
-rw-r--r--libopenjpeg/jp2.h4
-rw-r--r--libopenjpeg/openjpeg.c8
-rw-r--r--libopenjpeg/openjpeg.h102
-rw-r--r--libopenjpeg/t2.c40
-rw-r--r--libopenjpeg/t2.h4
-rw-r--r--libopenjpeg/tcd.c46
-rw-r--r--libopenjpeg/tcd.h6
12 files changed, 221 insertions, 455 deletions
diff --git a/libopenjpeg/cio.c b/libopenjpeg/cio.c
index a462edb2..0725b381 100644
--- a/libopenjpeg/cio.c
+++ b/libopenjpeg/cio.c
@@ -139,7 +139,7 @@ bool cio_byteout(opj_cio_t *cio, unsigned char v) {
*/
unsigned char cio_bytein(opj_cio_t *cio) {
if (cio->bp >= cio->end) {
- opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n");
+ opj_event_msg(cio->cinfo, EVT_ERROR, "read error: passed the end of the codestream (start = %d, current = %d, end = %d\n", cio->start, cio->bp, cio->end);
return 0;
}
return *cio->bp++;
diff --git a/libopenjpeg/j2k.c b/libopenjpeg/j2k.c
index cbf6a1fa..f020167c 100644
--- a/libopenjpeg/j2k.c
+++ b/libopenjpeg/j2k.c
@@ -1340,7 +1340,7 @@ static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) {
int l, layno;
int totlen;
opj_tcp_t *tcp = NULL;
- opj_image_info_t *image_info = NULL;
+ opj_codestream_info_t *cstr_info = NULL;
opj_tcd_t *tcd = (opj_tcd_t*)tile_coder; /* cast is needed because of conflicts in header inclusions */
opj_cp_t *cp = j2k->cp;
@@ -1355,13 +1355,13 @@ static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) {
}
/* INDEX >> */
- image_info = j2k->image_info;
- if (image_info && image_info->index_on) {
+ cstr_info = j2k->cstr_info;
+ if (cstr_info && cstr_info->index_on) {
if (!j2k->cur_tp_num ){
- image_info->tile[j2k->curtileno].end_header = cio_tell(cio) + j2k->pos_correction - 1;
+ cstr_info->tile[j2k->curtileno].end_header = cio_tell(cio) + j2k->pos_correction - 1;
}else{
- if(image_info->tile[j2k->curtileno].packet[image_info->num - 1].end_pos < cio_tell(cio))
- image_info->tile[j2k->curtileno].packet[image_info->num].start_pos = cio_tell(cio);
+ if(cstr_info->tile[j2k->curtileno].packet[cstr_info->num - 1].end_pos < cio_tell(cio))
+ cstr_info->tile[j2k->curtileno].packet[cstr_info->num].start_pos = cio_tell(cio);
}
}
/* << INDEX */
@@ -1370,11 +1370,11 @@ static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) {
for (layno = 0; layno < tcp->numlayers; layno++) {
tcp->rates[layno] -= tcp->rates[layno] ? (j2k->sod_start / (cp->th * cp->tw)) : 0;
}
- if(image_info && (j2k->cur_tp_num == 0)) {
- image_info->num = 0;
+ if(cstr_info && (j2k->cur_tp_num == 0)) {
+ cstr_info->num = 0;
}
- l = tcd_encode_tile(tcd, j2k->curtileno, cio_getbp(cio), cio_numbytesleft(cio) - 2, image_info);
+ l = tcd_encode_tile(tcd, j2k->curtileno, cio_getbp(cio), cio_numbytesleft(cio) - 2, cstr_info);
/* Writing Psot in SOT marker */
totlen = cio_tell(cio) + l - j2k->sot_start;
@@ -1901,18 +1901,17 @@ void j2k_destroy_compress(opj_j2k_t *j2k) {
if(!j2k) return;
- if(j2k->image_info != NULL) {
- opj_image_info_t *image_info = j2k->image_info;
- if (image_info->index_on && j2k->cp) {
+ if(j2k->cstr_info != NULL) {
+ opj_codestream_info_t *cstr_info = j2k->cstr_info;
+ if (cstr_info->index_on && j2k->cp) {
opj_cp_t *cp = j2k->cp;
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
- opj_tile_info_t *tile_info = &image_info->tile[tileno];
+ opj_tile_info_t *tile_info = &cstr_info->tile[tileno];
opj_free(tile_info->thresh);
opj_free(tile_info->packet);
}
- opj_free(image_info->tile);
+ opj_free(cstr_info->tile);
}
- opj_free(image_info);
}
if(j2k->cp != NULL) {
opj_cp_t *cp = j2k->cp;
@@ -1970,9 +1969,6 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
/* creation of an index file ? */
cp->index_on = parameters->index_on;
- if(cp->index_on) {
- j2k->image_info = (opj_image_info_t*)opj_malloc(sizeof(opj_image_info_t));
- }
/* tiles */
cp->tdx = parameters->cp_tdx;
@@ -2198,241 +2194,8 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
}
}
-/**
-Create an index file
-@param j2k
-@param cio
-@param image_info
-@param index Index filename
-@return Returns 1 if successful, returns 0 otherwise
-*/
-static int j2k_create_index(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_info_t *image_info, char *index) {
- int tileno, compno, layno, resno, precno, pack_nb, x, y;
- FILE *stream = NULL;
- double total_disto = 0;
-
- image_info->codestream_size = cio_tell(cio) + j2k->pos_correction; /* Correction 14/4/03 suite rmq de Patrick */
-
-
-#ifdef USE_JPWL
- /* if JPWL is enabled and the name coincides with our own set
- then discard the creation of the file: this was just done to
- enable indexing, we do not want an index file
- */
- if (j2k->cp->epc_on && !strcmp(index, JPWL_PRIVATEINDEX_NAME))
- return 1;
-#endif /* USE_JPWL */
-
-
- stream = fopen(index, "w");
- if (!stream) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "failed to open %s for writing\n", index);
- return 0;
- }
-
- fprintf(stream, "%d %d\n", image_info->image_w, image_info->image_h);
- fprintf(stream, "%d\n", image_info->prog);
- fprintf(stream, "%d %d\n", image_info->tile_x, image_info->tile_y);
- fprintf(stream, "%d %d\n", image_info->tw, image_info->th);
- fprintf(stream, "%d\n", image_info->comp);
- fprintf(stream, "%d\n", image_info->layer);
- fprintf(stream, "%d\n", image_info->decomposition);
-
- for (resno = image_info->decomposition; resno >= 0; resno--) {
- fprintf(stream, "[%d,%d] ",
- (1 << image_info->tile[0].pdx[resno]), (1 << image_info->tile[0].pdx[resno])); /* based on tile 0 */
- }
- fprintf(stream, "\n");
- fprintf(stream, "%d\n", image_info->main_head_end);
- fprintf(stream, "%d\n", image_info->codestream_size);
-
- for (tileno = 0; tileno < image_info->tw * image_info->th; tileno++) {
- fprintf(stream, "%4d %9d %9d %9d %9e %9d %9e\n",
- image_info->tile[tileno].num_tile,
- image_info->tile[tileno].start_pos,
- image_info->tile[tileno].end_header,
- image_info->tile[tileno].end_pos,
- image_info->tile[tileno].distotile, image_info->tile[tileno].nbpix,
- image_info->tile[tileno].distotile / image_info->tile[tileno].nbpix);
- }
-
- for (tileno = 0; tileno < image_info->tw * image_info->th; tileno++) {
- int start_pos, end_pos;
- double disto = 0;
- pack_nb = 0;
-
- if (image_info->prog == LRCP) { /* LRCP */
-
- fprintf(stream, "pack_nb tileno layno resno compno precno start_pos end_pos disto\n");
-
- for (layno = 0; layno < image_info->layer; layno++) {
- for (resno = 0; resno < image_info->decomposition + 1; resno++) {
- for (compno = 0; compno < image_info->comp; compno++) {
- int prec_max = image_info->tile[tileno].pw[resno] * image_info->tile[tileno].ph[resno];
- for (precno = 0; precno < prec_max; precno++) {
- start_pos = image_info->tile[tileno].packet[pack_nb].start_pos;
- end_pos = image_info->tile[tileno].packet[pack_nb].end_pos;
- disto = image_info->tile[tileno].packet[pack_nb].disto;
- fprintf(stream, "%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",
- pack_nb, tileno, layno, resno, compno, precno, start_pos, end_pos, disto);
- total_disto += disto;
- pack_nb++;
- }
- }
- }
- }
- } /* LRCP */
- else if (image_info->prog == RLCP) { /* RLCP */
-
- fprintf(stream, "pack_nb tileno resno layno compno precno start_pos end_pos disto\n");
-
- for (resno = 0; resno < image_info->decomposition + 1; resno++) {
- for (layno = 0; layno < image_info->layer; layno++) {
- for (compno = 0; compno < image_info->comp; compno++) {
- int prec_max = image_info->tile[tileno].pw[resno] * image_info->tile[tileno].ph[resno];
- for (precno = 0; precno < prec_max; precno++) {
- start_pos = image_info->tile[tileno].packet[pack_nb].start_pos;
- end_pos = image_info->tile[tileno].packet[pack_nb].end_pos;
- disto = image_info->tile[tileno].packet[pack_nb].disto;
- fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %8e\n",
- pack_nb, tileno, resno, layno, compno, precno, start_pos, end_pos, disto);
- total_disto += disto;
- pack_nb++;
- }
- }
- }
- }
- } /* RLCP */
- else if (image_info->prog == RPCL) { /* RPCL */
-
- fprintf(stream, "\npack_nb tileno resno precno compno layno start_pos end_pos disto\n");
-
- for (resno = 0; resno < image_info->decomposition + 1; resno++) {
- /* I suppose components have same XRsiz, YRsiz */
- int x0 = image_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)image_info->tw ) * image_info->tw * image_info->tile_x;
- int y0 = image_info->tile_Ox + (int)floor( (float)tileno/(float)image_info->tw ) * image_info->tile_y;
- int x1 = x0 + image_info->tile_x;
- int y1 = y0 + image_info->tile_y;
- for (compno = 0; compno < image_info->comp; compno++) {
- int prec_max = image_info->tile[tileno].pw[resno] * image_info->tile[tileno].ph[resno];
- for (precno = 0; precno < prec_max; precno++) {
- int pcnx = image_info->tile[tileno].pw[resno];
- int pcx = (int) pow( 2, image_info->tile[tileno].pdx[resno] + image_info->decomposition - resno );
- int pcy = (int) pow( 2, image_info->tile[tileno].pdy[resno] + image_info->decomposition - resno );
- int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
- int precno_y = (int) floor( (float)precno/(float)pcnx );
- for(y = y0; y < y1; y++) {
- if (precno_y*pcy == y ) {
- for (x = x0; x < x1; x++) {
- if (precno_x*pcx == x ) {
- for (layno = 0; layno < image_info->layer; layno++) {
- start_pos = image_info->tile[tileno].packet[pack_nb].start_pos;
- end_pos = image_info->tile[tileno].packet[pack_nb].end_pos;
- disto = image_info->tile[tileno].packet[pack_nb].disto;
- fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d %9d %8e\n",
- pack_nb, tileno, resno, precno, compno, layno, start_pos, end_pos, disto);
- total_disto += disto;
- pack_nb++;
- }
- }
- }/* x = x0..x1 */
- }
- } /* y = y0..y1 */
- } /* precno */
- } /* compno */
- } /* resno */
- } /* RPCL */
- else if (image_info->prog == PCRL) { /* PCRL */
- /* I suppose components have same XRsiz, YRsiz */
- int x0 = image_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)image_info->tw ) * image_info->tw * image_info->tile_x;
- int y0 = image_info->tile_Ox + (int)floor( (float)tileno/(float)image_info->tw ) * image_info->tile_y;
- int x1 = x0 + image_info->tile_x;
- int y1 = y0 + image_info->tile_y;
-
- fprintf(stream, "\npack_nb tileno precno compno resno layno start_pos end_pos disto\n");
-
- for (compno = 0; compno < image_info->comp; compno++) {
- for (resno = 0; resno < image_info->decomposition + 1; resno++) {
- int prec_max = image_info->tile[tileno].pw[resno] * image_info->tile[tileno].ph[resno];
- for (precno = 0; precno < prec_max; precno++) {
- int pcnx = image_info->tile[tileno].pw[resno];
- int pcx = (int) pow( 2, image_info->tile[tileno].pdx[resno] + image_info->decomposition - resno );
- int pcy = (int) pow( 2, image_info->tile[tileno].pdy[resno] + image_info->decomposition - resno );
- int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
- int precno_y = (int) floor( (float)precno/(float)pcnx );
- for(y = y0; y < y1; y++) {
- if (precno_y*pcy == y ) {
- for (x = x0; x < x1; x++) {
- if (precno_x*pcx == x ) {
- for (layno = 0; layno < image_info->layer; layno++) {
- start_pos = image_info->tile[tileno].packet[pack_nb].start_pos;
- end_pos = image_info->tile[tileno].packet[pack_nb].end_pos;
- disto = image_info->tile[tileno].packet[pack_nb].disto;
- fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n",
- pack_nb, tileno, precno, compno, resno, layno, start_pos, end_pos, disto);
- total_disto += disto;
- pack_nb++;
- }
- }
- }/* x = x0..x1 */
- }
- } /* y = y0..y1 */
- } /* precno */
- } /* resno */
- } /* compno */
- } /* PCRL */
- else { /* CPRL */
-
- fprintf(stream, "\npack_nb tileno compno precno resno layno start_pos end_pos disto\n");
-
- for (compno = 0; compno < image_info->comp; compno++) {
- /* I suppose components have same XRsiz, YRsiz */
- int x0 = image_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)image_info->tw ) * image_info->tw * image_info->tile_x;
- int y0 = image_info->tile_Ox + (int)floor( (float)tileno/(float)image_info->tw ) * image_info->tile_y;
- int x1 = x0 + image_info->tile_x;
- int y1 = y0 + image_info->tile_y;
-
- for (resno = 0; resno < image_info->decomposition + 1; resno++) {
- int prec_max = image_info->tile[tileno].pw[resno] * image_info->tile[tileno].ph[resno];
- for (precno = 0; precno < prec_max; precno++) {
- int pcnx = image_info->tile[tileno].pw[resno];
- int pcx = (int) pow( 2, image_info->tile[tileno].pdx[resno] + image_info->decomposition - resno );
- int pcy = (int) pow( 2, image_info->tile[tileno].pdy[resno] + image_info->decomposition - resno );
- int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
- int precno_y = (int) floor( (float)precno/(float)pcnx );
- for(y = y0; y < y1; y++) {
- if (precno_y*pcy == y ) {
- for (x = x0; x < x1; x++) {
- if (precno_x*pcx == x ) {
- for (layno = 0; layno < image_info->layer; layno++) {
- start_pos = image_info->tile[tileno].packet[pack_nb].start_pos;
- end_pos = image_info->tile[tileno].packet[pack_nb].end_pos;
- disto = image_info->tile[tileno].packet[pack_nb].disto;
- fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n",
- pack_nb, tileno, compno, precno, resno, layno, start_pos, end_pos, disto);
- total_disto += disto;
- pack_nb++;
- }
- }
- }/* x = x0..x1 */
- }
- } /* y = y0..y1 */
- } /* precno */
- } /* resno */
- } /* compno */
- } /* CPRL */
- } /* tileno */
-
- fprintf(stream, "%8e\n", image_info->D_max); /* SE max */
- fprintf(stream, "%.8e\n", total_disto); /* SE totale */
- fclose(stream);
-
- return 1;
-}
-
-bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index) {
+bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
int tileno, compno;
- opj_image_info_t *image_info = NULL;
opj_cp_t *cp = NULL;
opj_tcd_t *tcd = NULL; /* TCD component */
@@ -2445,23 +2208,26 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
/* j2k_dump_cp(stdout, image, cp); */
/* INDEX >> */
- image_info = j2k->image_info;
- if (image_info && cp->index_on) {
- image_info->index_on = cp->index_on;
- image_info->tile = (opj_tile_info_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tile_info_t));
- image_info->image_w = image->x1 - image->x0;
- image_info->image_h = image->y1 - image->y0;
- image_info->prog = (&cp->tcps[0])->prg;
- image_info->tw = cp->tw;
- image_info->th = cp->th;
- image_info->tile_x = cp->tdx; /* new version parser */
- image_info->tile_y = cp->tdy; /* new version parser */
- image_info->tile_Ox = cp->tx0; /* new version parser */
- image_info->tile_Oy = cp->ty0; /* new version parser */
- image_info->comp = image->numcomps;
- image_info->layer = (&cp->tcps[0])->numlayers;
- image_info->decomposition = (&cp->tcps[0])->tccps->numresolutions - 1;
- image_info->D_max = 0; /* ADD Marcela */
+ j2k->cstr_info = cstr_info;
+ if (cstr_info && cp->index_on) {
+ cstr_info->index_on = cp->index_on;
+ cstr_info->tile = (opj_tile_info_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tile_info_t));
+ cstr_info->image_w = image->x1 - image->x0;
+ cstr_info->image_h = image->y1 - image->y0;
+ cstr_info->prog = (&cp->tcps[0])->prg;
+ cstr_info->tw = cp->tw;
+ cstr_info->th = cp->th;
+ cstr_info->tile_x = cp->tdx; /* new version parser */
+ cstr_info->tile_y = cp->tdy; /* new version parser */
+ cstr_info->tile_Ox = cp->tx0; /* new version parser */
+ cstr_info->tile_Oy = cp->ty0; /* new version parser */
+ cstr_info->comp = image->numcomps;
+ cstr_info->layer = (&cp->tcps[0])->numlayers;
+ cstr_info->decomposition = (&cp->tcps[0])->tccps->numresolutions - 1;
+ cstr_info->D_max = 0; /* ADD Marcela */
+ }
+ else if (cstr_info) {
+ cstr_info->index_on = 0;
}
/* << INDEX */
@@ -2487,7 +2253,7 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
}
j2k->totnum_tp = j2k_calculate_tp(cp,image->numcomps,image,j2k);
- /* TLM Marker*/
+ /* TLM Marker*/
if(cp->cinema){
j2k_write_tlm(j2k);
if (cp->cinema == CINEMA4K_24) {
@@ -2496,8 +2262,8 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
}
/* INDEX >> */
- if(image_info && image_info->index_on) {
- image_info->main_head_end = cio_tell(cio) - 1;
+ if(cstr_info && cstr_info->index_on) {
+ cstr_info->main_head_end = cio_tell(cio) - 1;
}
/* << INDEX */
/**** Main Header ENDS here ***/
@@ -2506,7 +2272,6 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
tcd = tcd_create(j2k->cinfo);
/* encode each tile */
-
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
int pino;
int tilepartno=0;
@@ -2525,9 +2290,9 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
}
/* INDEX >> */
- if(image_info && image_info->index_on) {
- image_info->tile[j2k->curtileno].num_tile = j2k->curtileno;
- image_info->tile[j2k->curtileno].start_pos = cio_tell(cio) + j2k->pos_correction;
+ if(cstr_info && cstr_info->index_on) {
+ cstr_info->tile[j2k->curtileno].num_tile = j2k->curtileno;
+ cstr_info->tile[j2k->curtileno].start_pos = cio_tell(cio) + j2k->pos_correction;
}
/* << INDEX */
@@ -2559,8 +2324,8 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
}
/* INDEX >> */
- if(image_info && image_info->index_on) {
- image_info->tile[j2k->curtileno].end_pos = cio_tell(cio) + j2k->pos_correction - 1;
+ if(cstr_info && cstr_info->index_on) {
+ cstr_info->tile[j2k->curtileno].end_pos = cio_tell(cio) + j2k->pos_correction - 1;
}
/* << INDEX */
@@ -2590,22 +2355,17 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
free(j2k->cur_totnum_tp);
j2k_write_eoc(j2k);
-
- /* Creation of the index file */
- if(image_info && image_info->index_on) {
- if(!j2k_create_index(j2k, cio, image_info, index)) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "failed to create index file %s\n", index);
- return false;
- }
- }
+ if(cstr_info && cstr_info->index_on) {
+ cstr_info->codestream_size = cio_tell(cio) + j2k->pos_correction;
+ }
#ifdef USE_JPWL
/*
preparation of JPWL marker segments: can be finalized only when the whole
codestream is known
*/
- if(image_info && image_info->index_on && cp->epc_on) {
+ if(cstr_info && cstr_info->index_on && cp->epc_on) {
/* let's begin creating a marker list, according to user wishes */
jpwl_prepare_marks(j2k, cio, image);
@@ -2616,23 +2376,11 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
/* do not know exactly what is this for,
but it gets called during index creation */
j2k->pos_correction = 0;
-
- /* Re-creation of the index file, with updated info */
- if(image_info && image_info->index_on) {
- if(!j2k_create_index(j2k, cio, image_info, index)) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "failed to re-create index file %s\n", index);
- return false;
- }
- }
-
- /* now we finalize the marker contents */
- /*jpwl_finalize_marks(j2k, cio, image);*/
-
}
#endif /* USE_JPWL */
-
return true;
}
+
diff --git a/libopenjpeg/j2k.h b/libopenjpeg/j2k.h
index c18f4cdc..8ed758c2 100644
--- a/libopenjpeg/j2k.h
+++ b/libopenjpeg/j2k.h
@@ -305,92 +305,6 @@ typedef struct opj_cp {
} opj_cp_t;
/**
-Information concerning a packet inside tile
-*/
-typedef struct opj_packet_info {
- /** start position */
- int start_pos;
- /** end position */
- int end_pos;
- /** ADD for Marcela */
- double disto;
-} opj_packet_info_t;
-
-/**
-Index structure : information regarding tiles inside image
-*/
-typedef struct opj_tile_info {
- /** value of thresh for each layer by tile cfr. Marcela */
- double *thresh;
- /** number of tile */
- int num_tile;
- /** start position */
- int start_pos;
- /** end position of the header */
- int end_header;
- /** end position */
- int end_pos;
- /** precinct number for each resolution level (width) */
- int pw[33];
- /** precinct number for each resolution level (height) */
- int ph[33];
- /** precinct size (in power of 2), in X for each resolution level */
- int pdx[33];
- /** precinct size (in power of 2), in Y for each resolution level */
- int pdy[33];
- /** information concerning packets inside tile */
- opj_packet_info_t *packet;
- /** add fixed_quality */
- int nbpix;
- /** add fixed_quality */
- double distotile;
-} opj_tile_info_t;
-
-/**
-Index structure
-*/
-typedef struct opj_image_info {
- /** 0 = no index || 1 = index */
- int index_on;
- /** maximum distortion reduction on the whole image (add for Marcela) */
- double D_max;
- /** packet number */
- int num;
- /** writing the packet in the index with t2_encode_packets */
- int index_write;
- /** image width */
- int image_w;
- /** image height */
- int image_h;
- /** progression order */
- OPJ_PROG_ORDER prog;
- /** tile size in x */
- int tile_x;
- /** tile size in y */
- int tile_y;
- /** */
- int tile_Ox;
- /** */
- int tile_Oy;
- /** number of tiles in X */
- int tw;
- /** number of tiles in Y */
- int th;
- /** component numbers */
- int comp;
- /** number of layer */
- int layer;
- /** number of decomposition */
- int decomposition;
- /** main header position */
- int main_head_end;
- /** codestream's size */
- int codestream_size;
- /** information regarding tiles inside image */
- opj_tile_info_t *tile;
-} opj_image_info_t;
-
-/**
JPEG-2000 codestream reader/writer
*/
typedef struct opj_j2k {
@@ -445,7 +359,7 @@ typedef struct opj_j2k {
/** pointer to the coding parameters */
opj_cp_t *cp;
/** helper used to write the index file */
- opj_image_info_t *image_info;
+ opj_codestream_info_t *cstr_info;
/** pointer to the byte i/o stream */
opj_cio_t *cio;
} opj_j2k_t;
@@ -513,10 +427,11 @@ Encode an image into a JPEG-2000 codestream
@param j2k J2K compressor handle
@param cio Output buffer stream
@param image Image to encode
-@param index Name of the index file if required, NULL otherwise
+@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns true if successful, returns false otherwise
*/
-bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index);
+bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
+
/* ----------------------------------------------------------------------- */
/*@}*/
diff --git a/libopenjpeg/j2k_lib.h b/libopenjpeg/j2k_lib.h
index a8fc8f20..bb936c8b 100644
--- a/libopenjpeg/j2k_lib.h
+++ b/libopenjpeg/j2k_lib.h
@@ -69,8 +69,17 @@ Allocate memory aligned to a 16 byte boundry
#include <malloc.h>
#endif
-#define opj_aligned_malloc(size) _mm_malloc(size, 16)
-#define opj_aligned_free(m) _mm_free(m)
+#ifdef _mm_malloc
+ #define opj_aligned_malloc(size) _mm_malloc(size, 16)
+ #else
+ #define opj_aligned_malloc(size) malloc(size)
+ #endif
+
+ #ifdef _mm_free
+ #define opj_aligned_free(m) _mm_free(m)
+ #else
+ #define opj_aligned_free(m) free(m)
+ #endif
#else /* Not WIN32 */
diff --git a/libopenjpeg/jp2.c b/libopenjpeg/jp2.c
index a40e56d4..79e367c0 100644
--- a/libopenjpeg/jp2.c
+++ b/libopenjpeg/jp2.c
@@ -71,7 +71,7 @@ Read the FTYP box - File type box
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
-static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index);
+static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
static bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset);
static void jp2_write_jp(opj_cio_t *cio);
/**
@@ -404,7 +404,7 @@ static bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
return true;
}
-static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index) {
+static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
unsigned int j2k_codestream_offset, j2k_codestream_length;
opj_jp2_box_t box;
@@ -416,7 +416,7 @@ static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, ch
/* J2K encoding */
j2k_codestream_offset = cio_tell(cio);
- if(!j2k_encode(j2k, cio, image, index)) {
+ if(!j2k_encode(j2k, cio, image, cstr_info)) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Failed to encode image\n");
return 0;
}
@@ -686,7 +686,7 @@ void jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_
}
-bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index) {
+bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
/* JP2 encoding */
@@ -699,7 +699,7 @@ bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index)
/* J2K encoding */
- if(!jp2_write_jp2c(jp2, cio, image, index)) {
+ if(!jp2_write_jp2c(jp2, cio, image, cstr_info)) {
opj_event_msg(jp2->cinfo, EVT_ERROR, "Failed to encode image\n");
return false;
}
diff --git a/libopenjpeg/jp2.h b/libopenjpeg/jp2.h
index 61fc1e42..d04324bc 100644
--- a/libopenjpeg/jp2.h
+++ b/libopenjpeg/jp2.h
@@ -163,10 +163,10 @@ Encode an image into a JPEG-2000 file stream
@param jp2 JP2 compressor handle
@param cio Output buffer stream
@param image Image to encode
-@param index Name of the index file if required, NULL otherwise
+@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns true if successful, returns false otherwise
*/
-bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index);
+bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
/* ----------------------------------------------------------------------- */
/*@}*/
diff --git a/libopenjpeg/openjpeg.c b/libopenjpeg/openjpeg.c
index ba3ac6d8..327154db 100644
--- a/libopenjpeg/openjpeg.c
+++ b/libopenjpeg/openjpeg.c
@@ -287,13 +287,13 @@ void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *param
}
}
-bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
+bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
if(cinfo && cio && image) {
switch(cinfo->codec_format) {
case CODEC_J2K:
- return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, index);
+ return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info);
case CODEC_JP2:
- return jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, index);
+ return jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info);
case CODEC_JPT:
case CODEC_UNKNOWN:
default:
@@ -303,5 +303,3 @@ bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *im
return false;
}
-
-
diff --git a/libopenjpeg/openjpeg.h b/libopenjpeg/openjpeg.h
index 483f8d6b..24e2f6a5 100644
--- a/libopenjpeg/openjpeg.h
+++ b/libopenjpeg/openjpeg.h
@@ -580,6 +580,98 @@ typedef struct opj_image_comptparm {
int sgnd;
} opj_image_cmptparm_t;
+/*
+==========================================================
+ Information on the JPEG 2000 codestream
+==========================================================
+*/
+
+/**
+Index structure : Information concerning a packet inside tile
+*/
+typedef struct opj_packet_info {
+ /** start position */
+ int start_pos;
+ /** end position */
+ int end_pos;
+ /** packet distorsion */
+ double disto;
+} opj_packet_info_t;
+
+/**
+Index structure : information regarding tiles inside image
+*/
+typedef struct opj_tile_info {
+ /** value of thresh for each layer by tile cfr. Marcela */
+ double *thresh;
+ /** number of tile */
+ int num_tile;
+ /** start position */
+ int start_pos;
+ /** end position of the header */
+ int end_header;
+ /** end position */
+ int end_pos;
+ /** precinct number for each resolution level (width) */
+ int pw[33];
+ /** precinct number for each resolution level (height) */
+ int ph[33];
+ /** precinct size (in power of 2), in X for each resolution level */
+ int pdx[33];
+ /** precinct size (in power of 2), in Y for each resolution level */
+ int pdy[33];
+ /** information concerning packets inside tile */
+ opj_packet_info_t *packet;
+ /** add fixed_quality */
+ int nbpix;
+ /** add fixed_quality */
+ double distotile;
+} opj_tile_info_t;
+
+/**
+Index structure of the codestream
+*/
+typedef struct opj_codestream_info {
+ /** 0 = no index || 1 = index */
+ int index_on;
+ /** maximum distortion reduction on the whole image (add for Marcela) */
+ double D_max;
+ /** packet number */
+ int num;
+ /** writing the packet in the index with t2_encode_packets */
+ int index_write;
+ /** image width */
+ int image_w;
+ /** image height */
+ int image_h;
+ /** progression order */
+ OPJ_PROG_ORDER prog;
+ /** tile size in x */
+ int tile_x;
+ /** tile size in y */
+ int tile_y;
+ /** */
+ int tile_Ox;
+ /** */
+ int tile_Oy;
+ /** number of tiles in X */
+ int tw;
+ /** number of tiles in Y */
+ int th;
+ /** component numbers */
+ int comp;
+ /** number of layer */
+ int layer;
+ /** number of decomposition */
+ int decomposition;
+ /** main header position */
+ int main_head_end;
+ /** codestream's size */
+ int codestream_size;
+ /** information regarding tiles inside image */
+ opj_tile_info_t *tile;
+} opj_codestream_info_t;
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -730,9 +822,9 @@ Set encoding parameters to default values, that means :
OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
/**
Setup the encoder parameters using the current image and using user parameters.
-@param cinfo compressor handle
-@param parameters compression parameters
-@param image input filled image
+@param cinfo Compressor handle
+@param parameters Compression parameters
+@param image Input filled image
*/
OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
/**
@@ -740,10 +832,10 @@ Encode an image into a JPEG-2000 codestream
@param cinfo compressor handle
@param cio Output buffer stream
@param image Image to encode
-@param index Name of the index file if required, NULL otherwise
+@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns true if successful, returns false otherwise
*/
-OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
+OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
#ifdef __cplusplus
}
diff --git a/libopenjpeg/t2.c b/libopenjpeg/t2.c
index 649493c7..53d5868b 100644
--- a/libopenjpeg/t2.c
+++ b/libopenjpeg/t2.c
@@ -53,11 +53,11 @@ Encode a packet of a tile to a destination buffer
@param pi Packet identity
@param dest Destination buffer
@param len Length of the destination buffer
-@param image_info Structure to create an index file
+@param cstr_info Codestream information structure
@param tileno Number of the tile encoded
@return
*/
-static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_image_info_t *image_info, int tileno);
+static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_codestream_info_t *cstr_info, int tileno);
/**
@param seg
@param cblksty
@@ -126,7 +126,7 @@ static int t2_getnumpasses(opj_bio_t *bio) {
return (37 + bio_read(bio, 7));
}
-static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int length, opj_image_info_t * image_info, int tileno) {
+static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int length, opj_codestream_info_t *cstr_info, int tileno) {
int bandno, cblkno;
unsigned char *sop = 0, *eph = 0;
unsigned char *c = dest;
@@ -148,8 +148,8 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
sop[1] = 145;
sop[2] = 0;
sop[3] = 4;
- sop[4] = (image_info->num % 65536) / 256;
- sop[5] = (image_info->num % 65536) % 256;
+ sop[4] = (cstr_info->num % 65536) / 256;
+ sop[5] = (cstr_info->num % 65536) % 256;
memcpy(c, sop, 6);
opj_free(sop);
c += 6;
@@ -278,12 +278,12 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
cblk->numpasses += layer->numpasses;
c += layer->len;
/* ADD for index Cfr. Marcela --> delta disto by packet */
- if(image_info && image_info->index_write && image_info->index_on) {
- opj_tile_info_t *info_TL = &image_info->tile[tileno];
- opj_packet_info_t *info_PK = &info_TL->packet[image_info->num];
+ if(cstr_info && cstr_info->index_write && cstr_info->index_on) {
+ opj_tile_info_t *info_TL = &cstr_info->tile[tileno];
+ opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->num];
info_PK->disto += layer->disto;
- if (image_info->D_max < info_PK->disto) {
- image_info->D_max = info_PK->disto;
+ if (cstr_info->D_max < info_PK->disto) {
+ cstr_info->D_max = info_PK->disto;
}
}
/* </ADD> */
@@ -564,7 +564,7 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
/* ----------------------------------------------------------------------- */
-int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_image_info_t *image_info,int tpnum, int tppos,int pino, J2K_T2_MODE t2_mode){
+int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_codestream_info_t *cstr_info,int tpnum, int tppos,int pino, J2K_T2_MODE t2_mode){
unsigned char *c = dest;
int e = 0;
int compno;
@@ -590,7 +590,7 @@ int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlaye
pi_create_encode(pi, cp,tileno,poc,tpnum,tppos,t2_mode);
while (pi_next(&pi[poc])) {
if (pi[poc].layno < maxlayers) {
- e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[poc], c, dest + len - c, image_info, tileno);
+ e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[poc], c, dest + len - c, cstr_info, tileno);
comp_len = comp_len + e;
if (e == -999) {
break;
@@ -613,26 +613,26 @@ int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlaye
pi_create_encode(pi, cp,tileno,pino,tpnum,tppos,t2_mode);
while (pi_next(&pi[pino])) {
if (pi[pino].layno < maxlayers) {
- e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, image_info, tileno);
+ e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, cstr_info, tileno);
if (e == -999) {
break;
} else {
c += e;
}
/* INDEX >> */
- if(image_info && image_info->index_on) {
- if(image_info->index_write) {
- opj_tile_info_t *info_TL = &image_info->tile[tileno];
- opj_packet_info_t *info_PK = &info_TL->packet[image_info->num];
- if (!image_info->num) {
+ if(cstr_info && cstr_info->index_on) {
+ if(cstr_info->index_write) {
+ opj_tile_info_t *info_TL = &cstr_info->tile[tileno];
+ opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->num];
+ if (!cstr_info->num) {
info_PK->start_pos = info_TL->end_header + 1;
} else {
- info_PK->start_pos = (cp->tp_on && info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[image_info->num - 1].end_pos + 1;
+ info_PK->start_pos = (cp->tp_on && info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->num - 1].end_pos + 1;
}
info_PK->end_pos = info_PK->start_pos + e - 1;
}
- image_info->num++;
+ cstr_info->num++;
}
/* << INDEX */
}
diff --git a/libopenjpeg/t2.h b/libopenjpeg/t2.h
index 87ed2d2c..ae2db635 100644
--- a/libopenjpeg/t2.h
+++ b/libopenjpeg/t2.h
@@ -64,12 +64,12 @@ Encode the packets of a tile to a destination buffer
@param maxlayers maximum number of layers
@param dest the destination buffer
@param len the length of the destination buffer
-@param image_info structure to create an index file
+@param cstr_info Codestream information structure
@param tpnum Tile part number of the current tile
@param tppos The position of the tile part flag in the progression order
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
*/
-int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_image_info_t *image_info,int tpnum, int tppos,int pino,J2K_T2_MODE t2_mode);
+int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_codestream_info_t *cstr_info,int tpnum, int tppos,int pino,J2K_T2_MODE t2_mode);
/**
Decode the packets of a tile from a source buffer
@param t2 T2 handle
diff --git a/libopenjpeg/tcd.c b/libopenjpeg/tcd.c
index 7479822a..1e7ed1a7 100644
--- a/libopenjpeg/tcd.c
+++ b/libopenjpeg/tcd.c
@@ -979,7 +979,7 @@ void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) {
}
}
-bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_info_t * image_info) {
+bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) {
int compno, resno, bandno, precno, cblkno, passno, layno;
double min, max;
double cumdisto[100]; /* fixed_quality */
@@ -1048,8 +1048,8 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
} /* compno */
/* index file */
- if(image_info && image_info->index_on) {
- opj_tile_info_t *tile_info = &image_info->tile[tcd->tcd_tileno];
+ if(cstr_info && cstr_info->index_on) {
+ opj_tile_info_t *tile_info = &cstr_info->tile[tcd->tcd_tileno];
tile_info->nbpix = tcd_tile->nbpix;
tile_info->distotile = tcd_tile->distotile;
tile_info->thresh = (double *) opj_malloc(tcd_tcp->numlayers * sizeof(double));
@@ -1068,7 +1068,11 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
/* fixed_quality */
distotarget = tcd_tile->distotile - ((K * maxSE) / pow((float)10, tcd_tcp->distoratio[layno] / 10));
- if ((tcd_tcp->rates[layno]) || (cp->disto_alloc == 0)) {
+ /* Don't try to find an optimal threshold but rather take everything not included yet, if
+ -r xx,yy,zz,0 (disto_alloc == 1 and rates == 0)
+ -q xx,yy,zz,0 (fixed_quality == 1 and distoratio == 0)
+ ==> possible to have some lossy layers and the last layer for sure lossless */
+ if ( ((cp->disto_alloc==1) && (tcd_tcp->rates[layno]>0)) || ((cp->fixed_quality==1) && (tcd_tcp->distoratio[layno]>0))) {
opj_t2_t *t2 = t2_create(tcd->cinfo, tcd->image, cp);
for (i = 0; i < 32; i++) {
@@ -1080,7 +1084,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
if (cp->fixed_quality) { /* fixed_quality */
if(cp->cinema){
- l = t2_encode_packets(t2,tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, image_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC);
+ l = t2_encode_packets(t2,tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC);
if (l == -999) {
lo = thresh;
continue;
@@ -1106,7 +1110,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
lo = thresh;
}
} else {
- l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, image_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC);
+ l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC);
/* TODO: what to do with l ??? seek / tell ??? */
/* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */
if (l == -999) {
@@ -1129,8 +1133,8 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
return false;
}
- if(image_info && image_info->index_on) { /* Threshold for Marcela Index */
- image_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh;
+ if(cstr_info && cstr_info->index_on) { /* Threshold for Marcela Index */
+ cstr_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh;
}
tcd_makelayer(tcd, layno, goodthresh, 1);
@@ -1141,7 +1145,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
return true;
}
-int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_image_info_t * image_info) {
+int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) {
int compno;
int l, i, npck = 0;
opj_tcd_tile_t *tile = NULL;
@@ -1166,20 +1170,20 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
if(tcd->cur_tp_num == 0){
tcd->encoding_time = opj_clock(); /* time needed to encode a tile */
/* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */
- if(image_info && image_info->index_on) {
+ if(cstr_info && cstr_info->index_on) {
opj_tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /* based on component 0 */
for (i = 0; i < tilec_idx->numresolutions; i++) {
opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[i];
- image_info->tile[tileno].pw[i] = res_idx->pw;
- image_info->tile[tileno].ph[i] = res_idx->ph;
+ cstr_info->tile[tileno].pw[i] = res_idx->pw;
+ cstr_info->tile[tileno].ph[i] = res_idx->ph;
npck += res_idx->pw * res_idx->ph;
- image_info->tile[tileno].pdx[i] = tccp->prcw[i];
- image_info->tile[tileno].pdy[i] = tccp->prch[i];
+ cstr_info->tile[tileno].pdx[i] = tccp->prcw[i];
+ cstr_info->tile[tileno].pdy[i] = tccp->prch[i];
}
- image_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(image_info->comp * image_info->layer * npck * sizeof(opj_packet_info_t));
+ cstr_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(cstr_info->comp * cstr_info->layer * npck * sizeof(opj_packet_info_t));
}
/* << INDEX */
@@ -1251,12 +1255,12 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
/*-----------RATE-ALLOCATE------------------*/
/* INDEX */
- if(image_info) {
- image_info->index_write = 0;
+ if(cstr_info) {
+ cstr_info->index_write = 0;
}
if (cp->disto_alloc || cp->fixed_quality) { /* fixed_quality */
/* Normal Rate/distortion allocation */
- tcd_rateallocate(tcd, dest, len, image_info);
+ tcd_rateallocate(tcd, dest, len, cstr_info);
} else {
/* Fixed layer allocation */
tcd_rateallocate_fixed(tcd);
@@ -1265,12 +1269,12 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
/*--------------TIER2------------------*/
/* INDEX */
- if(image_info) {
- image_info->index_write = 1;
+ if(cstr_info) {
+ cstr_info->index_write = 1;
}
t2 = t2_create(tcd->cinfo, image, cp);
- l = t2_encode_packets(t2,tileno, tile, tcd_tcp->numlayers, dest, len, image_info,tcd->tp_num,tcd->tp_pos,tcd->cur_pino,FINAL_PASS);
+ l = t2_encode_packets(t2,tileno, tile, tcd_tcp->numlayers, dest, len, cstr_info,tcd->tp_num,tcd->tp_pos,tcd->cur_pino,FINAL_PASS);
t2_destroy(t2);
/*---------------CLEAN-------------------*/
diff --git a/libopenjpeg/tcd.h b/libopenjpeg/tcd.h
index 836926d6..a357b104 100644
--- a/libopenjpeg/tcd.h
+++ b/libopenjpeg/tcd.h
@@ -238,17 +238,17 @@ void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);
void tcd_rateallocate_fixed(opj_tcd_t *tcd);
void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);
-bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_info_t * image_info);
+bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info);
/**
Encode a tile from the raw image into a buffer
@param tcd TCD handle
@param tileno Number that identifies one of the tiles to be encoded
@param dest Destination buffer
@param len Length of destination buffer
-@param image_info Creation of index file
+@param cstr_info Codestream information structure
@return
*/
-int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_image_info_t * image_info);
+int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info);
/**
Decode a tile from a buffer into a raw image
@param tcd TCD handle