Implement writing of IMF profiles
[openjpeg.git] / src / lib / openjp3d / jp3d.h
old mode 100755 (executable)
new mode 100644 (file)
index edd27a1..2f47ffe
-/*\r
- * Copyright (c) 2001-2003, David Janssens\r
- * Copyright (c) 2002-2003, Yannick Verschueren\r
- * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe\r
- * Copyright (c) 2005, Herve Drolon, FreeImage Team\r
- * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium\r
- * Copyright (c) 2006, M�nica D�ez Garc�a, Image Processing Laboratory, University of Valladolid, Spain\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- *    notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the\r
- *    documentation and/or other materials provided with the distribution.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'\r
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
- * POSSIBILITY OF SUCH DAMAGE.\r
- */\r
-#ifndef __J3D_H\r
-#define __J3D_H\r
-/**\r
-@file jp3d.h\r
-@brief The JPEG-2000 Codestream Reader/Writer (J3D)\r
-\r
-The functions in J3D.C have for goal to read/write the several parts of the codestream: markers and data.\r
-*/\r
-\r
-/** @defgroup J3D J3D - JPEG-2000 PART 10 codestream reader/writer */\r
-/*@{*/\r
-\r
-#define J3D_CP_CSTY_PRT 0x01\r
-#define J3D_CP_CSTY_SOP 0x02\r
-#define J3D_CP_CSTY_EPH 0x04\r
-#define J3D_CCP_CSTY_PRT 0x01\r
-/** Table A-8 */\r
-#define J3D_CCP_CBLKSTY_LAZY 0x01       /* Selective arithmetic coding bypass */\r
-#define J3D_CCP_CBLKSTY_RESET 0x02   /* Reset context probabilities on coding pass boundaries */\r
-#define J3D_CCP_CBLKSTY_TERMALL 0x04 /* Termination on each coding pass */\r
-#define J3D_CCP_CBLKSTY_VSC 0x08        /* Vertically causal context, add also hook for switching off and on 3D context models */      \r
-#define J3D_CCP_CBLKSTY_PTERM 0x10      /* Predictable termination */\r
-#define J3D_CCP_CBLKSTY_SEGSYM 0x20     /* Segmentation symbols are used */\r
-#define J3D_CCP_CBLKSTY_3DCTXT 0x40  /* 3D context models (3D-EBCOT) vs 2D context models */\r
-\r
-#define J3D_CCP_QNTSTY_NOQNT 0 /* Quantization style : no quantization */\r
-#define J3D_CCP_QNTSTY_SIQNT 1 /* Quantization style : scalar derived (values signalled only in LLL subband) */\r
-#define J3D_CCP_QNTSTY_SEQNT 2 /* Quantization style : scalar expounded (values signalled for each subband) */\r
-\r
-/* ----------------------------------------------------------------------- */\r
-\r
-#define J3D_MS_SOC 0xff4f      /**< SOC marker value */\r
-#define J3D_MS_SOT 0xff90      /**< SOT marker value */\r
-#define J3D_MS_SOD 0xff93      /**< SOD marker value */\r
-#define J3D_MS_EOC 0xffd9      /**< EOC marker value */\r
-#define J3D_MS_CAP 0xff50      /**< CAP marker value */\r
-#define J3D_MS_SIZ 0xff51      /**< SIZ marker value */\r
-#define J3D_MS_NSI 0xff54      /**< NSI marker value */\r
-#define J3D_MS_COD 0xff52      /**< COD marker value */\r
-#define J3D_MS_COC 0xff53      /**< COC marker value */\r
-#define J3D_MS_RGN 0xff5e      /**< RGN marker value */\r
-#define J3D_MS_QCD 0xff5c      /**< QCD marker value */\r
-#define J3D_MS_QCC 0xff5d      /**< QCC marker value */\r
-#define J3D_MS_POC 0xff5f      /**< POC marker value */\r
-#define J3D_MS_TLM 0xff55      /**< TLM marker value */\r
-#define J3D_MS_PLM 0xff57      /**< PLM marker value */\r
-#define J3D_MS_PLT 0xff58      /**< PLT marker value */\r
-#define J3D_MS_PPM 0xff60      /**< PPM marker value */\r
-#define J3D_MS_PPT 0xff61      /**< PPT marker value */\r
-#define J3D_MS_SOP 0xff91      /**< SOP marker value */\r
-#define J3D_MS_EPH 0xff92      /**< EPH marker value */\r
-#define J3D_MS_CRG 0xff63      /**< CRG marker value */\r
-#define J3D_MS_COM 0xff64      /**< COM marker value */\r
-/*15444-2*/\r
-#define J3D_MS_DCO 0xff70      /**< DCO marker value */\r
-#define J3D_MS_VMS 0xff71   /**< VMS marker value */\r
-#define J3D_MS_DFS 0xff72      /**< DFS marker value */\r
-#define J3D_MS_ADS 0xff73      /**< ADS marker value */\r
-#define J3D_MS_ATK 0xff79      /**< ATK marker value */\r
-#define J3D_MS_CBD 0xff78      /**< CBD marker value */\r
-#define J3D_MS_MCT 0xff74      /**< MCT marker value */\r
-#define J3D_MS_MCC 0xff75      /**< MCC marker value */\r
-#define J3D_MS_MCO 0xff77      /**< MCO marker value */\r
-#define J3D_MS_NLT 0xff76      /**< NLT marker value */\r
-#define J3D_MS_QPD 0xff5a      /**< QPD marker value */\r
-#define J3D_MS_QPC 0xff5b      /**< QPC marker value */\r
-\r
-/* ----------------------------------------------------------------------- */\r
-/* Capability RSIZ parameter, extended */\r
-#define J3D_RSIZ_BASIC 0x0000\r
-\r
-#define J3D_RSIZ_DCO   0x8001 /* Required */\r
-#define J3D_RSIZ_VSQNT 0x8002\r
-#define J3D_RSIZ_TCQNT 0x8004\r
-#define J3D_RSIZ_VMASK 0x8008\r
-#define J3D_RSIZ_SSOVL 0x8010\r
-#define J3D_RSIZ_ADECS 0x8020\r
-#define J3D_RSIZ_ATK   0x8040 /*Required*/\r
-#define J3D_RSIZ_SSYMK 0x8080\r
-#define J3D_RSIZ_MCT   0x8100 /*Not compatible with DCO*/\r
-#define J3D_RSIZ_NLT   0x8200 /*Required*/\r
-#define J3D_RSIZ_ASHAP 0x8400\r
-#define J3D_RSIZ_PRQNT 0x8800\r
-\r
-#define J3D_CAP_10             0x00400000\r
-/* Arbitrary transformation kernel, 15444-2 */\r
-#define J3D_ATK_IRR 0\r
-#define J3D_ATK_REV 1\r
-#define J3D_ATK_ARB 0\r
-#define J3D_ATK_WS 1\r
-#define J3D_ATK_CON 0\r
-/* ----------------------------------------------------------------------- */\r
-\r
-/**\r
-Values that specify the status of the decoding process when decoding the main header. \r
-These values may be combined with a | operator. \r
-*/\r
-typedef enum J3D_STATUS {\r
-       /**< a SOC marker is expected */\r
-       J3D_STATE_MHSOC  = 0x0001, \r
-       /**< a SIZ marker is expected */\r
-       J3D_STATE_MHSIZ  = 0x0002, \r
-       /**< the decoding process is in the main header */\r
-       J3D_STATE_MH     = 0x0004, \r
-       /**< the decoding process is in a tile part header and expects a SOT marker */\r
-       J3D_STATE_TPHSOT = 0x0008, \r
-       /**< the decoding process is in a tile part header */\r
-       J3D_STATE_TPH    = 0x0010, \r
-       /**< the EOC marker has just been read */\r
-       J3D_STATE_MT     = 0x0020, \r
-       /**< the decoding process must not expect a EOC marker because the codestream is truncated */\r
-       J3D_STATE_NEOC   = 0x0040  \r
-} J3D_STATUS;\r
-\r
-\r
-\r
-/**\r
-Arbitrary transformation kernel\r
-*/\r
-typedef struct opj_atk {\r
-/** index of wavelet kernel */\r
-       int index;\r
-/** Numerical type of scaling factor and lifting step parameters */\r
-       int coeff_typ;          \r
-/** Wavelet filter category */\r
-       int filt_cat;           \r
-/** Wavelet transformation type (REV/IRR) */\r
-       int wt_typ;                     \r
-/** Initial odd/even subsequence */\r
-       int minit;                      \r
-/** Boundary extension method (constant CON / whole-sample symmetric WS) */\r
-       int exten;                      \r
-/** Scaling factor. Only for wt_typ=IRR */\r
-       double Katk;                    \r
-/** Number of lifting steps */\r
-       int Natk;                       \r
-/** Offset for lifting step s. Only for filt_cat=ARB */\r
-       int Oatk[256];          \r
-/** Base 2 scaling exponent for lifting step s. Only for wt_typ=REV */\r
-       int Eatk[256];          \r
-/** Additive residue for lifting step s. Only for wt_typ=REV */\r
-       int Batk[256];          \r
-/** Number of lifting coefficients signaled for lifting step s  */\r
-       int LCatk[256]; \r
-/** Lifting coefficient k for lifting step s */\r
-       double Aatk[256][256];  \r
-} opj_atk_t;\r
-\r
-\r
-/**\r
-Quantization stepsize\r
-*/\r
-typedef struct opj_stepsize {\r
-/** exponent */\r
-       int expn;       \r
-/** mantissa */\r
-       int mant;       \r
-} opj_stepsize_t;\r
-\r
-/**\r
-Tile-component coding parameters\r
-*/\r
-typedef struct opj_tccp {\r
-       /** coding style */\r
-       int csty;                                                       \r
-       /** number of resolutions of x, y and z-axis */\r
-       int numresolution[3];   \r
-       /** code-blocks width height & depth*/\r
-       int cblk[3];                    \r
-       /** code-block coding style */\r
-       int cblksty;                    \r
-       /** 0: no ATK (only 9-7 or 5-3) 1: ATK defined WT*/\r
-       int atk_wt[3];                          \r
-       /** Arbitrary transformation kernel (15444-2)*/\r
-       opj_atk_t *atk;                 \r
-       /** DWT identifier for x, y and z-axis (0:WT9-7 1:WT5-3 >1:WT-atk->index) */\r
-       int dwtid[3];\r
-       /** reversible/irreversible wavelet transfomation (0:irrev 1:reversible)*/      \r
-       int reversible;                 \r
-       /** quantisation style */\r
-       int qntsty;                             \r
-       /** stepsizes used for quantization */\r
-       opj_stepsize_t stepsizes[J3D_MAXBANDS]; \r
-       /** number of guard bits. Table A28 de 15444-1*/\r
-       int numgbits;                   \r
-       /** Region Of Interest shift */\r
-       int roishift;                   \r
-       /** precinct width heigth & depth*/\r
-       int prctsiz[3][J3D_MAXRLVLS];           \r
-} opj_tccp_t;\r
-\r
-/**\r
-Tile coding parameters : coding/decoding parameters common to all tiles \r
-(information like COD, COC in main header)\r
-*/\r
-typedef struct opj_tcp {\r
-/** 1 : first part-tile of a tile */\r
-       int first;                              \r
-       /** coding style */\r
-       int csty;                               \r
-       /** progression order */\r
-       OPJ_PROG_ORDER prg;             \r
-       /** number of layers */\r
-       int numlayers;                  \r
-       /** multi-component transform identifier */\r
-       int mct;                                \r
-       /** rates of layers */\r
-       float rates[100];                       \r
-       /** number of progression order changes */\r
-       int numpocs;                    \r
-       /** indicates if a POC marker has been used O:NO, 1:YES */\r
-       int POC;                                \r
-       /** progression order changes */\r
-       opj_poc_t pocs[J3D_MAXRLVLS - 1];\r
-       /** add fixed_quality */\r
-       float distoratio[100];\r
-       /** tile-component coding parameters */\r
-       opj_tccp_t *tccps;              \r
-/** packet header store there for futur use in t2_decode_packet */\r
-       unsigned char *ppt_data;                \r
-       /** pointer remaining on the first byte of the first header if ppt is used */\r
-       unsigned char *ppt_data_first;  \r
-       /** If ppt == 1 --> there was a PPT marker for the present tile */\r
-       int ppt;                \r
-       /** used in case of multiple marker PPT (number of info already stored) */\r
-       int ppt_store;  \r
-       int ppt_len;    \r
-} opj_tcp_t;\r
-\r
-/**\r
-Coding parameters\r
-*/\r
-typedef struct opj_cp {\r
-/** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */\r
-       OPJ_TRANSFORM transform_format;         \r
-       /** entropy coding format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/\r
-       OPJ_ENTROPY_CODING encoding_format;     \r
-       /** allocation by rate/distortion */\r
-       int disto_alloc;        \r
-       /** allocation by fixed layer */\r
-       int fixed_alloc;        \r
-       /** add fixed_quality */\r
-       int fixed_quality;      \r
-       /** Rsiz: capabilities */\r
-       int rsiz;                       \r
-       /** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, volume is decoded to the full resolution */\r
-       int reduce[3];          \r
-       /** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */\r
-       int layer;                      \r
-       /** 0 = no index || 1 = index */\r
-       int index_on;           \r
-       /** Big-Endian/Little-endian order */\r
-       int bigendian;\r
-       /** XTOsiz */\r
-       int tx0;        \r
-       /** YTOsiz */\r
-       int ty0;                \r
-       /** ZTOsiz */\r
-       int tz0;        \r
-       /** XTsiz */\r
-       int tdx;        \r
-       /** YTsiz */\r
-       int tdy;        \r
-       /** ZTsiz */\r
-       int tdz;        \r
-       /** comment for coding */\r
-       char *comment;          \r
-       /** number of tiles in width, heigth and depth */\r
-       int tw;         \r
-       int th;\r
-       int tl;\r
-       /** ID number of the tiles present in the codestream */\r
-       int *tileno;    \r
-       /** size of the vector tileno */\r
-       int tileno_size;\r
-       /** tile coding parameters */\r
-       opj_tcp_t *tcps;\r
-       /** fixed layer */\r
-       int *matrice;           \r
-\r
-       /** packet header store there for futur use in t2_decode_packet */\r
-       unsigned char *ppm_data;                \r
-       /** pointer remaining on the first byte of the first header if ppm is used */\r
-       unsigned char *ppm_data_first;  \r
-       /** if ppm == 1 --> there was a PPM marker for the present tile */\r
-       int ppm;                        \r
-       /** use in case of multiple marker PPM (number of info already store) */\r
-       int ppm_store;          \r
-       /** use in case of multiple marker PPM (case on non-finished previous info) */\r
-       int ppm_previous;       \r
-       int ppm_len;            \r
-} opj_cp_t;\r
-\r
-/**\r
-Information concerning a packet inside tile\r
-*/\r
-typedef struct opj_packet_info {\r
-       /** start position */\r
-       int start_pos;  \r
-       /** end position */\r
-       int end_pos;    \r
-       /** distorsion introduced */\r
-       double disto;   \r
-} opj_packet_info_t;\r
-\r
-/**\r
-Index structure : information regarding tiles inside volume\r
-*/\r
-typedef struct opj_tile_info {\r
-       /** value of thresh for each layer by tile cfr. Marcela   */\r
-       double *thresh;         \r
-       /** number of tile */\r
-       int num_tile;           \r
-       /** start position */\r
-       int start_pos;          \r
-       /** end position of the header */\r
-       int end_header;         \r
-       /** end position */\r
-       int end_pos;            \r
-       /** precinct number for each resolution level (width, heigth and depth) */\r
-       int prctno[3][J3D_MAXRLVLS];    \r
-       /** precinct size (in power of 2), in X for each resolution level */\r
-       int prctsiz[3][J3D_MAXRLVLS];   \r
-       /** information concerning packets inside tile */\r
-       opj_packet_info_t *packet;              \r
-       \r
-       /** add fixed_quality */\r
-       int nbpix;                      \r
-       /** add fixed_quality */\r
-       double distotile;       \r
-} opj_tile_info_t;\r
-\r
-/**\r
-Index structure\r
-*/\r
-typedef struct opj_volume_info {\r
-       \r
-       /** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */\r
-       OPJ_TRANSFORM transform_format;         \r
-       /** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/\r
-       OPJ_ENTROPY_CODING encoding_format;     /** 0 = no index || 1 = index */\r
-       int index_on;   \r
-       /** 0 = wt 9-7 || 1 = wt 5-3 || >=2 wt atk defined */\r
-       int dwtid[3];   \r
-       /** maximum distortion reduction on the whole volume (add for Marcela) */\r
-       double D_max;   \r
-       /** packet number */\r
-       int num;                \r
-       /** writing the packet in the index with t2_encode_packets */\r
-       int index_write;        \r
-       /** volume width, height and depth */\r
-       int volume_w;   \r
-       int volume_h;\r
-       int volume_l;\r
-       /** progression order */\r
-       OPJ_PROG_ORDER prog;    \r
-       /** tile size in x, y and z */\r
-       int tile_x;             \r
-       int tile_y;\r
-       int tile_z;\r
-       /** tile origin in x, y and z */\r
-       int tile_Ox;    \r
-       int tile_Oy;\r
-       int tile_Oz;\r
-       /** number of tiles in X, Y and Z */\r
-       int tw;                 \r
-       int th;\r
-       int tl;\r
-       /** component numbers */\r
-       int comp;                               \r
-       /** number of layer */\r
-       int layer;                              \r
-       /** number of decomposition in X, Y and Z*/\r
-       int decomposition[3];   \r
-       /** DC offset (15444-2) */\r
-       int dcoffset;   \r
-       /** main header position */\r
-       int main_head_end;              \r
-       /** codestream's size */\r
-       int codestream_size;    \r
-       /** information regarding tiles inside volume */\r
-       opj_tile_info_t *tile;  \r
-} opj_volume_info_t;\r
-\r
-/**\r
-JPEG-2000 codestream reader/writer\r
-*/\r
-typedef struct opj_j3d {\r
-       /** codec context */\r
-       opj_common_ptr cinfo;   \r
-       /** locate in which part of the codestream the decoder is (main header, tile header, end) */\r
-       int state;                              \r
-       /** number of the tile curently concern by coding/decoding */\r
-       int curtileno;                  \r
-       /** locate the position of the end of the tile in the codestream, used to detect a truncated codestream (in j3d_read_sod)       */\r
-       unsigned char *eot;     \r
-       /**     locate the start position of the SOT marker of the current coded tile:  */\r
-       int sot_start;          \r
-       /*  after encoding the tile, a jump (in j3d_write_sod) is done to the SOT marker to store the value of its length. */\r
-       int sod_start;          \r
-       /**     as the J3D-file is written in several parts during encoding, it enables to make the right correction in position return by cio_tell     */\r
-       int pos_correction;     \r
-       /** array used to store the data of each tile */\r
-       unsigned char **tile_data;      \r
-       /** array used to store the length of each tile */\r
-       int *tile_len;                          \r
-\r
-       /** decompression only : store decoding parameters common to all tiles */\r
-       opj_tcp_t *default_tcp;         \r
-       /** pointer to the encoded / decoded volume */\r
-       opj_volume_t *volume;           \r
-       /** pointer to the coding parameters */\r
-       opj_cp_t *cp;                           \r
-       /** helper used to write the index file */\r
-       opj_volume_info_t *volume_info; \r
-       /** pointer to the byte i/o stream */\r
-    opj_cio_t *cio;                                            \r
-} opj_j3d_t;\r
-\r
-/** @name Funciones generales */\r
-/*@{*/\r
-/* ----------------------------------------------------------------------- */\r
-/**\r
-Creates a J3D decompression structure\r
-@param cinfo Codec context info\r
-@return Returns a handle to a J3D decompressor if successful, returns NULL otherwise\r
-*/\r
-opj_j3d_t* j3d_create_decompress(opj_common_ptr cinfo);\r
-/**\r
-Destroy a J3D decompressor handle\r
-@param j3d J3D decompressor handle to destroy\r
-*/\r
-void j3d_destroy_decompress(opj_j3d_t *j3d);\r
-/**\r
-Setup the decoder decoding parameters using user parameters.\r
-Decoding parameters are returned in j3d->cp. \r
-@param j3d J3D decompressor handle\r
-@param parameters decompression parameters\r
-*/\r
-void j3d_setup_decoder(opj_j3d_t *j3d, opj_dparameters_t *parameters);\r
-/**\r
-Decode an volume from a JPEG-2000 codestream\r
-@param j3d J3D decompressor handle\r
-@param cio Input buffer stream\r
-@return Returns a decoded volume if successful, returns NULL otherwise\r
-*/\r
-opj_volume_t* j3d_decode(opj_j3d_t *j3d, opj_cio_t *cio);\r
-/**\r
-Decode an volume form a JPT-stream (JPEG 2000, JPIP)\r
-@param j3d J3D decompressor handle\r
-@param cio Input buffer stream\r
-@return Returns a decoded volume if successful, returns NULL otherwise\r
-*/\r
-opj_volume_t* j3d_decode_jpt_stream(opj_j3d_t *j3d, opj_cio_t *cio);\r
-/**\r
-Creates a J3D compression structure\r
-@param cinfo Codec context info\r
-@return Returns a handle to a J3D compressor if successful, returns NULL otherwise\r
-*/\r
-opj_j3d_t* j3d_create_compress(opj_common_ptr cinfo);\r
-/**\r
-Destroy a J3D compressor handle\r
-@param j3d J3D compressor handle to destroy\r
-*/\r
-void j3d_destroy_compress(opj_j3d_t *j3d);\r
-/**\r
-Setup the encoder parameters using the current volume and using user parameters. \r
-Coding parameters are returned in j3d->cp. \r
-@param j3d J3D compressor handle\r
-@param parameters compression parameters\r
-@param volume input filled volume\r
-*/\r
-void j3d_setup_encoder(opj_j3d_t *j3d, opj_cparameters_t *parameters, opj_volume_t *volume);\r
-/**\r
-Encode an volume into a JPEG-2000 codestream\r
-@param j3d J3D compressor handle\r
-@param cio Output buffer stream\r
-@param volume Volume to encode\r
-@param index Name of the index file if required, NULL otherwise\r
-@return Returns true if successful, returns false otherwise\r
-*/\r
-bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume, char *index);\r
-/* ----------------------------------------------------------------------- */\r
-/*@}*/\r
-\r
-/*@}*/\r
-\r
-#endif /* __J3D_H */\r
+/*
+ * The copyright in this software is being made available under the 2-clauses
+ * BSD License, included below. This software may be subject to other third
+ * party and contributor rights, including patent rights, and no such rights
+ * are granted under this license.
+ *
+ * Copyright (c) 2001-2003, David Janssens
+ * Copyright (c) 2002-2003, Yannick Verschueren
+ * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
+ * Copyright (c) 2005, Herve Drolon, FreeImage Team
+ * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
+ * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef __J3D_H
+#define __J3D_H
+/**
+@file jp3d.h
+@brief The JPEG-2000 Codestream Reader/Writer (J3D)
+
+The functions in J3D.C have for goal to read/write the several parts of the codestream: markers and data.
+*/
+
+/** @defgroup J3D J3D - JPEG-2000 PART 10 codestream reader/writer */
+/*@{*/
+
+#define J3D_CP_CSTY_PRT 0x01
+#define J3D_CP_CSTY_SOP 0x02
+#define J3D_CP_CSTY_EPH 0x04
+#define J3D_CCP_CSTY_PRT 0x01
+/** Table A-8 */
+#define J3D_CCP_CBLKSTY_LAZY 0x01    /* Selective arithmetic coding bypass */
+#define J3D_CCP_CBLKSTY_RESET 0x02   /* Reset context probabilities on coding pass boundaries */
+#define J3D_CCP_CBLKSTY_TERMALL 0x04 /* Termination on each coding pass */
+#define J3D_CCP_CBLKSTY_VSC 0x08     /* Vertically causal context, add also hook for switching off and on 3D context models */
+#define J3D_CCP_CBLKSTY_PTERM 0x10   /* Predictable termination */
+#define J3D_CCP_CBLKSTY_SEGSYM 0x20  /* Segmentation symbols are used */
+#define J3D_CCP_CBLKSTY_3DCTXT 0x40  /* 3D context models (3D-EBCOT) vs 2D context models */
+
+#define J3D_CCP_QNTSTY_NOQNT 0  /* Quantization style : no quantization */
+#define J3D_CCP_QNTSTY_SIQNT 1  /* Quantization style : scalar derived (values signalled only in LLL subband) */
+#define J3D_CCP_QNTSTY_SEQNT 2  /* Quantization style : scalar expounded (values signalled for each subband) */
+
+/* ----------------------------------------------------------------------- */
+
+#define J3D_MS_SOC 0xff4f   /**< SOC marker value */
+#define J3D_MS_SOT 0xff90   /**< SOT marker value */
+#define J3D_MS_SOD 0xff93   /**< SOD marker value */
+#define J3D_MS_EOC 0xffd9   /**< EOC marker value */
+#define J3D_MS_CAP 0xff50   /**< CAP marker value */
+#define J3D_MS_SIZ 0xff51   /**< SIZ marker value */
+#define J3D_MS_NSI 0xff54   /**< NSI marker value */
+#define J3D_MS_COD 0xff52   /**< COD marker value */
+#define J3D_MS_COC 0xff53   /**< COC marker value */
+#define J3D_MS_RGN 0xff5e   /**< RGN marker value */
+#define J3D_MS_QCD 0xff5c   /**< QCD marker value */
+#define J3D_MS_QCC 0xff5d   /**< QCC marker value */
+#define J3D_MS_POC 0xff5f   /**< POC marker value */
+#define J3D_MS_TLM 0xff55   /**< TLM marker value */
+#define J3D_MS_PLM 0xff57   /**< PLM marker value */
+#define J3D_MS_PLT 0xff58   /**< PLT marker value */
+#define J3D_MS_PPM 0xff60   /**< PPM marker value */
+#define J3D_MS_PPT 0xff61   /**< PPT marker value */
+#define J3D_MS_SOP 0xff91   /**< SOP marker value */
+#define J3D_MS_EPH 0xff92   /**< EPH marker value */
+#define J3D_MS_CRG 0xff63   /**< CRG marker value */
+#define J3D_MS_COM 0xff64   /**< COM marker value */
+/*15444-2*/
+#define J3D_MS_DCO 0xff70   /**< DCO marker value */
+#define J3D_MS_VMS 0xff71   /**< VMS marker value */
+#define J3D_MS_DFS 0xff72   /**< DFS marker value */
+#define J3D_MS_ADS 0xff73   /**< ADS marker value */
+#define J3D_MS_ATK 0xff79   /**< ATK marker value */
+#define J3D_MS_CBD 0xff78   /**< CBD marker value */
+#define J3D_MS_MCT 0xff74   /**< MCT marker value */
+#define J3D_MS_MCC 0xff75   /**< MCC marker value */
+#define J3D_MS_MCO 0xff77   /**< MCO marker value */
+#define J3D_MS_NLT 0xff76   /**< NLT marker value */
+#define J3D_MS_QPD 0xff5a   /**< QPD marker value */
+#define J3D_MS_QPC 0xff5b   /**< QPC marker value */
+
+/* ----------------------------------------------------------------------- */
+/* Capability RSIZ parameter, extended */
+#define J3D_RSIZ_BASIC 0x0000
+
+#define J3D_RSIZ_DCO   0x8001 /* Required */
+#define J3D_RSIZ_VSQNT 0x8002
+#define J3D_RSIZ_TCQNT 0x8004
+#define J3D_RSIZ_VMASK 0x8008
+#define J3D_RSIZ_SSOVL 0x8010
+#define J3D_RSIZ_ADECS 0x8020
+#define J3D_RSIZ_ATK   0x8040 /*Required*/
+#define J3D_RSIZ_SSYMK 0x8080
+#define J3D_RSIZ_MCT   0x8100 /*Not compatible with DCO*/
+#define J3D_RSIZ_NLT   0x8200 /*Required*/
+#define J3D_RSIZ_ASHAP 0x8400
+#define J3D_RSIZ_PRQNT 0x8800
+
+#define J3D_CAP_10      0x00400000
+/* Arbitrary transformation kernel, 15444-2 */
+#define J3D_ATK_IRR 0
+#define J3D_ATK_REV 1
+#define J3D_ATK_ARB 0
+#define J3D_ATK_WS 1
+#define J3D_ATK_CON 0
+/* ----------------------------------------------------------------------- */
+
+/**
+Values that specify the status of the decoding process when decoding the main header.
+These values may be combined with a | operator.
+*/
+typedef enum J3D_STATUS {
+    /**< a SOC marker is expected */
+    J3D_STATE_MHSOC  = 0x0001,
+    /**< a SIZ marker is expected */
+    J3D_STATE_MHSIZ  = 0x0002,
+    /**< the decoding process is in the main header */
+    J3D_STATE_MH     = 0x0004,
+    /**< the decoding process is in a tile part header and expects a SOT marker */
+    J3D_STATE_TPHSOT = 0x0008,
+    /**< the decoding process is in a tile part header */
+    J3D_STATE_TPH    = 0x0010,
+    /**< the EOC marker has just been read */
+    J3D_STATE_MT     = 0x0020,
+    /**< the decoding process must not expect a EOC marker because the codestream is truncated */
+    J3D_STATE_NEOC   = 0x0040
+} J3D_STATUS;
+
+
+
+/**
+Arbitrary transformation kernel
+*/
+typedef struct opj_atk {
+    /** index of wavelet kernel */
+    int index;
+    /** Numerical type of scaling factor and lifting step parameters */
+    int coeff_typ;
+    /** Wavelet filter category */
+    int filt_cat;
+    /** Wavelet transformation type (REV/IRR) */
+    int wt_typ;
+    /** Initial odd/even subsequence */
+    int minit;
+    /** Boundary extension method (constant CON / whole-sample symmetric WS) */
+    int exten;
+    /** Scaling factor. Only for wt_typ=IRR */
+    double Katk;
+    /** Number of lifting steps */
+    int Natk;
+    /** Offset for lifting step s. Only for filt_cat=ARB */
+    int Oatk[256];
+    /** Base 2 scaling exponent for lifting step s. Only for wt_typ=REV */
+    int Eatk[256];
+    /** Additive residue for lifting step s. Only for wt_typ=REV */
+    int Batk[256];
+    /** Number of lifting coefficients signaled for lifting step s  */
+    int LCatk[256];
+    /** Lifting coefficient k for lifting step s */
+    double Aatk[256][256];
+} opj_atk_t;
+
+
+/**
+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 of x, y and z-axis */
+    int numresolution[3];
+    /** code-blocks width height & depth*/
+    int cblk[3];
+    /** code-block coding style */
+    int cblksty;
+    /** 0: no ATK (only 9-7 or 5-3) 1: ATK defined WT*/
+    int atk_wt[3];
+    /** Arbitrary transformation kernel (15444-2)*/
+    opj_atk_t *atk;
+    /** DWT identifier for x, y and z-axis (0:WT9-7 1:WT5-3 >1:WT-atk->index) */
+    int dwtid[3];
+    /** reversible/irreversible wavelet transfomation (0:irrev 1:reversible)*/
+    int reversible;
+    /** quantisation style */
+    int qntsty;
+    /** stepsizes used for quantization */
+    opj_stepsize_t stepsizes[J3D_MAXBANDS];
+    /** number of guard bits. Table A28 de 15444-1*/
+    int numgbits;
+    /** Region Of Interest shift */
+    int roishift;
+    /** precinct width height & depth*/
+    int prctsiz[3][J3D_MAXRLVLS];
+} opj_tccp_t;
+
+/**
+Tile coding parameters : 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 */
+    float 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[J3D_MAXRLVLS - 1];
+    /** add fixed_quality */
+    float distoratio[100];
+    /** tile-component coding parameters */
+    opj_tccp_t *tccps;
+    /** 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;
+    int ppt_len;
+} opj_tcp_t;
+
+/**
+Coding parameters
+*/
+typedef struct opj_cp {
+    /** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */
+    OPJ_TRANSFORM transform_format;
+    /** entropy coding format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/
+    OPJ_ENTROPY_CODING encoding_format;
+    /** allocation by rate/distortion */
+    int disto_alloc;
+    /** allocation by fixed layer */
+    int fixed_alloc;
+    /** add fixed_quality */
+    int fixed_quality;
+    /** Rsiz: capabilities */
+    int rsiz;
+    /** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, volume is decoded to the full resolution */
+    int reduce[3];
+    /** 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 */
+    int index_on;
+    /** Big-Endian/Little-endian order */
+    int bigendian;
+    /** XTOsiz */
+    int tx0;
+    /** YTOsiz */
+    int ty0;
+    /** ZTOsiz */
+    int tz0;
+    /** XTsiz */
+    int tdx;
+    /** YTsiz */
+    int tdy;
+    /** ZTsiz */
+    int tdz;
+    /** comment for coding */
+    char *comment;
+    /** number of tiles in width, height and depth */
+    int tw;
+    int th;
+    int tl;
+    /** ID number of the tiles present in the codestream */
+    int *tileno;
+    /** size of the vector tileno */
+    int tileno_size;
+    /** tile coding parameters */
+    opj_tcp_t *tcps;
+    /** fixed layer */
+    int *matrice;
+
+    /** packet header store there for futur use in t2_decode_packet */
+    unsigned char *ppm_data;
+    /** pointer remaining on the first byte of the first header if ppm is used */
+    unsigned char *ppm_data_first;
+    /** if ppm == 1 --> there was a PPM marker for the present tile */
+    int ppm;
+    /** use in case of multiple marker PPM (number of info already store) */
+    int ppm_store;
+    /** use in case of multiple marker PPM (case on non-finished previous info) */
+    int ppm_previous;
+    int ppm_len;
+} opj_cp_t;
+
+/**
+Information concerning a packet inside tile
+*/
+typedef struct opj_packet_info {
+    /** start position */
+    int start_pos;
+    /** end position */
+    int end_pos;
+    /** distorsion introduced */
+    double disto;
+} opj_packet_info_t;
+
+/**
+Index structure : information regarding tiles inside volume
+*/
+typedef struct opj_tile_info {
+    /** value of thresh for each layer by tile cfr. Marcela   */
+    double *thresh;
+    /** number of tile */
+    int num_tile;
+    /** start position */
+    int start_pos;
+    /** end position of the header */
+    int end_header;
+    /** end position */
+    int end_pos;
+    /** precinct number for each resolution level (width, height and depth) */
+    int prctno[3][J3D_MAXRLVLS];
+    /** precinct size (in power of 2), in X for each resolution level */
+    int prctsiz[3][J3D_MAXRLVLS];
+    /** information concerning packets inside tile */
+    opj_packet_info_t *packet;
+
+    /** add fixed_quality */
+    int nbpix;
+    /** add fixed_quality */
+    double distotile;
+} opj_tile_info_t;
+
+/**
+Index structure
+*/
+typedef struct opj_volume_info {
+
+    /** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */
+    OPJ_TRANSFORM transform_format;
+    /** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/
+    OPJ_ENTROPY_CODING encoding_format; /** 0 = no index || 1 = index */
+    int index_on;
+    /** 0 = wt 9-7 || 1 = wt 5-3 || >=2 wt atk defined */
+    int dwtid[3];
+    /** maximum distortion reduction on the whole volume (add for Marcela) */
+    double D_max;
+    /** packet number */
+    int num;
+    /** writing the packet in the index with t2_encode_packets */
+    int index_write;
+    /** volume width, height and depth */
+    int volume_w;
+    int volume_h;
+    int volume_l;
+    /** progression order */
+    OPJ_PROG_ORDER prog;
+    /** tile size in x, y and z */
+    int tile_x;
+    int tile_y;
+    int tile_z;
+    /** tile origin in x, y and z */
+    int tile_Ox;
+    int tile_Oy;
+    int tile_Oz;
+    /** number of tiles in X, Y and Z */
+    int tw;
+    int th;
+    int tl;
+    /** component numbers */
+    int comp;
+    /** number of layer */
+    int layer;
+    /** number of decomposition in X, Y and Z*/
+    int decomposition[3];
+    /** DC offset (15444-2) */
+    int dcoffset;
+    /** main header position */
+    int main_head_end;
+    /** codestream's size */
+    int codestream_size;
+    /** information regarding tiles inside volume */
+    opj_tile_info_t *tile;
+} opj_volume_info_t;
+
+/**
+JPEG-2000 codestream reader/writer
+*/
+typedef struct opj_j3d {
+    /** codec context */
+    opj_common_ptr cinfo;
+    /** locate in which part of the codestream the decoder is (main header, tile header, end) */
+    int state;
+    /** number of the tile currently concern by coding/decoding */
+    int curtileno;
+    /** locate the position of the end of the tile in the codestream, used to detect a truncated codestream (in j3d_read_sod)   */
+    unsigned char *eot;
+    /** locate the start position of the SOT marker of the current coded tile:  */
+    int sot_start;
+    /*  after encoding the tile, a jump (in j3d_write_sod) is done to the SOT marker to store the value of its length. */
+    int sod_start;
+    /** as the J3D-file is written in several parts during encoding, it enables to make the right correction in position return by cio_tell */
+    int pos_correction;
+    /** array used to store the data of each tile */
+    unsigned char **tile_data;
+    /** array used to store the length of each tile */
+    int *tile_len;
+
+    /** decompression only : store decoding parameters common to all tiles */
+    opj_tcp_t *default_tcp;
+    /** pointer to the encoded / decoded volume */
+    opj_volume_t *volume;
+    /** pointer to the coding parameters */
+    opj_cp_t *cp;
+    /** helper used to write the index file */
+    opj_volume_info_t *volume_info;
+    /** pointer to the byte i/o stream */
+    opj_cio_t *cio;
+} opj_j3d_t;
+
+/** @name Funciones generales */
+/*@{*/
+/* ----------------------------------------------------------------------- */
+/**
+Creates a J3D decompression structure
+@param cinfo Codec context info
+@return Returns a handle to a J3D decompressor if successful, returns NULL otherwise
+*/
+opj_j3d_t* j3d_create_decompress(opj_common_ptr cinfo);
+/**
+Destroy a J3D decompressor handle
+@param j3d J3D decompressor handle to destroy
+*/
+void j3d_destroy_decompress(opj_j3d_t *j3d);
+/**
+Setup the decoder decoding parameters using user parameters.
+Decoding parameters are returned in j3d->cp.
+@param j3d J3D decompressor handle
+@param parameters decompression parameters
+*/
+void j3d_setup_decoder(opj_j3d_t *j3d, opj_dparameters_t *parameters);
+/**
+Decode an volume from a JPEG-2000 codestream
+@param j3d J3D decompressor handle
+@param cio Input buffer stream
+@return Returns a decoded volume if successful, returns NULL otherwise
+*/
+opj_volume_t* j3d_decode(opj_j3d_t *j3d, opj_cio_t *cio);
+/**
+Decode an volume form a JPT-stream (JPEG 2000, JPIP)
+@param j3d J3D decompressor handle
+@param cio Input buffer stream
+@return Returns a decoded volume if successful, returns NULL otherwise
+*/
+opj_volume_t* j3d_decode_jpt_stream(opj_j3d_t *j3d, opj_cio_t *cio);
+/**
+Creates a J3D compression structure
+@param cinfo Codec context info
+@return Returns a handle to a J3D compressor if successful, returns NULL otherwise
+*/
+opj_j3d_t* j3d_create_compress(opj_common_ptr cinfo);
+/**
+Destroy a J3D compressor handle
+@param j3d J3D compressor handle to destroy
+*/
+void j3d_destroy_compress(opj_j3d_t *j3d);
+/**
+Setup the encoder parameters using the current volume and using user parameters.
+Coding parameters are returned in j3d->cp.
+@param j3d J3D compressor handle
+@param parameters compression parameters
+@param volume input filled volume
+*/
+void j3d_setup_encoder(opj_j3d_t *j3d, opj_cparameters_t *parameters,
+                       opj_volume_t *volume);
+/**
+Encode an volume into a JPEG-2000 codestream
+@param j3d J3D compressor handle
+@param cio Output buffer stream
+@param volume Volume to encode
+@param index Name of the index file if required, NULL otherwise
+@return Returns true if successful, returns false otherwise
+*/
+bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume,
+                char *index);
+/* ----------------------------------------------------------------------- */
+/*@}*/
+
+/*@}*/
+
+#endif /* __J3D_H */