[trunk] WIP: clean the j2k_dump application and the lib regards to the event management

This commit is contained in:
Mickael Savinaud 2011-09-21 16:37:45 +00:00
parent ba0c271774
commit 5d0b813cec
8 changed files with 303 additions and 170 deletions

View File

@ -6,6 +6,7 @@ What's New for OpenJPEG
+ : added
September 21, 2011
+ [mickael] WIP: clean the j2k_dump application and the lib regards to the event management
+ [mickael] Enhance the support of endianess with cmake and inside the code (credit to Winfried)
September 20, 2011

View File

@ -74,6 +74,11 @@ typedef struct img_folder{
}img_fol_t;
/* -------------------------------------------------------------------------- */
static void j2k_dump_image(FILE *fd, opj_image_header_t * img);
static void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_v2_t * cp);
/* -------------------------------------------------------------------------- */
void decode_help_display(void) {
fprintf(stdout,"HELP for j2k_dump\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@ -97,13 +102,18 @@ void decode_help_display(void) {
fprintf(stdout," OPTIONAL\n");
fprintf(stdout," Output file where file info will be dump.\n");
fprintf(stdout," By default it will be in the stdout.\n");
fprintf(stdout," -d <x0,x1,y0,y1>\n"); /* FIXME WIP_MSD */
fprintf(stdout," OPTIONAL\n");
fprintf(stdout," Decoding area\n");
fprintf(stdout," By default all tiles header are read.\n");
fprintf(stdout," -v "); /* FIXME WIP_MSD */
fprintf(stdout," OPTIONAL\n");
fprintf(stdout," Activate or not the verbose mode (display info and warning message)\n");
fprintf(stdout," By default verbose mode is off.\n");
fprintf(stdout,"\n");
}
/* -------------------------------------------------------------------------- */
static void j2k_dump_image(FILE *fd, opj_image_header_t * img);
static void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_v2_t * cp);
int get_num_images(char *imgdirpath){
DIR *dir;
struct dirent* content;
@ -125,6 +135,7 @@ int get_num_images(char *imgdirpath){
return num_images;
}
/* -------------------------------------------------------------------------- */
int load_images(dircnt_t *dirptr, char *imgdirpath){
DIR *dir;
struct dirent* content;
@ -150,6 +161,7 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
return 0;
}
/* -------------------------------------------------------------------------- */
int get_file_format(char *filename) {
unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
@ -169,6 +181,7 @@ int get_file_format(char *filename) {
return -1;
}
/* -------------------------------------------------------------------------- */
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN]="";
@ -195,13 +208,16 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
}
/* -------------------------------------------------------------------------- */
/* parse the command line */
/**
* Parse the command line
*/
/* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) {
int totlen, c;
opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
};
const char optlist[] = "i:o:d:h";
const char optlist[] = "i:o:d:hv";
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
@ -266,7 +282,14 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
strncpy(ROI_values, opj_optarg, strlen(opj_optarg));
ROI_values[strlen(opj_optarg)] = '\0';
/*printf("ROI_values = %s [%d / %d]\n", ROI_values, strlen(ROI_values), size_optarg ); */
parse_ROI_values( ROI_values, &parameters->ROI_x0, &parameters->ROI_y0, &parameters->ROI_x1, &parameters->ROI_y1);
parse_ROI_values( ROI_values, &parameters->DA_x0, &parameters->DA_y0, &parameters->DA_x1, &parameters->DA_y1);
}
break;
/* ----------------------------------------------------- */
case 'v': /* Verbose mode */
{
parameters->m_verbose = 1;
}
break;
@ -303,11 +326,13 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
return 0;
}
/*******************************************************************************
* Parse ROI input values
/* -------------------------------------------------------------------------- */
/**
* Parse decoding area input values
* separator = ","
*******************************************************************************/
int parse_ROI_values( char* inArg, unsigned int *ROI_x0, unsigned int *ROI_y0, unsigned int *ROI_x1, unsigned int *ROI_y1)
*/
/* -------------------------------------------------------------------------- */
int parse_ROI_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsigned int *DA_x1, unsigned int *DA_y1)
{
int it = 0;
int values[4];
@ -325,78 +350,53 @@ int parse_ROI_values( char* inArg, unsigned int *ROI_x0, unsigned int *ROI_y0, u
return EXIT_FAILURE;
}
else{
*ROI_x0 = values[0]; *ROI_y0 = values[1];
*ROI_x1 = values[2]; *ROI_y1 = values[3];
*DA_x0 = values[0]; *DA_y0 = values[1];
*DA_x1 = values[2]; *DA_y1 = values[3];
return EXIT_SUCCESS;
}
}
/* -------------------------------------------------------------------------- */
/**
sample error callback expecting a FILE* client object
*/
void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting no client object
*/
void info_callback(const char *msg, void *client_data) {
(void)client_data;
fprintf(stdout, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
/**
* J2K_DUMP MAIN
*/
/* -------------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int ret;
opj_dparameters_t parameters; /* decompression parameters */
img_fol_t img_fol;
opj_event_mgr_t event_mgr; /* event manager */
opj_image_header_t* image = NULL;
opj_file_info_t file_info;
FILE *fsrc = NULL, *fout = NULL;
int num_images;
int i,imageno;
dircnt_t *dirptr = NULL;
opj_codec_t* dinfo = NULL; /* handle to a decompressor */
opj_stream_t *cio = NULL;
opj_codestream_info_t* cstr_info =NULL; /* Codestream information structure */
opj_bool l_go_on = OPJ_TRUE;
opj_dparameters_t parameters; /* Decompression parameters */
opj_event_mgr_t event_mgr; /* Event manager */
opj_file_info_t file_info; /* File info structure */
opj_codec_t* dinfo = NULL; /* Handle to a decompressor */
opj_stream_t *cio = NULL; /* Stream */
OPJ_INT32 num_images, imageno;
img_fol_t img_fol;
dircnt_t *dirptr = NULL;
opj_bool l_go_on = OPJ_TRUE;
OPJ_UINT32 l_max_data_size = 1000;
OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000);
/* FIXME configure the event callbacks (not required) */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
event_mgr.client_data = stderr;
/* set decoding parameters to default values */
/* Set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters);
/* Initialize img_fol */
memset(&img_fol,0,sizeof(img_fol_t));
/* parse input and get user encoding parameters */
/* Parse input and get user encoding parameters */
if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) {
return EXIT_FAILURE;
}
/* Set default event mgr */
opj_set_default_event_handler(&event_mgr, parameters.m_verbose);
/* Initialize reading of directory */
if(img_fol.set_imgdir==1){
int it_image;
num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
@ -408,8 +408,8 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
for(i=0;i<num_images;i++){
dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
for(it_image=0;it_image<num_images;it_image++){
dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN;
}
}
if(load_images(dirptr,img_fol.imgdirpath)==1){
@ -447,7 +447,7 @@ int main(int argc, char *argv[])
}
}
/* read the input file and put it in memory */
/* Read the input file and put it in memory */
/* ---------------------------------------- */
fsrc = fopen(parameters.infile, "rb");
if (!fsrc) {
@ -461,28 +461,25 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
/* decode the code-stream */
/* ---------------------- */
/* Read the JPEG2000 stream */
/* ------------------------ */
switch(parameters.decod_format) {
case J2K_CFMT:
{ /* JPEG-2000 codestream */
/* get a decoder handle */
case J2K_CFMT: /* JPEG-2000 codestream */
{
/* Get a decoder handle */
dinfo = opj_create_decompress_v2(CODEC_J2K);
break;
}
case JP2_CFMT:
{ /* JPEG 2000 compressed image data */
/* get a decoder handle */
case JP2_CFMT: /* JPEG 2000 compressed image data */
{
/* Get a decoder handle */
dinfo = opj_create_decompress_v2(CODEC_JP2);
break;
}
case JPT_CFMT:
{ /* JPEG 2000, JPIP */
/* get a decoder handle */
case JPT_CFMT: /* JPEG 2000, JPIP */
{
/* Get a decoder handle */
dinfo = opj_create_decompress_v2(CODEC_JPT);
break;
}
@ -492,27 +489,38 @@ int main(int argc, char *argv[])
continue;
}
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder_v2(dinfo, &parameters, &event_mgr);
/* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder_v2(dinfo, &parameters, &event_mgr) ){
fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
opj_stream_destroy(cio);
fclose(fsrc);
opj_destroy_codec(dinfo);
fclose(fout);
return EXIT_FAILURE;
}
/* Read the main header of the codestream and if necessary the JP2 boxes*/
if(! opj_read_header(cio, dinfo, &file_info, OPJ_IMG_INFO | OPJ_J2K_INFO)){
fprintf(stderr, "ERROR -> j2k_dump: failed to read the header\n");
opj_stream_destroy(cio);
fclose(fsrc);
opj_destroy_codec(dinfo);
fclose(fout);
return EXIT_FAILURE;
}
printf("Setting decoding area to %d,%d,%d,%d\n",
parameters.ROI_x0, parameters.ROI_y0, parameters.ROI_x1, parameters.ROI_y1);
fprintf(stdout,"Setting decoding area to %d,%d,%d,%d\n",
parameters.DA_x0, parameters.DA_y0, parameters.DA_x1, parameters.DA_y1);
/* FIXME WIP_MSD <*/
if (! opj_set_decode_area( dinfo,
parameters.ROI_x0, parameters.ROI_y0,
parameters.ROI_x1, parameters.ROI_y1)){
parameters.DA_x0, parameters.DA_y0,
parameters.DA_x1, parameters.DA_y1)){
fprintf(stderr, "ERROR -> j2k_dump: failed to set the decoded area\n");
opj_stream_destroy(cio);
fclose(fsrc);
opj_destroy_codec(dinfo);
fclose(fsrc);
fclose(fout);
return EXIT_FAILURE;
}
@ -546,9 +554,10 @@ int main(int argc, char *argv[])
l_data = (OPJ_BYTE *) realloc(l_data,l_data_size);
if (! l_data) {
opj_stream_destroy(cio);
fclose(fsrc);
opj_destroy_codec(dinfo);
return 1;
fclose(fsrc);
fclose(fout);
return EXIT_FAILURE;
}
l_max_data_size = l_data_size;
@ -558,13 +567,15 @@ int main(int argc, char *argv[])
{
free(l_data);
opj_stream_destroy(cio);
fclose(fsrc);
opj_destroy_codec(dinfo);
return 1;
fclose(fsrc);
fclose(fout);
return EXIT_FAILURE;
}
/** now should inspect image to know the reduction factor and then how to behave with data */
}
}
/* FIXME WIP_MSD >*/
/* Dump file informations from header */
dump_file_info(fout, &file_info);
@ -578,13 +589,8 @@ int main(int argc, char *argv[])
opj_destroy_codec(dinfo);
}
opj_image_header_destroy(image);
//FIXME opj_file_info_destroy(file_info);
}
/* Close the output file */
fclose(fout);

View File

@ -60,8 +60,8 @@ _itoa(int i, char *a, int r) {
#endif /* !_WIN32 */
#endif
/* ----------------------------------------------------------------------- */
/* ----------------------------------------------------------------------- */
opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) {
if(cinfo) {
opj_event_mgr_t *previous = cinfo->event_mgr;
@ -73,6 +73,7 @@ opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_
return NULL;
}
/* ----------------------------------------------------------------------- */
opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
opj_msg_callback msg_handler = NULL;
@ -120,6 +121,7 @@ opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ..
return OPJ_TRUE;
}
/* ----------------------------------------------------------------------- */
opj_bool opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char *fmt, ...) {
#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
opj_msg_callback msg_handler = NULL;
@ -165,3 +167,62 @@ opj_bool opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char
return OPJ_TRUE;
}
/* ----------------------------------------------------------------------- */
void opj_set_default_event_handler(opj_event_mgr_t * p_manager, opj_bool verbose)
{
p_manager->client_data = NULL;
p_manager->error_handler = opj_error_default_callback;
if (verbose) {
p_manager->info_handler = opj_info_default_callback;
p_manager->warning_handler = opj_warning_default_callback;
}
else {
/* FIXME (MSD) This message should be remove when the documentation will be updated */
fprintf(stdout, "[INFO] Verbose mode = OFF => no other info/warning output.\n");
p_manager->info_handler = opj_default_callback ;
p_manager->warning_handler = opj_default_callback ;
}
}
/* ---------------------------------------------------------------------- */
/* Default callback functions */
/**
* Default callback function.
* Do nothing.
*/
void opj_default_callback (const char *msg, void *client_data)
{
}
/**
* Default info callback function.
* Output = stdout.
*/
void opj_info_default_callback (const char *msg, void *client_data)
{
(void)client_data;
fprintf(stdout, "[INFO] %s", msg);
}
/**
* Default warning callback function.
* Output = stderr.
*/
void opj_warning_default_callback (const char *msg, void *client_data)
{
(void)client_data;
fprintf(stderr, "[WARNING] %s", msg);
}
/**
* Default error callback function.
* Output = stderr.
*/
void opj_error_default_callback (const char *msg, void *client_data)
{
(void)client_data;
fprintf(stderr, "[ERROR] %s", msg);
}

View File

@ -48,14 +48,54 @@ Write formatted data to a string and send the string to a user callback.
@param event_type Event type or callback to use to send the message
@param fmt Format-control string (plus optional arguments)
@return Returns true if successful, returns false otherwise
* FIXME Change by its v2 version this function after ended the merge (perhaps remove to the exported function)
*/
opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...);
/**
* Set the default event handler. This function set the output of message event to be stderr for warning and error output
* and stdout for info output. It is optional, you can set your own event handler or provide a null structure to the
* opj_setup_decoder function. In this last case no output will be displayed.
*
* @param p_manager a opj_event_mgr structure which will be pass to the codec.
*/
void opj_set_default_event_handler(opj_event_mgr_t * p_manager, opj_bool verbose);
opj_bool opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char *fmt, ...);
/* ----------------------------------------------------------------------- */
/*@}*/
/**
* Write formatted data to a string and send the string to a user callback.
*
* @param event_mgr Event handler
* @param event_type Event type or callback to use to send the message
* @param fmt Format-control string (plus optional arguments)
*
* @return Returns true if successful, returns false otherwise
*/
opj_bool opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char *fmt, ...);
/**
* Default callback function. No message sent to output.
*/
void opj_default_callback (const char *msg, void *client_data);
/**
* Default info callback function, message is sent to the stdout output.
*/
void opj_info_default_callback (const char *msg, void *client_data);
/**
* Default warning callback function, message is sent to stderr output.
*/
void opj_warning_default_callback (const char *msg, void *client_data);
/**
* Default error callback function, message is sent to stderr output.
*/
void opj_error_default_callback (const char *msg, void *client_data);
/*@}*/
#endif /* __EVENT_H */

View File

@ -4097,24 +4097,17 @@ void j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) {
}
}
void j2k_setup_decoder_v2(opj_j2k_v2_t *j2k, opj_dparameters_t *parameters) {
void j2k_setup_decoder_v2(opj_j2k_v2_t *j2k, opj_dparameters_t *parameters)
{
if(j2k && parameters) {
/* create and initialize the coding parameters structure */
//opj_cp_v2_t *cp = (opj_cp_v2_t*) opj_calloc(1, sizeof(opj_cp_v2_t));
j2k->m_cp.m_specific_param.m_dec.m_layer = parameters->cp_layer;
j2k->m_cp.m_specific_param.m_dec.m_reduce = parameters->cp_reduce;
/*cp->reduce = parameters->cp_reduce;
cp->layer = parameters->cp_layer;
cp->limit_decoding = parameters->cp_limit_decoding;*/
// TODO MS
#ifdef USE_JPWL
j2k->m_cp.correct = parameters->jpwl_correct;
j2k->m_cp.exp_comps = parameters->jpwl_exp_comps;
j2k->m_cp.max_tiles = parameters->jpwl_max_tiles;
#endif /* USE_JPWL */
}
}

View File

@ -1750,11 +1750,12 @@ void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) {
/* further JP2 initializations go here */
}
void jp2_setup_decoder_v2(opj_jp2_v2_t *jp2, opj_dparameters_t *parameters) {
void jp2_setup_decoder_v2(opj_jp2_v2_t *jp2, opj_dparameters_t *parameters)
{
/* setup the J2K codec */
j2k_setup_decoder_v2(jp2->j2k, parameters);
/* further JP2 initializations go here */
/* further JP2 initializations go here */
jp2->color.jp2_has_colr = 0;
}

View File

@ -31,17 +31,22 @@
#include "opj_config.h"
#include "opj_includes.h"
/**
* Decompression handler.
*/
typedef struct opj_decompression
{
/** Main header reading function handler*/
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);
/** FIXME DOC */
opj_image_t* (* opj_decode) ( void * p_codec,
struct opj_stream_private *p_cio,
struct opj_event_mgr * p_manager);
/** FIXME DOC */
opj_bool (*opj_read_tile_header)( void * p_codec,
OPJ_UINT32 * p_tile_index,
OPJ_UINT32* p_data_size,
@ -51,28 +56,31 @@ typedef struct opj_decompression
opj_bool * p_should_go_on,
struct opj_stream_private *p_cio,
struct opj_event_mgr * p_manager);
/** FIXME DOC */
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);
/** FIXME DOC */
opj_bool (* opj_end_decompress) ( void *p_codec,
struct opj_stream_private *cio,
struct opj_event_mgr * p_manager);
/** Codec destroy function handler*/
void (* opj_destroy) (void * p_codec);
/** Setup decoder function handler */
void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param);
/** Set decode area function handler */
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;
/**
* Compression handler. FIXME DOC
*/
typedef struct opj_compression
{
opj_bool (* opj_start_compress) (void *p_codec,struct opj_stream_private *cio,struct opj_image * p_image, struct opj_event_mgr * p_manager);
@ -84,38 +92,29 @@ typedef struct opj_compression
}opj_compression_t;
/**
* Main codec handler used for compression or decompression.
*/
typedef struct opj_codec_private
{
/* code-blocks informations */
/** FIXME DOC */
union {
opj_decompression_t m_decompression;
opj_compression_t m_compression;
} m_codec_data;
/** FIXME DOC*/
void * m_codec;
/** Event handler */
opj_event_mgr_t* m_event_mgr;
unsigned is_decompressor : 1;
/** Flag to indicate if the codec is used to decode or encode*/
opj_bool is_decompressor;
}
opj_codec_private_t;
/**
* Default callback function.
* Do nothing.
*/
void opj_default_callback (const char *msg, void *client_data)
{
//FIXME V2 -> V1 cf below
}
void set_default_event_handler(opj_event_mgr_t * p_manager)
{
//FIXME V2 -> V1
//p_manager->m_error_data = 00;
//p_manager->m_warning_data = 00;
//p_manager->m_info_data = 00;
p_manager->error_handler = opj_default_callback;
p_manager->info_handler = opj_default_callback;
p_manager->warning_handler = opj_default_callback;
}
/* ---------------------------------------------------------------------- */
OPJ_UINT32 opj_read_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p_file)
{
@ -177,6 +176,8 @@ const char* OPJ_CALLCONV opj_version(void) {
return PACKAGE_VERSION;
}
opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t));
if(!dinfo) return NULL;
@ -378,28 +379,29 @@ void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *param
opj_bool OPJ_CALLCONV opj_setup_decoder_v2(opj_codec_t *p_info, opj_dparameters_t *parameters, opj_event_mgr_t* event_mgr)
{
if (p_info && parameters) {
opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
if ( !p_info || !parameters || !event_mgr ){
fprintf(stderr, "[ERROR] Input parameters of the setup_decoder function are incorrect.\n");
return OPJ_FALSE;
}
if ( !event_mgr->error_handler || !event_mgr->warning_handler || !event_mgr->error_handler){
fprintf(stderr, "[ERROR] Event handler provided to the setup_decoder function is not valid.\n");
return OPJ_FALSE;
}
if (! l_info->is_decompressor) {
opj_event_msg_v2(event_mgr, EVT_ERROR, "Codec provided to the setup_decoder function is not a decompressor handler.\n");
return OPJ_FALSE;
}
l_info->m_codec_data.m_decompression.opj_setup_decoder(l_info->m_codec, parameters);
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;
}
opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
return opj_decode_with_info(dinfo, cio, NULL);
@ -675,6 +677,7 @@ opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
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;
}
@ -684,25 +687,24 @@ opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
p_file_info,
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)
{
if (p_info) {
opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
if
(l_info->is_decompressor)
{
if (l_info->is_decompressor) {
l_info->m_codec_data.m_decompression.opj_destroy(l_info->m_codec);
}
else
{
else {
l_info->m_codec_data.m_compression.opj_destroy(l_info->m_codec);
}
l_info->m_codec = 00;
opj_free(l_info);
}

View File

@ -192,7 +192,7 @@ typedef enum LIMIT_DECODING {
/**
Callback function prototype for events
@param msg Event message
@param client_data
@param client_data FIXME DOC
*/
typedef void (*opj_msg_callback) (const char *msg, void *client_data);
@ -206,6 +206,7 @@ used for
</ul>
*/
typedef struct opj_event_mgr {
/** FIXME DOC */
void* client_data;
/** Error message callback if available, NULL otherwise */
opj_msg_callback error_handler;
@ -434,11 +435,16 @@ typedef struct opj_dparameters {
OPJ_LIMIT_DECODING cp_limit_decoding;
/* V2 */
OPJ_UINT32 ROI_x0;
OPJ_UINT32 ROI_x1;
OPJ_UINT32 ROI_y0;
OPJ_UINT32 ROI_y1;
/** Decoding area left boundary */
OPJ_UINT32 DA_x0;
/** Decoding area right boundary */
OPJ_UINT32 DA_x1;
/** Decoding area up boundary */
OPJ_UINT32 DA_y0;
/** Decoding area bottom boundary */
OPJ_UINT32 DA_y1;
/** Verbose mode */
opj_bool m_verbose;
} opj_dparameters_t;
@ -1175,6 +1181,17 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file,
OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context);
/**
* Set the default event handler. This function set the output of message event to be stderr for warning and error output
* and stdout for info output. It is optional, you can set your own event handler or provide a null structure to the
* opj_setup_decoder function. In this last case no output will be displayed.
*
* @param p_manager a opj_event_mgr structure which will be pass to the codec.
*
*/
OPJ_API void OPJ_CALLCONV opj_set_default_event_handler(opj_event_mgr_t * p_manager, opj_bool verbose);
/*
==========================================================
codec functions definitions
@ -1212,6 +1229,17 @@ Decoding parameters are returned in j2k->cp.
*/
OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
/**
* Setup the decoder with decompression parameters provided by the user and with the message handler
* provided by the user.
*
* @param dinfo decompressor handlers
* @param parameters decompression parameters
* @param vent_mgr message handler
*
* @return true if the decoder is correctly set
*/
OPJ_API opj_bool OPJ_CALLCONV opj_setup_decoder_v2( opj_codec_t *p_info,
opj_dparameters_t *parameters,
opj_event_mgr_t* event_mgr);
@ -1384,6 +1412,7 @@ OPJ_API opj_bool OPJ_CALLCONV opj_decode_tile_data( opj_codec_t *p_codec,
OPJ_UINT32 p_data_size,
opj_stream_t *p_stream );
#ifdef __cplusplus
}
#endif