fixed opj_malloc.h for macosx (bugfix provided by janpeder, thanks)
[openjpeg.git] / libopenjpeg / j2k.h
index 42e452a9d25c5a5bebfd2bd3ad0486683f519131..5599be47a8dbe5acc326cec00a9b0cf67096816e 100644 (file)
@@ -1,9 +1,11 @@
 /*
+ * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
+ * Copyright (c) 2002-2007, Professor Benoit Macq
  * Copyright (c) 2001-2003, David Janssens
  * Copyright (c) 2002-2003, Yannick Verschueren
- * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
- * Copyright (c) 2005, Herv Drolon, FreeImage Team
- * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
+ * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
+ * Copyright (c) 2005, Herve Drolon, FreeImage Team
+ * Copyright (c) 2006-2007, Parvatha Elangovan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -75,6 +77,19 @@ The functions in J2K.C have for goal to read/write the several parts of the code
 #define J2K_MS_EPH 0xff92      /**< EPH marker value */
 #define J2K_MS_CRG 0xff63      /**< CRG marker value */
 #define J2K_MS_COM 0xff64      /**< COM marker value */
+/* UniPG>> */
+#ifdef USE_JPWL
+#define J2K_MS_EPC 0xff68      /**< EPC marker value (Part 11: JPEG 2000 for Wireless) */
+#define J2K_MS_EPB 0xff66      /**< EPB marker value (Part 11: JPEG 2000 for Wireless) */ 
+#define J2K_MS_ESD 0xff67      /**< ESD marker value (Part 11: JPEG 2000 for Wireless) */ 
+#define J2K_MS_RED 0xff69      /**< RED marker value (Part 11: JPEG 2000 for Wireless) */
+#endif /* USE_JPWL */
+#ifdef USE_JPSEC
+#define J2K_MS_SEC 0xff65    /**< SEC marker value (Part 8: Secure JPEG 2000) */
+#define J2K_MS_INSEC 0xff94  /**< INSEC marker value (Part 8: Secure JPEG 2000) */
+#endif /* USE_JPSEC */
+/* <<UniPG */
+
 
 /* ----------------------------------------------------------------------- */
 
@@ -89,11 +104,20 @@ typedef enum J2K_STATUS {
        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_STATE_NEOC   = 0x0040, /**< the decoding process must not expect a EOC marker because the codestream is truncated */
+       J2K_STATE_ERR    = 0x0080  /**< the decoding process has encountered an error */
 } J2K_STATUS;
 
 /* ----------------------------------------------------------------------- */
 
+/** 
+T2 encoding mode 
+*/
+typedef enum T2_MODE {
+       THRESH_CALC = 0,        /** Function called in Rate allocation process*/
+       FINAL_PASS = 1          /** Function called in Tier 2 process*/
+}J2K_T2_MODE;
+
 /**
 Quantization stepsize
 */
@@ -151,7 +175,7 @@ typedef struct opj_tcp {
        /** multi-component transform identifier */
        int mct;
        /** rates of layers */
-       int rates[100];
+       float rates[100];
        /** number of progression order changes */
        int numpocs;
        /** indicates if a POC marker has been used O:NO, 1:YES */
@@ -178,6 +202,20 @@ typedef struct opj_tcp {
 Coding parameters
 */
 typedef struct opj_cp {
+       /** Digital cinema profile*/
+       OPJ_CINEMA_MODE cinema;
+       /** Maximum rate for each component. If == 0, component size limitation is not considered */
+       int max_comp_size;
+       /** Size of the image in bits*/
+       int img_size;
+       /** Rsiz*/
+       OPJ_RSIZ_CAPABILITIES rsiz;
+       /** Enabling Tile part generation*/
+       char tp_on;
+       /** Flag determining tile part generation*/
+       char tp_flag;
+       /** Position of tile part flag in progression order*/
+       int tp_pos;
        /** allocation by rate/distortion */
        int disto_alloc;
        /** allocation by fixed layer */
@@ -188,8 +226,8 @@ typedef struct opj_cp {
        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 */
-       int index_on;
+       /** if == NO_LIMITATION, decode entire codestream; if == LIMIT_TO_MAIN_HEADER then only decode the main header */
+       OPJ_LIMIT_DECODING limit_decoding;
        /** XTOsiz */
        int tx0;
        /** YTOsiz */
@@ -224,94 +262,52 @@ typedef struct opj_cp {
        opj_tcp_t *tcps;
        /** fixed layer */
        int *matrice;
+/* UniPG>> */
+#ifdef USE_JPWL
+       /** enables writing of EPC in MH, thus activating JPWL */
+       bool epc_on;
+       /** enables writing of EPB, in case of activated JPWL */
+       bool epb_on;
+       /** enables writing of ESD, in case of activated JPWL */
+       bool esd_on;
+       /** enables writing of informative techniques of ESD, in case of activated JPWL */
+       bool info_on;
+       /** enables writing of RED, in case of activated JPWL */
+       bool red_on;
+       /** error protection method for MH (0,1,16,32,37-128) */
+       int hprot_MH;
+       /** tile number of header protection specification (>=0) */
+       int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
+       /** error protection methods for TPHs (0,1,16,32,37-128) */
+       int hprot_TPH[JPWL_MAX_NO_TILESPECS];
+       /** tile number of packet protection specification (>=0) */
+       int pprot_tileno[JPWL_MAX_NO_PACKSPECS];
+       /** packet number of packet protection specification (>=0) */
+       int pprot_packno[JPWL_MAX_NO_PACKSPECS];
+       /** error protection methods for packets (0,1,16,32,37-128) */
+       int pprot[JPWL_MAX_NO_PACKSPECS];
+       /** enables writing of ESD, (0/2/4 bytes) */
+       int sens_size;
+       /** sensitivity addressing size (0=auto/2/4 bytes) */
+       int sens_addr;
+       /** sensitivity range (0-3) */
+       int sens_range;
+       /** sensitivity method for MH (-1,0-7) */
+       int sens_MH;
+       /** tile number of sensitivity specification (>=0) */
+       int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
+       /** sensitivity methods for TPHs (-1,0-7) */
+       int sens_TPH[JPWL_MAX_NO_TILESPECS];
+       /** enables JPWL correction at the decoder */
+       bool correct;
+       /** expected number of components at the decoder */
+       int exp_comps;
+       /** maximum number of tiles at the decoder */
+       int max_tiles;
+#endif /* USE_JPWL */
+/* <<UniPG */
 } opj_cp_t;
 
-/**
-Information concerning a packet inside tile
-*/
-typedef struct opj_packet_info {
-       /** start position */
-       int start_pos;
-       /** end position */
-       int end_pos;
-       /** ADD for Marcela */
-       double disto;
-} opj_packet_info_t;
-
-/**
-Index structure : information regarding tiles inside image
-*/
-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) */
-       int pw[33];
-       /** precinct number for each resolution level (height) */
-       int ph[33];
-       /** precinct size (in power of 2), in X for each resolution level */
-       int pdx[33];
-       /** precinct size (in power of 2), in Y for each resolution level */
-       int pdy[33];
-       /** 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_image_info {
-       /** 0 = no index || 1 = index */
-       int index_on;
-       /** maximum distortion reduction on the whole image (add for Marcela) */
-       double D_max;
-       /** packet number */
-       int num;
-       /** writing the packet in the index with t2_encode_packets */
-       int index_write;
-       /** image width */
-       int image_w;
-       /** image height */
-       int image_h;
-       /** progression order */
-       OPJ_PROG_ORDER prog;
-       /** tile size in x */
-       int tile_x;
-       /** tile size in y */
-       int tile_y;
-       /** */
-       int tile_Ox;
-       /** */
-       int tile_Oy;
-       /** number of tiles in X */
-       int tw;
-       /** number of tiles in Y */
-       int th;
-       /** component numbers */
-       int comp;
-       /** number of layer */
-       int layer;
-       /** number of decomposition */
-       int decomposition;
-       /** main header position */
-       int main_head_end;
-       /** codestream's size */
-       int codestream_size;
-       /** information regarding tiles inside image */
-       opj_tile_info_t *tile;
-} opj_image_info_t;
-
 /**
 JPEG-2000 codestream reader/writer
 */
@@ -323,6 +319,20 @@ typedef struct opj_j2k {
        int state;
        /** number of the tile curently concern by coding/decoding */
        int curtileno;
+       /** Tile part number*/
+       int tp_num;
+       /** Tilepart number currently coding*/
+       int cur_tp_num;
+       /** Total number of tileparts of the current tile*/
+       int *cur_totnum_tp;
+       /**
+       locate the start position of the TLM marker  
+       after encoding the tilepart, a jump (in j2k_write_sod) is done to the TLM marker to store the value of its length. 
+       */
+       int tlm_start;
+       /** Total num of tile parts in whole image = num tiles* num tileparts in each tile*/
+       /** used in TLMmarker*/
+       int totnum_tp;  
        /** 
        locate the position of the end of the tile in the codestream, 
        used to detect a truncated codestream (in j2k_read_sod)
@@ -353,7 +363,7 @@ typedef struct opj_j2k {
        /** pointer to the coding parameters */
        opj_cp_t *cp;
        /** helper used to write the index file */
-       opj_image_info_t *image_info;
+       opj_codestream_info_t *cstr_info;
        /** pointer to the byte i/o stream */
        opj_cio_t *cio;
 } opj_j2k_t;
@@ -383,16 +393,18 @@ void j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters);
 Decode an image from a JPEG-2000 codestream
 @param j2k J2K decompressor handle
 @param cio Input buffer stream
+@param cstr_info Codestream information structure if required, NULL otherwise
 @return Returns a decoded image if successful, returns NULL otherwise
 */
-opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio);
+opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
 /**
 Decode an image form a JPT-stream (JPEG 2000, JPIP)
 @param j2k J2K decompressor handle
 @param cio Input buffer stream
+@param cstr_info Codestream information structure if required, NULL otherwise
 @return Returns a decoded image if successful, returns NULL otherwise
 */
-opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio);
+opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
 /**
 Creates a J2K compression structure
 @param cinfo Codec context info
@@ -413,14 +425,19 @@ Coding parameters are returned in j2k->cp.
 */
 void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image);
 /**
+Converts an enum type progression order to string type
+*/
+char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order);
+/**
 Encode an image into a JPEG-2000 codestream
 @param j2k J2K compressor handle
 @param cio Output buffer stream
 @param image Image to encode
-@param index Name of the index file if required, NULL otherwise
+@param cstr_info Codestream information structure if required, NULL otherwise
 @return Returns true if successful, returns false otherwise
 */
-bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index);
+bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
+
 /* ----------------------------------------------------------------------- */
 /*@}*/