+
+void OPJ_CALLCONV opj_destroy_cstr_info_v2(opj_codestream_info_v2_t *cstr_info) {
+ if (cstr_info) {
+ int tileno, compno;
+
+ if (cstr_info->tile_info){
+ for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
+ for (compno = 0; compno < cstr_info->nbcomps; compno++){
+ opj_free(cstr_info->tile_info[tileno].tccp_info);
+ }
+ }
+ opj_free(cstr_info->tile_info);
+ }
+
+ if (cstr_info->m_default_tile_info.tccp_info){
+ opj_free(cstr_info->m_default_tile_info.tccp_info);
+ }
+
+ opj_free(cstr_info);
+ }
+}
+
+
+
+#ifdef OLD_WAY_MS
+opj_bool OPJ_CALLCONV opj_read_header (
+ opj_codec_t *p_codec,
+ opj_image_t ** p_image,
+ OPJ_INT32 * p_tile_x0,
+ OPJ_INT32 * p_tile_y0,
+ OPJ_UINT32 * p_tile_width,
+ OPJ_UINT32 * p_tile_height,
+ OPJ_UINT32 * p_nb_tiles_x,
+ OPJ_UINT32 * p_nb_tiles_y,
+ opj_stream_t *p_cio)
+{
+ if (p_codec && p_cio) {
+ opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
+ opj_stream_private_t * l_cio = (opj_stream_private_t *) p_cio;
+
+ if(! l_info->is_decompressor) {
+ return OPJ_FALSE;
+ }
+
+ return l_info->m_codec_data.m_decompression.opj_read_header(
+ l_info->m_codec,
+ p_image,
+ p_tile_x0,
+ p_tile_y0,
+ p_tile_width,
+ p_tile_height,
+ p_nb_tiles_x,
+ p_nb_tiles_y,
+ l_cio,
+ l_info->m_event_mgr); //&(l_info->m_event_mgr));
+ }
+ return OPJ_FALSE;
+}
+#endif
+
+opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
+ opj_codec_t *p_codec,
+ opj_image_t *p_image )
+{
+ if (p_codec && p_cio) {
+ opj_codec_private_t* l_info = (opj_codec_private_t*) p_codec;
+ opj_stream_private_t* l_cio = (opj_stream_private_t*) p_cio;
+
+ if(! l_info->is_decompressor) {
+ opj_event_msg_v2(l_info->m_event_mgr, EVT_ERROR, "Codec provided to the read_header function is not a decompressor handler.\n");
+ return OPJ_FALSE;
+ }
+
+ return l_info->m_codec_data.m_decompression.opj_read_header(
+ l_cio,
+ l_info->m_codec,
+ p_image,
+ l_info->m_event_mgr);
+ }
+
+ fprintf(stderr, "[ERROR] Input parameters of the read_header function are incorrect.\n");
+ return OPJ_FALSE;
+}
+
+
+void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_info)
+{
+ if (p_info) {
+ opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
+
+ if (l_info->is_decompressor) {
+ l_info->m_codec_data.m_decompression.opj_destroy(l_info->m_codec);
+ }
+ else {
+ l_info->m_codec_data.m_compression.opj_destroy(l_info->m_codec);
+ }
+
+ l_info->m_codec = 00;
+ opj_free(l_info);
+ }
+}
+
+/**
+ * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
+ *
+ * @param p_codec the jpeg2000 codec.
+ * @param p_start_x the left position of the rectangle to decode (in image coordinates).
+ * @param p_end_x the right position of the rectangle to decode (in image coordinates).
+ * @param p_start_y the up position of the rectangle to decode (in image coordinates).
+ * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
+ *
+ * @return true if the area could be set.
+ */
+opj_bool OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec,
+ OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
+ OPJ_INT32 p_end_x, OPJ_INT32 p_end_y
+ )
+{
+ if (p_codec) {
+ opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
+ if (! l_info->is_decompressor) {
+ return OPJ_FALSE;
+ }
+
+ return l_info->m_codec_data.m_decompression.opj_set_decode_area(
+ l_info->m_codec,
+ p_start_x,
+ p_start_y,
+ p_end_x,
+ p_end_y,
+ l_info->m_event_mgr);
+
+ }
+ return OPJ_FALSE;
+}
+
+/**
+ * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
+ * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
+ *
+ * @param p_codec the jpeg2000 codec.
+ * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
+ * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
+ * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
+ * as depicted in opj_write_tile.
+ * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
+ * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
+ * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
+ * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
+ * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
+ * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
+ * codestream is over at the time of the call, the value will be set to false. The user should then stop
+ * the decoding.
+ * @param p_stream the stream to decode.
+ * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
+ * returning false may be the result of a shortage of memory or an internal error.
+ */
+opj_bool OPJ_CALLCONV opj_read_tile_header(
+ opj_codec_t *p_codec,
+ opj_stream_t * p_stream,
+ OPJ_UINT32 * p_tile_index,
+ OPJ_UINT32 * p_data_size,
+ OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
+ OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
+ OPJ_UINT32 * p_nb_comps,
+ opj_bool * p_should_go_on)
+{
+ if (p_codec && p_stream && p_data_size && p_tile_index) {
+ opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
+ opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
+
+ if (! l_info->is_decompressor) {
+ return OPJ_FALSE;
+ }
+
+ return l_info->m_codec_data.m_decompression.opj_read_tile_header(
+ l_info->m_codec,
+ p_tile_index,
+ p_data_size,
+ p_tile_x0, p_tile_y0,
+ p_tile_x1, p_tile_y1,
+ p_nb_comps,
+ p_should_go_on,
+ l_cio,
+ l_info->m_event_mgr);
+ }
+ return OPJ_FALSE;
+}
+
+/**
+ * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
+ * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
+ *
+ * @param p_codec the jpeg2000 codec.
+ * @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
+ * @param p_data pointer to a memory block that will hold the decoded data.
+ * @param p_data_size size of p_data. p_data_size should be bigger or equal to the value set by opj_read_tile_header.
+ * @param p_stream the stream to decode.
+ *
+ * @return true if the data could be decoded.
+ */
+opj_bool OPJ_CALLCONV opj_decode_tile_data(
+ opj_codec_t *p_codec,
+ OPJ_UINT32 p_tile_index,
+ OPJ_BYTE * p_data,
+ OPJ_UINT32 p_data_size,
+ opj_stream_t *p_stream
+ )
+{
+ if (p_codec && p_data && p_stream) {
+ opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
+ opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
+
+ if (! l_info->is_decompressor) {
+ return OPJ_FALSE;
+ }
+
+ return l_info->m_codec_data.m_decompression.opj_decode_tile_data( l_info->m_codec,
+ p_tile_index,
+ p_data,
+ p_data_size,
+ l_cio,
+ l_info->m_event_mgr);
+ }
+ return OPJ_FALSE;
+}
+
+/*
+ *
+ *
+ */
+void OPJ_CALLCONV opj_dump_codec( opj_codec_t *p_codec,
+ OPJ_INT32 info_flag,
+ FILE* output_stream)
+{
+ if (p_codec) {
+ opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;
+
+ l_codec->opj_dump_codec(l_codec->m_codec, info_flag, output_stream);
+ return;
+ }
+
+ fprintf(stderr, "[ERROR] Input parameter of the dump_codec function are incorrect.\n");
+ return;
+}
+
+/*
+ *
+ *
+ */
+opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec)
+{
+ if (p_codec) {
+ opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;
+
+ return l_codec->opj_get_codec_info(l_codec->m_codec);
+ }
+
+ return NULL;
+}
+
+/*
+ *
+ *
+ */
+opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec)
+{
+ if (p_codec) {
+ opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;
+
+ return l_codec->opj_get_codec_index(l_codec->m_codec);
+ }
+
+ return NULL;
+}
+
+opj_bool OPJ_CALLCONV opj_decode_v2(opj_codec_t *p_info,
+ opj_stream_t *cio,
+ opj_image_t* p_image)
+{
+ if (p_info && cio) {
+ opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
+ opj_stream_private_t * l_cio = (opj_stream_private_t *) cio;
+
+ if (! l_info->is_decompressor) {
+ return OPJ_FALSE;
+ }
+
+ return l_info->m_codec_data.m_decompression.opj_decode( l_info->m_codec,
+ l_cio,
+ p_image,
+ l_info->m_event_mgr);
+ }
+
+ return OPJ_FALSE;
+}
+
+opj_bool OPJ_CALLCONV opj_end_decompress (opj_codec_t *p_codec,opj_stream_t *p_cio)
+{
+ if (p_codec && p_cio) {
+ opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
+ opj_stream_private_t * l_cio = (opj_stream_private_t *) p_cio;
+
+ if (! l_info->is_decompressor) {
+ return OPJ_FALSE;
+ }
+ return l_info->m_codec_data.m_decompression.opj_end_decompress( l_info->m_codec,
+ l_cio,
+ l_info->m_event_mgr);
+ }
+
+ return OPJ_FALSE;
+}