From ac0cc6df623f02e21fb9eb950e73237c794f4a89 Mon Sep 17 00:00:00 2001 From: Giuseppe Baruffa Date: Mon, 11 Feb 2008 14:43:11 +0000 Subject: [PATCH] Minor style modifications to comply with c99 compiler flag; removed Microsoft-specific "union-in-struct" syntax; Re-enabled cstr_info struct creation when -W switch is specified. Changed a number of things in opjviewer (e.g., decoding thread does not execute GUI calls anymore), to have it running under linux --> it is better than before, but still crashes --- ChangeLog | 4 ++ OPJViewer/Makefile | 6 +- OPJViewer/OPJViewer.iss | 6 +- OPJViewer/Readme.txt | 7 +- OPJViewer/source/OPJThreads.cpp | 80 ++++++++++------------ OPJViewer/source/OPJViewer.cpp | 109 ++++++++++++++++++++++++------ OPJViewer/source/OPJViewer.h | 14 +++- OPJViewer/source/build.h | 2 +- OPJViewer/source/imagjpeg2000.cpp | 65 +++++++++++------- codec/image_to_j2k.c | 10 +-- jpwl/JPWL_j2k_to_image.dsp | 3 +- jpwl/LibOpenJPEG_JPWL.dsp | 6 +- jpwl/Makefile | 8 +-- jpwl/jpwl.c | 76 ++++++++++----------- jpwl/jpwl.h | 4 +- jpwl/jpwl_lib.c | 33 ++++++--- jpwl/rs.h | 3 +- 17 files changed, 271 insertions(+), 165 deletions(-) diff --git a/ChangeLog b/ChangeLog index b97905f2..01a4409b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ What's New for OpenJPEG ! : changed + : added +February 11, 2000 +* [GB] Minor style modifications to comply with c99 compiler flag; removed Microsoft-specific "union-in-struct" syntax; Re-enabled cstr_info struct creation when -W switch is specified +! [GB] Changed a number of things in opjviewer (e.g., decoding thread does not execute GUI calls anymore), to have it running under linux --> it is better than before, but still crashes + February 5, 2008 ! [Parvatha] In convert.c, corrected imagetobmp() conversion for grayscale. In tcd.c, corrected Rate modification in tcd_init_encode(). Thanks to Jeremy Furtek and Jérôme Fimes. diff --git a/OPJViewer/Makefile b/OPJViewer/Makefile index d3cb3416..b691dc7b 100644 --- a/OPJViewer/Makefile +++ b/OPJViewer/Makefile @@ -4,9 +4,9 @@ CC = $(shell wx-config-2.8 --cxx) AR = ar -CFLAGS = -DUSE_JPWL -DwxUSE_LIBOPENJPEG -DwxUSE_GUI=1 -DOPJ_STATIC -DOPJ_HTMLABOUT $(shell wx-config-2.8 --cxxflags) # -g -p -pg -DUSE_JPWL +CFLAGS = -DUSE_JPWL -DwxUSE_LIBOPENJPEG -DwxUSE_GUI=1 -DOPJ_STATIC -DOPJ_HTMLABOUT -DOPJ_INICONFIG -DUSE_JPSEC -DOPJ_MANYFORMATS $(shell wx-config-2.8 --cxxflags) # -g -p -pg -DUSE_JPWL -OPJV_SRCS = source/imagj2k.cpp source/imagmj2.cpp source/wxj2kparser.cpp source/imagjp2.cpp source/OPJViewer.cpp source/wxjp2parser.cpp source/OPJViewer.cpp source/OPJThreads.cpp +OPJV_SRCS = source/imagjpeg2000.cpp source/wxj2kparser.cpp source/OPJViewer.cpp source/wxjp2parser.cpp source/OPJDialogs.cpp source/OPJThreads.cpp source/OPJAbout.cpp ../codec/index.c MODULES = $(OPJV_SRCS:.cpp=.o) @@ -19,7 +19,7 @@ lib: cd ../jpwl; make opjviewer: $(OPJV_SRCS) lib - $(CC) $(CFLAGS) -I .. $(OPJV_SRCS) -o OPJViewer -L ../jpwl -lopenjpeg_JPWL -lm -lstdc++ -ltiff $(shell wx-config-2.8 --libs) + $(CC) $(CFLAGS) -I .. -I ../codec -I ../libopenjpeg $(OPJV_SRCS) -o OPJViewer -L ../jpwl -lopenjpeg_JPWL -lm -lstdc++ -ltiff $(shell wx-config-2.8 --libs) clean: diff --git a/OPJViewer/OPJViewer.iss b/OPJViewer/OPJViewer.iss index a45bde6f..d4cfadbb 100644 --- a/OPJViewer/OPJViewer.iss +++ b/OPJViewer/OPJViewer.iss @@ -3,7 +3,7 @@ [Setup] AppName=OPJViewer -AppVerName=OPJViewer 0.3 alpha +AppVerName=OPJViewer 0.4 beta AppPublisher=OpenJPEG AppPublisherURL=http://www.openjpeg.org AppSupportURL=http://www.openjpeg.org @@ -11,13 +11,13 @@ AppUpdatesURL=http://www.openjpeg.org DefaultDirName={pf}\OPJViewer DefaultGroupName=OPJViewer OutputDir=setup -OutputBaseFilename=OPJViewer03alpha_setup +OutputBaseFilename=OPJViewer04beta_setup Compression=lzma SolidCompression=true InfoBeforeFile=source\readmebefore.txt InfoAfterFile=source\readmeafter.txt LicenseFile=source\license.txt -VersionInfoVersion=0.3.0.0 +VersionInfoVersion=0.4.0.0 VersionInfoCompany=OpenJPEG VersionInfoDescription=JPEG 2000 viewer ShowLanguageDialog=yes diff --git a/OPJViewer/Readme.txt b/OPJViewer/Readme.txt index 9322b32c..7eb3e467 100644 --- a/OPJViewer/Readme.txt +++ b/OPJViewer/Readme.txt @@ -1,7 +1,7 @@ =============================================================================== JPEG2000 Visualization Software - OPJViewer - Version 0.3 alpha + Version 0.4 beta =============================================================================== @@ -38,6 +38,11 @@ f) Build! g) Run! h) (OPTIONAL) Prepare an installer by compiling the InnoSetup script OPJViewer.iss (you need to download InnoSetup from http://www.jrsoftware.org/isinfo.php). +2.1.1 Additional libraries +---------------------------- + +Since we are also working on the Digital Cinema JPEG 2000, we are integrating the viewer with the MXF library, which is used to prepare the DCPs for digital movies. You can enable its linking in the code by specifying the USE_MXF preprocessor directive but, remember, the integration is at a very early stage. + 2.2. Compiling the source code in Unix-like systems ----------------------------------------------------- diff --git a/OPJViewer/source/OPJThreads.cpp b/OPJViewer/source/OPJThreads.cpp index 3b59a892..3c93ee23 100644 --- a/OPJViewer/source/OPJThreads.cpp +++ b/OPJViewer/source/OPJThreads.cpp @@ -130,7 +130,6 @@ void *OPJEncoThread::Entry() ///////////////////////////////////////////////////////////////////// // Decoding thread class ///////////////////////////////////////////////////////////////////// - OPJDecoThread::OPJDecoThread(OPJCanvas *canvas) : wxThread() { @@ -141,7 +140,15 @@ OPJDecoThread::OPJDecoThread(OPJCanvas *canvas) void OPJDecoThread::WriteText(const wxString& text) { wxString msg; + + // we use a fake event and post it for inter-thread gui communication + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, OPJFRAME_THREADLOGMSG); + event.SetInt(-1); + msg << text; + event.SetString(msg); + wxPostEvent(this->m_canvas->m_childframe->m_frame, event); +/* // before doing any GUI calls we must ensure that this thread is the only // one doing it! @@ -155,6 +162,7 @@ void OPJDecoThread::WriteText(const wxString& text) #ifndef __WXGTK__ wxMutexGuiLeave(); #endif // __WXGTK__ +*/ } void OPJDecoThread::OnExit() @@ -180,53 +188,24 @@ void *OPJDecoThread::Entry() wxString text; - srand(GetId()); + //srand(GetId()); //int m_countnum = rand() % 9; //text.Printf(wxT("Deco thread 0x%lx started (priority = %u, time = %d)."), // GetId(), GetPriority(), m_countnum); - text.Printf(wxT("Deco thread %d started"), m_canvas->m_childframe->m_winnumber); + // we have started + text.Printf(wxT("Deco thread %d started"), m_canvas->m_childframe->m_winnumber); WriteText(text); + // prepare dummy wximage wxBitmap bitmap(100, 100); wxImage image(100, 100, true); //= bitmap.ConvertToImage(); image.Destroy(); + // show image full name WriteText(m_canvas->m_fname.GetFullPath()); - // set handler properties -/* wxJ2KHandler *j2kkkhandler = (wxJ2KHandler *) wxImage::FindHandler( wxBITMAP_TYPE_J2K); - j2kkkhandler->m_reducefactor = wxGetApp().m_reducefactor; - j2kkkhandler->m_qualitylayers = wxGetApp().m_qualitylayers; - j2kkkhandler->m_components = wxGetApp().m_components; -#ifdef USE_JPWL - j2kkkhandler->m_enablejpwl = wxGetApp().m_enablejpwl; - j2kkkhandler->m_expcomps = wxGetApp().m_expcomps; - j2kkkhandler->m_maxtiles = wxGetApp().m_maxtiles; -#endif // USE_JPWL*/ - -/* wxJP2Handler *jp222handler = (wxJP2Handler *) wxImage::FindHandler( wxBITMAP_TYPE_JP2); - jp222handler->m_reducefactor = wxGetApp().m_reducefactor; - jp222handler->m_qualitylayers = wxGetApp().m_qualitylayers; - jp222handler->m_components = wxGetApp().m_components; -#ifdef USE_JPWL - jp222handler->m_enablejpwl = wxGetApp().m_enablejpwl; - jp222handler->m_expcomps = wxGetApp().m_expcomps; - jp222handler->m_maxtiles = wxGetApp().m_maxtiles; -#endif // USE_JPWL*/ - -/* wxMJ2Handler *mj222handler = (wxMJ2Handler *) wxImage::FindHandler( wxBITMAP_TYPE_MJ2); - mj222handler->m_reducefactor = wxGetApp().m_reducefactor; - mj222handler->m_qualitylayers = wxGetApp().m_qualitylayers; - mj222handler->m_components = wxGetApp().m_components; - mj222handler->m_framenum = wxGetApp().m_framenum; -#ifdef USE_JPWL - mj222handler->m_enablejpwl = wxGetApp().m_enablejpwl; - mj222handler->m_expcomps = wxGetApp().m_expcomps; - mj222handler->m_maxtiles = wxGetApp().m_maxtiles; -#endif // USE_JPWL*/ - wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(wxBITMAP_TYPE_JPEG2000); jpeg2000handler->m_reducefactor = wxGetApp().m_reducefactor; jpeg2000handler->m_qualitylayers = wxGetApp().m_qualitylayers; @@ -239,7 +218,7 @@ void *OPJDecoThread::Entry() #endif // USE_JPWL #ifdef USE_MXF - wxMXFHandler *mxfffhandler = (wxMXFHandler *) wxImage::FindHandler( wxBITMAP_TYPE_MXF); + wxMXFHandler *mxfffhandler = (wxMXFHandler *) wxImage::FindHandler(wxBITMAP_TYPE_MXF); mxfffhandler->m_reducefactor = wxGetApp().m_reducefactor; mxfffhandler->m_qualitylayers = wxGetApp().m_qualitylayers; mxfffhandler->m_components = wxGetApp().m_components; @@ -252,11 +231,12 @@ void *OPJDecoThread::Entry() #endif // USE_JPWL #endif // USE_MXF + // if decoding is enabled... if (wxGetApp().m_enabledeco) { // load the file if (!image.LoadFile(m_canvas->m_fname.GetFullPath(), wxBITMAP_TYPE_ANY, 0)) { - WriteText(wxT("Can't load image")); + WriteText(wxT("Can't load image!")); return NULL; } @@ -264,7 +244,7 @@ void *OPJDecoThread::Entry() // display a warning if (!image.Create(300, 5, false)) { - WriteText(wxT("Can't create image")); + WriteText(wxT("Can't create image!")); return NULL; } @@ -273,16 +253,22 @@ void *OPJDecoThread::Entry() // assign 100% image m_canvas->m_image100 = wxBitmap(image); + // signal the frame to refresh the canvas + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, OPJFRAME_VIEWFIT); + event.SetString(wxT("Fit me")); + event.SetInt(m_canvas->m_childframe->m_winnumber); + wxPostEvent(m_canvas->m_childframe->m_frame, event); + // find a fit-to-width zoom - int zooml, wzooml, hzooml; + /*int zooml, wzooml, hzooml; wxSize clientsize = m_canvas->GetClientSize(); wzooml = (int) floor(100.0 * (double) clientsize.GetWidth() / (double) (2 * OPJ_CANVAS_BORDER + image.GetWidth())); hzooml = (int) floor(100.0 * (double) clientsize.GetHeight() / (double) (2 * OPJ_CANVAS_BORDER + image.GetHeight())); - zooml = wxMin(100, wxMin(wzooml, hzooml)); + zooml = wxMin(100, wxMin(wzooml, hzooml));*/ // fit to width #ifndef __WXGTK__ - m_canvas->m_childframe->m_frame->Rescale(zooml, m_canvas->m_childframe); + //m_canvas->m_childframe->m_frame->Rescale(zooml, m_canvas->m_childframe); #endif // __WXGTK__ //m_canvas->m_image = m_canvas->m_image100; @@ -311,8 +297,15 @@ OPJParseThread::OPJParseThread(OPJMarkerTree *tree, wxTreeItemId parentid) void OPJParseThread::WriteText(const wxString& text) { wxString msg; + + // we use a fake event and post it for inter-thread gui communication + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, OPJFRAME_THREADLOGMSG); + event.SetInt(-1); + msg << text; + event.SetString(msg); + wxPostEvent(this->m_tree->m_childframe->m_frame, event); - // before doing any GUI calls we must ensure that this thread is the only +/* // before doing any GUI calls we must ensure that this thread is the only // one doing it! #ifndef __WXGTK__ @@ -324,7 +317,7 @@ void OPJParseThread::WriteText(const wxString& text) #ifndef __WXGTK__ wxMutexGuiLeave(); -#endif // __WXGTK +#endif // __WXGTK*/ } void OPJParseThread::OnExit() @@ -595,7 +588,6 @@ void OPJParseThread::LoadFile(wxFileName fname) } - // this is the root node if (this->m_parentid) m_tree->SetItemText(rootid, wxT("Codestream")); diff --git a/OPJViewer/source/OPJViewer.cpp b/OPJViewer/source/OPJViewer.cpp index 2cd2eb52..8f2c86e8 100644 --- a/OPJViewer/source/OPJViewer.cpp +++ b/OPJViewer/source/OPJViewer.cpp @@ -165,10 +165,6 @@ bool OPJViewerApp::OnInit(void) wxCmdLineParser parser(cmdLineDesc, argc, wxArgv); - /*parser.AddOption(_T("project_name"), _T(""), _T("full path to project file"), - wxCMD_LINE_VAL_STRING, - wxCMD_LINE_OPTION_MANDATORY | wxCMD_LINE_NEEDS_SEPARATOR);*/ - switch (parser.Parse()) { case -1: wxLogMessage(wxT("Help was given, terminating.")); @@ -190,9 +186,6 @@ bool OPJViewerApp::OnInit(void) wxImage::AddHandler( new wxJPEGHandler ); #endif #if wxUSE_LIBOPENJPEG - //wxImage::AddHandler( new wxJ2KHandler ); - //wxImage::AddHandler( new wxJP2Handler ); - //wxImage::AddHandler( new wxMJ2Handler ); wxImage::AddHandler( new wxJPEG2000Handler ); #endif #if USE_MXF @@ -477,9 +470,6 @@ void OPJViewerApp::ShowCmdLine(const wxCmdLineParser& parser) // OPJFrame events // Event class for sending text messages between worker and GUI threads -DECLARE_EVENT_TYPE(wxEVT_LOGMSG_EVENT, -1) -DEFINE_EVENT_TYPE(wxEVT_LOGMSG_EVENT) - BEGIN_EVENT_TABLE(OPJFrame, wxMDIParentFrame) EVT_MENU(OPJFRAME_HELPABOUT, OPJFrame::OnAbout) EVT_MENU(OPJFRAME_FILEOPEN, OPJFrame::OnFileOpen) @@ -510,7 +500,7 @@ BEGIN_EVENT_TABLE(OPJFrame, wxMDIParentFrame) EVT_MENU(OPJFRAME_SETSDECO, OPJFrame::OnSetsDeco) EVT_SASH_DRAGGED_RANGE(OPJFRAME_BROWSEWIN, OPJFRAME_LOGWIN, OPJFrame::OnSashDrag) EVT_NOTEBOOK_PAGE_CHANGED(LEFT_NOTEBOOK_ID, OPJFrame::OnNotebook) - EVT_COMMAND(wxID_ANY, wxEVT_LOGMSG_EVENT, OPJFrame::OnLogmsgEvent) + EVT_MENU(OPJFRAME_THREADLOGMSG, OPJFrame::OnThreadLogmsg) END_EVENT_TABLE() // this is the frame constructor @@ -928,10 +918,21 @@ void OPJFrame::OnClose(wxCommandEvent& WXUNUSED(event)) currframe->OnClose(e); } -void OPJFrame::OnFit(wxCommandEvent& WXUNUSED(event)) +void OPJFrame::OnFit(wxCommandEvent& event) { + OPJChildFrame *currchild; + wxString eventstring = event.GetString(); + + //wxLogMessage(wxT("OnFit:%d:%s"), event.GetInt(), eventstring); + // current child - OPJChildFrame *currchild = (OPJChildFrame *) GetActiveChild(); + if (event.GetInt() >= 1) { + currchild = m_childhash[event.GetInt()]; + } else { + currchild = (OPJChildFrame *) GetActiveChild(); + } + + // problems if (!currchild) return; @@ -939,14 +940,14 @@ void OPJFrame::OnFit(wxCommandEvent& WXUNUSED(event)) OPJCanvas *currcanvas = currchild->m_canvas; // find a fit-to-width zoom - int zooml, wzooml, hzooml; + /*int zooml, wzooml, hzooml; wxSize clientsize = currcanvas->GetClientSize(); wzooml = (int) ceil(100.0 * (double) (clientsize.GetWidth() - 2 * OPJ_CANVAS_BORDER) / (double) (currcanvas->m_image100.GetWidth())); hzooml = (int) ceil(100.0 * (double) (clientsize.GetHeight() - 2 * OPJ_CANVAS_BORDER) / (double) (currcanvas->m_image100.GetHeight())); - zooml = wxMin(100, wxMin(wzooml, hzooml)); + zooml = wxMin(100, wxMin(wzooml, hzooml));*/ // fit to width - Rescale(zooml, currchild); + Rescale(-1, currchild); } void OPJFrame::OnZoom(wxCommandEvent& WXUNUSED(event)) @@ -976,7 +977,20 @@ void OPJFrame::Rescale(int zooml, OPJChildFrame *currframe) // resizing enabled? if (wxGetApp().m_resizemethod == -1) { + zooml = 100; + + } else { + + if (zooml < 0) { + // find a fit-to-width zoom + int wzooml, hzooml; + //wxSize clientsize = currframe->m_canvas->GetClientSize(); + wxSize clientsize = currframe->m_frame->GetActiveChild()->GetClientSize(); + wzooml = (int) floor(100.0 * (double) clientsize.GetWidth() / (double) (2 * OPJ_CANVAS_BORDER + currframe->m_canvas->m_image100.GetWidth())); + hzooml = (int) floor(100.0 * (double) clientsize.GetHeight() / (double) (2 * OPJ_CANVAS_BORDER + currframe->m_canvas->m_image100.GetHeight())); + zooml = wxMin(100, wxMin(wzooml, hzooml)); + } } if (zooml != 100) @@ -992,6 +1006,8 @@ void OPJFrame::Rescale(int zooml, OPJChildFrame *currframe) currframe->m_canvas->Refresh(); + wxLogMessage(wxT("Rescale said %d%%"), zooml); + // update zoom currframe->m_canvas->m_zooml = zooml; } @@ -1199,6 +1215,36 @@ void OPJFrame::OnSashDrag(wxSashEvent& event) } +void OPJFrame::OnThreadLogmsg(wxCommandEvent& event) +{ +#if 1 + wxLogMessage(wxT("Frame got message from worker thread: %d"), event.GetInt()); + wxLogMessage(event.GetString()); +#else + int n = event.GetInt(); + if ( n == -1 ) + { + m_dlgProgress->Destroy(); + m_dlgProgress = (wxProgressDialog *)NULL; + + // the dialog is aborted because the event came from another thread, so + // we may need to wake up the main event loop for the dialog to be + // really closed + wxWakeUpIdle(); + } + else + { + if ( !m_dlgProgress->Update(n) ) + { + wxCriticalSectionLocker lock(m_critsectWork); + + m_cancelled = true; + } + } +#endif +} + + // physically save the file void OPJFrame::SaveFile(wxArrayString paths, wxArrayString filenames) { @@ -1364,6 +1410,7 @@ void OPJFrame::OnMemoryOpen(wxCommandEvent& WXUNUSED(event)) BEGIN_EVENT_TABLE(OPJCanvas, wxScrolledWindow) EVT_MOUSE_EVENTS(OPJCanvas::OnEvent) + EVT_MENU(OPJCANVAS_THREADSIGNAL, OPJCanvas::OnThreadSignal) END_EVENT_TABLE() // Define a constructor for my canvas @@ -1469,13 +1516,33 @@ void OPJFrame::OnSize(wxSizeEvent& WXUNUSED(event)) layout.LayoutMDIFrame(this); } -void OPJFrame::OnLogmsgEvent(wxCommandEvent &event) +void OPJCanvas::OnThreadSignal(wxCommandEvent& event) { - // receive string - wxString text = event.GetString(); +#if 1 + wxLogMessage(wxT("Canvas got signal from deco thread: %d"), event.GetInt()); + wxLogMessage(event.GetString()); +#else + int n = event.GetInt(); + if ( n == -1 ) + { + m_dlgProgress->Destroy(); + m_dlgProgress = (wxProgressDialog *)NULL; - // show it on the log - wxLogMessage(text); + // the dialog is aborted because the event came from another thread, so + // we may need to wake up the main event loop for the dialog to be + // really closed + wxWakeUpIdle(); + } + else + { + if ( !m_dlgProgress->Update(n) ) + { + wxCriticalSectionLocker lock(m_critsectWork); + + m_cancelled = true; + } + } +#endif } diff --git a/OPJViewer/source/OPJViewer.h b/OPJViewer/source/OPJViewer.h index 8d36bcc2..3574dac1 100644 --- a/OPJViewer/source/OPJViewer.h +++ b/OPJViewer/source/OPJViewer.h @@ -269,8 +269,13 @@ class OPJCanvas: public wxScrolledWindow wxMutexGuiLeave(); #endif //__WXGTK__ } + + void OnThreadSignal(wxCommandEvent& event); + OPJDecoThread *CreateDecoThread(void); OPJEncoThread *CreateEncoThread(void); + + OPJChildFrame *m_childframe; wxBitmap m_image, m_image100; @@ -419,7 +424,7 @@ class OPJFrame: public wxMDIParentFrame void OnQuit(wxCommandEvent& WXUNUSED(event)); void OnClose(wxCommandEvent& WXUNUSED(event)); void OnZoom(wxCommandEvent& WXUNUSED(event)); - void OnFit(wxCommandEvent& WXUNUSED(event)); + void OnFit(wxCommandEvent& event); void OnToggleBrowser(wxCommandEvent& WXUNUSED(event)); void OnTogglePeeker(wxCommandEvent& WXUNUSED(event)); void OnToggleToolbar(wxCommandEvent& WXUNUSED(event)); @@ -443,7 +448,7 @@ class OPJFrame: public wxMDIParentFrame void SaveFile(wxArrayString paths, wxArrayString filenames); void OnNotebook(wxNotebookEvent& event); void Rescale(int scale, OPJChildFrame *child); - void OnLogmsgEvent(wxCommandEvent &event); + void OnThreadLogmsg(wxCommandEvent& event); OPJMarkerTreeHash m_treehash; OPJChildFrameHash m_childhash; @@ -523,7 +528,10 @@ enum { OPJFRAME_BROWSEWIN = 10000, OPJFRAME_LOGWIN, - OPJFRAME_TOOLBAR + OPJFRAME_TOOLBAR, + + OPJFRAME_THREADLOGMSG, + OPJCANVAS_THREADSIGNAL }; diff --git a/OPJViewer/source/build.h b/OPJViewer/source/build.h index f4941bb1..9858dffe 100644 --- a/OPJViewer/source/build.h +++ b/OPJViewer/source/build.h @@ -1 +1 @@ -wxT("468") +wxT("491") diff --git a/OPJViewer/source/imagjpeg2000.cpp b/OPJViewer/source/imagjpeg2000.cpp index bcf1ca73..66e1146b 100644 --- a/OPJViewer/source/imagjpeg2000.cpp +++ b/OPJViewer/source/imagjpeg2000.cpp @@ -128,46 +128,61 @@ jpeg2000familytype(unsigned char *hdr, int hdr_len) } -/* sample error callback expecting a FILE* client object */ -void jpeg2000_error_callback(const char *msg, void *client_data) { - int message_len = strlen(msg) - 1; - if (msg[message_len] != '\n') - message_len = MAX_MESSAGE_LEN; +/* we have to use this to avoid GUI-noGUI threads crashing */ +void printevent(const char *msg) +{ #ifndef __WXGTK__ - wxMutexGuiEnter(); + wxMutexGuiEnter(); #endif /* __WXGTK__ */ - wxLogMessage(wxT("[ERROR] %.*s"), message_len, msg); + wxLogMessage(wxT("%s"), msg); #ifndef __WXGTK__ wxMutexGuiLeave(); #endif /* __WXGTK__ */ } +/* sample error callback expecting a FILE* client object */ +void jpeg2000_error_callback(const char *msg, void *client_data) { + char mess[MAX_MESSAGE_LEN + 20]; + int message_len = strlen(msg); + + if (message_len > MAX_MESSAGE_LEN) + message_len = MAX_MESSAGE_LEN; + + if (msg[message_len - 1] == '\n') + message_len--; + + sprintf(mess, "[ERROR] %.*s", message_len, msg); + printevent(mess); +} + /* sample warning callback expecting a FILE* client object */ void jpeg2000_warning_callback(const char *msg, void *client_data) { - int message_len = strlen(msg) - 1; - if (msg[message_len] != '\n') + char mess[MAX_MESSAGE_LEN + 20]; + int message_len = strlen(msg); + + if (message_len > MAX_MESSAGE_LEN) message_len = MAX_MESSAGE_LEN; -#ifndef __WXGTK__ - wxMutexGuiEnter(); -#endif /* __WXGTK__ */ - wxLogMessage(wxT("[WARNING] %.*s"), message_len, msg); -#ifndef __WXGTK__ - wxMutexGuiLeave(); -#endif /* __WXGTK__ */ + + if (msg[message_len - 1] == '\n') + message_len--; + + sprintf(mess, "[WARNING] %.*s", message_len, msg); + printevent(mess); } /* sample debug callback expecting no client object */ void jpeg2000_info_callback(const char *msg, void *client_data) { - int message_len = strlen(msg) - 1; - if (msg[message_len] != '\n') + char mess[MAX_MESSAGE_LEN + 20]; + int message_len = strlen(msg); + + if (message_len > MAX_MESSAGE_LEN) message_len = MAX_MESSAGE_LEN; -#ifndef __WXGTK__ - wxMutexGuiEnter(); -#endif /* __WXGTK__ */ - wxLogMessage(wxT("[INFO] %.*s"), message_len, msg); -#ifndef __WXGTK__ - wxMutexGuiLeave(); -#endif /* __WXGTK__ */ + + if (msg[message_len - 1] == '\n') + message_len--; + + sprintf(mess, "[INFO] %.*s", message_len, msg); + printevent(mess); } /* macro functions */ diff --git a/codec/image_to_j2k.c b/codec/image_to_j2k.c index 7fbd5a8a..0ce1a357 100644 --- a/codec/image_to_j2k.c +++ b/codec/image_to_j2k.c @@ -1054,7 +1054,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, int hprot, pprot, sens, addr, size, range; /* we need to enable indexing */ - if (!indexfilename) { + if (!indexfilename || !strcmp(indexfilename, "")) { strncpy(indexfilename, JPWL_PRIVATEINDEX_NAME, OPJ_PATH_LEN); } @@ -1122,7 +1122,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, /* search packet error protection method */ if (*token == 'p') { - static int pack = 0, tile = 0, packspec = 0, lastpackno = 0; + static int pack = 0, tile = 0, packspec = 0/*, lastpackno = 0*/; pprot = 1; /* predefined method */ @@ -1278,7 +1278,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, /* search addressing size */ if (*token == 'a') { - static int tile = 0, tilespec = 0, lasttileno = 0; + /*static int tile = 0, tilespec = 0, lasttileno = 0*/; addr = 0; /* predefined: auto */ @@ -1304,7 +1304,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, /* search sensitivity size */ if (*token == 'z') { - static int tile = 0, tilespec = 0, lasttileno = 0; + /*static int tile = 0, tilespec = 0, lasttileno = 0;*/ size = 1; /* predefined: 1 byte */ @@ -1330,7 +1330,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, /* search range method */ if (*token == 'g') { - static int tile = 0, tilespec = 0, lasttileno = 0; + /*static int tile = 0, tilespec = 0, lasttileno = 0;*/ range = 0; /* predefined: 0 (packet) */ diff --git a/jpwl/JPWL_j2k_to_image.dsp b/jpwl/JPWL_j2k_to_image.dsp index 971b8a31..a64d80c8 100644 --- a/jpwl/JPWL_j2k_to_image.dsp +++ b/jpwl/JPWL_j2k_to_image.dsp @@ -42,7 +42,8 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /FD /c +# SUBTRACT CPP /YX # ADD BASE RSC /l 0x80c /d "NDEBUG" # ADD RSC /l 0x80c /d "NDEBUG" BSC32=bscmake.exe diff --git a/jpwl/LibOpenJPEG_JPWL.dsp b/jpwl/LibOpenJPEG_JPWL.dsp index d4d0bef9..d7bf7937 100644 --- a/jpwl/LibOpenJPEG_JPWL.dsp +++ b/jpwl/LibOpenJPEG_JPWL.dsp @@ -41,7 +41,8 @@ RSC=rc.exe # PROP Intermediate_Dir "Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /FD /c +# SUBTRACT CPP /YX # ADD BASE RSC /l 0x80c /d "NDEBUG" # ADD RSC /l 0x80c /d "NDEBUG" BSC32=bscmake.exe @@ -64,7 +65,8 @@ LIB32=link.exe -lib # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../libopenjpeg" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../libopenjpeg" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /FD /GZ /c +# SUBTRACT CPP /YX # ADD BASE RSC /l 0x80c /d "_DEBUG" # ADD RSC /l 0x80c /d "_DEBUG" BSC32=bscmake.exe diff --git a/jpwl/Makefile b/jpwl/Makefile index 4c4bb105..9dce884a 100755 --- a/jpwl/Makefile +++ b/jpwl/Makefile @@ -19,8 +19,8 @@ INSTALL_INCLUDE = $(PREFIX)/include # Converts cr/lf to just lf DOS2UNIX = dos2unix -COMPILERFLAGS = -O3 -fPIC -LIBRARIES = -lstdc++ +COMPILERFLAGS = -Wall -O3 -ffast-math -std=c99 -fPIC +LIBRARIES = -lstdc++ MODULES = $(SRCS:.c=.o) CFLAGS = $(COMPILERFLAGS) $(INCLUDE) -DUSE_JPWL @@ -60,10 +60,10 @@ $(SHAREDLIB): $(MODULES) $(CC) -s -shared -Wl,-soname,$(LIBNAME) -o $@ $(MODULES) $(LIBRARIES) JPWL_j2k_to_image: ../codec/j2k_to_image.c - gcc $(CFLAGS) ../codec/convert.c ../codec/j2k_to_image.c -o JPWL_j2k_to_image -I ../libopenjpeg/ -L . -lopenjpeg_JPWL -lm -ltiff + gcc $(CFLAGS) ../codec/compat/getopt.c ../codec/index.c ../codec/convert.c ../codec/j2k_to_image.c -o JPWL_j2k_to_image -I ../libopenjpeg/ -L . -lopenjpeg_JPWL -lm -ltiff JPWL_image_to_j2k: ../codec/image_to_j2k.c - gcc $(CFLAGS) ../codec/convert.c ../codec/image_to_j2k.c -o JPWL_image_to_j2k -I ../libopenjpeg/ -L . -lopenjpeg_JPWL -lm -ltiff + gcc $(CFLAGS) ../codec/compat/getopt.c ../codec/index.c ../codec/convert.c ../codec/image_to_j2k.c -o JPWL_image_to_j2k -I ../libopenjpeg/ -L . -lopenjpeg_JPWL -lm -ltiff install: OpenJPEG install -d '$(DESTDIR)$(INSTALL_LIBDIR)' '$(DESTDIR)$(INSTALL_INCLUDE)' diff --git a/jpwl/jpwl.c b/jpwl/jpwl.c index 7351409f..07ca796a 100644 --- a/jpwl/jpwl.c +++ b/jpwl/jpwl.c @@ -122,19 +122,19 @@ void jpwl_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { switch (jwmarker[mm].id) { case J2K_MS_EPB: - free(jwmarker[mm].epbmark); + opj_free(jwmarker[mm].m.epbmark); break; case J2K_MS_EPC: - free(jwmarker[mm].epcmark); + opj_free(jwmarker[mm].m.epcmark); break; case J2K_MS_ESD: - free(jwmarker[mm].esdmark); + opj_free(jwmarker[mm].m.esdmark); break; case J2K_MS_RED: - free(jwmarker[mm].redmark); + opj_free(jwmarker[mm].m.redmark); break; default: @@ -202,18 +202,18 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { EPC MS for Main Header: if we are here it's required */ /* create the EPC */ - if (epc_mark = jpwl_epc_create( + if ((epc_mark = jpwl_epc_create( j2k, j2k->cp->esd_on, /* is ESD present? */ j2k->cp->red_on, /* is RED present? */ j2k->cp->epb_on, /* is EPB present? */ false /* are informative techniques present? */ - )) { + ))) { /* Add this marker to the 'insertanda' list */ if (epc_mark) { jwmarker[jwmarker_num].id = J2K_MS_EPC; /* its type */ - jwmarker[jwmarker_num].epcmark = epc_mark; /* the EPC */ + jwmarker[jwmarker_num].m.epcmark = epc_mark; /* the EPC */ jwmarker[jwmarker_num].pos = soc_pos + socsiz_len; /* after SIZ */ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.1; /* not so first */ jwmarker[jwmarker_num].len = epc_mark->Lepc; /* its length */ @@ -243,7 +243,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { if (j2k->cp->esd_on && (j2k->cp->sens_MH >= 0)) { /* Create the ESD */ - if (esd_mark = jpwl_esd_create( + if ((esd_mark = jpwl_esd_create( j2k, /* this encoder handle */ -1, /* we are averaging over all components */ (unsigned char) j2k->cp->sens_range, /* range method */ @@ -253,12 +253,12 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { -1, /* this ESD is in main header */ 0 /*j2k->cstr_info->num*/, /* number of packets in codestream */ NULL /*sensval*/ /* pointer to sensitivity data of packets */ - )) { + ))) { /* Add this marker to the 'insertanda' list */ if (jwmarker_num < JPWL_MAX_NO_MARKERS) { jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */ - jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */ + jwmarker[jwmarker_num].m.esdmark = esd_mark; /* the EPB */ jwmarker[jwmarker_num].pos = soc_pos + socsiz_len; /* we choose to place it after SIZ */ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */ jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */ @@ -337,7 +337,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { if (j2k->cp->esd_on && (sens >= 0)) { /* Create the ESD */ - if (esd_mark = jpwl_esd_create( + if ((esd_mark = jpwl_esd_create( j2k, /* this encoder handle */ -1, /* we are averaging over all components */ (unsigned char) j2k->cp->sens_range, /* range method */ @@ -347,12 +347,12 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { tileno, /* this ESD is in a tile */ 0, /* number of packets in codestream */ NULL /* pointer to sensitivity data of packets */ - )) { + ))) { /* Add this marker to the 'insertanda' list */ if (jwmarker_num < JPWL_MAX_NO_MARKERS) { jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */ - jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */ + jwmarker[jwmarker_num].m.esdmark = esd_mark; /* the EPB */ /****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */ jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */ @@ -416,7 +416,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { } /* Create the EPB */ - if (epb_mark = jpwl_epb_create( + if ((epb_mark = jpwl_epb_create( j2k, /* this encoder handle */ true, /* is it the latest? */ true, /* is it packed? not for now */ @@ -425,12 +425,12 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { j2k->cp->hprot_MH, /* protection type parameters of data */ socsiz_len, /* pre-data: only SOC+SIZ */ left_MHmarks_len /* post-data: from SOC to SOT, and all JPWL markers within */ - )) { + ))) { /* Add this marker to the 'insertanda' list */ if (jwmarker_num < JPWL_MAX_NO_MARKERS) { jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */ - jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */ + jwmarker[jwmarker_num].m.epbmark = epb_mark; /* the EPB */ jwmarker[jwmarker_num].pos = soc_pos + socsiz_len; /* after SIZ */ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */ jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */ @@ -474,7 +474,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { int sot_len, Psot, Psotp, mm, epb_index = 0, prot_len = 0; unsigned long sot_pos, post_sod_pos; - unsigned long int left_THmarks_len, epbs_len = 0; + unsigned long int left_THmarks_len/*, epbs_len = 0*/; int startpack = 0, stoppack = j2k->cstr_info->packno; int first_tp_pack, last_tp_pack; jpwl_epb_ms_t *tph_epb = NULL; @@ -514,7 +514,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { if (j2k->cp->epb_on && (hprot > 0)) { /* Create the EPB */ - if (epb_mark = jpwl_epb_create( + if ((epb_mark = jpwl_epb_create( j2k, /* this encoder handle */ false, /* is it the latest? in TPH, no for now (if huge data size in TPH, we'd need more) */ true, /* is it packed? yes for now */ @@ -523,12 +523,12 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { hprot, /* protection type parameters of following data */ sot_len + 2, /* pre-data length: only SOT */ left_THmarks_len /* post-data length: from SOT end to SOD inclusive */ - )) { + ))) { /* Add this marker to the 'insertanda' list */ if (jwmarker_num < JPWL_MAX_NO_MARKERS) { jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */ - jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */ + jwmarker[jwmarker_num].m.epbmark = epb_mark; /* the EPB */ /****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */ jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */ @@ -712,7 +712,7 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { int mm; unsigned long int old_size = j2k->cstr_info->codestream_size; unsigned long int new_size = old_size; - int ciopos = cio_tell(cio), soc_pos = j2k->cstr_info->main_head_start; + int /*ciopos = cio_tell(cio),*/ soc_pos = j2k->cstr_info->main_head_start; unsigned char *jpwl_buf, *orig_buf; unsigned long int orig_pos; double epbcoding_time = 0.0, esdcoding_time = 0.0; @@ -758,15 +758,15 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { switch (jwmarker[mm].id) { case J2K_MS_EPB: - jpwl_epb_write(j2k, jwmarker[mm].epbmark, jpwl_buf); + jpwl_epb_write(j2k, jwmarker[mm].m.epbmark, jpwl_buf); break; case J2K_MS_EPC: - jpwl_epc_write(j2k, jwmarker[mm].epcmark, jpwl_buf); + jpwl_epc_write(j2k, jwmarker[mm].m.epcmark, jpwl_buf); break; case J2K_MS_ESD: - jpwl_esd_write(j2k, jwmarker[mm].esdmark, jpwl_buf); + jpwl_esd_write(j2k, jwmarker[mm].m.esdmark, jpwl_buf); break; case J2K_MS_RED: @@ -812,11 +812,11 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { unsigned short int mycrc = 0x0000; /* fix and fill the DL field */ - jwmarker[mm].epcmark->DL = new_size; - orig_buf[epc_pos + 6] = (unsigned char) (jwmarker[mm].epcmark->DL >> 24); - orig_buf[epc_pos + 7] = (unsigned char) (jwmarker[mm].epcmark->DL >> 16); - orig_buf[epc_pos + 8] = (unsigned char) (jwmarker[mm].epcmark->DL >> 8); - orig_buf[epc_pos + 9] = (unsigned char) (jwmarker[mm].epcmark->DL >> 0); + jwmarker[mm].m.epcmark->DL = new_size; + orig_buf[epc_pos + 6] = (unsigned char) (jwmarker[mm].m.epcmark->DL >> 24); + orig_buf[epc_pos + 7] = (unsigned char) (jwmarker[mm].m.epcmark->DL >> 16); + orig_buf[epc_pos + 8] = (unsigned char) (jwmarker[mm].m.epcmark->DL >> 8); + orig_buf[epc_pos + 9] = (unsigned char) (jwmarker[mm].m.epcmark->DL >> 0); /* compute the CRC field (excluding itself) */ for (pp = 0; pp < 4; pp++) @@ -825,9 +825,9 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { jpwl_updateCRC16(&mycrc, orig_buf[epc_pos + pp]); /* fix and fill the CRC */ - jwmarker[mm].epcmark->Pcrc = mycrc; - orig_buf[epc_pos + 4] = (unsigned char) (jwmarker[mm].epcmark->Pcrc >> 8); - orig_buf[epc_pos + 5] = (unsigned char) (jwmarker[mm].epcmark->Pcrc >> 0); + jwmarker[mm].m.epcmark->Pcrc = mycrc; + orig_buf[epc_pos + 4] = (unsigned char) (jwmarker[mm].m.epcmark->Pcrc >> 8); + orig_buf[epc_pos + 5] = (unsigned char) (jwmarker[mm].m.epcmark->Pcrc >> 0); } } @@ -842,7 +842,7 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { /* remember that they are now in a new position (dpos) */ int esd_pos = (int) jwmarker[mm].dpos; - jpwl_esd_fill(j2k, jwmarker[mm].esdmark, &orig_buf[esd_pos]); + jpwl_esd_fill(j2k, jwmarker[mm].m.esdmark, &orig_buf[esd_pos]); } @@ -867,16 +867,16 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) { accum_len = 0; for (nn = mm; (nn < jwmarker_num) && (jwmarker[nn].id == J2K_MS_EPB) && (jwmarker[nn].pos == jwmarker[mm].pos); nn++) - accum_len += jwmarker[nn].epbmark->Lepb + 2; + accum_len += jwmarker[nn].m.epbmark->Lepb + 2; /* fill the current (first) EPB with post-data starting from the computed position */ - jpwl_epb_fill(j2k, jwmarker[mm].epbmark, &orig_buf[(int) jwmarker[mm].dpos], + jpwl_epb_fill(j2k, jwmarker[mm].m.epbmark, &orig_buf[(int) jwmarker[mm].dpos], &orig_buf[(int) jwmarker[mm].dpos + accum_len]); /* fill the remaining EPBs in the header with post-data starting from the last position */ for (nn = mm + 1; (nn < jwmarker_num) && (jwmarker[nn].id == J2K_MS_EPB) && (jwmarker[nn].pos == jwmarker[mm].pos); nn++) - jpwl_epb_fill(j2k, jwmarker[nn].epbmark, &orig_buf[(int) jwmarker[nn].dpos], NULL); + jpwl_epb_fill(j2k, jwmarker[nn].m.epbmark, &orig_buf[(int) jwmarker[nn].dpos], NULL); /* skip all the processed EPBs */ mm = nn - 1; @@ -1106,9 +1106,9 @@ void j2k_read_epb(opj_j2k_t *j2k) { if (((Pepb & 0xF0000000) >> 28) == 0) sprintf(str1, "pred"); /* predefined */ else if (((Pepb & 0xF0000000) >> 28) == 1) - sprintf(str1, "crc-%d", 16 * ((Pepb & 0x00000001) + 1)); /* CRC mode */ + sprintf(str1, "crc-%lu", 16 * ((Pepb & 0x00000001) + 1)); /* CRC mode */ else if (((Pepb & 0xF0000000) >> 28) == 2) - sprintf(str1, "rs(%d,32)", (Pepb & 0x0000FF00) >> 8); /* RS mode */ + sprintf(str1, "rs(%lu,32)", (Pepb & 0x0000FF00) >> 8); /* RS mode */ else if (Pepb == 0xFFFFFFFF) sprintf(str1, "nometh"); /* RS mode */ else diff --git a/jpwl/jpwl.h b/jpwl/jpwl.h index a58f2882..a96840cc 100644 --- a/jpwl/jpwl.h +++ b/jpwl/jpwl.h @@ -179,7 +179,7 @@ typedef struct jpwl_marker { /** marker value (J2K_MS_EPC, etc.) */ int id; /** union keeping the pointer to the real marker struct */ - union { + union jpwl_marks { /** pointer to EPB marker */ jpwl_epb_ms_t *epbmark; /** pointer to EPC marker */ @@ -188,7 +188,7 @@ typedef struct jpwl_marker { jpwl_esd_ms_t *esdmark; /** pointer to RED marker */ jpwl_red_ms_t *redmark; - }; + } m; /** position where the marker should go, in the pre-JPWL codestream */ unsigned long int pos; /** same as before, only written as a double, so we can sort it better */ diff --git a/jpwl/jpwl_lib.c b/jpwl/jpwl_lib.c index f6a165b3..90391b01 100644 --- a/jpwl/jpwl_lib.c +++ b/jpwl/jpwl_lib.c @@ -152,7 +152,7 @@ int jpwl_epbs_add(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int *jwmarker_num, /* length to use */ dL4 = min(max_postlen, post_len); - if (epb_mark = jpwl_epb_create( + if ((epb_mark = jpwl_epb_create( j2k, /* this encoder handle */ latest ? (dL4 < max_postlen) : false, /* is it the latest? */ packed, /* is it packed? */ @@ -161,12 +161,12 @@ int jpwl_epbs_add(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int *jwmarker_num, hprot, /* protection type parameters of following data */ 0, /* pre-data: nothing for now */ dL4 /* post-data: the stub computed previously */ - )) { + ))) { /* Add this marker to the 'insertanda' list */ if (*jwmarker_num < JPWL_MAX_NO_MARKERS) { jwmarker[*jwmarker_num].id = J2K_MS_EPB; /* its type */ - jwmarker[*jwmarker_num].epbmark = epb_mark; /* the EPB */ + jwmarker[*jwmarker_num].m.epbmark = epb_mark; /* the EPB */ jwmarker[*jwmarker_num].pos = (int) place_pos; /* after SOT */ jwmarker[*jwmarker_num].dpos = place_pos + 0.0000001 * (double)(*idx); /* not very first! */ jwmarker[*jwmarker_num].len = epb_mark->Lepb; /* its length */ @@ -200,10 +200,10 @@ jpwl_epb_ms_t *jpwl_epb_create(opj_j2k_t *j2k, bool latest, bool packed, int til unsigned long int pre_len, unsigned long int post_len) { jpwl_epb_ms_t *epb = NULL; - unsigned short int data_len = 0; + /*unsigned short int data_len = 0;*/ unsigned short int L2, L3; unsigned long int L1, L4; - unsigned char *predata_in = NULL; + /*unsigned char *predata_in = NULL;*/ bool insideMH = (tileno == -1); @@ -335,7 +335,7 @@ jpwl_epc_ms_t *jpwl_epc_create(opj_j2k_t *j2k, bool esd_on, bool red_on, bool ep jpwl_epc_ms_t *epc = NULL; /* Alloc space */ - if (!(epc = (jpwl_epc_ms_t *) malloc((size_t) 1 * sizeof (jpwl_epc_ms_t)))) { + if (!(epc = (jpwl_epc_ms_t *) opj_malloc((size_t) 1 * sizeof (jpwl_epc_ms_t)))) { opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for EPC MS\n"); return NULL; }; @@ -596,6 +596,15 @@ bool jpwl_correct(opj_j2k_t *j2k) { return true; } + /* Disable correction in case of missing or bad head EPB */ + /* We can't do better! */ + /* PATCHED: 2008-01-25 */ + /* MOVED UP: 2008-02-01 */ + if (!status) { + j2k->cp->correct = false; + opj_event_msg(j2k->cinfo, EVT_WARNING, "Couldn't find the MH EPB: disabling JPWL\n"); + } + } } @@ -790,6 +799,8 @@ bool jpwl_epb_correct(opj_j2k_t *j2k, unsigned char *buffer, int type, int pre_l case 3: /* automatic setup */ + opj_event_msg(j2k->cinfo, EVT_ERROR, "Auto. setup not yet implemented\n"); + return false; break; default: @@ -911,9 +922,9 @@ bool jpwl_epb_correct(opj_j2k_t *j2k, unsigned char *buffer, int type, int pre_l if (((Pepb & 0xF0000000) >> 28) == 0) sprintf(str1, "pred"); /* predefined */ else if (((Pepb & 0xF0000000) >> 28) == 1) - sprintf(str1, "crc-%d", 16 * ((Pepb & 0x00000001) + 1)); /* CRC mode */ + sprintf(str1, "crc-%lu", 16 * ((Pepb & 0x00000001) + 1)); /* CRC mode */ else if (((Pepb & 0xF0000000) >> 28) == 2) - sprintf(str1, "rs(%d,32)", (Pepb & 0x0000FF00) >> 8); /* RS mode */ + sprintf(str1, "rs(%lu,32)", (Pepb & 0x0000FF00) >> 8); /* RS mode */ else if (Pepb == 0xFFFFFFFF) sprintf(str1, "nometh"); /* RS mode */ else @@ -1196,7 +1207,7 @@ jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comp, unsigned char addrm, un jpwl_esd_ms_t *esd = NULL; /* Alloc space */ - if (!(esd = (jpwl_esd_ms_t *) malloc((size_t) 1 * sizeof (jpwl_esd_ms_t)))) { + if (!(esd = (jpwl_esd_ms_t *) opj_malloc((size_t) 1 * sizeof (jpwl_esd_ms_t)))) { opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for ESD MS\n"); return NULL; }; @@ -1325,8 +1336,8 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) { int i; unsigned long int vv; - unsigned long int addr1, addr2; - double dvalue, Omax2, tmp, TSE, MSE, oldMSE, PSNR, oldPSNR; + unsigned long int addr1 = 0L, addr2 = 0L; + double dvalue = 0.0, Omax2, tmp, TSE = 0.0, MSE, oldMSE = 0.0, PSNR, oldPSNR = 0.0; unsigned short int pfpvalue; unsigned long int addrmask = 0x00000000; bool doneMH = false, doneTPH = false; diff --git a/jpwl/rs.h b/jpwl/rs.h index fb89a734..6d2ed59b 100644 --- a/jpwl/rs.h +++ b/jpwl/rs.h @@ -55,7 +55,8 @@ * each error counting as two erasures. */ #define MM 8 /* RS code over GF(2**MM) - change to suit */ -static int KK; +//static int KK; +int KK; /* Original code */ /*#define KK 239*/ /* KK = number of information symbols */