diff --git a/ChangeLog b/ChangeLog index 8e348eac..d71b6032 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ What's New for OpenJPEG ! : changed + : added +November 29, 2007 +! [GB] Added index.h and index.c in VC6 projects; wrapped index.h in the C++ preprocessor; modified OPJViewer project and some files. + November 14, 2007 + [FOD] Created the file index.c in the codec directory. This file handles the creation of index files, at encoding and decoding. diff --git a/OPJViewer/Makefile b/OPJViewer/Makefile index 75f57230..d3cb3416 100644 --- a/OPJViewer/Makefile +++ b/OPJViewer/Makefile @@ -6,7 +6,7 @@ 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 -OPJV_SRCS = source/imagj2k.cpp source/imagmj2.cpp source/wxj2kparser.cpp source/imagjp2.cpp source/OPJViewer.cpp source/wxjp2parser.cpp +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 MODULES = $(OPJV_SRCS:.cpp=.o) diff --git a/OPJViewer/OPJViewer.dsp b/OPJViewer/OPJViewer.dsp index d9521f4c..dad478be 100644 --- a/OPJViewer/OPJViewer.dsp +++ b/OPJViewer/OPJViewer.dsp @@ -42,7 +42,7 @@ 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 /G6 /MD /W3 /GX /O2 /I "d:\programmi\wxWidgets-2.8.0\lib\vc_lib\msw" /I "d:\programmi\wxWidgets-2.8.0\include" /I ".." /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D WINVER=0x400 /D "_MT" /D wxUSE_GUI=1 /D "wxUSE_LIBOPENJPEG" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /D "OPJ_HTMLABOUT" /D "OPJ_MANYFORMATS" /D "OPJ_INICONFIG" /FR /FD /c +# ADD CPP /nologo /G6 /MD /W3 /GX /O2 /I "d:\programmi\wxWidgets-2.8.0\lib\vc_lib\msw" /I "d:\programmi\wxWidgets-2.8.0\include" /I ".." /I "../libopenjpeg" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D WINVER=0x400 /D "_MT" /D wxUSE_GUI=1 /D "wxUSE_LIBOPENJPEG" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /D "USE_MXF" /D "OPJ_HTMLABOUT" /D "OPJ_MANYFORMATS" /D "OPJ_INICONFIG" /FR /FD /c # ADD BASE RSC /l 0x410 /d "NDEBUG" # ADD RSC /l 0x409 /i "d:\programmi\wxWidgets-2.8.0\include" /d "NDEBUG" BSC32=bscmake.exe @@ -72,15 +72,15 @@ PostBuild_Cmds=buildupdate.bat # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "d:\Programmi\wxWidgets-2.8.0\INCLUDE" /I "d:\programmi\wxWidgets-2.8.0\lib\vc_lib\msw" /I "c:\programmi\wxWidgets-2.8.0\include" /I ".." /D "_DEBUG" /D "__WXDEBUG__" /D WXDEBUG=1 /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D WINVER=0x400 /D "_MT" /D wxUSE_GUI=1 /D "wxUSE_LIBOPENJPEG" /D "OPJ_STATIC" /D "USE_JPWL" /D "OPJ_HTMLABOUT" /FR /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "c:\Programmi\wxWidgets-2.8.0\INCLUDE" /I "c:\programmi\wxWidgets-2.8.0\lib\vc_lib\msw" /I "c:\programmi\wxWidgets-2.8.0\include" /I ".." /D "_DEBUG" /D "__WXDEBUG__" /D WXDEBUG=1 /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D WINVER=0x400 /D "_MT" /D wxUSE_GUI=1 /D "wxUSE_LIBOPENJPEG" /D "OPJ_STATIC" /D "USE_JPWL" /D "OPJ_HTMLABOUT" /FR /FD /GZ /c # ADD BASE RSC /l 0x410 /d "_DEBUG" -# ADD RSC /l 0x410 /i "d:\programmi\wxWidgets-2.8.0\include" /d "_DEBUG" +# ADD RSC /l 0x410 /i "c:\programmi\wxWidgets-2.8.0\include" /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib wxzlibd.lib wxregexd.lib wxpngd.lib wxjpegd.lib wxtiffd.lib wxbase28d.lib wxmsw28d_core.lib wxmsw28d_html.lib wxmsw28d_adv.lib LibOpenJPEG_JPWLd.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"libcmtd.lib" /pdbtype:sept /libpath:"d:\programmi\wxWidgets-2.8.0\lib\vc_lib" /libpath:"..\jpwl\Debug" +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib wxzlibd.lib wxregexd.lib wxpngd.lib wxjpegd.lib wxtiffd.lib wxbase28d.lib wxmsw28d_core.lib wxmsw28d_html.lib wxmsw28d_adv.lib LibOpenJPEG_JPWLd.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"libcmtd.lib" /pdbtype:sept /libpath:"c:\programmi\wxWidgets-2.8.0\lib\vc_lib" /libpath:"..\jpwl\Debug" # SUBTRACT LINK32 /pdb:none !ENDIF @@ -111,10 +111,26 @@ SOURCE=.\source\imagmj2.cpp # End Source File # Begin Source File +SOURCE=.\source\imagmxf.cpp +# End Source File +# Begin Source File + +SOURCE=..\codec\index.c +# End Source File +# Begin Source File + +SOURCE=.\source\OPJAbout.cpp +# End Source File +# Begin Source File + SOURCE=.\source\OPJDialogs.cpp # End Source File # Begin Source File +SOURCE=.\source\OPJThreads.cpp +# End Source File +# Begin Source File + SOURCE=.\source\OPJViewer.cpp # End Source File # Begin Source File @@ -160,6 +176,14 @@ SOURCE=.\source\imagmj2.h # End Source File # Begin Source File +SOURCE=.\source\imagmxf.h +# End Source File +# Begin Source File + +SOURCE=..\codec\index.h +# End Source File +# Begin Source File + SOURCE=.\source\OPJViewer.h # End Source File # End Group diff --git a/OPJViewer/source/OPJDialogs.cpp b/OPJViewer/source/OPJDialogs.cpp index 063cec8b..ed68ef3f 100644 --- a/OPJViewer/source/OPJDialogs.cpp +++ b/OPJViewer/source/OPJDialogs.cpp @@ -32,8 +32,8 @@ IMPLEMENT_CLASS(OPJDecoderDialog, wxPropertySheetDialog) BEGIN_EVENT_TABLE(OPJDecoderDialog, wxPropertySheetDialog) -#ifdef USE_JPWL EVT_CHECKBOX(OPJDECO_ENABLEDECO, OPJDecoderDialog::OnEnableDeco) +#ifdef USE_JPWL EVT_CHECKBOX(OPJDECO_ENABLEJPWL, OPJDecoderDialog::OnEnableJPWL) #endif // USE_JPWL END_EVENT_TABLE() @@ -400,21 +400,6 @@ void OPJDecoderDialog::OnEnableJPWL(wxCommandEvent& event) #endif // USE_JPWL -bool OPJDnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString& filenames) -{ - /*size_t nFiles = filenames.GetCount(); - wxString str; - str.Printf( _T("%d files dropped\n"), (int)nFiles); - for ( size_t n = 0; n < nFiles; n++ ) { - str << filenames[n] << wxT("\n"); - } - wxLogMessage(str);*/ - m_pOwner->OpenFiles(filenames, filenames); - - return true; -} - - @@ -425,12 +410,16 @@ bool OPJDnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString& filenames) IMPLEMENT_CLASS(OPJEncoderDialog, wxPropertySheetDialog) BEGIN_EVENT_TABLE(OPJEncoderDialog, wxPropertySheetDialog) -#ifdef USE_JPWL - EVT_CHECKBOX(OPJENCO_ENABLEJPWL, OPJEncoderDialog::OnEnableJPWL) EVT_CHECKBOX(OPJENCO_ENABLECOMM, OPJEncoderDialog::OnEnableComm) EVT_CHECKBOX(OPJENCO_ENABLEINDEX, OPJEncoderDialog::OnEnableIdx) + EVT_CHECKBOX(OPJENCO_ENABLEPOC, OPJEncoderDialog::OnEnablePoc) EVT_RADIOBUTTON(OPJENCO_RATERADIO, OPJEncoderDialog::OnRadioQualityRate) EVT_RADIOBUTTON(OPJENCO_QUALITYRADIO, OPJEncoderDialog::OnRadioQualityRate) +#ifdef USE_JPWL + EVT_CHECKBOX(OPJENCO_ENABLEJPWL, OPJEncoderDialog::OnEnableJPWL) + EVT_CHOICE(OPJENCO_HPROT, OPJEncoderDialog::OnHprotSelect) + EVT_CHOICE(OPJENCO_PPROT, OPJEncoderDialog::OnPprotSelect) + EVT_CHOICE(OPJENCO_SENSI, OPJEncoderDialog::OnSensiSelect) #endif // USE_JPWL END_EVENT_TABLE() @@ -454,12 +443,12 @@ OPJEncoderDialog::OPJEncoderDialog(wxWindow* win, int dialogType) wxPanel* jpwlSettings = CreatePart11SettingsPage(m_settingsNotebook); #endif // USE_JPWL - m_settingsNotebook->AddPage(jpeg2000_1Settings, wxT("JPEG 2000 - 1"), false); - m_settingsNotebook->AddPage(jpeg2000_2Settings, wxT("JPEG 2000 - 2"), false); - m_settingsNotebook->AddPage(mainSettings, wxT("General"), false); #ifdef USE_JPWL m_settingsNotebook->AddPage(jpwlSettings, wxT("JPWL"), false); #endif // USE_JPWL + m_settingsNotebook->AddPage(jpeg2000_1Settings, wxT("JPEG 2000 - 1"), false); + m_settingsNotebook->AddPage(jpeg2000_2Settings, wxT("JPEG 2000 - 2"), false); + m_settingsNotebook->AddPage(mainSettings, wxT("General"), false); LayoutDialog(); } @@ -491,12 +480,218 @@ wxPanel* OPJEncoderDialog::CreateMainSettingsPage(wxWindow* parent) wxPanel* OPJEncoderDialog::CreatePart11SettingsPage(wxWindow* parent) { wxPanel* panel = new wxPanel(parent, wxID_ANY); + int specno; // top sizer wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL); + // add JPWL enabling check box + topSizer->Add( + m_enablejpwlCheck = new wxCheckBox(panel, OPJENCO_ENABLEJPWL, wxT("Enable JPWL"), + wxDefaultPosition, wxDefaultSize), + 0, wxGROW | wxALL | wxALIGN_CENTER, 5); + m_enablejpwlCheck->SetValue(wxGetApp().m_enablejpwle); + // sub top sizer - wxBoxSizer *subtopSizer = new wxBoxSizer(wxVERTICAL); + wxFlexGridSizer *subtopSizer = new wxFlexGridSizer(2, 3, 3); + + // header settings, column + wxStaticBox* headerBox = new wxStaticBox(panel, wxID_ANY, wxT("Header protection")); + wxBoxSizer* headerSizer = new wxStaticBoxSizer(headerBox, wxVERTICAL); + + // info sizer, row + wxBoxSizer* info1Sizer = new wxBoxSizer(wxHORIZONTAL); + + // add some text + info1Sizer->Add(new wxStaticText(panel, wxID_ANY, + wxT("Type")), + 0, wxALL | wxALIGN_CENTER_VERTICAL, 1); + + // add some horizontal space + info1Sizer->Add(3, 3, 1, wxALL, 0); + + // add some text + info1Sizer->Add(new wxStaticText(panel, wxID_ANY, + wxT("Tile part")), + 0, wxALL | wxALIGN_CENTER_VERTICAL, 1); + + headerSizer->Add(info1Sizer, 0, wxGROW | wxALL, 0); + + // specify specs + wxString hprotvalues[] = {wxT("None"), wxT("Pred."), wxT("CRC16"), wxT("CRC32"), + wxT("RS37"), wxT("RS38"), wxT("RS40"), wxT("RS43"), wxT("RS45"), wxT("RS48"), + wxT("RS51"), wxT("RS53"), wxT("RS56"), wxT("RS64"), wxT("RS75"), wxT("RS80"), + wxT("RS85"), wxT("RS96"), wxT("RS112"), wxT("RS128")}; + for (specno = 0; specno < MYJPWL_MAX_NO_TILESPECS; specno++) { + + // tile+hprot sizer, row + wxBoxSizer* tilehprotSizer = new wxBoxSizer(wxHORIZONTAL); + + // add the value selection + tilehprotSizer->Add( + m_hprotChoice[specno] = new wxChoice(panel, OPJENCO_HPROT, + wxDefaultPosition, wxSize(60, wxDefaultCoord), + WXSIZEOF(hprotvalues), hprotvalues), + 0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 1); + m_hprotChoice[specno]->SetSelection(wxGetApp().m_hprotsel[specno]); + + // add some horizontal space + tilehprotSizer->Add(3, 3, 1, wxALL, 0); + + // add the value control + tilehprotSizer->Add( + m_htileCtrl[specno] = new wxSpinCtrl(panel, OPJENCO_HTILE, + wxString::Format(wxT("%d"), wxGetApp().m_htileval[specno]), + wxDefaultPosition, wxSize(45, wxDefaultCoord), + wxSP_ARROW_KEYS, + 0, JPWL_MAXIMUM_TILES - 1, 0), + 0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 1); + + headerSizer->Add(tilehprotSizer, 0, wxGROW | wxALL, 0); + } + + wxCommandEvent event1; + OnHprotSelect(event1); + + subtopSizer->Add(headerSizer, 0, wxGROW | wxALL, 3); + + // packet settings, column + wxStaticBox* packetBox = new wxStaticBox(panel, wxID_ANY, wxT("Packet protection")); + wxBoxSizer* packetSizer = new wxStaticBoxSizer(packetBox, wxVERTICAL); + + // info sizer, row + wxBoxSizer* info2Sizer = new wxBoxSizer(wxHORIZONTAL); + + // add some text + info2Sizer->Add(new wxStaticText(panel, wxID_ANY, + wxT("Type")), + 0, wxALL | wxALIGN_CENTER_VERTICAL, 1); + + // add some horizontal space + info2Sizer->Add(3, 3, 1, wxALL, 0); + + // add some text + info2Sizer->Add(new wxStaticText(panel, wxID_ANY, + wxT("Tile part")), + 0, wxALL | wxALIGN_CENTER_VERTICAL, 1); + + // add some horizontal space + info2Sizer->Add(3, 3, 1, wxALL, 0); + + // add some text + info2Sizer->Add(new wxStaticText(panel, wxID_ANY, + wxT("Packet")), + 0, wxALL | wxALIGN_CENTER_VERTICAL, 1); + + packetSizer->Add(info2Sizer, 0, wxGROW | wxALL, 0); + + // specify specs + wxString pprotvalues[] = {wxT("None"), wxT("Pred."), wxT("CRC16"), wxT("CRC32"), + wxT("RS37"), wxT("RS38"), wxT("RS40"), wxT("RS43"), wxT("RS45"), wxT("RS48"), + wxT("RS51"), wxT("RS53"), wxT("RS56"), wxT("RS64"), wxT("RS75"), wxT("RS80"), + wxT("RS85"), wxT("RS96"), wxT("RS112"), wxT("RS128")}; + for (specno = 0; specno < MYJPWL_MAX_NO_TILESPECS; specno++) { + + // tile+pprot sizer, row + wxBoxSizer* tilepprotSizer = new wxBoxSizer(wxHORIZONTAL); + + // add the value selection + tilepprotSizer->Add( + m_pprotChoice[specno] = new wxChoice(panel, OPJENCO_PPROT, + wxDefaultPosition, wxSize(60, wxDefaultCoord), + WXSIZEOF(pprotvalues), pprotvalues), + 0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 1); + m_pprotChoice[specno]->SetSelection(wxGetApp().m_pprotsel[specno]); + + // add some horizontal space + tilepprotSizer->Add(3, 3, 1, wxALL, 0); + + // add the value control + tilepprotSizer->Add( + m_ptileCtrl[specno] = new wxSpinCtrl(panel, OPJENCO_PTILE, + wxString::Format(wxT("%d"), wxGetApp().m_ptileval[specno]), + wxDefaultPosition, wxSize(45, wxDefaultCoord), + wxSP_ARROW_KEYS, + 0, JPWL_MAXIMUM_TILES - 1, 0), + 0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 1); + + // add some horizontal space + tilepprotSizer->Add(3, 3, 1, wxALL, 0); + + // add the value control + tilepprotSizer->Add( + m_ppackCtrl[specno] = new wxSpinCtrl(panel, OPJENCO_PPACK, + wxString::Format(wxT("%d"), wxGetApp().m_ppackval[specno]), + wxDefaultPosition, wxSize(50, wxDefaultCoord), + wxSP_ARROW_KEYS, + 0, 2047, 0), + 0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 1); + + packetSizer->Add(tilepprotSizer, 0, wxGROW | wxALL, 0); + } + + wxCommandEvent event2; + OnPprotSelect(event2); + + subtopSizer->Add(packetSizer, 0, wxGROW | wxALL, 3); + + // sensitivity settings, column + wxStaticBox* sensiBox = new wxStaticBox(panel, wxID_ANY, wxT("Sensitivity")); + wxBoxSizer* sensiSizer = new wxStaticBoxSizer(sensiBox, wxVERTICAL); + + // info sizer, row + wxBoxSizer* info3Sizer = new wxBoxSizer(wxHORIZONTAL); + + // add some text + info3Sizer->Add(new wxStaticText(panel, wxID_ANY, + wxT("Type")), + 0, wxALL | wxALIGN_CENTER_VERTICAL, 1); + + // add some horizontal space + info3Sizer->Add(3, 3, 1, wxALL, 0); + + // add some text + info3Sizer->Add(new wxStaticText(panel, wxID_ANY, + wxT("Tile part")), + 0, wxALL | wxALIGN_CENTER_VERTICAL, 1); + + sensiSizer->Add(info3Sizer, 0, wxGROW | wxALL, 0); + + // specify specs + wxString sensivalues[] = {wxT("None"), wxT("RELATIVE ERROR"), wxT("MSE"), + wxT("MSE REDUCTION"), wxT("PSNR INCREMENT"), wxT("MAXERR"), wxT("TSE")}; + for (specno = 0; specno < MYJPWL_MAX_NO_TILESPECS; specno++) { + + // tile+sensi sizer, row + wxBoxSizer* tilesensiSizer = new wxBoxSizer(wxHORIZONTAL); + + // add the value selection + tilesensiSizer->Add( + m_sensiChoice[specno] = new wxChoice(panel, OPJENCO_SENSI, + wxDefaultPosition, wxSize(110, wxDefaultCoord), + WXSIZEOF(sensivalues), sensivalues), + 0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 1); + m_sensiChoice[specno]->SetSelection(wxGetApp().m_sensisel[specno]); + + // add some horizontal space + tilesensiSizer->Add(3, 3, 1, wxALL, 0); + + // add the value control + tilesensiSizer->Add( + m_stileCtrl[specno] = new wxSpinCtrl(panel, OPJENCO_STILE, + wxString::Format(wxT("%d"), wxGetApp().m_stileval[specno]), + wxDefaultPosition, wxSize(45, wxDefaultCoord), + wxSP_ARROW_KEYS, + 0, JPWL_MAXIMUM_TILES - 1, 0), + 0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 1); + + sensiSizer->Add(tilesensiSizer, 0, wxGROW | wxALL, 0); + } + + wxCommandEvent event3; + OnSensiSelect(event3); + + subtopSizer->Add(sensiSizer, 0, wxGROW | wxALL, 3); topSizer->Add(subtopSizer, 1, wxGROW | wxALIGN_CENTRE | wxALL, 5); @@ -668,7 +863,7 @@ wxPanel* OPJEncoderDialog::CreatePart1_1SettingsPage(wxWindow* parent) wxString::Format(wxT("%d"), wxGetApp().m_resolutions), wxDefaultPosition, wxSize(80, wxDefaultCoord), wxSP_ARROW_KEYS, - 0, 256, 6), + 1, 256, 6), 0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3); transformSizer->Add(resnumSizer, 0, wxGROW | wxALL, 3); @@ -926,6 +1121,65 @@ wxPanel* OPJEncoderDialog::CreatePart1_2SettingsPage(wxWindow* parent) subtopSizer->Add(roiSizer, 0, wxGROW | wxALL, 3); + // POC settings, column + wxStaticBox* pocBox = new wxStaticBox(panel, wxID_ANY, wxT("POC")); + wxBoxSizer* pocSizer = new wxStaticBoxSizer(pocBox, wxVERTICAL); + + // POC check box + pocSizer->Add( + m_enablepocCheck = new wxCheckBox(panel, OPJENCO_ENABLEPOC, wxT("Enabled (tn=rs,cs,le,re,ce,pr)"), + wxDefaultPosition, wxDefaultSize), + 0, wxGROW | wxALL, 3); + m_enablepocCheck->SetValue(wxGetApp().m_enablepoc); + + // POC sizer, row + wxBoxSizer* pocspecSizer = new wxBoxSizer(wxHORIZONTAL); + + // add some text + pocspecSizer->Add(new wxStaticText(panel, wxID_ANY, wxT("&Changes:")), + 0, wxALL | wxALIGN_TOP, 3); + + // add some horizontal space + pocspecSizer->Add(3, 3, 1, wxALL, 0); + + // add the value control + pocspecSizer->Add( + m_pocCtrl = new wxTextCtrl(panel, OPJENCO_POCSPEC, + wxGetApp().m_poc, + wxDefaultPosition, wxSize(140, 60), + wxTE_LEFT | wxTE_MULTILINE), + 0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3); + m_pocCtrl->Enable(wxGetApp().m_enablepoc); + + pocSizer->Add(pocspecSizer, 0, wxGROW | wxALL, 3); + + subtopSizer->Add(pocSizer, 0, wxGROW | wxALL, 3); + + // Comment settings, column + wxStaticBox* commentBox = new wxStaticBox(panel, wxID_ANY, wxT("Comment")); + wxBoxSizer* commentSizer = new wxStaticBoxSizer(commentBox, wxVERTICAL); + + // commenting check box + commentSizer->Add( + m_enablecommCheck = new wxCheckBox(panel, OPJENCO_ENABLECOMM, wxT("Enabled (empty to reset)"), + wxDefaultPosition, wxDefaultSize), + 0, wxGROW | wxALL, 3); + m_enablecommCheck->SetValue(wxGetApp().m_enablecomm); + + // add some horizontal space + commentSizer->Add(3, 3, 1, wxALL, 0); + + // add the value control + commentSizer->Add( + m_commentCtrl = new wxTextCtrl(panel, OPJENCO_COMMENTTEXT, + wxGetApp().m_comment, + wxDefaultPosition, wxSize(wxDefaultCoord, 60), + wxTE_LEFT | wxTE_MULTILINE), + 0, wxGROW | wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3); + m_commentCtrl->Enable(wxGetApp().m_enablecomm); + + subtopSizer->Add(commentSizer, 0, wxGROW | wxALL, 3); + // Index file settings, column wxStaticBox* indexBox = new wxStaticBox(panel, wxID_ANY, wxT("Indexing")); wxBoxSizer* indexSizer = new wxStaticBoxSizer(indexBox, wxVERTICAL); @@ -960,65 +1214,6 @@ wxPanel* OPJEncoderDialog::CreatePart1_2SettingsPage(wxWindow* parent) subtopSizer->Add(indexSizer, 0, wxGROW | wxALL, 3); - // Comment settings, column - wxStaticBox* commentBox = new wxStaticBox(panel, wxID_ANY, wxT("Comment")); - wxBoxSizer* commentSizer = new wxStaticBoxSizer(commentBox, wxVERTICAL); - - // commenting check box - commentSizer->Add( - m_enablecommCheck = new wxCheckBox(panel, OPJENCO_ENABLECOMM, wxT("Enabled (empty to reset)"), - wxDefaultPosition, wxDefaultSize), - 0, wxGROW | wxALL, 3); - m_enablecommCheck->SetValue(wxGetApp().m_enablecomm); - - // add some horizontal space - commentSizer->Add(3, 3, 1, wxALL, 0); - - // add the value control - commentSizer->Add( - m_commentCtrl = new wxTextCtrl(panel, OPJENCO_COMMENTTEXT, - wxGetApp().m_comment, - wxDefaultPosition, wxSize(wxDefaultCoord, 60), - wxTE_LEFT | wxTE_MULTILINE), - 0, wxGROW | wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3); - m_commentCtrl->Enable(wxGetApp().m_enablecomm); - - subtopSizer->Add(commentSizer, 0, wxGROW | wxALL, 3); - - // POC settings, column - wxStaticBox* pocBox = new wxStaticBox(panel, wxID_ANY, wxT("POC")); - wxBoxSizer* pocSizer = new wxStaticBoxSizer(pocBox, wxVERTICAL); - - // POC check box - pocSizer->Add( - m_enablepocCheck = new wxCheckBox(panel, OPJENCO_ENABLEPOC, wxT("Enabled"), - wxDefaultPosition, wxDefaultSize), - 0, wxGROW | wxALL, 3); - m_enablepocCheck->SetValue(/*wxGetApp().m_enableidx*/true); - - // POC sizer, row - wxBoxSizer* pocspecSizer = new wxBoxSizer(wxHORIZONTAL); - - // add some text - pocspecSizer->Add(new wxStaticText(panel, wxID_ANY, wxT("&Changes:")), - 0, wxALL | wxALIGN_CENTER_VERTICAL, 3); - - // add some horizontal space - pocspecSizer->Add(3, 3, 1, wxALL, 0); - - // add the value control - pocspecSizer->Add( - m_pocCtrl = new wxTextCtrl(panel, OPJENCO_POCSPEC, - /*wxGetApp().m_index*/wxT("RRRR"), - wxDefaultPosition, wxSize(120, wxDefaultCoord), - wxTE_LEFT), - 0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3); - m_pocCtrl->Enable(/*wxGetApp().m_enableidx*/true); - - pocSizer->Add(pocspecSizer, 0, wxGROW | wxALL, 3); - - subtopSizer->Add(pocSizer, 0, wxGROW | wxALL, 3); - topSizer->Add(subtopSizer, 1, wxGROW | wxALIGN_CENTRE | wxALL, 5); // assign top and fit it @@ -1052,6 +1247,18 @@ void OPJEncoderDialog::OnEnableIdx(wxCommandEvent& event) } +void OPJEncoderDialog::OnEnablePoc(wxCommandEvent& event) +{ + if (event.IsChecked()) { + wxLogMessage(wxT("POC enabled")); + m_pocCtrl->Enable(true); + } else { + wxLogMessage(wxT("POC disabled")); + m_pocCtrl->Enable(false); + } + +} + void OPJEncoderDialog::OnRadioQualityRate(wxCommandEvent& event) { if (event.GetId() == OPJENCO_QUALITYRADIO) { @@ -1068,15 +1275,99 @@ void OPJEncoderDialog::OnRadioQualityRate(wxCommandEvent& event) #ifdef USE_JPWL void OPJEncoderDialog::OnEnableJPWL(wxCommandEvent& event) { - /*if (event.IsChecked()) { + int specno; + + if (event.IsChecked()) { wxLogMessage(wxT("JPWL enabled")); - m_expcompsCtrl->Enable(true); - m_maxtilesCtrl->Enable(true); + for (specno = 0; specno < MYJPWL_MAX_NO_TILESPECS; specno++) { + m_hprotChoice[specno]->Enable(true); + m_htileCtrl[specno]->Enable(true); + m_pprotChoice[specno]->Enable(true); + m_ptileCtrl[specno]->Enable(true); + m_ppackCtrl[specno]->Enable(true); + m_sensiChoice[specno]->Enable(true); + m_stileCtrl[specno]->Enable(true); + } + OnHprotSelect(event); + OnPprotSelect(event); + OnSensiSelect(event); } else { wxLogMessage(wxT("JPWL disabled")); - m_expcompsCtrl->Enable(false); - m_maxtilesCtrl->Enable(false); - }*/ + for (specno = 0; specno < MYJPWL_MAX_NO_TILESPECS; specno++) { + m_hprotChoice[specno]->Enable(false); + m_htileCtrl[specno]->Enable(false); + m_pprotChoice[specno]->Enable(false); + m_ptileCtrl[specno]->Enable(false); + m_ppackCtrl[specno]->Enable(false); + m_sensiChoice[specno]->Enable(false); + m_stileCtrl[specno]->Enable(false); + } + } } + +void OPJEncoderDialog::OnHprotSelect(wxCommandEvent& event) +{ + int specno; + + // deactivate properly + for (specno = MYJPWL_MAX_NO_TILESPECS - 1; specno >= 0; specno--) { + if (!m_hprotChoice[specno]->GetSelection()) { + m_hprotChoice[specno]->Enable(false); + m_htileCtrl[specno]->Enable(false); + } else + break; + } + if (specno < (MYJPWL_MAX_NO_TILESPECS - 1)) { + m_hprotChoice[specno + 1]->Enable(true); + m_htileCtrl[specno + 1]->Enable(true); + } + + //wxLogMessage(wxT("hprot changed: %d"), specno); +} + +void OPJEncoderDialog::OnPprotSelect(wxCommandEvent& event) +{ + int specno; + + // deactivate properly + for (specno = MYJPWL_MAX_NO_TILESPECS - 1; specno >= 0; specno--) { + if (!m_pprotChoice[specno]->GetSelection()) { + m_pprotChoice[specno]->Enable(false); + m_ptileCtrl[specno]->Enable(false); + m_ppackCtrl[specno]->Enable(false); + } else + break; + } + if (specno < (MYJPWL_MAX_NO_TILESPECS - 1)) { + m_pprotChoice[specno + 1]->Enable(true); + m_ptileCtrl[specno + 1]->Enable(true); + m_ppackCtrl[specno + 1]->Enable(true); + } + + //wxLogMessage(wxT("pprot changed: %d"), specno); +} + +void OPJEncoderDialog::OnSensiSelect(wxCommandEvent& event) +{ + int specno; + + // deactivate properly + for (specno = MYJPWL_MAX_NO_TILESPECS - 1; specno >= 0; specno--) { + if (!m_sensiChoice[specno]->GetSelection()) { + m_sensiChoice[specno]->Enable(false); + m_stileCtrl[specno]->Enable(false); + } else + break; + } + if (specno < (MYJPWL_MAX_NO_TILESPECS - 1)) { + m_sensiChoice[specno + 1]->Enable(true); + m_stileCtrl[specno + 1]->Enable(true); + } + + //wxLogMessage(wxT("sprot changed: %d"), specno); +} + + #endif // USE_JPWL + diff --git a/OPJViewer/source/OPJThreads.cpp b/OPJViewer/source/OPJThreads.cpp new file mode 100644 index 00000000..55ed4ac8 --- /dev/null +++ b/OPJViewer/source/OPJThreads.cpp @@ -0,0 +1,1251 @@ +/* + * Copyright (c) 2007, Digital Signal Processing Laboratory, Universita'  degli studi di Perugia (UPG), Italy + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include "OPJViewer.h" + + +///////////////////////////////////////////////////////////////////// +// Encoding thread class +///////////////////////////////////////////////////////////////////// + +OPJEncoThread::OPJEncoThread(OPJCanvas *canvas) + : wxThread() +{ + m_count = 0; + m_canvas = canvas; +} + +void OPJEncoThread::WriteText(const wxString& text) +{ + wxString msg; + + // before doing any GUI calls we must ensure that this thread is the only + // one doing it! + +#ifndef __WXGTK__ + wxMutexGuiEnter(); +#endif // __WXGTK__ + + msg << text; + m_canvas->WriteText(msg); + +#ifndef __WXGTK__ + wxMutexGuiLeave(); +#endif // __WXGTK__ +} + +void OPJEncoThread::OnExit() +{ + wxCriticalSectionLocker locker(wxGetApp().m_enco_critsect); + + wxArrayThread& ethreads = wxGetApp().m_enco_threads; + ethreads.Remove(this); + + if (ethreads.IsEmpty() ) + { + // signal the main thread that there are no more threads left if it is + // waiting for us + if (wxGetApp().m_enco_waitingUntilAllDone) { + wxGetApp().m_enco_waitingUntilAllDone = false; + wxGetApp().m_enco_semAllDone.Post(); + } + } +} + +void *OPJEncoThread::Entry() +{ + wxString text; + + 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("Enco thread %d started"), m_canvas->m_childframe->m_winnumber); + WriteText(text); + + // set handler properties + wxJ2KHandler *j2kkkhandler = (wxJ2KHandler *) wxImage::FindHandler( wxBITMAP_TYPE_J2K); + j2kkkhandler->m_subsampling = wxGetApp().m_subsampling; + j2kkkhandler->m_origin = wxGetApp().m_origin; + j2kkkhandler->m_rates = wxGetApp().m_rates; + j2kkkhandler->m_quality = wxGetApp().m_quality; + j2kkkhandler->m_enablequality = wxGetApp().m_enablequality; + j2kkkhandler->m_multicomp = wxGetApp().m_multicomp; + j2kkkhandler->m_irreversible = wxGetApp().m_irreversible; + j2kkkhandler->m_resolutions = wxGetApp().m_resolutions; + j2kkkhandler->m_progression = wxGetApp().m_progression; + j2kkkhandler->m_cbsize = wxGetApp().m_cbsize; + j2kkkhandler->m_prsize = wxGetApp().m_prsize; + j2kkkhandler->m_tsize = wxGetApp().m_tsize; + j2kkkhandler->m_torigin = wxGetApp().m_torigin; + j2kkkhandler->m_enablesop = wxGetApp().m_enablesop; + j2kkkhandler->m_enableeph = wxGetApp().m_enableeph; + j2kkkhandler->m_enablebypass = wxGetApp().m_enablebypass; + j2kkkhandler->m_enablerestart = wxGetApp().m_enablerestart; + j2kkkhandler->m_enablereset = wxGetApp().m_enablereset; + j2kkkhandler->m_enablesegmark = wxGetApp().m_enablesegmark; + j2kkkhandler->m_enableerterm = wxGetApp().m_enableerterm; + j2kkkhandler->m_enablevsc = wxGetApp().m_enablevsc; + j2kkkhandler->m_enableidx = wxGetApp().m_enableidx; + j2kkkhandler->m_index = m_canvas->m_savename.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxGetApp().m_index; + j2kkkhandler->m_enablecomm = wxGetApp().m_enablecomm; + j2kkkhandler->m_comment = wxGetApp().m_comment; + j2kkkhandler->m_enablepoc = wxGetApp().m_enablepoc; + j2kkkhandler->m_poc = wxGetApp().m_poc; + + // save the file + if (!m_canvas->m_image100.SaveFile(m_canvas->m_savename.GetFullPath(), (wxBitmapType) wxBITMAP_TYPE_J2K)) { + WriteText(wxT("Can't save image")); + return NULL; + } + + text.Printf(wxT("Enco thread %d finished"), m_canvas->m_childframe->m_winnumber); + WriteText(text); + return NULL; +} + + +///////////////////////////////////////////////////////////////////// +// Decoding thread class +///////////////////////////////////////////////////////////////////// + +OPJDecoThread::OPJDecoThread(OPJCanvas *canvas) + : wxThread() +{ + m_count = 0; + m_canvas = canvas; +} + +void OPJDecoThread::WriteText(const wxString& text) +{ + wxString msg; + + // before doing any GUI calls we must ensure that this thread is the only + // one doing it! + +#ifndef __WXGTK__ + wxMutexGuiEnter(); +#endif // __WXGTK__ + + msg << text; + m_canvas->WriteText(msg); + +#ifndef __WXGTK__ + wxMutexGuiLeave(); +#endif // __WXGTK__ +} + +void OPJDecoThread::OnExit() +{ + wxCriticalSectionLocker locker(wxGetApp().m_deco_critsect); + + wxArrayThread& dthreads = wxGetApp().m_deco_threads; + dthreads.Remove(this); + + if (dthreads.IsEmpty() ) + { + // signal the main thread that there are no more threads left if it is + // waiting for us + if (wxGetApp().m_deco_waitingUntilAllDone) { + wxGetApp().m_deco_waitingUntilAllDone = false; + wxGetApp().m_deco_semAllDone.Post(); + } + } +} + +void *OPJDecoThread::Entry() +{ + + wxString text; + + 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); + + WriteText(text); + + wxBitmap bitmap(100, 100); + wxImage image(100, 100, true); //= bitmap.ConvertToImage(); + image.Destroy(); + + 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 + + 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")); + return NULL; + } + + } else { + + // display a macaron + if (!image.Create(300, 5, false)) { + WriteText(wxT("Can't create image")); + return NULL; + } + + } + + // assign 100% image + m_canvas->m_image100 = wxBitmap(image); + + // find a fit-to-width zoom + 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)); + + // fit to width +#ifndef __WXGTK__ + m_canvas->m_childframe->m_frame->Rescale(zooml, m_canvas->m_childframe); +#endif // __WXGTK__ + + //m_canvas->m_image = m_canvas->m_image100; + //m_canvas->Refresh(); + //m_canvas->SetScrollbars(20, 20, (int)(0.5 + (double) image.GetWidth() / 20.0), (int)(0.5 + (double) image.GetHeight() / 20.0)); + + //text.Printf(wxT("Deco thread 0x%lx finished."), GetId()); + text.Printf(wxT("Deco thread %d finished"), m_canvas->m_childframe->m_winnumber); + WriteText(text); + return NULL; + +} + +///////////////////////////////////////////////////////////////////// +// Parsing thread class +///////////////////////////////////////////////////////////////////// + +OPJParseThread::OPJParseThread(OPJMarkerTree *tree, wxTreeItemId parentid) + : wxThread() +{ + m_count = 0; + m_tree = tree; + m_parentid = parentid; +} + +void OPJParseThread::WriteText(const wxString& text) +{ + wxString msg; + + // before doing any GUI calls we must ensure that this thread is the only + // one doing it! + +#ifndef __WXGTK__ + wxMutexGuiEnter(); +#endif // __WXGTK + + msg << text; + m_tree->WriteText(msg); + +#ifndef __WXGTK__ + wxMutexGuiLeave(); +#endif // __WXGTK +} + +void OPJParseThread::OnExit() +{ + wxCriticalSectionLocker locker(wxGetApp().m_parse_critsect); + + wxArrayThread& threads = wxGetApp().m_parse_threads; + threads.Remove(this); + + if (threads.IsEmpty()) { + // signal the main thread that there are no more threads left if it is + // waiting for us + if (wxGetApp().m_parse_waitingUntilAllDone) { + wxGetApp().m_parse_waitingUntilAllDone = false; + wxGetApp().m_parse_semAllDone.Post(); + } + } +} + +void *OPJParseThread::Entry() +{ + + printf("Entering\n\n"); + + wxString text; + + srand(GetId()); + int m_countnum = rand() % 9; + text.Printf(wxT("Parse thread 0x%lx started (priority = %u, time = %d)."), + GetId(), GetPriority(), m_countnum); + WriteText(text); + LoadFile(m_tree->m_fname); + text.Printf(wxT("Parse thread 0x%lx finished."), GetId()); + WriteText(text); + + + //wxLogMessage(wxT("Entering\n")); //test wxLog thread safeness + + //wxBusyCursor wait; + //wxBusyInfo wait(wxT("Decoding image ...")); + + + /*for ( m_count = 0; m_count < m_countnum; m_count++ ) + { + // check if we were asked to exit + if ( TestDestroy() ) + break; + + text.Printf(wxT("[%u] Parse thread 0x%lx here."), m_count, GetId()); + WriteText(text); + + // wxSleep() can't be called from non-GUI thread! + wxThread::Sleep(10); + }*/ + + // wxLogMessage(text); -- test wxLog thread safeness + + printf("Exiting\n\n"); + + return NULL; +} + + +/////////////////////////////////////////// +// Parsing hread and related +/////////////////////////////////////////// + +#if USE_GENERIC_TREECTRL +BEGIN_EVENT_TABLE(OPJMarkerTree, wxGenericTreeCtrl) +#else +BEGIN_EVENT_TABLE(OPJMarkerTree, wxTreeCtrl) +#endif + /*EVT_TREE_BEGIN_DRAG(TreeTest_Ctrl, OPJMarkerTree::OnBeginDrag) + EVT_TREE_BEGIN_RDRAG(TreeTest_Ctrl, OPJMarkerTree::OnBeginRDrag) + EVT_TREE_END_DRAG(TreeTest_Ctrl, OPJMarkerTree::OnEndDrag)*/ + /*EVT_TREE_BEGIN_LABEL_EDIT(TreeTest_Ctrl, OPJMarkerTree::OnBeginLabelEdit) + EVT_TREE_END_LABEL_EDIT(TreeTest_Ctrl, OPJMarkerTree::OnEndLabelEdit)*/ + /*EVT_TREE_DELETE_ITEM(TreeTest_Ctrl, OPJMarkerTree::OnDeleteItem)*/ +#if 0 // there are so many of those that logging them causes flicker + /*EVT_TREE_GET_INFO(TreeTest_Ctrl, OPJMarkerTree::OnGetInfo)*/ +#endif + /*EVT_TREE_SET_INFO(TreeTest_Ctrl, OPJMarkerTree::OnSetInfo) + EVT_TREE_ITEM_EXPANDED(TreeTest_Ctrl, OPJMarkerTree::OnItemExpanded)*/ + EVT_TREE_ITEM_EXPANDING(TreeTest_Ctrl, OPJMarkerTree::OnItemExpanding) + /*EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl, OPJMarkerTree::OnItemCollapsed) + EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, OPJMarkerTree::OnItemCollapsing)*/ + + EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, OPJMarkerTree::OnSelChanged) + /*EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, OPJMarkerTree::OnSelChanging)*/ + /*EVT_TREE_KEY_DOWN(TreeTest_Ctrl, OPJMarkerTree::OnTreeKeyDown)*/ + /*EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl, OPJMarkerTree::OnItemActivated)*/ + + // so many differents ways to handle right mouse button clicks... + /*EVT_CONTEXT_MENU(OPJMarkerTree::OnContextMenu)*/ + // EVT_TREE_ITEM_MENU is the preferred event for creating context menus + // on a tree control, because it includes the point of the click or item, + // meaning that no additional placement calculations are required. + EVT_TREE_ITEM_MENU(TreeTest_Ctrl, OPJMarkerTree::OnItemMenu) + /*EVT_TREE_ITEM_RIGHT_CLICK(TreeTest_Ctrl, OPJMarkerTree::OnItemRClick)*/ + + /*EVT_RIGHT_DOWN(OPJMarkerTree::OnRMouseDown) + EVT_RIGHT_UP(OPJMarkerTree::OnRMouseUp) + EVT_RIGHT_DCLICK(OPJMarkerTree::OnRMouseDClick)*/ +END_EVENT_TABLE() + +// OPJMarkerTree implementation +#if USE_GENERIC_TREECTRL +IMPLEMENT_DYNAMIC_CLASS(OPJMarkerTree, wxGenericTreeCtrl) +#else +IMPLEMENT_DYNAMIC_CLASS(OPJMarkerTree, wxTreeCtrl) +#endif + +OPJMarkerTree::OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileName fname, wxString name, const wxWindowID id, + const wxPoint& pos, const wxSize& size, long style) + : wxTreeCtrl(parent, id, pos, size, style) +{ + m_reverseSort = false; + m_fname = fname; + + m_peektextCtrl = ((OPJFrame *) (parent->GetParent()->GetParent()))->m_textCtrlbrowse; + CreateImageList(); + + // Add some items to the tree + //AddTestItemsToTree(5, 5); + int image = wxGetApp().ShowImages() ? OPJMarkerTree::TreeCtrlIcon_Folder : -1; + wxTreeItemId rootId = AddRoot(name, + image, image, + new OPJMarkerData(name)); + + OPJParseThread *pthread = CreateParseThread(0x00, subframe); + if (pthread->Run() != wxTHREAD_NO_ERROR) + wxLogMessage(wxT("Can't start parse thread!")); + else + wxLogMessage(wxT("New parse thread started.")); + + m_childframe = subframe; +} + +void OPJMarkerTree::CreateImageList(int size) +{ + if (size == -1) { + SetImageList(NULL); + return; + } + if (size == 0) + size = m_imageSize; + else + m_imageSize = size; + + // Make an image list containing small icons + wxImageList *images = new wxImageList(size, size, true); + + // should correspond to TreeCtrlIcon_xxx enum + wxBusyCursor wait; + wxIcon icons[5]; + icons[0] = wxIcon(icon1_xpm); + icons[1] = wxIcon(icon2_xpm); + icons[2] = wxIcon(icon3_xpm); + icons[3] = wxIcon(icon4_xpm); + icons[4] = wxIcon(icon5_xpm); + + int sizeOrig = icons[0].GetWidth(); + for (size_t i = 0; i < WXSIZEOF(icons); i++) { + if (size == sizeOrig) { + images->Add(icons[i]); + } else { + images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size))); + } + } + + AssignImageList(images); +} + +#if USE_GENERIC_TREECTRL || !defined(__WXMSW__) +void OPJMarkerTree::CreateButtonsImageList(int size) +{ + if ( size == -1 ) { + SetButtonsImageList(NULL); + return; + } + + // Make an image list containing small icons + wxImageList *images = new wxImageList(size, size, true); + + // should correspond to TreeCtrlIcon_xxx enum + wxBusyCursor wait; + wxIcon icons[4]; + icons[0] = wxIcon(icon3_xpm); // closed + icons[1] = wxIcon(icon3_xpm); // closed, selected + icons[2] = wxIcon(icon5_xpm); // open + icons[3] = wxIcon(icon5_xpm); // open, selected + + for ( size_t i = 0; i < WXSIZEOF(icons); i++ ) { + int sizeOrig = icons[i].GetWidth(); + if ( size == sizeOrig ) { + images->Add(icons[i]); + } else { + images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size))); + } + } + + AssignButtonsImageList(images); +#else +void OPJMarkerTree::CreateButtonsImageList(int WXUNUSED(size)) +{ +#endif +} + +void OPJParseThread::LoadFile(wxFileName fname) +{ + wxTreeItemId rootid; + + // this is the root node + int image = wxGetApp().ShowImages() ? m_tree->TreeCtrlIcon_Folder : -1; + + if (this->m_parentid) { + // leaf of a tree + rootid = m_parentid; + m_tree->SetItemText(rootid, wxT("Parsing...")); + + } else { + + // delete the existing tree hierarchy + m_tree->DeleteAllItems(); + + // new tree + rootid = m_tree->AddRoot(wxT("Parsing..."), + image, + image, + new OPJMarkerData(fname.GetFullPath()) + ); + //m_tree->SetItemFont(rootid, *wxITALIC_FONT); + m_tree->SetItemBold(rootid); + } + + // open the file + wxFile m_file(fname.GetFullPath().c_str(), wxFile::read); + + // parsing enabled? + if (wxGetApp().m_enableparse) { + + // what is the extension? + if ((fname.GetExt() == wxT("j2k")) || (fname.GetExt() == wxT("j2c"))) { + + // parse the file + ParseJ2KFile(&m_file, 0, m_file.Length(), rootid); + + } else if ((fname.GetExt() == wxT("jp2")) || (fname.GetExt() == wxT("mj2"))) { + + // parse the file + if (this->m_parentid) { + //WriteText(wxT("Only a subsection of jp2")); + OPJMarkerData *data = (OPJMarkerData *) m_tree->GetItemData(rootid); + ParseJ2KFile(&m_file, data->m_start, data->m_length, rootid); + m_tree->Expand(rootid); + + } else { + // as usual + ParseJP2File(&m_file, 0, m_file.Length(), rootid); + } + + } else { + + // unknown extension + WriteText(wxT("Unknown file format!")); + + } + + } + + + // this is the root node + if (this->m_parentid) + m_tree->SetItemText(rootid, wxT("Codestream")); + else + //m_tree->SetItemText(rootid, wxString::Format(wxT("%s (%d B)"), fname.GetFullName(), m_file.Length())); + m_tree->SetItemText(rootid, fname.GetFullName()); + + // close the file + m_file.Close(); + + WriteText(wxT("Parsing finished!")); +} + +/*int OPJMarkerTree::OnCompareItems(const wxTreeItemId& item1, + const wxTreeItemId& item2) +{ + if ( m_reverseSort ) + { + // just exchange 1st and 2nd items + return wxTreeCtrl::OnCompareItems(item2, item1); + } + else + { + return wxTreeCtrl::OnCompareItems(item1, item2); + } +}*/ + +/*void OPJMarkerTree::AddItemsRecursively(const wxTreeItemId& idParent, + size_t numChildren, + size_t depth, + size_t folder) +{ + if ( depth > 0 ) + { + bool hasChildren = depth > 1; + + wxString str; + for ( size_t n = 0; n < numChildren; n++ ) + { + // at depth 1 elements won't have any more children + if ( hasChildren ) + str.Printf(wxT("%s child %u"), wxT("Folder"), unsigned(n + 1)); + else + str.Printf(wxT("%s child %u.%u"), wxT("File"), unsigned(folder), unsigned(n + 1)); + + // here we pass to AppendItem() normal and selected item images (we + // suppose that selected image follows the normal one in the enum) + int image, imageSel; + if ( wxGetApp().ShowImages() ) + { + image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder; + imageSel = image + 1; + } + else + { + image = imageSel = -1; + } + wxTreeItemId id = AppendItem(idParent, str, image, imageSel, + new OPJMarkerData(str)); + + // and now we also set the expanded one (only for the folders) + if ( hasChildren && wxGetApp().ShowImages() ) + { + SetItemImage(id, TreeCtrlIcon_FolderOpened, + wxTreeItemIcon_Expanded); + } + + // remember the last child for OnEnsureVisible() + if ( !hasChildren && n == numChildren - 1 ) + { + m_lastItem = id; + } + + AddItemsRecursively(id, numChildren, depth - 1, n + 1); + } + } + //else: done! +}*/ + +/*void OPJMarkerTree::AddTestItemsToTree(size_t numChildren, + size_t depth) +{ + int image = wxGetApp().ShowImages() ? OPJMarkerTree::TreeCtrlIcon_Folder : -1; + wxTreeItemId rootId = AddRoot(wxT("Root"), + image, image, + new OPJMarkerData(wxT("Root item"))); + if ( image != -1 ) + { + SetItemImage(rootId, TreeCtrlIcon_FolderOpened, wxTreeItemIcon_Expanded); + } + + AddItemsRecursively(rootId, numChildren, depth, 0); + + // set some colours/fonts for testing + SetItemFont(rootId, *wxITALIC_FONT); + + wxTreeItemIdValue cookie; + wxTreeItemId id = GetFirstChild(rootId, cookie); + SetItemTextColour(id, *wxBLUE); + + id = GetNextChild(rootId, cookie); + id = GetNextChild(rootId, cookie); + SetItemTextColour(id, *wxRED); + SetItemBackgroundColour(id, *wxLIGHT_GREY); +}*/ + +/*void OPJMarkerTree::GetItemsRecursively(const wxTreeItemId& idParent, + wxTreeItemIdValue cookie) +{ + wxTreeItemId id; + + if ( !cookie ) + id = GetFirstChild(idParent, cookie); + else + id = GetNextChild(idParent, cookie); + + if ( !id.IsOk() ) + return; + + wxString text = GetItemText(id); + wxLogMessage(text); + + if (ItemHasChildren(id)) + GetItemsRecursively(id); + + GetItemsRecursively(idParent, cookie); +}*/ + +/*void OPJMarkerTree::DoToggleIcon(const wxTreeItemId& item) +{ + int image = (GetItemImage(item) == TreeCtrlIcon_Folder) + ? TreeCtrlIcon_File + : TreeCtrlIcon_Folder; + SetItemImage(item, image, wxTreeItemIcon_Normal); + + image = (GetItemImage(item) == TreeCtrlIcon_FolderSelected) + ? TreeCtrlIcon_FileSelected + : TreeCtrlIcon_FolderSelected; + SetItemImage(item, image, wxTreeItemIcon_Selected); +}*/ + +void OPJMarkerTree::LogEvent(const wxChar *name, const wxTreeEvent& event) +{ + wxTreeItemId item = event.GetItem(); + wxString text; + if ( item.IsOk() ) + text << wxT('"') << GetItemText(item).c_str() << wxT('"'); + else + text = wxT("invalid item"); + wxLogMessage(wxT("%s(%s)"), name, text.c_str()); +} + +OPJParseThread *OPJMarkerTree::CreateParseThread(wxTreeItemId parentid, OPJChildFrame *subframe) +{ + OPJParseThread *pthread = new OPJParseThread(this, parentid); + + if (pthread->Create() != wxTHREAD_NO_ERROR) + wxLogError(wxT("Can't create parse thread!")); + + wxCriticalSectionLocker enter(wxGetApp().m_parse_critsect); + wxGetApp().m_parse_threads.Add(pthread); + + return pthread; +} + + +/*// avoid repetition +#define TREE_EVENT_HANDLER(name) \ +void OPJMarkerTree::name(wxTreeEvent& event) \ +{ \ + LogEvent(_T(#name), event); \ + SetLastItem(wxTreeItemId()); \ + event.Skip(); \ +}*/ + +/*TREE_EVENT_HANDLER(OnBeginRDrag)*/ +/*TREE_EVENT_HANDLER(OnDeleteItem)*/ +/*TREE_EVENT_HANDLER(OnGetInfo) +TREE_EVENT_HANDLER(OnSetInfo)*/ +/*TREE_EVENT_HANDLER(OnItemExpanded) +TREE_EVENT_HANDLER(OnItemExpanding)*/ +/*TREE_EVENT_HANDLER(OnItemCollapsed)*/ +/*TREE_EVENT_HANDLER(OnSelChanged) +TREE_EVENT_HANDLER(OnSelChanging)*/ + +/*#undef TREE_EVENT_HANDLER*/ + +void OPJMarkerTree::OnItemExpanding(wxTreeEvent& event) +{ + wxTreeItemId item = event.GetItem(); + OPJMarkerData* data = (OPJMarkerData *) GetItemData(item); + wxString text; + + if (item.IsOk()) + text << wxT('"') << GetItemText(item).c_str() << wxT('"'); + else + text = wxT("invalid item"); + + if (wxStrcmp(data->GetDesc1(), wxT("INFO-CSTREAM"))) + return; + + wxLogMessage(wxT("Expanding... (%s -> %s, %s, %d, %d)"), + text.c_str(), data->GetDesc1(), data->GetDesc2(), + data->m_start, data->m_length); + + // the codestream box is being asked for expansion + wxTreeItemIdValue cookie; + if (!GetFirstChild(item, cookie).IsOk()) { + OPJParseThread *pthread = CreateParseThread(item); + if (pthread->Run() != wxTHREAD_NO_ERROR) + wxLogMessage(wxT("Can't start parse thread!")); + else + wxLogMessage(wxT("New parse thread started.")); + } +} + +void OPJMarkerTree::OnSelChanged(wxTreeEvent& event) +{ + int bunch_linesize = 16; + int bunch_numlines = 7; + + wxTreeItemId item = event.GetItem(); + OPJMarkerData* data = (OPJMarkerData *) GetItemData(item); + wxString text; + int l, c, pos = 0, pre_pos; + + m_peektextCtrl->Clear(); + + /*text << wxString::Format(wxT("Selected... (%s -> %s, %s, %d, %d)"), + text.c_str(), data->GetDesc1(), data->GetDesc2(), + data->m_start, data->m_length) << wxT("\n");*/ + + // open the file and browse a little + wxFile *fp = new wxFile(m_fname.GetFullPath().c_str(), wxFile::read); + + // go to position claimed + fp->Seek(data->m_start, wxFromStart); + + // read a bunch + int max_read = wxMin(wxFileOffset(bunch_linesize * bunch_numlines), data->m_length - data->m_start + 1); + if (data->m_desc == wxT("MARK (65380)")) { + /*wxLogMessage(data->m_desc);*/ + max_read = data->m_length - data->m_start + 1; + bunch_numlines = (int) ceil((float) max_read / (float) bunch_linesize); + } + unsigned char *buffer = new unsigned char[bunch_linesize * bunch_numlines]; + fp->Read(buffer, max_read); + + // write the file data between start and stop + pos = 0; + for (l = 0; l < bunch_numlines; l++) { + + text << wxString::Format(wxT("%010d:"), data->m_start + pos); + + pre_pos = pos; + + // add hex browsing text + for (c = 0; c < bunch_linesize; c++) { + + if (!(c % 8)) + text << wxT(" "); + + if (pos < max_read) { + text << wxString::Format(wxT("%02X "), buffer[pos]); + } else + text << wxT(" "); + pos++; + } + + text << wxT(" "); + + // add char browsing text + for (c = 0; c < bunch_linesize; c++) { + + if (pre_pos < max_read) { + if ((buffer[pre_pos] == '\n') || + (buffer[pre_pos] == '\t') || + (buffer[pre_pos] == '\0') || + (buffer[pre_pos] == 0x0D) || + (buffer[pre_pos] == 0x0B)) + buffer[pre_pos] = ' '; + text << wxString::FromAscii((char) buffer[pre_pos]) << wxT("."); + } else + text << wxT(" "); + pre_pos++; + } + + text << wxT("\n"); + + } + + // close the file + fp->Close(); + + m_peektextCtrl->WriteText(text); + + delete buffer; +} + +/*void LogKeyEvent(const wxChar *name, const wxKeyEvent& event) +{ + wxString key; + long keycode = event.GetKeyCode(); + { + switch ( keycode ) + { + case WXK_BACK: key = wxT("BACK"); break; + case WXK_TAB: key = wxT("TAB"); break; + case WXK_RETURN: key = wxT("RETURN"); break; + case WXK_ESCAPE: key = wxT("ESCAPE"); break; + case WXK_SPACE: key = wxT("SPACE"); break; + case WXK_DELETE: key = wxT("DELETE"); break; + case WXK_START: key = wxT("START"); break; + case WXK_LBUTTON: key = wxT("LBUTTON"); break; + case WXK_RBUTTON: key = wxT("RBUTTON"); break; + case WXK_CANCEL: key = wxT("CANCEL"); break; + case WXK_MBUTTON: key = wxT("MBUTTON"); break; + case WXK_CLEAR: key = wxT("CLEAR"); break; + case WXK_SHIFT: key = wxT("SHIFT"); break; + case WXK_ALT: key = wxT("ALT"); break; + case WXK_CONTROL: key = wxT("CONTROL"); break; + case WXK_MENU: key = wxT("MENU"); break; + case WXK_PAUSE: key = wxT("PAUSE"); break; + case WXK_CAPITAL: key = wxT("CAPITAL"); break; + case WXK_END: key = wxT("END"); break; + case WXK_HOME: key = wxT("HOME"); break; + case WXK_LEFT: key = wxT("LEFT"); break; + case WXK_UP: key = wxT("UP"); break; + case WXK_RIGHT: key = wxT("RIGHT"); break; + case WXK_DOWN: key = wxT("DOWN"); break; + case WXK_SELECT: key = wxT("SELECT"); break; + case WXK_PRINT: key = wxT("PRINT"); break; + case WXK_EXECUTE: key = wxT("EXECUTE"); break; + case WXK_SNAPSHOT: key = wxT("SNAPSHOT"); break; + case WXK_INSERT: key = wxT("INSERT"); break; + case WXK_HELP: key = wxT("HELP"); break; + case WXK_NUMPAD0: key = wxT("NUMPAD0"); break; + case WXK_NUMPAD1: key = wxT("NUMPAD1"); break; + case WXK_NUMPAD2: key = wxT("NUMPAD2"); break; + case WXK_NUMPAD3: key = wxT("NUMPAD3"); break; + case WXK_NUMPAD4: key = wxT("NUMPAD4"); break; + case WXK_NUMPAD5: key = wxT("NUMPAD5"); break; + case WXK_NUMPAD6: key = wxT("NUMPAD6"); break; + case WXK_NUMPAD7: key = wxT("NUMPAD7"); break; + case WXK_NUMPAD8: key = wxT("NUMPAD8"); break; + case WXK_NUMPAD9: key = wxT("NUMPAD9"); break; + case WXK_MULTIPLY: key = wxT("MULTIPLY"); break; + case WXK_ADD: key = wxT("ADD"); break; + case WXK_SEPARATOR: key = wxT("SEPARATOR"); break; + case WXK_SUBTRACT: key = wxT("SUBTRACT"); break; + case WXK_DECIMAL: key = wxT("DECIMAL"); break; + case WXK_DIVIDE: key = wxT("DIVIDE"); break; + case WXK_F1: key = wxT("F1"); break; + case WXK_F2: key = wxT("F2"); break; + case WXK_F3: key = wxT("F3"); break; + case WXK_F4: key = wxT("F4"); break; + case WXK_F5: key = wxT("F5"); break; + case WXK_F6: key = wxT("F6"); break; + case WXK_F7: key = wxT("F7"); break; + case WXK_F8: key = wxT("F8"); break; + case WXK_F9: key = wxT("F9"); break; + case WXK_F10: key = wxT("F10"); break; + case WXK_F11: key = wxT("F11"); break; + case WXK_F12: key = wxT("F12"); break; + case WXK_F13: key = wxT("F13"); break; + case WXK_F14: key = wxT("F14"); break; + case WXK_F15: key = wxT("F15"); break; + case WXK_F16: key = wxT("F16"); break; + case WXK_F17: key = wxT("F17"); break; + case WXK_F18: key = wxT("F18"); break; + case WXK_F19: key = wxT("F19"); break; + case WXK_F20: key = wxT("F20"); break; + case WXK_F21: key = wxT("F21"); break; + case WXK_F22: key = wxT("F22"); break; + case WXK_F23: key = wxT("F23"); break; + case WXK_F24: key = wxT("F24"); break; + case WXK_NUMLOCK: key = wxT("NUMLOCK"); break; + case WXK_SCROLL: key = wxT("SCROLL"); break; + case WXK_PAGEUP: key = wxT("PAGEUP"); break; + case WXK_PAGEDOWN: key = wxT("PAGEDOWN"); break; + case WXK_NUMPAD_SPACE: key = wxT("NUMPAD_SPACE"); break; + case WXK_NUMPAD_TAB: key = wxT("NUMPAD_TAB"); break; + case WXK_NUMPAD_ENTER: key = wxT("NUMPAD_ENTER"); break; + case WXK_NUMPAD_F1: key = wxT("NUMPAD_F1"); break; + case WXK_NUMPAD_F2: key = wxT("NUMPAD_F2"); break; + case WXK_NUMPAD_F3: key = wxT("NUMPAD_F3"); break; + case WXK_NUMPAD_F4: key = wxT("NUMPAD_F4"); break; + case WXK_NUMPAD_HOME: key = wxT("NUMPAD_HOME"); break; + case WXK_NUMPAD_LEFT: key = wxT("NUMPAD_LEFT"); break; + case WXK_NUMPAD_UP: key = wxT("NUMPAD_UP"); break; + case WXK_NUMPAD_RIGHT: key = wxT("NUMPAD_RIGHT"); break; + case WXK_NUMPAD_DOWN: key = wxT("NUMPAD_DOWN"); break; + case WXK_NUMPAD_PAGEUP: key = wxT("NUMPAD_PAGEUP"); break; + case WXK_NUMPAD_PAGEDOWN: key = wxT("NUMPAD_PAGEDOWN"); break; + case WXK_NUMPAD_END: key = wxT("NUMPAD_END"); break; + case WXK_NUMPAD_BEGIN: key = wxT("NUMPAD_BEGIN"); break; + case WXK_NUMPAD_INSERT: key = wxT("NUMPAD_INSERT"); break; + case WXK_NUMPAD_DELETE: key = wxT("NUMPAD_DELETE"); break; + case WXK_NUMPAD_EQUAL: key = wxT("NUMPAD_EQUAL"); break; + case WXK_NUMPAD_MULTIPLY: key = wxT("NUMPAD_MULTIPLY"); break; + case WXK_NUMPAD_ADD: key = wxT("NUMPAD_ADD"); break; + case WXK_NUMPAD_SEPARATOR: key = wxT("NUMPAD_SEPARATOR"); break; + case WXK_NUMPAD_SUBTRACT: key = wxT("NUMPAD_SUBTRACT"); break; + case WXK_NUMPAD_DECIMAL: key = wxT("NUMPAD_DECIMAL"); break; + + default: + { + if ( keycode < 128 && wxIsprint((int)keycode) ) + key.Printf(wxT("'%c'"), (char)keycode); + else if ( keycode > 0 && keycode < 27 ) + key.Printf(_("Ctrl-%c"), wxT('A') + keycode - 1); + else + key.Printf(wxT("unknown (%ld)"), keycode); + } + } + } + + wxLogMessage(wxT("%s event: %s (flags = %c%c%c%c)"), + name, + key.c_str(), + event.ControlDown() ? wxT('C') : wxT('-'), + event.AltDown() ? wxT('A') : wxT('-'), + event.ShiftDown() ? wxT('S') : wxT('-'), + event.MetaDown() ? wxT('M') : wxT('-')); +} + +void OPJMarkerTree::OnTreeKeyDown(wxTreeEvent& event) +{ + LogKeyEvent(wxT("Tree key down "), event.GetKeyEvent()); + + event.Skip(); +}*/ + +/*void OPJMarkerTree::OnBeginDrag(wxTreeEvent& event) +{ + // need to explicitly allow drag + if ( event.GetItem() != GetRootItem() ) + { + m_draggedItem = event.GetItem(); + + wxLogMessage(wxT("OnBeginDrag: started dragging %s"), + GetItemText(m_draggedItem).c_str()); + + event.Allow(); + } + else + { + wxLogMessage(wxT("OnBeginDrag: this item can't be dragged.")); + } +} + +void OPJMarkerTree::OnEndDrag(wxTreeEvent& event) +{ + wxTreeItemId itemSrc = m_draggedItem, + itemDst = event.GetItem(); + m_draggedItem = (wxTreeItemId)0l; + + // where to copy the item? + if ( itemDst.IsOk() && !ItemHasChildren(itemDst) ) + { + // copy to the parent then + itemDst = GetItemParent(itemDst); + } + + if ( !itemDst.IsOk() ) + { + wxLogMessage(wxT("OnEndDrag: can't drop here.")); + + return; + } + + wxString text = GetItemText(itemSrc); + wxLogMessage(wxT("OnEndDrag: '%s' copied to '%s'."), + text.c_str(), GetItemText(itemDst).c_str()); + + // just do append here - we could also insert it just before/after the item + // on which it was dropped, but this requires slightly more work... we also + // completely ignore the client data and icon of the old item but could + // copy them as well. + // + // Finally, we only copy one item here but we might copy the entire tree if + // we were dragging a folder. + int image = wxGetApp().ShowImages() ? TreeCtrlIcon_File : -1; + AppendItem(itemDst, text, image); +}*/ + +/*void OPJMarkerTree::OnBeginLabelEdit(wxTreeEvent& event) +{ + wxLogMessage(wxT("OnBeginLabelEdit")); + + // for testing, prevent this item's label editing + wxTreeItemId itemId = event.GetItem(); + if ( IsTestItem(itemId) ) + { + wxMessageBox(wxT("You can't edit this item.")); + + event.Veto(); + } + else if ( itemId == GetRootItem() ) + { + // test that it is possible to change the text of the item being edited + SetItemText(itemId, _T("Editing root item")); + } +} + +void OPJMarkerTree::OnEndLabelEdit(wxTreeEvent& event) +{ + wxLogMessage(wxT("OnEndLabelEdit")); + + // don't allow anything except letters in the labels + if ( !event.GetLabel().IsWord() ) + { + wxMessageBox(wxT("The new label should be a single word.")); + + event.Veto(); + } +}*/ + +/*void OPJMarkerTree::OnItemCollapsing(wxTreeEvent& event) +{ + wxLogMessage(wxT("OnItemCollapsing")); + + // for testing, prevent the user from collapsing the first child folder + wxTreeItemId itemId = event.GetItem(); + if ( IsTestItem(itemId) ) + { + wxMessageBox(wxT("You can't collapse this item.")); + + event.Veto(); + } +}*/ + +/*void OPJMarkerTree::OnItemActivated(wxTreeEvent& event) +{ + // show some info about this item + wxTreeItemId itemId = event.GetItem(); + OPJMarkerData *item = (OPJMarkerData *)GetItemData(itemId); + + if ( item != NULL ) + { + item->ShowInfo(this); + } + + wxLogMessage(wxT("OnItemActivated")); +}*/ + +void OPJMarkerTree::OnItemMenu(wxTreeEvent& event) +{ + /*wxTreeItemId itemId = event.GetItem(); + OPJMarkerData *item = itemId.IsOk() ? (OPJMarkerData *)GetItemData(itemId) + : NULL; + + wxLogMessage(wxT("OnItemMenu for item \"%s\""), item ? item->GetDesc() + : _T(""));*/ + + //wxLogMessage(wxT("EEEEEEEEEE")); + + //event.Skip(); +} + +/*void OPJMarkerTree::OnContextMenu(wxContextMenuEvent& event) +{ + wxPoint pt = event.GetPosition(); + wxTreeItemId item; + wxLogMessage(wxT("OnContextMenu at screen coords (%i, %i)"), pt.x, pt.y); + + // check if event was generated by keyboard (MSW-specific?) + if ( pt.x == -1 && pt.y == -1 ) //(this is how MSW indicates it) + { + if ( !HasFlag(wxTR_MULTIPLE) ) + item = GetSelection(); + + // attempt to guess where to show the menu + if ( item.IsOk() ) + { + // if an item was clicked, show menu to the right of it + wxRect rect; + GetBoundingRect(item, rect, true );// only the label + pt = wxPoint(rect.GetRight(), rect.GetTop()); + } + else + { + pt = wxPoint(0, 0); + } + } + else // event was generated by mouse, use supplied coords + { + pt = ScreenToClient(pt); + item = HitTest(pt); + } + + ShowMenu(item, pt); +}*/ + +/*void OPJMarkerTree::ShowMenu(wxTreeItemId id, const wxPoint& pt) +{ + wxString title; + if ( id.IsOk() ) + { + title << wxT("Menu for ") << GetItemText(id); + } + else + { + title = wxT("Menu for no particular item"); + } + +#if wxUSE_MENUS + wxMenu menu(title); + menu.Append(TreeTest_About, wxT("&About...")); + menu.AppendSeparator(); + menu.Append(TreeTest_Highlight, wxT("&Highlight item")); + menu.Append(TreeTest_Dump, wxT("&Dump")); + + PopupMenu(&menu, pt); +#endif // wxUSE_MENUS +}*/ + +/*void OPJMarkerTree::OnItemRClick(wxTreeEvent& event) +{ + wxTreeItemId itemId = event.GetItem(); + OPJMarkerData *item = itemId.IsOk() ? (OPJMarkerData *)GetItemData(itemId) + : NULL; + + wxLogMessage(wxT("Item \"%s\" right clicked"), item ? item->GetDesc() + : _T("")); + + event.Skip(); +}*/ + +/* +void OPJMarkerTree::OnRMouseDown(wxMouseEvent& event) +{ + wxLogMessage(wxT("Right mouse button down")); + + event.Skip(); +} + +void OPJMarkerTree::OnRMouseUp(wxMouseEvent& event) +{ + wxLogMessage(wxT("Right mouse button up")); + + event.Skip(); +} + +void OPJMarkerTree::OnRMouseDClick(wxMouseEvent& event) +{ + wxTreeItemId id = HitTest(event.GetPosition()); + if ( !id ) + wxLogMessage(wxT("No item under mouse")); + else + { + OPJMarkerData *item = (OPJMarkerData *)GetItemData(id); + if ( item ) + wxLogMessage(wxT("Item '%s' under mouse"), item->GetDesc()); + } + + event.Skip(); +} +*/ + +static inline const wxChar *Bool2String(bool b) +{ + return b ? wxT("") : wxT("not "); +} + +void OPJMarkerData::ShowInfo(wxTreeCtrl *tree) +{ + wxLogMessage(wxT("Item '%s': %sselected, %sexpanded, %sbold,\n") + wxT("%u children (%u immediately under this item)."), + m_desc.c_str(), + Bool2String(tree->IsSelected(GetId())), + Bool2String(tree->IsExpanded(GetId())), + Bool2String(tree->IsBold(GetId())), + unsigned(tree->GetChildrenCount(GetId())), + unsigned(tree->GetChildrenCount(GetId(), false))); +} + + diff --git a/OPJViewer/source/OPJViewer.cpp b/OPJViewer/source/OPJViewer.cpp index 61668e41..082a04fb 100644 --- a/OPJViewer/source/OPJViewer.cpp +++ b/OPJViewer/source/OPJViewer.cpp @@ -132,11 +132,11 @@ int winNumber = 1; // Initialise this in OnInit, not statically bool OPJViewerApp::OnInit(void) { + int n; #if wxUSE_UNICODE wxChar **wxArgv = new wxChar *[argc + 1]; - int n; for (n = 0; n < argc; n++ ) { wxMB2WXbuf warg = wxConvertMB2WX((char *) argv[n]); wxArgv[n] = wxStrdup(warg); @@ -189,6 +189,9 @@ bool OPJViewerApp::OnInit(void) #if wxUSE_LIBJPEG wxImage::AddHandler( new wxJPEGHandler ); #endif +#if USE_MXF + wxImage::AddHandler( new wxMXFHandler ); +#endif // USE_MXF #if wxUSE_LIBOPENJPEG wxImage::AddHandler( new wxJ2KHandler ); wxImage::AddHandler( new wxJP2Handler ); @@ -211,17 +214,17 @@ bool OPJViewerApp::OnInit(void) //load decoding engine parameters OPJconfig = new wxConfig(OPJ_APPLICATION, OPJ_APPLICATION_VENDOR); - OPJconfig->Read(wxT("enabledeco"), &m_enabledeco, (bool) true); - OPJconfig->Read(wxT("enableparse"), &m_enableparse, (bool) true); - OPJconfig->Read(wxT("resizemethod"), &m_resizemethod, (long) 0); - OPJconfig->Read(wxT("xxxreducefactor"), &m_reducefactor, (long) 0); - OPJconfig->Read(wxT("xxxqualitylayers"), &m_qualitylayers, (long) 0); - OPJconfig->Read(wxT("xxxcomponents"), &m_components, (long) 0); - OPJconfig->Read(wxT("xxxframenum"), &m_framenum, (long) 0); + OPJconfig->Read(wxT("decode/enabledeco"), &m_enabledeco, (bool) true); + OPJconfig->Read(wxT("decode/enableparse"), &m_enableparse, (bool) true); + OPJconfig->Read(wxT("decode/resizemethod"), &m_resizemethod, (long) 0); + OPJconfig->Read(wxT("decode/xxxreducefactor"), &m_reducefactor, (long) 0); + OPJconfig->Read(wxT("decode/xxxqualitylayers"), &m_qualitylayers, (long) 0); + OPJconfig->Read(wxT("decode/xxxcomponents"), &m_components, (long) 0); + OPJconfig->Read(wxT("decode/xxxframenum"), &m_framenum, (long) 0); #ifdef USE_JPWL - OPJconfig->Read(wxT("enablejpwl"), &m_enablejpwl, (bool) true); - OPJconfig->Read(wxT("expcomps"), &m_expcomps, (long) JPWL_EXPECTED_COMPONENTS); - OPJconfig->Read(wxT("maxtiles"), &m_maxtiles, (long) JPWL_MAXIMUM_TILES); + OPJconfig->Read(wxT("decode/enablejpwl"), &m_enablejpwl, (bool) true); + OPJconfig->Read(wxT("decode/expcomps"), &m_expcomps, (long) JPWL_EXPECTED_COMPONENTS); + OPJconfig->Read(wxT("decode/maxtiles"), &m_maxtiles, (long) JPWL_MAXIMUM_TILES); #endif // USE_JPWL OPJconfig->Write(wxT("teststring"), wxT("This is a test value")); @@ -237,31 +240,45 @@ bool OPJViewerApp::OnInit(void) OPJconfig->Read(wxT("frameheight"), &m_frameheight, (long) OPJ_FRAME_HEIGHT); // load encoding engine parameters - OPJconfig->Read(wxT("subsampling"), &m_subsampling, (wxString) wxT("1,1")); - OPJconfig->Read(wxT("origin"), &m_origin, (wxString) wxT("0,0")); - OPJconfig->Read(wxT("rates"), &m_rates, (wxString) wxT("20,10,5")); - OPJconfig->Read(wxT("quality"), &m_quality, (wxString) wxT("30,35,40")); - OPJconfig->Read(wxT("enablequality"), &m_enablequality, (bool) false); - OPJconfig->Read(wxT("multicomp"), &m_multicomp, (bool) false); - OPJconfig->Read(wxT("irreversible"), &m_irreversible, (bool) false); - OPJconfig->Read(wxT("resolutions"), &m_resolutions, (int) 6); - OPJconfig->Read(wxT("progression"), &m_progression, (int) 0); - OPJconfig->Read(wxT("cbsize"), &m_cbsize, (wxString) wxT("32,32")); - OPJconfig->Read(wxT("prsize"), &m_prsize, (wxString) wxT("[128,128],[128,128]")); - OPJconfig->Read(wxT("tsize"), &m_tsize, (wxString) wxT("")); - OPJconfig->Read(wxT("torigin"), &m_torigin, (wxString) wxT("0,0")); - OPJconfig->Read(wxT("enablesop"), &m_enablesop, (bool) false); - OPJconfig->Read(wxT("enableeph"), &m_enableeph, (bool) false); - OPJconfig->Read(wxT("enablebypass"), &m_enablebypass, (bool) false); - OPJconfig->Read(wxT("enablereset"), &m_enablereset, (bool) false); - OPJconfig->Read(wxT("enablerestart"), &m_enablerestart, (bool) false); - OPJconfig->Read(wxT("enablevsc"), &m_enablevsc, (bool) false); - OPJconfig->Read(wxT("enableerterm"), &m_enableerterm, (bool) false); - OPJconfig->Read(wxT("enablesegmark"), &m_enablesegmark, (bool) false); - OPJconfig->Read(wxT("enablecomm"), &m_enablecomm, (bool) true); - OPJconfig->Read(wxT("comment"), &m_comment, (wxString) wxT("")); - OPJconfig->Read(wxT("enableidx"), &m_enableidx, (bool) false); - OPJconfig->Read(wxT("index"), &m_index, (wxString) wxT("index.txt")); + OPJconfig->Read(wxT("encode/subsampling"), &m_subsampling, (wxString) wxT("1,1")); + OPJconfig->Read(wxT("encode/origin"), &m_origin, (wxString) wxT("0,0")); + OPJconfig->Read(wxT("encode/rates"), &m_rates, (wxString) wxT("20,10,5")); + OPJconfig->Read(wxT("encode/quality"), &m_quality, (wxString) wxT("30,35,40")); + OPJconfig->Read(wxT("encode/enablequality"), &m_enablequality, (bool) false); + OPJconfig->Read(wxT("encode/multicomp"), &m_multicomp, (bool) false); + OPJconfig->Read(wxT("encode/irreversible"), &m_irreversible, (bool) false); + OPJconfig->Read(wxT("encode/resolutions"), &m_resolutions, (int) 6); + OPJconfig->Read(wxT("encode/progression"), &m_progression, (int) 0); + OPJconfig->Read(wxT("encode/cbsize"), &m_cbsize, (wxString) wxT("32,32")); + OPJconfig->Read(wxT("encode/prsize"), &m_prsize, (wxString) wxT("[128,128],[128,128]")); + OPJconfig->Read(wxT("encode/tsize"), &m_tsize, (wxString) wxT("")); + OPJconfig->Read(wxT("encode/torigin"), &m_torigin, (wxString) wxT("0,0")); + OPJconfig->Read(wxT("encode/enablesop"), &m_enablesop, (bool) false); + OPJconfig->Read(wxT("encode/enableeph"), &m_enableeph, (bool) false); + OPJconfig->Read(wxT("encode/enablebypass"), &m_enablebypass, (bool) false); + OPJconfig->Read(wxT("encode/enablereset"), &m_enablereset, (bool) false); + OPJconfig->Read(wxT("encode/enablerestart"), &m_enablerestart, (bool) false); + OPJconfig->Read(wxT("encode/enablevsc"), &m_enablevsc, (bool) false); + OPJconfig->Read(wxT("encode/enableerterm"), &m_enableerterm, (bool) false); + OPJconfig->Read(wxT("encode/enablesegmark"), &m_enablesegmark, (bool) false); + OPJconfig->Read(wxT("encode/enablecomm"), &m_enablecomm, (bool) true); + OPJconfig->Read(wxT("encode/enablepoc"), &m_enablepoc, (bool) false); + OPJconfig->Read(wxT("encode/comment"), &m_comment, (wxString) wxT("")); + OPJconfig->Read(wxT("encode/poc"), &m_poc, (wxString) wxT("T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL")); + OPJconfig->Read(wxT("encode/enableidx"), &m_enableidx, (bool) false); + OPJconfig->Read(wxT("encode/index"), &m_index, (wxString) wxT("index.txt")); +#ifdef USE_JPWL + OPJconfig->Read(wxT("encode/enablejpwl"), &m_enablejpwle, (bool) true); + for (n = 0; n < MYJPWL_MAX_NO_TILESPECS; n++) { + OPJconfig->Read(wxT("encode/jpwl/hprotsel") + wxString::Format(wxT("%02d"), n), &m_hprotsel[n], 0); + OPJconfig->Read(wxT("encode/jpwl/htileval") + wxString::Format(wxT("%02d"), n), &m_htileval[n], 0); + OPJconfig->Read(wxT("encode/jpwl/pprotsel") + wxString::Format(wxT("%02d"), n), &m_pprotsel[n], 0); + OPJconfig->Read(wxT("encode/jpwl/ptileval") + wxString::Format(wxT("%02d"), n), &m_ptileval[n], 0); + OPJconfig->Read(wxT("encode/jpwl/ppackval") + wxString::Format(wxT("%02d"), n), &m_ppackval[n], 0); + OPJconfig->Read(wxT("encode/jpwl/sensisel") + wxString::Format(wxT("%02d"), n), &m_sensisel[n], 0); + OPJconfig->Read(wxT("encode/jpwl/stileval") + wxString::Format(wxT("%02d"), n), &m_stileval[n], 0); + } +#endif // USE_JPWL #else // set decoding engine parameters @@ -311,6 +328,19 @@ bool OPJViewerApp::OnInit(void) m_index = wxT("index.txt"); m_enablecomm = true; m_comment = wxT(""); + m_enablepoc = false; + m_poc = wxT("T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL"); +#ifdef USE_JPWL + m_enablejpwle = true; + for (n = 0; n < MYJPWL_MAX_NO_TILESPECS; n++) { + m_hprotsel[n] = 0; + m_htileval[n] = 0; + m_pprotsel[n] = 0; + m_ptileval[n] = 0; + m_sensisel[n] = 0; + m_stileval[n] = 0; + } +#endif // USE_JPWL #endif // OPJ_INICONFIG @@ -362,18 +392,20 @@ bool OPJViewerApp::OnInit(void) int OPJViewerApp::OnExit() { + int n; + #ifdef OPJ_INICONFIG - OPJconfig->Write(wxT("enabledeco"), m_enabledeco); - OPJconfig->Write(wxT("enableparse"), m_enableparse); - OPJconfig->Write(wxT("resizemethod"), m_resizemethod); - OPJconfig->Write(wxT("reducefactor"), m_reducefactor); - OPJconfig->Write(wxT("qualitylayers"), m_qualitylayers); - OPJconfig->Write(wxT("components"), m_components); - OPJconfig->Write(wxT("framenum"), m_framenum); + OPJconfig->Write(wxT("decode/enabledeco"), m_enabledeco); + OPJconfig->Write(wxT("decode/enableparse"), m_enableparse); + OPJconfig->Write(wxT("decode/resizemethod"), m_resizemethod); + OPJconfig->Write(wxT("decode/reducefactor"), m_reducefactor); + OPJconfig->Write(wxT("decode/qualitylayers"), m_qualitylayers); + OPJconfig->Write(wxT("decode/components"), m_components); + OPJconfig->Write(wxT("decode/framenum"), m_framenum); #ifdef USE_JPWL - OPJconfig->Write(wxT("enablejpwl"), m_enablejpwl); - OPJconfig->Write(wxT("expcomps"), m_expcomps); - OPJconfig->Write(wxT("maxtiles"), m_maxtiles); + OPJconfig->Write(wxT("decode/enablejpwl"), m_enablejpwl); + OPJconfig->Write(wxT("decode/expcomps"), m_expcomps); + OPJconfig->Write(wxT("decode/maxtiles"), m_maxtiles); #endif // USE_JPWL OPJconfig->Write(wxT("showtoolbar"), m_showtoolbar); OPJconfig->Write(wxT("showbrowser"), m_showbrowser); @@ -383,31 +415,45 @@ int OPJViewerApp::OnExit() OPJconfig->Write(wxT("framewidth"), m_framewidth); OPJconfig->Write(wxT("frameheight"), m_frameheight); - OPJconfig->Write(wxT("subsampling"), m_subsampling); - OPJconfig->Write(wxT("origin"), m_origin); - OPJconfig->Write(wxT("rates"), m_rates); - OPJconfig->Write(wxT("quality"), m_quality); - OPJconfig->Write(wxT("enablequality"), m_enablequality); - OPJconfig->Write(wxT("multicomp"), m_multicomp); - OPJconfig->Write(wxT("irreversible"), m_irreversible); - OPJconfig->Write(wxT("resolutions"), m_resolutions); - OPJconfig->Write(wxT("progression"), m_progression); - OPJconfig->Write(wxT("cbsize"), m_cbsize); - OPJconfig->Write(wxT("prsize"), m_prsize); - OPJconfig->Write(wxT("tiles"), m_tsize); - OPJconfig->Write(wxT("torigin"), m_torigin); - OPJconfig->Write(wxT("enablesop"), m_enablesop); - OPJconfig->Write(wxT("enableeph"), m_enableeph); - OPJconfig->Write(wxT("enablebypass"), m_enablebypass); - OPJconfig->Write(wxT("enablereset"), m_enablereset); - OPJconfig->Write(wxT("enablerestart"), m_enablerestart); - OPJconfig->Write(wxT("enablevsc"), m_enablevsc); - OPJconfig->Write(wxT("enableerterm"), m_enableerterm); - OPJconfig->Write(wxT("enablesegmark"), m_enablesegmark); - OPJconfig->Write(wxT("enableidx"), m_enableidx); - OPJconfig->Write(wxT("index"), m_index); - OPJconfig->Write(wxT("enablecomm"), m_enablecomm); - OPJconfig->Write(wxT("comment"), m_comment); + OPJconfig->Write(wxT("encode/subsampling"), m_subsampling); + OPJconfig->Write(wxT("encode/origin"), m_origin); + OPJconfig->Write(wxT("encode/rates"), m_rates); + OPJconfig->Write(wxT("encode/quality"), m_quality); + OPJconfig->Write(wxT("encode/enablequality"), m_enablequality); + OPJconfig->Write(wxT("encode/multicomp"), m_multicomp); + OPJconfig->Write(wxT("encode/irreversible"), m_irreversible); + OPJconfig->Write(wxT("encode/resolutions"), m_resolutions); + OPJconfig->Write(wxT("encode/progression"), m_progression); + OPJconfig->Write(wxT("encode/cbsize"), m_cbsize); + OPJconfig->Write(wxT("encode/prsize"), m_prsize); + OPJconfig->Write(wxT("encode/tiles"), m_tsize); + OPJconfig->Write(wxT("encode/torigin"), m_torigin); + OPJconfig->Write(wxT("encode/enablesop"), m_enablesop); + OPJconfig->Write(wxT("encode/enableeph"), m_enableeph); + OPJconfig->Write(wxT("encode/enablebypass"), m_enablebypass); + OPJconfig->Write(wxT("encode/enablereset"), m_enablereset); + OPJconfig->Write(wxT("encode/enablerestart"), m_enablerestart); + OPJconfig->Write(wxT("encode/enablevsc"), m_enablevsc); + OPJconfig->Write(wxT("encode/enableerterm"), m_enableerterm); + OPJconfig->Write(wxT("encode/enablesegmark"), m_enablesegmark); + OPJconfig->Write(wxT("encode/enableidx"), m_enableidx); + OPJconfig->Write(wxT("encode/index"), m_index); + OPJconfig->Write(wxT("encode/enablecomm"), m_enablecomm); + OPJconfig->Write(wxT("encode/comment"), m_comment); + OPJconfig->Write(wxT("encode/enablepoc"), m_enablepoc); + OPJconfig->Write(wxT("encode/poc"), m_poc); +#ifdef USE_JPWL + OPJconfig->Write(wxT("encode/enablejpwl"), m_enablejpwle); + for (n = 0; n < MYJPWL_MAX_NO_TILESPECS; n++) { + OPJconfig->Write(wxT("encode/jpwl/hprotsel") + wxString::Format(wxT("%02d"), n), m_hprotsel[n]); + OPJconfig->Write(wxT("encode/jpwl/htileval") + wxString::Format(wxT("%02d"), n), m_htileval[n]); + OPJconfig->Write(wxT("encode/jpwl/pprotsel") + wxString::Format(wxT("%02d"), n), m_pprotsel[n]); + OPJconfig->Write(wxT("encode/jpwl/ptileval") + wxString::Format(wxT("%02d"), n), m_ptileval[n]); + OPJconfig->Write(wxT("encode/jpwl/ppackval") + wxString::Format(wxT("%02d"), n), m_ppackval[n]); + OPJconfig->Write(wxT("encode/jpwl/sensisel") + wxString::Format(wxT("%02d"), n), m_sensisel[n]); + OPJconfig->Write(wxT("encode/jpwl/stileval") + wxString::Format(wxT("%02d"), n), m_stileval[n]); + } +#endif // USE_JPWL #endif // OPJ_INICONFIG @@ -786,6 +832,8 @@ void OPJFrame::Resize(int number) void OPJFrame::OnSetsEnco(wxCommandEvent& event) { + int n; + OPJEncoderDialog dialog(this, event.GetId()); if (dialog.ShowModal() == wxID_OK) { @@ -816,6 +864,20 @@ void OPJFrame::OnSetsEnco(wxCommandEvent& event) wxGetApp().m_index = dialog.m_indexCtrl->GetValue(); wxGetApp().m_enablecomm = dialog.m_enablecommCheck->GetValue(); wxGetApp().m_comment = dialog.m_commentCtrl->GetValue(); + wxGetApp().m_enablepoc = dialog.m_enablepocCheck->GetValue(); + wxGetApp().m_poc = dialog.m_pocCtrl->GetValue(); +#ifdef USE_JPWL + wxGetApp().m_enablejpwle = dialog.m_enablejpwlCheck->GetValue(); + for (n = 0; n < MYJPWL_MAX_NO_TILESPECS; n++) { + wxGetApp().m_hprotsel[n] = dialog.m_hprotChoice[n]->GetSelection(); + wxGetApp().m_htileval[n] = dialog.m_htileCtrl[n]->GetValue(); + wxGetApp().m_pprotsel[n] = dialog.m_pprotChoice[n]->GetSelection(); + wxGetApp().m_ptileval[n] = dialog.m_ptileCtrl[n]->GetValue(); + wxGetApp().m_ppackval[n] = dialog.m_ppackCtrl[n]->GetValue(); + wxGetApp().m_sensisel[n] = dialog.m_sensiChoice[n]->GetSelection(); + wxGetApp().m_stileval[n] = dialog.m_stileCtrl[n]->GetValue(); + } +#endif // USE_JPWL }; } @@ -1047,63 +1109,6 @@ void OPJFrame::OnNextComp(wxCommandEvent& event) OnReload(e); } -// about window for the frame -void OPJFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) -{ -#ifdef OPJ_HTMLABOUT -#include "about_htm.h" -#include "opj_logo.xpm" - - wxBoxSizer *topsizer; - wxHtmlWindow *html; - wxDialog dlg(this, wxID_ANY, wxString(_("About"))); - - wxMemoryFSHandler::AddFile(wxT("opj_logo.xpm"), wxBitmap(opj_logo), wxBITMAP_TYPE_XPM); - - topsizer = new wxBoxSizer(wxVERTICAL); - - html = new wxHtmlWindow(&dlg, wxID_ANY, wxDefaultPosition, wxSize(320, 250), wxHW_SCROLLBAR_NEVER); - html->SetBorders(0); - //html->LoadPage(wxT("about/about.htm")); - //html->SetPage("Hello, world!"); - html->SetPage(htmlaboutpage); - html->SetSize(html->GetInternalRepresentation()->GetWidth(), - html->GetInternalRepresentation()->GetHeight()); - - topsizer->Add(html, 1, wxALL, 10); - - topsizer->Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10); - - wxButton *bu1 = new wxButton(&dlg, wxID_OK, wxT("OK")); - bu1->SetDefault(); - - topsizer->Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15); - - dlg.SetSizer(topsizer); - topsizer->Fit(&dlg); - - dlg.ShowModal(); - -#else - - wxMessageBox(wxString::Format(OPJ_APPLICATION_TITLEBAR - wxT("\n\n") - wxT("Built with %s and OpenJPEG ") - wxT(OPENJPEG_VERSION) - wxT("\non ") wxT(__DATE__) wxT(", ") wxT(__TIME__) - wxT("\nRunning under %s\n\n") - OPJ_APPLICATION_COPYRIGHT, - wxVERSION_STRING, - wxGetOsDescription().c_str()), - wxT("About ") OPJ_APPLICATION_NAME, - wxOK | wxICON_INFORMATION, - this - ); - -#endif - -} - void OPJFrame::OnToggleBrowser(wxCommandEvent& WXUNUSED(event)) { if (markerTreeWindow->IsShown()) @@ -1275,6 +1280,9 @@ void OPJFrame::OnFileOpen(wxCommandEvent& WXUNUSED(event)) #if wxUSE_LIBOPENJPEG wxT("JPEG 2000 files (*.jp2,*.j2k,*.j2c,*.mj2)|*.jp2;*.j2k;*.j2c;*.mj2") #endif +#if USE_MXF + wxT("|MXF JPEG 2000 video (*.mxf)|*.mxf") +#endif // USE_MXF #if wxUSE_LIBJPEG wxT("|JPEG files (*.jpg)|*.jpg") #endif @@ -1332,6 +1340,9 @@ void OPJFrame::OnFileSaveAs(wxCommandEvent& WXUNUSED(event)) void OPJFrame::OnMemoryOpen(wxCommandEvent& WXUNUSED(event)) { + // do nothing + return; + wxTextEntryDialog dialog(this, wxT("Memory HEX address range: start_address-stop_address"), wxT("Decode a memory buffer"), wxT("0x-0x"), @@ -1548,1223 +1559,22 @@ void OPJChildFrame::OnLostFocus(wxFocusEvent& event) //wxLogMessage(wxT("Lost focus: %d (%x)"), m_winnumber, event.GetWindow()); } -#if USE_GENERIC_TREECTRL -BEGIN_EVENT_TABLE(OPJMarkerTree, wxGenericTreeCtrl) -#else -BEGIN_EVENT_TABLE(OPJMarkerTree, wxTreeCtrl) -#endif - /*EVT_TREE_BEGIN_DRAG(TreeTest_Ctrl, OPJMarkerTree::OnBeginDrag) - EVT_TREE_BEGIN_RDRAG(TreeTest_Ctrl, OPJMarkerTree::OnBeginRDrag) - EVT_TREE_END_DRAG(TreeTest_Ctrl, OPJMarkerTree::OnEndDrag)*/ - /*EVT_TREE_BEGIN_LABEL_EDIT(TreeTest_Ctrl, OPJMarkerTree::OnBeginLabelEdit) - EVT_TREE_END_LABEL_EDIT(TreeTest_Ctrl, OPJMarkerTree::OnEndLabelEdit)*/ - /*EVT_TREE_DELETE_ITEM(TreeTest_Ctrl, OPJMarkerTree::OnDeleteItem)*/ -#if 0 // there are so many of those that logging them causes flicker - /*EVT_TREE_GET_INFO(TreeTest_Ctrl, OPJMarkerTree::OnGetInfo)*/ -#endif - /*EVT_TREE_SET_INFO(TreeTest_Ctrl, OPJMarkerTree::OnSetInfo) - EVT_TREE_ITEM_EXPANDED(TreeTest_Ctrl, OPJMarkerTree::OnItemExpanded)*/ - EVT_TREE_ITEM_EXPANDING(TreeTest_Ctrl, OPJMarkerTree::OnItemExpanding) - /*EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl, OPJMarkerTree::OnItemCollapsed) - EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, OPJMarkerTree::OnItemCollapsing)*/ - EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, OPJMarkerTree::OnSelChanged) - /*EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, OPJMarkerTree::OnSelChanging)*/ - /*EVT_TREE_KEY_DOWN(TreeTest_Ctrl, OPJMarkerTree::OnTreeKeyDown)*/ - /*EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl, OPJMarkerTree::OnItemActivated)*/ +//////////////////////////////// +// drag and drop +//////////////////////////////// - // so many differents ways to handle right mouse button clicks... - /*EVT_CONTEXT_MENU(OPJMarkerTree::OnContextMenu)*/ - // EVT_TREE_ITEM_MENU is the preferred event for creating context menus - // on a tree control, because it includes the point of the click or item, - // meaning that no additional placement calculations are required. - EVT_TREE_ITEM_MENU(TreeTest_Ctrl, OPJMarkerTree::OnItemMenu) - /*EVT_TREE_ITEM_RIGHT_CLICK(TreeTest_Ctrl, OPJMarkerTree::OnItemRClick)*/ - - /*EVT_RIGHT_DOWN(OPJMarkerTree::OnRMouseDown) - EVT_RIGHT_UP(OPJMarkerTree::OnRMouseUp) - EVT_RIGHT_DCLICK(OPJMarkerTree::OnRMouseDClick)*/ -END_EVENT_TABLE() - -// OPJMarkerTree implementation -#if USE_GENERIC_TREECTRL -IMPLEMENT_DYNAMIC_CLASS(OPJMarkerTree, wxGenericTreeCtrl) -#else -IMPLEMENT_DYNAMIC_CLASS(OPJMarkerTree, wxTreeCtrl) -#endif - -OPJMarkerTree::OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileName fname, wxString name, const wxWindowID id, - const wxPoint& pos, const wxSize& size, long style) - : wxTreeCtrl(parent, id, pos, size, style) +bool OPJDnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString& filenames) { - m_reverseSort = false; - m_fname = fname; - - m_peektextCtrl = ((OPJFrame *) (parent->GetParent()->GetParent()))->m_textCtrlbrowse; - CreateImageList(); - - // Add some items to the tree - //AddTestItemsToTree(5, 5); - int image = wxGetApp().ShowImages() ? OPJMarkerTree::TreeCtrlIcon_Folder : -1; - wxTreeItemId rootId = AddRoot(name, - image, image, - new OPJMarkerData(name)); - - OPJParseThread *pthread = CreateParseThread(0x00, subframe); - if (pthread->Run() != wxTHREAD_NO_ERROR) - wxLogMessage(wxT("Can't start parse thread!")); - else - wxLogMessage(wxT("New parse thread started.")); - - m_childframe = subframe; -} - -void OPJMarkerTree::CreateImageList(int size) -{ - if (size == -1) { - SetImageList(NULL); - return; + /*size_t nFiles = filenames.GetCount(); + wxString str; + str.Printf( _T("%d files dropped\n"), (int)nFiles); + for ( size_t n = 0; n < nFiles; n++ ) { + str << filenames[n] << wxT("\n"); } - if (size == 0) - size = m_imageSize; - else - m_imageSize = size; + wxLogMessage(str);*/ + m_pOwner->OpenFiles(filenames, filenames); - // Make an image list containing small icons - wxImageList *images = new wxImageList(size, size, true); - - // should correspond to TreeCtrlIcon_xxx enum - wxBusyCursor wait; - wxIcon icons[5]; - icons[0] = wxIcon(icon1_xpm); - icons[1] = wxIcon(icon2_xpm); - icons[2] = wxIcon(icon3_xpm); - icons[3] = wxIcon(icon4_xpm); - icons[4] = wxIcon(icon5_xpm); - - int sizeOrig = icons[0].GetWidth(); - for (size_t i = 0; i < WXSIZEOF(icons); i++) { - if (size == sizeOrig) { - images->Add(icons[i]); - } else { - images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size))); - } - } - - AssignImageList(images); + return true; } -#if USE_GENERIC_TREECTRL || !defined(__WXMSW__) -void OPJMarkerTree::CreateButtonsImageList(int size) -{ - if ( size == -1 ) { - SetButtonsImageList(NULL); - return; - } - - // Make an image list containing small icons - wxImageList *images = new wxImageList(size, size, true); - - // should correspond to TreeCtrlIcon_xxx enum - wxBusyCursor wait; - wxIcon icons[4]; - icons[0] = wxIcon(icon3_xpm); // closed - icons[1] = wxIcon(icon3_xpm); // closed, selected - icons[2] = wxIcon(icon5_xpm); // open - icons[3] = wxIcon(icon5_xpm); // open, selected - - for ( size_t i = 0; i < WXSIZEOF(icons); i++ ) { - int sizeOrig = icons[i].GetWidth(); - if ( size == sizeOrig ) { - images->Add(icons[i]); - } else { - images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size))); - } - } - - AssignButtonsImageList(images); -#else -void OPJMarkerTree::CreateButtonsImageList(int WXUNUSED(size)) -{ -#endif -} - -void OPJParseThread::LoadFile(wxFileName fname) -{ - wxTreeItemId rootid; - - // this is the root node - int image = wxGetApp().ShowImages() ? m_tree->TreeCtrlIcon_Folder : -1; - - if (this->m_parentid) { - // leaf of a tree - rootid = m_parentid; - m_tree->SetItemText(rootid, wxT("Parsing...")); - - } else { - - // delete the existing tree hierarchy - m_tree->DeleteAllItems(); - - // new tree - rootid = m_tree->AddRoot(wxT("Parsing..."), - image, - image, - new OPJMarkerData(fname.GetFullPath()) - ); - //m_tree->SetItemFont(rootid, *wxITALIC_FONT); - m_tree->SetItemBold(rootid); - } - - // open the file - wxFile m_file(fname.GetFullPath().c_str(), wxFile::read); - - // parsing enabled? - if (wxGetApp().m_enableparse) { - - // what is the extension? - if ((fname.GetExt() == wxT("j2k")) || (fname.GetExt() == wxT("j2c"))) { - - // parse the file - ParseJ2KFile(&m_file, 0, m_file.Length(), rootid); - - } else if ((fname.GetExt() == wxT("jp2")) || (fname.GetExt() == wxT("mj2"))) { - - // parse the file - if (this->m_parentid) { - //WriteText(wxT("Only a subsection of jp2")); - OPJMarkerData *data = (OPJMarkerData *) m_tree->GetItemData(rootid); - ParseJ2KFile(&m_file, data->m_start, data->m_length, rootid); - m_tree->Expand(rootid); - - } else { - // as usual - ParseJP2File(&m_file, 0, m_file.Length(), rootid); - } - - } else { - - // unknown extension - WriteText(wxT("Unknown file format!")); - - } - - } - - - // this is the root node - if (this->m_parentid) - m_tree->SetItemText(rootid, wxT("Codestream")); - else - //m_tree->SetItemText(rootid, wxString::Format(wxT("%s (%d B)"), fname.GetFullName(), m_file.Length())); - m_tree->SetItemText(rootid, fname.GetFullName()); - - // close the file - m_file.Close(); - - WriteText(wxT("Parsing finished!")); -} - -/*int OPJMarkerTree::OnCompareItems(const wxTreeItemId& item1, - const wxTreeItemId& item2) -{ - if ( m_reverseSort ) - { - // just exchange 1st and 2nd items - return wxTreeCtrl::OnCompareItems(item2, item1); - } - else - { - return wxTreeCtrl::OnCompareItems(item1, item2); - } -}*/ - -/*void OPJMarkerTree::AddItemsRecursively(const wxTreeItemId& idParent, - size_t numChildren, - size_t depth, - size_t folder) -{ - if ( depth > 0 ) - { - bool hasChildren = depth > 1; - - wxString str; - for ( size_t n = 0; n < numChildren; n++ ) - { - // at depth 1 elements won't have any more children - if ( hasChildren ) - str.Printf(wxT("%s child %u"), wxT("Folder"), unsigned(n + 1)); - else - str.Printf(wxT("%s child %u.%u"), wxT("File"), unsigned(folder), unsigned(n + 1)); - - // here we pass to AppendItem() normal and selected item images (we - // suppose that selected image follows the normal one in the enum) - int image, imageSel; - if ( wxGetApp().ShowImages() ) - { - image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder; - imageSel = image + 1; - } - else - { - image = imageSel = -1; - } - wxTreeItemId id = AppendItem(idParent, str, image, imageSel, - new OPJMarkerData(str)); - - // and now we also set the expanded one (only for the folders) - if ( hasChildren && wxGetApp().ShowImages() ) - { - SetItemImage(id, TreeCtrlIcon_FolderOpened, - wxTreeItemIcon_Expanded); - } - - // remember the last child for OnEnsureVisible() - if ( !hasChildren && n == numChildren - 1 ) - { - m_lastItem = id; - } - - AddItemsRecursively(id, numChildren, depth - 1, n + 1); - } - } - //else: done! -}*/ - -/*void OPJMarkerTree::AddTestItemsToTree(size_t numChildren, - size_t depth) -{ - int image = wxGetApp().ShowImages() ? OPJMarkerTree::TreeCtrlIcon_Folder : -1; - wxTreeItemId rootId = AddRoot(wxT("Root"), - image, image, - new OPJMarkerData(wxT("Root item"))); - if ( image != -1 ) - { - SetItemImage(rootId, TreeCtrlIcon_FolderOpened, wxTreeItemIcon_Expanded); - } - - AddItemsRecursively(rootId, numChildren, depth, 0); - - // set some colours/fonts for testing - SetItemFont(rootId, *wxITALIC_FONT); - - wxTreeItemIdValue cookie; - wxTreeItemId id = GetFirstChild(rootId, cookie); - SetItemTextColour(id, *wxBLUE); - - id = GetNextChild(rootId, cookie); - id = GetNextChild(rootId, cookie); - SetItemTextColour(id, *wxRED); - SetItemBackgroundColour(id, *wxLIGHT_GREY); -}*/ - -/*void OPJMarkerTree::GetItemsRecursively(const wxTreeItemId& idParent, - wxTreeItemIdValue cookie) -{ - wxTreeItemId id; - - if ( !cookie ) - id = GetFirstChild(idParent, cookie); - else - id = GetNextChild(idParent, cookie); - - if ( !id.IsOk() ) - return; - - wxString text = GetItemText(id); - wxLogMessage(text); - - if (ItemHasChildren(id)) - GetItemsRecursively(id); - - GetItemsRecursively(idParent, cookie); -}*/ - -/*void OPJMarkerTree::DoToggleIcon(const wxTreeItemId& item) -{ - int image = (GetItemImage(item) == TreeCtrlIcon_Folder) - ? TreeCtrlIcon_File - : TreeCtrlIcon_Folder; - SetItemImage(item, image, wxTreeItemIcon_Normal); - - image = (GetItemImage(item) == TreeCtrlIcon_FolderSelected) - ? TreeCtrlIcon_FileSelected - : TreeCtrlIcon_FolderSelected; - SetItemImage(item, image, wxTreeItemIcon_Selected); -}*/ - -void OPJMarkerTree::LogEvent(const wxChar *name, const wxTreeEvent& event) -{ - wxTreeItemId item = event.GetItem(); - wxString text; - if ( item.IsOk() ) - text << wxT('"') << GetItemText(item).c_str() << wxT('"'); - else - text = wxT("invalid item"); - wxLogMessage(wxT("%s(%s)"), name, text.c_str()); -} - -OPJParseThread *OPJMarkerTree::CreateParseThread(wxTreeItemId parentid, OPJChildFrame *subframe) -{ - OPJParseThread *pthread = new OPJParseThread(this, parentid); - - if (pthread->Create() != wxTHREAD_NO_ERROR) - wxLogError(wxT("Can't create parse thread!")); - - wxCriticalSectionLocker enter(wxGetApp().m_parse_critsect); - wxGetApp().m_parse_threads.Add(pthread); - - return pthread; -} - - -/*// avoid repetition -#define TREE_EVENT_HANDLER(name) \ -void OPJMarkerTree::name(wxTreeEvent& event) \ -{ \ - LogEvent(_T(#name), event); \ - SetLastItem(wxTreeItemId()); \ - event.Skip(); \ -}*/ - -/*TREE_EVENT_HANDLER(OnBeginRDrag)*/ -/*TREE_EVENT_HANDLER(OnDeleteItem)*/ -/*TREE_EVENT_HANDLER(OnGetInfo) -TREE_EVENT_HANDLER(OnSetInfo)*/ -/*TREE_EVENT_HANDLER(OnItemExpanded) -TREE_EVENT_HANDLER(OnItemExpanding)*/ -/*TREE_EVENT_HANDLER(OnItemCollapsed)*/ -/*TREE_EVENT_HANDLER(OnSelChanged) -TREE_EVENT_HANDLER(OnSelChanging)*/ - -/*#undef TREE_EVENT_HANDLER*/ - -void OPJMarkerTree::OnItemExpanding(wxTreeEvent& event) -{ - wxTreeItemId item = event.GetItem(); - OPJMarkerData* data = (OPJMarkerData *) GetItemData(item); - wxString text; - - if (item.IsOk()) - text << wxT('"') << GetItemText(item).c_str() << wxT('"'); - else - text = wxT("invalid item"); - - if (wxStrcmp(data->GetDesc1(), wxT("INFO-CSTREAM"))) - return; - - wxLogMessage(wxT("Expanding... (%s -> %s, %s, %d, %d)"), - text.c_str(), data->GetDesc1(), data->GetDesc2(), - data->m_start, data->m_length); - - // the codestream box is being asked for expansion - wxTreeItemIdValue cookie; - if (!GetFirstChild(item, cookie).IsOk()) { - OPJParseThread *pthread = CreateParseThread(item); - if (pthread->Run() != wxTHREAD_NO_ERROR) - wxLogMessage(wxT("Can't start parse thread!")); - else - wxLogMessage(wxT("New parse thread started.")); - } -} - -void OPJMarkerTree::OnSelChanged(wxTreeEvent& event) -{ - int bunch_linesize = 16; - int bunch_numlines = 7; - - wxTreeItemId item = event.GetItem(); - OPJMarkerData* data = (OPJMarkerData *) GetItemData(item); - wxString text; - int l, c, pos = 0, pre_pos; - - m_peektextCtrl->Clear(); - - /*text << wxString::Format(wxT("Selected... (%s -> %s, %s, %d, %d)"), - text.c_str(), data->GetDesc1(), data->GetDesc2(), - data->m_start, data->m_length) << wxT("\n");*/ - - // open the file and browse a little - wxFile *fp = new wxFile(m_fname.GetFullPath().c_str(), wxFile::read); - - // go to position claimed - fp->Seek(data->m_start, wxFromStart); - - // read a bunch - int max_read = wxMin(wxFileOffset(bunch_linesize * bunch_numlines), data->m_length - data->m_start + 1); - if (data->m_desc == wxT("MARK (65380)")) { - /*wxLogMessage(data->m_desc);*/ - max_read = data->m_length - data->m_start + 1; - bunch_numlines = (int) ceil((float) max_read / (float) bunch_linesize); - } - unsigned char *buffer = new unsigned char[bunch_linesize * bunch_numlines]; - fp->Read(buffer, max_read); - - // write the file data between start and stop - pos = 0; - for (l = 0; l < bunch_numlines; l++) { - - text << wxString::Format(wxT("%010d:"), data->m_start + pos); - - pre_pos = pos; - - // add hex browsing text - for (c = 0; c < bunch_linesize; c++) { - - if (!(c % 8)) - text << wxT(" "); - - if (pos < max_read) { - text << wxString::Format(wxT("%02X "), buffer[pos]); - } else - text << wxT(" "); - pos++; - } - - text << wxT(" "); - - // add char browsing text - for (c = 0; c < bunch_linesize; c++) { - - if (pre_pos < max_read) { - if ((buffer[pre_pos] == '\n') || - (buffer[pre_pos] == '\t') || - (buffer[pre_pos] == '\0') || - (buffer[pre_pos] == 0x0D) || - (buffer[pre_pos] == 0x0B)) - buffer[pre_pos] = ' '; - text << wxString::FromAscii((char) buffer[pre_pos]) << wxT("."); - } else - text << wxT(" "); - pre_pos++; - } - - text << wxT("\n"); - - } - - // close the file - fp->Close(); - - m_peektextCtrl->WriteText(text); - - delete buffer; -} - -/*void LogKeyEvent(const wxChar *name, const wxKeyEvent& event) -{ - wxString key; - long keycode = event.GetKeyCode(); - { - switch ( keycode ) - { - case WXK_BACK: key = wxT("BACK"); break; - case WXK_TAB: key = wxT("TAB"); break; - case WXK_RETURN: key = wxT("RETURN"); break; - case WXK_ESCAPE: key = wxT("ESCAPE"); break; - case WXK_SPACE: key = wxT("SPACE"); break; - case WXK_DELETE: key = wxT("DELETE"); break; - case WXK_START: key = wxT("START"); break; - case WXK_LBUTTON: key = wxT("LBUTTON"); break; - case WXK_RBUTTON: key = wxT("RBUTTON"); break; - case WXK_CANCEL: key = wxT("CANCEL"); break; - case WXK_MBUTTON: key = wxT("MBUTTON"); break; - case WXK_CLEAR: key = wxT("CLEAR"); break; - case WXK_SHIFT: key = wxT("SHIFT"); break; - case WXK_ALT: key = wxT("ALT"); break; - case WXK_CONTROL: key = wxT("CONTROL"); break; - case WXK_MENU: key = wxT("MENU"); break; - case WXK_PAUSE: key = wxT("PAUSE"); break; - case WXK_CAPITAL: key = wxT("CAPITAL"); break; - case WXK_END: key = wxT("END"); break; - case WXK_HOME: key = wxT("HOME"); break; - case WXK_LEFT: key = wxT("LEFT"); break; - case WXK_UP: key = wxT("UP"); break; - case WXK_RIGHT: key = wxT("RIGHT"); break; - case WXK_DOWN: key = wxT("DOWN"); break; - case WXK_SELECT: key = wxT("SELECT"); break; - case WXK_PRINT: key = wxT("PRINT"); break; - case WXK_EXECUTE: key = wxT("EXECUTE"); break; - case WXK_SNAPSHOT: key = wxT("SNAPSHOT"); break; - case WXK_INSERT: key = wxT("INSERT"); break; - case WXK_HELP: key = wxT("HELP"); break; - case WXK_NUMPAD0: key = wxT("NUMPAD0"); break; - case WXK_NUMPAD1: key = wxT("NUMPAD1"); break; - case WXK_NUMPAD2: key = wxT("NUMPAD2"); break; - case WXK_NUMPAD3: key = wxT("NUMPAD3"); break; - case WXK_NUMPAD4: key = wxT("NUMPAD4"); break; - case WXK_NUMPAD5: key = wxT("NUMPAD5"); break; - case WXK_NUMPAD6: key = wxT("NUMPAD6"); break; - case WXK_NUMPAD7: key = wxT("NUMPAD7"); break; - case WXK_NUMPAD8: key = wxT("NUMPAD8"); break; - case WXK_NUMPAD9: key = wxT("NUMPAD9"); break; - case WXK_MULTIPLY: key = wxT("MULTIPLY"); break; - case WXK_ADD: key = wxT("ADD"); break; - case WXK_SEPARATOR: key = wxT("SEPARATOR"); break; - case WXK_SUBTRACT: key = wxT("SUBTRACT"); break; - case WXK_DECIMAL: key = wxT("DECIMAL"); break; - case WXK_DIVIDE: key = wxT("DIVIDE"); break; - case WXK_F1: key = wxT("F1"); break; - case WXK_F2: key = wxT("F2"); break; - case WXK_F3: key = wxT("F3"); break; - case WXK_F4: key = wxT("F4"); break; - case WXK_F5: key = wxT("F5"); break; - case WXK_F6: key = wxT("F6"); break; - case WXK_F7: key = wxT("F7"); break; - case WXK_F8: key = wxT("F8"); break; - case WXK_F9: key = wxT("F9"); break; - case WXK_F10: key = wxT("F10"); break; - case WXK_F11: key = wxT("F11"); break; - case WXK_F12: key = wxT("F12"); break; - case WXK_F13: key = wxT("F13"); break; - case WXK_F14: key = wxT("F14"); break; - case WXK_F15: key = wxT("F15"); break; - case WXK_F16: key = wxT("F16"); break; - case WXK_F17: key = wxT("F17"); break; - case WXK_F18: key = wxT("F18"); break; - case WXK_F19: key = wxT("F19"); break; - case WXK_F20: key = wxT("F20"); break; - case WXK_F21: key = wxT("F21"); break; - case WXK_F22: key = wxT("F22"); break; - case WXK_F23: key = wxT("F23"); break; - case WXK_F24: key = wxT("F24"); break; - case WXK_NUMLOCK: key = wxT("NUMLOCK"); break; - case WXK_SCROLL: key = wxT("SCROLL"); break; - case WXK_PAGEUP: key = wxT("PAGEUP"); break; - case WXK_PAGEDOWN: key = wxT("PAGEDOWN"); break; - case WXK_NUMPAD_SPACE: key = wxT("NUMPAD_SPACE"); break; - case WXK_NUMPAD_TAB: key = wxT("NUMPAD_TAB"); break; - case WXK_NUMPAD_ENTER: key = wxT("NUMPAD_ENTER"); break; - case WXK_NUMPAD_F1: key = wxT("NUMPAD_F1"); break; - case WXK_NUMPAD_F2: key = wxT("NUMPAD_F2"); break; - case WXK_NUMPAD_F3: key = wxT("NUMPAD_F3"); break; - case WXK_NUMPAD_F4: key = wxT("NUMPAD_F4"); break; - case WXK_NUMPAD_HOME: key = wxT("NUMPAD_HOME"); break; - case WXK_NUMPAD_LEFT: key = wxT("NUMPAD_LEFT"); break; - case WXK_NUMPAD_UP: key = wxT("NUMPAD_UP"); break; - case WXK_NUMPAD_RIGHT: key = wxT("NUMPAD_RIGHT"); break; - case WXK_NUMPAD_DOWN: key = wxT("NUMPAD_DOWN"); break; - case WXK_NUMPAD_PAGEUP: key = wxT("NUMPAD_PAGEUP"); break; - case WXK_NUMPAD_PAGEDOWN: key = wxT("NUMPAD_PAGEDOWN"); break; - case WXK_NUMPAD_END: key = wxT("NUMPAD_END"); break; - case WXK_NUMPAD_BEGIN: key = wxT("NUMPAD_BEGIN"); break; - case WXK_NUMPAD_INSERT: key = wxT("NUMPAD_INSERT"); break; - case WXK_NUMPAD_DELETE: key = wxT("NUMPAD_DELETE"); break; - case WXK_NUMPAD_EQUAL: key = wxT("NUMPAD_EQUAL"); break; - case WXK_NUMPAD_MULTIPLY: key = wxT("NUMPAD_MULTIPLY"); break; - case WXK_NUMPAD_ADD: key = wxT("NUMPAD_ADD"); break; - case WXK_NUMPAD_SEPARATOR: key = wxT("NUMPAD_SEPARATOR"); break; - case WXK_NUMPAD_SUBTRACT: key = wxT("NUMPAD_SUBTRACT"); break; - case WXK_NUMPAD_DECIMAL: key = wxT("NUMPAD_DECIMAL"); break; - - default: - { - if ( keycode < 128 && wxIsprint((int)keycode) ) - key.Printf(wxT("'%c'"), (char)keycode); - else if ( keycode > 0 && keycode < 27 ) - key.Printf(_("Ctrl-%c"), wxT('A') + keycode - 1); - else - key.Printf(wxT("unknown (%ld)"), keycode); - } - } - } - - wxLogMessage(wxT("%s event: %s (flags = %c%c%c%c)"), - name, - key.c_str(), - event.ControlDown() ? wxT('C') : wxT('-'), - event.AltDown() ? wxT('A') : wxT('-'), - event.ShiftDown() ? wxT('S') : wxT('-'), - event.MetaDown() ? wxT('M') : wxT('-')); -} - -void OPJMarkerTree::OnTreeKeyDown(wxTreeEvent& event) -{ - LogKeyEvent(wxT("Tree key down "), event.GetKeyEvent()); - - event.Skip(); -}*/ - -/*void OPJMarkerTree::OnBeginDrag(wxTreeEvent& event) -{ - // need to explicitly allow drag - if ( event.GetItem() != GetRootItem() ) - { - m_draggedItem = event.GetItem(); - - wxLogMessage(wxT("OnBeginDrag: started dragging %s"), - GetItemText(m_draggedItem).c_str()); - - event.Allow(); - } - else - { - wxLogMessage(wxT("OnBeginDrag: this item can't be dragged.")); - } -} - -void OPJMarkerTree::OnEndDrag(wxTreeEvent& event) -{ - wxTreeItemId itemSrc = m_draggedItem, - itemDst = event.GetItem(); - m_draggedItem = (wxTreeItemId)0l; - - // where to copy the item? - if ( itemDst.IsOk() && !ItemHasChildren(itemDst) ) - { - // copy to the parent then - itemDst = GetItemParent(itemDst); - } - - if ( !itemDst.IsOk() ) - { - wxLogMessage(wxT("OnEndDrag: can't drop here.")); - - return; - } - - wxString text = GetItemText(itemSrc); - wxLogMessage(wxT("OnEndDrag: '%s' copied to '%s'."), - text.c_str(), GetItemText(itemDst).c_str()); - - // just do append here - we could also insert it just before/after the item - // on which it was dropped, but this requires slightly more work... we also - // completely ignore the client data and icon of the old item but could - // copy them as well. - // - // Finally, we only copy one item here but we might copy the entire tree if - // we were dragging a folder. - int image = wxGetApp().ShowImages() ? TreeCtrlIcon_File : -1; - AppendItem(itemDst, text, image); -}*/ - -/*void OPJMarkerTree::OnBeginLabelEdit(wxTreeEvent& event) -{ - wxLogMessage(wxT("OnBeginLabelEdit")); - - // for testing, prevent this item's label editing - wxTreeItemId itemId = event.GetItem(); - if ( IsTestItem(itemId) ) - { - wxMessageBox(wxT("You can't edit this item.")); - - event.Veto(); - } - else if ( itemId == GetRootItem() ) - { - // test that it is possible to change the text of the item being edited - SetItemText(itemId, _T("Editing root item")); - } -} - -void OPJMarkerTree::OnEndLabelEdit(wxTreeEvent& event) -{ - wxLogMessage(wxT("OnEndLabelEdit")); - - // don't allow anything except letters in the labels - if ( !event.GetLabel().IsWord() ) - { - wxMessageBox(wxT("The new label should be a single word.")); - - event.Veto(); - } -}*/ - -/*void OPJMarkerTree::OnItemCollapsing(wxTreeEvent& event) -{ - wxLogMessage(wxT("OnItemCollapsing")); - - // for testing, prevent the user from collapsing the first child folder - wxTreeItemId itemId = event.GetItem(); - if ( IsTestItem(itemId) ) - { - wxMessageBox(wxT("You can't collapse this item.")); - - event.Veto(); - } -}*/ - -/*void OPJMarkerTree::OnItemActivated(wxTreeEvent& event) -{ - // show some info about this item - wxTreeItemId itemId = event.GetItem(); - OPJMarkerData *item = (OPJMarkerData *)GetItemData(itemId); - - if ( item != NULL ) - { - item->ShowInfo(this); - } - - wxLogMessage(wxT("OnItemActivated")); -}*/ - -void OPJMarkerTree::OnItemMenu(wxTreeEvent& event) -{ - /*wxTreeItemId itemId = event.GetItem(); - OPJMarkerData *item = itemId.IsOk() ? (OPJMarkerData *)GetItemData(itemId) - : NULL; - - wxLogMessage(wxT("OnItemMenu for item \"%s\""), item ? item->GetDesc() - : _T(""));*/ - - //wxLogMessage(wxT("EEEEEEEEEE")); - - //event.Skip(); -} - -/*void OPJMarkerTree::OnContextMenu(wxContextMenuEvent& event) -{ - wxPoint pt = event.GetPosition(); - wxTreeItemId item; - wxLogMessage(wxT("OnContextMenu at screen coords (%i, %i)"), pt.x, pt.y); - - // check if event was generated by keyboard (MSW-specific?) - if ( pt.x == -1 && pt.y == -1 ) //(this is how MSW indicates it) - { - if ( !HasFlag(wxTR_MULTIPLE) ) - item = GetSelection(); - - // attempt to guess where to show the menu - if ( item.IsOk() ) - { - // if an item was clicked, show menu to the right of it - wxRect rect; - GetBoundingRect(item, rect, true );// only the label - pt = wxPoint(rect.GetRight(), rect.GetTop()); - } - else - { - pt = wxPoint(0, 0); - } - } - else // event was generated by mouse, use supplied coords - { - pt = ScreenToClient(pt); - item = HitTest(pt); - } - - ShowMenu(item, pt); -}*/ - -/*void OPJMarkerTree::ShowMenu(wxTreeItemId id, const wxPoint& pt) -{ - wxString title; - if ( id.IsOk() ) - { - title << wxT("Menu for ") << GetItemText(id); - } - else - { - title = wxT("Menu for no particular item"); - } - -#if wxUSE_MENUS - wxMenu menu(title); - menu.Append(TreeTest_About, wxT("&About...")); - menu.AppendSeparator(); - menu.Append(TreeTest_Highlight, wxT("&Highlight item")); - menu.Append(TreeTest_Dump, wxT("&Dump")); - - PopupMenu(&menu, pt); -#endif // wxUSE_MENUS -}*/ - -/*void OPJMarkerTree::OnItemRClick(wxTreeEvent& event) -{ - wxTreeItemId itemId = event.GetItem(); - OPJMarkerData *item = itemId.IsOk() ? (OPJMarkerData *)GetItemData(itemId) - : NULL; - - wxLogMessage(wxT("Item \"%s\" right clicked"), item ? item->GetDesc() - : _T("")); - - event.Skip(); -}*/ - -/* -void OPJMarkerTree::OnRMouseDown(wxMouseEvent& event) -{ - wxLogMessage(wxT("Right mouse button down")); - - event.Skip(); -} - -void OPJMarkerTree::OnRMouseUp(wxMouseEvent& event) -{ - wxLogMessage(wxT("Right mouse button up")); - - event.Skip(); -} - -void OPJMarkerTree::OnRMouseDClick(wxMouseEvent& event) -{ - wxTreeItemId id = HitTest(event.GetPosition()); - if ( !id ) - wxLogMessage(wxT("No item under mouse")); - else - { - OPJMarkerData *item = (OPJMarkerData *)GetItemData(id); - if ( item ) - wxLogMessage(wxT("Item '%s' under mouse"), item->GetDesc()); - } - - event.Skip(); -} -*/ - -static inline const wxChar *Bool2String(bool b) -{ - return b ? wxT("") : wxT("not "); -} - -void OPJMarkerData::ShowInfo(wxTreeCtrl *tree) -{ - wxLogMessage(wxT("Item '%s': %sselected, %sexpanded, %sbold,\n") - wxT("%u children (%u immediately under this item)."), - m_desc.c_str(), - Bool2String(tree->IsSelected(GetId())), - Bool2String(tree->IsExpanded(GetId())), - Bool2String(tree->IsBold(GetId())), - unsigned(tree->GetChildrenCount(GetId())), - unsigned(tree->GetChildrenCount(GetId(), false))); -} - -///////////////////////////////////////////////////////////////////// -// Encoding thread class -///////////////////////////////////////////////////////////////////// - -OPJEncoThread::OPJEncoThread(OPJCanvas *canvas) - : wxThread() -{ - m_count = 0; - m_canvas = canvas; -} - -void OPJEncoThread::WriteText(const wxString& text) -{ - wxString msg; - - // before doing any GUI calls we must ensure that this thread is the only - // one doing it! - -#ifndef __WXGTK__ - wxMutexGuiEnter(); -#endif // __WXGTK__ - - msg << text; - m_canvas->WriteText(msg); - -#ifndef __WXGTK__ - wxMutexGuiLeave(); -#endif // __WXGTK__ -} - -void OPJEncoThread::OnExit() -{ - wxCriticalSectionLocker locker(wxGetApp().m_enco_critsect); - - wxArrayThread& ethreads = wxGetApp().m_enco_threads; - ethreads.Remove(this); - - if (ethreads.IsEmpty() ) - { - // signal the main thread that there are no more threads left if it is - // waiting for us - if (wxGetApp().m_enco_waitingUntilAllDone) { - wxGetApp().m_enco_waitingUntilAllDone = false; - wxGetApp().m_enco_semAllDone.Post(); - } - } -} - -void *OPJEncoThread::Entry() -{ - wxString text; - - 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("Enco thread %d started"), m_canvas->m_childframe->m_winnumber); - WriteText(text); - - // set handler properties - wxJ2KHandler *j2kkkhandler = (wxJ2KHandler *) wxImage::FindHandler( wxBITMAP_TYPE_J2K); - j2kkkhandler->m_subsampling = wxGetApp().m_subsampling; - j2kkkhandler->m_origin = wxGetApp().m_origin; - j2kkkhandler->m_rates = wxGetApp().m_rates; - j2kkkhandler->m_quality = wxGetApp().m_quality; - j2kkkhandler->m_enablequality = wxGetApp().m_enablequality; - j2kkkhandler->m_multicomp = wxGetApp().m_multicomp; - j2kkkhandler->m_irreversible = wxGetApp().m_irreversible; - j2kkkhandler->m_resolutions = wxGetApp().m_resolutions; - j2kkkhandler->m_progression = wxGetApp().m_progression; - j2kkkhandler->m_cbsize = wxGetApp().m_cbsize; - j2kkkhandler->m_prsize = wxGetApp().m_prsize; - j2kkkhandler->m_tsize = wxGetApp().m_tsize; - j2kkkhandler->m_torigin = wxGetApp().m_torigin; - j2kkkhandler->m_enablesop = wxGetApp().m_enablesop; - j2kkkhandler->m_enableeph = wxGetApp().m_enableeph; - j2kkkhandler->m_enablebypass = wxGetApp().m_enablebypass; - j2kkkhandler->m_enablerestart = wxGetApp().m_enablerestart; - j2kkkhandler->m_enablereset = wxGetApp().m_enablereset; - j2kkkhandler->m_enablesegmark = wxGetApp().m_enablesegmark; - j2kkkhandler->m_enableerterm = wxGetApp().m_enableerterm; - j2kkkhandler->m_enablevsc = wxGetApp().m_enablevsc; - j2kkkhandler->m_enableidx = wxGetApp().m_enableidx; - j2kkkhandler->m_index = m_canvas->m_savename.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxGetApp().m_index; - j2kkkhandler->m_enablecomm = wxGetApp().m_enablecomm; - j2kkkhandler->m_comment = wxGetApp().m_comment; - - // save the file - if (!m_canvas->m_image100.SaveFile(m_canvas->m_savename.GetFullPath(), (wxBitmapType) wxBITMAP_TYPE_J2K)) { - WriteText(wxT("Can't save image")); - return NULL; - } - - text.Printf(wxT("Enco thread %d finished"), m_canvas->m_childframe->m_winnumber); - WriteText(text); - return NULL; -} - -///////////////////////////////////////////////////////////////////// -// Decoding thread class -///////////////////////////////////////////////////////////////////// - -OPJDecoThread::OPJDecoThread(OPJCanvas *canvas) - : wxThread() -{ - m_count = 0; - m_canvas = canvas; -} - -void OPJDecoThread::WriteText(const wxString& text) -{ - wxString msg; - - // before doing any GUI calls we must ensure that this thread is the only - // one doing it! - -#ifndef __WXGTK__ - wxMutexGuiEnter(); -#endif // __WXGTK__ - - msg << text; - m_canvas->WriteText(msg); - -#ifndef __WXGTK__ - wxMutexGuiLeave(); -#endif // __WXGTK__ -} - -void OPJDecoThread::OnExit() -{ - wxCriticalSectionLocker locker(wxGetApp().m_deco_critsect); - - wxArrayThread& dthreads = wxGetApp().m_deco_threads; - dthreads.Remove(this); - - if (dthreads.IsEmpty() ) - { - // signal the main thread that there are no more threads left if it is - // waiting for us - if (wxGetApp().m_deco_waitingUntilAllDone) { - wxGetApp().m_deco_waitingUntilAllDone = false; - wxGetApp().m_deco_semAllDone.Post(); - } - } -} - -void *OPJDecoThread::Entry() -{ - - wxString text; - - 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); - - WriteText(text); - - wxBitmap bitmap(100, 100); - wxImage image(100, 100, true); //= bitmap.ConvertToImage(); - image.Destroy(); - - 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 - - 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")); - return NULL; - } - - } else { - - // display a macaron - if (!image.Create(300, 5, false)) { - WriteText(wxT("Can't create image")); - return NULL; - } - - } - - // assign 100% image - m_canvas->m_image100 = wxBitmap(image); - - // find a fit-to-width zoom - 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)); - - // fit to width -#ifndef __WXGTK__ - m_canvas->m_childframe->m_frame->Rescale(zooml, m_canvas->m_childframe); -#endif // __WXGTK__ - - //m_canvas->m_image = m_canvas->m_image100; - //m_canvas->Refresh(); - //m_canvas->SetScrollbars(20, 20, (int)(0.5 + (double) image.GetWidth() / 20.0), (int)(0.5 + (double) image.GetHeight() / 20.0)); - - //text.Printf(wxT("Deco thread 0x%lx finished."), GetId()); - text.Printf(wxT("Deco thread %d finished"), m_canvas->m_childframe->m_winnumber); - WriteText(text); - return NULL; - -} - -///////////////////////////////////////////////////////////////////// -// Parsing thread class -///////////////////////////////////////////////////////////////////// - -OPJParseThread::OPJParseThread(OPJMarkerTree *tree, wxTreeItemId parentid) - : wxThread() -{ - m_count = 0; - m_tree = tree; - m_parentid = parentid; -} - -void OPJParseThread::WriteText(const wxString& text) -{ - wxString msg; - - // before doing any GUI calls we must ensure that this thread is the only - // one doing it! - -#ifndef __WXGTK__ - wxMutexGuiEnter(); -#endif // __WXGTK - - msg << text; - m_tree->WriteText(msg); - -#ifndef __WXGTK__ - wxMutexGuiLeave(); -#endif // __WXGTK -} - -void OPJParseThread::OnExit() -{ - wxCriticalSectionLocker locker(wxGetApp().m_parse_critsect); - - wxArrayThread& threads = wxGetApp().m_parse_threads; - threads.Remove(this); - - if (threads.IsEmpty()) { - // signal the main thread that there are no more threads left if it is - // waiting for us - if (wxGetApp().m_parse_waitingUntilAllDone) { - wxGetApp().m_parse_waitingUntilAllDone = false; - wxGetApp().m_parse_semAllDone.Post(); - } - } -} - -void *OPJParseThread::Entry() -{ - - printf("Entering\n\n"); - - wxString text; - - srand(GetId()); - int m_countnum = rand() % 9; - text.Printf(wxT("Parse thread 0x%lx started (priority = %u, time = %d)."), - GetId(), GetPriority(), m_countnum); - WriteText(text); - LoadFile(m_tree->m_fname); - text.Printf(wxT("Parse thread 0x%lx finished."), GetId()); - WriteText(text); - - - //wxLogMessage(wxT("Entering\n")); //test wxLog thread safeness - - //wxBusyCursor wait; - //wxBusyInfo wait(wxT("Decoding image ...")); - - - /*for ( m_count = 0; m_count < m_countnum; m_count++ ) - { - // check if we were asked to exit - if ( TestDestroy() ) - break; - - text.Printf(wxT("[%u] Parse thread 0x%lx here."), m_count, GetId()); - WriteText(text); - - // wxSleep() can't be called from non-GUI thread! - wxThread::Sleep(10); - }*/ - - // wxLogMessage(text); -- test wxLog thread safeness - - printf("Exiting\n\n"); - - return NULL; -} - - - - - - - diff --git a/OPJViewer/source/OPJViewer.h b/OPJViewer/source/OPJViewer.h index 51b6badb..d44f7e48 100644 --- a/OPJViewer/source/OPJViewer.h +++ b/OPJViewer/source/OPJViewer.h @@ -106,6 +106,9 @@ #include "imagj2k.h" #include "imagjp2.h" #include "imagmj2.h" +#ifdef USE_MXF +#include "imagmxf.h" +#endif // USE_MXF #ifdef __WXMSW__ typedef unsigned __int64 int8byte; @@ -150,6 +153,16 @@ typedef unsigned long long int8byte; #define OPJ_CANVAS_BORDER 10 #define OPJ_CANVAS_COLOUR *wxWHITE + + +#ifdef USE_JPWL + +//#define MYJPWL_MAX_NO_TILESPECS JPWL_MAX_NO_TILESPECS +#define MYJPWL_MAX_NO_TILESPECS 4 + +#endif // USE_JPWL + + class OPJDecoThread; class OPJEncoThread; class OPJParseThread; @@ -198,19 +211,25 @@ class OPJViewerApp: public wxApp bool m_enabledeco, m_enableparse; int m_reducefactor, m_qualitylayers, m_components, m_framenum; #ifdef USE_JPWL - bool m_enablejpwl; + bool m_enablejpwl, m_enablejpwle; int m_expcomps, m_maxtiles; int m_framewidth, m_frameheight; #endif // USE_JPWL // encoding engine parameters wxString m_subsampling, m_origin, m_rates, m_comment, m_index, m_quality; - wxString m_cbsize, m_prsize, m_tsize, m_torigin; + wxString m_cbsize, m_prsize, m_tsize, m_torigin, m_poc; bool m_enablecomm, m_enableidx, m_multicomp, m_irreversible, m_enablesop, m_enableeph; bool m_enablebypass, m_enablereset, m_enablerestart, m_enablevsc, m_enableerterm; - bool m_enablesegmark; + bool m_enablesegmark, m_enablepoc; bool m_enablequality; int m_resolutions, m_progression; +#ifdef USE_JPWL + int m_hprotsel[MYJPWL_MAX_NO_TILESPECS], m_pprotsel[MYJPWL_MAX_NO_TILESPECS]; + int m_htileval[MYJPWL_MAX_NO_TILESPECS], m_ptileval[MYJPWL_MAX_NO_TILESPECS], + m_ppackval[MYJPWL_MAX_NO_TILESPECS]; + int m_sensisel[MYJPWL_MAX_NO_TILESPECS], m_stileval[MYJPWL_MAX_NO_TILESPECS]; +#endif // USE_JPWL // some layout settings bool m_showtoolbar, m_showbrowser, m_showpeeker; @@ -655,13 +674,24 @@ public: wxPanel* CreatePart1_1SettingsPage(wxWindow* parent); wxPanel* CreatePart1_2SettingsPage(wxWindow* parent); /* wxPanel* CreatePart3SettingsPage(wxWindow* parent);*/ -#ifdef USE_JPWL - void OnEnableJPWL(wxCommandEvent& event); void OnEnableComm(wxCommandEvent& event); void OnEnableIdx(wxCommandEvent& event); + void OnEnablePoc(wxCommandEvent& event); void OnRadioQualityRate(wxCommandEvent& event); +#ifdef USE_JPWL + void OnEnableJPWL(wxCommandEvent& event); wxPanel* CreatePart11SettingsPage(wxWindow* parent); /*wxCheckBox *m_enablejpwlCheck;*/ + wxChoice *m_hprotChoice[MYJPWL_MAX_NO_TILESPECS]; + wxSpinCtrl *m_htileCtrl[MYJPWL_MAX_NO_TILESPECS]; + wxChoice *m_pprotChoice[MYJPWL_MAX_NO_TILESPECS]; + wxSpinCtrl *m_ptileCtrl[MYJPWL_MAX_NO_TILESPECS]; + wxSpinCtrl *m_ppackCtrl[MYJPWL_MAX_NO_TILESPECS]; + wxChoice *m_sensiChoice[MYJPWL_MAX_NO_TILESPECS]; + wxSpinCtrl *m_stileCtrl[MYJPWL_MAX_NO_TILESPECS]; + void OnHprotSelect(wxCommandEvent& event); + void OnPprotSelect(wxCommandEvent& event); + void OnSensiSelect(wxCommandEvent& event); #endif // USE_JPWL wxTextCtrl *m_subsamplingCtrl, *m_originCtrl, *m_rateCtrl, *m_commentCtrl; @@ -672,7 +702,7 @@ public: wxCheckBox *m_enablecommCheck, *m_enableidxCheck, *m_mctCheck, *m_irrevCheck; wxCheckBox *m_sopCheck, *m_ephCheck, *m_enablebypassCheck, *m_enableresetCheck, *m_enablerestartCheck, *m_enablevscCheck, *m_enableertermCheck, *m_enablesegmarkCheck; - wxCheckBox *m_enablepocCheck; + wxCheckBox *m_enablepocCheck, *m_enablejpwlCheck; wxSpinCtrl *m_resolutionsCtrl; protected: @@ -708,7 +738,14 @@ protected: OPJENCO_INDEXNAME, OPJENCO_POCSPEC, OPJENCO_ENABLECOMM, - OPJENCO_COMMENTTEXT + OPJENCO_COMMENTTEXT, + OPJENCO_HPROT, + OPJENCO_HTILE, + OPJENCO_PPROT, + OPJENCO_PTILE, + OPJENCO_PPACK, + OPJENCO_SENSI, + OPJENCO_STILE }; DECLARE_EVENT_TABLE() diff --git a/OPJViewer/source/build.h b/OPJViewer/source/build.h index 654179bd..e7f871ba 100644 --- a/OPJViewer/source/build.h +++ b/OPJViewer/source/build.h @@ -1 +1 @@ -wxT("292") +wxT("404") diff --git a/OPJViewer/source/imagj2k.cpp b/OPJViewer/source/imagj2k.cpp index 143a1c0c..e1c732d4 100644 --- a/OPJViewer/source/imagj2k.cpp +++ b/OPJViewer/source/imagj2k.cpp @@ -670,8 +670,7 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo /* Write the index to disk */ if (*indexfilename) { - bSuccess = write_index_file(&cstr_info, indexfilename); - if (!bSuccess) { + if (write_index_file(&cstr_info, indexfilename)) { wxLogError(wxT("Failed to output index file")); } } @@ -717,268 +716,6 @@ bool wxJ2KHandler::DoCanRead( wxInputStream& stream ) return hdr[0] == 0xFF && hdr[1] == 0x4F; } -// write the index file -bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *index) { - int tileno, compno, layno, resno, precno, pack_nb, x, y; - FILE *stream = NULL; - double total_disto = 0; - int tilepartno; - -#ifdef USE_JPWL - if (!strcmp(index, JPWL_PRIVATEINDEX_NAME)) - return true; -#endif // USE_JPWL - - if (!cstr_info) - return 1; - - stream = fopen(index, "w"); - if (!stream) { - fprintf(stderr, "failed to open index file [%s] for writing\n", index); - return false; - } - - fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h); - fprintf(stream, "%d\n", cstr_info->prog); - fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y); - fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th); - fprintf(stream, "%d\n", cstr_info->numcomps); - fprintf(stream, "%d\n", cstr_info->numlayers); - fprintf(stream, "%d\n", cstr_info->numdecompos); - - for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) { - fprintf(stream, "[%d,%d] ", - (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */ - } - - fprintf(stream, "\n"); - fprintf(stream, "%d\n", cstr_info->main_head_start); - fprintf(stream, "%d\n", cstr_info->main_head_end); - fprintf(stream, "%d\n", cstr_info->codestream_size); - - fprintf(stream, "\nINFO ON TILES\n"); - fprintf(stream, "tileno start_pos end_hd end_tile nbparts disto nbpix disto/nbpix\n"); - for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { - fprintf(stream, "%4d %9d %9d %9d %9d %9e %9d %9e\n", - cstr_info->tile[tileno].tileno, - cstr_info->tile[tileno].start_pos, - cstr_info->tile[tileno].end_header, - cstr_info->tile[tileno].end_pos, - cstr_info->tile[tileno].num_tps, - cstr_info->tile[tileno].distotile, cstr_info->tile[tileno].numpix, - cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix); - } - - for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { - int start_pos, end_ph_pos, end_pos; - double disto = 0; - int max_numdecompos = 0; - pack_nb = 0; - - for (compno = 0; compno < cstr_info->numcomps; compno++) { - if (max_numdecompos < cstr_info->numdecompos[compno]) - max_numdecompos = cstr_info->numdecompos[compno]; - } - - fprintf(stream, "\nTILE %d DETAILS\n", tileno); - fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n"); - for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++) - fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n", - tilepartno, tileno, - cstr_info->tile[tileno].tp[tilepartno].tp_start_pack, - cstr_info->tile[tileno].tp[tilepartno].tp_numpacks, - cstr_info->tile[tileno].tp[tilepartno].tp_start_pos, - cstr_info->tile[tileno].tp[tilepartno].tp_end_header, - cstr_info->tile[tileno].tp[tilepartno].tp_end_pos - ); - if (cstr_info->prog == LRCP) { /* LRCP */ - fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos disto\n"); - - for (layno = 0; layno < cstr_info->numlayers; layno++) { - for (resno = 0; resno < max_numdecompos + 1; resno++) { - for (compno = 0; compno < cstr_info->numcomps; compno++) { - int prec_max; - if (resno > cstr_info->numdecompos[compno]) - break; - prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; - for (precno = 0; precno < prec_max; precno++) { - start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; - end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; - end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; - disto = cstr_info->tile[tileno].packet[pack_nb].disto; - fprintf(stream, "%4d %6d %7d %5d %6d %6d %6d %6d %7d %8e\n", - pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos, disto); - total_disto += disto; - pack_nb++; - } - } - } - } - } /* LRCP */ - else if (cstr_info->prog == RLCP) { /* RLCP */ - - fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos disto\n"); - - for (resno = 0; resno < max_numdecompos + 1; resno++) { - for (layno = 0; layno < cstr_info->numlayers; layno++) { - for (compno = 0; compno < cstr_info->numcomps; compno++) { - int prec_max; - if (resno > cstr_info->numdecompos[compno]) - break; - prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; - for (precno = 0; precno < prec_max; precno++) { - start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; - end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; - end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; - disto = cstr_info->tile[tileno].packet[pack_nb].disto; - fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %7d %8e\n", - pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos, disto); - total_disto += disto; - pack_nb++; - } - } - } - } - } /* RLCP */ - else if (cstr_info->prog == RPCL) { /* RPCL */ - - fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos disto\n"); - - for (resno = 0; resno < max_numdecompos + 1; resno++) { - /* I suppose components have same XRsiz, YRsiz */ - int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; - int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; - int x1 = x0 + cstr_info->tile_x; - int y1 = y0 + cstr_info->tile_y; - for (compno = 0; compno < cstr_info->numcomps; compno++) { - int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; - if (resno > cstr_info->numdecompos[compno]) - break; - for (precno = 0; precno < prec_max; precno++) { - int pcnx = cstr_info->tile[tileno].pw[resno]; - int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); - int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); - int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; - int precno_y = (int) floor( (float)precno/(float)pcnx ); - for(y = y0; y < y1; y++) { - if (precno_y*pcy == y ) { - for (x = x0; x < x1; x++) { - if (precno_x*pcx == x ) { - for (layno = 0; layno < cstr_info->numlayers; layno++) { - start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; - end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; - end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; - disto = cstr_info->tile[tileno].packet[pack_nb].disto; - fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d %9d %7d %8e\n", - pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos, disto); - total_disto += disto; - pack_nb++; - } - } - }/* x = x0..x1 */ - } - } /* y = y0..y1 */ - } /* precno */ - } /* compno */ - } /* resno */ - } /* RPCL */ - else if (cstr_info->prog == PCRL) { /* PCRL */ - /* I suppose components have same XRsiz, YRsiz */ - int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; - int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; - int x1 = x0 + cstr_info->tile_x; - int y1 = y0 + cstr_info->tile_y; - - fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos disto\n"); - - for (compno = 0; compno < cstr_info->numcomps; compno++) { - for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { - int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; - for (precno = 0; precno < prec_max; precno++) { - int pcnx = cstr_info->tile[tileno].pw[resno]; - int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); - int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); - int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; - int precno_y = (int) floor( (float)precno/(float)pcnx ); - for(y = y0; y < y1; y++) { - if (precno_y*pcy == y ) { - for (x = x0; x < x1; x++) { - if (precno_x*pcx == x ) { - for (layno = 0; layno < cstr_info->numlayers; layno++) { - start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; - end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; - end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; - disto = cstr_info->tile[tileno].packet[pack_nb].disto; - fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d %8e\n", - pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos, disto); - total_disto += disto; - pack_nb++; - } - } - }/* x = x0..x1 */ - } - } /* y = y0..y1 */ - } /* precno */ - } /* resno */ - } /* compno */ - } /* PCRL */ - else { /* CPRL */ - - fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos disto\n"); - - for (compno = 0; compno < cstr_info->numcomps; compno++) { - /* I suppose components have same XRsiz, YRsiz */ - int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; - int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; - int x1 = x0 + cstr_info->tile_x; - int y1 = y0 + cstr_info->tile_y; - - for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { - int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; - for (precno = 0; precno < prec_max; precno++) { - int pcnx = cstr_info->tile[tileno].pw[resno]; - int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); - int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); - int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; - int precno_y = (int) floor( (float)precno/(float)pcnx ); - for(y = y0; y < y1; y++) { - if (precno_y*pcy == y ) { - for (x = x0; x < x1; x++) { - if (precno_x*pcx == x ) { - for (layno = 0; layno < cstr_info->numlayers; layno++) { - start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; - end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; - end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; - disto = cstr_info->tile[tileno].packet[pack_nb].disto; - fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d %8e\n", - pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos, disto); - total_disto += disto; - pack_nb++; - } - } - }/* x = x0..x1 */ - } - } /* y = y0..y1 */ - } /* precno */ - } /* resno */ - } /* compno */ - } /* CPRL */ - } /* tileno */ - - fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */ - fprintf(stream, "%.8e\n", total_disto); /* SE totale */ - fprintf(stream, "\nMARKER LIST\n"); - fprintf(stream, "%d\n", cstr_info->marknum); - fprintf(stream, "type\tstart_pos length\n"); - for (x = 0; x < cstr_info->marknum; x++) - fprintf(stream, "%X\t%9d %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len); - fclose(stream); - - fprintf(stderr,"Generated index file %s\n", index); - - return true; -} - #endif // wxUSE_STREAMS #endif // wxUSE_LIBOPENJPEG diff --git a/OPJViewer/source/imagj2k.h b/OPJViewer/source/imagj2k.h index af70392e..72000e31 100644 --- a/OPJViewer/source/imagj2k.h +++ b/OPJViewer/source/imagj2k.h @@ -45,6 +45,7 @@ #include "wx/image.h" #include "libopenjpeg/openjpeg.h" +#include "codec/index.h" #define wxBITMAP_TYPE_J2K 47 @@ -106,6 +107,8 @@ public: m_indexfname*/ m_enableidx = false; m_index = wxT("index.txt"); + m_enablepoc = false; + m_poc = wxT("T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL"); m_enablecomm = true; #if defined __WXMSW__ @@ -162,8 +165,8 @@ public: wxString m_index; bool m_enablecomm; wxString m_comment; - - bool write_index_file(opj_codestream_info_t *cstr_info, char *index); + bool m_enablepoc; + wxString m_poc; #if wxUSE_STREAMS virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 ); @@ -173,6 +176,7 @@ protected: #endif private: + OPJ_PROG_ORDER give_progression(char progression[4]); DECLARE_DYNAMIC_CLASS(wxJ2KHandler) }; diff --git a/OPJViewer/source/imagmxf.cpp b/OPJViewer/source/imagmxf.cpp new file mode 100644 index 00000000..4bc4a2c5 --- /dev/null +++ b/OPJViewer/source/imagmxf.cpp @@ -0,0 +1,274 @@ +/* + * Copyright (c) 2007, Digital Signal Processing Laboratory, Universitą degli studi di Perugia (UPG), Italy + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +///////////////////////////////////////////////////////////////////////////// +// Name: imagmxf.cpp +// Purpose: wxImage MXF (Material eXchange Format) JPEG 2000 file format handler +// Author: Giuseppe Baruffa - based on imagjpeg.cpp, Vaclav Slavik +// RCS-ID: $Id: imagmxf.cpp,v 0.00 2007/11/19 17:00:00 MW Exp $ +// Copyright: (c) Giuseppe Baruffa +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef USE_MXF + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_IMAGE && wxUSE_LIBOPENJPEG + +#include "imagmxf.h" + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/app.h" + #include "wx/intl.h" + #include "wx/bitmap.h" + #include "wx/module.h" +#endif + + +#include "libopenjpeg/openjpeg.h" + + +#include "wx/filefn.h" +#include "wx/wfstream.h" + +// ---------------------------------------------------------------------------- +// types +// ---------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// wxMXFHandler +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxMXFHandler,wxImageHandler) + +#if wxUSE_STREAMS + +//------------- JPEG 2000 Data Source Manager + +#define J2K_CFMT 0 +#define JP2_CFMT 1 +#define JPT_CFMT 2 +#define MJ2_CFMT 3 +#define PXM_DFMT 0 +#define PGX_DFMT 1 +#define BMP_DFMT 2 +#define YUV_DFMT 3 + +#define MAX_MESSAGE_LEN 200 + +/* sample error callback expecting a FILE* client object */ +void mxf_error_callback(const char *msg, void *client_data) { + int message_len = strlen(msg) - 1; + if (msg[message_len] != '\n') + message_len = MAX_MESSAGE_LEN; +#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 mxf_warning_callback(const char *msg, void *client_data) { + int message_len = strlen(msg) - 1; + if (msg[message_len] != '\n') + message_len = MAX_MESSAGE_LEN; +#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 mxf_info_callback(const char *msg, void *client_data) { + int message_len = strlen(msg) - 1; + if (msg[message_len] != '\n') + message_len = MAX_MESSAGE_LEN; +#ifndef __WXGTK__ + wxMutexGuiEnter(); +#endif /* __WXGTK__ */ + wxLogMessage(wxT("[INFO] %.*s"), message_len, msg); +#ifndef __WXGTK__ + wxMutexGuiLeave(); +#endif /* __WXGTK__ */ +} + + +///////////////////////////////////////////////// +///////////////////////////////////////////////// + +// load the mxf file format +bool wxMXFHandler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, int index) +{ + opj_dparameters_t parameters; /* decompression parameters */ + opj_event_mgr_t event_mgr; /* event manager */ + opj_image_t *opjimage = NULL; + unsigned char *src = NULL; + unsigned char *ptr; + int file_length, j2k_point, j2k_len; + opj_codestream_info_t cstr_info; /* Codestream information structure */ + + // destroy the image + image->Destroy(); + + /* handle to a decompressor */ + opj_dinfo_t* dinfo = NULL; + opj_cio_t *cio = NULL; + + /* configure the event callbacks (not required) */ + memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); + event_mgr.error_handler = mxf_error_callback; + event_mgr.warning_handler = mxf_warning_callback; + event_mgr.info_handler = mxf_info_callback; + + /* set decoding parameters to default values */ + opj_set_default_decoder_parameters(¶meters); + + /* prepare parameters */ + strncpy(parameters.infile, "", sizeof(parameters.infile)-1); + strncpy(parameters.outfile, "", sizeof(parameters.outfile)-1); + parameters.decod_format = J2K_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_J2K); + + /* find length of the stream */ + stream.SeekI(0, wxFromEnd); + file_length = (int) stream.TellI(); + + /* search for the m_framenum codestream position and length */ + //jp2c_point = searchjp2c(stream, file_length, m_framenum); + //jp2c_len = searchjp2c(stream, file_length, m_framenum); + j2k_point = 0; + j2k_len = 10; + + // malloc memory source + src = (unsigned char *) malloc(j2k_len); + + // copy the jp2c + stream.SeekI(j2k_point, wxFromStart); + stream.Read(src, j2k_len); + + /* catch events using our callbacks and give a local context */ + opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); + + /* setup the decoder decoding parameters using user parameters */ + opj_setup_decoder(dinfo, ¶meters); + + /* open a byte stream */ + cio = opj_cio_open((opj_common_ptr)dinfo, src, j2k_len); + + /* decode the stream and fill the image structure */ + opjimage = opj_decode_with_info(dinfo, cio, &cstr_info); + if (!opjimage) { + wxMutexGuiEnter(); + wxLogError(wxT("MXF: failed to decode image!")); + wxMutexGuiLeave(); + opj_destroy_decompress(dinfo); + opj_cio_close(cio); + free(src); + return false; + } + + /* close the byte stream */ + opj_cio_close(cio); + + /* common rendering method */ +#include "imagjpeg2000.cpp" + + wxMutexGuiEnter(); + wxLogMessage(wxT("MXF: image loaded.")); + wxMutexGuiLeave(); + + /* close openjpeg structs */ + opj_destroy_decompress(dinfo); + opj_image_destroy(opjimage); + free(src); + + if (!image->Ok()) + return false; + else + return true; + +} + +// save the mxf file format +bool wxMXFHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose ) +{ + wxLogError(wxT("MXF: Couldn't save movie -> not implemented.")); + return false; +} + +#ifdef __VISUALC__ + #pragma warning(default:4611) +#endif /* VC++ */ + +// recognize the MXF JPEG 2000 starting box +bool wxMXFHandler::DoCanRead( wxInputStream& stream ) +{ + unsigned char hdr[4]; + + if ( !stream.Read(hdr, WXSIZEOF(hdr)) ) + return false; + + return (hdr[0] == 0x06 && + hdr[1] == 0x0E && + hdr[2] == 0x2B && + hdr[3] == 0x34); +} + +#endif // wxUSE_STREAMS + +#endif // wxUSE_LIBOPENJPEG + +#endif // USE_MXF + diff --git a/OPJViewer/source/imagmxf.h b/OPJViewer/source/imagmxf.h new file mode 100644 index 00000000..f747a1df --- /dev/null +++ b/OPJViewer/source/imagmxf.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2007, Digital Signal Processing Laboratory, Universitą degli studi di Perugia (UPG), Italy + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +///////////////////////////////////////////////////////////////////////////// +// Name: imagmxf.h +// Purpose: wxImage MXF (Material eXchange Format) JPEG 2000 file format handler +// Author: G. Baruffa - based on imagjpeg.h, Vaclav Slavik +// RCS-ID: $Id: imagmj2.h,v 0.0 2007/11/19 17:00:00 VZ Exp $ +// Copyright: (c) Giuseppe Baruffa +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_IMAGMXF_H_ +#define _WX_IMAGMXF_H_ + +#ifdef USE_MXF + +#include "wx/defs.h" + +//----------------------------------------------------------------------------- +// wxMXFHandler +//----------------------------------------------------------------------------- + +#if wxUSE_LIBOPENJPEG + +#include "wx/image.h" +#include "libopenjpeg/openjpeg.h" + +#define wxBITMAP_TYPE_MXF 50 + +class WXDLLEXPORT wxMXFHandler: public wxImageHandler +{ +public: + inline wxMXFHandler() + { + m_name = wxT("MXF JPEG 2000 file format"); + m_extension = wxT("mxf"); + m_type = wxBITMAP_TYPE_MXF; + m_mime = wxT("image/mxf"); + + m_reducefactor = 0; + m_qualitylayers = 0; + m_components = 0; +#ifdef USE_JPWL + m_enablejpwl = true; + m_expcomps = JPWL_EXPECTED_COMPONENTS; + m_maxtiles = JPWL_MAXIMUM_TILES; +#endif // USE_JPWL + } + + // decoding engine parameters + int m_reducefactor, m_qualitylayers, m_components, m_framenum; +#ifdef USE_JPWL + bool m_enablejpwl; + int m_expcomps, m_maxtiles; +#endif // USE_JPWL + +#if wxUSE_STREAMS + virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 ); + virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true ); +protected: + virtual bool DoCanRead( wxInputStream& stream ); +#endif + +private: + DECLARE_DYNAMIC_CLASS(wxMXFHandler) +}; + +#endif // wxUSE_LIBOPENJPEG + +#endif // USE_MXF + +#endif // _WX_IMAGMXF_H_ + diff --git a/codec/image_to_j2k.dsp b/codec/image_to_j2k.dsp index ee02c169..3e1b0f66 100644 --- a/codec/image_to_j2k.dsp +++ b/codec/image_to_j2k.dsp @@ -106,5 +106,13 @@ SOURCE=.\compat\getopt.h SOURCE=.\image_to_j2k.c # End Source File +# Begin Source File + +SOURCE=.\index.c +# End Source File +# Begin Source File + +SOURCE=.\index.h +# End Source File # End Target # End Project diff --git a/codec/index.c b/codec/index.c index 985c18a0..2e0283dd 100644 --- a/codec/index.c +++ b/codec/index.c @@ -28,6 +28,7 @@ #include #include +#include #include "openjpeg.h" #include "index.h" diff --git a/codec/index.h b/codec/index.h index aed61e62..29f673a1 100644 --- a/codec/index.h +++ b/codec/index.h @@ -29,6 +29,10 @@ #ifndef __J2K_INDEX_H #define __J2K_INDEX_H +#ifdef __cplusplus +extern "C" { +#endif + /** Write a structured index to a file @param cstr_info Codestream information @@ -37,5 +41,9 @@ Write a structured index to a file */ int write_index_file(opj_codestream_info_t *cstr_info, char *index); +#ifdef __cplusplus +} +#endif + #endif /* __J2K_INDEX_H */ diff --git a/codec/j2k_to_image.dsp b/codec/j2k_to_image.dsp index 36fc74bb..927f1a59 100644 --- a/codec/j2k_to_image.dsp +++ b/codec/j2k_to_image.dsp @@ -103,6 +103,14 @@ SOURCE=.\compat\getopt.h # End Source File # Begin Source File +SOURCE=.\index.c +# End Source File +# Begin Source File + +SOURCE=.\index.h +# End Source File +# Begin Source File + SOURCE=.\j2k_to_image.c # End Source File # End Target diff --git a/jpwl/JPWL_image_to_j2k.dsp b/jpwl/JPWL_image_to_j2k.dsp index 52d5e9aa..dfc30d30 100644 --- a/jpwl/JPWL_image_to_j2k.dsp +++ b/jpwl/JPWL_image_to_j2k.dsp @@ -98,6 +98,10 @@ SOURCE=..\codec\compat\getopt.c SOURCE=..\codec\image_to_j2k.c # End Source File +# Begin Source File + +SOURCE=..\codec\index.c +# End Source File # End Group # Begin Group "Header Files" @@ -112,6 +116,10 @@ SOURCE=..\codec\compat\getopt.h # End Source File # Begin Source File +SOURCE=..\codec\index.h +# End Source File +# Begin Source File + SOURCE=..\libopenjpeg\openjpeg.h # End Source File # End Group diff --git a/jpwl/JPWL_j2k_to_image.dsp b/jpwl/JPWL_j2k_to_image.dsp index 408c3d6b..971b8a31 100644 --- a/jpwl/JPWL_j2k_to_image.dsp +++ b/jpwl/JPWL_j2k_to_image.dsp @@ -95,6 +95,10 @@ SOURCE=..\codec\compat\getopt.c # End Source File # Begin Source File +SOURCE=..\codec\index.c +# End Source File +# Begin Source File + SOURCE=..\codec\j2k_to_image.c # End Source File # End Group @@ -115,6 +119,10 @@ SOURCE=..\codec\compat\getopt.h # End Source File # Begin Source File +SOURCE=..\codec\index.h +# End Source File +# Begin Source File + SOURCE=.\jpwl.h # End Source File # Begin Source File diff --git a/jpwl/LibOpenJPEG_JPWL.dsp b/jpwl/LibOpenJPEG_JPWL.dsp index e4167374..d4d0bef9 100644 --- a/jpwl/LibOpenJPEG_JPWL.dsp +++ b/jpwl/LibOpenJPEG_JPWL.dsp @@ -41,7 +41,7 @@ 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 /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" /YX /FD /c # ADD BASE RSC /l 0x80c /d "NDEBUG" # ADD RSC /l 0x80c /d "NDEBUG" BSC32=bscmake.exe @@ -64,7 +64,7 @@ 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 /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" /YX /FD /GZ /c # ADD BASE RSC /l 0x80c /d "_DEBUG" # ADD RSC /l 0x80c /d "_DEBUG" BSC32=bscmake.exe diff --git a/jpwl/jpwl.c b/jpwl/jpwl.c index 5b424235..7351409f 100644 --- a/jpwl/jpwl.c +++ b/jpwl/jpwl.c @@ -1219,6 +1219,7 @@ void j2k_read_red(opj_j2k_t *j2k) { bool jpwl_check_tile(opj_j2k_t *j2k, opj_tcd_t *tcd, int tileno) { +#ifdef oerhgierhgvhreit4u /* we navigate through the tile and find possible invalid parameters: this saves a lot of crashes!!!!! @@ -1280,6 +1281,8 @@ bool jpwl_check_tile(opj_j2k_t *j2k, opj_tcd_t *tcd, int tileno) { } } +#endif + return true; } diff --git a/jpwl/jpwl_lib.c b/jpwl/jpwl_lib.c index 5ee53603..f6a165b3 100644 --- a/jpwl/jpwl_lib.c +++ b/jpwl/jpwl_lib.c @@ -661,7 +661,7 @@ bool jpwl_correct(opj_j2k_t *j2k) { j2k->state = J2K_STATE_MHSOC; /* cycle all over the markers */ - while ((unsigned int) cio_tell(cio) < cio->length) { + while (cio_tell(cio) < cio->length) { /* read the marker */ mark_pos = cio_tell(cio);