WIP: new image_header struct is used and enable used of cstr_info
authorMickael Savinaud <savmickael@users.noreply.github.com>
Mon, 19 Sep 2011 13:30:21 +0000 (13:30 +0000)
committerMickael Savinaud <savmickael@users.noreply.github.com>
Mon, 19 Sep 2011 13:30:21 +0000 (13:30 +0000)
14 files changed:
CHANGES
applications/codec/j2k_dump.c
libopenjpeg/image.c
libopenjpeg/image.h
libopenjpeg/j2k.c
libopenjpeg/j2k.h
libopenjpeg/openjpeg.c
libopenjpeg/openjpeg.h
libopenjpeg/pi.c
libopenjpeg/pi.h
libopenjpeg/t2.c
libopenjpeg/t2.h
libopenjpeg/tcd.c
libopenjpeg/tcd.h

diff --git a/CHANGES b/CHANGES
index 6ced318001bf27e9044b36edb05af115073fed8b..ab862605baa59da489d6b522caf800711aa523b0 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,7 @@ What's New for OpenJPEG
 + : added
 
 September 19, 2011
++ [mickael] WIP: new image_header struct is used and enable used of cstr_info
 + [mickael] WIP: manage the case of event_mgr is not provided to setup_decoder function 
 + [mickael] WIP: insert elements from V2 framework into the trunk (add missing files). 
 + [mickael] Work In Progress: insert elements from V2 framework into the trunk. 
index 1c1e8620abbe01a59996a097efd9e0317256b681..a7893e50d7092332425af2e9c0702c0861b96484 100644 (file)
@@ -100,8 +100,8 @@ void decode_help_display(void) {
 }
 
 /* -------------------------------------------------------------------------- */
-static void j2k_dump_image(FILE *fd, opj_image_t * img);
-static void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp);
+static void j2k_dump_image(FILE *fd, opj_image_header_t * img);
+static void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_v2_t * cp);
 
 int get_num_images(char *imgdirpath){
        DIR *dir;
@@ -194,7 +194,7 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
 }
 
 /* -------------------------------------------------------------------------- */
-int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
+int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) {
        /* parse the command line */
        int totlen, c;
        opj_option_t long_option[]={
@@ -202,8 +202,6 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
        };
        const char optlist[] = "i:o:h";
 
-       OPJ_ARG_NOT_USED(indexfilename);
-
        totlen=sizeof(long_option);
        img_fol->set_out_format = 0;
        do {
@@ -321,7 +319,7 @@ int main(int argc, char *argv[])
        opj_dparameters_t parameters;   /* decompression parameters */
        img_fol_t img_fol;
        opj_event_mgr_t event_mgr;              /* event manager */
-       opj_image_t *image = NULL;
+       opj_image_header_t* image = NULL;
        FILE *fsrc = NULL, *fout = NULL;
        opj_bool bResult;
        int num_images;
@@ -329,10 +327,9 @@ int main(int argc, char *argv[])
        dircnt_t *dirptr = NULL;
        opj_codec_t* dinfo = NULL;      /* handle to a decompressor */
        opj_stream_t *cio = NULL;
-       opj_codestream_info_t cstr_info;  /* Codestream information structure */
-       char indexfilename[OPJ_PATH_LEN];       /* index file name */
-       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_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;
 
 
        /* FIXME configure the event callbacks (not required) */
@@ -345,12 +342,11 @@ int main(int argc, char *argv[])
        /* set decoding parameters to default values */
        opj_set_default_decoder_parameters(&parameters);
 
-       /* Initialize indexfilename and img_fol */
-       *indexfilename = 0;
+       /* Initialize img_fol */
        memset(&img_fol,0,sizeof(img_fol_t));
 
        /* parse input and get user encoding parameters */
-       if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol, indexfilename) == 1) {
+       if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) {
                return EXIT_FAILURE;
        }
 
@@ -366,6 +362,7 @@ int main(int argc, char *argv[])
                        if(!dirptr->filename_buf){
                                return EXIT_FAILURE;
                        }
+
                        for(i=0;i<num_images;i++){
                                dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
                        }
@@ -373,6 +370,7 @@ int main(int argc, char *argv[])
                if(load_images(dirptr,img_fol.imgdirpath)==1){
                        return EXIT_FAILURE;
                }
+
                if (num_images==0){
                        fprintf(stdout,"Folder is empty\n");
                        return EXIT_FAILURE;
@@ -385,14 +383,14 @@ int main(int argc, char *argv[])
        if (parameters.outfile[0] != 0){
                fout = fopen(parameters.outfile,"w");
                if (!fout){
-                       fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.outfile);
+                       fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile);
                        return EXIT_FAILURE;
                }
        }
        else
                fout = stdout;
 
-       /*Encoding 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");
@@ -404,7 +402,7 @@ int main(int argc, char *argv[])
                        }
                }
 
-/*NEW V2 STYLE*/
+               /*NEW V2 STYLE*/
                /* read the input file and put it in memory */
                /* ---------------------------------------- */
                fsrc = fopen(parameters.infile, "rb");
@@ -413,10 +411,8 @@ int main(int argc, char *argv[])
                        return EXIT_FAILURE;
                }
 
-
                cio = opj_stream_create_default_file_stream(fsrc,1);
 
-
                /* decode the code-stream */
                /* ---------------------- */
 
@@ -448,11 +444,6 @@ int main(int argc, char *argv[])
                                continue;
                }
 
-               /* FIXME catch events using our callbacks and give a local context */
-               //opj_set_event_mgr_v2(dinfo, &event_mgr, stderr);
-
-
-
                /* setup the decoder decoding parameters using user parameters */
                opj_setup_decoder_v2(dinfo, &parameters, &event_mgr);
 
@@ -461,7 +452,9 @@ int main(int argc, char *argv[])
                                image = opj_decode_with_info(dinfo, cio, &cstr_info);
                        else
                        */
-               bResult = opj_read_header(      dinfo,
+               //opj_codestream_info_t *cstr_info = NULL;
+
+               /*bResult = opj_read_header(    dinfo,
                                                                        &image,
                                                                        &l_tile_x0,
                                                                        &l_tile_y0,
@@ -469,7 +462,9 @@ int main(int argc, char *argv[])
                                                                        &l_tile_height,
                                                                        &l_nb_tiles_x,
                                                                        &l_nb_tiles_y,
-                                                                       cio);
+                                                                       cio);*/
+
+               bResult = opj_read_header(cio, dinfo, &image, &cstr_info);
 
                if(!bResult){
                        fprintf(stderr, "ERROR -> j2k_to_image: failed to read header\n");
@@ -480,7 +475,7 @@ int main(int argc, char *argv[])
                        /* dump image */
                        j2k_dump_image(fout, image);
                        /* dump cp */
-                       //j2k_dump_cp(stdout, image, dinfo->m_codec);
+                       //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){
@@ -500,7 +495,7 @@ int main(int argc, char *argv[])
                fclose(fsrc);
 
                /* Write the index to disk */
-               if (*indexfilename) {
+               /*if (*indexfilename) {
                        char bSuccess;
                        bSuccess = write_index_file(&cstr_info, indexfilename);
                        if (bSuccess) {
@@ -510,7 +505,7 @@ int main(int argc, char *argv[])
                        else
                                ret = EXIT_SUCCESS;
                }
-               else
+               else*/
                        ret = EXIT_SUCCESS;
 
                /* free remaining structures */
@@ -518,10 +513,10 @@ int main(int argc, char *argv[])
                        opj_destroy_codec(dinfo);
                }
                /* free codestream information structure */
-               if (*indexfilename)     
-                       opj_destroy_cstr_info(&cstr_info);
+               /*if (*indexfilename)
+                       FIXME A GARDER opj_destroy_cstr_info(&cstr_info);*/
                /* free image data structure */
-               opj_image_destroy(image);
+               opj_image_header_destroy(image);
 
        }
 /*NEW V2 STYLE*/
@@ -532,13 +527,13 @@ int main(int argc, char *argv[])
 }
 
 
-static void j2k_dump_image(FILE *fd, opj_image_t * img) {
+static void j2k_dump_image(FILE *fd, opj_image_header_t * img) {
        int compno;
        fprintf(fd, "image {\n");
        fprintf(fd, "  x0=%d, y0=%d, x1=%d, y1=%d\n", img->x0, img->y0, img->x1, img->y1);
        fprintf(fd, "  numcomps=%d\n", img->numcomps);
        for (compno = 0; compno < img->numcomps; compno++) {
-               opj_image_comp_t *comp = &img->comps[compno];
+               opj_image_comp_header_t *comp = &img->comps[compno];
                fprintf(fd, "  comp %d {\n", compno);
                fprintf(fd, "    dx=%d, dy=%d\n", comp->dx, comp->dy);
                fprintf(fd, "    prec=%d\n", comp->prec);
@@ -549,14 +544,14 @@ static void j2k_dump_image(FILE *fd, opj_image_t * img) {
        fprintf(fd, "}\n");
 }
 
-static void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp) {
+static void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_v2_t * cp) {
        int tileno, compno, layno, bandno, resno, numbands;
        fprintf(fd, "coding parameters {\n");
        fprintf(fd, "  tx0=%d, ty0=%d\n", cp->tx0, cp->ty0);
        fprintf(fd, "  tdx=%d, tdy=%d\n", cp->tdx, cp->tdy);
        fprintf(fd, "  tw=%d, th=%d\n", cp->tw, cp->th);
        for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
-               opj_tcp_t *tcp = &cp->tcps[tileno];
+               opj_tcp_v2_t *tcp = &cp->tcps[tileno];
                fprintf(fd, "  tile %d {\n", tileno);
                fprintf(fd, "    csty=%x\n", tcp->csty);
                fprintf(fd, "    prg=%d\n", tcp->prg);
index 7ca25b1e904ffe8f8d490fbb0f0a789d7c57582d..a368c942c1eaf45c0951566ef2d520664b51e8a8 100644 (file)
@@ -31,6 +31,11 @@ opj_image_t* opj_image_create0(void) {
        return image;
 }
 
+opj_image_header_t* opj_image_header_create0(void) {
+       opj_image_header_t *image_header = (opj_image_header_t*)opj_calloc(1, sizeof(opj_image_header_t));
+       return image_header;
+}
+
 opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
        int compno;
        opj_image_t *image = NULL;
@@ -70,6 +75,7 @@ opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *c
        return image;
 }
 
+// TODO remove this one
 void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
        int i;
        if(image) {
@@ -87,26 +93,37 @@ 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) {
+                       /* image components */
+                       opj_free(image->comps);
+               }
+               opj_free(image);
+       }
+}
+
 /**
- * Updates the components of the image from the coding parameters.
+ * Updates the components characteristics of the image from the coding parameters.
  *
- * @param p_image              the image to update.
- * @param p_cp                 the coding parameters from which to update the image.
+ * @param p_image_header       the image header to update.
+ * @param p_cp                         the coding parameters from which to update the image.
  */
-void opj_image_comp_update(opj_image_t * p_image,const opj_cp_v2_t * p_cp)
+void opj_image_comp_header_update(opj_image_header_t * p_image_header, const opj_cp_v2_t * p_cp)
 {
        OPJ_UINT32 i, l_width, l_height;
-       OPJ_INT32 l_x0,l_y0,l_x1,l_y1;
-       OPJ_INT32 l_comp_x0,l_comp_y0,l_comp_x1,l_comp_y1;
-       opj_image_comp_t * l_img_comp = 00;
+       OPJ_INT32 l_x0, l_y0, l_x1, l_y1;
+       OPJ_INT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1;
+       opj_image_comp_header_t* l_img_comp = NULL;
 
-       l_x0 = int_max(p_cp->tx0 , p_image->x0);
-       l_y0 = int_max(p_cp->ty0 , p_image->y0);
-       l_x1 = int_min(p_cp->tx0 + p_cp->tw * p_cp->tdx, p_image->x1);
-       l_y1 = int_min(p_cp->ty0 + p_cp->th * p_cp->tdy, p_image->y1);
+       l_x0 = int_max(p_cp->tx0 , p_image_header->x0);
+       l_y0 = int_max(p_cp->ty0 , p_image_header->y0);
+       l_x1 = int_min(p_cp->tx0 + p_cp->tw * p_cp->tdx, p_image_header->x1);
+       l_y1 = int_min(p_cp->ty0 + p_cp->th * p_cp->tdy, p_image_header->y1);
 
-       l_img_comp = p_image->comps;
-       for     (i = 0; i < p_image->numcomps; ++i) {
+       l_img_comp = p_image_header->comps;
+       for     (i = 0; i < p_image_header->numcomps; ++i) {
                l_comp_x0 = int_ceildiv(l_x0, l_img_comp->dx);
                l_comp_y0 = int_ceildiv(l_y0, l_img_comp->dy);
                l_comp_x1 = int_ceildiv(l_x1, l_img_comp->dx);
index cb6ad650c597eeb5ed4d3a846bfd98636f8dfd07..5be33b35e671ade508502520db5cedb187a37546 100644 (file)
@@ -46,12 +46,19 @@ Create an empty image
 opj_image_t* opj_image_create0(void);
 
 /**
- * Updates the components of the image from the coding parameters.
+Create an empty image header
+@return returns an image header if successful, returns NULL otherwise
+*/
+opj_image_header_t* opj_image_header_create0(void);
+
+
+/**
+ * Updates the components characteristics of the image from the coding parameters.
  *
- * @param p_image              the image to update.
+ * @param p_image_header               the image header to update.
  * @param p_cp                 the coding parameters from which to update the image.
  */
-void opj_image_comp_update(struct opj_image * p_image,const struct opj_cp_v2 * p_cp);
+void opj_image_comp_header_update(struct opj_image_header * p_image_header, const struct opj_cp_v2* p_cp);
 
 /*@}*/
 
index 2732014e6e5252ae866f74f84ac04dcc6b54ea7b..f605ccbcc557e2ee4df385c913bd219ab475b1b5 100644 (file)
@@ -1132,9 +1132,9 @@ opj_bool j2k_read_siz_v2 (
        OPJ_UINT32 l_remaining_size;
        OPJ_UINT32 l_nb_tiles;
        OPJ_UINT32 l_tmp;
-       opj_image_t *l_image = 00;
+       opj_image_header_t *l_image = 00;
        opj_cp_v2_t *l_cp = 00;
-       opj_image_comp_t * l_img_comp = 00;
+       opj_image_comp_header_t * l_img_comp = 00;
        opj_tcp_v2_t * l_current_tile_param = 00;
 
        // preconditions
@@ -1142,7 +1142,7 @@ opj_bool j2k_read_siz_v2 (
        assert(p_manager != 00);
        assert(p_header_data != 00);
 
-       l_image = p_j2k->m_image;
+       l_image = p_j2k->m_image_header;
        l_cp = &(p_j2k->m_cp);
 
        // minimum size == 39 - 3 (= minimum component parameter)
@@ -1234,14 +1234,14 @@ opj_bool j2k_read_siz_v2 (
 #endif /* USE_JPWL */
 
        // Allocate the resulting image components
-       l_image->comps = (opj_image_comp_t*) opj_calloc(l_image->numcomps, sizeof(opj_image_comp_t));
+       l_image->comps = (opj_image_comp_header_t*) opj_calloc(l_image->numcomps, sizeof(opj_image_comp_header_t));
        if (l_image->comps == 00){
                l_image->numcomps = 0;
                opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
                return OPJ_FALSE;
        }
 
-       memset(l_image->comps,0,l_image->numcomps * sizeof(opj_image_comp_t));
+       memset(l_image->comps,0,l_image->numcomps * sizeof(opj_image_comp_header_t));
        l_img_comp = l_image->comps;
 
        // Read the component information
@@ -1419,26 +1419,26 @@ opj_bool j2k_read_siz_v2 (
        }
 
        p_j2k->m_specific_param.m_decoder.m_state =  J2K_STATE_MH; // FIXME J2K_DEC_STATE_MH;
-       opj_image_comp_update(l_image,l_cp);
+       opj_image_comp_header_update(l_image,l_cp);
 
        /* Index */
        if (p_j2k->cstr_info) {
-               opj_codestream_info_t *cstr_info = p_j2k->cstr_info;
-               cstr_info->image_w = l_image->x1 - l_image->x0;
-               cstr_info->image_h = l_image->y1 - l_image->y0;
-               cstr_info->numcomps = l_image->numcomps;
-               cstr_info->tw = l_cp->tw;
-               cstr_info->th = l_cp->th;
-               cstr_info->tile_x = l_cp->tdx;
-               cstr_info->tile_y = l_cp->tdy;
-               cstr_info->tile_Ox = l_cp->tx0;
-               cstr_info->tile_Oy = l_cp->ty0;
-               cstr_info->tile = (opj_tile_info_t*) opj_calloc(l_nb_tiles, sizeof(opj_tile_info_t));
-               if (cstr_info->tile == 00) {
+               //opj_codestream_info_t *cstr_info = p_j2k->cstr_info;
+               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");
                        return OPJ_FALSE;
                }
-               memset(cstr_info->tile,0,l_nb_tiles * sizeof(opj_tile_info_t));
+               memset(p_j2k->cstr_info->tile,0,l_nb_tiles * sizeof(opj_tile_info_t));
        }
        return OPJ_TRUE;
 }
@@ -1651,7 +1651,7 @@ opj_bool j2k_read_cod_v2 (
        OPJ_UINT32 l_tmp;
        opj_cp_v2_t *l_cp = 00;
        opj_tcp_v2_t *l_tcp = 00;
-       opj_image_t *l_image = 00;
+       opj_image_header_t *l_image = 00;
 
        // preconditions
        assert(p_header_data != 00);
@@ -1660,7 +1660,7 @@ opj_bool j2k_read_cod_v2 (
 
        l_cp = &(p_j2k->m_cp);
        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;
-       l_image = p_j2k->m_image;
+       l_image = p_j2k->m_image_header;
 
        // make sure room is sufficient
        if (p_header_size < 5) {
@@ -1704,12 +1704,12 @@ opj_bool j2k_read_cod_v2 (
 
        /* Index */
        if (p_j2k->cstr_info) {
-               opj_codestream_info_t *l_cstr_info = p_j2k->cstr_info;
-               l_cstr_info->prog = l_tcp->prg;
-               l_cstr_info->numlayers = l_tcp->numlayers;
-               l_cstr_info->numdecompos = (OPJ_INT32*) opj_malloc(l_image->numcomps * sizeof(OPJ_UINT32));
+               //opj_codestream_info_t *l_cstr_info = p_j2k->cstr_info;
+               p_j2k->cstr_info->prog = l_tcp->prg;
+               p_j2k->cstr_info->numlayers = l_tcp->numlayers;
+               p_j2k->cstr_info->numdecompos = (OPJ_INT32*) opj_malloc(l_image->numcomps * sizeof(OPJ_UINT32));
                for     (i = 0; i < l_image->numcomps; ++i) {
-                       l_cstr_info->numdecompos[i] = l_tcp->tccps[i].numresolutions - 1;
+                       p_j2k->cstr_info->numdecompos[i] = l_tcp->tccps[i].numresolutions - 1;
                }
        }
        return OPJ_TRUE;
@@ -1765,7 +1765,7 @@ opj_bool j2k_read_coc_v2 (
 {
        opj_cp_v2_t *l_cp = NULL;
        opj_tcp_v2_t *l_tcp = NULL;
-       opj_image_t *l_image = NULL;
+       opj_image_header_t *l_image = NULL;
        OPJ_UINT32 l_comp_room;
        OPJ_UINT32 l_comp_no;
 
@@ -1776,7 +1776,7 @@ opj_bool j2k_read_coc_v2 (
 
        l_cp = &(p_j2k->m_cp);
        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;
-       l_image = p_j2k->m_image;
+       l_image = p_j2k->m_image_header;
 
        l_comp_room = l_image->numcomps <= 256 ? 1 : 2;
 
@@ -2043,7 +2043,7 @@ opj_bool j2k_read_qcc_v2(
        assert(p_j2k != 00);
        assert(p_manager != 00);
 
-       l_num_comp = p_j2k->m_image->numcomps;
+       l_num_comp = p_j2k->m_image_header->numcomps;
 
 #ifdef USE_JPWL
        if (p_j2k->m_cp->correct) {
@@ -2177,7 +2177,7 @@ opj_bool j2k_read_poc_v2 (
 {
        OPJ_UINT32 i;
        OPJ_UINT32 l_nb_comp;
-       opj_image_t * l_image = 00;
+       opj_image_header_t * l_image = 00;
        OPJ_UINT32 l_old_poc_nb,l_current_poc_nb,l_current_poc_remaining;
        OPJ_UINT32 l_chunk_size;
        OPJ_UINT32 l_tmp;
@@ -2192,7 +2192,7 @@ opj_bool j2k_read_poc_v2 (
        assert(p_j2k != 00);
        assert(p_manager != 00);
 
-       l_image = p_j2k->m_image;
+       l_image = p_j2k->m_image_header;
        l_nb_comp = l_image->numcomps;
        if (l_nb_comp <= 256) {
                l_comp_room = 1;
@@ -2277,7 +2277,7 @@ opj_bool j2k_read_crg_v2 (
        assert(p_j2k != 00);
        assert(p_manager != 00);
 
-       l_nb_comp = p_j2k->m_image->numcomps;
+       l_nb_comp = p_j2k->m_image_header->numcomps;
 
        if (p_header_size != l_nb_comp *4) {
                opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading CRG marker\n");
@@ -3390,7 +3390,7 @@ opj_bool j2k_read_rgn_v2 (
                                        )
 {
        OPJ_UINT32 l_nb_comp;
-       opj_image_t * l_image = 00;
+       opj_image_header_t * l_image = 00;
 
        opj_cp_v2_t *l_cp = 00;
        opj_tcp_v2_t *l_tcp = 00;
@@ -3403,7 +3403,7 @@ opj_bool j2k_read_rgn_v2 (
        assert(p_j2k != 00);
        assert(p_manager != 00);
 
-       l_image = p_j2k->m_image;
+       l_image = p_j2k->m_image_header;
        l_nb_comp = l_image->numcomps;
 
        if (l_nb_comp <= 256) {
@@ -4460,43 +4460,32 @@ opj_bool j2k_end_decompress(
  *
  * @return true if the box is valid.
  */
-opj_bool j2k_read_header(
-                                                               opj_j2k_v2_t *p_j2k,
-                                                               struct opj_image ** p_image,
-                                                               OPJ_INT32 * p_tile_x0,
-                                                               OPJ_INT32 * p_tile_y0,
-                                                               OPJ_UINT32 * p_tile_width,
-                                                               OPJ_UINT32 * p_tile_height,
-                                                               OPJ_UINT32 * p_nb_tiles_x,
-                                                               OPJ_UINT32 * p_nb_tiles_y,
-                                                               opj_stream_private_t *p_stream,
-                                                               opj_event_mgr_t * p_manager
-                                                       )
+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,
+                                                       struct opj_event_mgr* p_manager )
 {
        // preconditions
        assert(p_j2k != 00);
        assert(p_stream != 00);
        assert(p_manager != 00);
 
+       //p_image_header = NULL;
 
-       *p_image = 00;
-       /* create an empty image */
-       p_j2k->m_image = opj_image_create0();
-       if
-               (! p_j2k->m_image)
-       {
+       /* create an empty image header */
+       p_j2k->m_image_header = opj_image_header_create0();
+       if (! p_j2k->m_image_header) {
                return OPJ_FALSE;
        }
 
        /* customization of the validation */
-       j2k_setup_decoding_validation (p_j2k);
+       j2k_setup_decoding_validation(p_j2k);
 
        /* validation of the parameters codec */
-       if
-               (! j2k_exec(p_j2k,p_j2k->m_validation_list,p_stream,p_manager))
-       {
-               opj_image_destroy(p_j2k->m_image);
-               p_j2k->m_image = 00;
+       if (! j2k_exec(p_j2k, p_j2k->m_validation_list, p_stream,p_manager)) {
+               opj_image_header_destroy(p_j2k->m_image_header);
+               p_j2k->m_image_header = NULL;
                return OPJ_FALSE;
        }
 
@@ -4504,20 +4493,22 @@ opj_bool j2k_read_header(
        j2k_setup_header_reading(p_j2k);
 
        /* read header */
-       if
-               (! j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager))
-       {
-               opj_image_destroy(p_j2k->m_image);
-               p_j2k->m_image = 00;
+       if (! j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) {
+               opj_image_header_destroy(p_j2k->m_image_header);
+               p_j2k->m_image_header = NULL;
                return OPJ_FALSE;
        }
-       *p_image = p_j2k->m_image;
-       * p_tile_x0 = p_j2k->m_cp.tx0;
-    * p_tile_y0 = p_j2k->m_cp.ty0;
-       * p_tile_width = p_j2k->m_cp.tdx;
-    * p_tile_height = p_j2k->m_cp.tdy;
-       * p_nb_tiles_x = p_j2k->m_cp.tw;
-       * p_nb_tiles_y = p_j2k->m_cp.th;
+
+       *cstr_info = p_j2k->cstr_info;
+
+       *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;
 }
 
@@ -4754,7 +4745,7 @@ opj_bool j2k_copy_default_tcp_and_create_tcd
        opj_tccp_t *l_current_tccp = 00;
        OPJ_UINT32 l_tccp_size;
        OPJ_UINT32 l_mct_size;
-       opj_image_t * l_image;
+       opj_image_header_t * l_image;
        OPJ_UINT32 l_mcc_records_size,l_mct_records_size;
        opj_mct_data_t * l_src_mct_rec, *l_dest_mct_rec;
        opj_simple_mcc_decorrelation_data_t * l_src_mcc_rec, *l_dest_mcc_rec;
@@ -4766,7 +4757,7 @@ opj_bool j2k_copy_default_tcp_and_create_tcd
        assert(p_manager != 00);
 
 
-       l_image = p_j2k->m_image;
+       l_image = p_j2k->m_image_header;
        l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw;
        l_tcp = p_j2k->m_cp.tcps;
        l_tccp_size = l_image->numcomps * sizeof(opj_tccp_t);
@@ -4862,9 +4853,7 @@ opj_bool j2k_copy_default_tcp_and_create_tcd
        {
                tcd_destroy_v2(p_j2k->m_tcd);
                p_j2k->m_tcd = 00;
-#ifdef TOTO_MSD
-               opj_event_msg(p_manager, EVT_ERROR, "Cannot decode tile, memory error\n");
-#endif
+               opj_event_msg_v2(p_manager, EVT_ERROR, "Cannot decode tile, memory error\n");
                return OPJ_FALSE;
        }
        return OPJ_TRUE;
@@ -5409,49 +5398,50 @@ opj_bool j2k_set_decode_area(
 opj_j2k_v2_t* j2k_create_decompress_v2()
 {
        opj_j2k_v2_t *l_j2k = (opj_j2k_v2_t*) opj_malloc(sizeof(opj_j2k_v2_t));
-       if
-               (!l_j2k)
-       {
+       if (!l_j2k) {
                return 00;
        }
        memset(l_j2k,0,sizeof(opj_j2k_v2_t));
+
        l_j2k->m_is_decoder = 1;
        l_j2k->m_cp.m_is_decoder = 1;
        l_j2k->m_specific_param.m_decoder.m_default_tcp = (opj_tcp_v2_t*) opj_malloc(sizeof(opj_tcp_v2_t));
-       if
-               (!l_j2k->m_specific_param.m_decoder.m_default_tcp)
-       {
+
+       if (!l_j2k->m_specific_param.m_decoder.m_default_tcp) {
                opj_free(l_j2k);
                return 00;
        }
        memset(l_j2k->m_specific_param.m_decoder.m_default_tcp,0,sizeof(opj_tcp_v2_t));
 
        l_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE *) opj_malloc(J2K_DEFAULT_HEADER_SIZE);
-       if
-               (! l_j2k->m_specific_param.m_decoder.m_header_data)
-       {
+       if (! l_j2k->m_specific_param.m_decoder.m_header_data) {
                j2k_destroy(l_j2k);
                return 00;
        }
+
        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));
+       if (!l_j2k->cstr_info){
+               opj_free(l_j2k);
+               return NULL;
+       }
+
        // validation list creation
        l_j2k->m_validation_list = opj_procedure_list_create();
-       if
-               (! l_j2k->m_validation_list)
-       {
+       if (! l_j2k->m_validation_list) {
                j2k_destroy(l_j2k);
                return 00;
        }
 
        // execution list creation
        l_j2k->m_procedure_list = opj_procedure_list_create();
-       if
-               (! l_j2k->m_procedure_list)
-       {
+       if (! l_j2k->m_procedure_list) {
                j2k_destroy(l_j2k);
                return 00;
        }
+
        return l_j2k;
 }
 
@@ -5486,7 +5476,7 @@ opj_bool j2k_read_SPCod_SPCoc(
        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;
 
        // precondition again
-       assert(compno < p_j2k->m_image->numcomps);
+       assert(compno < p_j2k->m_image_header->numcomps);
 
        l_tccp = &l_tcp->tccps[compno];
        l_current_ptr = p_header_data;
@@ -5581,7 +5571,7 @@ void j2k_copy_tile_component_parameters( opj_j2k_v2_t *p_j2k )
        l_copied_tccp = l_ref_tccp + 1;
        l_prc_size = l_ref_tccp->numresolutions * sizeof(OPJ_UINT32);
 
-       for     (i=1;i<p_j2k->m_image->numcomps;++i) {
+       for     (i=1;i<p_j2k->m_image_header->numcomps;++i) {
                l_copied_tccp->numresolutions = l_ref_tccp->numresolutions;
                l_copied_tccp->cblkw = l_ref_tccp->cblkw;
                l_copied_tccp->cblkh = l_ref_tccp->cblkh;
@@ -5627,7 +5617,7 @@ opj_bool j2k_read_SQcd_SQcc(
        l_cp = &(p_j2k->m_cp);
        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;
        // precondition again
-       assert(p_comp_no <  p_j2k->m_image->numcomps);
+       assert(p_comp_no <  p_j2k->m_image_header->numcomps);
 
        l_tccp = &l_tcp->tccps[p_comp_no];
        l_current_ptr = p_header_data;
@@ -5734,7 +5724,7 @@ void j2k_copy_tile_quantization_parameters( opj_j2k_v2_t *p_j2k )
        l_copied_tccp = l_ref_tccp + 1;
        l_size = J2K_MAXBANDS * sizeof(opj_stepsize_t);
 
-       for     (i=1;i<p_j2k->m_image->numcomps;++i) {
+       for     (i=1;i<p_j2k->m_image_header->numcomps;++i) {
                l_copied_tccp->qntsty = l_ref_tccp->qntsty;
                l_copied_tccp->numgbits = l_ref_tccp->numgbits;
                memcpy(l_copied_tccp->stepsizes,l_ref_tccp->stepsizes,l_size);
index 0b8f30d6cbeecca7af88c13fef41012907fe3ea0..e617eff540c5981392fb92f56edcbbd362cde6cc 100644 (file)
@@ -736,7 +736,8 @@ typedef struct opj_j2k_v2
        OPJ_UINT32 m_current_tile_number;
 
        /** pointer to the encoded / decoded image */
-       opj_image_t *m_image;
+       //opj_image_t *m_image;
+       opj_image_header_t* m_image_header;
 
        /** Coding parameters */
        opj_cp_v2_t m_cp;
@@ -852,18 +853,12 @@ opj_bool j2k_end_decompress(opj_j2k_t *j2k, struct opj_stream_private *cio, stru
  *
  * @return true if the box is valid.
  */
-opj_bool j2k_read_header(
-                                                               opj_j2k_v2_t *p_j2k,
-                                                               struct opj_image ** p_image,
-                                                               OPJ_INT32 * p_tile_x0,
-                                                               OPJ_INT32 * p_tile_y0,
-                                                               OPJ_UINT32 * p_tile_width,
-                                                               OPJ_UINT32 * p_tile_height,
-                                                               OPJ_UINT32 * p_nb_tiles_x,
-                                                               OPJ_UINT32 * p_nb_tiles_y,
-                                                               struct opj_stream_private *cio,
-                                                               struct opj_event_mgr * p_manager
-                                                       );
+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,
+                                                       struct opj_event_mgr* p_manager );
+
 
 /**
  * Destroys a jpeg2000 codec.
index da3fe0d288ba131e96efb8dc000868b8a187d2ab..f5e4ee23ff86b04fe46de835033f1ffc63fd9f8f 100644 (file)
 typedef struct opj_decompression
 {
        opj_bool (* opj_read_header) (
-               void *p_codec,
-               opj_image_t **,
-               OPJ_INT32 * p_tile_x0,
-               OPJ_INT32 * p_tile_y0,
-               OPJ_UINT32 * p_tile_width,
-               OPJ_UINT32 * p_tile_height,
-               OPJ_UINT32 * p_nb_tiles_x,
-               OPJ_UINT32 * p_nb_tiles_y,
-               struct opj_stream_private *cio,
-               struct opj_event_mgr * p_manager);
+                       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,
@@ -224,16 +219,11 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format)
                        l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_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;
                        l_info->m_codec_data.m_decompression.opj_read_header =  (opj_bool (*) (
-                               void *,
-                               opj_image_t **,
-                               OPJ_INT32 * ,
-                               OPJ_INT32 * ,
-                               OPJ_UINT32 * ,
-                               OPJ_UINT32 * ,
-                               OPJ_UINT32 * ,
-                               OPJ_UINT32 * ,
-                               struct opj_stream_private *,
-                               struct opj_event_mgr * )) j2k_read_header;
+                                       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_destroy = (void (*) (void *))j2k_destroy;
                        l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) j2k_setup_decoder;
                        l_info->m_codec_data.m_decompression.opj_read_tile_header = (opj_bool (*) (
@@ -547,22 +537,22 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file,
 opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_UINT32 p_size, opj_bool p_is_read_stream)
 {
        opj_stream_t* l_stream = 00;
-       if
-               (! p_file)
-       {
-               return 00;
+
+       if (! p_file) {
+               return NULL;
        }
+
        l_stream = opj_stream_create(p_size,p_is_read_stream);
-       if
-               (! l_stream)
-       {
-               return 00;
+       if (! l_stream) {
+               return NULL;
        }
-       opj_stream_set_user_data(l_stream,p_file);
-       opj_stream_set_read_function(l_stream,(opj_stream_read_fn) opj_read_from_file);
+
+       opj_stream_set_user_data(l_stream, p_file);
+       opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
        opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);
        opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);
        opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file);
+
        return l_stream;
 }
 
@@ -623,7 +613,7 @@ 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,
                                                                   opj_image_t ** p_image,
@@ -635,16 +625,14 @@ opj_bool OPJ_CALLCONV opj_read_header (
                                                                   OPJ_UINT32 * p_nb_tiles_y,
                                                                   opj_stream_t *p_cio)
 {
-       if
-               (p_codec && p_cio)
-       {
+       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;
-               if
-                       (! l_info->is_decompressor)
-               {
+
+               if(! l_info->is_decompressor) {
                        return OPJ_FALSE;
                }
+
                return l_info->m_codec_data.m_decompression.opj_read_header(
                        l_info->m_codec,
                        p_image,
@@ -655,12 +643,37 @@ opj_bool OPJ_CALLCONV opj_read_header (
                        p_nb_tiles_x,
                        p_nb_tiles_y,
                        l_cio,
-                       //&(l_info->m_event_mgr));
-                       l_info->m_event_mgr);
+                       l_info->m_event_mgr); //&(l_info->m_event_mgr));
+       }
+       return OPJ_FALSE;
+}
+#endif
+
+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     )
+
+{
+       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;
+
+               if(! l_info->is_decompressor) {
+                       return OPJ_FALSE;
+               }
+
+               return l_info->m_codec_data.m_decompression.opj_read_header(
+                                       l_cio,
+                                       l_info->m_codec,
+                                       p_image_header,
+                                       p_cstr_info,
+                                       l_info->m_event_mgr);
        }
        return OPJ_FALSE;
 }
 
+
 void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_info)
 {
        if
index 0f35fbd334b8c91736e668e78daa58df3c2d620f..2102f742351e68da2af2671590974b81c137ff34 100644 (file)
@@ -600,6 +600,75 @@ typedef struct opj_image_comptparm {
        int sgnd;
 } opj_image_cmptparm_t;
 
+
+
+/**
+Defines a single image component characteristics (uses in new API)
+*/
+typedef struct opj_image_comp_header {
+       /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
+       int dx;
+       /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
+       int dy;
+       /** data width */
+       int w;
+       /** data height */
+       int h;
+       /** x component offset compared to the whole image */
+       int x0;
+       /** y component offset compared to the whole image */
+       int y0;
+       /** precision */
+       int prec;
+       /** image depth in bits */
+       int bpp;
+       /** signed (1) / unsigned (0) */
+       int sgnd;
+       /** number of decoded resolution */
+       int resno_decoded;
+       /** number of division by 2 of the out image compared to the original size of image */
+       int factor;
+} opj_image_comp_header_t;
+
+/**
+Defines image characteristics (uses in new API)
+*/
+typedef struct opj_image_header {
+       /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
+       OPJ_UINT32 x0;
+       /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
+       OPJ_UINT32 y0;
+       /** Xsiz: width of the reference grid */
+       OPJ_UINT32 x1;
+       /** Ysiz: height of the reference grid */
+       OPJ_UINT32 y1;
+       /** number of components in the image */
+       OPJ_UINT16 numcomps;
+       /** color space: sRGB, Greyscale or YUV */
+       OPJ_COLOR_SPACE color_space;
+       /** image components */
+       opj_image_comp_header_t *comps;
+
+       /** XTOsiz */
+       OPJ_UINT32 tile_x0;
+       /** YTOsiz */
+       OPJ_UINT32 tile_y0;
+       /** XTsiz */
+       OPJ_UINT32 tile_width;
+       /** YTsiz */
+       OPJ_UINT32 tile_height;
+       /** number of tiles in width */
+       OPJ_UINT32 nb_tiles_x;
+       /** number of tiles in height */
+       OPJ_UINT32 nb_tiles_y;
+
+       /** 'restricted' ICC profile */
+       unsigned char *icc_profile_buf;
+       /** size of ICC profile */
+       int icc_profile_len;
+} opj_image_header_t;
+
+
 /* 
 ==========================================================
    Information on the JPEG 2000 codestream
@@ -777,6 +846,8 @@ 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);
+
 /* 
 ==========================================================
    stream functions definitions
@@ -1024,16 +1095,10 @@ OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info
  * @param      p_nb_tiles_x    pointer to a value that will hold the number of tiles in the x direction.
  * @param      p_nb_tiles_y    pointer to a value that will hold the number of tiles in the y direction.
  */
-OPJ_API opj_bool OPJ_CALLCONV opj_read_header (
-                                                                               opj_codec_t *p_codec,
-                                                                               opj_image_t ** p_image,
-                                                                               OPJ_INT32 * p_tile_x0,
-                                                                               OPJ_INT32 * p_tile_y0,
-                                                                               OPJ_UINT32 * p_tile_width,
-                                                                               OPJ_UINT32 * p_tile_height,
-                                                                               OPJ_UINT32 * p_nb_tiles_x,
-                                                                               OPJ_UINT32 * p_nb_tiles_y,
-                                                                               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_image_header_t **p_image_header,
+                                                                                               opj_codestream_info_t **p_cstr_info     );
 
 /**
 Destroy a decompressor handle
index f01bab75e5cb96dfdb12dcbd5ab0585ed726c9b3..f7942afcfb38e81b3e38264492247cbefd1454c3 100644 (file)
@@ -92,7 +92,7 @@ static opj_bool pi_next_cprl(opj_pi_iterator_t * pi);
  * @param      p_resolutions   pointer to an area corresponding to the one described above.
  */
 void get_all_encoding_parameters(
-                                                               const opj_image_t *p_image,
+                                                               const opj_image_header_t *p_image,
                                                                const opj_cp_v2_t *p_cp,
                                                                OPJ_UINT32 tileno,
                                                                OPJ_INT32 * p_tx0,
@@ -116,7 +116,7 @@ void get_all_encoding_parameters(
  * @param      p_tile_no       the index of the tile from which creating the packet iterator.
  */
 opj_pi_iterator_t * pi_create(
-                                                               const opj_image_t *image,
+                                                               const opj_image_header_t *image,
                                                                const opj_cp_v2_t *cp,
                                                                OPJ_UINT32 tileno
                                                        );
@@ -597,7 +597,7 @@ opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno
 
 
 opj_pi_iterator_t *pi_create_decode_v2(
-                                                                               opj_image_t *p_image,
+                                                                               opj_image_header_t *p_image,
                                                                                opj_cp_v2_t *p_cp,
                                                                                OPJ_UINT32 p_tile_no
                                                                                )
@@ -624,7 +624,7 @@ opj_pi_iterator_t *pi_create_decode_v2(
        opj_tcp_v2_t *l_tcp = 00;
        const opj_tccp_t *l_tccp = 00;
        opj_pi_comp_t *l_current_comp = 00;
-       opj_image_comp_t * l_img_comp = 00;
+       opj_image_comp_header_t * l_img_comp = 00;
        opj_pi_iterator_t * l_current_pi = 00;
        OPJ_UINT32 * l_encoding_value_ptr = 00;
 
@@ -655,10 +655,8 @@ opj_pi_iterator_t *pi_create_decode_v2(
        }
 
        // memory allocation for pi
-       l_pi = pi_create(p_image,p_cp,p_tile_no);
-       if
-               (!l_pi)
-       {
+       l_pi = pi_create(p_image, p_cp, p_tile_no);
+       if (!l_pi) {
                opj_free(l_tmp_data);
                opj_free(l_tmp_ptr);
                return 00;
@@ -743,7 +741,7 @@ opj_pi_iterator_t *pi_create_decode_v2(
                (pino = 1 ; pino<l_bound ; ++pino )
        {
                opj_pi_comp_t *l_current_comp = l_current_pi->comps;
-               opj_image_comp_t * l_img_comp = p_image->comps;
+               opj_image_comp_header_t * l_img_comp = p_image->comps;
                l_tccp = l_tcp->tccps;
 
                l_current_pi->tx0 = l_tx0;
@@ -1244,7 +1242,7 @@ opj_bool pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int p
  * @param      p_resolutions   pointer to an area corresponding to the one described above.
  */
 void get_all_encoding_parameters(
-                                                               const opj_image_t *p_image,
+                                                               const opj_image_header_t *p_image,
                                                                const opj_cp_v2_t *p_cp,
                                                                OPJ_UINT32 tileno,
                                                                OPJ_INT32 * p_tx0,
@@ -1264,7 +1262,7 @@ void get_all_encoding_parameters(
        // pointers
        const opj_tcp_v2_t *tcp = 00;
        const opj_tccp_t * l_tccp = 00;
-       const opj_image_comp_t * l_img_comp = 00;
+       const opj_image_comp_header_t * l_img_comp = 00;
 
        // to store l_dx, l_dy, w and h for each resolution and component.
        OPJ_UINT32 * lResolutionPtr;
@@ -1377,7 +1375,7 @@ void get_all_encoding_parameters(
  * @param      p_tile_no       the index of the tile from which creating the packet iterator.
  */
 opj_pi_iterator_t * pi_create(
-                                                               const opj_image_t *image,
+                                                               const opj_image_header_t *image,
                                                                const opj_cp_v2_t *cp,
                                                                OPJ_UINT32 tileno
                                                        )
@@ -1404,41 +1402,36 @@ opj_pi_iterator_t * pi_create(
        tcp = &cp->tcps[tileno];
        l_poc_bound = tcp->numpocs+1;
 
-
        // memory allocations
        l_pi = (opj_pi_iterator_t*) opj_calloc((l_poc_bound), sizeof(opj_pi_iterator_t));
-
-       if
-               (!l_pi)
-       {
-               return 00;
+       if (!l_pi) {
+               return NULL;
        }
        memset(l_pi,0,l_poc_bound * sizeof(opj_pi_iterator_t));
+
        l_current_pi = l_pi;
-       for
-               (pino = 0; pino < l_poc_bound ; ++pino)
-       {
+       for (pino = 0; pino < l_poc_bound ; ++pino) {
+
                l_current_pi->comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t));
-               if
-                       (! l_current_pi->comps)
-               {
+               if (! l_current_pi->comps) {
                        pi_destroy_v2(l_pi, l_poc_bound);
-                       return 00;
+                       return NULL;
                }
+
                l_current_pi->numcomps = image->numcomps;
                memset(l_current_pi->comps,0,image->numcomps * sizeof(opj_pi_comp_t));
-               for
-                       (compno = 0; compno < image->numcomps; ++compno)
-               {
+
+               for (compno = 0; compno < image->numcomps; ++compno) {
                        opj_pi_comp_t *comp = &l_current_pi->comps[compno];
+
                        tccp = &tcp->tccps[compno];
+
                        comp->resolutions = (opj_pi_resolution_t*) opj_malloc(tccp->numresolutions * sizeof(opj_pi_resolution_t));
-                       if
-                               (!comp->resolutions)
-                       {
+                       if (!comp->resolutions) {
                                pi_destroy_v2(l_pi, l_poc_bound);
                                return 00;
                        }
+
                        comp->numresolutions = tccp->numresolutions;
                        memset(comp->resolutions,0,tccp->numresolutions * sizeof(opj_pi_resolution_t));
                }
index 5c7b99813d3498607f05084d42c5fdbad7379c60..55b941f982817d01a2de80c8a35d4c4abe20f3cd 100644 (file)
@@ -142,7 +142,7 @@ Create a packet iterator for Decoder
 @return Returns a packet iterator that points to the first packet of the tile
 @see pi_destroy
 */
-opj_pi_iterator_t *pi_create_decode_v2(struct opj_image * image, struct opj_cp_v2 * cp, OPJ_UINT32 tileno);
+opj_pi_iterator_t *pi_create_decode_v2(struct opj_image_header * image, struct opj_cp_v2 * cp, OPJ_UINT32 tileno);
 
 
 /**
index 93a296b743abfdbbc53b73494628f0d12ac0a5d7..90fbf90d6a269b6110c6f896dc85185f12232178 100644 (file)
@@ -846,7 +846,7 @@ opj_bool t2_decode_packets_v2(
        OPJ_BYTE *l_current_data = p_src;
        opj_pi_iterator_t *l_pi = 00;
        OPJ_UINT32 pino;
-       opj_image_t *l_image = p_t2->image;
+       opj_image_header_t *l_image = p_t2->image;
        opj_cp_v2_t *l_cp = p_t2->cp;
        opj_cp_v2_t *cp = p_t2->cp;
        opj_tcp_v2_t *l_tcp = &(p_t2->cp->tcps[p_tile_no]);
@@ -856,56 +856,46 @@ opj_bool t2_decode_packets_v2(
        OPJ_UINT32 curtp = 0;
        OPJ_UINT32 tp_start_packno;
        opj_packet_info_t *l_pack_info = 00;
-       opj_image_comp_t* l_img_comp = 00;
+       opj_image_comp_header_t* l_img_comp = 00;
 
 
-       if
-               (p_cstr_info)
-       {
+       if (p_cstr_info) {
                l_pack_info = p_cstr_info->tile[p_tile_no].packet;
        }
 
        /* create a packet iterator */
        l_pi = pi_create_decode_v2(l_image, l_cp, p_tile_no);
-       if
-               (!l_pi)
-       {
+       if (!l_pi) {
                return OPJ_FALSE;
        }
 
        tp_start_packno = 0;
        l_current_pi = l_pi;
 
-       for
-               (pino = 0; pino <= l_tcp->numpocs; ++pino)
-       {
-               while
-                       (pi_next(l_current_pi))
-               {
+       for     (pino = 0; pino <= l_tcp->numpocs; ++pino) {
 
-                       if
-                               (l_tcp->num_layers_to_decode > l_current_pi->layno && l_current_pi->resno < p_tile->comps[l_current_pi->compno].minimum_num_resolutions)
-                       {
+               while (pi_next(l_current_pi)) {
+
+                       if (l_tcp->num_layers_to_decode > l_current_pi->layno
+                                       && l_current_pi->resno < p_tile->comps[l_current_pi->compno].minimum_num_resolutions) {
                                l_nb_bytes_read = 0;
-                               if
-                                       (! t2_decode_packet_v2(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info))
-                               {
+
+                               if (! t2_decode_packet_v2(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info)) {
                                        pi_destroy_v2(l_pi,l_nb_pocs);
                                        return OPJ_FALSE;
                                }
+
                                l_img_comp = &(l_image->comps[l_current_pi->compno]);
                                l_img_comp->resno_decoded = uint_max(l_current_pi->resno, l_img_comp->resno_decoded);
                        }
-                       else
-                       {
+                       else {
                                l_nb_bytes_read = 0;
-                               if
-                                       (! t2_skip_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info))
-                               {
+                               if (! t2_skip_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info)) {
                                        pi_destroy_v2(l_pi,l_nb_pocs);
                                        return OPJ_FALSE;
                                }
                        }
+
                        l_current_data += l_nb_bytes_read;
                        p_max_len -= l_nb_bytes_read;
 
@@ -965,7 +955,7 @@ opj_t2_t* t2_create(opj_common_ptr cinfo, opj_image_t *image, opj_cp_t *cp) {
  * @return             a new T2 handle if successful, NULL otherwise.
 */
 opj_t2_v2_t* t2_create_v2(
-                                       opj_image_t *p_image,
+                                       opj_image_header_t *p_image,
                                        opj_cp_v2_t *p_cp)
 {
        /* create the tcd structure */
@@ -1010,27 +1000,27 @@ static opj_bool t2_decode_packet_v2(
 
        *p_data_read = 0;
 
-       if
-               (! t2_read_packet_header(p_t2,p_tile,p_tcp,p_pi,&l_read_data,p_src,&l_nb_bytes_read,p_max_length,p_pack_info))
-       {
+       if (! t2_read_packet_header(p_t2,p_tile,p_tcp,p_pi,&l_read_data,p_src,&l_nb_bytes_read,p_max_length,p_pack_info)) {
                return OPJ_FALSE;
        }
+
        p_src += l_nb_bytes_read;
        l_nb_total_bytes_read += l_nb_bytes_read;
        p_max_length -= l_nb_bytes_read;
+
        /* we should read data for the packet */
-       if
-               (l_read_data)
-       {
+       if (l_read_data) {
                l_nb_bytes_read = 0;
-               if
-                       (! t2_read_packet_data(p_t2,p_tile,p_pi,p_src,&l_nb_bytes_read,p_max_length,p_pack_info))
-               {
+
+               if (! t2_read_packet_data(p_t2,p_tile,p_pi,p_src,&l_nb_bytes_read,p_max_length,p_pack_info)) {
                        return OPJ_FALSE;
                }
+
                l_nb_total_bytes_read += l_nb_bytes_read;
        }
+
        *p_data_read = l_nb_total_bytes_read;
+
        return OPJ_FALSE;
 }
 
index fd68331ecce3ba6846048d6ad4cdb3730226bc59..b130746ff4fad9a56367ae31ba15d0f165aba75f 100644 (file)
@@ -60,7 +60,7 @@ typedef struct opj_t2_v2 {
        opj_common_ptr cinfo;
 
        /** Encoding: pointer to the src image. Decoding: pointer to the dst image. */
-       opj_image_t *image;
+       opj_image_header_t *image;
        /** pointer to the image coding parameters */
        opj_cp_v2_t *cp;
 } opj_t2_v2_t;
@@ -113,7 +113,7 @@ opj_bool t2_decode_packets_v2(opj_t2_v2_t *t2, OPJ_UINT32 tileno,struct opj_tcd_
  * @param      p_cp            Image coding parameters.
  * @return             a new T2 handle if successful, NULL otherwise.
 */
-opj_t2_v2_t* t2_create_v2(struct opj_image *p_image, opj_cp_v2_t *p_cp);
+opj_t2_v2_t* t2_create_v2(struct opj_image_header *p_image, opj_cp_v2_t *p_cp);
 
 /**
 Create a T2 handle
index 5a0f0f4dae355fa9285352d27ba533e9b0b16420..1eeba0028ce7cc0463d612c83b41009b8f274ac8 100644 (file)
@@ -1583,35 +1583,31 @@ void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno) {
 }
 
 
-opj_bool tcd_init_v2(
-                                          opj_tcd_v2_t *p_tcd,
-                                          opj_image_t * p_image,
-                                          opj_cp_v2_t * p_cp
-                                          )
+opj_bool tcd_init_v2(  opj_tcd_v2_t *p_tcd,
+                                          opj_image_header_t * p_image_header,
+                                          opj_cp_v2_t * p_cp )
 {
        OPJ_UINT32 l_tile_comp_size;
 
-       p_tcd->image = p_image;
+       p_tcd->image_header = p_image_header;
        p_tcd->cp = p_cp;
        p_tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_malloc(sizeof(opj_tcd_tile_t));
 
-       if
-               (! p_tcd->tcd_image->tiles)
-       {
+       if (! p_tcd->tcd_image->tiles) {
                return OPJ_FALSE;
        }
        memset(p_tcd->tcd_image->tiles,0, sizeof(opj_tcd_tile_t));
 
-       l_tile_comp_size = p_image->numcomps * sizeof(opj_tcd_tilecomp_t);
+       l_tile_comp_size = p_image_header->numcomps * sizeof(opj_tcd_tilecomp_t);
        p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_t *) opj_malloc(l_tile_comp_size);
-       if
-               (! p_tcd->tcd_image->tiles->comps )
-       {
+       if (! p_tcd->tcd_image->tiles->comps ) {
                return OPJ_FALSE;
        }
        memset( p_tcd->tcd_image->tiles->comps , 0 , l_tile_comp_size);
-       p_tcd->tcd_image->tiles->numcomps = p_image->numcomps;
+
+       p_tcd->tcd_image->tiles->numcomps = p_image_header->numcomps;
        p_tcd->tp_pos = p_cp->m_specific_param.m_enc.m_tp_pos;
+
        return OPJ_TRUE;
 }
 
@@ -1663,7 +1659,7 @@ opj_bool FUNCTION                                                                                                                         \
        opj_stepsize_t * l_step_size = 00;                                                                              \
        opj_tcd_precinct_t *l_current_precinct = 00;                                                    \
        TYPE* l_code_block = 00;                                                                                                \
-       opj_image_t *   l_image = 00;                                                                                   \
+       opj_image_header_t *    l_image = 00;                                                                                   \
        OPJ_UINT32 p,q;                                                                                                                 \
        OPJ_UINT32 l_level_no;                                                                                                  \
        OPJ_UINT32 l_pdx, l_pdy;                                                                                                \
@@ -1686,8 +1682,8 @@ opj_bool FUNCTION                                                                                                                         \
        l_tile = p_tcd->tcd_image->tiles;                                                                               \
        l_tccp = l_tcp->tccps;                                                                                                  \
        l_tilec = l_tile->comps;                                                                                                \
-       l_image = p_tcd->image;                                                                                                 \
-       l_image_comp = p_tcd->image->comps;                                                                             \
+       l_image = p_tcd->image_header;                                                                                                  \
+       l_image_comp = p_tcd->image_header->comps;                                                                              \
                                                                                                                                                        \
        p = p_tile_no % l_cp->tw;       /* tile coordinates */                                          \
        q = p_tile_no / l_cp->tw;                                                                                               \
@@ -2014,15 +2010,15 @@ OPJ_UINT32 tcd_get_decoded_tile_size (
 {
        OPJ_UINT32 i;
        OPJ_UINT32 l_data_size = 0;
-       opj_image_comp_t * l_img_comp = 00;
+       opj_image_comp_header_t * l_img_comp = 00;
        opj_tcd_tilecomp_t * l_tile_comp = 00;
        opj_tcd_resolution_t * l_res = 00;
        OPJ_UINT32 l_size_comp, l_remaining;
 
        l_tile_comp = p_tcd->tcd_image->tiles->comps;
-       l_img_comp = p_tcd->image->comps;
+       l_img_comp = p_tcd->image_header->comps;
        for
-               (i=0;i<p_tcd->image->numcomps;++i)
+               (i=0;i<p_tcd->image_header->numcomps;++i)
        {
                l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/
                l_remaining = l_img_comp->prec & 7;  /* (%8) */
@@ -2136,7 +2132,7 @@ opj_bool tcd_update_tile_data (
                                                 )
 {
        OPJ_UINT32 i,j,k,l_data_size = 0;
-       opj_image_comp_t * l_img_comp = 00;
+       opj_image_comp_header_t * l_img_comp = 00;
        opj_tcd_tilecomp_t * l_tilec = 00;
        opj_tcd_resolution_t * l_res;
        OPJ_UINT32 l_size_comp, l_remaining;
@@ -2150,9 +2146,9 @@ opj_bool tcd_update_tile_data (
        }
 
        l_tilec = p_tcd->tcd_image->tiles->comps;
-       l_img_comp = p_tcd->image->comps;
+       l_img_comp = p_tcd->image_header->comps;
        for
-               (i=0;i<p_tcd->image->numcomps;++i)
+               (i=0;i<p_tcd->image_header->numcomps;++i)
        {
                l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/
                l_remaining = l_img_comp->prec & 7;  /* (%8) */
@@ -2405,7 +2401,7 @@ opj_bool tcd_t2_decode (
 {
        opj_t2_v2_t * l_t2;
 
-       l_t2 = t2_create_v2(p_tcd->image, p_tcd->cp);
+       l_t2 = t2_create_v2(p_tcd->image_header, p_tcd->cp);
        if
                (l_t2 == 00)
        {
@@ -2469,7 +2465,7 @@ opj_bool tcd_dwt_decode (
        opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles;
        opj_tcd_tilecomp_t * l_tile_comp = l_tile->comps;
        opj_tccp_t * l_tccp = p_tcd->tcp->tccps;
-       opj_image_comp_t * l_img_comp = p_tcd->image->comps;
+       opj_image_comp_header_t * l_img_comp = p_tcd->image_header->comps;
 
        for
                (compno = 0; compno < l_tile->numcomps; compno++)
@@ -2555,7 +2551,7 @@ opj_bool tcd_mct_decode (
                                                                // nb of components (i.e. size of pData)
                                                                l_tile->numcomps,
                                                                // tells if the data is signed
-                                                               p_tcd->image->comps->sgnd))
+                                                               p_tcd->image_header->comps->sgnd))
                {
                        opj_free(l_data);
                        return OPJ_FALSE;
@@ -2593,7 +2589,7 @@ opj_bool tcd_dc_level_shift_decode (
        OPJ_UINT32 compno;
        opj_tcd_tilecomp_t * l_tile_comp = 00;
        opj_tccp_t * l_tccp = 00;
-       opj_image_comp_t * l_img_comp = 00;
+       opj_image_comp_header_t * l_img_comp = 00;
        opj_tcd_resolution_t* l_res = 00;
        opj_tcp_v2_t * l_tcp = 00;
        opj_tcd_tile_t * l_tile;
@@ -2606,7 +2602,7 @@ opj_bool tcd_dc_level_shift_decode (
        l_tile_comp = l_tile->comps;
        l_tcp = p_tcd->tcp;
        l_tccp = p_tcd->tcp->tccps;
-       l_img_comp = p_tcd->image->comps;
+       l_img_comp = p_tcd->image_header->comps;
 
        for
                (compno = 0; compno < l_tile->numcomps; compno++)
index 6489ddeba2870ed03b54c4d17a2a365d07fdb9d9..09c184ac674b85d5bd607b4a99de7cfaf7ba33bb 100644 (file)
@@ -283,8 +283,8 @@ typedef struct opj_tcd_v2
        OPJ_UINT32 cur_pino;
        /** info on each image tile */
        opj_tcd_image_t *tcd_image;
-       /** image */
-       struct opj_image *image;
+       /** image header */
+       struct opj_image_header *image_header;
        /** coding parameters */
        struct opj_cp_v2 *cp;
        /** coding/decoding parameters common to all tiles */
@@ -335,7 +335,7 @@ void tcd_destroy_v2(opj_tcd_v2_t *tcd);
 opj_bool tcd_init_v2(
                                                opj_tcd_v2_t *p_tcd,
                                                //struct opj_image * p_image,
-                                               opj_image_t * p_image,
+                                               opj_image_header_t * p_image_header,
                                                //struct opj_cp * p_cp
                                                opj_cp_v2_t * p_cp
                                        );