correct style in cio.c and use only op_bool return value; correct error in jp2.c and some style

This commit is contained in:
Mickael Savinaud 2012-05-14 10:02:59 +00:00
parent 1023be33fb
commit 202d5ab754
2 changed files with 43 additions and 59 deletions

View File

@ -428,6 +428,7 @@ opj_stream_t* OPJ_CALLCONV opj_stream_default_create(opj_bool l_is_input)
OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream) OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream)
{ {
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if (l_stream) { if (l_stream) {
opj_free(l_stream->m_stored_data); opj_free(l_stream->m_stored_data);
l_stream->m_stored_data = 00; l_stream->m_stored_data = 00;
@ -454,9 +455,8 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, o
OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function) OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function)
{ {
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if
(!l_stream) if (!l_stream) {
{
return; return;
} }
l_stream->m_seek_fn = p_function; l_stream->m_seek_fn = p_function;
@ -470,11 +470,11 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, o
OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function) OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function)
{ {
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if
((!l_stream )|| (! (l_stream->m_status & opj_stream_e_output))) if ((!l_stream )|| (! (l_stream->m_status & opj_stream_e_output))) {
{
return; return;
} }
l_stream->m_write_fn = p_function; l_stream->m_write_fn = p_function;
} }
@ -486,11 +486,11 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream,
OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function) OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function)
{ {
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if
(! l_stream) if (! l_stream) {
{
return; return;
} }
l_stream->m_skip_fn = p_function; l_stream->m_skip_fn = p_function;
} }
@ -681,7 +681,7 @@ OPJ_SIZE_T opj_stream_write_data (opj_stream_private_t * p_stream,
p_stream->m_byte_offset += (OPJ_OFF_T)l_remaining_bytes; p_stream->m_byte_offset += (OPJ_OFF_T)l_remaining_bytes;
} }
if (opj_stream_flush(p_stream, p_event_mgr) == EXIT_FAILURE) { if (! opj_stream_flush(p_stream, p_event_mgr)) {
return (OPJ_SIZE_T)-1; return (OPJ_SIZE_T)-1;
} }
} }
@ -711,7 +711,7 @@ opj_bool opj_stream_flush (opj_stream_private_t * p_stream, opj_event_mgr_t * p_
p_stream->m_status |= opj_stream_e_error; p_stream->m_status |= opj_stream_e_error;
opj_event_msg_v2(p_event_mgr, EVT_INFO, "Error on writting stream!\n"); opj_event_msg_v2(p_event_mgr, EVT_INFO, "Error on writting stream!\n");
return EXIT_FAILURE; return OPJ_FALSE;
} }
p_stream->m_current_data += l_current_write_nb_bytes; p_stream->m_current_data += l_current_write_nb_bytes;
@ -720,7 +720,7 @@ opj_bool opj_stream_flush (opj_stream_private_t * p_stream, opj_event_mgr_t * p_
p_stream->m_current_data = p_stream->m_stored_data; p_stream->m_current_data = p_stream->m_stored_data;
return EXIT_SUCCESS; return OPJ_TRUE;
} }
/** /**
@ -736,9 +736,8 @@ OPJ_OFF_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz
OPJ_OFF_T l_current_skip_nb_bytes = 0; OPJ_OFF_T l_current_skip_nb_bytes = 0;
assert( p_size >= 0 ); assert( p_size >= 0 );
if
(p_stream->m_bytes_in_buffer >= (OPJ_SIZE_T)p_size) if (p_stream->m_bytes_in_buffer >= (OPJ_SIZE_T)p_size) {
{
p_stream->m_current_data += p_size; p_stream->m_current_data += p_size;
/* it is safe to cast p_size to OPJ_SIZE_T since it is <= m_bytes_in_buffer /* it is safe to cast p_size to OPJ_SIZE_T since it is <= m_bytes_in_buffer
which is of type OPJ_SIZE_T */ which is of type OPJ_SIZE_T */
@ -749,9 +748,7 @@ OPJ_OFF_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz
} }
/* we are now in the case when the remaining data if not sufficient */ /* we are now in the case when the remaining data if not sufficient */
if if (p_stream->m_status & opj_stream_e_end) {
(p_stream->m_status & opj_stream_e_end)
{
l_skip_nb_bytes += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; l_skip_nb_bytes += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_current_data += p_stream->m_bytes_in_buffer; p_stream->m_current_data += p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
@ -760,23 +757,17 @@ OPJ_OFF_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz
} }
/* the flag is not set, we copy data and then do an actual skip on the stream */ /* the flag is not set, we copy data and then do an actual skip on the stream */
if if (p_stream->m_bytes_in_buffer) {
(p_stream->m_bytes_in_buffer)
{
l_skip_nb_bytes += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; l_skip_nb_bytes += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_current_data = p_stream->m_stored_data; p_stream->m_current_data = p_stream->m_stored_data;
p_size -= (OPJ_OFF_T)p_stream->m_bytes_in_buffer; p_size -= (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
} }
while while (p_size > 0) {
(p_size > 0)
{
/* we should do an actual skip on the media */ /* we should do an actual skip on the media */
l_current_skip_nb_bytes = p_stream->m_skip_fn(p_size, p_stream->m_user_data); l_current_skip_nb_bytes = p_stream->m_skip_fn(p_size, p_stream->m_user_data);
if if (l_current_skip_nb_bytes == (OPJ_OFF_T) -1) {
(l_current_skip_nb_bytes == (OPJ_OFF_T) -1)
{
opj_event_msg_v2(p_event_mgr, EVT_INFO, "Stream reached its end !\n"); opj_event_msg_v2(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
p_stream->m_status |= opj_stream_e_end; p_stream->m_status |= opj_stream_e_end;
@ -787,7 +778,9 @@ OPJ_OFF_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz
p_size -= l_current_skip_nb_bytes; p_size -= l_current_skip_nb_bytes;
l_skip_nb_bytes += l_current_skip_nb_bytes; l_skip_nb_bytes += l_current_skip_nb_bytes;
} }
p_stream->m_byte_offset += l_skip_nb_bytes; p_stream->m_byte_offset += l_skip_nb_bytes;
return l_skip_nb_bytes; return l_skip_nb_bytes;
} }
@ -804,17 +797,13 @@ OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_si
OPJ_OFF_T l_current_skip_nb_bytes = 0; OPJ_OFF_T l_current_skip_nb_bytes = 0;
OPJ_OFF_T l_skip_nb_bytes = 0; OPJ_OFF_T l_skip_nb_bytes = 0;
if if (p_stream->m_status & opj_stream_e_error) {
(p_stream->m_status & opj_stream_e_error)
{
return (OPJ_OFF_T) -1; return (OPJ_OFF_T) -1;
} }
/* we should flush data */ /* we should flush data */
l_is_written = opj_stream_flush (p_stream, p_event_mgr); l_is_written = opj_stream_flush (p_stream, p_event_mgr);
if if (! l_is_written) {
(! l_is_written)
{
p_stream->m_status |= opj_stream_e_error; p_stream->m_status |= opj_stream_e_error;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
p_stream->m_current_data = p_stream->m_current_data; p_stream->m_current_data = p_stream->m_current_data;
@ -822,14 +811,11 @@ OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_si
} }
/* then skip */ /* then skip */
while while (p_size > 0) {
(p_size > 0)
{
/* we should do an actual skip on the media */ /* we should do an actual skip on the media */
l_current_skip_nb_bytes = p_stream->m_skip_fn(p_size, p_stream->m_user_data); l_current_skip_nb_bytes = p_stream->m_skip_fn(p_size, p_stream->m_user_data);
if
(l_current_skip_nb_bytes == (OPJ_OFF_T)-1) if (l_current_skip_nb_bytes == (OPJ_OFF_T)-1) {
{
opj_event_msg_v2(p_event_mgr, EVT_INFO, "Stream error!\n"); opj_event_msg_v2(p_event_mgr, EVT_INFO, "Stream error!\n");
p_stream->m_status |= opj_stream_e_error; p_stream->m_status |= opj_stream_e_error;
@ -840,7 +826,9 @@ OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_si
p_size -= l_current_skip_nb_bytes; p_size -= l_current_skip_nb_bytes;
l_skip_nb_bytes += l_current_skip_nb_bytes; l_skip_nb_bytes += l_current_skip_nb_bytes;
} }
p_stream->m_byte_offset += l_skip_nb_bytes; p_stream->m_byte_offset += l_skip_nb_bytes;
return l_skip_nb_bytes; return l_skip_nb_bytes;
} }
@ -923,27 +911,23 @@ opj_bool opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size
*/ */
opj_bool opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr) opj_bool opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr)
{ {
if if (! opj_stream_flush(p_stream,p_event_mgr)) {
(! opj_stream_flush(p_stream,p_event_mgr))
{
p_stream->m_status |= opj_stream_e_error; p_stream->m_status |= opj_stream_e_error;
return EXIT_FAILURE; return OPJ_FALSE;
} }
p_stream->m_current_data = p_stream->m_stored_data; p_stream->m_current_data = p_stream->m_stored_data;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
if if (! p_stream->m_seek_fn(p_size,p_stream->m_user_data)) {
(! p_stream->m_seek_fn(p_size,p_stream->m_user_data))
{
p_stream->m_status |= opj_stream_e_error; p_stream->m_status |= opj_stream_e_error;
return EXIT_FAILURE; return OPJ_FALSE;
} }
else else {
{
p_stream->m_byte_offset = p_size; p_stream->m_byte_offset = p_size;
} }
return EXIT_SUCCESS;
return OPJ_TRUE;
} }

View File

@ -805,7 +805,7 @@ static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio) {
* *
* @return the data being copied. * @return the data being copied.
*/ */
unsigned char * jp2_write_bpcc_v2( opj_jp2_t *jp2, unsigned char * jp2_write_bpcc_v2( opj_jp2_v2_t *jp2,
unsigned int * p_nb_bytes_written ) unsigned int * p_nb_bytes_written )
{ {
unsigned int i; unsigned int i;
@ -2909,17 +2909,17 @@ opj_bool jp2_read_ftyp_v2(
* @return true if writting was successful. * @return true if writting was successful.
*/ */
opj_bool jp2_skip_jp2c( opj_jp2_v2_t *jp2, opj_bool jp2_skip_jp2c( opj_jp2_v2_t *jp2,
struct opj_stream_private *cio, struct opj_stream_private *stream,
struct opj_event_mgr * p_manager ) struct opj_event_mgr * p_manager )
{ {
/* preconditions */ /* preconditions */
assert(jp2 != 00); assert(jp2 != 00);
assert(cio != 00); assert(stream != 00);
assert(p_manager != 00); assert(p_manager != 00);
jp2->j2k_codestream_offset = opj_stream_tell(cio); jp2->j2k_codestream_offset = opj_stream_tell(stream);
if (opj_stream_skip(cio,8,p_manager) != 8) { if (opj_stream_skip(stream,8,p_manager) != 8) {
return OPJ_FALSE; return OPJ_FALSE;
} }