WIP: begin to clean j2k_dump and some other small things
This commit is contained in:
parent
6ece3f6792
commit
dcb3fcbfa7
1
CHANGES
1
CHANGES
|
@ -6,6 +6,7 @@ What's New for OpenJPEG
|
||||||
+ : added
|
+ : added
|
||||||
|
|
||||||
September 19, 2011
|
September 19, 2011
|
||||||
|
+ [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
|
||||||
+ [mickael] WIP: add support of jp2 for new j2k_dump function and some other small stuff
|
+ [mickael] WIP: add support of jp2 for new j2k_dump function and some other small stuff
|
||||||
+ [mickael] WIP: new image_header struct is used and enable used of cstr_info
|
+ [mickael] WIP: new image_header struct is used and enable used of cstr_info
|
||||||
|
|
|
@ -181,7 +181,7 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
|
||||||
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
|
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
|
||||||
strncpy(parameters->infile, infilename, sizeof(infilename));
|
strncpy(parameters->infile, infilename, sizeof(infilename));
|
||||||
|
|
||||||
//Set output file
|
/* Set output file */
|
||||||
strcpy(temp_ofname,strtok(image_filename,"."));
|
strcpy(temp_ofname,strtok(image_filename,"."));
|
||||||
while((temp_p = strtok(NULL,".")) != NULL){
|
while((temp_p = strtok(NULL,".")) != NULL){
|
||||||
strcat(temp_ofname,temp1);
|
strcat(temp_ofname,temp1);
|
||||||
|
@ -216,7 +216,9 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||||
parameters->decod_format = get_file_format(infile);
|
parameters->decod_format = get_file_format(infile);
|
||||||
switch(parameters->decod_format) {
|
switch(parameters->decod_format) {
|
||||||
case J2K_CFMT:
|
case J2K_CFMT:
|
||||||
|
break;
|
||||||
case JP2_CFMT:
|
case JP2_CFMT:
|
||||||
|
break;
|
||||||
case JPT_CFMT:
|
case JPT_CFMT:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -322,15 +324,14 @@ int main(int argc, char *argv[])
|
||||||
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;
|
||||||
FILE *fsrc = NULL, *fout = NULL;
|
FILE *fsrc = NULL, *fout = NULL;
|
||||||
opj_bool bResult;
|
|
||||||
int num_images;
|
int num_images;
|
||||||
int i,imageno;
|
int i,imageno;
|
||||||
dircnt_t *dirptr = NULL;
|
dircnt_t *dirptr = NULL;
|
||||||
opj_codec_t* dinfo = NULL; /* handle to a decompressor */
|
opj_codec_t* dinfo = NULL; /* handle to a decompressor */
|
||||||
opj_stream_t *cio = NULL;
|
opj_stream_t *cio = NULL;
|
||||||
opj_codestream_info_t* cstr_info =NULL; /* Codestream information structure */
|
opj_codestream_info_t* cstr_info =NULL; /* Codestream information structure */
|
||||||
//OPJ_INT32 l_tile_x0,l_tile_y0;
|
/* OPJ_INT32 l_tile_x0,l_tile_y0; */
|
||||||
//OPJ_UINT32 l_tile_width,l_tile_height,l_nb_tiles_x,l_nb_tiles_y;
|
/* OPJ_UINT32 l_tile_width,l_tile_height,l_nb_tiles_x,l_nb_tiles_y; */
|
||||||
|
|
||||||
|
|
||||||
/* FIXME configure the event callbacks (not required) */
|
/* FIXME configure the event callbacks (not required) */
|
||||||
|
@ -357,7 +358,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
|
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
|
||||||
if(dirptr){
|
if(dirptr){
|
||||||
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); // Stores at max 10 image file names
|
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names */
|
||||||
dirptr->filename = (char**) malloc(num_images*sizeof(char*));
|
dirptr->filename = (char**) malloc(num_images*sizeof(char*));
|
||||||
|
|
||||||
if(!dirptr->filename_buf){
|
if(!dirptr->filename_buf){
|
||||||
|
@ -380,7 +381,7 @@ int main(int argc, char *argv[])
|
||||||
num_images=1;
|
num_images=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/* Try to open for writing the output file if necessary */
|
||||||
if (parameters.outfile[0] != 0){
|
if (parameters.outfile[0] != 0){
|
||||||
fout = fopen(parameters.outfile,"w");
|
fout = fopen(parameters.outfile,"w");
|
||||||
if (!fout){
|
if (!fout){
|
||||||
|
@ -448,84 +449,36 @@ 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, ¶meters, &event_mgr);
|
opj_setup_decoder_v2(dinfo, ¶meters, &event_mgr);
|
||||||
|
|
||||||
/* decode the stream and fill the image structure */
|
if(! opj_read_header(cio, dinfo, &image, &cstr_info)){
|
||||||
/* if (*indexfilename) // If need to extract codestream information
|
fprintf(stderr, "ERROR -> j2k_dump: failed to read the header\n");
|
||||||
image = opj_decode_with_info(dinfo, cio, &cstr_info);
|
opj_stream_destroy(cio);
|
||||||
else
|
fclose(fsrc);
|
||||||
*/
|
opj_destroy_codec(dinfo);
|
||||||
//opj_codestream_info_t *cstr_info = NULL;
|
|
||||||
|
|
||||||
/*bResult = opj_read_header( dinfo,
|
|
||||||
&image,
|
|
||||||
&l_tile_x0,
|
|
||||||
&l_tile_y0,
|
|
||||||
&l_tile_width,
|
|
||||||
&l_tile_height,
|
|
||||||
&l_nb_tiles_x,
|
|
||||||
&l_nb_tiles_y,
|
|
||||||
cio);*/
|
|
||||||
|
|
||||||
bResult = opj_read_header(cio, dinfo, &image, &cstr_info);
|
|
||||||
|
|
||||||
if(!bResult){
|
|
||||||
fprintf(stderr, "ERROR -> j2k_to_image: failed to read header\n");
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parameters.decod_format == J2K_CFMT){
|
/* Dump file informations from header */
|
||||||
/* dump image */
|
|
||||||
j2k_dump_image(fout, image);
|
|
||||||
write_index_file_v2(fout, cstr_info);
|
|
||||||
/* dump cp */
|
|
||||||
//j2k_dump_cp(stdout, image, ((opj_codec_private_t)dinfo)->m_codec);
|
|
||||||
//j2k_dump_cp(fout, image, ((opj_j2k_t*)dinfo->j2k_handle)->cp);
|
|
||||||
}
|
|
||||||
else if (parameters.decod_format == JP2_CFMT){
|
|
||||||
/* dump image */
|
|
||||||
if(image->icc_profile_buf){
|
|
||||||
free(image->icc_profile_buf);
|
|
||||||
image->icc_profile_buf = NULL;
|
|
||||||
}
|
|
||||||
j2k_dump_image(fout, image);
|
|
||||||
/* dump cp */
|
|
||||||
//j2k_dump_cp(stdout, image, dinfo->m_codec);
|
|
||||||
//j2k_dump_cp(fout, image, ((opj_jp2_t*)dinfo->jp2_handle)->j2k->cp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* close the byte stream */
|
/* close the byte stream */
|
||||||
opj_stream_destroy(cio);
|
opj_stream_destroy(cio);
|
||||||
fclose(fsrc);
|
fclose(fsrc);
|
||||||
|
|
||||||
/* Write the index to disk */
|
|
||||||
/*if (*indexfilename) {
|
|
||||||
char bSuccess;
|
|
||||||
bSuccess = write_index_file(&cstr_info, indexfilename);
|
|
||||||
if (bSuccess) {
|
|
||||||
fprintf(stderr, "Failed to output index file\n");
|
|
||||||
ret = EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ret = EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
else*/
|
|
||||||
ret = EXIT_SUCCESS;
|
|
||||||
|
|
||||||
/* free remaining structures */
|
/* free remaining structures */
|
||||||
if (dinfo) {
|
if (dinfo) {
|
||||||
opj_destroy_codec(dinfo);
|
opj_destroy_codec(dinfo);
|
||||||
}
|
}
|
||||||
/* free codestream information structure */
|
|
||||||
/*if (*indexfilename)
|
|
||||||
FIXME A GARDER opj_destroy_cstr_info(&cstr_info);*/
|
|
||||||
/* free image data structure */
|
|
||||||
opj_image_header_destroy(image);
|
opj_image_header_destroy(image);
|
||||||
|
|
||||||
}
|
}
|
||||||
/*NEW V2 STYLE*/
|
/*NEW V2 STYLE*/
|
||||||
|
|
||||||
|
/* Close the output file */
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
|
|
||||||
return ret;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -539,7 +492,7 @@ static void j2k_dump_image(FILE *fd, opj_image_header_t * img) {
|
||||||
fprintf(fd, " comp %d {\n", compno);
|
fprintf(fd, " comp %d {\n", compno);
|
||||||
fprintf(fd, " dx=%d, dy=%d\n", comp->dx, comp->dy);
|
fprintf(fd, " dx=%d, dy=%d\n", comp->dx, comp->dy);
|
||||||
fprintf(fd, " prec=%d\n", comp->prec);
|
fprintf(fd, " prec=%d\n", comp->prec);
|
||||||
//fprintf(fd, " bpp=%d\n", comp->bpp);
|
/* fprintf(fd, " bpp=%d\n", comp->bpp); */
|
||||||
fprintf(fd, " sgnd=%d\n", comp->sgnd);
|
fprintf(fd, " sgnd=%d\n", comp->sgnd);
|
||||||
fprintf(fd, " }\n");
|
fprintf(fd, " }\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -567,9 +567,8 @@ OPJ_UINT32 opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
|
||||||
(p_stream->m_bytes_in_buffer == -1)
|
(p_stream->m_bytes_in_buffer == -1)
|
||||||
{
|
{
|
||||||
// end of stream
|
// end of stream
|
||||||
#ifdef TODO_MSD
|
opj_event_msg_v2(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
|
||||||
opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
|
|
||||||
#endif
|
|
||||||
p_stream->m_bytes_in_buffer = 0;
|
p_stream->m_bytes_in_buffer = 0;
|
||||||
p_stream->m_status |= opj_stream_e_end;
|
p_stream->m_status |= opj_stream_e_end;
|
||||||
// end of stream
|
// end of stream
|
||||||
|
@ -605,9 +604,8 @@ OPJ_UINT32 opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
|
||||||
(p_stream->m_bytes_in_buffer == -1)
|
(p_stream->m_bytes_in_buffer == -1)
|
||||||
{
|
{
|
||||||
// end of stream
|
// end of stream
|
||||||
#ifdef TODO_MSD
|
opj_event_msg_v2(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
|
||||||
opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
|
|
||||||
#endif
|
|
||||||
p_stream->m_bytes_in_buffer = 0;
|
p_stream->m_bytes_in_buffer = 0;
|
||||||
p_stream->m_status |= opj_stream_e_end;
|
p_stream->m_status |= opj_stream_e_end;
|
||||||
// end of stream
|
// end of stream
|
||||||
|
@ -713,9 +711,8 @@ opj_bool opj_stream_flush (opj_stream_private_t * p_stream, opj_event_mgr_t * p_
|
||||||
(l_current_write_nb_bytes == -1)
|
(l_current_write_nb_bytes == -1)
|
||||||
{
|
{
|
||||||
p_stream->m_status |= opj_stream_e_error;
|
p_stream->m_status |= opj_stream_e_error;
|
||||||
#ifdef TODO_MSD
|
opj_event_msg_v2(p_event_mgr, EVT_INFO, "Error on writting stream!\n");
|
||||||
opj_event_msg(p_event_mgr, EVT_INFO, "Error on writting stream!\n");
|
|
||||||
#endif
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
p_stream->m_current_data += l_current_write_nb_bytes;
|
p_stream->m_current_data += l_current_write_nb_bytes;
|
||||||
|
@ -776,9 +773,8 @@ OPJ_SIZE_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_SIZE_T p_s
|
||||||
if
|
if
|
||||||
(l_current_skip_nb_bytes == (OPJ_SIZE_T) -1)
|
(l_current_skip_nb_bytes == (OPJ_SIZE_T) -1)
|
||||||
{
|
{
|
||||||
#ifdef TODO_MSD
|
opj_event_msg_v2(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
|
||||||
opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
|
|
||||||
# endif
|
|
||||||
p_stream->m_status |= opj_stream_e_end;
|
p_stream->m_status |= opj_stream_e_end;
|
||||||
p_stream->m_byte_offset += l_skip_nb_bytes;
|
p_stream->m_byte_offset += l_skip_nb_bytes;
|
||||||
// end if stream
|
// end if stream
|
||||||
|
@ -830,9 +826,8 @@ OPJ_SIZE_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_SIZE_T p_
|
||||||
if
|
if
|
||||||
(l_current_skip_nb_bytes == (OPJ_SIZE_T)-1)
|
(l_current_skip_nb_bytes == (OPJ_SIZE_T)-1)
|
||||||
{
|
{
|
||||||
#ifdef TODO_MSD
|
opj_event_msg_v2(p_event_mgr, EVT_INFO, "Stream error!\n");
|
||||||
opj_event_msg(p_event_mgr, EVT_INFO, "Stream error!\n");
|
|
||||||
#endif
|
|
||||||
p_stream->m_status |= opj_stream_e_error;
|
p_stream->m_status |= opj_stream_e_error;
|
||||||
p_stream->m_byte_offset += l_skip_nb_bytes;
|
p_stream->m_byte_offset += l_skip_nb_bytes;
|
||||||
// end if stream
|
// end if stream
|
||||||
|
|
|
@ -94,13 +94,16 @@ void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OPJ_CALLCONV opj_image_header_destroy(opj_image_header_t *image) {
|
void OPJ_CALLCONV opj_image_header_destroy(opj_image_header_t *image_header) {
|
||||||
if(image) {
|
if(image_header) {
|
||||||
if(image->comps) {
|
if(image_header->comps) {
|
||||||
/* image components */
|
/* image components */
|
||||||
opj_free(image->comps);
|
opj_free(image_header->comps);
|
||||||
}
|
}
|
||||||
opj_free(image);
|
if(image_header->icc_profile_buf) {
|
||||||
|
opj_free(image_header->icc_profile_buf);
|
||||||
|
}
|
||||||
|
opj_free(image_header);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1317,7 +1317,7 @@ static opj_bool jp2_read_colr_v2( opj_jp2_v2_t * jp2,
|
||||||
|
|
||||||
}
|
}
|
||||||
else // TODO MSD
|
else // TODO MSD
|
||||||
opj_event_msg_v2(p_manager, EVT_INFO, "COLR BOX meth value is not is not a regular value (%d), so we will skip the fields following approx field.\n", jp2->meth);
|
opj_event_msg_v2(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), so we will skip the fields following the approx field.\n", jp2->meth);
|
||||||
|
|
||||||
jp2->color.jp2_has_colr = 1;
|
jp2->color.jp2_has_colr = 1;
|
||||||
|
|
||||||
|
|
|
@ -947,7 +947,7 @@ Deallocate any resources associated with an image
|
||||||
*/
|
*/
|
||||||
OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
|
OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
|
||||||
|
|
||||||
OPJ_API void OPJ_CALLCONV opj_image_header_destroy(opj_image_header_t *image);
|
OPJ_API void OPJ_CALLCONV opj_image_header_destroy(opj_image_header_t *image_header);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
==========================================================
|
==========================================================
|
||||||
|
|
Loading…
Reference in New Issue