This commit is contained in:
Mickael Savinaud 2012-05-14 17:17:53 +00:00
parent 383495c863
commit 0fb6576511
4 changed files with 68 additions and 9 deletions

View File

@ -888,9 +888,9 @@ opj_bool opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size
p_stream->m_current_data = p_stream->m_stored_data;
p_stream->m_bytes_in_buffer = 0;
if( p_stream->m_seek_fn(p_size,p_stream->m_user_data)) {
if( !(p_stream->m_seek_fn(p_size,p_stream->m_user_data)) ) {
p_stream->m_status |= opj_stream_e_end;
return EXIT_FAILURE;
return OPJ_FALSE;
}
else {
/* reset stream status */
@ -899,7 +899,7 @@ opj_bool opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size
}
return EXIT_SUCCESS;
return OPJ_TRUE;
}
/**
@ -979,5 +979,5 @@ opj_bool opj_stream_default_seek (OPJ_OFF_T p_nb_bytes, void * p_user_data)
{
OPJ_ARG_NOT_USED(p_nb_bytes);
OPJ_ARG_NOT_USED(p_user_data);
return EXIT_FAILURE;
return OPJ_FALSE;
}

View File

@ -11795,7 +11795,7 @@ static opj_bool j2k_decode_one_tile ( opj_j2k_v2_t *p_j2k,
if(l_current_tile_no == l_tile_no_to_dec)
{
/* move into the codestream to the the first SOT (FIXME or not move?)*/
if (opj_stream_read_seek(p_stream, p_j2k->cstr_index->main_head_end + 2, p_manager) ) {
if (!(opj_stream_read_seek(p_stream, p_j2k->cstr_index->main_head_end + 2, p_manager) ) ) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Problem with seek function\n");
return OPJ_FALSE;
}

View File

@ -210,6 +210,21 @@ static opj_bool jp2_read_jp2h_v2(
);
static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
/**
* Writes the Jpeg2000 codestream Header box - JP2C Header box. This function must be called AFTER the coding has been done.
*
* @param cio the stream to write data to.
* @param jp2 the jpeg2000 file codec.
* @param p_manager user event manager.
*
* @return true if writting was successful.
*/
static opj_bool jp2_write_jp2c_v2( opj_jp2_v2_t *jp2,
struct opj_stream_private *cio,
struct opj_event_mgr * p_manager );
static opj_bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset);
static void jp2_write_jp(opj_cio_t *cio);
/**
@ -2063,6 +2078,50 @@ static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, op
return box.length;
}
/**
* Writes the Jpeg2000 codestream Header box - JP2C Header box.
*
* @param cio the stream to write data to.
* @param jp2 the jpeg2000 file codec.
* @param p_manager user event manager.
*
* @return true if writting was successful.
*/
opj_bool jp2_write_jp2c_v2( opj_jp2_v2_t *jp2,
opj_stream_private_t *cio,
opj_event_mgr_t * p_manager )
{
unsigned int j2k_codestream_exit;
unsigned char l_data_header [8];
// preconditions
assert(jp2 != 00);
assert(cio != 00);
assert(p_manager != 00);
assert(opj_stream_has_seek(cio));
j2k_codestream_exit = opj_stream_tell(cio);
opj_write_bytes(l_data_header,j2k_codestream_exit - jp2->j2k_codestream_offset,4); /* size of codestream */
opj_write_bytes(l_data_header + 4,JP2_JP2C,4); /* JP2C */
if (! opj_stream_seek(cio,jp2->j2k_codestream_offset,p_manager)) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
return OPJ_FALSE;
}
if (opj_stream_write_data(cio,l_data_header,8,p_manager) != 8) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
return OPJ_FALSE;
}
if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
return OPJ_FALSE;
}
return OPJ_TRUE;
}
static opj_bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset) {
opj_jp2_box_t box;
@ -2500,7 +2559,7 @@ void jp2_setup_end_header_writting (opj_jp2_v2_t *jp2)
/* preconditions */
assert(jp2 != 00);
opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)jp2_write_jp2c );
opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)jp2_write_jp2c_v2 );
/* DEVELOPER CORNER, add your custom procedures */
}

View File

@ -248,10 +248,10 @@ OPJ_OFF_T opj_skip_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
opj_bool opj_seek_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
{
if (OPJ_FSEEK(p_user_data,p_nb_bytes,SEEK_SET)) {
return EXIT_FAILURE;
return OPJ_FALSE;
}
return EXIT_SUCCESS;
return OPJ_TRUE;
}
/* ---------------------------------------------------------------------- */
@ -660,7 +660,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress_v2(OPJ_CODEC_FORMAT p_format)
/* get a JP2 decoder handle */
l_codec->m_codec_data.m_compression.opj_encode = (opj_bool (*) (void *,
struct opj_stream_private *,
struct opj_event_mgr * )) opj_jp2_encode;
struct opj_event_mgr * )) opj_jp2_encode_v2;
l_codec->m_codec_data.m_compression.opj_end_compress = (opj_bool (*) ( void *,
struct opj_stream_private *,