+static opj_bool jp2_read_boxhdr(opj_common_ptr cinfo, opj_cio_t *cio, opj_jp2_box_t *box);
+/*static void jp2_write_url(opj_cio_t *cio, char *Idx_file);*/
+/**
+Read the IHDR box - Image Header box
+@param jp2 JP2 handle
+@param cio Input buffer stream
+@return Returns true if successful, returns false otherwise
+*/
+static opj_bool jp2_read_ihdr(opj_jp2_t *jp2, opj_cio_t *cio);
+
+/**
+ * Reads a IHDR box - Image Header box
+ *
+ * @param p_image_header_data pointer to actual data (already read from file)
+ * @param jp2 the jpeg2000 file codec.
+ * @param p_image_header_size the size of the image header
+ * @param p_manager the user event manager.
+ *
+ * @return true if the image header is valid, fale else.
+ */
+static opj_bool jp2_read_ihdr_v2(
+ opj_jp2_v2_t *jp2,
+ unsigned char * p_image_header_data,
+ unsigned int p_image_header_size,
+ struct opj_event_mgr * p_manager
+ );
+
+static void jp2_write_ihdr(opj_jp2_t *jp2, opj_cio_t *cio);
+static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio);
+static opj_bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio);
+
+/**
+ * Reads a Bit per Component box.
+ *
+ * @param p_bpc_header_data pointer to actual data (already read from file)
+ * @param jp2 the jpeg2000 file codec.
+ * @param p_bpc_header_size the size of the bpc header
+ * @param p_manager the user event manager.
+ *
+ * @return true if the bpc header is valid, fale else.
+ */
+static opj_bool jp2_read_bpcc_v2(
+ opj_jp2_v2_t *jp2,
+ unsigned char * p_bpc_header_data,
+ unsigned int p_bpc_header_size,
+ struct opj_event_mgr * p_manager
+ );
+
+static opj_bool jp2_read_cdef_v2( opj_jp2_v2_t * jp2,
+ unsigned char * p_cdef_header_data,
+ OPJ_UINT32 p_cdef_header_size,
+ opj_event_mgr_t * p_manager
+ );
+
+static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio);
+/**
+Write the FTYP box - File type box
+@param jp2 JP2 handle
+@param cio Output buffer stream
+*/
+static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
+/**
+Read the FTYP box - File type box
+@param jp2 JP2 handle
+@param cio Input buffer stream
+@return Returns true if successful, returns false otherwise
+*/
+static opj_bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
+
+/**
+ * Reads a a FTYP box - File type box
+ *
+ * @param p_header_data the data contained in the FTYP box.
+ * @param jp2 the jpeg2000 file codec.
+ * @param p_header_size the size of the data contained in the FTYP box.
+ * @param p_manager the user event manager.
+ *
+ * @return true if the FTYP box is valid.
+ */
+static opj_bool jp2_read_ftyp_v2(
+ opj_jp2_v2_t *jp2,
+ unsigned char * p_header_data,
+ unsigned int p_header_size,
+ struct opj_event_mgr * p_manager
+ );
+
+/**
+ * Reads the Jpeg2000 file Header box - JP2 Header box (warning, this is a super box).
+ *
+ * @param p_header_data the data contained in the file header box.
+ * @param jp2 the jpeg2000 file codec.
+ * @param p_header_size the size of the data contained in the file header box.
+ * @param p_manager the user event manager.
+ *
+ * @return true if the JP2 Header box was successfully reconized.
+*/
+static opj_bool jp2_read_jp2h_v2(
+ opj_jp2_v2_t *jp2,
+ unsigned char * p_header_data,
+ unsigned int p_header_size,
+ struct opj_event_mgr * p_manager
+ );
+
+static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
+static opj_bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset);
+static void jp2_write_jp(opj_cio_t *cio);
+/**
+Read the JP box - JPEG 2000 signature
+@param jp2 JP2 handle
+@param cio Input buffer stream
+@return Returns true if successful, returns false otherwise
+*/
+static opj_bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio);
+
+/**
+ * Reads a jpeg2000 file signature box.
+ *
+ * @param p_header_data the data contained in the signature box.
+ * @param jp2 the jpeg2000 file codec.
+ * @param p_header_size the size of the data contained in the signature box.
+ * @param p_manager the user event manager.
+ *
+ * @return true if the file signature box is valid.
+ */
+static opj_bool jp2_read_jp_v2(
+ opj_jp2_v2_t *jp2,
+ unsigned char * p_header_data,
+ unsigned int p_header_size,
+ struct opj_event_mgr * p_manager
+ );
+
+/**
+Decode the structure of a JP2 file
+@param jp2 JP2 handle
+@param cio Input buffer stream
+@param color Collector for profile, cdef and pclr data
+@return Returns true if successful, returns false otherwise
+*/
+static opj_bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio,
+ opj_jp2_color_t *color);
+/**
+Apply collected palette data
+@param color Collector for profile, cdef and pclr data
+@param image
+*/
+static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image);
+/**
+Collect palette data
+@param jp2 JP2 handle
+@param cio Input buffer stream
+@param box
+@param color Collector for profile, cdef and pclr data
+@return Returns true if successful, returns false otherwise
+*/
+static opj_bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio,
+ opj_jp2_box_t *box, opj_jp2_color_t *color);
+
+static opj_bool jp2_read_pclr_v2( opj_jp2_v2_t *jp2,
+ unsigned char * p_pclr_header_data,
+ OPJ_UINT32 p_pclr_header_size,
+ opj_event_mgr_t * p_manager
+ );
+
+/**
+Collect component mapping data
+@param jp2 JP2 handle
+@param cio Input buffer stream
+@param box
+@param color Collector for profile, cdef and pclr data
+@return Returns true if successful, returns false otherwise
+*/
+static opj_bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio,
+ opj_jp2_box_t *box, opj_jp2_color_t *color);
+
+
+static opj_bool jp2_read_cmap_v2( opj_jp2_v2_t * jp2,
+ unsigned char * p_cmap_header_data,
+ OPJ_UINT32 p_cmap_header_size,
+ opj_event_mgr_t * p_manager
+ );
+
+/**
+Collect colour specification data
+@param jp2 JP2 handle
+@param cio Input buffer stream
+@param box
+@param color Collector for profile, cdef and pclr data
+@return Returns true if successful, returns false otherwise
+*/
+static opj_bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio,
+ opj_jp2_box_t *box, opj_jp2_color_t *color);
+
+/**
+ * Reads the Color Specification box.
+ *
+ * @param p_colr_header_data pointer to actual data (already read from file)
+ * @param jp2 the jpeg2000 file codec.
+ * @param p_colr_header_size the size of the color header
+ * @param p_manager the user event manager.
+ *
+ * @return true if the bpc header is valid, fale else.
+*/
+static opj_bool jp2_read_colr_v2(
+ opj_jp2_v2_t *jp2,
+ unsigned char * p_colr_header_data,
+ OPJ_UINT32 p_colr_header_size,
+ struct opj_event_mgr * p_manager
+ );
+
+/**
+Write file Index (superbox)
+@param[in] offset_jp2c offset of jp2c box
+@param[in] length_jp2c length of jp2c box
+@param[in] offset_idx offset of cidx box
+@param[in] length_idx length of cidx box
+@param[in] cio file output handle
+@return length of fidx box
+*/
+static int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio);
+/**
+Write index Finder box
+@param[in] offset offset of fidx box
+@param[in] length length of fidx box
+@param[in] cio file output handle
+*/
+static void write_iptr( int offset, int length, opj_cio_t *cio);
+/**
+
+Write proxy box
+@param[in] offset_jp2c offset of jp2c box
+@param[in] length_jp2c length of jp2c box
+@param[in] offset_idx offset of cidx box
+@param[in] length_idx length of cidx box
+@param[in] cio file output handle
+*/
+static void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio);
+/*@}*/
+
+/*@}*/
+
+/**
+ * Sets up the procedures to do on reading header after the codestream.
+ * Developpers wanting to extend the library can add their own writting procedures.
+ */
+static void jp2_setup_end_header_reading (opj_jp2_v2_t *jp2);
+
+/**
+ * Reads a jpeg2000 file header structure.
+ *
+ * @param cio the stream to read data from.
+ * @param jp2 the jpeg2000 file header structure.
+ * @param p_manager the user event manager.
+ *
+ * @return true if the box is valid.
+ */
+opj_bool jp2_read_header_procedure(
+ opj_jp2_v2_t *jp2,
+ struct opj_stream_private *cio,
+ struct opj_event_mgr * p_manager
+ );
+
+/**
+ * Excutes the given procedures on the given codec.
+ *
+ * @param p_procedure_list the list of procedures to execute
+ * @param jp2 the jpeg2000 file codec to execute the procedures on.
+ * @param cio the stream to execute the procedures on.
+ * @param p_manager the user manager.
+ *
+ * @return true if all the procedures were successfully executed.
+ */
+static opj_bool jp2_exec (
+ opj_jp2_v2_t * jp2,
+ struct opj_procedure_list * p_procedure_list,
+ struct opj_stream_private *cio,
+ struct opj_event_mgr * p_manager
+ );
+
+/**
+ * Reads a box header. The box is the way data is packed inside a jpeg2000 file structure.
+ *
+ * @param cio the input stream to read data from.
+ * @param box the box structure to fill.
+ * @param p_number_bytes_read pointer to an int that will store the number of bytes read from the stream (shoul usually be 2).
+ * @param p_manager user event manager.
+ *
+ * @return true if the box is reconized, false otherwise
+*/
+static opj_bool jp2_read_boxhdr_v2(
+ opj_jp2_box_t *box,
+ OPJ_UINT32 * p_number_bytes_read,
+ struct opj_stream_private *cio,
+ struct opj_event_mgr * p_manager
+ );
+
+/**
+ * Finds the execution function related to the given box id.
+ *
+ * @param p_id the id of the handler to fetch.
+ *
+ * @return the given handler or NULL if it could not be found.
+ */
+static const opj_jp2_header_handler_t * jp2_find_handler (int p_id );
+
+/**
+ * Finds the image execution function related to the given box id.
+ *
+ * @param p_id the id of the handler to fetch.
+ *
+ * @return the given handler or NULL if it could not be found.
+ */
+static const opj_jp2_header_handler_t * jp2_img_find_handler (int p_id);
+
+const opj_jp2_header_handler_t jp2_header [] =
+{
+ {JP2_JP,jp2_read_jp_v2},
+ {JP2_FTYP,jp2_read_ftyp_v2},
+ {JP2_JP2H,jp2_read_jp2h_v2}
+};