[trunk] WIP: add stream length value to read unknown marker size, backport 855 into V2 framework, correct memory leak into get_cstr_info

This commit is contained in:
Mickael Savinaud 2011-10-11 08:01:31 +00:00
parent c4642d4fda
commit 990dd18474
7 changed files with 121 additions and 49 deletions

View File

@ -6,6 +6,7 @@ What's New for OpenJPEG
+ : added
October 11, 2011
* [mickael] WIP: add stream length value to read unknown marker size, backport 855 into V2 framework, correct memory leak into get_cstr_info
* [mickael] WIP: add output elements about decoding of jp2 files with last tile part lenght equal zero
* [mickael] WIP: correct mistake with JP2 files and manage correctly the text_GBR.jp2 filecase

View File

@ -439,11 +439,11 @@ OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream)
OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function)
{
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if
((!l_stream) || (! (l_stream->m_status & opj_stream_e_input)))
{
if ((!l_stream) || (! (l_stream->m_status & opj_stream_e_input))) {
return;
}
l_stream->m_read_fn = p_function;
}
@ -501,6 +501,18 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void
l_stream->m_user_data = p_data;
}
/**
* Sets the given data to be used as a user data for the stream.
* @param p_stream the stream to modify
* @param p_data the data to set.
*/
OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT32 data_length)
{
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
l_stream->m_user_data_length = data_length;
}
/**
* Reads some bytes from the stream.
* @param p_stream the stream to read data from.
@ -852,6 +864,21 @@ OPJ_SIZE_T opj_stream_tell (const opj_stream_private_t * p_stream)
return p_stream->m_byte_offset;
}
/**
* Get the number of bytes left before the end of the stream (similar to cio_numbytesleft).
*
* @param p_stream the stream to get the information from.
*
* @return Number of bytes left before the end of the stream.
*/
OPJ_SIZE_T opj_stream_get_number_byte_left (const opj_stream_private_t * p_stream)
{
return p_stream->m_user_data_length ?
p_stream->m_user_data_length - p_stream->m_byte_offset :
0;
}
/**
* Skips a number of bytes from the stream.
* @param p_stream the stream to skip data from.

View File

@ -125,6 +125,11 @@ typedef struct opj_stream_private
*/
void * m_user_data;
/**
* User data length
*/
OPJ_UINT32 m_user_data_length;
/**
* Pointer to actual read function (NULL at the initialization of the cio.
*/
@ -326,6 +331,16 @@ OPJ_SIZE_T opj_stream_skip (opj_stream_private_t * p_stream,OPJ_SIZE_T p_size, s
*/
OPJ_SIZE_T opj_stream_tell (const opj_stream_private_t * p_stream);
/**
* Get the number of bytes left before the end of the stream (similar to cio_numbytesleft).
*
* @param p_stream the stream to get the information from.
*
* @return Number of bytes left before the end of the stream.
*/
OPJ_SIZE_T opj_stream_get_number_byte_left (const opj_stream_private_t * p_stream);
/**
* Skips a number of bytes from the stream.
* @param p_stream the stream to skip data from.

View File

@ -3352,10 +3352,9 @@ opj_bool j2k_read_sot_v2 (
/* Ref A.4.2: Psot could be equal zero if it is the last tile-part of the codestream.*/
if (!l_tot_len) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Psot value of the current tile-part is equal to zero, "
"for the moment we couldn't manage this case (need to compute the number of byte left"
" in the codestream).\n");
return OPJ_FALSE;
opj_event_msg_v2(p_manager, EVT_INFO, "Psot value of the current tile-part is equal to zero, "
"we assuming it is the last tile-part of the codestream.\n");
p_j2k->m_specific_param.m_decoder.m_last_tile_part = 1;
}
opj_read_bytes(p_header_data,&l_current_part ,1); /* TPsot */
@ -3575,6 +3574,10 @@ opj_bool j2k_read_sod_v2 (
assert(p_stream != 00);
l_tcp = &(p_j2k->m_cp.tcps[p_j2k->m_current_tile_number]);
if (p_j2k->m_specific_param.m_decoder.m_last_tile_part)
p_j2k->m_specific_param.m_decoder.m_sot_length = opj_stream_get_number_byte_left(p_stream) - 2;
else
p_j2k->m_specific_param.m_decoder.m_sot_length -= 2;
l_current_data = &(l_tcp->m_data);
@ -6765,7 +6768,7 @@ opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_v2_t* p_j2k)
cstr_info->m_default_tile_info.numlayers = l_default_tile->numlayers;
cstr_info->m_default_tile_info.mct = l_default_tile->mct;
cstr_info->m_default_tile_info.tccp_info = (opj_tccp_info_t*) opj_calloc(1,sizeof(opj_tccp_info_t));
cstr_info->m_default_tile_info.tccp_info = (opj_tccp_info_t*) opj_calloc(cstr_info->nbcomps, sizeof(opj_tccp_info_t));
for (compno = 0; compno < numcomps; compno++) {
opj_tccp_t *l_tccp = &(l_default_tile->tccps[compno]);
@ -6781,8 +6784,8 @@ opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_v2_t* p_j2k)
l_tccp_info->qmfbid = l_tccp->qmfbid;
if (l_tccp->numresolutions < J2K_MAXRLVLS)
{
memcpy(l_tccp_info->prch, l_tccp->prch, l_tccp->numresolutions);
memcpy(l_tccp_info->prcw, l_tccp->prcw, l_tccp->numresolutions);
memcpy(l_tccp_info->prch, l_tccp->prch, l_tccp->numresolutions - 1);
memcpy(l_tccp_info->prcw, l_tccp->prcw, l_tccp->numresolutions - 1);
}
/* quantization style*/

View File

@ -126,6 +126,17 @@ OPJ_UINT32 opj_read_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p_
return l_nb_read ? l_nb_read : -1;
}
OPJ_UINT32 opj_get_data_length_from_file (FILE * p_file)
{
OPJ_UINT32 file_length = 0;
fseek(p_file, 0, SEEK_END);
file_length = ftell(p_file);
fseek(p_file, 0, SEEK_SET);
return file_length;
}
OPJ_UINT32 opj_write_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p_file)
{
return fwrite(p_buffer,1,p_nb_bytes,p_file);
@ -586,6 +597,7 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_UIN
}
opj_stream_set_user_data(l_stream, p_file);
opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file));
opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);
opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);

View File

@ -1085,6 +1085,13 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, o
*/
OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data);
/**
* Sets the length of the user data for the stream.
* @param p_stream the stream to modify
* @param data_length length of the user_data.
*/
OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT32 data_length);
/**
* Helper function.

View File

@ -2458,6 +2458,8 @@ opj_bool tcd_mct_decode ( opj_tcd_v2_t *p_tcd )
}
l_samples = (l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0);
if (l_tile->numcomps >= 3 ){
if (l_tcp->mct == 2) {
OPJ_BYTE ** l_data;
@ -2505,6 +2507,11 @@ opj_bool tcd_mct_decode ( opj_tcd_v2_t *p_tcd )
l_samples);
}
}
}
else {
/* FIXME need to use opj_event_msg_v2 function */
fprintf(stderr,"Number of components (%d) is inconsistent with a MCT. Skip the MCT step.\n",l_tile->numcomps);
}
return OPJ_TRUE;
}