[MJ2] Avoid index out of bounds access to pi->include[]
[openjpeg.git] / src / lib / openmj2 / mj2.h
index 15e0ed238c65174288263b244636df753363e5f3..8e08f0b5e73c0477d027ecc69e020596ff1284ae 100644 (file)
@@ -80,7 +80,7 @@
 Decompressed format used in parameters
 YUV = 0
 */
-#define YUV_DFMT 1 
+#define YUV_DFMT 1
 
 /**
 Compressed format used in parameters
@@ -95,208 +95,208 @@ MJ2 = 0
 Time To Sample
 */
 typedef struct mj2_tts {
-  int sample_count;
-  int sample_delta;
+    int sample_count;
+    int sample_delta;
 } mj2_tts_t;
 
 /**
 Chunk
 */
-typedef struct mj2_chunk {             
-  unsigned int num_samples;
-  int sample_descr_idx;
-  int offset;
+typedef struct mj2_chunk {
+    unsigned int num_samples;
+    int sample_descr_idx;
+    int offset;
 } mj2_chunk_t;
 
 /**
 Sample to chunk
 */
-typedef struct mj2_sampletochunk {             
-  unsigned int first_chunk;
-  unsigned int samples_per_chunk;
-  int sample_descr_idx;
+typedef struct mj2_sampletochunk {
+    unsigned int first_chunk;
+    unsigned int samples_per_chunk;
+    int sample_descr_idx;
 } mj2_sampletochunk_t;
 
 /**
 Sample
 */
-typedef struct mj2_sample {            
-  unsigned int sample_size;
-  unsigned int offset;
-  unsigned int sample_delta;
+typedef struct mj2_sample {
+    unsigned int sample_size;
+    unsigned int offset;
+    unsigned int sample_delta;
 } mj2_sample_t;
 
 /**
 URL
 */
 typedef struct mj2_url {
-  int location[4];
+    int location[4];
 } mj2_url_t;
 
 /**
 URN
 */
-typedef struct mj2_urn {               
-  int name[2];
-  int location[4];
+typedef struct mj2_urn {
+    int name[2];
+    int location[4];
 } mj2_urn_t;
 
 /**
 Video Track Parameters
 */
 typedef struct mj2_tk {
-       /** codec context */
-       opj_common_ptr cinfo;
-  int track_ID;
-  int track_type;
-  unsigned int creation_time;
-  unsigned int modification_time;
-  int duration;
-  int timescale;
-  int layer;
-  int volume;
-  int language;
-  int balance;
-  int maxPDUsize;
-  int avgPDUsize;
-  int maxbitrate;
-  int avgbitrate;
-  int slidingavgbitrate;
-  int graphicsmode;
-  int opcolor[3];
-  int num_url;
-  mj2_url_t *url;
-  int num_urn;
-  mj2_urn_t *urn;
-  int Dim[2];
-  int w;
-  int h;
-  int visual_w;
-  int visual_h;
-  int CbCr_subsampling_dx;
-  int CbCr_subsampling_dy;
-  int sample_rate;
-  int sample_description;
-  int horizresolution;
-  int vertresolution;
-  int compressorname[8];
-  int depth;
-  unsigned char fieldcount;
-  unsigned char fieldorder;
-  unsigned char or_fieldcount;
-  unsigned char or_fieldorder;
-  int num_br;
-  unsigned int *br;
-  unsigned char num_jp2x;
-  unsigned char *jp2xdata;
-  unsigned char hsub;
-  unsigned char vsub;
-  unsigned char hoff;
-  unsigned char voff;
-  int trans_matrix[9];
-       /** Number of samples */
-  unsigned int num_samples;    
-  int transorm;
-  int handler_type;
-  int name_size;
-  unsigned char same_sample_size;
-  int num_tts;
-       /** Time to sample    */
-  mj2_tts_t *tts;              
-  unsigned int num_chunks;
-  mj2_chunk_t *chunk;
-  unsigned int num_samplestochunk;
-  mj2_sampletochunk_t *sampletochunk;
-  char *name;
-  opj_jp2_t jp2_struct;
-       /** Sample parameters */
-  mj2_sample_t *sample;                
-} mj2_tk_t;                    
+    /** codec context */
+    opj_common_ptr cinfo;
+    int track_ID;
+    int track_type;
+    unsigned int creation_time;
+    unsigned int modification_time;
+    int duration;
+    int timescale;
+    int layer;
+    int volume;
+    int language;
+    int balance;
+    int maxPDUsize;
+    int avgPDUsize;
+    int maxbitrate;
+    int avgbitrate;
+    int slidingavgbitrate;
+    int graphicsmode;
+    int opcolor[3];
+    int num_url;
+    mj2_url_t *url;
+    int num_urn;
+    mj2_urn_t *urn;
+    int Dim[2];
+    int w;
+    int h;
+    int visual_w;
+    int visual_h;
+    int CbCr_subsampling_dx;
+    int CbCr_subsampling_dy;
+    int sample_rate;
+    int sample_description;
+    int horizresolution;
+    int vertresolution;
+    int compressorname[8];
+    int depth;
+    unsigned char fieldcount;
+    unsigned char fieldorder;
+    unsigned char or_fieldcount;
+    unsigned char or_fieldorder;
+    int num_br;
+    unsigned int *br;
+    unsigned char num_jp2x;
+    unsigned char *jp2xdata;
+    unsigned char hsub;
+    unsigned char vsub;
+    unsigned char hoff;
+    unsigned char voff;
+    int trans_matrix[9];
+    /** Number of samples */
+    unsigned int num_samples;
+    int transorm;
+    int handler_type;
+    int name_size;
+    unsigned char same_sample_size;
+    int num_tts;
+    /** Time to sample    */
+    mj2_tts_t *tts;
+    unsigned int num_chunks;
+    mj2_chunk_t *chunk;
+    unsigned int num_samplestochunk;
+    mj2_sampletochunk_t *sampletochunk;
+    char *name;
+    opj_jp2_t jp2_struct;
+    /** Sample parameters */
+    mj2_sample_t *sample;
+} mj2_tk_t;
 
 /**
 MJ2 box
 */
 typedef struct mj2_box {
-  int length;
-  int type;
-  int init_pos;
+    int length;
+    int type;
+    int init_pos;
 } mj2_box_t;
 
 /**
 MJ2 Movie
 */
-typedef struct opj_mj2 {               
-       /** codec context */
-       opj_common_ptr cinfo;
-       /** handle to the J2K codec  */
-       opj_j2k_t *j2k;
-  unsigned int brand;
-  unsigned int minversion;
-  int num_cl;
-  unsigned int *cl;
-  unsigned int creation_time;
-  unsigned int modification_time;
-  int timescale;
-  unsigned int duration;
-  int rate;
-  int num_vtk;
-  int num_stk;
-  int num_htk;
-  int volume;
-  int trans_matrix[9];
-  int next_tk_id;
-       /** Track Parameters  */
-  mj2_tk_t *tk;                        
+typedef struct opj_mj2 {
+    /** codec context */
+    opj_common_ptr cinfo;
+    /** handle to the J2K codec  */
+    opj_j2k_t *j2k;
+    unsigned int brand;
+    unsigned int minversion;
+    int num_cl;
+    unsigned int *cl;
+    unsigned int creation_time;
+    unsigned int modification_time;
+    int timescale;
+    unsigned int duration;
+    int rate;
+    int num_vtk;
+    int num_stk;
+    int num_htk;
+    int volume;
+    int trans_matrix[9];
+    int next_tk_id;
+    /** Track Parameters  */
+    mj2_tk_t *tk;
 } opj_mj2_t;
 
 /**
 Decompression parameters
 */
 typedef struct mj2_dparameters {
-       /**@name command line encoder parameters (not used inside the library) */
-       /*@{*/
-       /** input file name */
-       char infile[OPJ_PATH_LEN];
-       /** output file name */
-       char outfile[OPJ_PATH_LEN];     
-       /** J2K decompression parameters */
-       opj_dparameters_t j2k_parameters;       
+    /**@name command line encoder parameters (not used inside the library) */
+    /*@{*/
+    /** input file name */
+    char infile[OPJ_PATH_LEN];
+    /** output file name */
+    char outfile[OPJ_PATH_LEN];
+    /** J2K decompression parameters */
+    opj_dparameters_t j2k_parameters;
 } mj2_dparameters_t;
 
 /**
 Compression parameters
 */
 typedef struct mj2_cparameters {
-       /**@name command line encoder parameters (not used inside the library) */
-       /*@{*/
-       /** J2K compression parameters */
-       opj_cparameters_t j2k_parameters;       
-       /** input file name */
-       char infile[OPJ_PATH_LEN];
-       /** output file name */
-       char outfile[OPJ_PATH_LEN];     
-       /** input file format 0:MJ2 */
-       int decod_format;
-       /** output file format 0:YUV */
-       int cod_format;
-       /** Portion of the image coded */
-       int Dim[2];
-       /** YUV Frame width */
-       int w;
-       /** YUV Frame height */
-       int h;
-       /*   Sample rate of YUV 4:4:4, 4:2:2 or 4:2:0 */
-       int CbCr_subsampling_dx;        
-       /*   Sample rate of YUV 4:4:4, 4:2:2 or 4:2:0 */
-  int CbCr_subsampling_dy;     
-       /*   Video Frame Rate  */
-  int frame_rate;              
-       /*   In YUV files, numcomps always considered as 3 */
-  int numcomps;                        
-       /*   In YUV files, precision always considered as 8 */
-  int prec;            
-  unsigned int meth;
-  unsigned int enumcs;
+    /**@name command line encoder parameters (not used inside the library) */
+    /*@{*/
+    /** J2K compression parameters */
+    opj_cparameters_t j2k_parameters;
+    /** input file name */
+    char infile[OPJ_PATH_LEN];
+    /** output file name */
+    char outfile[OPJ_PATH_LEN];
+    /** input file format 0:MJ2 */
+    int decod_format;
+    /** output file format 0:YUV */
+    int cod_format;
+    /** Portion of the image coded */
+    int Dim[2];
+    /** YUV Frame width */
+    int w;
+    /** YUV Frame height */
+    int h;
+    /*   Sample rate of YUV 4:4:4, 4:2:2 or 4:2:0 */
+    int CbCr_subsampling_dx;
+    /*   Sample rate of YUV 4:4:4, 4:2:2 or 4:2:0 */
+    int CbCr_subsampling_dy;
+    /*   Video Frame Rate  */
+    int frame_rate;
+    /*   In YUV files, numcomps always considered as 3 */
+    int numcomps;
+    /*   In YUV files, precision always considered as 8 */
+    int prec;
+    unsigned int meth;
+    unsigned int enumcs;
 } mj2_cparameters_t;
 
 
@@ -304,32 +304,33 @@ typedef struct mj2_cparameters {
 /*@{*/
 /* ----------------------------------------------------------------------- */
 /**
-Write the JP box 
+Write the JP box
 */
-void mj2_write_jp(opj_cio_t *cio);
+OPJ_API void OPJ_CALLCONV mj2_write_jp(opj_cio_t *cio);
 /**
 Write the FTYP box
 @param movie MJ2 movie
 @param cio Output buffer stream
 */
-void mj2_write_ftyp(opj_mj2_t *movie, opj_cio_t *cio);
+OPJ_API void OPJ_CALLCONV mj2_write_ftyp(opj_mj2_t *movie, opj_cio_t *cio);
 /**
 Creates an MJ2 decompression structure
 @return Returns a handle to a MJ2 decompressor if successful, returns NULL otherwise
 */
-opj_dinfo_t* mj2_create_decompress();
+OPJ_API opj_dinfo_t* OPJ_CALLCONV mj2_create_decompress();
 /**
 Destroy a MJ2 decompressor handle
 @param movie MJ2 decompressor handle to destroy
 */
-void mj2_destroy_decompress(opj_mj2_t *movie);
+OPJ_API void OPJ_CALLCONV mj2_destroy_decompress(opj_mj2_t *movie);
 /**
 Setup the decoder decoding parameters using user parameters.
-Decoding parameters are returned in mj2->j2k->cp. 
+Decoding parameters are returned in mj2->j2k->cp.
 @param movie MJ2 decompressor handle
 @param mj2_parameters decompression parameters
 */
-void mj2_setup_decoder(opj_mj2_t *movie, mj2_dparameters_t *mj2_parameters);
+OPJ_API void OPJ_CALLCONV mj2_setup_decoder(opj_mj2_t *movie,
+        mj2_dparameters_t *mj2_parameters);
 /**
 Decode an image from a JPEG-2000 file stream
 @param movie MJ2 decompressor handle
@@ -341,19 +342,20 @@ opj_image_t* mj2_decode(opj_mj2_t *movie, opj_cio_t *cio);
 Creates a MJ2 compression structure
 @return Returns a handle to a MJ2 compressor if successful, returns NULL otherwise
 */
-opj_cinfo_t* mj2_create_compress();
+OPJ_API opj_cinfo_t* OPJ_CALLCONV mj2_create_compress();
 /**
 Destroy a MJ2 compressor handle
 @param movie MJ2 compressor handle to destroy
 */
-void mj2_destroy_compress(opj_mj2_t *movie);
+OPJ_API void OPJ_CALLCONV mj2_destroy_compress(opj_mj2_t *movie);
 /**
-Setup the encoder parameters using the current image and using user parameters. 
-Coding parameters are returned in mj2->j2k->cp. 
+Setup the encoder parameters using the current image and using user parameters.
+Coding parameters are returned in mj2->j2k->cp.
 @param movie MJ2 compressor handle
 @param parameters compression parameters
 */
-void mj2_setup_encoder(opj_mj2_t *movie, mj2_cparameters_t *parameters);
+OPJ_API void OPJ_CALLCONV mj2_setup_encoder(opj_mj2_t *movie,
+        mj2_cparameters_t *parameters);
 /**
 Encode an image into a JPEG-2000 file stream
 @param movie MJ2 compressor handle
@@ -362,27 +364,28 @@ Encode an image into a JPEG-2000 file stream
 @param index Name of the index file if required, NULL otherwise
 @return Returns true if successful, returns false otherwise
 */
-opj_bool mj2_encode(opj_mj2_t *movie, opj_cio_t *cio, opj_image_t *image, char *index);
+opj_bool mj2_encode(opj_mj2_t *movie, opj_cio_t *cio, opj_image_t *image,
+                    char *index);
 
 /**
 Init a Standard MJ2 movie
 @param movie MJ2 Movie
 @return Returns 0 if successful, returns 1 otherwise
 */
-int mj2_init_stdmovie(opj_mj2_t *movie);
+OPJ_API int OPJ_CALLCONV mj2_init_stdmovie(opj_mj2_t *movie);
 /**
 Read the structure of an MJ2 file
 @param file MJ2 input File
-@param mj2 J2 movie structure 
+@param mj2 J2 movie structure
 @return Returns 0 if successful, returns 1 otherwise
 */
-int mj2_read_struct(FILE *file, opj_mj2_t *mj2);
+OPJ_API int OPJ_CALLCONV mj2_read_struct(FILE *file, opj_mj2_t *mj2);
 /**
-Write the the MOOV box to an output buffer stream
-@param movie MJ2 movie structure 
+Write the MOOV box to an output buffer stream
+@param movie MJ2 movie structure
 @param cio Output buffer stream
 */
-void mj2_write_moov(opj_mj2_t *movie, opj_cio_t *cio);
+OPJ_API void OPJ_CALLCONV mj2_write_moov(opj_mj2_t *movie, opj_cio_t *cio);
 
 
 /* ----------------------------------------------------------------------- */