]> granicus.if.org Git - openjpeg/commitdiff
WIP: create a new framework to output file information
authorMickael Savinaud <savmickael@users.noreply.github.com>
Mon, 19 Sep 2011 16:01:49 +0000 (16:01 +0000)
committerMickael Savinaud <savmickael@users.noreply.github.com>
Mon, 19 Sep 2011 16:01:49 +0000 (16:01 +0000)
15 files changed:
CHANGES
applications/codec/index.c
applications/codec/index.h
applications/codec/j2k_dump.c
libopenjpeg/image.c
libopenjpeg/j2k.c
libopenjpeg/j2k.h
libopenjpeg/jp2.c
libopenjpeg/jp2.h
libopenjpeg/openjpeg.c
libopenjpeg/openjpeg.h
libopenjpeg/t2.c
libopenjpeg/t2.h
libopenjpeg/tcd.c
libopenjpeg/tcd.h

diff --git a/CHANGES b/CHANGES
index 581b63c16adceb1fab44d149944113d5f991408f..01508eed415086fa9e8f5badee47c02925ac5a44 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,7 @@ What's New for OpenJPEG
 + : added
 
 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: 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
index 3765819b78dfaeb429c206d1968eaff71e645e7d..2879f47f32d5e2fa246f80d007328407489f6527 100644 (file)
@@ -742,3 +742,109 @@ int write_index_file_v2(FILE* stream, opj_codestream_info_t *cstr_info) {
 \r
        return EXIT_SUCCESS;\r
 }\r
+\r
+/* ------------------------------------------------------------------------------------ */\r
+\r
+/**\r
+Dump the file info structure into a file\r
+@param stream          output stream\r
+@param file_info       informations read into the JPG2000 file\r
+@return Returns 0 if successful, returns 1 otherwise\r
+*/\r
+int dump_file_info(FILE* stream, opj_file_info_t *file_info)\r
+{\r
+       /* IMAGE HEADER */\r
+       if ( file_info->file_info_flag & OPJ_IMG_INFO ) {\r
+               opj_image_header_t img_header = file_info->img_info;\r
+               int compno;\r
+\r
+               fprintf(stream, "Image info {\n");\r
+               fprintf(stream, "\t x0=%d, y0=%d\n",img_header.x0, img_header.y0);\r
+               fprintf(stream, "\t x1=%d, y1=%d\n",img_header.x1, img_header.y1);\r
+               fprintf(stream, "\t numcomps=%d\n", img_header.numcomps);\r
+               for (compno = 0; compno < img_header.numcomps; compno++) {\r
+                       opj_image_comp_header_t comp = img_header.comps[compno];\r
+\r
+                       fprintf(stream, "\t component %d {\n", compno);\r
+                       fprintf(stream, "\t\t dx=%d, dy=%d\n", comp.dx, comp.dy);\r
+                       fprintf(stream, "\t\t prec=%d\n", comp.prec);\r
+                       fprintf(stream, "\t\t sgnd=%d\n", comp.sgnd);\r
+                       fprintf(stream, "\t}\n");\r
+               }\r
+               fprintf(stream, "}\n");\r
+       }\r
+\r
+       /* CODESTREAM INFO */\r
+       if ( file_info->file_info_flag & OPJ_J2K_INFO ) {\r
+               opj_codestream_info_v2_t cstr_info = file_info->codestream_info;\r
+               int tileno, compno, layno, bandno, resno, numbands;\r
+\r
+               fprintf(stream, "Codestream info {\n");\r
+               fprintf(stream, "\t tx0=%d, ty0=%d\n", cstr_info.tx0, cstr_info.ty0);\r
+               fprintf(stream, "\t tdx=%d, tdy=%d\n", cstr_info.tdx, cstr_info.tdy);\r
+               fprintf(stream, "\t tw=%d, th=%d\n", cstr_info.tw, cstr_info.th);\r
+\r
+               for (tileno = 0; tileno < cstr_info.tw * cstr_info.th; tileno++) {\r
+                       opj_tile_info_v2_t tile_info = cstr_info.tile[tileno];\r
+\r
+                       fprintf(stream, "\t tile %d {\n", tileno);\r
+                       fprintf(stream, "\t\t csty=%x\n", tile_info.csty);\r
+                       fprintf(stream, "\t\t prg=%d\n", tile_info.prg);\r
+                       fprintf(stream, "\t\t numlayers=%d\n", tile_info.numlayers);\r
+                       fprintf(stream, "\t\t mct=%d\n", tile_info.mct);\r
+                       fprintf(stream, "\t\t rates=");\r
+\r
+                       for (layno = 0; layno < tile_info.numlayers; layno++) {\r
+                               fprintf(stream, "%.1f ", tile_info.rates[layno]);\r
+                       }\r
+                       fprintf(stream, "\n");\r
+\r
+                       for (compno = 0; compno < cstr_info.numcomps; compno++) {\r
+                               opj_tccp_info_t tccp_info = tile_info.tccp_info[compno];\r
+\r
+                               fprintf(stream, "\t\t comp %d {\n", compno);\r
+                               fprintf(stream, "\t\t\t csty=%x\n", tccp_info.csty);\r
+                               fprintf(stream, "\t\t\t numresolutions=%d\n", tccp_info.numresolutions);\r
+                               fprintf(stream, "\t\t\t cblkw=%d\n", tccp_info.cblkw);\r
+                               fprintf(stream, "\t\t\t cblkh=%d\n", tccp_info.cblkh);\r
+                               fprintf(stream, "\t\t\t cblksty=%x\n", tccp_info.cblksty);\r
+                               fprintf(stream, "\t\t\t qmfbid=%d\n", tccp_info.qmfbid);\r
+                               fprintf(stream, "\t\t\t qntsty=%d\n", tccp_info.qntsty);\r
+                               fprintf(stream, "\t\t\t numgbits=%d\n", tccp_info.numgbits);\r
+                               fprintf(stream, "\t\t\t roishift=%d\n", tccp_info.roishift);\r
+\r
+#ifdef TODO_MSD\r
+                               fprintf(stream, "\t\t\t stepsizes=");\r
+                               numbands = tccp_info->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : tccp_info->numresolutions * 3 - 2;\r
+                               for (bandno = 0; bandno < numbands; bandno++) {\r
+                                       fprintf(stream, "(%d,%d) ", tccp_info->stepsizes[bandno].mant,\r
+                                               tccp_info->stepsizes[bandno].expn);\r
+                               }\r
+                               fprintf(stream, "\n");\r
+\r
+                               if (tccp_info->csty & J2K_CCP_CSTY_PRT) {\r
+                                       fprintf(stream, "      prcw=");\r
+                                       for (resno = 0; resno < tccp_info->numresolutions; resno++) {\r
+                                               fprintf(stream, "%d ", tccp_info->prcw[resno]);\r
+                                       }\r
+                                       fprintf(stream, "\n");\r
+\r
+                                       fprintf(stream, "      prch=");\r
+                                       for (resno = 0; resno < tccp_info->numresolutions; resno++) {\r
+                                               fprintf(stream, "%d ", tccp_info->prch[resno]);\r
+                                       }\r
+                                       fprintf(stream, "\n");\r
+                               }\r
+#endif\r
+                               fprintf(stream, "\t\t\t }\n");\r
+                       } /*end of component*/\r
+                       fprintf(stream, "\t\t }\n");\r
+               } /*end of tile */\r
+               fprintf(stream, "\t }\n");\r
+       }\r
+\r
+       if ( file_info->file_info_flag & OPJ_JP2_INFO ) {\r
+               // not yet coded\r
+       }\r
+       return EXIT_SUCCESS;\r
+}\r
index 29f673a10452e8159ec2e446d72265f7db2f3092..aefce6653dad3765ce40da7ad7a9ed4e348fbf01 100644 (file)
@@ -41,6 +41,8 @@ Write a structured index to a file
 */\r
 int write_index_file(opj_codestream_info_t *cstr_info, char *index);\r
 \r
+int dump_file_info(FILE* stream, opj_file_info_t *file_info);\r
+\r
 #ifdef __cplusplus\r
 }\r
 #endif\r
index 7f5844000c78382e8f98c3fa15f9f1f9b4a83d00..d1c1fb694bbf4aba41cc2352dcdb8f6a172f13c3 100644 (file)
@@ -201,7 +201,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
        opj_option_t long_option[]={
                {"ImgDir",REQ_ARG, NULL ,'y'},
        };
-       const char optlist[] = "i:o:h";
+       const char optlist[] = "i:o:d:h";
 
        totlen=sizeof(long_option);
        img_fol->set_out_format = 0;
@@ -257,7 +257,19 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
                                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:
                                fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
                                break;
@@ -290,6 +302,34 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
        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;
        opj_event_mgr_t event_mgr;              /* event manager */
        opj_image_header_t* image = NULL;
+       opj_file_info_t file_info;
        FILE *fsrc = NULL, *fout = NULL;
        int num_images;
        int i,imageno;
@@ -394,7 +435,7 @@ int main(int argc, char *argv[])
 
        /* Read the header of each image one by one */
        for(imageno = 0; imageno < num_images ; imageno++){
-               image = NULL;
+
                fprintf(stderr,"\n");
 
                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 */
                /* ---------------------------------------- */
                fsrc = fopen(parameters.infile, "rb");
@@ -414,6 +454,10 @@ int main(int argc, char *argv[])
                }
 
                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 */
                /* ---------------------- */
@@ -449,7 +493,7 @@ int main(int argc, char *argv[])
                /* setup the decoder decoding parameters using user parameters */
                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");
                        opj_stream_destroy(cio);
                        fclose(fsrc);
@@ -457,8 +501,14 @@ int main(int argc, char *argv[])
                        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 */
                opj_stream_destroy(cio);
@@ -471,9 +521,10 @@ int main(int argc, char *argv[])
 
 
                opj_image_header_destroy(image);
+               //FIXME opj_file_info_destroy(file_info);
 
        }
-/*NEW V2 STYLE*/
+
 
        /* Close the output file */
        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, "  }\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, "  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, "  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, "}\n");
 }
 
index 0869b9af234419f48375b4b83e1bea24e311316e..9941b1d89a74006760331c1f3d2d955769bedeef 100644 (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;
+}
index f551c10c8af8bb9678ab603e28fbddb6cce751eb..9375b618a5f6406f66672f53fc587fa05b6a789a 100644 (file)
@@ -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,19 +4939,121 @@ 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.
  */
@@ -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);
index 0835e09afa8ec736802ff6cd29f8d7d4e9470a14..e2d8429bbb572b6f7098e2b581f82b94fe53074a 100644 (file)
@@ -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 );
 
 
index 14e8c585941c12c477b83825c9e923d2f235db61..efbf8d101da8d28cb8bfe6bdac1b1aafed68ab41 100644 (file)
@@ -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);
 }
 
index b0a60086582d8f259506aafda9004b25d8a31a46..0203fd122287d2f6eee3648ad1bbcee42a325045 100644 (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_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
                                                        );
 
index 707a2066a856e983155592944d7fa71dfbdb4442..5b99d4d1b99dfae6ec7c939fef3ca8a2350b0928 100644 (file)
 
 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;
+}
index a94f3a4735cae622851046b9bc529b402cdf82b8..94fbdfa5dae5417e4df205b2076ee14d82e8795a 100644 (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 */
 /* <<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 */
+
+
index 90fbf90d6a269b6110c6f896dc85185f12232178..e9f08abb22ae54ffc2a2f1130c2b470f54747b57 100644 (file)
@@ -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;
index b130746ff4fad9a56367ae31ba15d0f165aba75f..55cac98f741fc77276337b7a7e1a65eb23fa0c06 100644 (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 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
index 1eeba0028ce7cc0463d612c83b41009b8f274ac8..9d8dc782a2f5cb39ee4660cf7992023af78d17c6 100644 (file)
@@ -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;
index 09c184ac674b85d5bd607b4a99de7cfaf7ba33bb..c3c416c6ecdc5a67b4f7cc8daf1a1316e7226de6 100644 (file)
@@ -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);
 
 
 /**