diff options
| author | Mickael Savinaud <savmickael@users.noreply.github.com> | 2011-09-19 16:01:49 +0000 |
|---|---|---|
| committer | Mickael Savinaud <savmickael@users.noreply.github.com> | 2011-09-19 16:01:49 +0000 |
| commit | d44375aece5dea2af83ffb8c9de4ade2ad35c593 (patch) | |
| tree | 9c4c43b99c704852d3c55c501206e02aaf4e39ad /libopenjpeg | |
| parent | cf37058d7c5ba3560e86e40244556b58e4349e8c (diff) | |
WIP: create a new framework to output file information
Diffstat (limited to 'libopenjpeg')
| -rw-r--r-- | libopenjpeg/image.c | 5 | ||||
| -rw-r--r-- | libopenjpeg/j2k.c | 189 | ||||
| -rw-r--r-- | libopenjpeg/j2k.h | 5 | ||||
| -rw-r--r-- | libopenjpeg/jp2.c | 6 | ||||
| -rw-r--r-- | libopenjpeg/jp2.h | 3 | ||||
| -rw-r--r-- | libopenjpeg/openjpeg.c | 189 | ||||
| -rw-r--r-- | libopenjpeg/openjpeg.h | 144 | ||||
| -rw-r--r-- | libopenjpeg/t2.c | 4 | ||||
| -rw-r--r-- | libopenjpeg/t2.h | 7 | ||||
| -rw-r--r-- | libopenjpeg/tcd.c | 8 | ||||
| -rw-r--r-- | libopenjpeg/tcd.h | 6 |
11 files changed, 443 insertions, 123 deletions
diff --git a/libopenjpeg/image.c b/libopenjpeg/image.c index 0869b9af..9941b1d8 100644 --- a/libopenjpeg/image.c +++ b/libopenjpeg/image.c @@ -141,3 +141,8 @@ void opj_image_comp_header_update(opj_image_header_t * p_image_header, const opj } } +void opj_initialise_file_info(opj_file_info_t *file_info, OPJ_INT32 file_info_flag, OPJ_INT32 codec_format) { + + file_info->file_info_flag = file_info_flag; + file_info->file_format = codec_format; +} diff --git a/libopenjpeg/j2k.c b/libopenjpeg/j2k.c index f551c10c..9375b618 100644 --- a/libopenjpeg/j2k.c +++ b/libopenjpeg/j2k.c @@ -1476,23 +1476,34 @@ opj_bool j2k_read_siz_v2 ( /* Index */ if (p_j2k->cstr_info) { - //opj_codestream_info_t *cstr_info = p_j2k->cstr_info; + int it_tile = 0; + p_j2k->cstr_info->image_w = l_image->x1 - l_image->x0; p_j2k->cstr_info->image_h = l_image->y1 - l_image->y0; p_j2k->cstr_info->numcomps = l_image->numcomps; p_j2k->cstr_info->tw = l_cp->tw; p_j2k->cstr_info->th = l_cp->th; - p_j2k->cstr_info->tile_x = l_cp->tdx; - p_j2k->cstr_info->tile_y = l_cp->tdy; - p_j2k->cstr_info->tile_Ox = l_cp->tx0; - p_j2k->cstr_info->tile_Oy = l_cp->ty0; - p_j2k->cstr_info->tile = (opj_tile_info_t*) opj_calloc(l_nb_tiles, sizeof(opj_tile_info_t)); - if (p_j2k->cstr_info->tile == 00) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n"); + p_j2k->cstr_info->tdx = l_cp->tdx; + p_j2k->cstr_info->tdy = l_cp->tdy; + p_j2k->cstr_info->tx0 = l_cp->tx0; + p_j2k->cstr_info->ty0 = l_cp->ty0; + + p_j2k->cstr_info->tile = (opj_tile_info_v2_t*) opj_calloc(l_nb_tiles, sizeof(opj_tile_info_v2_t)); + if (! p_j2k->cstr_info->tile) { + opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory [SIZ marker]\n"); return OPJ_FALSE; } - memset(p_j2k->cstr_info->tile,0,l_nb_tiles * sizeof(opj_tile_info_t)); + + for (it_tile = 0; it_tile < l_nb_tiles; it_tile++ ) { + p_j2k->cstr_info->tile[it_tile].tccp_info = + (opj_tccp_info_t*) opj_calloc( l_image->numcomps, sizeof(opj_tccp_info_t)); + if (! p_j2k->cstr_info->tile[it_tile].tccp_info) { + opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory [SIZ marker]\n"); + return OPJ_FALSE; + } + } } + return OPJ_TRUE; } @@ -1706,20 +1717,20 @@ opj_bool j2k_read_cod_v2 ( opj_tcp_v2_t *l_tcp = 00; opj_image_header_t *l_image = 00; - // preconditions + /* preconditions */ assert(p_header_data != 00); assert(p_j2k != 00); assert(p_manager != 00); l_image = p_j2k->m_image_header; l_cp = &(p_j2k->m_cp); - // If we are in a tile-part header + + /* If we are in the first tile-part header of the current tile */ l_tcp = (p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_TPH) ? /*FIXME J2K_DEC_STATE_TPH)*/ &l_cp->tcps[p_j2k->m_current_tile_number] : p_j2k->m_specific_param.m_decoder.m_default_tcp; - - // Make sure room is sufficient + /* Make sure room is sufficient */ if (p_header_size < 5) { opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading COD marker\n"); return OPJ_FALSE; @@ -3505,7 +3516,7 @@ opj_bool j2k_read_sod_v2 ( ) { OPJ_UINT32 l_current_read_size; - opj_codestream_info_t * l_cstr_info = 00; + opj_codestream_info_v2_t * l_cstr_info = 00; OPJ_BYTE ** l_current_data = 00; opj_tcp_v2_t * l_tcp = 00; OPJ_UINT32 * l_tile_len = 00; @@ -4894,17 +4905,14 @@ opj_bool j2k_end_decompress( */ opj_bool j2k_read_header( struct opj_stream_private *p_stream, opj_j2k_v2_t* p_j2k, - struct opj_image_header** image_header, - struct opj_codestream_info** cstr_info, + opj_file_info_t* p_file_info, struct opj_event_mgr* p_manager ) { - // preconditions + /* preconditions */ assert(p_j2k != 00); assert(p_stream != 00); assert(p_manager != 00); - //p_image_header = NULL; - /* create an empty image header */ p_j2k->m_image_header = opj_image_header_create0(); if (! p_j2k->m_image_header) { @@ -4931,20 +4939,122 @@ opj_bool j2k_read_header( struct opj_stream_private *p_stream, return OPJ_FALSE; } - *cstr_info = p_j2k->cstr_info; + /* If necessary copy j2k header information into the output structure */ + if (p_file_info->file_info_flag & OPJ_J2K_INFO){ + fill_cstr_info( &(p_file_info->codestream_info), p_j2k, p_manager); + } + + /* If necessary copy image header information into the output structure */ + if (p_file_info->file_info_flag & OPJ_IMG_INFO){ + fill_img_info( &(p_file_info->img_info), p_j2k, p_manager); + } - *image_header = p_j2k->m_image_header; - (*image_header)->tile_x0 = p_j2k->m_cp.tx0; - (*image_header)->tile_y0 = p_j2k->m_cp.ty0; - (*image_header)->tile_width = p_j2k->m_cp.tdx; - (*image_header)->tile_height = p_j2k->m_cp.tdy; - (*image_header)->nb_tiles_x = p_j2k->m_cp.tw; - (*image_header)->nb_tiles_y = p_j2k->m_cp.th; + return OPJ_TRUE; +} + +/** + * Fill the image info struct from information read from main header. + */ +opj_bool fill_img_info(opj_image_header_t* img_info, opj_j2k_v2_t* p_j2k, struct opj_event_mgr* p_manager) +{ + opj_image_header_t* l_image_header = p_j2k->m_image_header; + + img_info->x0 = l_image_header->x0; + img_info->y0 = l_image_header->y0; + img_info->x1 = l_image_header->x1; + img_info->y1 = l_image_header->y1; + img_info->numcomps = l_image_header->numcomps; + + if (img_info->numcomps) { + img_info->comps = (opj_image_comp_header_t*)opj_malloc(img_info->numcomps * sizeof(opj_image_comp_header_t)); + if (!img_info->comps){ + opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory\n"); + return OPJ_FALSE; + } + + memcpy(img_info->comps, l_image_header->comps, img_info->numcomps * sizeof(opj_image_comp_header_t) ); + } + + + img_info->icc_profile_len = l_image_header->icc_profile_len; + if (img_info->icc_profile_len) { + img_info->icc_profile_buf = (unsigned char*)opj_malloc(img_info->icc_profile_len * sizeof(unsigned char)); + if (!img_info->icc_profile_buf){ + opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory\n"); + return OPJ_FALSE; + } + + memcpy(img_info->icc_profile_buf, l_image_header->icc_profile_buf, img_info->icc_profile_len); + } return OPJ_TRUE; } /** + * Fill the codestream info struct from information read from main header. + */ +opj_bool fill_cstr_info(opj_codestream_info_v2_t* cstr_info, opj_j2k_v2_t* p_j2k, struct opj_event_mgr* p_manager) +{ + + //opj_cp_v2_t l_cp = p_j2k->m_cp; + opj_image_header_t* l_image_header = p_j2k->m_image_header; + int it_tile, it_comp; + int nb_tiles, nb_comps; + + cstr_info->image_w = l_image_header->x1 - l_image_header->x0; + cstr_info->image_h = l_image_header->y1 - l_image_header->y0; + cstr_info->numcomps = l_image_header->numcomps; + cstr_info->tw = p_j2k->m_cp.tw; + cstr_info->th = p_j2k->m_cp.th; + cstr_info->tdx = p_j2k->m_cp.tdx; + cstr_info->tdy = p_j2k->m_cp.tdy; + cstr_info->tx0 = p_j2k->m_cp.tx0; + cstr_info->ty0 = p_j2k->m_cp.ty0; + + nb_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th; + nb_comps = l_image_header->numcomps; + + cstr_info->tile = (opj_tile_info_v2_t*) opj_calloc(nb_tiles, sizeof(opj_tile_info_v2_t)); + if (! p_j2k->cstr_info->tile) { + opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory\n"); + return OPJ_FALSE; + } + + for (it_tile=0; it_tile < nb_tiles; it_tile++){ + cstr_info->tile[it_tile].tileno = it_tile; + cstr_info->tile[it_tile].csty = p_j2k->m_cp.tcps[it_tile].csty; + cstr_info->tile[it_tile].prg = p_j2k->m_cp.tcps[it_tile].prg; + cstr_info->tile[it_tile].mct = p_j2k->m_cp.tcps[it_tile].mct; + cstr_info->tile[it_tile].numlayers = p_j2k->m_cp.tcps[it_tile].numlayers; + // FIXME Number of tile part l_cstr_info->tile[it_tile].num_tps = ; + + cstr_info->tile[it_tile].tccp_info = + (opj_tccp_info_t*) opj_calloc(nb_comps, sizeof(opj_tccp_info_t)); + if (! p_j2k->cstr_info->tile[it_tile].tccp_info) { + opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory\n"); + return OPJ_FALSE; + } + + for (it_comp=0; it_comp < nb_comps; it_comp++){ + cstr_info->tile[it_tile].tccp_info[it_comp].compno = it_comp; + cstr_info->tile[it_tile].tccp_info[it_comp].cblkh = p_j2k->m_cp.tcps[it_tile].tccps[it_comp].cblkh; + cstr_info->tile[it_tile].tccp_info[it_comp].cblkw = p_j2k->m_cp.tcps[it_tile].tccps[it_comp].cblkw; + cstr_info->tile[it_tile].tccp_info[it_comp].cblksty = p_j2k->m_cp.tcps[it_tile].tccps[it_comp].cblksty; + cstr_info->tile[it_tile].tccp_info[it_comp].csty = p_j2k->m_cp.tcps[it_tile].tccps[it_comp].csty; + cstr_info->tile[it_tile].tccp_info[it_comp].numgbits = p_j2k->m_cp.tcps[it_tile].tccps[it_comp].numgbits; + cstr_info->tile[it_tile].tccp_info[it_comp].numresolutions = p_j2k->m_cp.tcps[it_tile].tccps[it_comp].numresolutions; + cstr_info->tile[it_tile].tccp_info[it_comp].qmfbid = p_j2k->m_cp.tcps[it_tile].tccps[it_comp].qmfbid; + cstr_info->tile[it_tile].tccp_info[it_comp].qntsty = p_j2k->m_cp.tcps[it_tile].tccps[it_comp].qntsty; + cstr_info->tile[it_tile].tccp_info[it_comp].roishift = p_j2k->m_cp.tcps[it_tile].tccps[it_comp].roishift; + } + } + + return OPJ_TRUE; +} + + + +/** * Sets up the procedures to do on reading header. Developpers wanting to extend the library can add their own reading procedures. */ void j2k_setup_header_reading (opj_j2k_v2_t *p_j2k) @@ -5891,7 +6001,7 @@ opj_j2k_v2_t* j2k_create_decompress_v2() l_j2k->m_specific_param.m_decoder.m_header_data_size = J2K_DEFAULT_HEADER_SIZE; // codestream info creation - l_j2k->cstr_info = (opj_codestream_info_t*) opj_malloc(sizeof(opj_codestream_info_t)); + l_j2k->cstr_info = (opj_codestream_info_v2_t*) opj_malloc(sizeof(opj_codestream_info_v2_t)); if (!l_j2k->cstr_info){ opj_free(l_j2k); return NULL; @@ -5936,7 +6046,7 @@ opj_bool j2k_read_SPCod_SPCoc( opj_tccp_t *l_tccp = NULL; OPJ_BYTE * l_current_ptr = NULL; - // preconditions + /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); assert(p_header_data != 00); @@ -5946,22 +6056,23 @@ opj_bool j2k_read_SPCod_SPCoc( &l_cp->tcps[p_j2k->m_current_tile_number] : p_j2k->m_specific_param.m_decoder.m_default_tcp; - // precondition again + /* precondition again */ assert(compno < p_j2k->m_image_header->numcomps); l_tccp = &l_tcp->tccps[compno]; l_current_ptr = p_header_data; - // make sure room is sufficient + /* make sure room is sufficient */ if (*p_header_size < 5) { opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading SPCod SPCoc element\n"); return OPJ_FALSE; } + opj_read_bytes(l_current_ptr, &l_tccp->numresolutions ,1); /* SPcox (D) */ ++l_tccp->numresolutions; /* tccp->numresolutions = read() + 1 */ ++l_current_ptr; - // If user wants to remove more resolutions than the codestream contains, return error + /* If user wants to remove more resolutions than the codestream contains, return error */ if (l_cp->m_specific_param.m_dec.m_reduce >= l_tccp->numresolutions) { opj_event_msg_v2(p_manager, EVT_ERROR, "Error decoding component %d.\nThe number of resolutions to remove is higher than the number " "of resolutions of this component\nModify the cp_reduce parameter.\n\n", compno); @@ -5985,18 +6096,20 @@ opj_bool j2k_read_SPCod_SPCoc( *p_header_size = *p_header_size - 5; - // use custom precinct size ? + /* use custom precinct size ? */ if (l_tccp->csty & J2K_CCP_CSTY_PRT) { if (*p_header_size < l_tccp->numresolutions) { opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading SPCod SPCoc element\n"); return OPJ_FALSE; } + for (i = 0; i < l_tccp->numresolutions; ++i) { opj_read_bytes(l_current_ptr,&l_tmp ,1); /* SPcoc (I_i) */ ++l_current_ptr; l_tccp->prcw[i] = l_tmp & 0xf; l_tccp->prch[i] = l_tmp >> 4; } + *p_header_size = *p_header_size - l_tccp->numresolutions; } else { @@ -6010,6 +6123,14 @@ opj_bool j2k_read_SPCod_SPCoc( /* INDEX >> */ if (p_j2k->cstr_info && compno == 0) { OPJ_UINT32 l_data_size = l_tccp->numresolutions * sizeof(OPJ_UINT32); + + p_j2k->cstr_info->tile[p_j2k->m_current_tile_number].tccp_info[compno].cblkh = l_tccp->cblkh; + p_j2k->cstr_info->tile[p_j2k->m_current_tile_number].tccp_info[compno].cblkw = l_tccp->cblkw; + p_j2k->cstr_info->tile[p_j2k->m_current_tile_number].tccp_info[compno].numresolutions = l_tccp->numresolutions; + p_j2k->cstr_info->tile[p_j2k->m_current_tile_number].tccp_info[compno].cblksty = l_tccp->cblksty; + p_j2k->cstr_info->tile[p_j2k->m_current_tile_number].tccp_info[compno].qmfbid = l_tccp->qmfbid; + + memcpy(p_j2k->cstr_info->tile[p_j2k->m_current_tile_number].pdx,l_tccp->prcw, l_data_size); memcpy(p_j2k->cstr_info->tile[p_j2k->m_current_tile_number].pdy,l_tccp->prch, l_data_size); } @@ -6031,7 +6152,7 @@ void j2k_copy_tile_component_parameters( opj_j2k_v2_t *p_j2k ) opj_tccp_t *l_ref_tccp = NULL, *l_copied_tccp = NULL; OPJ_UINT32 l_prc_size; - // preconditions + /* preconditions */ assert(p_j2k != 00); l_cp = &(p_j2k->m_cp); diff --git a/libopenjpeg/j2k.h b/libopenjpeg/j2k.h index 0835e09a..e2d8429b 100644 --- a/libopenjpeg/j2k.h +++ b/libopenjpeg/j2k.h @@ -767,7 +767,7 @@ typedef struct opj_j2k_v2 struct opj_procedure_list * m_validation_list; /** helper used to write the index file */ - opj_codestream_info_t *cstr_info; + opj_codestream_info_v2_t *cstr_info; /** the current tile coder/decoder **/ struct opj_tcd_v2 * m_tcd; @@ -884,8 +884,7 @@ opj_bool j2k_end_decompress(opj_j2k_v2_t *j2k, struct opj_stream_private *cio, s */ opj_bool j2k_read_header( struct opj_stream_private *p_stream, opj_j2k_v2_t* p_j2k, - struct opj_image_header** image_header, - struct opj_codestream_info** cstr_info, + opj_file_info_t * p_file_info, struct opj_event_mgr* p_manager ); diff --git a/libopenjpeg/jp2.c b/libopenjpeg/jp2.c index 14e8c585..efbf8d10 100644 --- a/libopenjpeg/jp2.c +++ b/libopenjpeg/jp2.c @@ -2389,8 +2389,7 @@ static opj_bool jp2_read_boxhdr_char( */ opj_bool jp2_read_header( struct opj_stream_private *p_stream, opj_jp2_v2_t *jp2, - opj_image_header_t ** p_image_header, - struct opj_codestream_info** p_cstr_info, + opj_file_info_t * p_file_info, struct opj_event_mgr * p_manager ) { @@ -2417,8 +2416,7 @@ opj_bool jp2_read_header( struct opj_stream_private *p_stream, return j2k_read_header( p_stream, jp2->j2k, - p_image_header, - p_cstr_info, + p_file_info, p_manager); } diff --git a/libopenjpeg/jp2.h b/libopenjpeg/jp2.h index b0a60086..0203fd12 100644 --- a/libopenjpeg/jp2.h +++ b/libopenjpeg/jp2.h @@ -334,8 +334,7 @@ opj_bool jp2_end_decompress(opj_jp2_v2_t *jp2, struct opj_stream_private *cio, s */ opj_bool jp2_read_header( struct opj_stream_private *p_stream, opj_jp2_v2_t *jp2, - opj_image_header_t ** p_image_header, - struct opj_codestream_info** p_cstr_info, + opj_file_info_t * p_file_info, struct opj_event_mgr * p_manager ); diff --git a/libopenjpeg/openjpeg.c b/libopenjpeg/openjpeg.c index 707a2066..5b99d4d1 100644 --- a/libopenjpeg/openjpeg.c +++ b/libopenjpeg/openjpeg.c @@ -33,32 +33,44 @@ typedef struct opj_decompression { - opj_bool (* opj_read_header) ( - struct opj_stream_private * cio, - void * p_codec, - opj_image_header_t ** image_header, - opj_codestream_info_t ** cstr_info, - struct opj_event_mgr * p_manager); - opj_image_t* (* opj_decode) (void * p_codec, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager); - opj_bool (*opj_read_tile_header)( - void * p_codec, - OPJ_UINT32 * p_tile_index, - OPJ_UINT32* p_data_size, - OPJ_INT32 * p_tile_x0, - OPJ_INT32 * p_tile_y0, - OPJ_INT32 * p_tile_x1, - OPJ_INT32 * p_tile_y1, - OPJ_UINT32 * p_nb_comps, - opj_bool * p_should_go_on, - struct opj_stream_private *p_cio, - struct opj_event_mgr * p_manager); - opj_bool (*opj_decode_tile_data)(void * p_codec,OPJ_UINT32 p_tile_index,OPJ_BYTE * p_data,OPJ_UINT32 p_data_size,struct opj_stream_private *p_cio,struct opj_event_mgr * p_manager); - opj_bool (* opj_end_decompress) (void *p_codec,struct opj_stream_private *cio,struct opj_event_mgr * p_manager); + opj_bool (* opj_read_header) ( struct opj_stream_private * cio, + void * p_codec, + opj_file_info_t * file_info, + struct opj_event_mgr * p_manager); + + opj_image_t* (* opj_decode) ( void * p_codec, + struct opj_stream_private *p_cio, + struct opj_event_mgr * p_manager); + + opj_bool (*opj_read_tile_header)( void * p_codec, + OPJ_UINT32 * p_tile_index, + OPJ_UINT32* p_data_size, + OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0, + OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1, + OPJ_UINT32 * p_nb_comps, + opj_bool * p_should_go_on, + struct opj_stream_private *p_cio, + struct opj_event_mgr * p_manager); + + opj_bool (*opj_decode_tile_data)( void * p_codec, + OPJ_UINT32 p_tile_index, + OPJ_BYTE * p_data, + OPJ_UINT32 p_data_size, + struct opj_stream_private *p_cio, + struct opj_event_mgr * p_manager); + + opj_bool (* opj_end_decompress) ( void *p_codec, + struct opj_stream_private *cio, + struct opj_event_mgr * p_manager); + void (* opj_destroy) (void * p_codec); - void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param); - opj_bool (*opj_set_decode_area) (void * p_codec,OPJ_INT32 p_start_x,OPJ_INT32 p_end_x,OPJ_INT32 p_start_y,OPJ_INT32 p_end_y,struct opj_event_mgr * p_manager); + void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param); + opj_bool (*opj_set_decode_area) ( void * p_codec, + OPJ_INT32 p_start_x, OPJ_INT32 p_end_x, + OPJ_INT32 p_start_y, OPJ_INT32 p_end_y, + struct opj_event_mgr * p_manager); }opj_decompression_t; typedef struct opj_compression @@ -74,10 +86,10 @@ typedef struct opj_compression typedef struct opj_codec_private { - union - { /* code-blocks informations */ - opj_decompression_t m_decompression; - opj_compression_t m_compression; + /* code-blocks informations */ + union { + opj_decompression_t m_decompression; + opj_compression_t m_compression; } m_codec_data; void * m_codec; opj_event_mgr_t* m_event_mgr; @@ -118,21 +130,19 @@ OPJ_UINT32 opj_write_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p OPJ_SIZE_T opj_skip_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data) { - if - (fseek(p_user_data,p_nb_bytes,SEEK_CUR)) - { + if (fseek(p_user_data,p_nb_bytes,SEEK_CUR)) { return -1; } + return p_nb_bytes; } opj_bool opj_seek_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data) { - if - (fseek(p_user_data,p_nb_bytes,SEEK_SET)) - { + if (fseek(p_user_data,p_nb_bytes,SEEK_SET)) { return EXIT_FAILURE; } + return EXIT_SUCCESS; } @@ -214,30 +224,39 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format) switch (p_format) { case CODEC_J2K: - l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_decode; // TODO MSD - l_info->m_codec_data.m_decompression.opj_end_decompress = (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *))j2k_end_decompress; - l_info->m_codec_data.m_decompression.opj_read_header = (opj_bool (*) ( - struct opj_stream_private *, - void *, - opj_image_header_t **, - opj_codestream_info_t**, - struct opj_event_mgr * )) j2k_read_header; + l_info->m_codec_data.m_decompression.opj_decode = + (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_decode; // TODO MSD + + l_info->m_codec_data.m_decompression.opj_end_decompress = + (opj_bool (*) (void *, struct opj_stream_private *, struct opj_event_mgr *))j2k_end_decompress; + + l_info->m_codec_data.m_decompression.opj_read_header = + (opj_bool (*) ( struct opj_stream_private *, + void *, + opj_file_info_t *, + struct opj_event_mgr * )) j2k_read_header; + l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))j2k_destroy; - l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) j2k_setup_decoder_v2; - l_info->m_codec_data.m_decompression.opj_read_tile_header = (opj_bool (*) ( - void *, - OPJ_UINT32*, - OPJ_UINT32*, - OPJ_INT32 * , - OPJ_INT32 * , - OPJ_INT32 * , - OPJ_INT32 * , - OPJ_UINT32 * , - opj_bool *, - struct opj_stream_private *, - struct opj_event_mgr * )) j2k_read_tile_header; - l_info->m_codec_data.m_decompression.opj_decode_tile_data = (opj_bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *, struct opj_event_mgr * )) j2k_decode_tile; - l_info->m_codec_data.m_decompression.opj_set_decode_area = (opj_bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) j2k_set_decode_area; + + l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * , opj_dparameters_t * )) j2k_setup_decoder_v2; + + l_info->m_codec_data.m_decompression.opj_read_tile_header = + (opj_bool (*) ( void *, + OPJ_UINT32*, + OPJ_UINT32*, + OPJ_INT32*, OPJ_INT32*, + OPJ_INT32*, OPJ_INT32*, + OPJ_UINT32*, + opj_bool*, + struct opj_stream_private *, + struct opj_event_mgr * )) j2k_read_tile_header; + + l_info->m_codec_data.m_decompression.opj_decode_tile_data = + (opj_bool (*) (void *, OPJ_UINT32, OPJ_BYTE*, OPJ_UINT32, struct opj_stream_private *, struct opj_event_mgr *)) j2k_decode_tile; + + l_info->m_codec_data.m_decompression.opj_set_decode_area = + (opj_bool (*) (void *, OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, struct opj_event_mgr *)) j2k_set_decode_area; + l_info->m_codec = j2k_create_decompress_v2(); if (! l_info->m_codec) { @@ -250,16 +269,16 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format) case CODEC_JP2: /* get a JP2 decoder handle */ l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))opj_jp2_decode; // TODO MSD + l_info->m_codec_data.m_decompression.opj_end_decompress = (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *)) jp2_end_decompress; + l_info->m_codec_data.m_decompression.opj_read_header = (opj_bool (*) ( struct opj_stream_private *, void *, - opj_image_header_t **, - opj_codestream_info_t**, + opj_file_info_t *, struct opj_event_mgr * )) jp2_read_header; - l_info->m_codec_data.m_decompression.opj_read_tile_header = ( - opj_bool (*) ( + l_info->m_codec_data.m_decompression.opj_read_tile_header = ( opj_bool (*) ( void *, OPJ_UINT32*, OPJ_UINT32*, @@ -275,7 +294,9 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format) l_info->m_codec_data.m_decompression.opj_decode_tile_data = (opj_bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *, struct opj_event_mgr * )) opj_jp2_decode_tile; l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))jp2_destroy; + l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) jp2_setup_decoder_v2; + l_info->m_codec_data.m_decompression.opj_set_decode_area = (opj_bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) jp2_set_decode_area; l_info->m_codec = jp2_create(OPJ_TRUE); @@ -473,7 +494,7 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *paramete parameters->cod_format = -1; parameters->tcp_rates[0] = 0; parameters->tcp_numlayers = 0; - parameters->cp_disto_alloc = 0; + parameters->cp_disto_alloc = 0; parameters->cp_fixed_alloc = 0; parameters->cp_fixed_quality = 0; parameters->jpip_on = OPJ_FALSE; @@ -602,6 +623,8 @@ void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) { } } + + #ifdef OLD_WAY_MS opj_bool OPJ_CALLCONV opj_read_header ( opj_codec_t *p_codec, @@ -640,10 +663,13 @@ opj_bool OPJ_CALLCONV opj_read_header ( opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio, opj_codec_t *p_codec, - opj_image_header_t **p_image_header, - opj_codestream_info_t **p_cstr_info ) + opj_file_info_t* p_file_info, + OPJ_INT32 file_info_flag) { + /* Initialize the output structure */ + opj_initialise_file_info(p_file_info, file_info_flag, CODEC_J2K); + if (p_codec && p_cio) { opj_codec_private_t* l_info = (opj_codec_private_t*) p_codec; opj_stream_private_t* l_cio = (opj_stream_private_t*) p_cio; @@ -655,8 +681,7 @@ opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio, return l_info->m_codec_data.m_decompression.opj_read_header( l_cio, l_info->m_codec, - p_image_header, - p_cstr_info, + p_file_info, l_info->m_event_mgr); } return OPJ_FALSE; @@ -682,3 +707,37 @@ void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_info) opj_free(l_info); } } + +/** + * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading. + * + * @param p_codec the jpeg2000 codec. + * @param p_start_x the left position of the rectangle to decode (in image coordinates). + * @param p_end_x the right position of the rectangle to decode (in image coordinates). + * @param p_start_y the up position of the rectangle to decode (in image coordinates). + * @param p_end_y the bottom position of the rectangle to decode (in image coordinates). + * + * @return true if the area could be set. + */ +opj_bool OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec, + OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, + OPJ_INT32 p_end_x, OPJ_INT32 p_end_y + ) +{ + if (p_codec) { + opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec; + if (! l_info->is_decompressor) { + return OPJ_FALSE; + } + + return l_info->m_codec_data.m_decompression.opj_set_decode_area( + l_info->m_codec, + p_start_x, + p_start_y, + p_end_x, + p_end_y, + &(l_info->m_event_mgr)); + + } + return OPJ_FALSE; +} diff --git a/libopenjpeg/openjpeg.h b/libopenjpeg/openjpeg.h index a94f3a47..94fbdfa5 100644 --- a/libopenjpeg/openjpeg.h +++ b/libopenjpeg/openjpeg.h @@ -105,6 +105,15 @@ typedef float OPJ_FLOAT32; #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */ /* <<UniPG */ +/** +Supported options about file information +*/ +#define OPJ_NO_INFO 0x0 /**< No information provied to the user */ +#define OPJ_IMG_INFO 0x1 /**< Basic image information provided to the user */ +#define OPJ_J2K_INFO 0x2 /**< J2K codestream information provided to the user */ +#define OPJ_JP2_INFO 0x4 /**< JP2 file information provided to the user */ + + /* ========================================================== enum definitions @@ -171,6 +180,9 @@ typedef enum LIMIT_DECODING { DECODE_ALL_BUT_PACKETS = 2 /**< Decode everything except the JPEG 2000 packets */ } OPJ_LIMIT_DECODING; + + + /* ========================================================== event manager typedef definitions @@ -421,6 +433,14 @@ typedef struct opj_dparameters { */ OPJ_LIMIT_DECODING cp_limit_decoding; + + /* V2 */ + OPJ_UINT32 ROI_x0; + OPJ_UINT32 ROI_x1; + OPJ_UINT32 ROI_y0; + OPJ_UINT32 ROI_y1; + + } opj_dparameters_t; /** Common fields between JPEG-2000 compression and decompression master structs. */ @@ -649,6 +669,7 @@ typedef struct opj_image_header { /** image components */ opj_image_comp_header_t *comps; +#ifdef TODO_MSD /** XTOsiz */ OPJ_UINT32 tile_x0; /** YTOsiz */ @@ -661,6 +682,7 @@ typedef struct opj_image_header { OPJ_UINT32 nb_tiles_x; /** number of tiles in height */ OPJ_UINT32 nb_tiles_y; +#endif /** 'restricted' ICC profile */ unsigned char *icc_profile_buf; @@ -814,9 +836,43 @@ typedef struct opj_codestream_info { // NEW codestream +/** +Tile-component coding parameters +*/ +typedef struct opj_tccp_info +{ + /** component index */ + OPJ_UINT32 compno; + /** coding style */ + OPJ_UINT32 csty; + /** number of resolutions */ + OPJ_UINT32 numresolutions; + /** code-blocks width */ + OPJ_UINT32 cblkw; + /** code-blocks height */ + OPJ_UINT32 cblkh; + /** code-block coding style */ + OPJ_UINT32 cblksty; + /** discrete wavelet transform identifier */ + OPJ_UINT32 qmfbid; + /** quantisation style */ + OPJ_UINT32 qntsty; + /** stepsizes used for quantization */ + //FIXME opj_stepsize_t stepsizes[J2K_MAXBANDS]; + /** number of guard bits */ + OPJ_UINT32 numgbits; + /** Region Of Interest shift */ + OPJ_INT32 roishift; + /** precinct width */ + OPJ_UINT32 prcw[J2K_MAXRLVLS]; + /** precinct height */ + OPJ_UINT32 prch[J2K_MAXRLVLS]; +} +opj_tccp_info_t; + typedef struct opj_tile_v2_info { - /** number of tile */ + /** number (index) of tile */ int tileno; /** start position */ @@ -831,6 +887,17 @@ typedef struct opj_tile_v2_info { /** add fixed_quality */ double distotile; + /** coding style */ + OPJ_UINT32 csty; + /** progression order */ + OPJ_PROG_ORDER prg; + /** number of layers */ + OPJ_UINT32 numlayers; + /** multi-component transform identifier */ + OPJ_UINT32 mct; + /** rates of layers */ + OPJ_FLOAT32 rates[100]; + /** precinct number for each resolution level (width) */ int pw[33]; /** precinct number for each resolution level (height) */ @@ -848,14 +915,18 @@ typedef struct opj_tile_v2_info { /** information concerning tile parts */ opj_tp_info_t *tp; + /** information concerning tile component parameters*/ + opj_tccp_info_t *tccp_info; + /** value of thresh for each layer by tile cfr. Marcela */ - double *thresh; + double *thresh; } opj_tile_info_v2_t; /** Index structure of the codestream */ -typedef struct opj_codestream_v2_info { +typedef struct opj_codestream_info_v2 { + /* Basic image info */ /** image width */ int image_w; /** image height */ @@ -863,14 +934,15 @@ typedef struct opj_codestream_v2_info { /** numbers of component */ int numcomps; + /* Codestream Info */ /** progression order */ OPJ_PROG_ORDER prog; /** number of layer */ int numlayers; - /** */ + /** tile origin in x */ int tx0; - /** */ + /** tile origin in y */ int ty0; /** tile size in x */ int tdx; @@ -913,6 +985,47 @@ typedef struct opj_codestream_v2_info { opj_tile_info_v2_t *tile; } opj_codestream_info_v2_t; + +/* +========================================================== + Metadata from the JP2file +========================================================== +*/ + +/** +Info structure of the file +*/ +typedef struct opj_jp2_metadata { + /** */ + OPJ_INT32 empty_fields; + +} opj_jp2_metadata_t; + +/* +========================================================== + Information on the JPEG2000 file +========================================================== +*/ + +/** +Info structure of the file +*/ +typedef struct opj_file_info { + /** file format */ + OPJ_INT32 file_format; + /** file info level*/ + OPJ_INT32 file_info_flag; + /** image info*/ + opj_image_header_t img_info; + /** codestream info */ + opj_codestream_info_v2_t codestream_info; + /** file info */ + opj_jp2_metadata_t jp2_metadata; + +} opj_file_info_t; + + + #ifdef __cplusplus extern "C" { #endif @@ -1198,8 +1311,8 @@ OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info */ OPJ_API opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio, opj_codec_t *p_codec, - opj_image_header_t **p_image_header, - opj_codestream_info_t **p_cstr_info ); + opj_file_info_t * p_file_info, + OPJ_INT32 file_info_flag); /** Destroy a decompressor handle @@ -1207,8 +1320,25 @@ Destroy a decompressor handle */ OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec); +/** + * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading. + * + * @param p_codec the jpeg2000 codec. + * @param p_start_x the left position of the rectangle to decode (in image coordinates). + * @param p_end_x the right position of the rectangle to decode (in image coordinates). + * @param p_start_y the up position of the rectangle to decode (in image coordinates). + * @param p_end_y the bottom position of the rectangle to decode (in image coordinates). + * + * @return true if the area could be set. + */ +OPJ_API opj_bool OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec, + OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, + OPJ_INT32 p_end_x, OPJ_INT32 p_end_y ); + #ifdef __cplusplus } #endif #endif /* OPENJPEG_H */ + + diff --git a/libopenjpeg/t2.c b/libopenjpeg/t2.c index 90fbf90d..e9f08abb 100644 --- a/libopenjpeg/t2.c +++ b/libopenjpeg/t2.c @@ -841,7 +841,7 @@ opj_bool t2_decode_packets_v2( OPJ_BYTE *p_src, OPJ_UINT32 * p_data_read, OPJ_UINT32 p_max_len, - struct opj_codestream_info *p_cstr_info) + struct opj_codestream_info_v2 *p_cstr_info) { OPJ_BYTE *l_current_data = p_src; opj_pi_iterator_t *l_pi = 00; @@ -901,7 +901,7 @@ opj_bool t2_decode_packets_v2( /* INDEX >> */ if(p_cstr_info) { - opj_tile_info_t *info_TL = &p_cstr_info->tile[p_tile_no]; + opj_tile_info_v2_t *info_TL = &p_cstr_info->tile[p_tile_no]; opj_packet_info_t *info_PK = &info_TL->packet[p_cstr_info->packno]; if (!p_cstr_info->packno) { info_PK->start_pos = info_TL->end_header + 1; diff --git a/libopenjpeg/t2.h b/libopenjpeg/t2.h index b130746f..55cac98f 100644 --- a/libopenjpeg/t2.h +++ b/libopenjpeg/t2.h @@ -104,7 +104,12 @@ Decode the packets of a tile from a source buffer @param tileno number that identifies the tile for which to decode the packets @param tile tile for which to decode the packets */ -opj_bool t2_decode_packets_v2(opj_t2_v2_t *t2, OPJ_UINT32 tileno,struct opj_tcd_tile *tile, OPJ_BYTE *src, OPJ_UINT32 * p_data_read, OPJ_UINT32 len, struct opj_codestream_info *cstr_info); +opj_bool t2_decode_packets_v2( opj_t2_v2_t *t2, + OPJ_UINT32 tileno, + struct opj_tcd_tile *tile, + OPJ_BYTE *src, OPJ_UINT32 * p_data_read, + OPJ_UINT32 len, + struct opj_codestream_info_v2 *cstr_info); /** * Creates a Tier 2 handle diff --git a/libopenjpeg/tcd.c b/libopenjpeg/tcd.c index 1eeba002..9d8dc782 100644 --- a/libopenjpeg/tcd.c +++ b/libopenjpeg/tcd.c @@ -107,7 +107,7 @@ opj_bool tcd_t2_decode ( OPJ_BYTE * p_src_data, OPJ_UINT32 * p_data_read, OPJ_UINT32 p_max_src_size, - opj_codestream_info_t *p_cstr_info + opj_codestream_info_v2_t *p_cstr_info ); opj_bool tcd_t1_decode ( @@ -2046,7 +2046,7 @@ opj_bool tcd_decode_tile_v2( OPJ_BYTE *p_src, OPJ_UINT32 p_max_length, OPJ_UINT32 p_tile_no, - opj_codestream_info_t *p_cstr_info) + opj_codestream_info_v2_t *p_cstr_info) { OPJ_UINT32 l_data_read; p_tcd->tcd_tileno = p_tile_no; @@ -2077,7 +2077,7 @@ opj_bool tcd_decode_tile_v2( // FIXME _ProfStart(PGROUP_T2); l_data_read = 0; if - (! tcd_t2_decode(p_tcd,p_src,&l_data_read,p_max_length,p_cstr_info)) + (! tcd_t2_decode(p_tcd, p_src, &l_data_read, p_max_length, p_cstr_info)) { return OPJ_FALSE; } @@ -2396,7 +2396,7 @@ opj_bool tcd_t2_decode ( OPJ_BYTE * p_src_data, OPJ_UINT32 * p_data_read, OPJ_UINT32 p_max_src_size, - opj_codestream_info_t *p_cstr_info + opj_codestream_info_v2_t *p_cstr_info ) { opj_t2_v2_t * l_t2; diff --git a/libopenjpeg/tcd.h b/libopenjpeg/tcd.h index 09c184ac..c3c416c6 100644 --- a/libopenjpeg/tcd.h +++ b/libopenjpeg/tcd.h @@ -436,7 +436,11 @@ Decode a tile from a buffer into a raw image @param len Length of source buffer @param tileno Number that identifies one of the tiles to be decoded */ -opj_bool tcd_decode_tile_v2(opj_tcd_v2_t *tcd, OPJ_BYTE *src, OPJ_UINT32 len, OPJ_UINT32 tileno, struct opj_codestream_info *cstr_info); +opj_bool tcd_decode_tile_v2(opj_tcd_v2_t *tcd, + OPJ_BYTE *src, + OPJ_UINT32 len, + OPJ_UINT32 tileno, + struct opj_codestream_info_v2 *cstr_info); /** |
