X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=OPJViewer%2Fsource%2Fimagjp2.cpp;h=3c61905bc97c9f391190d5e0f860926fa5153998;hb=123a680669995d50f354dd0159c83e7803a70ef3;hp=99ef23c99526d19540c244e5531f71e73afb83dc;hpb=8a75823eeaa6f36c428a848d757e7d94ce4386f1;p=openjpeg.git diff --git a/OPJViewer/source/imagjp2.cpp b/OPJViewer/source/imagjp2.cpp index 99ef23c9..3c61905b 100644 --- a/OPJViewer/source/imagjp2.cpp +++ b/OPJViewer/source/imagjp2.cpp @@ -86,36 +86,44 @@ IMPLEMENT_DYNAMIC_CLASS(wxJP2Handler,wxImageHandler) /* sample error callback expecting a FILE* client object */ void jp2_error_callback(const char *msg, void *client_data) { - char m_msg[MAX_MESSAGE_LEN]; int message_len = strlen(msg) - 1; if (msg[message_len] != '\n') message_len = MAX_MESSAGE_LEN; - sprintf(m_msg, "[ERROR] %.*s", message_len, msg); - wxMutexGuiEnter(); - wxLogMessage(m_msg); +#ifndef __WXGTK__ + wxMutexGuiEnter(); +#endif /* __WXGTK__ */ + wxLogMessage(wxT("[ERROR] %.*s"), message_len, msg); +#ifndef __WXGTK__ wxMutexGuiLeave(); +#endif /* __WXGTK__ */ } + /* sample warning callback expecting a FILE* client object */ void jp2_warning_callback(const char *msg, void *client_data) { - char m_msg[MAX_MESSAGE_LEN]; int message_len = strlen(msg) - 1; if (msg[message_len] != '\n') message_len = MAX_MESSAGE_LEN; - sprintf(m_msg, "[WARNING] %.*s", message_len, msg); - wxMutexGuiEnter(); - wxLogMessage(m_msg); +#ifndef __WXGTK__ + wxMutexGuiEnter(); +#endif /* __WXGTK__ */ + wxLogMessage(wxT("[WARNING] %.*s"), message_len, msg); +#ifndef __WXGTK__ wxMutexGuiLeave(); +#endif /* __WXGTK__ */ } + /* sample debug callback expecting no client object */ void jp2_info_callback(const char *msg, void *client_data) { - char m_msg[MAX_MESSAGE_LEN]; int message_len = strlen(msg) - 1; if (msg[message_len] != '\n') message_len = MAX_MESSAGE_LEN; - sprintf(m_msg, "[INFO] %.*s", message_len, msg); - wxMutexGuiEnter(); - wxLogMessage(m_msg); +#ifndef __WXGTK__ + wxMutexGuiEnter(); +#endif /* __WXGTK__ */ + wxLogMessage(wxT("[INFO] %.*s"), message_len, msg); +#ifndef __WXGTK__ wxMutexGuiLeave(); +#endif /* __WXGTK__ */ } // load the jp2 file format @@ -127,6 +135,7 @@ bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, unsigned char *src = NULL; unsigned char *ptr; int file_length; + opj_codestream_info_t cstr_info; /* Codestream information structure */ // destroy the image image->Destroy(); @@ -149,6 +158,19 @@ bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, strncpy(parameters.outfile, "", sizeof(parameters.outfile)-1); parameters.decod_format = JP2_CFMT; parameters.cod_format = BMP_DFMT; + if (m_reducefactor) + parameters.cp_reduce = m_reducefactor; + if (m_qualitylayers) + parameters.cp_layer = m_qualitylayers; + /*if (n_components) + parameters. = n_components;*/ + + /* JPWL only */ +#ifdef USE_JPWL + parameters.jpwl_exp_comps = m_expcomps; + parameters.jpwl_max_tiles = m_maxtiles; + parameters.jpwl_correct = m_enablejpwl; +#endif /* USE_JPWL */ /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_JP2); @@ -172,11 +194,15 @@ bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); /* decode the stream and fill the image structure */ - opjimage = opj_decode(dinfo, cio); + opjimage = opj_decode_with_info(dinfo, cio, &cstr_info); if (!opjimage) { +#ifndef __WXGTK__ wxMutexGuiEnter(); - wxLogError("JP2: failed to decode image!"); +#endif /* __WXGTK__ */ + wxLogError(wxT("JP2: failed to decode image!")); +#ifndef __WXGTK__ wxMutexGuiLeave(); +#endif /* __WXGTK__ */ opj_destroy_decompress(dinfo); opj_cio_close(cio); free(src); @@ -186,59 +212,16 @@ bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, /* close the byte stream */ opj_cio_close(cio); - // check image size - if ((opjimage->numcomps != 1) && (opjimage->numcomps != 3)) { - wxMutexGuiEnter(); - wxLogError("JP2: weird number of components"); - wxMutexGuiLeave(); - opj_destroy_decompress(dinfo); - free(src); - return false; - } - - - // prepare image size - image->Create(opjimage->comps[0].w, opjimage->comps[0].h, true ); - - // access image raw data - image->SetMask( false ); - ptr = image->GetData(); - - // RGB color picture - if (opjimage->numcomps == 3) { - int row, col; - int *r = opjimage->comps[0].data; - int *g = opjimage->comps[1].data; - int *b = opjimage->comps[2].data; - for (row = 0; row < opjimage->comps[0].h; row++) { - for (col = 0; col < opjimage->comps[0].w; col++) { - - *(ptr++) = *(r++); - *(ptr++) = *(g++); - *(ptr++) = *(b++); - - } - } - } - - // B/W picture - if (opjimage->numcomps == 1) { - int row, col; - int *y = opjimage->comps[0].data; - for (row = 0; row < opjimage->comps[0].h; row++) { - for (col = 0; col < opjimage->comps[0].w; col++) { - - *(ptr++) = *(y); - *(ptr++) = *(y); - *(ptr++) = *(y++); - - } - } - } + /* common rendering method */ +#include "imagjpeg2000.cpp" - wxMutexGuiEnter(); +#ifndef __WXGTK__ + wxMutexGuiEnter(); +#endif /* __WXGTK__ */ wxLogMessage(wxT("JP2: image loaded.")); - wxMutexGuiLeave(); +#ifndef __WXGTK__ + wxMutexGuiLeave(); +#endif /* __WXGTK__ */ /* close openjpeg structs */ opj_destroy_decompress(dinfo); @@ -255,7 +238,14 @@ bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, // save the jp2 file format bool wxJP2Handler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose ) { +#ifndef __WXGTK__ + wxMutexGuiEnter(); +#endif /* __WXGTK__ */ wxLogError(wxT("JP2: Couldn't save image -> not implemented.")); +#ifndef __WXGTK__ + wxMutexGuiLeave(); +#endif /* __WXGTK__ */ + return false; }