WIP: begin to clean j2k_dump and some other small things
authorMickael Savinaud <savmickael@users.noreply.github.com>
Mon, 19 Sep 2011 13:55:06 +0000 (13:55 +0000)
committerMickael Savinaud <savmickael@users.noreply.github.com>
Mon, 19 Sep 2011 13:55:06 +0000 (13:55 +0000)
CHANGES
applications/codec/j2k_dump.c
libopenjpeg/cio.c
libopenjpeg/image.c
libopenjpeg/jp2.c
libopenjpeg/openjpeg.h

diff --git a/CHANGES b/CHANGES
index fff3fdd03472aca65c0747079b6eee0c45b4157b..8a454091067765889ee058ca4b60930440020264 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,7 @@ What's New for OpenJPEG
 + : added
 
 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: 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
index e1a2feb10de5fcf2eb88eecdb0a994899ba7d5ea..7f5844000c78382e8f98c3fa15f9f1f9b4a83d00 100644 (file)
@@ -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);
        strncpy(parameters->infile, infilename, sizeof(infilename));
 
-       //Set output file
+       /* Set output file */
        strcpy(temp_ofname,strtok(image_filename,"."));
        while((temp_p = strtok(NULL,".")) != NULL){
                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);
                                switch(parameters->decod_format) {
                                        case J2K_CFMT:
+                                               break;
                                        case JP2_CFMT:
+                                               break;
                                        case JPT_CFMT:
                                                break;
                                        default:
@@ -322,15 +324,14 @@ int main(int argc, char *argv[])
        opj_event_mgr_t event_mgr;              /* event manager */
        opj_image_header_t* image = NULL;
        FILE *fsrc = NULL, *fout = NULL;
-       opj_bool bResult;
        int num_images;
        int i,imageno;
        dircnt_t *dirptr = NULL;
        opj_codec_t* dinfo = NULL;      /* handle to a decompressor */
        opj_stream_t *cio = NULL;
        opj_codestream_info_t* cstr_info =NULL;  /* Codestream information structure */
-       //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_INT32 l_tile_x0,l_tile_y0; */
+       /* OPJ_UINT32 l_tile_width,l_tile_height,l_nb_tiles_x,l_nb_tiles_y; */
 
 
        /* FIXME configure the event callbacks (not required) */
@@ -357,7 +358,7 @@ int main(int argc, char *argv[])
 
                dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
                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*));
 
                        if(!dirptr->filename_buf){
@@ -380,7 +381,7 @@ int main(int argc, char *argv[])
                num_images=1;
        }
 
-       //
+       /* Try to open for writing the output file if necessary */
        if (parameters.outfile[0] != 0){
                fout = fopen(parameters.outfile,"w");
                if (!fout){
@@ -391,7 +392,7 @@ int main(int argc, char *argv[])
        else
                fout = stdout;
 
-       /*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++){
                image = NULL;
                fprintf(stderr,"\n");
@@ -448,84 +449,36 @@ int main(int argc, char *argv[])
                /* setup the decoder decoding parameters using user parameters */
                opj_setup_decoder_v2(dinfo, &parameters, &event_mgr);
 
-               /* decode the stream and fill the image structure */
-               /*              if (*indexfilename)                             // If need to extract codestream information
-                               image = opj_decode_with_info(dinfo, cio, &cstr_info);
-                       else
-                       */
-               //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");
+               if(! opj_read_header(cio, dinfo, &image, &cstr_info)){
+                       fprintf(stderr, "ERROR -> j2k_dump: failed to read the header\n");
+                       opj_stream_destroy(cio);
+                       fclose(fsrc);
+                       opj_destroy_codec(dinfo);
                        return EXIT_FAILURE;
                }
 
-               if (parameters.decod_format == J2K_CFMT){
-                       /* 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);
-               }
+               /* Dump file informations from header */
+
 
                /* close the byte stream */
                opj_stream_destroy(cio);
                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 */
                if (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);
 
        }
 /*NEW V2 STYLE*/
 
+       /* Close the output file */
        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, "    dx=%d, dy=%d\n", comp->dx, comp->dy);
                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, "  }\n");
        }
index 2c5dec9f77ec7c40ab6e53bcc4a1f6ceef789be1..a65ff5c448638a8ab19dc091a4afec2b093ccb6b 100644 (file)
@@ -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)
                        {
                                // end of stream
-#ifdef TODO_MSD
-                               opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
-#endif
+                               opj_event_msg_v2(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
+
                                p_stream->m_bytes_in_buffer = 0;
                                p_stream->m_status |= opj_stream_e_end;
                                // 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)
                        {
                                // end of stream
-#ifdef TODO_MSD
-                               opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
-#endif
+                               opj_event_msg_v2(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
+
                                p_stream->m_bytes_in_buffer = 0;
                                p_stream->m_status |= opj_stream_e_end;
                                // 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)
                {
                        p_stream->m_status |= opj_stream_e_error;
-#ifdef TODO_MSD
-                       opj_event_msg(p_event_mgr, EVT_INFO, "Error on writting stream!\n");
-#endif
+                       opj_event_msg_v2(p_event_mgr, EVT_INFO, "Error on writting stream!\n");
+
                        return EXIT_FAILURE;
                }
                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
                        (l_current_skip_nb_bytes == (OPJ_SIZE_T) -1)
                {
-#ifdef TODO_MSD
-                       opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
-# endif
+                       opj_event_msg_v2(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
+
                        p_stream->m_status |= opj_stream_e_end;
                        p_stream->m_byte_offset += l_skip_nb_bytes;
                        // 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
                        (l_current_skip_nb_bytes == (OPJ_SIZE_T)-1)
                {
-#ifdef TODO_MSD
-                       opj_event_msg(p_event_mgr, EVT_INFO, "Stream error!\n");
-#endif
+                       opj_event_msg_v2(p_event_mgr, EVT_INFO, "Stream error!\n");
+
                        p_stream->m_status |= opj_stream_e_error;
                        p_stream->m_byte_offset += l_skip_nb_bytes;
                        // end if stream
index a368c942c1eaf45c0951566ef2d520664b51e8a8..0869b9af234419f48375b4b83e1bea24e311316e 100644 (file)
@@ -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) {
-       if(image) {
-               if(image->comps) {
+void OPJ_CALLCONV opj_image_header_destroy(opj_image_header_t *image_header) {
+       if(image_header) {
+               if(image_header->comps) {
                        /* 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);
        }
 }
 
index a27f8ac61653c23aed2b8e7492084cb76662a9bb..14e8c585941c12c477b83825c9e923d2f235db61 100644 (file)
@@ -1317,7 +1317,7 @@ static opj_bool jp2_read_colr_v2( opj_jp2_v2_t * jp2,
 
        }
        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;
 
index 229982d931c22ce55643844adfbd3ee80d71f7b7..a94f3a4735cae622851046b9bc529b402cdf82b8 100644 (file)
@@ -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_header_destroy(opj_image_header_t *image);
+OPJ_API void OPJ_CALLCONV opj_image_header_destroy(opj_image_header_t *image_header);
 
 /* 
 ==========================================================