Changed the way the image structure is allocated when the decoding parameters include some resolutions to discard. This should have a significant impact for the decoding of huge images when some resolutions are discarder (-r parameter)
Warning: The output image size is now reduced when discarding resolutions !
This commit is contained in:
@@ -406,7 +406,7 @@ static int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){
|
||||
|
||||
/** mem allocation for TLM marker*/
|
||||
int j2k_calculate_tp(opj_cp_t *cp,int img_numcomp,opj_image_t *image,opj_j2k_t *j2k ){
|
||||
int pino,tileno,maxres=0,totnum_tp=0;
|
||||
int pino,tileno,totnum_tp=0;
|
||||
j2k->cur_totnum_tp = (int *) opj_malloc(cp->tw * cp->th * sizeof(int));
|
||||
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
|
||||
int cur_totnum_tp = 0;
|
||||
@@ -579,7 +579,7 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
|
||||
h = int_ceildiv(image->y1 - image->y0, image->comps[i].dy);
|
||||
|
||||
image->comps[i].resno_decoded = 0; /* number of resolution decoded */
|
||||
image->comps[i].factor = 0; /* reducing factor per component */
|
||||
image->comps[i].factor = cp->reduce; /* reducing factor per component */
|
||||
}
|
||||
|
||||
cp->tw = int_ceildiv(image->x1 - cp->tx0, cp->tdx);
|
||||
@@ -658,7 +658,7 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
|
||||
j2k->default_tcp->tccps = (opj_tccp_t *) opj_malloc(sizeof(opj_tccp_t) * image->numcomps);
|
||||
for (i = 0; i < cp->tw * cp->th; i++) {
|
||||
cp->tcps[i].tccps = (opj_tccp_t *) opj_malloc(sizeof(opj_tccp_t) * image->numcomps);
|
||||
}
|
||||
}
|
||||
j2k->tile_data = (unsigned char **) opj_malloc(cp->tw * cp->th * sizeof(unsigned char *));
|
||||
j2k->tile_len = (int *) opj_malloc(cp->tw * cp->th * sizeof(int));
|
||||
j2k->state = J2K_STATE_MH;
|
||||
@@ -1069,7 +1069,6 @@ static void j2k_read_poc(opj_j2k_t *j2k) {
|
||||
|
||||
opj_cp_t *cp = j2k->cp;
|
||||
opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp;
|
||||
opj_tccp_t *tccp = &tcp->tccps[0];
|
||||
opj_cio_t *cio = j2k->cio;
|
||||
|
||||
old_poc = tcp->POC ? tcp->numpocs + 1 : 0;
|
||||
|
||||
@@ -586,7 +586,6 @@ int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlaye
|
||||
unsigned char *c = dest;
|
||||
int e = 0;
|
||||
int compno;
|
||||
int comp_len = 0;
|
||||
opj_pi_iterator_t *pi = NULL;
|
||||
int poc;
|
||||
opj_image_t *image = t2->image;
|
||||
|
||||
@@ -637,10 +637,10 @@ void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) {
|
||||
x1 = j == 0 ? tilec->x1 : int_max(x1, (unsigned int) tilec->x1);
|
||||
y1 = j == 0 ? tilec->y1 : int_max(y1, (unsigned int) tilec->y1);
|
||||
}
|
||||
|
||||
w = x1 - x0;
|
||||
h = y1 - y0;
|
||||
|
||||
|
||||
w = int_ceildivpow2(x1 - x0, image->comps[i].factor);
|
||||
h = int_ceildivpow2(y1 - y0, image->comps[i].factor);
|
||||
|
||||
image->comps[i].data = (int *) opj_malloc(w * h * sizeof(int));
|
||||
image->comps[i].w = w;
|
||||
image->comps[i].h = h;
|
||||
@@ -651,7 +651,6 @@ void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) {
|
||||
|
||||
void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int tileno, opj_codestream_info_t *cstr_info) {
|
||||
int compno, resno, bandno, precno, cblkno;
|
||||
unsigned int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
||||
opj_tcp_t *tcp;
|
||||
opj_tcd_tile_t *tile;
|
||||
|
||||
@@ -1363,6 +1362,11 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
||||
if (tcd->cp->reduce != 0) {
|
||||
tcd->image->comps[compno].resno_decoded =
|
||||
tile->comps[compno].numresolutions - tcd->cp->reduce - 1;
|
||||
if (tcd->image->comps[compno].resno_decoded < 1) {
|
||||
opj_event_msg(tcd->cinfo, EVT_ERROR, "Error decoding tile. The number of resolutions to remove is higher than the number "
|
||||
" of resolutions in the original codestream\nModify the cp_reduce parameter.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (tcd->tcp->tccps[compno].qmfbid == 1) {
|
||||
@@ -1371,9 +1375,6 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
||||
dwt_decode_real(tilec, tilec->numresolutions - 1 - tcd->image->comps[compno].resno_decoded);
|
||||
}
|
||||
|
||||
if (tile->comps[compno].numresolutions > 0) {
|
||||
tcd->image->comps[compno].factor = tile->comps[compno].numresolutions - (tcd->image->comps[compno].resno_decoded + 1);
|
||||
}
|
||||
}
|
||||
dwt_time = opj_clock() - dwt_time;
|
||||
opj_event_msg(tcd->cinfo, EVT_INFO, "- dwt took %f s\n", dwt_time);
|
||||
@@ -1389,6 +1390,7 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
||||
(tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------TILE-------------------*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user