typedef struct opj_decompression
{
- opj_bool (* opj_read_header) (
- void *p_codec,
- opj_image_t **,
- 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,
- struct opj_stream_private *cio,
- struct opj_event_mgr * p_manager);
- opj_image_t* (* opj_decode) (void * p_codec, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager);
- opj_bool (*opj_read_tile_header)(
- void * p_codec,
- 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,
- struct opj_stream_private *p_cio,
- struct opj_event_mgr * p_manager);
- opj_bool (*opj_decode_tile_data)(void * p_codec,OPJ_UINT32 p_tile_index,OPJ_BYTE * p_data,OPJ_UINT32 p_data_size,struct opj_stream_private *p_cio,struct opj_event_mgr * p_manager);
- opj_bool (* opj_end_decompress) (void *p_codec,struct opj_stream_private *cio,struct opj_event_mgr * p_manager);
+ opj_bool (* opj_read_header) ( struct opj_stream_private * cio,
+ void * p_codec,
+ opj_file_info_t * file_info,
+ struct opj_event_mgr * p_manager);
+
+ opj_image_t* (* opj_decode) ( void * p_codec,
+ struct opj_stream_private *p_cio,
+ struct opj_event_mgr * p_manager);
+
+ opj_bool (*opj_read_tile_header)( void * p_codec,
+ 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,
+ struct opj_stream_private *p_cio,
+ struct opj_event_mgr * p_manager);
+
+ opj_bool (*opj_decode_tile_data)( void * p_codec,
+ OPJ_UINT32 p_tile_index,
+ OPJ_BYTE * p_data,
+ OPJ_UINT32 p_data_size,
+ struct opj_stream_private *p_cio,
+ struct opj_event_mgr * p_manager);
+
+ opj_bool (* opj_end_decompress) ( void *p_codec,
+ struct opj_stream_private *cio,
+ struct opj_event_mgr * p_manager);
+
void (* opj_destroy) (void * p_codec);
- void (*opj_setup_decoder) (void * p_codec,opj_dparameters_t * p_param);
- opj_bool (*opj_set_decode_area) (void * p_codec,OPJ_INT32 p_start_x,OPJ_INT32 p_end_x,OPJ_INT32 p_start_y,OPJ_INT32 p_end_y,struct opj_event_mgr * p_manager);
+ void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param);
+ opj_bool (*opj_set_decode_area) ( void * p_codec,
+ OPJ_INT32 p_start_x, OPJ_INT32 p_end_x,
+ OPJ_INT32 p_start_y, OPJ_INT32 p_end_y,
+ struct opj_event_mgr * p_manager);
}opj_decompression_t;
typedef struct opj_compression
typedef struct opj_codec_private
{
- union
- { /* code-blocks informations */
- opj_decompression_t m_decompression;
- opj_compression_t m_compression;
+ /* code-blocks informations */
+ union {
+ opj_decompression_t m_decompression;
+ opj_compression_t m_compression;
} m_codec_data;
void * m_codec;
opj_event_mgr_t* m_event_mgr;
OPJ_SIZE_T opj_skip_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
{
- if
- (fseek(p_user_data,p_nb_bytes,SEEK_CUR))
- {
+ if (fseek(p_user_data,p_nb_bytes,SEEK_CUR)) {
return -1;
}
+
return p_nb_bytes;
}
opj_bool opj_seek_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
{
- if
- (fseek(p_user_data,p_nb_bytes,SEEK_SET))
- {
+ if (fseek(p_user_data,p_nb_bytes,SEEK_SET)) {
return EXIT_FAILURE;
}
+
return EXIT_SUCCESS;
}
l_info->is_decompressor = 1;
- switch
- (p_format)
- {
+ switch (p_format) {
case CODEC_J2K:
- l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_decode;
- l_info->m_codec_data.m_decompression.opj_end_decompress = (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *))j2k_end_decompress;
- l_info->m_codec_data.m_decompression.opj_read_header = (opj_bool (*) (
- void *,
- opj_image_t **,
- OPJ_INT32 * ,
- OPJ_INT32 * ,
- OPJ_UINT32 * ,
- OPJ_UINT32 * ,
- OPJ_UINT32 * ,
- OPJ_UINT32 * ,
- struct opj_stream_private *,
- struct opj_event_mgr * )) j2k_read_header;
+ l_info->m_codec_data.m_decompression.opj_decode =
+ (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_decode; // TODO MSD
+
+ l_info->m_codec_data.m_decompression.opj_end_decompress =
+ (opj_bool (*) (void *, struct opj_stream_private *, struct opj_event_mgr *))j2k_end_decompress;
+
+ l_info->m_codec_data.m_decompression.opj_read_header =
+ (opj_bool (*) ( struct opj_stream_private *,
+ void *,
+ opj_file_info_t *,
+ struct opj_event_mgr * )) j2k_read_header;
+
l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))j2k_destroy;
- l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) j2k_setup_decoder;
- l_info->m_codec_data.m_decompression.opj_read_tile_header = (opj_bool (*) (
- void *,
- OPJ_UINT32*,
- OPJ_UINT32*,
- OPJ_INT32 * ,
- OPJ_INT32 * ,
- OPJ_INT32 * ,
- OPJ_INT32 * ,
- OPJ_UINT32 * ,
- opj_bool *,
- struct opj_stream_private *,
- struct opj_event_mgr * )) j2k_read_tile_header;
- l_info->m_codec_data.m_decompression.opj_decode_tile_data = (opj_bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *, struct opj_event_mgr * )) j2k_decode_tile;
- l_info->m_codec_data.m_decompression.opj_set_decode_area = (opj_bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) j2k_set_decode_area;
+
+ l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * , opj_dparameters_t * )) j2k_setup_decoder_v2;
+
+ l_info->m_codec_data.m_decompression.opj_read_tile_header =
+ (opj_bool (*) ( void *,
+ OPJ_UINT32*,
+ OPJ_UINT32*,
+ OPJ_INT32*, OPJ_INT32*,
+ OPJ_INT32*, OPJ_INT32*,
+ OPJ_UINT32*,
+ opj_bool*,
+ struct opj_stream_private *,
+ struct opj_event_mgr * )) j2k_read_tile_header;
+
+ l_info->m_codec_data.m_decompression.opj_decode_tile_data =
+ (opj_bool (*) (void *, OPJ_UINT32, OPJ_BYTE*, OPJ_UINT32, struct opj_stream_private *, struct opj_event_mgr *)) j2k_decode_tile;
+
+ l_info->m_codec_data.m_decompression.opj_set_decode_area =
+ (opj_bool (*) (void *, OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, struct opj_event_mgr *)) j2k_set_decode_area;
+
l_info->m_codec = j2k_create_decompress_v2();
- if
- (! l_info->m_codec)
- {
+
+ if (! l_info->m_codec) {
opj_free(l_info);
- return 00;
+ return NULL;
}
+
break;
case CODEC_JP2:
/* get a JP2 decoder handle */
-#ifdef TODO_MSD
- l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))opj_jp2_decode;
+ l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))opj_jp2_decode; // TODO MSD
+
l_info->m_codec_data.m_decompression.opj_end_decompress = (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *)) jp2_end_decompress;
+
l_info->m_codec_data.m_decompression.opj_read_header = (opj_bool (*) (
- void *,
- opj_image_t **,
-
- OPJ_INT32 * ,
- OPJ_INT32 * ,
- OPJ_UINT32 * ,
- OPJ_UINT32 * ,
- OPJ_UINT32 * ,
- OPJ_UINT32 * ,
- struct opj_stream_private *,
- struct opj_event_mgr * )) jp2_read_header;
-
- l_info->m_codec_data.m_decompression.opj_read_tile_header = (
- opj_bool (*) (
+ struct opj_stream_private *,
+ void *,
+ opj_file_info_t *,
+ struct opj_event_mgr * )) jp2_read_header;
+
+ l_info->m_codec_data.m_decompression.opj_read_tile_header = ( opj_bool (*) (
void *,
OPJ_UINT32*,
OPJ_UINT32*,
l_info->m_codec_data.m_decompression.opj_decode_tile_data = (opj_bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *, struct opj_event_mgr * )) opj_jp2_decode_tile;
l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))jp2_destroy;
- l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) jp2_setup_decoder;
- l_info->m_codec_data.m_decompression.opj_set_decode_area = (opj_bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) jp2_set_decode_area;
+ l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) jp2_setup_decoder_v2;
+
+ l_info->m_codec_data.m_decompression.opj_set_decode_area = (opj_bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) jp2_set_decode_area;
l_info->m_codec = jp2_create(OPJ_TRUE);
- if
- (! l_info->m_codec)
- {
+
+ if (! l_info->m_codec) {
opj_free(l_info);
return 00;
}
-#endif
+
break;
case CODEC_UNKNOWN:
case CODEC_JPT:
}
l_info->m_codec_data.m_decompression.opj_setup_decoder(l_info->m_codec,parameters);
- l_info->m_event_mgr = event_mgr;
+
+ if (event_mgr == NULL)
+ {
+ l_info->m_event_mgr->error_handler = opj_default_callback ;
+ l_info->m_event_mgr->warning_handler = opj_default_callback ;
+ l_info->m_event_mgr->info_handler = opj_default_callback ;
+ l_info->m_event_mgr->client_data = stderr;
+ }
+ else
+ l_info->m_event_mgr = event_mgr;
return OPJ_TRUE;
}
return OPJ_FALSE;
parameters->cod_format = -1;
parameters->tcp_rates[0] = 0;
parameters->tcp_numlayers = 0;
- parameters->cp_disto_alloc = 0;
+ parameters->cp_disto_alloc = 0;
parameters->cp_fixed_alloc = 0;
parameters->cp_fixed_quality = 0;
parameters->jpip_on = OPJ_FALSE;
opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_UINT32 p_size, opj_bool p_is_read_stream)
{
opj_stream_t* l_stream = 00;
- if
- (! p_file)
- {
- return 00;
+
+ if (! p_file) {
+ return NULL;
}
+
l_stream = opj_stream_create(p_size,p_is_read_stream);
- if
- (! l_stream)
- {
- return 00;
+ if (! l_stream) {
+ return NULL;
}
- opj_stream_set_user_data(l_stream,p_file);
- opj_stream_set_read_function(l_stream,(opj_stream_read_fn) opj_read_from_file);
+
+ opj_stream_set_user_data(l_stream, p_file);
+ opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);
opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);
opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file);
+
return l_stream;
}
}
+
+#ifdef OLD_WAY_MS
opj_bool OPJ_CALLCONV opj_read_header (
opj_codec_t *p_codec,
opj_image_t ** p_image,
OPJ_UINT32 * p_nb_tiles_y,
opj_stream_t *p_cio)
{
- if
- (p_codec && 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)
- {
+
+ 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_nb_tiles_x,
p_nb_tiles_y,
l_cio,
- //&(l_info->m_event_mgr));
- l_info->m_event_mgr);
+ 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_file_info_t* p_file_info,
+ OPJ_INT32 file_info_flag)
+
+{
+ /* Initialize the output structure */
+ opj_initialise_file_info(p_file_info, file_info_flag, CODEC_J2K);
+
+ 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_cio,
+ l_info->m_codec,
+ p_file_info,
+ l_info->m_event_mgr);
+ }
+ return OPJ_FALSE;
+}
+
void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_info)
{
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;
+}