\r
/* sample error callback expecting a FILE* client object */\r
void jp2_error_callback(const char *msg, void *client_data) {\r
- char m_msg[MAX_MESSAGE_LEN];\r
int message_len = strlen(msg) - 1;\r
if (msg[message_len] != '\n')\r
message_len = MAX_MESSAGE_LEN;\r
- sprintf(m_msg, "[ERROR] %.*s", message_len, msg);\r
- wxMutexGuiEnter();\r
- wxLogMessage(m_msg);\r
+#ifndef __WXGTK__ \r
+ wxMutexGuiEnter();\r
+#endif /* __WXGTK__ */\r
+ wxLogMessage(wxT("[ERROR] %.*s"), message_len, msg);\r
+#ifndef __WXGTK__ \r
wxMutexGuiLeave();\r
+#endif /* __WXGTK__ */\r
}\r
+\r
/* sample warning callback expecting a FILE* client object */\r
void jp2_warning_callback(const char *msg, void *client_data) {\r
- char m_msg[MAX_MESSAGE_LEN];\r
int message_len = strlen(msg) - 1;\r
if (msg[message_len] != '\n')\r
message_len = MAX_MESSAGE_LEN;\r
- sprintf(m_msg, "[WARNING] %.*s", message_len, msg);\r
- wxMutexGuiEnter();\r
- wxLogMessage(m_msg);\r
+#ifndef __WXGTK__ \r
+ wxMutexGuiEnter();\r
+#endif /* __WXGTK__ */\r
+ wxLogMessage(wxT("[WARNING] %.*s"), message_len, msg);\r
+#ifndef __WXGTK__ \r
wxMutexGuiLeave();\r
+#endif /* __WXGTK__ */\r
}\r
+\r
/* sample debug callback expecting no client object */\r
void jp2_info_callback(const char *msg, void *client_data) {\r
- char m_msg[MAX_MESSAGE_LEN];\r
int message_len = strlen(msg) - 1;\r
if (msg[message_len] != '\n')\r
message_len = MAX_MESSAGE_LEN;\r
- sprintf(m_msg, "[INFO] %.*s", message_len, msg);\r
- wxMutexGuiEnter();\r
- wxLogMessage(m_msg);\r
+#ifndef __WXGTK__ \r
+ wxMutexGuiEnter();\r
+#endif /* __WXGTK__ */\r
+ wxLogMessage(wxT("[INFO] %.*s"), message_len, msg);\r
+#ifndef __WXGTK__ \r
wxMutexGuiLeave();\r
+#endif /* __WXGTK__ */\r
}\r
\r
// load the jp2 file format\r
opj_dparameters_t parameters; /* decompression parameters */\r
opj_event_mgr_t event_mgr; /* event manager */\r
opj_image_t *opjimage = NULL;\r
- FILE *fsrc = NULL;\r
unsigned char *src = NULL;\r
unsigned char *ptr;\r
int file_length;\r
+ opj_codestream_info_t cstr_info; /* Codestream information structure */\r
\r
// destroy the image\r
image->Destroy();\r
opj_set_default_decoder_parameters(¶meters);\r
\r
/* prepare parameters */\r
+ strncpy(parameters.infile, "", sizeof(parameters.infile)-1);\r
+ strncpy(parameters.outfile, "", sizeof(parameters.outfile)-1);\r
parameters.decod_format = JP2_CFMT;\r
parameters.cod_format = BMP_DFMT;\r
+ if (m_reducefactor)\r
+ parameters.cp_reduce = m_reducefactor;\r
+ if (m_qualitylayers)\r
+ parameters.cp_layer = m_qualitylayers;\r
+ /*if (n_components)\r
+ parameters. = n_components;*/\r
+\r
+ /* JPWL only */\r
+#ifdef USE_JPWL\r
+ parameters.jpwl_exp_comps = m_expcomps;\r
+ parameters.jpwl_max_tiles = m_maxtiles;\r
+ parameters.jpwl_correct = m_enablejpwl;\r
+#endif /* USE_JPWL */\r
\r
/* get a decoder handle */\r
dinfo = opj_create_decompress(CODEC_JP2);\r
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);\r
\r
/* decode the stream and fill the image structure */\r
- opjimage = opj_decode(dinfo, cio);\r
+ opjimage = opj_decode_with_info(dinfo, cio, &cstr_info);\r
if (!opjimage) {\r
+#ifndef __WXGTK__ \r
wxMutexGuiEnter();\r
- wxLogError("JP2: failed to decode image!");\r
+#endif /* __WXGTK__ */\r
+ wxLogError(wxT("JP2: failed to decode image!"));\r
+#ifndef __WXGTK__ \r
wxMutexGuiLeave();\r
+#endif /* __WXGTK__ */\r
opj_destroy_decompress(dinfo);\r
opj_cio_close(cio);\r
free(src);\r
return false;\r
}\r
\r
- // check image size\r
- if ((opjimage->numcomps != 1) && (opjimage->numcomps != 3)) {\r
- wxMutexGuiEnter();\r
- wxLogError("JP2: weird number of components");\r
- wxMutexGuiLeave();\r
- opj_destroy_decompress(dinfo);\r
- opj_cio_close(cio);\r
- free(src);\r
- return false;\r
- }\r
-\r
- // prepare image size\r
- image->Create(opjimage->comps[0].w, opjimage->comps[0].h, true );\r
-\r
- // access image raw data\r
- image->SetMask( false );\r
- ptr = image->GetData();\r
-\r
- // RGB color picture\r
- if (opjimage->numcomps == 3) {\r
- int row, col;\r
- int *r = opjimage->comps[0].data;\r
- int *g = opjimage->comps[1].data;\r
- int *b = opjimage->comps[2].data;\r
- for (row = 0; row < opjimage->comps[0].h; row++) {\r
- for (col = 0; col < opjimage->comps[0].w; col++) {\r
- \r
- *(ptr++) = *(r++);\r
- *(ptr++) = *(g++);\r
- *(ptr++) = *(b++);\r
-\r
- }\r
- }\r
- }\r
+ /* close the byte stream */\r
+ opj_cio_close(cio);\r
\r
- // B/W picture\r
- if (opjimage->numcomps == 1) {\r
- int row, col;\r
- int *y = opjimage->comps[0].data;\r
- for (row = 0; row < opjimage->comps[0].h; row++) {\r
- for (col = 0; col < opjimage->comps[0].w; col++) {\r
- \r
- *(ptr++) = *(y);\r
- *(ptr++) = *(y);\r
- *(ptr++) = *(y++);\r
-\r
- }\r
- }\r
- }\r
+ /* common rendering method */\r
+#include "imagjpeg2000.cpp"\r
\r
- wxMutexGuiEnter();\r
+#ifndef __WXGTK__ \r
+ wxMutexGuiEnter();\r
+#endif /* __WXGTK__ */\r
wxLogMessage(wxT("JP2: image loaded."));\r
- wxMutexGuiLeave();\r
+#ifndef __WXGTK__ \r
+ wxMutexGuiLeave();\r
+#endif /* __WXGTK__ */\r
\r
/* close openjpeg structs */\r
opj_destroy_decompress(dinfo);\r
- opj_cio_close(cio);\r
opj_image_destroy(opjimage);\r
free(src);\r
\r
// save the jp2 file format\r
bool wxJP2Handler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose )\r
{\r
+#ifndef __WXGTK__ \r
+ wxMutexGuiEnter();\r
+#endif /* __WXGTK__ */\r
wxLogError(wxT("JP2: Couldn't save image -> not implemented."));\r
+#ifndef __WXGTK__ \r
+ wxMutexGuiLeave();\r
+#endif /* __WXGTK__ */\r
+\r
return false;\r
}\r
\r