WIP: create a new framework to output file information

This commit is contained in:
Mickael Savinaud 2011-09-19 16:01:49 +00:00
parent cf37058d7c
commit d44375aece
15 changed files with 611 additions and 131 deletions

View File

@ -6,6 +6,7 @@ What's New for OpenJPEG
+ : added + : added
September 19, 2011 September 19, 2011
+ [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 + [mickael] WIP: remove a piece of code copy by the merge op at the wrong place
+ [mickael] WIP: begin to clean j2k_dump and some other small things + [mickael] WIP: begin to clean j2k_dump and some other small things
+ [mickael] WIP: enchance the new version with some bug fixes from v1 and from me + [mickael] WIP: enchance the new version with some bug fixes from v1 and from me

View File

@ -742,3 +742,109 @@ int write_index_file_v2(FILE* stream, opj_codestream_info_t *cstr_info) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* ------------------------------------------------------------------------------------ */
/**
Dump the file info structure into a file
@param stream output stream
@param file_info informations read into the JPG2000 file
@return Returns 0 if successful, returns 1 otherwise
*/
int dump_file_info(FILE* stream, opj_file_info_t *file_info)
{
/* IMAGE HEADER */
if ( file_info->file_info_flag & OPJ_IMG_INFO ) {
opj_image_header_t img_header = file_info->img_info;
int compno;
fprintf(stream, "Image info {\n");
fprintf(stream, "\t x0=%d, y0=%d\n",img_header.x0, img_header.y0);
fprintf(stream, "\t x1=%d, y1=%d\n",img_header.x1, img_header.y1);
fprintf(stream, "\t numcomps=%d\n", img_header.numcomps);
for (compno = 0; compno < img_header.numcomps; compno++) {
opj_image_comp_header_t comp = img_header.comps[compno];
fprintf(stream, "\t component %d {\n", compno);
fprintf(stream, "\t\t dx=%d, dy=%d\n", comp.dx, comp.dy);
fprintf(stream, "\t\t prec=%d\n", comp.prec);
fprintf(stream, "\t\t sgnd=%d\n", comp.sgnd);
fprintf(stream, "\t}\n");
}
fprintf(stream, "}\n");
}
/* CODESTREAM INFO */
if ( file_info->file_info_flag & OPJ_J2K_INFO ) {
opj_codestream_info_v2_t cstr_info = file_info->codestream_info;
int tileno, compno, layno, bandno, resno, numbands;
fprintf(stream, "Codestream info {\n");
fprintf(stream, "\t tx0=%d, ty0=%d\n", cstr_info.tx0, cstr_info.ty0);
fprintf(stream, "\t tdx=%d, tdy=%d\n", cstr_info.tdx, cstr_info.tdy);
fprintf(stream, "\t tw=%d, th=%d\n", cstr_info.tw, cstr_info.th);
for (tileno = 0; tileno < cstr_info.tw * cstr_info.th; tileno++) {
opj_tile_info_v2_t tile_info = cstr_info.tile[tileno];
fprintf(stream, "\t tile %d {\n", tileno);
fprintf(stream, "\t\t csty=%x\n", tile_info.csty);
fprintf(stream, "\t\t prg=%d\n", tile_info.prg);
fprintf(stream, "\t\t numlayers=%d\n", tile_info.numlayers);
fprintf(stream, "\t\t mct=%d\n", tile_info.mct);
fprintf(stream, "\t\t rates=");
for (layno = 0; layno < tile_info.numlayers; layno++) {
fprintf(stream, "%.1f ", tile_info.rates[layno]);
}
fprintf(stream, "\n");
for (compno = 0; compno < cstr_info.numcomps; compno++) {
opj_tccp_info_t tccp_info = tile_info.tccp_info[compno];
fprintf(stream, "\t\t comp %d {\n", compno);
fprintf(stream, "\t\t\t csty=%x\n", tccp_info.csty);
fprintf(stream, "\t\t\t numresolutions=%d\n", tccp_info.numresolutions);
fprintf(stream, "\t\t\t cblkw=%d\n", tccp_info.cblkw);
fprintf(stream, "\t\t\t cblkh=%d\n", tccp_info.cblkh);
fprintf(stream, "\t\t\t cblksty=%x\n", tccp_info.cblksty);
fprintf(stream, "\t\t\t qmfbid=%d\n", tccp_info.qmfbid);
fprintf(stream, "\t\t\t qntsty=%d\n", tccp_info.qntsty);
fprintf(stream, "\t\t\t numgbits=%d\n", tccp_info.numgbits);
fprintf(stream, "\t\t\t roishift=%d\n", tccp_info.roishift);
#ifdef TODO_MSD
fprintf(stream, "\t\t\t stepsizes=");
numbands = tccp_info->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : tccp_info->numresolutions * 3 - 2;
for (bandno = 0; bandno < numbands; bandno++) {
fprintf(stream, "(%d,%d) ", tccp_info->stepsizes[bandno].mant,
tccp_info->stepsizes[bandno].expn);
}
fprintf(stream, "\n");
if (tccp_info->csty & J2K_CCP_CSTY_PRT) {
fprintf(stream, " prcw=");
for (resno = 0; resno < tccp_info->numresolutions; resno++) {
fprintf(stream, "%d ", tccp_info->prcw[resno]);
}
fprintf(stream, "\n");
fprintf(stream, " prch=");
for (resno = 0; resno < tccp_info->numresolutions; resno++) {
fprintf(stream, "%d ", tccp_info->prch[resno]);
}
fprintf(stream, "\n");
}
#endif
fprintf(stream, "\t\t\t }\n");
} /*end of component*/
fprintf(stream, "\t\t }\n");
} /*end of tile */
fprintf(stream, "\t }\n");
}
if ( file_info->file_info_flag & OPJ_JP2_INFO ) {
// not yet coded
}
return EXIT_SUCCESS;
}

View File

@ -41,6 +41,8 @@ Write a structured index to a file
*/ */
int write_index_file(opj_codestream_info_t *cstr_info, char *index); int write_index_file(opj_codestream_info_t *cstr_info, char *index);
int dump_file_info(FILE* stream, opj_file_info_t *file_info);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -201,7 +201,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
opj_option_t long_option[]={ opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'}, {"ImgDir",REQ_ARG, NULL ,'y'},
}; };
const char optlist[] = "i:o:h"; const char optlist[] = "i:o:d:h";
totlen=sizeof(long_option); totlen=sizeof(long_option);
img_fol->set_out_format = 0; img_fol->set_out_format = 0;
@ -257,7 +257,19 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'd': /* Input decode ROI */
{
int size_optarg = (int)strlen(optarg) + 1;
char *ROI_values = (char*) malloc(size_optarg);
ROI_values[0] = '\0';
strncpy(ROI_values, optarg, strlen(optarg));
ROI_values[strlen(optarg)] = '\0';
printf("ROI_values = %s [%d / %d]\n", ROI_values, strlen(ROI_values), size_optarg );
parse_ROI_values( ROI_values, &parameters->ROI_x0, &parameters->ROI_y0, &parameters->ROI_x1, &parameters->ROI_y1);
}
break;
/* ----------------------------------------------------- */
default: default:
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg); fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
break; break;
@ -290,6 +302,34 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
return 0; return 0;
} }
/*******************************************************************************
* Parse ROI input values
* separator = ","
*******************************************************************************/
int parse_ROI_values( char* inArg, unsigned int *ROI_x0, unsigned int *ROI_y0, unsigned int *ROI_x1, unsigned int *ROI_y1)
{
int it = 0;
int values[4];
char delims[] = ",";
char *result = NULL;
result = strtok( inArg, delims );
while( (result != NULL) && (it < 4 ) ) {
values[it] = atoi(result);
result = strtok( NULL, delims );
it++;
}
if (it != 4) {
return EXIT_FAILURE;
}
else{
*ROI_x0 = values[0]; *ROI_y0 = values[1];
*ROI_x1 = values[2]; *ROI_y1 = values[3];
return EXIT_SUCCESS;
}
}
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/** /**
@ -323,6 +363,7 @@ int main(int argc, char *argv[])
img_fol_t img_fol; img_fol_t img_fol;
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
opj_image_header_t* image = NULL; opj_image_header_t* image = NULL;
opj_file_info_t file_info;
FILE *fsrc = NULL, *fout = NULL; FILE *fsrc = NULL, *fout = NULL;
int num_images; int num_images;
int i,imageno; int i,imageno;
@ -394,7 +435,7 @@ int main(int argc, char *argv[])
/* Read the header of each image one by one */ /* Read the header of each image one by one */
for(imageno = 0; imageno < num_images ; imageno++){ for(imageno = 0; imageno < num_images ; imageno++){
image = NULL;
fprintf(stderr,"\n"); fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1){
@ -404,7 +445,6 @@ int main(int argc, char *argv[])
} }
} }
/*NEW V2 STYLE*/
/* read the input file and put it in memory */ /* read the input file and put it in memory */
/* ---------------------------------------- */ /* ---------------------------------------- */
fsrc = fopen(parameters.infile, "rb"); fsrc = fopen(parameters.infile, "rb");
@ -414,6 +454,10 @@ int main(int argc, char *argv[])
} }
cio = opj_stream_create_default_file_stream(fsrc,1); cio = opj_stream_create_default_file_stream(fsrc,1);
if (!cio){
fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
return EXIT_FAILURE;
}
/* decode the code-stream */ /* decode the code-stream */
/* ---------------------- */ /* ---------------------- */
@ -449,7 +493,7 @@ int main(int argc, char *argv[])
/* setup the decoder decoding parameters using user parameters */ /* setup the decoder decoding parameters using user parameters */
opj_setup_decoder_v2(dinfo, &parameters, &event_mgr); opj_setup_decoder_v2(dinfo, &parameters, &event_mgr);
if(! opj_read_header(cio, dinfo, &image, &cstr_info)){ if(! opj_read_header(cio, dinfo, &file_info, OPJ_IMG_INFO | OPJ_J2K_INFO)){
fprintf(stderr, "ERROR -> j2k_dump: failed to read the header\n"); fprintf(stderr, "ERROR -> j2k_dump: failed to read the header\n");
opj_stream_destroy(cio); opj_stream_destroy(cio);
fclose(fsrc); fclose(fsrc);
@ -457,8 +501,14 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/* Dump file informations from header */ printf("Setting decoding area to %d,%d,%d,%d\n",
parameters.ROI_x0, parameters.ROI_y0, parameters.ROI_x1, parameters.ROI_x1);
opj_set_decode_area(dinfo,
parameters.ROI_x0, parameters.ROI_y0,
parameters.ROI_x1, parameters.ROI_x1);
/* Dump file informations from header */
dump_file_info(fout, &file_info);
/* close the byte stream */ /* close the byte stream */
opj_stream_destroy(cio); opj_stream_destroy(cio);
@ -471,9 +521,10 @@ int main(int argc, char *argv[])
opj_image_header_destroy(image); opj_image_header_destroy(image);
//FIXME opj_file_info_destroy(file_info);
} }
/*NEW V2 STYLE*/
/* Close the output file */ /* Close the output file */
fclose(fout); fclose(fout);
@ -496,8 +547,8 @@ static void j2k_dump_image(FILE *fd, opj_image_header_t * img) {
fprintf(fd, " sgnd=%d\n", comp->sgnd); fprintf(fd, " sgnd=%d\n", comp->sgnd);
fprintf(fd, " }\n"); fprintf(fd, " }\n");
} }
fprintf(fd, " XTOsiz=%d, YTOsiz=%d, XTsiz=%d, YTsiz=%d\n", img->tile_x0, img->tile_y0, img->tile_width, img->tile_height); //fprintf(fd, " XTOsiz=%d, YTOsiz=%d, XTsiz=%d, YTsiz=%d\n", img->tile_x0, img->tile_y0, img->tile_width, img->tile_height);
fprintf(fd, " Nb of tiles in x direction=%d, Nb of tiles in y direction=%d\n", img->nb_tiles_x, img->nb_tiles_y); //fprintf(fd, " Nb of tiles in x direction=%d, Nb of tiles in y direction=%d\n", img->nb_tiles_x, img->nb_tiles_y);
fprintf(fd, "}\n"); fprintf(fd, "}\n");
} }

View File

@ -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;
}

View File

@ -1476,23 +1476,34 @@ opj_bool j2k_read_siz_v2 (
/* Index */ /* Index */
if (p_j2k->cstr_info) { 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_w = l_image->x1 - l_image->x0;
p_j2k->cstr_info->image_h = l_image->y1 - l_image->y0; p_j2k->cstr_info->image_h = l_image->y1 - l_image->y0;
p_j2k->cstr_info->numcomps = l_image->numcomps; p_j2k->cstr_info->numcomps = l_image->numcomps;
p_j2k->cstr_info->tw = l_cp->tw; p_j2k->cstr_info->tw = l_cp->tw;
p_j2k->cstr_info->th = l_cp->th; p_j2k->cstr_info->th = l_cp->th;
p_j2k->cstr_info->tile_x = l_cp->tdx; p_j2k->cstr_info->tdx = l_cp->tdx;
p_j2k->cstr_info->tile_y = l_cp->tdy; p_j2k->cstr_info->tdy = l_cp->tdy;
p_j2k->cstr_info->tile_Ox = l_cp->tx0; p_j2k->cstr_info->tx0 = l_cp->tx0;
p_j2k->cstr_info->tile_Oy = l_cp->ty0; p_j2k->cstr_info->ty0 = 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) { p_j2k->cstr_info->tile = (opj_tile_info_v2_t*) opj_calloc(l_nb_tiles, sizeof(opj_tile_info_v2_t));
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n"); if (! p_j2k->cstr_info->tile) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory [SIZ marker]\n");
return OPJ_FALSE; 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; return OPJ_TRUE;
} }
@ -1706,20 +1717,20 @@ opj_bool j2k_read_cod_v2 (
opj_tcp_v2_t *l_tcp = 00; opj_tcp_v2_t *l_tcp = 00;
opj_image_header_t *l_image = 00; opj_image_header_t *l_image = 00;
// preconditions /* preconditions */
assert(p_header_data != 00); assert(p_header_data != 00);
assert(p_j2k != 00); assert(p_j2k != 00);
assert(p_manager != 00); assert(p_manager != 00);
l_image = p_j2k->m_image_header; l_image = p_j2k->m_image_header;
l_cp = &(p_j2k->m_cp); 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_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] : &l_cp->tcps[p_j2k->m_current_tile_number] :
p_j2k->m_specific_param.m_decoder.m_default_tcp; 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) { if (p_header_size < 5) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading COD marker\n"); opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading COD marker\n");
return OPJ_FALSE; return OPJ_FALSE;
@ -3505,7 +3516,7 @@ opj_bool j2k_read_sod_v2 (
) )
{ {
OPJ_UINT32 l_current_read_size; 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_BYTE ** l_current_data = 00;
opj_tcp_v2_t * l_tcp = 00; opj_tcp_v2_t * l_tcp = 00;
OPJ_UINT32 * l_tile_len = 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_bool j2k_read_header( struct opj_stream_private *p_stream,
opj_j2k_v2_t* p_j2k, opj_j2k_v2_t* p_j2k,
struct opj_image_header** image_header, opj_file_info_t* p_file_info,
struct opj_codestream_info** cstr_info,
struct opj_event_mgr* p_manager ) struct opj_event_mgr* p_manager )
{ {
// preconditions /* preconditions */
assert(p_j2k != 00); assert(p_j2k != 00);
assert(p_stream != 00); assert(p_stream != 00);
assert(p_manager != 00); assert(p_manager != 00);
//p_image_header = NULL;
/* create an empty image header */ /* create an empty image header */
p_j2k->m_image_header = opj_image_header_create0(); p_j2k->m_image_header = opj_image_header_create0();
if (! p_j2k->m_image_header) { if (! p_j2k->m_image_header) {
@ -4931,19 +4939,121 @@ opj_bool j2k_read_header( struct opj_stream_private *p_stream,
return OPJ_FALSE; 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);
}
*image_header = p_j2k->m_image_header; /* If necessary copy image header information into the output structure */
(*image_header)->tile_x0 = p_j2k->m_cp.tx0; if (p_file_info->file_info_flag & OPJ_IMG_INFO){
(*image_header)->tile_y0 = p_j2k->m_cp.ty0; fill_img_info( &(p_file_info->img_info), p_j2k, p_manager);
(*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; 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. * Sets up the procedures to do on reading header. Developpers wanting to extend the library can add their own reading procedures.
*/ */
@ -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; l_j2k->m_specific_param.m_decoder.m_header_data_size = J2K_DEFAULT_HEADER_SIZE;
// codestream info creation // 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){ if (!l_j2k->cstr_info){
opj_free(l_j2k); opj_free(l_j2k);
return NULL; return NULL;
@ -5936,7 +6046,7 @@ opj_bool j2k_read_SPCod_SPCoc(
opj_tccp_t *l_tccp = NULL; opj_tccp_t *l_tccp = NULL;
OPJ_BYTE * l_current_ptr = NULL; OPJ_BYTE * l_current_ptr = NULL;
// preconditions /* preconditions */
assert(p_j2k != 00); assert(p_j2k != 00);
assert(p_manager != 00); assert(p_manager != 00);
assert(p_header_data != 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] : &l_cp->tcps[p_j2k->m_current_tile_number] :
p_j2k->m_specific_param.m_decoder.m_default_tcp; p_j2k->m_specific_param.m_decoder.m_default_tcp;
// precondition again /* precondition again */
assert(compno < p_j2k->m_image_header->numcomps); assert(compno < p_j2k->m_image_header->numcomps);
l_tccp = &l_tcp->tccps[compno]; l_tccp = &l_tcp->tccps[compno];
l_current_ptr = p_header_data; l_current_ptr = p_header_data;
// make sure room is sufficient /* make sure room is sufficient */
if (*p_header_size < 5) { if (*p_header_size < 5) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading SPCod SPCoc element\n"); opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading SPCod SPCoc element\n");
return OPJ_FALSE; return OPJ_FALSE;
} }
opj_read_bytes(l_current_ptr, &l_tccp->numresolutions ,1); /* SPcox (D) */ opj_read_bytes(l_current_ptr, &l_tccp->numresolutions ,1); /* SPcox (D) */
++l_tccp->numresolutions; /* tccp->numresolutions = read() + 1 */ ++l_tccp->numresolutions; /* tccp->numresolutions = read() + 1 */
++l_current_ptr; ++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) { 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 " 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); "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; *p_header_size = *p_header_size - 5;
// use custom precinct size ? /* use custom precinct size ? */
if (l_tccp->csty & J2K_CCP_CSTY_PRT) { if (l_tccp->csty & J2K_CCP_CSTY_PRT) {
if (*p_header_size < l_tccp->numresolutions) { if (*p_header_size < l_tccp->numresolutions) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading SPCod SPCoc element\n"); opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading SPCod SPCoc element\n");
return OPJ_FALSE; return OPJ_FALSE;
} }
for (i = 0; i < l_tccp->numresolutions; ++i) { for (i = 0; i < l_tccp->numresolutions; ++i) {
opj_read_bytes(l_current_ptr,&l_tmp ,1); /* SPcoc (I_i) */ opj_read_bytes(l_current_ptr,&l_tmp ,1); /* SPcoc (I_i) */
++l_current_ptr; ++l_current_ptr;
l_tccp->prcw[i] = l_tmp & 0xf; l_tccp->prcw[i] = l_tmp & 0xf;
l_tccp->prch[i] = l_tmp >> 4; l_tccp->prch[i] = l_tmp >> 4;
} }
*p_header_size = *p_header_size - l_tccp->numresolutions; *p_header_size = *p_header_size - l_tccp->numresolutions;
} }
else { else {
@ -6010,6 +6123,14 @@ opj_bool j2k_read_SPCod_SPCoc(
/* INDEX >> */ /* INDEX >> */
if (p_j2k->cstr_info && compno == 0) { if (p_j2k->cstr_info && compno == 0) {
OPJ_UINT32 l_data_size = l_tccp->numresolutions * sizeof(OPJ_UINT32); 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].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); 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_tccp_t *l_ref_tccp = NULL, *l_copied_tccp = NULL;
OPJ_UINT32 l_prc_size; OPJ_UINT32 l_prc_size;
// preconditions /* preconditions */
assert(p_j2k != 00); assert(p_j2k != 00);
l_cp = &(p_j2k->m_cp); l_cp = &(p_j2k->m_cp);

View File

@ -767,7 +767,7 @@ typedef struct opj_j2k_v2
struct opj_procedure_list * m_validation_list; struct opj_procedure_list * m_validation_list;
/** helper used to write the index file */ /** 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 **/ /** the current tile coder/decoder **/
struct opj_tcd_v2 * m_tcd; 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_bool j2k_read_header( struct opj_stream_private *p_stream,
opj_j2k_v2_t* p_j2k, opj_j2k_v2_t* p_j2k,
struct opj_image_header** image_header, opj_file_info_t * p_file_info,
struct opj_codestream_info** cstr_info,
struct opj_event_mgr* p_manager ); struct opj_event_mgr* p_manager );

View File

@ -2389,8 +2389,7 @@ static opj_bool jp2_read_boxhdr_char(
*/ */
opj_bool jp2_read_header( struct opj_stream_private *p_stream, opj_bool jp2_read_header( struct opj_stream_private *p_stream,
opj_jp2_v2_t *jp2, opj_jp2_v2_t *jp2,
opj_image_header_t ** p_image_header, opj_file_info_t * p_file_info,
struct opj_codestream_info** p_cstr_info,
struct opj_event_mgr * p_manager 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, return j2k_read_header( p_stream,
jp2->j2k, jp2->j2k,
p_image_header, p_file_info,
p_cstr_info,
p_manager); p_manager);
} }

View File

@ -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_bool jp2_read_header( struct opj_stream_private *p_stream,
opj_jp2_v2_t *jp2, opj_jp2_v2_t *jp2,
opj_image_header_t ** p_image_header, opj_file_info_t * p_file_info,
struct opj_codestream_info** p_cstr_info,
struct opj_event_mgr * p_manager struct opj_event_mgr * p_manager
); );

View File

@ -33,32 +33,44 @@
typedef struct opj_decompression typedef struct opj_decompression
{ {
opj_bool (* opj_read_header) ( opj_bool (* opj_read_header) ( struct opj_stream_private * cio,
struct opj_stream_private * cio,
void * p_codec, void * p_codec,
opj_image_header_t ** image_header, opj_file_info_t * file_info,
opj_codestream_info_t ** cstr_info,
struct opj_event_mgr * p_manager); 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)( opj_image_t* (* opj_decode) ( void * p_codec,
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_tile_index,
OPJ_UINT32* p_data_size, OPJ_UINT32* p_data_size,
OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
OPJ_INT32 * p_tile_y0, OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
OPJ_INT32 * p_tile_x1,
OPJ_INT32 * p_tile_y1,
OPJ_UINT32 * p_nb_comps, OPJ_UINT32 * p_nb_comps,
opj_bool * p_should_go_on, opj_bool * p_should_go_on,
struct opj_stream_private *p_cio, struct opj_stream_private *p_cio,
struct opj_event_mgr * p_manager); 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_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_destroy) (void * p_codec);
void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param); 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_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; }opj_decompression_t;
typedef struct opj_compression typedef struct opj_compression
@ -74,8 +86,8 @@ typedef struct opj_compression
typedef struct opj_codec_private typedef struct opj_codec_private
{ {
union /* code-blocks informations */
{ /* code-blocks informations */ union {
opj_decompression_t m_decompression; opj_decompression_t m_decompression;
opj_compression_t m_compression; opj_compression_t m_compression;
} m_codec_data; } m_codec_data;
@ -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) OPJ_SIZE_T opj_skip_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
{ {
if if (fseek(p_user_data,p_nb_bytes,SEEK_CUR)) {
(fseek(p_user_data,p_nb_bytes,SEEK_CUR))
{
return -1; return -1;
} }
return p_nb_bytes; return p_nb_bytes;
} }
opj_bool opj_seek_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data) opj_bool opj_seek_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
{ {
if if (fseek(p_user_data,p_nb_bytes,SEEK_SET)) {
(fseek(p_user_data,p_nb_bytes,SEEK_SET))
{
return EXIT_FAILURE; return EXIT_FAILURE;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@ -214,30 +224,39 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format)
switch (p_format) { switch (p_format) {
case CODEC_J2K: 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_decode =
l_info->m_codec_data.m_decompression.opj_end_decompress = (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *))j2k_end_decompress; (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_decode; // TODO MSD
l_info->m_codec_data.m_decompression.opj_read_header = (opj_bool (*) (
struct opj_stream_private *, 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 *, void *,
opj_image_header_t **, opj_file_info_t *,
opj_codestream_info_t**,
struct opj_event_mgr * )) j2k_read_header; 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_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 (*) ( l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * , opj_dparameters_t * )) j2k_setup_decoder_v2;
void *,
l_info->m_codec_data.m_decompression.opj_read_tile_header =
(opj_bool (*) ( void *,
OPJ_UINT32*, OPJ_UINT32*,
OPJ_UINT32*, OPJ_UINT32*,
OPJ_INT32 * , OPJ_INT32*, OPJ_INT32*,
OPJ_INT32 * , OPJ_INT32*, OPJ_INT32*,
OPJ_INT32 * , OPJ_UINT32*,
OPJ_INT32 * , opj_bool*,
OPJ_UINT32 * ,
opj_bool *,
struct opj_stream_private *, struct opj_stream_private *,
struct opj_event_mgr * )) j2k_read_tile_header; 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_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(); l_info->m_codec = j2k_create_decompress_v2();
if (! l_info->m_codec) { 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: case CODEC_JP2:
/* get a JP2 decoder handle */ /* 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_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_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 (*) ( l_info->m_codec_data.m_decompression.opj_read_header = (opj_bool (*) (
struct opj_stream_private *, struct opj_stream_private *,
void *, void *,
opj_image_header_t **, opj_file_info_t *,
opj_codestream_info_t**,
struct opj_event_mgr * )) jp2_read_header; struct opj_event_mgr * )) jp2_read_header;
l_info->m_codec_data.m_decompression.opj_read_tile_header = ( l_info->m_codec_data.m_decompression.opj_read_tile_header = ( opj_bool (*) (
opj_bool (*) (
void *, void *,
OPJ_UINT32*, OPJ_UINT32*,
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_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_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_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_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); l_info->m_codec = jp2_create(OPJ_TRUE);
@ -602,6 +623,8 @@ void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
} }
} }
#ifdef OLD_WAY_MS #ifdef OLD_WAY_MS
opj_bool OPJ_CALLCONV opj_read_header ( opj_bool OPJ_CALLCONV opj_read_header (
opj_codec_t *p_codec, 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_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
opj_codec_t *p_codec, opj_codec_t *p_codec,
opj_image_header_t **p_image_header, opj_file_info_t* p_file_info,
opj_codestream_info_t **p_cstr_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) { if (p_codec && p_cio) {
opj_codec_private_t* l_info = (opj_codec_private_t*) p_codec; opj_codec_private_t* l_info = (opj_codec_private_t*) p_codec;
opj_stream_private_t* l_cio = (opj_stream_private_t*) p_cio; 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( return l_info->m_codec_data.m_decompression.opj_read_header(
l_cio, l_cio,
l_info->m_codec, l_info->m_codec,
p_image_header, p_file_info,
p_cstr_info,
l_info->m_event_mgr); l_info->m_event_mgr);
} }
return OPJ_FALSE; return OPJ_FALSE;
@ -682,3 +707,37 @@ void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_info)
opj_free(l_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;
}

View File

@ -105,6 +105,15 @@ typedef float OPJ_FLOAT32;
#define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */ #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
/* <<UniPG */ /* <<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 enum definitions
@ -171,6 +180,9 @@ typedef enum LIMIT_DECODING {
DECODE_ALL_BUT_PACKETS = 2 /**< Decode everything except the JPEG 2000 packets */ DECODE_ALL_BUT_PACKETS = 2 /**< Decode everything except the JPEG 2000 packets */
} OPJ_LIMIT_DECODING; } OPJ_LIMIT_DECODING;
/* /*
========================================================== ==========================================================
event manager typedef definitions event manager typedef definitions
@ -421,6 +433,14 @@ typedef struct opj_dparameters {
*/ */
OPJ_LIMIT_DECODING cp_limit_decoding; 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; } opj_dparameters_t;
/** Common fields between JPEG-2000 compression and decompression master structs. */ /** Common fields between JPEG-2000 compression and decompression master structs. */
@ -649,6 +669,7 @@ typedef struct opj_image_header {
/** image components */ /** image components */
opj_image_comp_header_t *comps; opj_image_comp_header_t *comps;
#ifdef TODO_MSD
/** XTOsiz */ /** XTOsiz */
OPJ_UINT32 tile_x0; OPJ_UINT32 tile_x0;
/** YTOsiz */ /** YTOsiz */
@ -661,6 +682,7 @@ typedef struct opj_image_header {
OPJ_UINT32 nb_tiles_x; OPJ_UINT32 nb_tiles_x;
/** number of tiles in height */ /** number of tiles in height */
OPJ_UINT32 nb_tiles_y; OPJ_UINT32 nb_tiles_y;
#endif
/** 'restricted' ICC profile */ /** 'restricted' ICC profile */
unsigned char *icc_profile_buf; unsigned char *icc_profile_buf;
@ -814,9 +836,43 @@ typedef struct opj_codestream_info {
// NEW codestream // 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 { typedef struct opj_tile_v2_info {
/** number of tile */ /** number (index) of tile */
int tileno; int tileno;
/** start position */ /** start position */
@ -831,6 +887,17 @@ typedef struct opj_tile_v2_info {
/** add fixed_quality */ /** add fixed_quality */
double distotile; 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) */ /** precinct number for each resolution level (width) */
int pw[33]; int pw[33];
/** precinct number for each resolution level (height) */ /** precinct number for each resolution level (height) */
@ -848,6 +915,9 @@ typedef struct opj_tile_v2_info {
/** information concerning tile parts */ /** information concerning tile parts */
opj_tp_info_t *tp; 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 */ /** value of thresh for each layer by tile cfr. Marcela */
double *thresh; double *thresh;
} opj_tile_info_v2_t; } opj_tile_info_v2_t;
@ -855,7 +925,8 @@ typedef struct opj_tile_v2_info {
/** /**
Index structure of the codestream Index structure of the codestream
*/ */
typedef struct opj_codestream_v2_info { typedef struct opj_codestream_info_v2 {
/* Basic image info */
/** image width */ /** image width */
int image_w; int image_w;
/** image height */ /** image height */
@ -863,14 +934,15 @@ typedef struct opj_codestream_v2_info {
/** numbers of component */ /** numbers of component */
int numcomps; int numcomps;
/* Codestream Info */
/** progression order */ /** progression order */
OPJ_PROG_ORDER prog; OPJ_PROG_ORDER prog;
/** number of layer */ /** number of layer */
int numlayers; int numlayers;
/** */ /** tile origin in x */
int tx0; int tx0;
/** */ /** tile origin in y */
int ty0; int ty0;
/** tile size in x */ /** tile size in x */
int tdx; int tdx;
@ -913,6 +985,47 @@ typedef struct opj_codestream_v2_info {
opj_tile_info_v2_t *tile; opj_tile_info_v2_t *tile;
} opj_codestream_info_v2_t; } 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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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_API opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
opj_codec_t *p_codec, opj_codec_t *p_codec,
opj_image_header_t **p_image_header, opj_file_info_t * p_file_info,
opj_codestream_info_t **p_cstr_info ); OPJ_INT32 file_info_flag);
/** /**
Destroy a decompressor handle 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); 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 #ifdef __cplusplus
} }
#endif #endif
#endif /* OPENJPEG_H */ #endif /* OPENJPEG_H */

View File

@ -841,7 +841,7 @@ opj_bool t2_decode_packets_v2(
OPJ_BYTE *p_src, OPJ_BYTE *p_src,
OPJ_UINT32 * p_data_read, OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_len, 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_BYTE *l_current_data = p_src;
opj_pi_iterator_t *l_pi = 00; opj_pi_iterator_t *l_pi = 00;
@ -901,7 +901,7 @@ opj_bool t2_decode_packets_v2(
/* INDEX >> */ /* INDEX >> */
if(p_cstr_info) { 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]; opj_packet_info_t *info_PK = &info_TL->packet[p_cstr_info->packno];
if (!p_cstr_info->packno) { if (!p_cstr_info->packno) {
info_PK->start_pos = info_TL->end_header + 1; info_PK->start_pos = info_TL->end_header + 1;

View File

@ -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 tileno number that identifies the tile for which to decode the packets
@param tile 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 * Creates a Tier 2 handle

View File

@ -107,7 +107,7 @@ opj_bool tcd_t2_decode (
OPJ_BYTE * p_src_data, OPJ_BYTE * p_src_data,
OPJ_UINT32 * p_data_read, OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_src_size, 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 ( opj_bool tcd_t1_decode (
@ -2046,7 +2046,7 @@ opj_bool tcd_decode_tile_v2(
OPJ_BYTE *p_src, OPJ_BYTE *p_src,
OPJ_UINT32 p_max_length, OPJ_UINT32 p_max_length,
OPJ_UINT32 p_tile_no, 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; OPJ_UINT32 l_data_read;
p_tcd->tcd_tileno = p_tile_no; p_tcd->tcd_tileno = p_tile_no;
@ -2077,7 +2077,7 @@ opj_bool tcd_decode_tile_v2(
// FIXME _ProfStart(PGROUP_T2); // FIXME _ProfStart(PGROUP_T2);
l_data_read = 0; l_data_read = 0;
if 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; return OPJ_FALSE;
} }
@ -2396,7 +2396,7 @@ opj_bool tcd_t2_decode (
OPJ_BYTE * p_src_data, OPJ_BYTE * p_src_data,
OPJ_UINT32 * p_data_read, OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_src_size, 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; opj_t2_v2_t * l_t2;

View File

@ -436,7 +436,11 @@ Decode a tile from a buffer into a raw image
@param len Length of source buffer @param len Length of source buffer
@param tileno Number that identifies one of the tiles to be decoded @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);
/** /**