-typedef struct {
- int dx, dy; /* XRsiz, YRsiz */
- int w, h; /* width and height of data */
- int x0, y0; /* offset of the component compare to the whole image */
- int prec; /* precision */
- int bpp; /* deapth of image in bits */
- int sgnd; /* signed */
- int resno_decoded; /* number of decoded resolution */
- int factor; /* number of division by 2 of the out image compare to the original size of image */
- int *data; /* image-component data */
-} j2k_comp_t;
-
-typedef struct {
- int x0, y0; /* XOsiz, YOsiz */
- int x1, y1; /* Xsiz, Ysiz */
- int numcomps; /* number of components */
- int color_space; /* sRGB, Greyscale or YUV */
- j2k_comp_t *comps; /* image-components */
-} j2k_image_t;
-
-typedef struct {
- int expn; /* exponent */
- int mant; /* mantissa */
-} j2k_stepsize_t;
-
-typedef struct {
- int csty; /* coding style */
- int numresolutions; /* number of resolutions */
- int cblkw; /* width of code-blocks */
- int cblkh; /* height of code-blocks */
- int cblksty; /* code-block coding style */
- int qmfbid; /* discrete wavelet transform identifier */
- int qntsty; /* quantisation style */
- j2k_stepsize_t stepsizes[J2K_MAXBANDS]; /* stepsizes used for quantization */
- int numgbits; /* number of guard bits */
- int roishift; /* Region Of Interest shift */
- int prcw[J2K_MAXRLVLS]; /* Precinct width */
- int prch[J2K_MAXRLVLS]; /* Precinct height */
-} j2k_tccp_t;
-
-typedef struct {
- int resno0, compno0;
- int layno1, resno1, compno1;
- int prg;
- int tile;
- char progorder[4];
-} j2k_poc_t;
-
-typedef struct {
- int first; /* 1 : first part-tile of a tile */
- int csty; /* coding style */
- int prg; /* progression order */
- int numlayers; /* number of layers */
- int mct; /* multi-component transform identifier */
- int rates[100]; /* rates of layers */
- int numpocs; /* number of progression order changes */
- int POC; /* Precise if a POC marker has been used O:NO, 1:YES */
- j2k_poc_t pocs[32]; /* progression order changes */
- unsigned char *ppt_data; /* packet header store there for futur use in t2_decode_packet */
- unsigned char *ppt_data_first; /* pointer remaining on the first byte of the first header if ppt is used */
- int ppt; /* If ppt == 1 --> there was a PPT marker for the present tile */
- int ppt_store; /* Use in case of multiple marker PPT (number of info already store) */
- int ppt_len; /* ppmbug1 */
- float distoratio[100]; /* add fixed_quality */
- j2k_tccp_t *tccps; /* tile-component coding parameters */
-} j2k_tcp_t;
-
-typedef struct {
- int intermed_file; /* 1: Store each encoded tile one by one in the output file (for mega-Images)*/
- int decod_format; /* 0: PGX, 1: PxM, 2: BMP */
- int cod_format; /* 0: J2K, 1: JP2, 2: JPT */
- int disto_alloc; /* Allocation by rate/distortion */
- int fixed_alloc; /* Allocation by fixed layer */
- int fixed_quality; /* add fixed_quality */
- int reduce; /* if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */
- int layer; /* if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */
- int index_on; /* 0 = no index || 1 = index */
- int tx0, ty0; /* XTOsiz, YTOsiz */
- int tdx, tdy; /* XTsiz, YTsiz */
- char *comment; /* comment for coding */
- int tw, th; /* number of tiles in width and heigth */
- int *tileno; /* ID number of the tiles present in the codestream */
- int tileno_size; /* size of the vector tileno */
- unsigned char *ppm_data; /* packet header store there for futur use in t2_decode_packet */
- unsigned char *ppm_data_first; /* pointer remaining on the first byte of the first header if ppm is used */
- int ppm; /* If ppm == 1 --> there was a PPM marker for the present tile */
- int ppm_store; /* Use in case of multiple marker PPM (number of info already store) */
- int ppm_previous; /* Use in case of multiple marker PPM (case on non-finished previous info) */
- int ppm_len; /* ppmbug1 */
- j2k_tcp_t *tcps; /* tile coding parameters */
- int *matrice; /* Fixed layer */
-} j2k_cp_t;
-
-typedef struct {
- int start_pos, end_pos; /* start and end position */
- double disto; /* ADD for Marcela */
-} info_packet; /* Index struct */
-
-typedef struct {
- double *thresh; /* value of thresh for each layer by tile cfr. Marcela */
- int num_tile; /* Number of Tile */
- int start_pos; /* Start position */
- int end_header; /* End position of the header */
- int end_pos; /* End position */
- int pw[33], ph[33]; /* precinct number for each resolution level */
-
- int pdx[33], pdy[33]; /* precinct size (in power of 2), in X and Y for each resolution level */
- info_packet *packet; /* information concerning packets inside tile */
- int nbpix; /* add fixed_quality */
- double distotile; /* add fixed_quality */
-} info_tile; /* index struct */
-
-typedef struct {
+/* ----------------------------------------------------------------------- */
+
+#define J2K_MS_SOC 0xff4f /**< SOC marker value */
+#define J2K_MS_SOT 0xff90 /**< SOT marker value */
+#define J2K_MS_SOD 0xff93 /**< SOD marker value */
+#define J2K_MS_EOC 0xffd9 /**< EOC marker value */
+#define J2K_MS_SIZ 0xff51 /**< SIZ marker value */
+#define J2K_MS_COD 0xff52 /**< COD marker value */
+#define J2K_MS_COC 0xff53 /**< COC marker value */
+#define J2K_MS_RGN 0xff5e /**< RGN marker value */
+#define J2K_MS_QCD 0xff5c /**< QCD marker value */
+#define J2K_MS_QCC 0xff5d /**< QCC marker value */
+#define J2K_MS_POC 0xff5f /**< POC marker value */
+#define J2K_MS_TLM 0xff55 /**< TLM marker value */
+#define J2K_MS_PLM 0xff57 /**< PLM marker value */
+#define J2K_MS_PLT 0xff58 /**< PLT marker value */
+#define J2K_MS_PPM 0xff60 /**< PPM marker value */
+#define J2K_MS_PPT 0xff61 /**< PPT marker value */
+#define J2K_MS_SOP 0xff91 /**< SOP marker value */
+#define J2K_MS_EPH 0xff92 /**< EPH marker value */
+#define J2K_MS_CRG 0xff63 /**< CRG marker value */
+#define J2K_MS_COM 0xff64 /**< COM marker value */
+
+/* ----------------------------------------------------------------------- */
+
+/**
+Values that specify the status of the decoding process when decoding the main header.
+These values may be combined with a | operator.
+*/
+typedef enum J2K_STATUS {
+ J2K_STATE_MHSOC = 0x0001, /**< a SOC marker is expected */
+ J2K_STATE_MHSIZ = 0x0002, /**< a SIZ marker is expected */
+ J2K_STATE_MH = 0x0004, /**< the decoding process is in the main header */
+ J2K_STATE_TPHSOT = 0x0008, /**< the decoding process is in a tile part header and expects a SOT marker */
+ J2K_STATE_TPH = 0x0010, /**< the decoding process is in a tile part header */
+ J2K_STATE_MT = 0x0020, /**< the EOC marker has just been read */
+ J2K_STATE_NEOC = 0x0040 /**< the decoding process must not expect a EOC marker because the codestream is truncated */
+} J2K_STATUS;
+
+/* ----------------------------------------------------------------------- */
+
+/**
+Quantization stepsize
+*/
+typedef struct opj_stepsize {
+ /** exponent */
+ int expn;
+ /** mantissa */
+ int mant;
+} opj_stepsize_t;
+
+/**
+Tile-component coding parameters
+*/
+typedef struct opj_tccp {
+ /** coding style */
+ int csty;
+ /** number of resolutions */
+ int numresolutions;
+ /** code-blocks width */
+ int cblkw;
+ /** code-blocks height */
+ int cblkh;
+ /** code-block coding style */
+ int cblksty;
+ /** discrete wavelet transform identifier */
+ int qmfbid;
+ /** quantisation style */
+ int qntsty;
+ /** stepsizes used for quantization */
+ opj_stepsize_t stepsizes[J2K_MAXBANDS];
+ /** number of guard bits */
+ int numgbits;
+ /** Region Of Interest shift */
+ int roishift;
+ /** precinct width */
+ int prcw[J2K_MAXRLVLS];
+ /** precinct height */
+ int prch[J2K_MAXRLVLS];
+} opj_tccp_t;
+
+/**
+Tile coding parameters :
+this structure is used to store coding/decoding parameters common to all
+tiles (information like COD, COC in main header)
+*/
+typedef struct opj_tcp {
+ /** 1 : first part-tile of a tile */
+ int first;
+ /** coding style */
+ int csty;
+ /** progression order */
+ OPJ_PROG_ORDER prg;
+ /** number of layers */
+ int numlayers;
+ /** multi-component transform identifier */
+ int mct;
+ /** rates of layers */
+ int rates[100];
+ /** number of progression order changes */
+ int numpocs;
+ /** indicates if a POC marker has been used O:NO, 1:YES */
+ int POC;
+ /** progression order changes */
+ opj_poc_t pocs[32];
+ /** packet header store there for futur use in t2_decode_packet */
+ unsigned char *ppt_data;
+ /** pointer remaining on the first byte of the first header if ppt is used */
+ unsigned char *ppt_data_first;
+ /** If ppt == 1 --> there was a PPT marker for the present tile */
+ int ppt;
+ /** used in case of multiple marker PPT (number of info already stored) */
+ int ppt_store;
+ /** ppmbug1 */
+ int ppt_len;
+ /** add fixed_quality */
+ float distoratio[100];
+ /** tile-component coding parameters */
+ opj_tccp_t *tccps;
+} opj_tcp_t;
+
+/**
+Coding parameters
+*/
+typedef struct opj_cp {
+ /** allocation by rate/distortion */
+ int disto_alloc;
+ /** allocation by fixed layer */
+ int fixed_alloc;
+ /** add fixed_quality */
+ int fixed_quality;
+ /** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */
+ int reduce;
+ /** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */
+ int layer;
+ /** 0 = no index || 1 = index */