Improved success for the linux build; OPJViewer shows all the COM contents
[openjpeg.git] / OPJViewer / source / imagjp2.cpp
index 849c6e453580dc86ba78a3361890e380aec38730..3c61905bc97c9f391190d5e0f860926fa5153998 100644 (file)
@@ -89,30 +89,43 @@ void jp2_error_callback(const char *msg, void *client_data) {
        int message_len = strlen(msg) - 1;\r
        if (msg[message_len] != '\n')\r
                message_len = MAX_MESSAGE_LEN;\r
-    wxMutexGuiEnter();\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
        int message_len = strlen(msg) - 1;\r
        if (msg[message_len] != '\n')\r
                message_len = MAX_MESSAGE_LEN;\r
-    wxMutexGuiEnter();\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
        int message_len = strlen(msg) - 1;\r
        if (msg[message_len] != '\n')\r
                message_len = MAX_MESSAGE_LEN;\r
-    wxMutexGuiEnter();\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
-\r
 // load the jp2 file format\r
 bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, int index)\r
 {\r
@@ -122,6 +135,7 @@ bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
        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
@@ -180,11 +194,15 @@ bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
        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
+#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
@@ -194,59 +212,16 @@ bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
        /* close the byte stream */\r
        opj_cio_close(cio);\r
 \r
-       // check image size\r
-       if ((opjimage->numcomps != 1) && (opjimage->numcomps != 3)) {\r
-               wxMutexGuiEnter();\r
-               wxLogError(wxT("JP2: weird number of components"));\r
-               wxMutexGuiLeave();\r
-               opj_destroy_decompress(dinfo);\r
-               free(src);\r
-               return false;\r
-       }\r
+       /* common rendering method */\r
+#include "imagjpeg2000.cpp"\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
-\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
-\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
@@ -263,7 +238,14 @@ bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
 // 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