diff --git a/CHANGES b/CHANGES
index 74403216..e7bd2e8c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,7 @@ What's New for OpenJPEG
+ : added
September 19, 2011
++ [mickael] WIP: update t1, t2, tcd to use same strut as in V2
+ [mickael] WIP: begin to test opj_read_tile_header with V2 style
+ [mickael] WIP: create a new framework to output file information
+ [mickael] WIP: remove a piece of code copy by the merge op at the wrong place
diff --git a/libopenjpeg/dwt.c b/libopenjpeg/dwt.c
index 69f385ea..bb40fd02 100644
--- a/libopenjpeg/dwt.c
+++ b/libopenjpeg/dwt.c
@@ -123,6 +123,10 @@ static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int i, DWT1DFN fn);
#endif
static opj_bool dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 i, DWT1DFN fn);
+/**
+Inverse wavelet transform in 2-D.
+*/
+static opj_bool dwt_decode_tile_v2(opj_tcd_tilecomp_v2_t* tilec, OPJ_UINT32 i, DWT1DFN fn);
/*@}*/
@@ -395,6 +399,13 @@ opj_bool dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres) {
return dwt_decode_tile(tilec, numres, &dwt_decode_1);
}
+/* */
+/* Inverse 5-3 wavelet transform in 2-D. */
+/* */
+opj_bool dwt_decode_v2(opj_tcd_tilecomp_v2_t* tilec, OPJ_UINT32 numres) {
+ return dwt_decode_tile_v2(tilec, numres, &dwt_decode_1);
+}
+
/* */
/* Get gain of 5-3 wavelet transform. */
@@ -407,6 +418,17 @@ int dwt_getgain(int orient) {
return 2;
}
+/* */
+/* Get gain of 5-3 wavelet transform. */
+/* */
+OPJ_UINT32 dwt_getgain_v2(OPJ_UINT32 orient) {
+ if (orient == 0)
+ return 0;
+ if (orient == 1 || orient == 2)
+ return 1;
+ return 2;
+}
+
/* */
/* Get norm of 5-3 wavelet. */
/* */
@@ -479,6 +501,14 @@ int dwt_getgain_real(int orient) {
return 0;
}
+/* */
+/* Get gain of 9-7 wavelet transform. */
+/* */
+OPJ_UINT32 dwt_getgain_real_v2(OPJ_UINT32 orient) {
+ (void)orient;
+ return 0;
+}
+
/* */
/* Get norm of 9-7 wavelet. */
/* */
@@ -540,6 +570,22 @@ static OPJ_UINT32 dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT3
return mr ;
}
+/* */
+/* Determine maximum computed resolution level for inverse wavelet transform */
+/* */
+static OPJ_UINT32 dwt_max_resolution_v2(opj_tcd_resolution_v2_t* restrict r, OPJ_UINT32 i) {
+ OPJ_UINT32 mr = 0;
+ OPJ_UINT32 w;
+ while( --i ) {
+ ++r;
+ if( mr < ( w = r->x1 - r->x0 ) )
+ mr = w ;
+ if( mr < ( w = r->y1 - r->y0 ) )
+ mr = w ;
+ }
+ return mr ;
+}
+
#ifdef OPJ_V1
/* */
/* Inverse wavelet transform in 2-D. */
@@ -654,6 +700,66 @@ static opj_bool dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DW
return OPJ_TRUE;
}
+/* */
+/* Inverse wavelet transform in 2-D. */
+/* */
+static opj_bool dwt_decode_tile_v2(opj_tcd_tilecomp_v2_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D) {
+ dwt_t h;
+ dwt_t v;
+
+ opj_tcd_resolution_v2_t* tr = tilec->resolutions;
+
+ OPJ_UINT32 rw = tr->x1 - tr->x0; /* width of the resolution level computed */
+ OPJ_UINT32 rh = tr->y1 - tr->y0; /* height of the resolution level computed */
+
+ OPJ_UINT32 w = tilec->x1 - tilec->x0;
+
+ h.mem = (OPJ_INT32*)
+ opj_aligned_malloc(dwt_max_resolution_v2(tr, numres) * sizeof(OPJ_INT32));
+ if
+ (! h.mem)
+ {
+ return OPJ_FALSE;
+ }
+
+ v.mem = h.mem;
+
+ while( --numres) {
+ OPJ_INT32 * restrict tiledp = tilec->data;
+ OPJ_UINT32 j;
+
+ ++tr;
+ h.sn = rw;
+ v.sn = rh;
+
+ rw = tr->x1 - tr->x0;
+ rh = tr->y1 - tr->y0;
+
+ h.dn = rw - h.sn;
+ h.cas = tr->x0 % 2;
+
+ for(j = 0; j < rh; ++j) {
+ dwt_interleave_h(&h, &tiledp[j*w]);
+ (dwt_1D)(&h);
+ memcpy(&tiledp[j*w], h.mem, rw * sizeof(OPJ_INT32));
+ }
+
+ v.dn = rh - v.sn;
+ v.cas = tr->y0 % 2;
+
+ for(j = 0; j < rw; ++j){
+ OPJ_UINT32 k;
+ dwt_interleave_v(&v, &tiledp[j], w);
+ (dwt_1D)(&v);
+ for(k = 0; k < rh; ++k) {
+ tiledp[k * w + j] = v.mem[k];
+ }
+ }
+ }
+ opj_aligned_free(h.mem);
+ return OPJ_TRUE;
+}
+
static void v4dwt_interleave_h(v4dwt_t* restrict w, float* restrict a, int x, int size){
float* restrict bi = (float*) (w->wavelet + w->cas);
int count = w->sn;
@@ -949,3 +1055,92 @@ opj_bool dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, int numres){
return OPJ_TRUE;
}
+
+/* */
+/* Inverse 9-7 wavelet transform in 2-D. */
+/* */
+opj_bool dwt_decode_real_v2(opj_tcd_tilecomp_v2_t* restrict tilec, OPJ_UINT32 numres){
+ v4dwt_t h;
+ v4dwt_t v;
+
+ opj_tcd_resolution_v2_t* res = tilec->resolutions;
+
+ OPJ_UINT32 rw = res->x1 - res->x0; /* width of the resolution level computed */
+ OPJ_UINT32 rh = res->y1 - res->y0; /* height of the resolution level computed */
+
+ OPJ_UINT32 w = tilec->x1 - tilec->x0;
+
+ h.wavelet = (v4*) opj_aligned_malloc((dwt_max_resolution_v2(res, numres)+5) * sizeof(v4));
+ v.wavelet = h.wavelet;
+
+ while( --numres) {
+ OPJ_FLOAT32 * restrict aj = (OPJ_FLOAT32*) tilec->data;
+ OPJ_UINT32 bufsize = (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0);
+ OPJ_INT32 j;
+
+ h.sn = rw;
+ v.sn = rh;
+
+ ++res;
+
+ rw = res->x1 - res->x0; /* width of the resolution level computed */
+ rh = res->y1 - res->y0; /* height of the resolution level computed */
+
+ h.dn = rw - h.sn;
+ h.cas = res->x0 & 1;
+
+ for(j = rh; j > 0; j -= 4) {
+ v4dwt_interleave_h(&h, aj, w, bufsize);
+ v4dwt_decode(&h);
+
+ if(j >= 4){
+ OPJ_INT32 k = rw;
+
+ while (--k >= 0) {
+ aj[k ] = h.wavelet[k].f[0];
+ aj[k+w ] = h.wavelet[k].f[1];
+ aj[k+w*2] = h.wavelet[k].f[2];
+ aj[k+w*3] = h.wavelet[k].f[3];
+ }
+ }
+ else {
+ OPJ_INT32 k = rw;
+
+ while (--k >= 0) {
+ switch(j) {
+ case 3: aj[k+w*2] = h.wavelet[k].f[2];
+ case 2: aj[k+w ] = h.wavelet[k].f[1];
+ case 1: aj[k ] = h.wavelet[k].f[0];
+ }
+ }
+ }
+
+ aj += w*4;
+ bufsize -= w*4;
+ }
+
+ v.dn = rh - v.sn;
+ v.cas = res->y0 % 2;
+
+ aj = (OPJ_FLOAT32*) tilec->data;
+ for(j = rw; j > 0; j -= 4){
+ v4dwt_interleave_v(&v, aj, w);
+ v4dwt_decode(&v);
+ if(j >= 4){
+ OPJ_UINT32 k;
+ for(k = 0; k < rh; ++k){
+ memcpy(&aj[k*w], &v.wavelet[k], 4 * sizeof(OPJ_FLOAT32));
+ }
+ }else{
+ OPJ_UINT32 k;
+ for(k = 0; k < rh; ++k){
+ memcpy(&aj[k*w], &v.wavelet[k], j * sizeof(OPJ_FLOAT32));
+ }
+ }
+ aj += 4;
+ }
+ }
+
+ opj_aligned_free(h.wavelet);
+ return OPJ_TRUE;
+}
diff --git a/libopenjpeg/dwt.h b/libopenjpeg/dwt.h
index 303fac1c..c2ed90ff 100644
--- a/libopenjpeg/dwt.h
+++ b/libopenjpeg/dwt.h
@@ -64,6 +64,7 @@ void dwt_decode(opj_tcd_tilecomp_t* tilec, int numres);
#endif
opj_bool dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres);
+opj_bool dwt_decode_v2(opj_tcd_tilecomp_v2_t* tilec, OPJ_UINT32 numres);
/**
Get the gain of a subband for the reversible 5-3 DWT.
@@ -71,6 +72,8 @@ Get the gain of a subband for the reversible 5-3 DWT.
@return Returns 0 if orient = 0, returns 1 if orient = 1 or 2, returns 2 otherwise
*/
int dwt_getgain(int orient);
+
+OPJ_UINT32 dwt_getgain_v2(OPJ_UINT32 orient) ;
/**
Get the norm of a wavelet function of a subband at a specified level for the reversible 5-3 DWT.
@param level Level of the wavelet function
@@ -93,12 +96,16 @@ Apply an irreversible inverse DWT transform to a component of an image.
*/
// V1 void dwt_decode_real(opj_tcd_tilecomp_t* tilec, int numres);
opj_bool dwt_decode_real(opj_tcd_tilecomp_t* tilec, int numres);
+
+opj_bool dwt_decode_real_v2(opj_tcd_tilecomp_v2_t* restrict tilec, OPJ_UINT32 numres);
+
/**
Get the gain of a subband for the irreversible 9-7 DWT.
@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)
@return Returns the gain of the 9-7 wavelet transform
*/
int dwt_getgain_real(int orient);
+OPJ_UINT32 dwt_getgain_real_v2(OPJ_UINT32 orient);
/**
Get the norm of a wavelet function of a subband at a specified level for the irreversible 9-7 DWT
@param level Level of the wavelet function
diff --git a/libopenjpeg/j2k.c b/libopenjpeg/j2k.c
index aa58b3b3..e705441d 100644
--- a/libopenjpeg/j2k.c
+++ b/libopenjpeg/j2k.c
@@ -2997,29 +2997,32 @@ static void j2k_read_ppt(opj_j2k_t *j2k) {
* @param p_header_size the size of the data contained in the PPT marker.
* @param p_manager the user event manager.
*/
-opj_bool j2k_read_ppt_v2 (
- opj_j2k_v2_t *p_j2k,
- OPJ_BYTE * p_header_data,
- OPJ_UINT32 p_header_size,
- struct opj_event_mgr * p_manager
- )
+opj_bool j2k_read_ppt_v2 ( opj_j2k_v2_t *p_j2k,
+ OPJ_BYTE * p_header_data,
+ OPJ_UINT32 p_header_size,
+ struct opj_event_mgr * p_manager )
{
-
opj_cp_v2_t *l_cp = 00;
opj_tcp_v2_t *l_tcp = 00;
OPJ_UINT32 l_Z_ppt;
- // preconditions
+ /* preconditions */
assert(p_header_data != 00);
assert(p_j2k != 00);
assert(p_manager != 00);
+ /* We need to have the Z_ppt element at minimum */
if (p_header_size < 1) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading PPT marker\n");
return OPJ_FALSE;
}
l_cp = &(p_j2k->m_cp);
+ if (l_cp->ppm){
+ opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading PPT marker: packet header have been previously found in the main header (PPM marker).\n");
+ return OPJ_FALSE;
+ }
+
l_tcp = &(l_cp->tcps[p_j2k->m_current_tile_number]);
l_tcp->ppt = 1;
@@ -3027,35 +3030,39 @@ opj_bool j2k_read_ppt_v2 (
++p_header_data;
--p_header_size;
- // first PPT marker
+ /* Allocate buffer to read the packet header */
if (l_Z_ppt == 0) {
/* First PPT marker */
- l_tcp->ppt_len = p_header_size;
l_tcp->ppt_data_size = 0;
- l_tcp->ppt_buffer = (OPJ_BYTE *) opj_malloc(l_tcp->ppt_len);
- l_tcp->ppt_data = l_tcp->ppt_buffer;
+ l_tcp->ppt_len = p_header_size;
+ l_tcp->ppt_buffer = (OPJ_BYTE *) opj_calloc(l_tcp->ppt_len, sizeof(OPJ_BYTE) );
if (l_tcp->ppt_buffer == 00) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory reading PPT marker\n");
return OPJ_FALSE;
}
- memset(l_tcp->ppt_buffer,0,l_tcp->ppt_len);
+ l_tcp->ppt_data = l_tcp->ppt_buffer;
+
+ /* memset(l_tcp->ppt_buffer,0,l_tcp->ppt_len); */
}
else {
l_tcp->ppt_len += p_header_size;
- l_tcp->ppt_buffer = (OPJ_BYTE *) opj_realloc(l_tcp->ppt_buffer,l_tcp->ppt_len);
+ l_tcp->ppt_buffer = (OPJ_BYTE *) opj_realloc(l_tcp->ppt_buffer,l_tcp->ppt_len);
if (l_tcp->ppt_buffer == 00) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory reading PPT marker\n");
return OPJ_FALSE;
}
-
l_tcp->ppt_data = l_tcp->ppt_buffer;
+
memset(l_tcp->ppt_buffer+l_tcp->ppt_data_size,0,p_header_size);
}
+
+ /* Read packet header from buffer */
memcpy(l_tcp->ppt_buffer+l_tcp->ppt_data_size,p_header_data,p_header_size);
l_tcp->ppt_data_size += p_header_size;
+
return OPJ_TRUE;
}
@@ -3253,11 +3260,12 @@ opj_bool j2k_read_sot_v2 (
OPJ_UINT32 l_current_part;
OPJ_UINT32 l_tile_x,l_tile_y;
- // preconditions
+ /* preconditions */
assert(p_header_data != 00);
assert(p_j2k != 00);
assert(p_manager != 00);
+ /* Size of this marker is fixed = 12 (we have already read marker and its size)*/
if (p_header_size != 8) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading SOT marker\n");
return OPJ_FALSE;
@@ -3322,7 +3330,6 @@ opj_bool j2k_read_sot_v2 (
"- setting Psot to %d => assuming it is the last tile\n",
totlen);
}
-
};
#endif /* USE_JPWL */
@@ -3337,18 +3344,22 @@ opj_bool j2k_read_sot_v2 (
opj_read_bytes(p_header_data,&l_num_parts ,1); /* TNsot */
++p_header_data;
- if (l_num_parts != 0) {
+ if (l_num_parts != 0) { /* Number of tile-part header is provided by this tile-part header */
l_tcp->m_nb_tile_parts = l_num_parts;
}
+ /* If know the number of tile part header we will check if we didn't read the last*/
if (l_tcp->m_nb_tile_parts) {
if (l_tcp->m_nb_tile_parts == (l_current_part + 1)) {
- p_j2k->m_specific_param.m_decoder.m_can_decode = 1;
+ p_j2k->m_specific_param.m_decoder.m_can_decode = 1; /* Process the last tile-part header*/
}
}
- p_j2k->m_specific_param.m_decoder.m_sot_length = l_tot_len - 12; // SOT_marker_size = 12
- p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPH;// FIXME J2K_DEC_STATE_TPH;
+ /* Keep the size of data to skip after this marker */
+ p_j2k->m_specific_param.m_decoder.m_sot_length = l_tot_len - 12; /* SOT_marker_size = 12 */
+ p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPH;
+
+ /* Check if the current tile is outside the area we want decode (in tile index)*/
p_j2k->m_specific_param.m_decoder.m_skip_data =
(l_tile_x < p_j2k->m_specific_param.m_decoder.m_start_tile_x)
|| (l_tile_x >= p_j2k->m_specific_param.m_decoder.m_end_tile_x)
@@ -3545,7 +3556,9 @@ opj_bool j2k_read_sod_v2 (
}
l_cstr_info = p_j2k->cstr_info;
+
/* Index */
+#ifdef TODO_MSD
if (l_cstr_info) {
OPJ_SIZE_T l_current_pos = opj_stream_tell(p_stream)-1;
l_cstr_info->tile[p_j2k->m_current_tile_number].tp[p_j2k->m_specific_param.m_encoder.m_current_tile_part_number].tp_end_header = l_current_pos;
@@ -3556,6 +3569,7 @@ opj_bool j2k_read_sod_v2 (
l_cstr_info->packno = 0;
}
+#endif
l_current_read_size = opj_stream_read_data( p_stream,
*l_current_data + *l_tile_len,
@@ -3563,10 +3577,10 @@ opj_bool j2k_read_sod_v2 (
p_manager);
if (l_current_read_size != p_j2k->m_specific_param.m_decoder.m_sot_length) {
- p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC; // FIXME J2K_DEC_STATE_NEOC;
+ p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC;
}
else {
- p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT; // FIXME J2K_DEC_STATE_TPHSOT;
+ p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT;
}
*l_tile_len += l_current_read_size;
@@ -5169,10 +5183,10 @@ opj_bool j2k_read_header_procedure( opj_j2k_v2_t *p_j2k,
// Read 2 bytes as the new marker ID
opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_current_marker,2);
- // Try to read until the SOT is detected
+ /* Try to read until the SOT is detected */
while (l_current_marker != J2K_MS_SOT) {
- // Check if the current marker ID is valid
+ /* Check if the current marker ID is valid */
if (l_current_marker < 0xff00) {
opj_event_msg_v2(p_manager, EVT_ERROR, "We expected read a marker ID (0xff--) instead of %.8x\n", l_current_marker);
return OPJ_FALSE;
@@ -5683,7 +5697,7 @@ opj_bool j2k_read_tile_header( opj_j2k_v2_t * p_j2k,
OPJ_UINT32 l_current_marker = J2K_MS_SOT;
OPJ_UINT32 l_marker_size;
const opj_dec_memory_marker_handler_t * l_marker_handler = 00;
- opj_tcp_v2_t * l_tcp = 00;
+ opj_tcp_v2_t * l_tcp = NULL;
OPJ_UINT32 l_nb_tiles;
/* preconditions */
@@ -5691,97 +5705,120 @@ opj_bool j2k_read_tile_header( opj_j2k_v2_t * p_j2k,
assert(p_j2k != 00);
assert(p_manager != 00);
- if (p_j2k->m_specific_param.m_decoder.m_state == 0x0100){// FIXME J2K_DEC_STATE_EOC)
+ /* Reach the End Of Codestream ?*/
+ if (p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_EOC){
l_current_marker = J2K_MS_EOC;
}
- else if (p_j2k->m_specific_param.m_decoder.m_state != J2K_STATE_TPHSOT){ // FIXME J2K_DEC_STATE_TPHSOT)
+ /* We need to encounter a SOT marker (a new tile-part header) */
+ else if (p_j2k->m_specific_param.m_decoder.m_state != J2K_STATE_TPHSOT){
return OPJ_FALSE;
}
+ /* Read into the codestream until reach the EOC or ! can_decode ??? FIXME */
while (! p_j2k->m_specific_param.m_decoder.m_can_decode && l_current_marker != J2K_MS_EOC) {
+
+ /* Try to read until the Start Of Data is detected */
while (l_current_marker != J2K_MS_SOD) {
+ /* Try to read 2 bytes (the marker size) from stream and copy them into the buffer */
if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_decoder.m_header_data,2,p_manager) != 2) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Stream too short\n");
return OPJ_FALSE;
}
+ /* Read 2 bytes from the buffer as the marker size */
opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_marker_size,2);
- if (p_j2k->m_specific_param.m_decoder.m_state & J2K_STATE_TPH){ // FIXME J2K_DEC_STATE_TPH)
+ /* Why this condition? FIXME */
+ if (p_j2k->m_specific_param.m_decoder.m_state & J2K_STATE_TPH){
p_j2k->m_specific_param.m_decoder.m_sot_length -= (l_marker_size + 2);
}
- l_marker_size -= 2;
+ l_marker_size -= 2; /* Subtract the size of the marker ID already read */
+ /* Get the marker handler from the marker ID */
l_marker_handler = j2k_get_marker_handler(l_current_marker);
- /* Check if the marker is known */
+ /* Check if the marker is known and if it is the right place to find it */
if (! (p_j2k->m_specific_param.m_decoder.m_state & l_marker_handler->states) ) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Marker is not compliant with its position\n");
return OPJ_FALSE;
}
+/* FIXME manage case of unknown marker as in the main header ? */
+ /* Check if the marker size is compatible with the header data size */
if (l_marker_size > p_j2k->m_specific_param.m_decoder.m_header_data_size) {
p_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE*)
opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data,l_marker_size);
if (p_j2k->m_specific_param.m_decoder.m_header_data == 00) {
return OPJ_FALSE;
}
-
p_j2k->m_specific_param.m_decoder.m_header_data_size = l_marker_size;
}
+ /* Try to read the rest of the marker segment from stream and copy them into the buffer */
if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_decoder.m_header_data,l_marker_size,p_manager) != l_marker_size) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Stream too short\n");
return OPJ_FALSE;
}
+ /* Read the marker segment with the correct marker handler */
if (! (*(l_marker_handler->handler))(p_j2k,p_j2k->m_specific_param.m_decoder.m_header_data,l_marker_size,p_manager)) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Marker is not compliant with its position\n");
return OPJ_FALSE;
}
if (p_j2k->m_specific_param.m_decoder.m_skip_data) {
+ /* Skip the rest of the tile part header*/
if (opj_stream_skip(p_stream,p_j2k->m_specific_param.m_decoder.m_sot_length,p_manager) != p_j2k->m_specific_param.m_decoder.m_sot_length) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Stream too short\n");
return OPJ_FALSE;
}
- l_current_marker = J2K_MS_SOD;
+ l_current_marker = J2K_MS_SOD; /* Normally we reached a SOD */
}
else {
+ /* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer*/
if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_decoder.m_header_data,2,p_manager) != 2) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Stream too short\n");
return OPJ_FALSE;
}
+ /* Read 2 bytes from the buffer as the new marker ID */
opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_current_marker,2);
}
}
+ /* If we didn't skip data before, we need to read the SOD marker*/
if (! p_j2k->m_specific_param.m_decoder.m_skip_data) {
- if (! j2k_read_sod_v2(p_j2k,p_stream,p_manager)) {
+ /* Try to read the SOD marker and skip data ? FIXME */
+ if (! j2k_read_sod_v2(p_j2k, p_stream, p_manager)) {
return OPJ_FALSE;
}
}
else {
+ /* Indicate we will try to read a new tile-part header*/
p_j2k->m_specific_param.m_decoder.m_skip_data = 0;
p_j2k->m_specific_param.m_decoder.m_can_decode = 0;
- p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT; // FIXME J2K_DEC_STATE_TPHSOT;
+ p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT;
+ /* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer */
if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_decoder.m_header_data,2,p_manager) != 2) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Stream too short\n");
return OPJ_FALSE;
}
+
+ /* Read 2 bytes from buffer as the new marker ID */
opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_current_marker,2);
}
}
+ /* Current marker is the EOC marker ?*/
if (l_current_marker == J2K_MS_EOC) {
- if (p_j2k->m_specific_param.m_decoder.m_state != 0x0100 ){// FIXME J2K_DEC_STATE_EOC)
+ if (p_j2k->m_specific_param.m_decoder.m_state != J2K_STATE_EOC ){
p_j2k->m_current_tile_number = 0;
- p_j2k->m_specific_param.m_decoder.m_state = 0x0100;// FIXME J2K_DEC_STATE_EOC;
+ p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_EOC;
}
}
+ /* FIXME ???*/
if ( ! p_j2k->m_specific_param.m_decoder.m_can_decode) {
l_tcp = p_j2k->m_cp.tcps + p_j2k->m_current_tile_number;
l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw;
@@ -5797,6 +5834,7 @@ opj_bool j2k_read_tile_header( opj_j2k_v2_t * p_j2k,
}
}
+ /*FIXME ???*/
if (! tcd_init_decode_tile(p_j2k->m_tcd, p_j2k->m_current_tile_number)) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Cannot decode tile, memory error\n");
return OPJ_FALSE;
@@ -5919,10 +5957,10 @@ opj_bool j2k_set_decode_area( opj_j2k_v2_t *p_j2k,
/* Check if the positions provided by the user are correct */
/* Left */
- if (p_start_x > l_cp->tw * l_cp->tdx) {
+ if (p_start_x > l_cp->tx0 + l_cp->tw * l_cp->tdx) {
opj_event_msg_v2(p_manager, EVT_ERROR,
- "Left position of the decoded area (ROI_x0=%d) is outside the tile area (nb_tw x XTsiz=%d).\n",
- p_start_x, l_cp->tw * l_cp->tdx);
+ "Left position of the decoded area (ROI_x0=%d) is outside the tile area (XTOsiz + nb_tw x XTsiz=%d).\n",
+ p_start_x, l_cp->tx0 + l_cp->tw * l_cp->tdx);
return OPJ_FALSE;
}
else if (p_start_x < l_cp->tx0){
@@ -5935,10 +5973,10 @@ opj_bool j2k_set_decode_area( opj_j2k_v2_t *p_j2k,
p_j2k->m_specific_param.m_decoder.m_start_tile_x = (p_start_x - l_cp->tx0) / l_cp->tdx;
/* Up */
- if (p_start_y > l_cp->th * l_cp->tdy){
+ if (p_start_y > l_cp->ty0 + l_cp->th * l_cp->tdy){
opj_event_msg_v2(p_manager, EVT_ERROR,
- "Up position of the decoded area (ROI_y0=%d) is outside the tile area (nb_th x YTsiz=%d).\n",
- p_start_y, l_cp->th * l_cp->tdy);
+ "Up position of the decoded area (ROI_y0=%d) is outside the tile area (YTOsiz + nb_th x YTsiz=%d).\n",
+ p_start_y, l_cp->ty0 + l_cp->th * l_cp->tdy);
return OPJ_FALSE;
}
else if (p_start_y < l_cp->ty0){
@@ -5957,10 +5995,10 @@ opj_bool j2k_set_decode_area( opj_j2k_v2_t *p_j2k,
p_end_x, l_cp->tx0);
return OPJ_FALSE;
}
- else if (p_end_x > l_cp->tw * l_cp->tdx) {
+ else if (p_end_x > l_cp->tx0 + l_cp->tw * l_cp->tdx) {
opj_event_msg_v2(p_manager, EVT_WARNING,
- "Right position of the decoded area (ROI_x1=%d) is outside the tile area (nb_tw x XTsiz=%d).\n",
- p_end_x, l_cp->tw * l_cp->tdx);
+ "Right position of the decoded area (ROI_x1=%d) is outside the tile area (XTOsiz + nb_tw x XTsiz=%d).\n",
+ p_end_x, l_cp->tx0 + l_cp->tw * l_cp->tdx);
p_j2k->m_specific_param.m_decoder.m_end_tile_x = l_cp->tw; // FIXME (-1) ???
}
else
@@ -5973,10 +6011,10 @@ opj_bool j2k_set_decode_area( opj_j2k_v2_t *p_j2k,
p_end_x, l_cp->ty0);
return OPJ_FALSE;
}
- if (p_end_y > l_cp->th * l_cp->tdy){
+ if (p_end_y > l_cp->ty0 + l_cp->th * l_cp->tdy){
opj_event_msg_v2(p_manager, EVT_WARNING,
- "Bottom position of the decoded area (ROI_y1=%d) is outside the tile area (nb_th x YTsiz=%d).\n",
- p_end_y, l_cp->th * l_cp->tdy);
+ "Bottom position of the decoded area (ROI_y1=%d) is outside the tile area (YTOsiz + nb_th x YTsiz=%d).\n",
+ p_end_y, l_cp->ty0 + l_cp->th * l_cp->tdy);
p_j2k->m_specific_param.m_decoder.m_start_tile_y = l_cp->th; // FIXME (-1) ???
}
else
diff --git a/libopenjpeg/j2k.h b/libopenjpeg/j2k.h
index e2d8429b..82cceec1 100644
--- a/libopenjpeg/j2k.h
+++ b/libopenjpeg/j2k.h
@@ -117,7 +117,9 @@ typedef enum J2K_STATUS {
J2K_STATE_TPH = 0x0010, /**< the decoding process is in a tile part header */
J2K_STATE_MT = 0x0020, /**< the EOC marker has just been read */
J2K_STATE_NEOC = 0x0040, /**< the decoding process must not expect a EOC marker because the codestream is truncated */
- J2K_STATE_ERR = 0x0080 /**< the decoding process has encountered an error */
+
+ J2K_STATE_EOC = 0x0100, /**< the decoding process has encountered the EOC marker */
+ J2K_STATE_ERR = 0x8000 /**< the decoding process has encountered an error (FIXME warning V1 = 0x0080)*/
} J2K_STATUS;
/* ----------------------------------------------------------------------- */
diff --git a/libopenjpeg/t1.c b/libopenjpeg/t1.c
index a5b102cb..2fb19776 100644
--- a/libopenjpeg/t1.c
+++ b/libopenjpeg/t1.c
@@ -59,6 +59,18 @@ static void t1_enc_sigpass_step(
int *nmsedec,
char type,
int vsc);
+
+/**
+Decode significant pass
+*/
+static void t1_dec_sigpass_step(
+ opj_t1_t *t1,
+ flag_t *flagsp,
+ OPJ_INT32 *datap,
+ OPJ_UINT32 orient,
+ OPJ_INT32 oneplushalf,
+ OPJ_BYTE type,
+ OPJ_UINT32 vsc);
/**
Decode significant pass
*/
@@ -92,6 +104,17 @@ static void t1_enc_sigpass(
int *nmsedec,
char type,
int cblksty);
+
+/**
+Decode significant pass
+*/
+static void t1_dec_sigpass(
+ opj_t1_t *t1,
+ OPJ_INT32 bpno,
+ OPJ_UINT32 orient,
+ OPJ_BYTE type,
+ OPJ_UINT32 cblksty);
+
/**
Decode significant pass
*/
@@ -153,6 +176,28 @@ static void t1_enc_refpass(
int *nmsedec,
char type,
int cblksty);
+
+/**
+Decode refinement pass
+*/
+static void t1_dec_refpass(
+ opj_t1_t *t1,
+ OPJ_INT32 bpno,
+ OPJ_BYTE type,
+ OPJ_UINT32 cblksty);
+
+/**
+Decode refinement pass
+*/
+static void t1_dec_refpass_step(
+ opj_t1_t *t1,
+ flag_t *flagsp,
+ OPJ_INT32 *datap,
+ OPJ_INT32 poshalf,
+ OPJ_INT32 neghalf,
+ OPJ_BYTE type,
+ OPJ_UINT32 vsc);
+
/**
Decode refinement pass
*/
@@ -1653,3 +1698,286 @@ void t1_destroy_v2(opj_t1_t *p_t1)
}
opj_free(p_t1);
}
+
+void t1_decode_cblks_v2(
+ opj_t1_t* t1,
+ opj_tcd_tilecomp_v2_t* tilec,
+ opj_tccp_t* tccp)
+{
+ OPJ_UINT32 resno, bandno, precno, cblkno;
+ OPJ_UINT32 tile_w = tilec->x1 - tilec->x0;
+
+ for (resno = 0; resno < tilec->minimum_num_resolutions; ++resno) {
+ opj_tcd_resolution_v2_t* res = &tilec->resolutions[resno];
+
+ for (bandno = 0; bandno < res->numbands; ++bandno) {
+ opj_tcd_band_v2_t* restrict band = &res->bands[bandno];
+
+ for (precno = 0; precno < res->pw * res->ph; ++precno) {
+ opj_tcd_precinct_v2_t* precinct = &band->precincts[precno];
+
+ for (cblkno = 0; cblkno < precinct->cw * precinct->ch; ++cblkno) {
+ opj_tcd_cblk_dec_v2_t* cblk = &precinct->cblks.dec[cblkno];
+ OPJ_INT32* restrict datap;
+ void* restrict tiledp;
+ OPJ_UINT32 cblk_w, cblk_h;
+ OPJ_INT32 x, y;
+ OPJ_UINT32 i, j;
+
+ t1_decode_cblk_v2(
+ t1,
+ cblk,
+ band->bandno,
+ tccp->roishift,
+ tccp->cblksty);
+
+ x = cblk->x0 - band->x0;
+ y = cblk->y0 - band->y0;
+ if (band->bandno & 1) {
+ opj_tcd_resolution_v2_t* pres = &tilec->resolutions[resno - 1];
+ x += pres->x1 - pres->x0;
+ }
+ if (band->bandno & 2) {
+ opj_tcd_resolution_v2_t* pres = &tilec->resolutions[resno - 1];
+ y += pres->y1 - pres->y0;
+ }
+
+ datap=t1->data;
+ cblk_w = t1->w;
+ cblk_h = t1->h;
+
+ if (tccp->roishift) {
+ OPJ_INT32 thresh = 1 << tccp->roishift;
+ for (j = 0; j < cblk_h; ++j) {
+ for (i = 0; i < cblk_w; ++i) {
+ OPJ_INT32 val = datap[(j * cblk_w) + i];
+ OPJ_INT32 mag = abs(val);
+ if (mag >= thresh) {
+ mag >>= tccp->roishift;
+ datap[(j * cblk_w) + i] = val < 0 ? -mag : mag;
+ }
+ }
+ }
+ }
+
+ tiledp=(void*)&tilec->data[(y * tile_w) + x];
+ if (tccp->qmfbid == 1) {
+ for (j = 0; j < cblk_h; ++j) {
+ for (i = 0; i < cblk_w; ++i) {
+ OPJ_INT32 tmp = datap[(j * cblk_w) + i];
+ ((OPJ_INT32*)tiledp)[(j * tile_w) + i] = tmp / 2;
+ }
+ }
+ } else { /* if (tccp->qmfbid == 0) */
+ for (j = 0; j < cblk_h; ++j) {
+ for (i = 0; i < cblk_w; ++i) {
+ float tmp = datap[(j * cblk_w) + i] * band->stepsize;
+ ((float*)tiledp)[(j * tile_w) + i] = tmp;
+ }
+ }
+ }
+ //opj_free(cblk->segs);
+ //cblk->segs = 00;
+ } /* cblkno */
+ } /* precno */
+ } /* bandno */
+ } /* resno */
+}
+
+
+static void t1_decode_cblk_v2(
+ opj_t1_t *t1,
+ opj_tcd_cblk_dec_v2_t* cblk,
+ OPJ_UINT32 orient,
+ OPJ_UINT32 roishift,
+ OPJ_UINT32 cblksty)
+{
+ opj_raw_t *raw = t1->raw; /* RAW component */
+ opj_mqc_t *mqc = t1->mqc; /* MQC component */
+
+ OPJ_INT32 bpno;
+ OPJ_UINT32 passtype;
+ OPJ_UINT32 segno, passno;
+ OPJ_BYTE type = T1_TYPE_MQ; /* BYPASS mode */
+
+ if(!allocate_buffers(
+ t1,
+ cblk->x1 - cblk->x0,
+ cblk->y1 - cblk->y0))
+ {
+ return;
+ }
+
+ bpno = roishift + cblk->numbps - 1;
+ passtype = 2;
+
+ mqc_resetstates(mqc);
+ mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
+ mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
+ mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
+
+ for (segno = 0; segno < cblk->real_num_segs; ++segno) {
+ opj_tcd_seg_t *seg = &cblk->segs[segno];
+
+ /* BYPASS mode */
+ type = ((bpno <= ((OPJ_INT32) (cblk->numbps) - 1) - 4) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
+ /* FIXME: slviewer gets here with a null pointer. Why? Partially downloaded and/or corrupt textures? */
+ if(seg->data == 00){
+ continue;
+ }
+ if (type == T1_TYPE_RAW) {
+ raw_init_dec(raw, (*seg->data) + seg->dataindex, seg->len);
+ } else {
+ mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len);
+ }
+
+ for (passno = 0; passno < seg->real_num_passes; ++passno) {
+ switch (passtype) {
+ case 0:
+ t1_dec_sigpass(t1, bpno+1, orient, type, cblksty);
+ break;
+ case 1:
+ t1_dec_refpass(t1, bpno+1, type, cblksty);
+ break;
+ case 2:
+ t1_dec_clnpass(t1, bpno+1, orient, cblksty);
+ break;
+ }
+
+ if ((cblksty & J2K_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) {
+ mqc_resetstates(mqc);
+ mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
+ mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
+ mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
+ }
+ if (++passtype == 3) {
+ passtype = 0;
+ bpno--;
+ }
+ }
+ }
+}
+
+static void t1_dec_refpass(
+ opj_t1_t *t1,
+ OPJ_INT32 bpno,
+ OPJ_BYTE type,
+ OPJ_UINT32 cblksty)
+{
+ OPJ_UINT32 i, j, k;
+ OPJ_INT32 one, poshalf, neghalf;
+ OPJ_UINT32 vsc;
+ one = 1 << bpno;
+ poshalf = one >> 1;
+ neghalf = bpno > 0 ? -poshalf : -1;
+ for (k = 0; k < t1->h; k += 4) {
+ for (i = 0; i < t1->w; ++i) {
+ for (j = k; j < k + 4 && j < t1->h; ++j) {
+ vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0;
+ t1_dec_refpass_step(
+ t1,
+ &t1->flags[((j+1) * t1->flags_stride) + i + 1],
+ &t1->data[(j * t1->w) + i],
+ poshalf,
+ neghalf,
+ type,
+ vsc);
+ }
+ }
+ }
+} /* VSC and BYPASS by Antonin */
+
+
+static void t1_dec_refpass_step(
+ opj_t1_t *t1,
+ flag_t *flagsp,
+ OPJ_INT32 *datap,
+ OPJ_INT32 poshalf,
+ OPJ_INT32 neghalf,
+ OPJ_BYTE type,
+ OPJ_UINT32 vsc)
+{
+ OPJ_INT32 t;
+ OPJ_UINT32 v,flag;
+
+ opj_mqc_t *mqc = t1->mqc; /* MQC component */
+ opj_raw_t *raw = t1->raw; /* RAW component */
+
+ flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
+ if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) {
+ mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */
+ if (type == T1_TYPE_RAW) {
+ v = raw_decode(raw);
+ } else {
+ v = mqc_decode(mqc);
+ }
+ t = v ? poshalf : neghalf;
+ *datap += *datap < 0 ? -t : t;
+ *flagsp |= T1_REFINE;
+ }
+} /* VSC and BYPASS by Antonin */
+
+static void t1_dec_sigpass(
+ opj_t1_t *t1,
+ OPJ_INT32 bpno,
+ OPJ_UINT32 orient,
+ OPJ_BYTE type,
+ OPJ_UINT32 cblksty)
+{
+ OPJ_UINT32 i, j, k, vsc;
+ OPJ_INT32 one, half, oneplushalf;
+ one = 1 << bpno;
+ half = one >> 1;
+ oneplushalf = one | half;
+ for (k = 0; k < t1->h; k += 4) {
+ for (i = 0; i < t1->w; ++i) {
+ for (j = k; j < k + 4 && j < t1->h; ++j) {
+ vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0;
+ t1_dec_sigpass_step(
+ t1,
+ &t1->flags[((j+1) * t1->flags_stride) + i + 1],
+ &t1->data[(j * t1->w) + i],
+ orient,
+ oneplushalf,
+ type,
+ vsc);
+ }
+ }
+ }
+} /* VSC and BYPASS by Antonin */
+
+static void t1_dec_sigpass_step(
+ opj_t1_t *t1,
+ flag_t *flagsp,
+ OPJ_INT32 *datap,
+ OPJ_UINT32 orient,
+ OPJ_INT32 oneplushalf,
+ OPJ_BYTE type,
+ OPJ_UINT32 vsc)
+{
+ OPJ_UINT32 v, flag;
+
+ opj_raw_t *raw = t1->raw; /* RAW component */
+ opj_mqc_t *mqc = t1->mqc; /* MQC component */
+
+ flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
+ if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
+ if (type == T1_TYPE_RAW) {
+ if (raw_decode(raw)) {
+ v = raw_decode(raw); /* ESSAI */
+ *datap = v ? -oneplushalf : oneplushalf;
+ t1_updateflags(flagsp, v, t1->flags_stride);
+ }
+ } else {
+ mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient));
+ if (mqc_decode(mqc)) {
+ mqc_setcurctx(mqc, t1_getctxno_sc(flag));
+ v = mqc_decode(mqc) ^ t1_getspb(flag);
+ *datap = v ? -oneplushalf : oneplushalf;
+ t1_updateflags(flagsp, v, t1->flags_stride);
+ }
+ }
+ *flagsp |= T1_VISIT;
+ }
+} /* VSC and BYPASS by Antonin */
+
diff --git a/libopenjpeg/t1.h b/libopenjpeg/t1.h
index bcc6e514..c38bfb82 100644
--- a/libopenjpeg/t1.h
+++ b/libopenjpeg/t1.h
@@ -141,6 +141,25 @@ Decode the code-blocks of a tile
void t1_decode_cblks(opj_t1_t* t1, opj_tcd_tilecomp_t* tilec, opj_tccp_t* tccp);
+void t1_decode_cblks_v2(
+ opj_t1_t* t1,
+ opj_tcd_tilecomp_v2_t* tilec,
+ opj_tccp_t* tccp);
+
+/**
+Decode 1 code-block
+@param t1 T1 handle
+@param cblk Code-block coding parameters
+@param orient
+@param roishift Region of interest shifting value
+@param cblksty Code-block style
+*/
+static void t1_decode_cblk_v2(
+ opj_t1_t *t1,
+ opj_tcd_cblk_dec_v2_t* cblk,
+ OPJ_UINT32 orient,
+ OPJ_UINT32 roishift,
+ OPJ_UINT32 cblksty);
/**
* Creates a new Tier 1 handle
diff --git a/libopenjpeg/t2.c b/libopenjpeg/t2.c
index e9f08abb..017203d6 100644
--- a/libopenjpeg/t2.c
+++ b/libopenjpeg/t2.c
@@ -92,7 +92,7 @@ Decode a packet of a tile from a source buffer
*/
static opj_bool t2_decode_packet_v2(
opj_t2_v2_t* p_t2,
- opj_tcd_tile_t *p_tile,
+ opj_tcd_tile_v2_t *p_tile,
opj_tcp_v2_t *p_tcp,
opj_pi_iterator_t *p_pi,
OPJ_BYTE *p_src,
@@ -102,7 +102,7 @@ static opj_bool t2_decode_packet_v2(
static opj_bool t2_skip_packet(
opj_t2_v2_t* p_t2,
- opj_tcd_tile_t *p_tile,
+ opj_tcd_tile_v2_t *p_tile,
opj_tcp_v2_t *p_tcp,
opj_pi_iterator_t *p_pi,
OPJ_BYTE *p_src,
@@ -112,7 +112,7 @@ static opj_bool t2_skip_packet(
static opj_bool t2_read_packet_header(
opj_t2_v2_t* p_t2,
- opj_tcd_tile_t *p_tile,
+ opj_tcd_tile_v2_t *p_tile,
opj_tcp_v2_t *p_tcp,
opj_pi_iterator_t *p_pi,
opj_bool * p_is_data_present,
@@ -123,7 +123,7 @@ static opj_bool t2_read_packet_header(
static opj_bool t2_read_packet_data(
opj_t2_v2_t* p_t2,
- opj_tcd_tile_t *p_tile,
+ opj_tcd_tile_v2_t *p_tile,
opj_pi_iterator_t *p_pi,
OPJ_BYTE *p_src_data,
OPJ_UINT32 * p_data_read,
@@ -132,7 +132,7 @@ static opj_bool t2_read_packet_data(
static opj_bool t2_skip_packet_data(
opj_t2_v2_t* p_t2,
- opj_tcd_tile_t *p_tile,
+ opj_tcd_tile_v2_t *p_tile,
opj_pi_iterator_t *p_pi,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
@@ -143,7 +143,10 @@ static opj_bool t2_skip_packet_data(
@param cblksty
@param first
*/
-static opj_bool t2_init_seg_v2(opj_tcd_cblk_dec_t* cblk, OPJ_UINT32 index, OPJ_UINT32 cblksty, OPJ_UINT32 first);
+static opj_bool t2_init_seg_v2( opj_tcd_cblk_dec_v2_t* cblk,
+ OPJ_UINT32 index,
+ OPJ_UINT32 cblksty,
+ OPJ_UINT32 first);
/*@}*/
@@ -837,7 +840,7 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj
opj_bool t2_decode_packets_v2(
opj_t2_v2_t *p_t2,
OPJ_UINT32 p_tile_no,
- struct opj_tcd_tile *p_tile,
+ struct opj_tcd_tile_v2 *p_tile,
OPJ_BYTE *p_src,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_len,
@@ -986,7 +989,7 @@ void t2_destroy_v2(opj_t2_v2_t *t2) {
static opj_bool t2_decode_packet_v2(
opj_t2_v2_t* p_t2,
- opj_tcd_tile_t *p_tile,
+ opj_tcd_tile_v2_t *p_tile,
opj_tcp_v2_t *p_tcp,
opj_pi_iterator_t *p_pi,
OPJ_BYTE *p_src,
@@ -1026,7 +1029,7 @@ static opj_bool t2_decode_packet_v2(
static opj_bool t2_skip_packet(
opj_t2_v2_t* p_t2,
- opj_tcd_tile_t *p_tile,
+ opj_tcd_tile_v2_t *p_tile,
opj_tcp_v2_t *p_tcp,
opj_pi_iterator_t *p_pi,
OPJ_BYTE *p_src,
@@ -1040,27 +1043,26 @@ static opj_bool t2_skip_packet(
*p_data_read = 0;
- if
- (! t2_read_packet_header(p_t2,p_tile,p_tcp,p_pi,&l_read_data,p_src,&l_nb_bytes_read,p_max_length,p_pack_info))
- {
+ if (! t2_read_packet_header(p_t2,p_tile,p_tcp,p_pi,&l_read_data,p_src,&l_nb_bytes_read,p_max_length,p_pack_info)) {
return OPJ_FALSE;
}
+
p_src += l_nb_bytes_read;
l_nb_total_bytes_read += l_nb_bytes_read;
p_max_length -= l_nb_bytes_read;
+
/* we should read data for the packet */
- if
- (l_read_data)
- {
+ if (l_read_data) {
l_nb_bytes_read = 0;
- if
- (! t2_skip_packet_data(p_t2,p_tile,p_pi,&l_nb_bytes_read,p_max_length,p_pack_info))
- {
+
+ if (! t2_skip_packet_data(p_t2,p_tile,p_pi,&l_nb_bytes_read,p_max_length,p_pack_info)) {
return OPJ_FALSE;
}
+
l_nb_total_bytes_read += l_nb_bytes_read;
}
*p_data_read = l_nb_total_bytes_read;
+
return OPJ_TRUE;
}
@@ -1068,7 +1070,7 @@ static opj_bool t2_skip_packet(
static opj_bool t2_read_packet_header(
opj_t2_v2_t* p_t2,
- opj_tcd_tile_t *p_tile,
+ opj_tcd_tile_v2_t *p_tile,
opj_tcp_v2_t *p_tcp,
opj_pi_iterator_t *p_pi,
opj_bool * p_is_data_present,
@@ -1086,40 +1088,35 @@ static opj_bool t2_read_packet_header(
OPJ_BYTE *l_current_data = p_src_data;
opj_cp_v2_t *l_cp = p_t2->cp;
opj_bio_t *l_bio = 00; /* BIO component */
- opj_tcd_band_t *l_band = 00;
- opj_tcd_cblk_dec_t* l_cblk = 00;
- opj_tcd_resolution_t* l_res = &p_tile->comps[p_pi->compno].resolutions[p_pi->resno];
+ opj_tcd_band_v2_t *l_band = 00;
+ opj_tcd_cblk_dec_v2_t* l_cblk = 00;
+ opj_tcd_resolution_v2_t* l_res = &p_tile->comps[p_pi->compno].resolutions[p_pi->resno];
OPJ_BYTE *l_header_data = 00;
OPJ_BYTE **l_header_data_start = 00;
OPJ_UINT32 l_present;
- if
- (p_pi->layno == 0)
- {
+ if (p_pi->layno == 0) {
l_band = l_res->bands;
- /* reset tagtrees */
- for
- (bandno = 0; bandno < l_res->numbands; ++bandno)
- {
- opj_tcd_precinct_t *l_prc = &l_band->precincts[p_pi->precno];
- if (
- ! ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0)))
- {
+ /* reset tagtrees */
+ for (bandno = 0; bandno < l_res->numbands; ++bandno) {
+ opj_tcd_precinct_v2_t *l_prc = &l_band->precincts[p_pi->precno];
+
+ if ( ! ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0)) ) {
tgt_reset(l_prc->incltree);
tgt_reset(l_prc->imsbtree);
l_cblk = l_prc->cblks.dec;
+
l_nb_code_blocks = l_prc->cw * l_prc->ch;
- for
- (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno)
- {
+ for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) {
l_cblk->numsegs = 0;
l_cblk->real_num_segs = 0;
++l_cblk;
}
}
+
++l_band;
}
}
@@ -1144,42 +1141,36 @@ static opj_bool t2_read_packet_header(
*/
l_bio = bio_create();
- if
- (! l_bio)
- {
+ if (! l_bio) {
return OPJ_FALSE;
}
- if
- (l_cp->ppm == 1)
- { /* PPM */
+ if (l_cp->ppm == 1) { /* PPM */
l_header_data_start = &l_cp->ppm_data;
l_header_data = *l_header_data_start;
l_modified_length_ptr = &(l_cp->ppm_len);
}
- else if
- (p_tcp->ppt == 1)
- { /* PPT */
+ else if (p_tcp->ppt == 1) { /* PPT */
l_header_data_start = &(p_tcp->ppt_data);
l_header_data = *l_header_data_start;
l_modified_length_ptr = &(p_tcp->ppt_len);
}
- else
- { /* Normal Case */
+ else { /* Normal Case */
l_header_data_start = &(l_current_data);
l_header_data = *l_header_data_start;
l_remaining_length = p_src_data+p_max_length-l_header_data;
l_modified_length_ptr = &(l_remaining_length);
}
+
bio_init_dec(l_bio, l_header_data,*l_modified_length_ptr);
+
l_present = bio_read(l_bio, 1);
- if
- (!l_present)
- {
+ if (!l_present) {
bio_inalign(l_bio);
l_header_data += bio_numbytes(l_bio);
bio_destroy(l_bio);
+
/* EPH markers */
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
@@ -1188,100 +1179,86 @@ static opj_bool t2_read_packet_header(
l_header_data += 2;
}
}
+
l_header_length = (l_header_data - *l_header_data_start);
*l_modified_length_ptr -= l_header_length;
*l_header_data_start += l_header_length;
+
/* << INDEX */
// End of packet header position. Currently only represents the distance to start of packet
// Will be updated later by incrementing with packet start value
- if
- (p_pack_info)
- {
+ if (p_pack_info) {
p_pack_info->end_ph_pos = (OPJ_INT32)(l_current_data - p_src_data);
}
/* INDEX >> */
+
* p_is_data_present = OPJ_FALSE;
*p_data_read = l_current_data - p_src_data;
return OPJ_TRUE;
}
l_band = l_res->bands;
- for
- (bandno = 0; bandno < l_res->numbands; ++bandno)
- {
- opj_tcd_precinct_t *l_prc = &(l_band->precincts[p_pi->precno]);
+ for (bandno = 0; bandno < l_res->numbands; ++bandno) {
+ opj_tcd_precinct_v2_t *l_prc = &(l_band->precincts[p_pi->precno]);
- if ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0))
- {
+ if ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0)) {
++l_band;
continue;
}
+
l_nb_code_blocks = l_prc->cw * l_prc->ch;
l_cblk = l_prc->cblks.dec;
- for
- (cblkno = 0; cblkno < l_nb_code_blocks; cblkno++)
- {
+ for (cblkno = 0; cblkno < l_nb_code_blocks; cblkno++) {
OPJ_UINT32 l_included,l_increment, l_segno;
OPJ_INT32 n;
+
/* if cblk not yet included before --> inclusion tagtree */
- if
- (!l_cblk->numsegs)
- {
+ if (!l_cblk->numsegs) {
l_included = tgt_decode(l_bio, l_prc->incltree, cblkno, p_pi->layno + 1);
/* else one bit */
}
- else
- {
+ else {
l_included = bio_read(l_bio, 1);
}
+
/* if cblk not included */
- if
- (!l_included)
- {
+ if (!l_included) {
l_cblk->numnewpasses = 0;
++l_cblk;
continue;
}
+
/* if cblk not yet included --> zero-bitplane tagtree */
- if
- (!l_cblk->numsegs)
- {
+ if (!l_cblk->numsegs) {
OPJ_UINT32 i = 0;
- while
- (!tgt_decode(l_bio, l_prc->imsbtree, cblkno, i))
- {
+
+ while (!tgt_decode(l_bio, l_prc->imsbtree, cblkno, i)) {
++i;
}
+
l_cblk->numbps = l_band->numbps + 1 - i;
l_cblk->numlenbits = 3;
}
+
/* number of coding passes */
l_cblk->numnewpasses = t2_getnumpasses(l_bio);
l_increment = t2_getcommacode(l_bio);
+
/* length indicator increment */
l_cblk->numlenbits += l_increment;
l_segno = 0;
- if
- (!l_cblk->numsegs)
- {
- if
- (! t2_init_seg_v2(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 1))
- {
+
+ if (!l_cblk->numsegs) {
+ if (! t2_init_seg_v2(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 1)) {
bio_destroy(l_bio);
return OPJ_FALSE;
}
-
}
- else
- {
+ else {
l_segno = l_cblk->numsegs - 1;
- if
- (l_cblk->segs[l_segno].numpasses == l_cblk->segs[l_segno].maxpasses)
- {
+ if (l_cblk->segs[l_segno].numpasses == l_cblk->segs[l_segno].maxpasses) {
++l_segno;
- if
- (! t2_init_seg_v2(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0))
- {
+ if (! t2_init_seg_v2(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0)) {
bio_destroy(l_bio);
return OPJ_FALSE;
}
@@ -1292,28 +1269,25 @@ static opj_bool t2_read_packet_header(
do {
l_cblk->segs[l_segno].numnewpasses = int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n);
l_cblk->segs[l_segno].newlen = bio_read(l_bio, l_cblk->numlenbits + uint_floorlog2(l_cblk->segs[l_segno].numnewpasses));
+
n -= l_cblk->segs[l_segno].numnewpasses;
- if
- (n > 0)
- {
+ if (n > 0) {
++l_segno;
- if
- (! t2_init_seg_v2(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0))
- {
+
+ if (! t2_init_seg_v2(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0)) {
bio_destroy(l_bio);
return OPJ_FALSE;
}
}
- }
- while (n > 0);
+ } while (n > 0);
+
++l_cblk;
}
+
++l_band;
}
- if
- (bio_inalign(l_bio))
- {
+ if (bio_inalign(l_bio)) {
bio_destroy(l_bio);
return OPJ_FALSE;
}
@@ -1330,27 +1304,27 @@ static opj_bool t2_read_packet_header(
}
}
-
l_header_length = (l_header_data - *l_header_data_start);
*l_modified_length_ptr -= l_header_length;
*l_header_data_start += l_header_length;
+
/* << INDEX */
// End of packet header position. Currently only represents the distance to start of packet
// Will be updated later by incrementing with packet start value
- if
- (p_pack_info)
- {
+ if (p_pack_info) {
p_pack_info->end_ph_pos = (OPJ_INT32)(l_current_data - p_src_data);
}
/* INDEX >> */
- * p_is_data_present = OPJ_TRUE;
+
+ *p_is_data_present = OPJ_TRUE;
*p_data_read = l_current_data - p_src_data;
+
return OPJ_TRUE;
}
static opj_bool t2_read_packet_data(
opj_t2_v2_t* p_t2,
- opj_tcd_tile_t *p_tile,
+ opj_tcd_tile_v2_t *p_tile,
opj_pi_iterator_t *p_pi,
OPJ_BYTE *p_src_data,
OPJ_UINT32 * p_data_read,
@@ -1360,58 +1334,47 @@ static opj_bool t2_read_packet_data(
OPJ_UINT32 bandno, cblkno;
OPJ_UINT32 l_nb_code_blocks;
OPJ_BYTE *l_current_data = p_src_data;
- opj_tcd_band_t *l_band = 00;
- opj_tcd_cblk_dec_t* l_cblk = 00;
- opj_tcd_resolution_t* l_res = &p_tile->comps[p_pi->compno].resolutions[p_pi->resno];
+ opj_tcd_band_v2_t *l_band = 00;
+ opj_tcd_cblk_dec_v2_t* l_cblk = 00;
+ opj_tcd_resolution_v2_t* l_res = &p_tile->comps[p_pi->compno].resolutions[p_pi->resno];
l_band = l_res->bands;
- for
- (bandno = 0; bandno < l_res->numbands; ++bandno)
- {
- opj_tcd_precinct_t *l_prc = &l_band->precincts[p_pi->precno];
+ for (bandno = 0; bandno < l_res->numbands; ++bandno) {
+ opj_tcd_precinct_v2_t *l_prc = &l_band->precincts[p_pi->precno];
- if
- ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0))
- {
+ if ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0)) {
++l_band;
continue;
}
+
l_nb_code_blocks = l_prc->cw * l_prc->ch;
l_cblk = l_prc->cblks.dec;
- for
- (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno)
- {
+
+ for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) {
opj_tcd_seg_t *l_seg = 00;
- if
- (!l_cblk->numnewpasses)
- {
+
+ if (!l_cblk->numnewpasses) {
/* nothing to do */
++l_cblk;
continue;
}
- if
- (!l_cblk->numsegs)
- {
+
+ if (!l_cblk->numsegs) {
l_seg = l_cblk->segs;
++l_cblk->numsegs;
l_cblk->len = 0;
}
- else
- {
+ else {
l_seg = &l_cblk->segs[l_cblk->numsegs - 1];
- if
- (l_seg->numpasses == l_seg->maxpasses)
- {
+
+ if (l_seg->numpasses == l_seg->maxpasses) {
++l_seg;
++l_cblk->numsegs;
}
}
- do
- {
- if
- (l_current_data + l_seg->newlen > p_src_data + p_max_length)
- {
+ do {
+ if (l_current_data + l_seg->newlen > p_src_data + p_max_length) {
return OPJ_FALSE;
}
@@ -1436,12 +1399,12 @@ static opj_bool t2_read_packet_data(
#endif /* USE_JPWL */
memcpy(l_cblk->data + l_cblk->len, l_current_data, l_seg->newlen);
- if
- (l_seg->numpasses == 0)
- {
+
+ if (l_seg->numpasses == 0) {
l_seg->data = &l_cblk->data;
l_seg->dataindex = l_cblk->len;
}
+
l_current_data += l_seg->newlen;
l_seg->numpasses += l_seg->numnewpasses;
l_cblk->numnewpasses -= l_seg->numnewpasses;
@@ -1449,26 +1412,28 @@ static opj_bool t2_read_packet_data(
l_seg->real_num_passes = l_seg->numpasses;
l_cblk->len += l_seg->newlen;
l_seg->len += l_seg->newlen;
- if
- (l_cblk->numnewpasses > 0)
- {
+
+ if (l_cblk->numnewpasses > 0) {
++l_seg;
++l_cblk->numsegs;
}
- }
- while (l_cblk->numnewpasses > 0);
+ } while (l_cblk->numnewpasses > 0);
+
l_cblk->real_num_segs = l_cblk->numsegs;
++l_cblk;
}
+
++l_band;
}
+
*(p_data_read) = l_current_data - p_src_data;
+
return OPJ_TRUE;
}
static opj_bool t2_skip_packet_data(
opj_t2_v2_t* p_t2,
- opj_tcd_tile_t *p_tile,
+ opj_tcd_tile_v2_t *p_tile,
opj_pi_iterator_t *p_pi,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
@@ -1476,60 +1441,49 @@ static opj_bool t2_skip_packet_data(
{
OPJ_UINT32 bandno, cblkno;
OPJ_UINT32 l_nb_code_blocks;
- opj_tcd_band_t *l_band = 00;
- opj_tcd_cblk_dec_t* l_cblk = 00;
-
- opj_tcd_resolution_t* l_res = &p_tile->comps[p_pi->compno].resolutions[p_pi->resno];
+ opj_tcd_band_v2_t *l_band = 00;
+ opj_tcd_cblk_dec_v2_t* l_cblk = 00;
+ opj_tcd_resolution_v2_t* l_res = &p_tile->comps[p_pi->compno].resolutions[p_pi->resno];
*p_data_read = 0;
l_band = l_res->bands;
- for
- (bandno = 0; bandno < l_res->numbands; ++bandno)
- {
- opj_tcd_precinct_t *l_prc = &l_band->precincts[p_pi->precno];
- if
- ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0))
- {
+ for (bandno = 0; bandno < l_res->numbands; ++bandno) {
+ opj_tcd_precinct_v2_t *l_prc = &l_band->precincts[p_pi->precno];
+
+ if ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0)) {
++l_band;
continue;
}
+
l_nb_code_blocks = l_prc->cw * l_prc->ch;
l_cblk = l_prc->cblks.dec;
- for
- (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno)
- {
+
+ for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) {
opj_tcd_seg_t *l_seg = 00;
- if
- (!l_cblk->numnewpasses)
- {
+
+ if (!l_cblk->numnewpasses) {
/* nothing to do */
++l_cblk;
continue;
}
- if
- (!l_cblk->numsegs)
- {
+
+ if (!l_cblk->numsegs) {
l_seg = l_cblk->segs;
++l_cblk->numsegs;
l_cblk->len = 0;
}
- else
- {
+ else {
l_seg = &l_cblk->segs[l_cblk->numsegs - 1];
- if
- (l_seg->numpasses == l_seg->maxpasses)
- {
+
+ if (l_seg->numpasses == l_seg->maxpasses) {
++l_seg;
++l_cblk->numsegs;
}
}
- do
- {
- if
- (* p_data_read + l_seg->newlen > p_max_length)
- {
+ do {
+ if (* p_data_read + l_seg->newlen > p_max_length) {
return OPJ_FALSE;
}
@@ -1553,40 +1507,40 @@ static opj_bool t2_skip_packet_data(
#endif /* USE_JPWL */
*(p_data_read) += l_seg->newlen;
+
l_seg->numpasses += l_seg->numnewpasses;
l_cblk->numnewpasses -= l_seg->numnewpasses;
- if
- (l_cblk->numnewpasses > 0)
+ if (l_cblk->numnewpasses > 0)
{
++l_seg;
++l_cblk->numsegs;
}
- }
- while (l_cblk->numnewpasses > 0);
+ } while (l_cblk->numnewpasses > 0);
+
++l_cblk;
}
+
++l_band;
}
+
return OPJ_TRUE;
}
-static opj_bool t2_init_seg_v2(opj_tcd_cblk_dec_t* cblk, OPJ_UINT32 index, OPJ_UINT32 cblksty, OPJ_UINT32 first)
+static opj_bool t2_init_seg_v2(opj_tcd_cblk_dec_v2_t* cblk, OPJ_UINT32 index, OPJ_UINT32 cblksty, OPJ_UINT32 first)
{
opj_tcd_seg_t* seg = 00;
OPJ_UINT32 l_nb_segs = index + 1;
- if
- (l_nb_segs > cblk->m_current_max_segs)
- {
+ if (l_nb_segs > cblk->m_current_max_segs) {
cblk->m_current_max_segs += J2K_DEFAULT_NB_SEGS;
- cblk->segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, cblk->m_current_max_segs * sizeof(opj_tcd_seg_t));
- if
- (! cblk->segs)
- {
+
+ cblk->segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, cblk->m_current_max_segs * sizeof(opj_tcd_seg_t));
+ if(! cblk->segs) {
return OPJ_FALSE;
}
}
+
seg = &cblk->segs[index];
memset(seg,0,sizeof(opj_tcd_seg_t));
@@ -1602,5 +1556,6 @@ static opj_bool t2_init_seg_v2(opj_tcd_cblk_dec_t* cblk, OPJ_UINT32 index, OPJ_U
} else {
seg->maxpasses = 109;
}
+
return OPJ_TRUE;
}
diff --git a/libopenjpeg/t2.h b/libopenjpeg/t2.h
index 55cac98f..0f6f65bb 100644
--- a/libopenjpeg/t2.h
+++ b/libopenjpeg/t2.h
@@ -106,7 +106,7 @@ Decode the packets of a tile from a source buffer
*/
opj_bool t2_decode_packets_v2( opj_t2_v2_t *t2,
OPJ_UINT32 tileno,
- struct opj_tcd_tile *tile,
+ struct opj_tcd_tile_v2 *tile,
OPJ_BYTE *src, OPJ_UINT32 * p_data_read,
OPJ_UINT32 len,
struct opj_codestream_info_v2 *cstr_info);
diff --git a/libopenjpeg/tcd.c b/libopenjpeg/tcd.c
index 9d8dc782..dd82eb02 100644
--- a/libopenjpeg/tcd.c
+++ b/libopenjpeg/tcd.c
@@ -93,7 +93,7 @@ void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) {
/**
* Allocates memory for a decoding code block.
*/
-static opj_bool tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_block);
+static opj_bool tcd_code_block_dec_allocate (opj_tcd_cblk_dec_v2_t * p_code_block);
/**
Free the memory allocated for encoding
@@ -126,7 +126,7 @@ opj_bool tcd_dc_level_shift_decode (
opj_tcd_v2_t *p_tcd
);
-void tcd_code_block_dec_deallocate (opj_tcd_precinct_t * p_precinct);
+void tcd_code_block_dec_deallocate (opj_tcd_precinct_v2_t * p_precinct);
/* ----------------------------------------------------------------------- */
/**
@@ -155,21 +155,20 @@ opj_tcd_v2_t* tcd_create_v2(opj_bool p_is_decoder)
/* create the tcd structure */
l_tcd = (opj_tcd_v2_t*) opj_malloc(sizeof(opj_tcd_v2_t));
- if
- (!l_tcd)
- {
+ if (!l_tcd) {
return 00;
}
memset(l_tcd,0,sizeof(opj_tcd_v2_t));
+
l_tcd->m_is_decoder = p_is_decoder ? 1 : 0;
- l_tcd->tcd_image = (opj_tcd_image_t*)opj_malloc(sizeof(opj_tcd_image_t));
- if
- (!l_tcd->tcd_image)
- {
+
+ l_tcd->tcd_image = (opj_tcd_image_v2_t*)opj_malloc(sizeof(opj_tcd_image_v2_t));
+ if (!l_tcd->tcd_image) {
opj_free(l_tcd);
return 00;
}
memset(l_tcd->tcd_image,0,sizeof(opj_tcd_image_t));
+
return l_tcd;
}
@@ -1591,15 +1590,15 @@ opj_bool tcd_init_v2( opj_tcd_v2_t *p_tcd,
p_tcd->image_header = p_image_header;
p_tcd->cp = p_cp;
- p_tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_malloc(sizeof(opj_tcd_tile_t));
+ p_tcd->tcd_image->tiles = (opj_tcd_tile_v2_t *) opj_malloc(sizeof(opj_tcd_tile_v2_t));
if (! p_tcd->tcd_image->tiles) {
return OPJ_FALSE;
}
- memset(p_tcd->tcd_image->tiles,0, sizeof(opj_tcd_tile_t));
+ memset(p_tcd->tcd_image->tiles,0, sizeof(opj_tcd_tile_v2_t));
- l_tile_comp_size = p_image_header->numcomps * sizeof(opj_tcd_tilecomp_t);
- p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_t *) opj_malloc(l_tile_comp_size);
+ l_tile_comp_size = p_image_header->numcomps * sizeof(opj_tcd_tilecomp_v2_t);
+ p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_v2_t *) opj_malloc(l_tile_comp_size);
if (! p_tcd->tcd_image->tiles->comps ) {
return OPJ_FALSE;
}
@@ -1615,13 +1614,10 @@ opj_bool tcd_init_v2( opj_tcd_v2_t *p_tcd,
Destroy a previously created TCD handle
*/
void tcd_destroy_v2(opj_tcd_v2_t *tcd) {
- if
- (tcd)
- {
+ if (tcd) {
tcd_free_tile(tcd);
- if
- (tcd->tcd_image)
- {
+
+ if (tcd->tcd_image) {
opj_free(tcd->tcd_image);
tcd->tcd_image = 00;
}
@@ -1639,404 +1635,370 @@ void tcd_destroy_v2(opj_tcd_v2_t *tcd) {
*
* @return true if the encoding values could be set (false otherwise).
*/
-#define MACRO_TCD_ALLOCATE(FUNCTION,TYPE,FRACTION,ELEMENT,FUNCTION_ELEMENT) \
-opj_bool FUNCTION \
- ( \
- opj_tcd_v2_t *p_tcd, \
- OPJ_UINT32 p_tile_no \
- ) \
-{ \
- OPJ_UINT32 (*l_gain_ptr)(OPJ_UINT32) = 00; \
- OPJ_UINT32 compno, resno, bandno, precno, cblkno; \
+#define MACRO_TCD_ALLOCATE(FUNCTION,TYPE,FRACTION,ELEMENT,FUNCTION_ELEMENT) \
+opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
+ OPJ_UINT32 p_tile_no \
+ ) \
+{ \
+ OPJ_UINT32 (*l_gain_ptr)(OPJ_UINT32) = 00; \
+ OPJ_UINT32 compno, resno, bandno, precno, cblkno; \
opj_tcp_v2_t * l_tcp = 00; \
opj_cp_v2_t * l_cp = 00; \
- opj_tcd_tile_t * l_tile = 00; \
- opj_tccp_t *l_tccp = 00; \
- opj_tcd_tilecomp_t *l_tilec = 00; \
- opj_image_comp_t * l_image_comp = 00; \
- opj_tcd_resolution_t *l_res = 00; \
- opj_tcd_band_t *l_band = 00; \
- opj_stepsize_t * l_step_size = 00; \
- opj_tcd_precinct_t *l_current_precinct = 00; \
- TYPE* l_code_block = 00; \
- opj_image_header_t * l_image = 00; \
- OPJ_UINT32 p,q; \
- OPJ_UINT32 l_level_no; \
- OPJ_UINT32 l_pdx, l_pdy; \
- OPJ_UINT32 l_gain; \
- OPJ_INT32 l_x0b, l_y0b; \
- /* extent of precincts , top left, bottom right**/ \
+ opj_tcd_tile_v2_t * l_tile = 00; \
+ opj_tccp_t *l_tccp = 00; \
+ opj_tcd_tilecomp_v2_t *l_tilec = 00; \
+ opj_image_comp_header_t * l_image_comp = 00; \
+ opj_tcd_resolution_v2_t *l_res = 00; \
+ opj_tcd_band_v2_t *l_band = 00; \
+ opj_stepsize_t * l_step_size = 00; \
+ opj_tcd_precinct_v2_t *l_current_precinct = 00; \
+ TYPE* l_code_block = 00; \
+ opj_image_header_t *l_image = 00; \
+ OPJ_UINT32 p,q; \
+ OPJ_UINT32 l_level_no; \
+ OPJ_UINT32 l_pdx, l_pdy; \
+ OPJ_UINT32 l_gain; \
+ OPJ_INT32 l_x0b, l_y0b; \
+ /* extent of precincts , top left, bottom right**/ \
OPJ_INT32 l_tl_prc_x_start, l_tl_prc_y_start, l_br_prc_x_end, l_br_prc_y_end; \
- /* number of precinct for a resolution */ \
- OPJ_UINT32 l_nb_precincts; \
- /* room needed to store l_nb_precinct precinct for a resolution */ \
- OPJ_UINT32 l_nb_precinct_size; \
- /* number of code blocks for a precinct*/ \
- OPJ_UINT32 l_nb_code_blocks; \
- /* room needed to store l_nb_code_blocks code blocks for a precinct*/ \
- OPJ_UINT32 l_nb_code_blocks_size; \
- /* size of data for a tile */ \
- OPJ_UINT32 l_data_size; \
- l_cp = p_tcd->cp; \
- l_tcp = &(l_cp->tcps[p_tile_no]); \
- l_tile = p_tcd->tcd_image->tiles; \
- l_tccp = l_tcp->tccps; \
- l_tilec = l_tile->comps; \
- l_image = p_tcd->image_header; \
- l_image_comp = p_tcd->image_header->comps; \
- \
- p = p_tile_no % l_cp->tw; /* tile coordinates */ \
- q = p_tile_no / l_cp->tw; \
- \
- /* 4 borders of the tile rescale on the image if necessary */ \
- l_tile->x0 = int_max(l_cp->tx0 + p * l_cp->tdx, l_image->x0); \
- l_tile->y0 = int_max(l_cp->ty0 + q * l_cp->tdy, l_image->y0); \
- l_tile->x1 = int_min(l_cp->tx0 + (p + 1) * l_cp->tdx, l_image->x1); \
- l_tile->y1 = int_min(l_cp->ty0 + (q + 1) * l_cp->tdy, l_image->y1); \
- /*tile->numcomps = image->numcomps; */ \
- for \
- (compno = 0; compno < l_tile->numcomps; ++compno) \
- { \
- /* border of each l_tile component (global) */ \
- l_tilec->x0 = int_ceildiv(l_tile->x0, l_image_comp->dx); \
- l_tilec->y0 = int_ceildiv(l_tile->y0, l_image_comp->dy); \
- l_tilec->x1 = int_ceildiv(l_tile->x1, l_image_comp->dx); \
- l_tilec->y1 = int_ceildiv(l_tile->y1, l_image_comp->dy); \
- \
- l_data_size = (l_tilec->x1 - l_tilec->x0) \
- * (l_tilec->y1 - l_tilec->y0) * sizeof(OPJ_UINT32 ); \
- l_tilec->numresolutions = l_tccp->numresolutions; \
- if \
- (l_tccp->numresolutions < l_cp->m_specific_param.m_dec.m_reduce)\
- { \
- l_tilec->minimum_num_resolutions = 1; \
- } \
- else \
- { \
- l_tilec->minimum_num_resolutions = l_tccp->numresolutions - l_cp->m_specific_param.m_dec.m_reduce;\
- } \
- if \
- (l_tilec->data == 00) \
- { \
- l_tilec->data = (OPJ_INT32 *) opj_aligned_malloc(l_data_size); \
- if \
- (! l_tilec->data ) \
- { \
+ /* number of precinct for a resolution */ \
+ OPJ_UINT32 l_nb_precincts; \
+ /* room needed to store l_nb_precinct precinct for a resolution */ \
+ OPJ_UINT32 l_nb_precinct_size; \
+ /* number of code blocks for a precinct*/ \
+ OPJ_UINT32 l_nb_code_blocks; \
+ /* room needed to store l_nb_code_blocks code blocks for a precinct*/ \
+ OPJ_UINT32 l_nb_code_blocks_size; \
+ /* size of data for a tile */ \
+ OPJ_UINT32 l_data_size; \
+ \
+ l_cp = p_tcd->cp; \
+ l_tcp = &(l_cp->tcps[p_tile_no]); \
+ l_tile = p_tcd->tcd_image->tiles; \
+ l_tccp = l_tcp->tccps; \
+ l_tilec = l_tile->comps; \
+ l_image = p_tcd->image_header; \
+ l_image_comp = p_tcd->image_header->comps; \
+ \
+ p = p_tile_no % l_cp->tw; /* tile coordinates */ \
+ q = p_tile_no / l_cp->tw; \
+ \
+ /* 4 borders of the tile rescale on the image if necessary */ \
+ l_tile->x0 = int_max(l_cp->tx0 + p * l_cp->tdx, l_image->x0); \
+ l_tile->y0 = int_max(l_cp->ty0 + q * l_cp->tdy, l_image->y0); \
+ l_tile->x1 = int_min(l_cp->tx0 + (p + 1) * l_cp->tdx, l_image->x1); \
+ l_tile->y1 = int_min(l_cp->ty0 + (q + 1) * l_cp->tdy, l_image->y1); \
+ \
+ /*tile->numcomps = image->numcomps; */ \
+ for(compno = 0; compno < l_tile->numcomps; ++compno) { \
+ \
+ /* border of each l_tile component (global) */ \
+ l_tilec->x0 = int_ceildiv(l_tile->x0, l_image_comp->dx); \
+ l_tilec->y0 = int_ceildiv(l_tile->y0, l_image_comp->dy); \
+ l_tilec->x1 = int_ceildiv(l_tile->x1, l_image_comp->dx); \
+ l_tilec->y1 = int_ceildiv(l_tile->y1, l_image_comp->dy); \
+ \
+ l_data_size = (l_tilec->x1 - l_tilec->x0) \
+ * (l_tilec->y1 - l_tilec->y0) * sizeof(OPJ_UINT32 ); \
+ l_tilec->numresolutions = l_tccp->numresolutions; \
+ if (l_tccp->numresolutions < l_cp->m_specific_param.m_dec.m_reduce) { \
+ l_tilec->minimum_num_resolutions = 1; \
+ } \
+ else { \
+ l_tilec->minimum_num_resolutions = l_tccp->numresolutions \
+ - l_cp->m_specific_param.m_dec.m_reduce; \
+ } \
+ \
+ if (l_tilec->data == 00) { \
+ l_tilec->data = (OPJ_INT32 *) opj_aligned_malloc(l_data_size); \
+ if (! l_tilec->data ) { \
return OPJ_FALSE; \
- } \
- l_tilec->data_size = l_data_size; \
- } \
- else if \
- (l_data_size > l_tilec->data_size) \
- { \
- l_tilec->data = (OPJ_INT32 *) opj_realloc(l_tilec->data, l_data_size);\
- if \
- (! l_tilec->data) \
- { \
+ } \
+ \
+ l_tilec->data_size = l_data_size; \
+ } \
+ else if (l_data_size > l_tilec->data_size) { \
+ l_tilec->data = (OPJ_INT32 *) opj_realloc(l_tilec->data, l_data_size); \
+ if (! l_tilec->data) { \
return OPJ_FALSE; \
- } \
- l_tilec->data_size = l_data_size; \
- } \
- l_data_size = l_tilec->numresolutions * sizeof(opj_tcd_resolution_t);\
- if \
- (l_tilec->resolutions == 00) \
- { \
- l_tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(l_data_size);\
- if \
- (! l_tilec->resolutions ) \
- { \
- return OPJ_FALSE; \
- } \
- l_tilec->resolutions_size = l_data_size; \
- memset(l_tilec->resolutions,0,l_data_size); \
- } \
- else if \
- (l_data_size > l_tilec->resolutions_size) \
- { \
- l_tilec->resolutions = (opj_tcd_resolution_t *) opj_realloc(l_tilec->resolutions, l_data_size);\
- if \
- (! l_tilec->resolutions) \
- { \
- return OPJ_FALSE; \
- } \
- memset(((OPJ_BYTE*) l_tilec->resolutions)+l_tilec->resolutions_size,0,l_data_size - l_tilec->resolutions_size);\
- l_tilec->resolutions_size = l_data_size; \
- } \
- l_level_no = l_tilec->numresolutions - 1; \
- l_res = l_tilec->resolutions; \
- l_step_size = l_tccp->stepsizes; \
- if \
- (l_tccp->qmfbid == 0) \
- { \
- l_gain_ptr = &dwt_getgain_real; \
- } \
- else \
- { \
- l_gain_ptr = &dwt_getgain; \
- } \
- for \
- (resno = 0; resno < l_tilec->numresolutions; ++resno) \
- { \
- OPJ_INT32 tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend; \
- OPJ_UINT32 cbgwidthexpn, cbgheightexpn; \
- OPJ_UINT32 cblkwidthexpn, cblkheightexpn; \
- /* border for each resolution level (global) */ \
- l_res->x0 = int_ceildivpow2(l_tilec->x0, l_level_no); \
- l_res->y0 = int_ceildivpow2(l_tilec->y0, l_level_no); \
- l_res->x1 = int_ceildivpow2(l_tilec->x1, l_level_no); \
- l_res->y1 = int_ceildivpow2(l_tilec->y1, l_level_no); \
- /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */\
- l_pdx = l_tccp->prcw[resno]; \
- l_pdy = l_tccp->prch[resno]; \
- /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ \
- l_tl_prc_x_start = int_floordivpow2(l_res->x0, l_pdx) << l_pdx; \
- l_tl_prc_y_start = int_floordivpow2(l_res->y0, l_pdy) << l_pdy; \
- l_br_prc_x_end = int_ceildivpow2(l_res->x1, l_pdx) << l_pdx; \
- l_br_prc_y_end = int_ceildivpow2(l_res->y1, l_pdy) << l_pdy; \
+ } \
+ \
+ l_tilec->data_size = l_data_size; \
+ } \
\
- l_res->pw = (l_res->x0 == l_res->x1) ? 0 : ((l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx);\
- l_res->ph = (l_res->y0 == l_res->y1) ? 0 : ((l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy);\
- l_nb_precincts = l_res->pw * l_res->ph; \
- l_nb_precinct_size = l_nb_precincts * sizeof(opj_tcd_precinct_t);\
- if \
- (resno == 0) \
- { \
- tlcbgxstart = l_tl_prc_x_start; \
- tlcbgystart = l_tl_prc_y_start; \
- brcbgxend = l_br_prc_x_end; \
- brcbgyend = l_br_prc_y_end; \
- cbgwidthexpn = l_pdx; \
- cbgheightexpn = l_pdy; \
- l_res->numbands = 1; \
- } \
- else \
- { \
- tlcbgxstart = int_ceildivpow2(l_tl_prc_x_start, 1); \
- tlcbgystart = int_ceildivpow2(l_tl_prc_y_start, 1); \
- brcbgxend = int_ceildivpow2(l_br_prc_x_end, 1); \
- brcbgyend = int_ceildivpow2(l_br_prc_y_end, 1); \
- cbgwidthexpn = l_pdx - 1; \
- cbgheightexpn = l_pdy - 1; \
- l_res->numbands = 3; \
- } \
- \
- cblkwidthexpn = uint_min(l_tccp->cblkw, cbgwidthexpn); \
- cblkheightexpn = uint_min(l_tccp->cblkh, cbgheightexpn); \
- l_band = l_res->bands; \
- for \
- (bandno = 0; bandno < l_res->numbands; ++bandno) \
- { \
- OPJ_INT32 numbps; \
- if \
- (resno == 0) \
- { \
- l_band->bandno = 0 ; \
- l_band->x0 = int_ceildivpow2(l_tilec->x0, l_level_no); \
- l_band->y0 = int_ceildivpow2(l_tilec->y0, l_level_no); \
- l_band->x1 = int_ceildivpow2(l_tilec->x1, l_level_no); \
- l_band->y1 = int_ceildivpow2(l_tilec->y1, l_level_no); \
- } \
- else \
- { \
- l_band->bandno = bandno + 1; \
- /* x0b = 1 if bandno = 1 or 3 */ \
- l_x0b = l_band->bandno&1; \
- /* y0b = 1 if bandno = 2 or 3 */ \
- l_y0b = (l_band->bandno)>>1; \
- /* l_band border (global) */ \
- l_band->x0 = int_ceildivpow2(l_tilec->x0 - (1 << l_level_no) * l_x0b, l_level_no + 1);\
- l_band->y0 = int_ceildivpow2(l_tilec->y0 - (1 << l_level_no) * l_y0b, l_level_no + 1);\
- l_band->x1 = int_ceildivpow2(l_tilec->x1 - (1 << l_level_no) * l_x0b, l_level_no + 1);\
- l_band->y1 = int_ceildivpow2(l_tilec->y1 - (1 << l_level_no) * l_y0b, l_level_no + 1);\
- } \
- /** avoid an if with storing function pointer */ \
- l_gain = (*l_gain_ptr) (l_band->bandno); \
- numbps = l_image_comp->prec + l_gain; \
+ l_data_size = l_tilec->numresolutions * sizeof(opj_tcd_resolution_v2_t); \
+ \
+ if (l_tilec->resolutions == 00) { \
+ l_tilec->resolutions = (opj_tcd_resolution_v2_t *) opj_malloc(l_data_size); \
+ if (! l_tilec->resolutions ) { \
+ return OPJ_FALSE; \
+ } \
+ \
+ l_tilec->resolutions_size = l_data_size; \
+ memset(l_tilec->resolutions,0,l_data_size); \
+ } \
+ else if (l_data_size > l_tilec->resolutions_size) { \
+ l_tilec->resolutions = (opj_tcd_resolution_v2_t *) opj_realloc(l_tilec->resolutions, l_data_size); \
+ if (! l_tilec->resolutions) { \
+ return OPJ_FALSE; \
+ } \
+ \
+ memset(((OPJ_BYTE*) l_tilec->resolutions)+l_tilec->resolutions_size,0,l_data_size - l_tilec->resolutions_size); \
+ l_tilec->resolutions_size = l_data_size; \
+ } \
+ \
+ l_level_no = l_tilec->numresolutions - 1; \
+ l_res = l_tilec->resolutions; \
+ l_step_size = l_tccp->stepsizes; \
+ if (l_tccp->qmfbid == 0) { \
+ l_gain_ptr = &dwt_getgain_real_v2; \
+ } \
+ else { \
+ l_gain_ptr = &dwt_getgain_v2; \
+ } \
+ \
+ for(resno = 0; resno < l_tilec->numresolutions; ++resno) { \
+ OPJ_INT32 tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend; \
+ OPJ_UINT32 cbgwidthexpn, cbgheightexpn; \
+ OPJ_UINT32 cblkwidthexpn, cblkheightexpn; \
+ \
+ /* border for each resolution level (global) */ \
+ l_res->x0 = int_ceildivpow2(l_tilec->x0, l_level_no); \
+ l_res->y0 = int_ceildivpow2(l_tilec->y0, l_level_no); \
+ l_res->x1 = int_ceildivpow2(l_tilec->x1, l_level_no); \
+ l_res->y1 = int_ceildivpow2(l_tilec->y1, l_level_no); \
+ /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ \
+ l_pdx = l_tccp->prcw[resno]; \
+ l_pdy = l_tccp->prch[resno]; \
+ /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ \
+ l_tl_prc_x_start = int_floordivpow2(l_res->x0, l_pdx) << l_pdx; \
+ l_tl_prc_y_start = int_floordivpow2(l_res->y0, l_pdy) << l_pdy; \
+ l_br_prc_x_end = int_ceildivpow2(l_res->x1, l_pdx) << l_pdx; \
+ l_br_prc_y_end = int_ceildivpow2(l_res->y1, l_pdy) << l_pdy; \
+ \
+ l_res->pw = (l_res->x0 == l_res->x1) ? 0 : ((l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx); \
+ l_res->ph = (l_res->y0 == l_res->y1) ? 0 : ((l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy); \
+ \
+ l_nb_precincts = l_res->pw * l_res->ph; \
+ l_nb_precinct_size = l_nb_precincts * sizeof(opj_tcd_precinct_v2_t); \
+ if (resno == 0) { \
+ tlcbgxstart = l_tl_prc_x_start; \
+ tlcbgystart = l_tl_prc_y_start; \
+ brcbgxend = l_br_prc_x_end; \
+ brcbgyend = l_br_prc_y_end; \
+ cbgwidthexpn = l_pdx; \
+ cbgheightexpn = l_pdy; \
+ l_res->numbands = 1; \
+ } \
+ else { \
+ tlcbgxstart = int_ceildivpow2(l_tl_prc_x_start, 1); \
+ tlcbgystart = int_ceildivpow2(l_tl_prc_y_start, 1); \
+ brcbgxend = int_ceildivpow2(l_br_prc_x_end, 1); \
+ brcbgyend = int_ceildivpow2(l_br_prc_y_end, 1); \
+ cbgwidthexpn = l_pdx - 1; \
+ cbgheightexpn = l_pdy - 1; \
+ l_res->numbands = 3; \
+ } \
+ \
+ cblkwidthexpn = uint_min(l_tccp->cblkw, cbgwidthexpn); \
+ cblkheightexpn = uint_min(l_tccp->cblkh, cbgheightexpn); \
+ l_band = l_res->bands; \
+ \
+ for (bandno = 0; bandno < l_res->numbands; ++bandno) { \
+ OPJ_INT32 numbps; \
+ \
+ if (resno == 0) { \
+ l_band->bandno = 0 ; \
+ l_band->x0 = int_ceildivpow2(l_tilec->x0, l_level_no); \
+ l_band->y0 = int_ceildivpow2(l_tilec->y0, l_level_no); \
+ l_band->x1 = int_ceildivpow2(l_tilec->x1, l_level_no); \
+ l_band->y1 = int_ceildivpow2(l_tilec->y1, l_level_no); \
+ } \
+ else { \
+ l_band->bandno = bandno + 1; \
+ /* x0b = 1 if bandno = 1 or 3 */ \
+ l_x0b = l_band->bandno&1; \
+ /* y0b = 1 if bandno = 2 or 3 */ \
+ l_y0b = (l_band->bandno)>>1; \
+ /* l_band border (global) */ \
+ l_band->x0 = int_ceildivpow2(l_tilec->x0 - (1 << l_level_no) * l_x0b, l_level_no + 1); \
+ l_band->y0 = int_ceildivpow2(l_tilec->y0 - (1 << l_level_no) * l_y0b, l_level_no + 1); \
+ l_band->x1 = int_ceildivpow2(l_tilec->x1 - (1 << l_level_no) * l_x0b, l_level_no + 1); \
+ l_band->y1 = int_ceildivpow2(l_tilec->y1 - (1 << l_level_no) * l_y0b, l_level_no + 1); \
+ } \
+ \
+ /** avoid an if with storing function pointer */ \
+ l_gain = (*l_gain_ptr) (l_band->bandno); \
+ numbps = l_image_comp->prec + l_gain; \
l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_size->mant / 2048.0) * pow(2.0, (OPJ_INT32) (numbps - l_step_size->expn)))) * FRACTION;\
l_band->numbps = l_step_size->expn + l_tccp->numgbits - 1; /* WHY -1 ? */\
- if \
- (! l_band->precincts) \
- { \
- l_band->precincts = (opj_tcd_precinct_t *) opj_malloc(/*3 * */ l_nb_precinct_size);\
- if \
- (! l_band->precincts) \
- { \
+ \
+ if (! l_band->precincts) { \
+ l_band->precincts = (opj_tcd_precinct_v2_t *) opj_malloc( /*3 * */ l_nb_precinct_size);\
+ if (! l_band->precincts) { \
return OPJ_FALSE; \
- } \
- memset(l_band->precincts,0,l_nb_precinct_size); \
- l_band->precincts_data_size = l_nb_precinct_size; \
- } \
- else if \
- (l_band->precincts_data_size < l_nb_precinct_size) \
- { \
- l_band->precincts = (opj_tcd_precinct_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size);\
- if \
- (! l_band->precincts) \
- { \
+ } \
+ \
+ memset(l_band->precincts,0,l_nb_precinct_size); \
+ l_band->precincts_data_size = l_nb_precinct_size; \
+ } \
+ else if (l_band->precincts_data_size < l_nb_precinct_size) { \
+ \
+ l_band->precincts = (opj_tcd_precinct_v2_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size);\
+ if (! l_band->precincts) { \
return OPJ_FALSE; \
- } \
+ } \
memset(((OPJ_BYTE *) l_band->precincts) + l_band->precincts_data_size,0,l_nb_precinct_size - l_band->precincts_data_size);\
- l_band->precincts_data_size = l_nb_precinct_size; \
- } \
- l_current_precinct = l_band->precincts; \
- for \
- (precno = 0; precno < l_nb_precincts; ++precno) \
- { \
+ l_band->precincts_data_size = l_nb_precinct_size; \
+ } \
+ \
+ l_current_precinct = l_band->precincts; \
+ for (precno = 0; precno < l_nb_precincts; ++precno) { \
OPJ_INT32 tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend; \
- OPJ_INT32 cbgxstart = tlcbgxstart + (precno % l_res->pw) * (1 << cbgwidthexpn);\
- OPJ_INT32 cbgystart = tlcbgystart + (precno / l_res->pw) * (1 << cbgheightexpn);\
- OPJ_INT32 cbgxend = cbgxstart + (1 << cbgwidthexpn); \
- OPJ_INT32 cbgyend = cbgystart + (1 << cbgheightexpn); \
- /* precinct size (global) */ \
- l_current_precinct->x0 = int_max(cbgxstart, l_band->x0);\
- l_current_precinct->y0 = int_max(cbgystart, l_band->y0);\
- l_current_precinct->x1 = int_min(cbgxend, l_band->x1); \
- l_current_precinct->y1 = int_min(cbgyend, l_band->y1); \
- tlcblkxstart = int_floordivpow2(l_current_precinct->x0, cblkwidthexpn) << cblkwidthexpn;\
- tlcblkystart = int_floordivpow2(l_current_precinct->y0, cblkheightexpn) << cblkheightexpn;\
- brcblkxend = int_ceildivpow2(l_current_precinct->x1, cblkwidthexpn) << cblkwidthexpn;\
- brcblkyend = int_ceildivpow2(l_current_precinct->y1, cblkheightexpn) << cblkheightexpn;\
- l_current_precinct->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn;\
- l_current_precinct->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn;\
- l_nb_code_blocks = l_current_precinct->cw * l_current_precinct->ch;\
- l_nb_code_blocks_size = l_nb_code_blocks * sizeof(TYPE);\
- if \
- (! l_current_precinct->cblks.ELEMENT) \
- { \
+ OPJ_INT32 cbgxstart = tlcbgxstart + (precno % l_res->pw) * (1 << cbgwidthexpn); \
+ OPJ_INT32 cbgystart = tlcbgystart + (precno / l_res->pw) * (1 << cbgheightexpn); \
+ OPJ_INT32 cbgxend = cbgxstart + (1 << cbgwidthexpn); \
+ OPJ_INT32 cbgyend = cbgystart + (1 << cbgheightexpn); \
+ \
+ /* precinct size (global) */ \
+ l_current_precinct->x0 = int_max(cbgxstart, l_band->x0); \
+ l_current_precinct->y0 = int_max(cbgystart, l_band->y0); \
+ l_current_precinct->x1 = int_min(cbgxend, l_band->x1); \
+ l_current_precinct->y1 = int_min(cbgyend, l_band->y1); \
+ tlcblkxstart = int_floordivpow2(l_current_precinct->x0, cblkwidthexpn) << cblkwidthexpn; \
+ tlcblkystart = int_floordivpow2(l_current_precinct->y0, cblkheightexpn) << cblkheightexpn; \
+ brcblkxend = int_ceildivpow2(l_current_precinct->x1, cblkwidthexpn) << cblkwidthexpn; \
+ brcblkyend = int_ceildivpow2(l_current_precinct->y1, cblkheightexpn) << cblkheightexpn; \
+ l_current_precinct->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; \
+ l_current_precinct->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; \
+ l_nb_code_blocks = l_current_precinct->cw * l_current_precinct->ch; \
+ l_nb_code_blocks_size = l_nb_code_blocks * sizeof(TYPE); \
+ \
+ if (! l_current_precinct->cblks.ELEMENT) { \
l_current_precinct->cblks.ELEMENT = (TYPE*) opj_malloc(l_nb_code_blocks_size);\
- if \
- (! l_current_precinct->cblks.ELEMENT ) \
- { \
+ if (! l_current_precinct->cblks.ELEMENT ) { \
return OPJ_FALSE; \
- } \
+ } \
+ \
memset(l_current_precinct->cblks.ELEMENT,0,l_nb_code_blocks_size);\
- l_current_precinct->block_size = l_nb_code_blocks_size;\
- } \
- else if \
- (l_nb_code_blocks_size > l_current_precinct->block_size)\
- { \
- l_current_precinct->cblks.ELEMENT = (TYPE*) \
- opj_realloc(l_current_precinct->cblks.ELEMENT, l_nb_code_blocks_size);\
- if \
- (! l_current_precinct->cblks.ELEMENT ) \
- { \
+ \
+ l_current_precinct->block_size = l_nb_code_blocks_size; \
+ } \
+ else if (l_nb_code_blocks_size > l_current_precinct->block_size) { \
+ l_current_precinct->cblks.ELEMENT = (TYPE*) \
+ opj_realloc(l_current_precinct->cblks.ELEMENT, l_nb_code_blocks_size); \
+ if (! l_current_precinct->cblks.ELEMENT ) { \
return OPJ_FALSE; \
- } \
- memset(((OPJ_BYTE *) l_current_precinct->cblks.ELEMENT) + l_current_precinct->block_size\
- ,0 \
- ,l_nb_code_blocks_size - l_current_precinct->block_size);\
- l_current_precinct->block_size = l_nb_code_blocks_size;\
- } \
- if \
- (! l_current_precinct->incltree) \
- { \
- l_current_precinct->incltree = tgt_create(l_current_precinct->cw,\
- l_current_precinct->ch);\
- } \
- else \
- { \
- l_current_precinct->incltree = tgt_init(l_current_precinct->incltree,\
- l_current_precinct->cw, \
- l_current_precinct->ch);\
- } \
- if \
- (! l_current_precinct->incltree) \
- { \
+ } \
+ \
+ memset(((OPJ_BYTE *) l_current_precinct->cblks.ELEMENT) + l_current_precinct->block_size \
+ ,0 \
+ ,l_nb_code_blocks_size - l_current_precinct->block_size); \
+ \
+ l_current_precinct->block_size = l_nb_code_blocks_size; \
+ } \
+ \
+ if (! l_current_precinct->incltree) { \
+ l_current_precinct->incltree = tgt_create(l_current_precinct->cw, \
+ l_current_precinct->ch); \
+ } \
+ else{ \
+ l_current_precinct->incltree = tgt_init(l_current_precinct->incltree, \
+ l_current_precinct->cw, \
+ l_current_precinct->ch); \
+ } \
+ \
+ if (! l_current_precinct->incltree) { \
return OPJ_FALSE; \
- } \
- if \
- (! l_current_precinct->imsbtree) \
- { \
- l_current_precinct->imsbtree = tgt_create( \
- l_current_precinct->cw,\
+ } \
+ \
+ if (! l_current_precinct->imsbtree) { \
+ l_current_precinct->imsbtree = tgt_create( \
+ l_current_precinct->cw, \
l_current_precinct->ch);\
- } \
- else \
- { \
- l_current_precinct->imsbtree = tgt_init( \
- l_current_precinct->imsbtree,\
- l_current_precinct->cw,\
- l_current_precinct->ch);\
- } \
- if \
- (! l_current_precinct->imsbtree) \
- { \
+ } \
+ else { \
+ l_current_precinct->imsbtree = tgt_init( \
+ l_current_precinct->imsbtree, \
+ l_current_precinct->cw, \
+ l_current_precinct->ch); \
+ } \
+ \
+ if (! l_current_precinct->imsbtree) { \
return OPJ_FALSE; \
- } \
- l_code_block = l_current_precinct->cblks.ELEMENT; \
- for \
- (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) \
- { \
- OPJ_INT32 cblkxstart = tlcblkxstart + (cblkno % l_current_precinct->cw) * (1 << cblkwidthexpn);\
- OPJ_INT32 cblkystart = tlcblkystart + (cblkno / l_current_precinct->cw) * (1 << cblkheightexpn);\
+ } \
+ \
+ l_code_block = l_current_precinct->cblks.ELEMENT; \
+ \
+ for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) { \
+ OPJ_INT32 cblkxstart = tlcblkxstart + (cblkno % l_current_precinct->cw) * (1 << cblkwidthexpn); \
+ OPJ_INT32 cblkystart = tlcblkystart + (cblkno / l_current_precinct->cw) * (1 << cblkheightexpn); \
OPJ_INT32 cblkxend = cblkxstart + (1 << cblkwidthexpn); \
- OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn); \
- /* code-block size (global) */ \
- l_code_block->x0 = int_max(cblkxstart, l_current_precinct->x0);\
- l_code_block->y0 = int_max(cblkystart, l_current_precinct->y0);\
- l_code_block->x1 = int_min(cblkxend, l_current_precinct->x1);\
- l_code_block->y1 = int_min(cblkyend, l_current_precinct->y1);\
- if \
- (! FUNCTION_ELEMENT(l_code_block)) \
- { \
+ OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn);\
+ \
+ /* code-block size (global) */ \
+ l_code_block->x0 = int_max(cblkxstart, l_current_precinct->x0); \
+ l_code_block->y0 = int_max(cblkystart, l_current_precinct->y0); \
+ l_code_block->x1 = int_min(cblkxend, l_current_precinct->x1); \
+ l_code_block->y1 = int_min(cblkyend, l_current_precinct->y1); \
+ \
+ if (! FUNCTION_ELEMENT(l_code_block)) { \
return OPJ_FALSE; \
- } \
- ++l_code_block; \
- } \
- ++l_current_precinct; \
- } /* precno */ \
- ++l_band; \
- ++l_step_size; \
- } /* bandno */ \
- ++l_res; \
- --l_level_no; \
- } /* resno */ \
- ++l_tccp; \
- ++l_tilec; \
- ++l_image_comp; \
- } /* compno */ \
+ } \
+ ++l_code_block; \
+ } \
+ ++l_current_precinct; \
+ } /* precno */ \
+ ++l_band; \
+ ++l_step_size; \
+ } /* bandno */ \
+ ++l_res; \
+ --l_level_no; \
+ } /* resno */ \
+ ++l_tccp; \
+ ++l_tilec; \
+ ++l_image_comp; \
+ } /* compno */ \
return OPJ_TRUE; \
-} \
+} \
+
// V2 ENCODE MACRO_TCD_ALLOCATE(tcd_init_encode_tile,opj_tcd_cblk_enc_t,1.f,enc,tcd_code_block_enc_allocate)
-MACRO_TCD_ALLOCATE(tcd_init_decode_tile,opj_tcd_cblk_dec_t,0.5f,dec,tcd_code_block_dec_allocate)
+MACRO_TCD_ALLOCATE(tcd_init_decode_tile, opj_tcd_cblk_dec_v2_t, 0.5f, dec, tcd_code_block_dec_allocate)
#undef MACRO_TCD_ALLOCATE
-OPJ_UINT32 tcd_get_decoded_tile_size (
- opj_tcd_v2_t *p_tcd
- )
+OPJ_UINT32 tcd_get_decoded_tile_size ( opj_tcd_v2_t *p_tcd )
{
OPJ_UINT32 i;
OPJ_UINT32 l_data_size = 0;
opj_image_comp_header_t * l_img_comp = 00;
- opj_tcd_tilecomp_t * l_tile_comp = 00;
- opj_tcd_resolution_t * l_res = 00;
+ opj_tcd_tilecomp_v2_t * l_tile_comp = 00;
+ opj_tcd_resolution_v2_t * l_res = 00;
OPJ_UINT32 l_size_comp, l_remaining;
l_tile_comp = p_tcd->tcd_image->tiles->comps;
l_img_comp = p_tcd->image_header->comps;
- for
- (i=0;iimage_header->numcomps;++i)
- {
+
+ for (i=0;iimage_header->numcomps;++i) {
l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/
l_remaining = l_img_comp->prec & 7; /* (%8) */
- if
- (l_remaining)
- {
+
+ if(l_remaining) {
++l_size_comp;
}
- if
- (l_size_comp == 3)
- {
+
+ if (l_size_comp == 3) {
l_size_comp = 4;
}
+
l_res = l_tile_comp->resolutions + l_tile_comp->minimum_num_resolutions - 1;
l_data_size += l_size_comp * (l_res->x1 - l_res->x0) * (l_res->y1 - l_res->y0);
++l_img_comp;
++l_tile_comp;
}
+
return l_data_size;
}
@@ -2058,9 +2020,9 @@ opj_bool tcd_decode_tile_v2(
for (compno = 0; compno < (OPJ_UINT32) p_cstr_info->numcomps; compno++) {
opj_tcp_v2_t *tcp = &p_tcd->cp->tcps[0];
opj_tccp_t *tccp = &tcp->tccps[compno];
- opj_tcd_tilecomp_t *tilec_idx = &p_tcd->tcd_image->tiles->comps[compno];
+ opj_tcd_tilecomp_v2_t *tilec_idx = &p_tcd->tcd_image->tiles->comps[compno];
for (resno = 0; resno < tilec_idx->numresolutions; resno++) {
- opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[resno];
+ opj_tcd_resolution_v2_t *res_idx = &tilec_idx->resolutions[resno];
p_cstr_info->tile[p_tile_no].pw[resno] = res_idx->pw;
p_cstr_info->tile[p_tile_no].ph[resno] = res_idx->ph;
numprec += res_idx->pw * res_idx->ph;
@@ -2133,108 +2095,84 @@ opj_bool tcd_update_tile_data (
{
OPJ_UINT32 i,j,k,l_data_size = 0;
opj_image_comp_header_t * l_img_comp = 00;
- opj_tcd_tilecomp_t * l_tilec = 00;
- opj_tcd_resolution_t * l_res;
+ opj_tcd_tilecomp_v2_t * l_tilec = 00;
+ opj_tcd_resolution_v2_t * l_res;
OPJ_UINT32 l_size_comp, l_remaining;
OPJ_UINT32 l_stride, l_width,l_height;
l_data_size = tcd_get_decoded_tile_size(p_tcd);
- if
- (l_data_size > p_dest_length)
- {
+ if (l_data_size > p_dest_length) {
return OPJ_FALSE;
}
l_tilec = p_tcd->tcd_image->tiles->comps;
l_img_comp = p_tcd->image_header->comps;
- for
- (i=0;iimage_header->numcomps;++i)
- {
+
+ for (i=0;iimage_header->numcomps;++i) {
l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/
l_remaining = l_img_comp->prec & 7; /* (%8) */
l_res = l_tilec->resolutions + l_img_comp->resno_decoded;
l_width = (l_res->x1 - l_res->x0);
l_height = (l_res->y1 - l_res->y0);
l_stride = (l_tilec->x1 - l_tilec->x0) - l_width;
- if
- (l_remaining)
- {
+
+ if (l_remaining) {
++l_size_comp;
}
- if
- (l_size_comp == 3)
- {
+
+ if (l_size_comp == 3) {
l_size_comp = 4;
}
- switch
- (l_size_comp)
- {
+
+ switch (l_size_comp)
+ {
case 1:
{
OPJ_CHAR * l_dest_ptr = (OPJ_CHAR *) p_dest;
const OPJ_INT32 * l_src_ptr = l_tilec->data;
- if
- (l_img_comp->sgnd)
- {
- for
- (j=0;jsgnd) {
+ for (j=0;jdata;
OPJ_INT16 * l_dest_ptr = (OPJ_INT16 *) p_dest;
- if
- (l_img_comp->sgnd)
- {
- for
- (j=0;jsgnd) {
+ for (j=0;jdata;
- for
- (j=0;jtcd_image)
- {
+
+ if (! p_tcd->tcd_image) {
return;
}
- if
- (p_tcd->m_is_decoder)
- {
+
+ if (p_tcd->m_is_decoder) {
l_tcd_code_block_deallocate = tcd_code_block_dec_deallocate;
}
- else
- {
+ else {
// FIXME l_tcd_code_block_deallocate = tcd_code_block_enc_deallocate;
}
-
l_tile = p_tcd->tcd_image->tiles;
- if
- (! l_tile)
- {
+ if (! l_tile) {
return;
}
+
l_tile_comp = l_tile->comps;
- for
- (compno = 0; compno < l_tile->numcomps; ++compno)
- {
+ for (compno = 0; compno < l_tile->numcomps; ++compno) {
l_res = l_tile_comp->resolutions;
- if
- (l_res)
- {
+ if (l_res) {
+
l_nb_resolutions = l_tile_comp->resolutions_size / sizeof(opj_tcd_resolution_t);
- for
- (resno = 0; resno < l_nb_resolutions; ++resno)
- {
+ for (resno = 0; resno < l_nb_resolutions; ++resno) {
l_band = l_res->bands;
- for
- (bandno = 0; bandno < 3; ++bandno)
- {
+ for (bandno = 0; bandno < 3; ++bandno) {
l_precinct = l_band->precincts;
- if
- (l_precinct)
- {
+ if (l_precinct) {
+
l_nb_precincts = l_band->precincts_data_size / sizeof(opj_tcd_precinct_t);
- for
- (precno = 0; precno < l_nb_precincts; ++precno)
- {
+ for (precno = 0; precno < l_nb_precincts; ++precno) {
tgt_destroy(l_precinct->incltree);
l_precinct->incltree = 00;
tgt_destroy(l_precinct->imsbtree);
@@ -2335,6 +2256,7 @@ void tcd_free_tile(opj_tcd_v2_t *p_tcd)
(*l_tcd_code_block_deallocate) (l_precinct);
++l_precinct;
}
+
opj_free(l_band->precincts);
l_band->precincts = 00;
}
@@ -2342,17 +2264,18 @@ void tcd_free_tile(opj_tcd_v2_t *p_tcd)
} /* for (resno */
++l_res;
}
+
opj_free(l_tile_comp->resolutions);
l_tile_comp->resolutions = 00;
}
- if
- (l_tile_comp->data)
- {
+
+ if (l_tile_comp->data) {
opj_aligned_free(l_tile_comp->data);
l_tile_comp->data = 00;
}
++l_tile_comp;
}
+
opj_free(l_tile->comps);
l_tile->comps = 00;
opj_free(p_tcd->tcd_image->tiles);
@@ -2363,31 +2286,29 @@ void tcd_free_tile(opj_tcd_v2_t *p_tcd)
/**
* Allocates memory for a decoding code block.
*/
-opj_bool tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_block)
+opj_bool tcd_code_block_dec_allocate (opj_tcd_cblk_dec_v2_t * p_code_block)
{
OPJ_UINT32 l_seg_size;
- if
- (! p_code_block->data)
- {
+ if (! p_code_block->data) {
+
p_code_block->data = (OPJ_BYTE*) opj_malloc(8192);
- if
- (! p_code_block->data)
- {
+ if (! p_code_block->data) {
return OPJ_FALSE;
}
+
l_seg_size = J2K_DEFAULT_NB_SEGS * sizeof(opj_tcd_seg_t);
p_code_block->segs = (opj_tcd_seg_t *) opj_malloc(l_seg_size);
- if
- (! p_code_block->segs)
- {
+ if (! p_code_block->segs) {
return OPJ_FALSE;
}
memset(p_code_block->segs,0,l_seg_size);
+
p_code_block->m_current_max_segs = J2K_DEFAULT_NB_SEGS;
}
// TODO
//p_code_block->numsegs = 0;
+
return OPJ_TRUE;
}
@@ -2427,49 +2348,42 @@ opj_bool tcd_t2_decode (
return OPJ_TRUE;
}
-opj_bool tcd_t1_decode (
- opj_tcd_v2_t *p_tcd
- )
+opj_bool tcd_t1_decode ( opj_tcd_v2_t *p_tcd )
{
OPJ_UINT32 compno;
opj_t1_t * l_t1;
- opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles;
- opj_tcd_tilecomp_t* l_tile_comp = l_tile->comps;
+ opj_tcd_tile_v2_t * l_tile = p_tcd->tcd_image->tiles;
+ opj_tcd_tilecomp_v2_t* l_tile_comp = l_tile->comps;
opj_tccp_t * l_tccp = p_tcd->tcp->tccps;
l_t1 = t1_create_v2();
- if
- (l_t1 == 00)
- {
+ if (l_t1 == 00) {
return OPJ_FALSE;
}
- for
- (compno = 0; compno < l_tile->numcomps; ++compno)
- {
+
+ for (compno = 0; compno < l_tile->numcomps; ++compno) {
/* The +3 is headroom required by the vectorized DWT */
- t1_decode_cblks(l_t1, l_tile_comp, l_tccp);
+ t1_decode_cblks_v2(l_t1, l_tile_comp, l_tccp);
++l_tile_comp;
++l_tccp;
}
+
t1_destroy_v2(l_t1);
+
return OPJ_TRUE;
}
-opj_bool tcd_dwt_decode (
- opj_tcd_v2_t *p_tcd
- )
+opj_bool tcd_dwt_decode ( opj_tcd_v2_t *p_tcd )
{
OPJ_UINT32 compno;
- opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles;
- opj_tcd_tilecomp_t * l_tile_comp = l_tile->comps;
+ opj_tcd_tile_v2_t * l_tile = p_tcd->tcd_image->tiles;
+ opj_tcd_tilecomp_v2_t * l_tile_comp = l_tile->comps;
opj_tccp_t * l_tccp = p_tcd->tcp->tccps;
opj_image_comp_header_t * l_img_comp = p_tcd->image_header->comps;
- for
- (compno = 0; compno < l_tile->numcomps; compno++)
- {
+ for (compno = 0; compno < l_tile->numcomps; compno++) {
/*
if (tcd->cp->reduce != 0) {
tcd->image->comps[compno].resno_decoded =
@@ -2482,67 +2396,55 @@ opj_bool tcd_dwt_decode (
numres2decode = tcd->image->comps[compno].resno_decoded + 1;
if(numres2decode > 0){
*/
- if
- (l_tccp->qmfbid == 1)
- {
- if
- (! dwt_decode(l_tile_comp, l_img_comp->resno_decoded+1))
- {
+
+ if (l_tccp->qmfbid == 1) {
+ if (! dwt_decode_v2(l_tile_comp, l_img_comp->resno_decoded+1)) {
return OPJ_FALSE;
}
}
- else
- {
- if
- (! dwt_decode_real(l_tile_comp, l_img_comp->resno_decoded+1))
- {
+ else {
+ if (! dwt_decode_real_v2(l_tile_comp, l_img_comp->resno_decoded+1)) {
return OPJ_FALSE;
}
}
+
++l_tile_comp;
++l_img_comp;
++l_tccp;
}
+
return OPJ_TRUE;
}
-opj_bool tcd_mct_decode (
- opj_tcd_v2_t *p_tcd
- )
+opj_bool tcd_mct_decode ( opj_tcd_v2_t *p_tcd )
{
- opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles;
+ opj_tcd_tile_v2_t * l_tile = p_tcd->tcd_image->tiles;
opj_tcp_v2_t * l_tcp = p_tcd->tcp;
- opj_tcd_tilecomp_t * l_tile_comp = l_tile->comps;
+ opj_tcd_tilecomp_v2_t * l_tile_comp = l_tile->comps;
OPJ_UINT32 l_samples,i;
- if
- (! l_tcp->mct)
- {
+ if (! l_tcp->mct) {
return OPJ_TRUE;
}
+
l_samples = (l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0);
- if
- (l_tcp->mct == 2)
- {
+ if (l_tcp->mct == 2) {
OPJ_BYTE ** l_data;
- if
- (! l_tcp->m_mct_decoding_matrix)
- {
+
+ if (! l_tcp->m_mct_decoding_matrix) {
return OPJ_TRUE;
}
+
l_data = (OPJ_BYTE **) opj_malloc(l_tile->numcomps*sizeof(OPJ_BYTE*));
- if
- (! l_data)
- {
+ if (! l_data) {
return OPJ_FALSE;
}
- for
- (i=0;inumcomps;++i)
- {
+
+ for (i=0;inumcomps;++i) {
l_data[i] = (OPJ_BYTE*) l_tile_comp->data;
++l_tile_comp;
}
- if
- (! mct_decode_custom( // MCT data
+
+ if (! mct_decode_custom(// MCT data
(OPJ_BYTE*) l_tcp->m_mct_decoding_matrix,
// size of components
l_samples,
@@ -2551,48 +2453,41 @@ opj_bool tcd_mct_decode (
// nb of components (i.e. size of pData)
l_tile->numcomps,
// tells if the data is signed
- p_tcd->image_header->comps->sgnd))
- {
+ p_tcd->image_header->comps->sgnd)) {
opj_free(l_data);
return OPJ_FALSE;
}
+
opj_free(l_data);
}
- else
- {
- if
- (l_tcp->tccps->qmfbid == 1)
- {
- mct_decode(
- l_tile->comps[0].data,
- l_tile->comps[1].data,
- l_tile->comps[2].data,
- l_samples);
+ else {
+ if (l_tcp->tccps->qmfbid == 1) {
+ mct_decode( l_tile->comps[0].data,
+ l_tile->comps[1].data,
+ l_tile->comps[2].data,
+ l_samples);
}
- else
- {
- mct_decode_real(
- (float*)l_tile->comps[0].data,
- (float*)l_tile->comps[1].data,
- (float*)l_tile->comps[2].data,
- l_samples);
+ else {
+ mct_decode_real( (float*)l_tile->comps[0].data,
+ (float*)l_tile->comps[1].data,
+ (float*)l_tile->comps[2].data,
+ l_samples);
}
}
+
return OPJ_TRUE;
}
-opj_bool tcd_dc_level_shift_decode (
- opj_tcd_v2_t *p_tcd
- )
+opj_bool tcd_dc_level_shift_decode ( opj_tcd_v2_t *p_tcd )
{
OPJ_UINT32 compno;
- opj_tcd_tilecomp_t * l_tile_comp = 00;
+ opj_tcd_tilecomp_v2_t * l_tile_comp = 00;
opj_tccp_t * l_tccp = 00;
opj_image_comp_header_t * l_img_comp = 00;
- opj_tcd_resolution_t* l_res = 00;
+ opj_tcd_resolution_v2_t* l_res = 00;
opj_tcp_v2_t * l_tcp = 00;
- opj_tcd_tile_t * l_tile;
+ opj_tcd_tile_v2_t * l_tile;
OPJ_UINT32 l_width,l_height,i,j;
OPJ_INT32 * l_current_ptr;
OPJ_INT32 l_min, l_max;
@@ -2604,48 +2499,35 @@ opj_bool tcd_dc_level_shift_decode (
l_tccp = p_tcd->tcp->tccps;
l_img_comp = p_tcd->image_header->comps;
- for
- (compno = 0; compno < l_tile->numcomps; compno++)
- {
+ for (compno = 0; compno < l_tile->numcomps; compno++) {
l_res = l_tile_comp->resolutions + l_img_comp->resno_decoded;
l_width = (l_res->x1 - l_res->x0);
l_height = (l_res->y1 - l_res->y0);
l_stride = (l_tile_comp->x1 - l_tile_comp->x0) - l_width;
- if
- (l_img_comp->sgnd)
- {
+
+ if (l_img_comp->sgnd) {
l_min = -(1 << (l_img_comp->prec - 1));
l_max = (1 << (l_img_comp->prec - 1)) - 1;
}
- else
- {
+ else {
l_min = 0;
l_max = (1 << l_img_comp->prec) - 1;
}
+
l_current_ptr = l_tile_comp->data;
- if
- (l_tccp->qmfbid == 1)
- {
- for
- (j=0;jqmfbid == 1) {
+ for (j=0;jm_dc_level_shift, l_min, l_max);
++l_current_ptr;
}
l_current_ptr += l_stride;
}
}
- else
- {
- for
- (j=0;jm_dc_level_shift, l_min, l_max); ;
++l_current_ptr;
@@ -2653,10 +2535,12 @@ opj_bool tcd_dc_level_shift_decode (
l_current_ptr += l_stride;
}
}
+
++l_img_comp;
++l_tccp;
++l_tile_comp;
}
+
return OPJ_TRUE;
}
@@ -2665,33 +2549,32 @@ opj_bool tcd_dc_level_shift_decode (
/**
* Deallocates the encoding data of the given precinct.
*/
-void tcd_code_block_dec_deallocate (opj_tcd_precinct_t * p_precinct)
+void tcd_code_block_dec_deallocate (opj_tcd_precinct_v2_t * p_precinct)
{
OPJ_UINT32 cblkno , l_nb_code_blocks;
- opj_tcd_cblk_dec_t * l_code_block = p_precinct->cblks.dec;
- if
- (l_code_block)
- {
+ opj_tcd_cblk_dec_v2_t * l_code_block = p_precinct->cblks.dec;
+ if (l_code_block) {
+
l_nb_code_blocks = p_precinct->block_size / sizeof(opj_tcd_cblk_dec_t);
- for
- (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno)
- {
- if
- (l_code_block->data)
- {
+ for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) {
+
+ if (l_code_block->data) {
opj_free(l_code_block->data);
l_code_block->data = 00;
}
- if
- (l_code_block->segs)
- {
+
+ if (l_code_block->segs) {
opj_free(l_code_block->segs );
l_code_block->segs = 00;
}
+
++l_code_block;
}
+
opj_free(p_precinct->cblks.dec);
p_precinct->cblks.dec = 00;
}
}
+
+
diff --git a/libopenjpeg/tcd.h b/libopenjpeg/tcd.h
index c3c416c6..c7395e82 100644
--- a/libopenjpeg/tcd.h
+++ b/libopenjpeg/tcd.h
@@ -58,14 +58,14 @@ FIXME: documentation
FIXME: documentation
*/
typedef struct opj_tcd_seg {
- OPJ_BYTE ** data;
- OPJ_UINT32 dataindex;
- OPJ_UINT32 numpasses;
- OPJ_UINT32 real_num_passes;
- OPJ_UINT32 len;
- OPJ_UINT32 maxpasses;
- OPJ_UINT32 numnewpasses;
- OPJ_UINT32 newlen;
+ OPJ_BYTE ** data;
+ OPJ_UINT32 dataindex;
+ OPJ_UINT32 numpasses;
+ OPJ_UINT32 real_num_passes;
+ OPJ_UINT32 len;
+ OPJ_UINT32 maxpasses;
+ OPJ_UINT32 numnewpasses;
+ OPJ_UINT32 newlen;
} opj_tcd_seg_t;
/**
@@ -77,14 +77,21 @@ typedef struct opj_tcd_pass {
int term, len;
} opj_tcd_pass_t;
+typedef struct opj_tcd_pass_v2 {
+ OPJ_UINT32 rate;
+ OPJ_FLOAT64 distortiondec;
+ OPJ_UINT32 len;
+ OPJ_UINT32 term : 1;
+} opj_tcd_pass_v2_t;
+
/**
FIXME: documentation
*/
typedef struct opj_tcd_layer {
- int numpasses; /* Number of passes in the layer */
- int len; /* len of information */
- double disto; /* add for index (Cfr. Marcela) */
- unsigned char *data; /* data */
+ OPJ_UINT32 numpasses; /* Number of passes in the layer */
+ OPJ_UINT32 len; /* len of information */
+ OPJ_FLOAT64 disto; /* add for index (Cfr. Marcela) */
+ OPJ_BYTE *data; /* data */
} opj_tcd_layer_t;
/**
@@ -102,77 +109,93 @@ typedef struct opj_tcd_cblk_enc {
int totalpasses; /* total number of passes */
} opj_tcd_cblk_enc_t;
-//typedef struct opj_tcd_cblk_dec {
-// unsigned char* data; /* Data */
-// opj_tcd_seg_t* segs; /* segments informations */
-// int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
-// int numbps;
-// int numlenbits;
-// int len; /* length */
-// int numnewpasses; /* number of pass added to the code-blocks */
-// int numsegs; /* number of segments */
-//} opj_tcd_cblk_dec_t;
+/**
+FIXME: documentation
+*/
+typedef struct opj_tcd_cblk_enc_v2 {
+ OPJ_BYTE* data; /* Data */
+ opj_tcd_layer_t* layers; /* layer information */
+ opj_tcd_pass_v2_t* passes; /* information about the passes */
+ OPJ_INT32 x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
+ OPJ_UINT32 numbps;
+ OPJ_UINT32 numlenbits;
+ OPJ_UINT32 numpasses; /* number of pass already done for the code-blocks */
+ OPJ_UINT32 numpassesinlayers; /* number of passes in the layer */
+ OPJ_UINT32 totalpasses; /* total number of passes */
+} opj_tcd_cblk_enc_v2_t;
typedef struct opj_tcd_cblk_dec {
- OPJ_BYTE * data; /* Data */
+ unsigned char* data; /* Data */
opj_tcd_seg_t* segs; /* segments informations */
- OPJ_INT32 x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
- OPJ_UINT32 numbps;
- OPJ_UINT32 numlenbits;
- OPJ_UINT32 len; /* length */
- OPJ_UINT32 numnewpasses; /* number of pass added to the code-blocks */
- OPJ_UINT32 numsegs; /* number of segments */
- OPJ_UINT32 real_num_segs;
- OPJ_UINT32 m_current_max_segs;
+ int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
+ int numbps;
+ int numlenbits;
+ int len; /* length */
+ int numnewpasses; /* number of pass added to the code-blocks */
+ int numsegs; /* number of segments */
} opj_tcd_cblk_dec_t;
+
+typedef struct opj_tcd_cblk_dec_v2 {
+ OPJ_BYTE * data; /* Data */
+ opj_tcd_seg_t* segs; /* segments informations */
+ OPJ_INT32 x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
+ OPJ_UINT32 numbps;
+ OPJ_UINT32 numlenbits;
+ OPJ_UINT32 len; /* length */
+ OPJ_UINT32 numnewpasses; /* number of pass added to the code-blocks */
+ OPJ_UINT32 numsegs; /* number of segments */
+ OPJ_UINT32 real_num_segs;
+ OPJ_UINT32 m_current_max_segs;
+} opj_tcd_cblk_dec_v2_t;
+
/**
FIXME: documentation
*/
-//typedef struct opj_tcd_precinct {
-// int x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
-// int cw, ch; /* number of precinct in width and heigth */
-// union{ /* code-blocks informations */
-// opj_tcd_cblk_enc_t* enc;
-// opj_tcd_cblk_dec_t* dec;
-// } cblks;
-// opj_tgt_tree_t *incltree; /* inclusion tree */
-// opj_tgt_tree_t *imsbtree; /* IMSB tree */
-//} opj_tcd_precinct_t;
-
-
typedef struct opj_tcd_precinct {
- OPJ_INT32 x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
- OPJ_UINT32 cw, ch; /* number of precinct in width and heigth */
+ int x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
+ int cw, ch; /* number of precinct in width and heigth */
union{ /* code-blocks informations */
opj_tcd_cblk_enc_t* enc;
opj_tcd_cblk_dec_t* dec;
} cblks;
- OPJ_UINT32 block_size; /* size taken by cblks (in bytes) */
- struct opj_tgt_tree *incltree; /* inclusion tree */
- struct opj_tgt_tree *imsbtree; /* IMSB tree */
+ opj_tgt_tree_t *incltree; /* inclusion tree */
+ opj_tgt_tree_t *imsbtree; /* IMSB tree */
} opj_tcd_precinct_t;
+
+typedef struct opj_tcd_precinct_v2 {
+ OPJ_INT32 x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
+ OPJ_UINT32 cw, ch; /* number of precinct in width and heigth */
+ union{ /* code-blocks informations */
+ opj_tcd_cblk_enc_v2_t* enc;
+ opj_tcd_cblk_dec_v2_t* dec;
+ } cblks;
+ OPJ_UINT32 block_size; /* size taken by cblks (in bytes) */
+ struct opj_tgt_tree *incltree; /* inclusion tree */
+ struct opj_tgt_tree *imsbtree; /* IMSB tree */
+} opj_tcd_precinct_v2_t;
+
/**
FIXME: documentation
*/
-//typedef struct opj_tcd_band {
-// int x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
-// int bandno;
-// opj_tcd_precinct_t *precincts; /* precinct information */
-// int numbps;
-// float stepsize;
-//} opj_tcd_band_t;
-
typedef struct opj_tcd_band {
- OPJ_INT32 x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
- OPJ_UINT32 bandno;
+ int x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
+ int bandno;
opj_tcd_precinct_t *precincts; /* precinct information */
- OPJ_UINT32 precincts_data_size; /* size of data taken by precincts */
- OPJ_INT32 numbps;
- OPJ_FLOAT32 stepsize;
+ int numbps;
+ float stepsize;
} opj_tcd_band_t;
+typedef struct opj_tcd_band_v2 {
+ OPJ_INT32 x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
+ OPJ_UINT32 bandno;
+ opj_tcd_precinct_v2_t *precincts; /* precinct information */
+ OPJ_UINT32 precincts_data_size; /* size of data taken by precincts */
+ OPJ_INT32 numbps;
+ OPJ_FLOAT32 stepsize;
+} opj_tcd_band_v2_t;
+
/**
FIXME: documentation
*/
@@ -183,29 +206,36 @@ typedef struct opj_tcd_resolution {
opj_tcd_band_t bands[3]; /* subband information */
} opj_tcd_resolution_t;
+typedef struct opj_tcd_resolution_v2 {
+ OPJ_INT32 x0, y0, x1, y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */
+ OPJ_UINT32 pw, ph;
+ OPJ_UINT32 numbands; /* number sub-band for the resolution level */
+ opj_tcd_band_v2_t bands[3]; /* subband information */
+} opj_tcd_resolution_v2_t;
+
/**
FIXME: documentation
*/
-//typedef struct opj_tcd_tilecomp {
-// int x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
-// int numresolutions; /* number of resolutions level */
-// opj_tcd_resolution_t *resolutions; /* resolutions information */
-// int *data; /* data of the component */
-// int numpix; /* add fixed_quality */
-//} opj_tcd_tilecomp_t;
-
-typedef struct opj_tcd_tilecomp
-{
- OPJ_INT32 x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
- OPJ_UINT32 numresolutions; /* number of resolutions level */
- OPJ_UINT32 minimum_num_resolutions; /* number of resolutions level to decode (at max)*/
+typedef struct opj_tcd_tilecomp {
+ int x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
+ int numresolutions; /* number of resolutions level */
opj_tcd_resolution_t *resolutions; /* resolutions information */
- OPJ_UINT32 resolutions_size; /* size of data for resolutions (in bytes) */
- OPJ_INT32 *data; /* data of the component */
- OPJ_UINT32 data_size; /* size of the data of the component */
- OPJ_INT32 numpix; /* add fixed_quality */
+ int *data; /* data of the component */
+ int numpix; /* add fixed_quality */
} opj_tcd_tilecomp_t;
+typedef struct opj_tcd_tilecomp_v2
+{
+ OPJ_INT32 x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
+ OPJ_UINT32 numresolutions; /* number of resolutions level */
+ OPJ_UINT32 minimum_num_resolutions; /* number of resolutions level to decode (at max)*/
+ opj_tcd_resolution_v2_t *resolutions; /* resolutions information */
+ OPJ_UINT32 resolutions_size; /* size of data for resolutions (in bytes) */
+ OPJ_INT32 *data; /* data of the component */
+ OPJ_UINT32 data_size; /* size of the data of the component */
+ OPJ_INT32 numpix; /* add fixed_quality */
+} opj_tcd_tilecomp_v2_t;
+
/**
FIXME: documentation
@@ -221,6 +251,17 @@ typedef struct opj_tcd_tile {
int packno;
} opj_tcd_tile_t;
+typedef struct opj_tcd_tile_v2 {
+ OPJ_INT32 x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */
+ OPJ_UINT32 numcomps; /* number of components in tile */
+ opj_tcd_tilecomp_v2_t *comps; /* Components information */
+ OPJ_INT32 numpix; /* add fixed_quality */
+ OPJ_FLOAT64 distotile; /* add fixed_quality */
+ OPJ_FLOAT64 distolayer[100]; /* add fixed_quality */
+ /** packet number */
+ OPJ_UINT32 packno;
+} opj_tcd_tile_v2_t;
+
/**
FIXME: documentation
*/
@@ -229,6 +270,12 @@ typedef struct opj_tcd_image {
opj_tcd_tile_t *tiles; /* Tiles information */
} opj_tcd_image_t;
+typedef struct opj_tcd_image_v2
+{
+ opj_tcd_tile_v2_t *tiles; /* Tiles information */
+}
+opj_tcd_image_v2_t;
+
/**
Tile coder/decoder
*/
@@ -282,7 +329,7 @@ typedef struct opj_tcd_v2
/** Current Packet iterator number */
OPJ_UINT32 cur_pino;
/** info on each image tile */
- opj_tcd_image_t *tcd_image;
+ opj_tcd_image_v2_t *tcd_image;
/** image header */
struct opj_image_header *image_header;
/** coding parameters */