]> granicus.if.org Git - openjpeg/commitdiff
Added a basic saving capability to OPJViewer
authorGiuseppe Baruffa <gbaruffa@users.noreply.github.com>
Thu, 2 Aug 2007 12:45:28 +0000 (12:45 +0000)
committerGiuseppe Baruffa <gbaruffa@users.noreply.github.com>
Thu, 2 Aug 2007 12:45:28 +0000 (12:45 +0000)
ChangeLog
OPJViewer/OPJViewer.dsp
OPJViewer/Readme.txt
OPJViewer/buildupdate.bat
OPJViewer/source/OPJViewer.cpp
OPJViewer/source/OPJViewer.h
OPJViewer/source/build.h
OPJViewer/source/imagj2k.cpp
OPJViewer/source/imagj2k.h
OPJViewer/source/wxjp2parser.cpp

index 50efa40617efbbcaf642e4af9b5e9df0e322d082..60d3d48486a1778eb37822737eb11a3f23679f52 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@ What's New for OpenJPEG
 ! : changed
 + : added
 
+August 02, 2007
++ [GB] Added a basic saving capability to OPJViewer
+
 July 18, 2007
 ! [FOD] Updated libtiff library version to 3.8.2 (for WIN32)
 * [FOD] Updated BMP and PxM truncation when decoding J2K files with more than 8 bits
index b34985850fdda116a9e51c5e0e790d2e4c000597..899127698b8f51cde5b2ba8c6b7295cb25c87c72 100644 (file)
@@ -42,15 +42,15 @@ RSC=rc.exe
 # PROP Ignore_Export_Lib 0\r
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# 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 "OPJ_HTMLABOUT" /D "OPJ_MANYFORMATS" /D "OPJ_INICONFIG" /FR /FD /c\r
+# ADD CPP /nologo /G6 /MD /W3 /GX /O2 /I "c:\programmi\wxWidgets-2.8.0\lib\vc_lib\msw" /I "c:\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 "OPJ_HTMLABOUT" /D "OPJ_MANYFORMATS" /D "OPJ_INICONFIG" /FR /FD /c\r
 # ADD BASE RSC /l 0x410 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /i "d:\programmi\wxWidgets-2.8.0\include" /d "NDEBUG"\r
+# ADD RSC /l 0x409 /i "c:\programmi\wxWidgets-2.8.0\include" /d "NDEBUG"\r
 BSC32=bscmake.exe\r
 # ADD BASE BSC32 /nologo\r
 # ADD BSC32 /nologo\r
 LINK32=link.exe\r
 # 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 /machine:I386\r
-# 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 wxzlib.lib wxregex.lib wxpng.lib wxjpeg.lib wxbase28.lib wxmsw28_core.lib wxmsw28_html.lib wxmsw28_adv.lib wxmsw28_core.lib wxbase28.lib wxtiff.lib wxjpeg.lib wxpng.lib wxzlib.lib wxregex.lib wxexpat.lib LibOpenJPEG_JPWL.lib /nologo /subsystem:windows /machine:I386 /nodefaultlib:"libcmt.lib" /libpath:"d:\programmi\wxWidgets-2.8.0\lib\vc_lib" /libpath:"..\jpwl\Release" /IGNORE:4089\r
+# 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 wxzlib.lib wxregex.lib wxpng.lib wxjpeg.lib wxbase28.lib wxmsw28_core.lib wxmsw28_html.lib wxmsw28_adv.lib wxmsw28_core.lib wxbase28.lib wxtiff.lib wxjpeg.lib wxpng.lib wxzlib.lib wxregex.lib wxexpat.lib LibOpenJPEG_JPWL.lib /nologo /subsystem:windows /machine:I386 /nodefaultlib:"libcmt.lib" /libpath:"c:\programmi\wxWidgets-2.8.0\lib\vc_lib" /libpath:"..\jpwl\Release" /IGNORE:4089\r
 # SUBTRACT LINK32 /pdb:none\r
 # Begin Special Build Tool\r
 SOURCE="$(InputPath)"\r
@@ -72,15 +72,15 @@ PostBuild_Cmds=buildupdate.bat
 # PROP Ignore_Export_Lib 0\r
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# 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 "d:\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\r
+# 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\r
 # ADD BASE RSC /l 0x410 /d "_DEBUG"\r
-# ADD RSC /l 0x410 /i "d:\programmi\wxWidgets-2.8.0\include" /d "_DEBUG"\r
+# ADD RSC /l 0x410 /i "c:\programmi\wxWidgets-2.8.0\include" /d "_DEBUG"\r
 BSC32=bscmake.exe\r
 # ADD BASE BSC32 /nologo\r
 # ADD BSC32 /nologo\r
 LINK32=link.exe\r
 # 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\r
-# 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"\r
+# 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"\r
 # SUBTRACT LINK32 /pdb:none\r
 \r
 !ENDIF \r
@@ -131,6 +131,19 @@ SOURCE=.\source\about_htm.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\source\build.h\r
+\r
+!IF  "$(CFG)" == "OPJViewer - Win32 Release"\r
+\r
+# PROP Exclude_From_Build 1\r
+\r
+!ELSEIF  "$(CFG)" == "OPJViewer - Win32 Debug"\r
+\r
+!ENDIF \r
+\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\source\imagj2k.h\r
 # End Source File\r
 # Begin Source File\r
@@ -151,6 +164,50 @@ SOURCE=.\source\OPJViewer.h
 # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
 # Begin Source File\r
 \r
+SOURCE=.\source\wx\msw\blank.cur\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\bullseye.cur\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\cdrom.ico\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\computer.ico\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\cross.cur\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\drive.ico\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\file1.ico\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\floppy.ico\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\folder1.ico\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\folder2.ico\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\hand.cur\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\source\icon1.xpm\r
 # End Source File\r
 # Begin Source File\r
@@ -171,6 +228,10 @@ SOURCE=.\source\icon5.xpm
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\source\wx\msw\magnif1.cur\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\source\opj_logo.xpm\r
 # End Source File\r
 # Begin Source File\r
@@ -193,6 +254,38 @@ SOURCE=.\source\OPJViewer.rc
 \r
 SOURCE=.\source\OPJViewer16.xpm\r
 # End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\pbrush.cur\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\pencil.cur\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\pntleft.cur\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\pntright.cur\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\removble.ico\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\rightarr.cur\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\roller.cur\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\source\wx\msw\std.ico\r
+# End Source File\r
 # End Group\r
 # End Target\r
 # End Project\r
index 469ee15bf1898e225e29a6f4376c3abd5dbf9c19..9322b32c87761260ee9a996f0610b7efc54b8e2c 100644 (file)
@@ -1,13 +1,8 @@
-===============================================================================
-\r
+===============================================================================\r
        JPEG2000 Visualization Software - OPJViewer\r
 \r
-               Version 0.1 alpha\r
-
-===============================================================================
-
-
-\r
+               Version 0.3 alpha\r
+===============================================================================\r
 \r
 \r
 1. Scope\r
@@ -15,7 +10,7 @@
 \r
 This document describes the installation and use of the OPJViewer in the framework of OpenJPEG library.\r
 \r
-This implementation has been developed using the OpenJPEG library as decoding engine and wxWidgets 2.8.0 as GUI engine.\r
+This implementation has been developed using the OpenJPEG library as decoding engine and wxWidgets 2.8 as GUI engine.\r
 \r
 If you find some bugs or if you have problems using the viewer, please send an e-mail to jpwl@diei.unipg.it\r
 \r
@@ -27,7 +22,7 @@ There are two options available, at the moment:
 a) compile from source code\r
 b) download a precompiled binary.\r
 \r
-In order to use option a), it is mandatory to have compiled and built the LibOpenJPEG_JPWL library and the wxWidgets 2.8.0 framework (you have to download it from http://www.wxwidgets.org/ and compile the wx* libraries).\r
+In order to use option a), it is mandatory to have compiled and built the LibOpenJPEG_JPWL library and the wxWidgets 2.8 framework (you have to download it from http://www.wxwidgets.org/ and compile the wx* libraries).\r
 \r
 2.1. Compiling the source code in Windows\r
 -------------------------------------------\r
index 6ff0d42a8ca1bb9be473a92cceac9a173208796c..0aae1c1c15bed42eef450d19dd55d26c96afb682 100644 (file)
@@ -5,7 +5,7 @@ setLocal EnableDelayedExpansion
 for /f "tokens=2,* delims=^(^) " %%a in ('find /v "" ^< .\source\build.h') do (\r
 rem echo %%a\r
 set /A M = %%a + 1\r
-echo Build !M!\r
+echo Build %%a done^!\r
 echo wxT^("!M!"^) > buildtemp283746825t347\r
 )\r
 \r
index 1e1ef64703134a9bc66c45cba652d082c0a5d50c..8253f90bb63e6eed869f1abb865388f46b965e19 100644 (file)
@@ -235,6 +235,25 @@ bool OPJViewerApp::OnInit(void)
        OPJconfig->Read(wxT("peekerheight"), &m_peekerheight, (long) OPJ_PEEKER_HEIGHT);\r
        OPJconfig->Read(wxT("framewidth"), &m_framewidth, (long) OPJ_FRAME_WIDTH);\r
        OPJconfig->Read(wxT("frameheight"), &m_frameheight, (long) OPJ_FRAME_HEIGHT);\r
+\r
+       // load encoding engine parameters\r
+       OPJconfig->Read(wxT("subsampling"), &m_subsampling, (wxString) wxT("1,1"));\r
+       OPJconfig->Read(wxT("origin"), &m_origin, (wxString) wxT("0,0"));\r
+       OPJconfig->Read(wxT("rates"), &m_rates, (wxString) wxT("20,10,5"));\r
+       OPJconfig->Read(wxT("quality"), &m_quality, (wxString) wxT("30,35,40"));\r
+       OPJconfig->Read(wxT("irreversible"), &m_irreversible, (bool) false);    \r
+       OPJconfig->Read(wxT("resolutions"), &m_resolutions, (int) 6);   \r
+       OPJconfig->Read(wxT("cbsize"), &m_cbsize, (wxString) wxT("32,32"));\r
+       OPJconfig->Read(wxT("prsize"), &m_prsize, (wxString) wxT("[128,128],[128,128]"));\r
+       OPJconfig->Read(wxT("tsize"), &m_tsize, (wxString) wxT(""));\r
+       OPJconfig->Read(wxT("torigin"), &m_torigin, (wxString) wxT("0,0"));\r
+       OPJconfig->Read(wxT("enablesop"), &m_enablesop, (bool) false);  \r
+       OPJconfig->Read(wxT("enableeph"), &m_enableeph, (bool) false);  \r
+       OPJconfig->Read(wxT("enablecomm"), &m_enablecomm, (bool) true); \r
+       OPJconfig->Read(wxT("comment"), &m_comment, (wxString) wxT(""));\r
+       OPJconfig->Read(wxT("enableidx"), &m_enableidx, (bool) false);  \r
+       OPJconfig->Read(wxT("index"), &m_index, (wxString) wxT("index.txt"));\r
+\r
 #else\r
        // set decoding engine parameters\r
        m_enabledeco = true;\r
@@ -256,8 +275,43 @@ bool OPJViewerApp::OnInit(void)
        m_peekerheight = OPJ_PEEKER_HEIGHT;\r
        m_framewidth = OPJ_FRAME_WIDTH;\r
        m_frameheight = OPJ_FRAME_HEIGHT;\r
+\r
+       // set encoding engine parameters\r
+       m_subsampling = wxT("1,1");\r
+       m_origin = wxT("0,0");\r
+       m_rates = wxT("20,10,5");\r
+       m_quality = wxT("30,35,40");\r
+       m_irreversible = false;\r
+       m_resolutions = 6;\r
+       m_cbsize= wxT("32,32");\r
+       m_prsize= wxT("[128,128],[128,128]");\r
+       m_tsize = wxT("");\r
+       m_torigin = wxT("0,0");\r
+       m_enablesop = false;\r
+       m_enableeph = false;\r
+       m_enableidx = false;\r
+       m_index = wxT("index.txt");\r
+       m_enablecomm = true;\r
+       m_comment = wxT("");\r
+\r
 #endif // OPJ_INICONFIG\r
 \r
+       if (m_comment == wxT("")) {\r
+#if defined __WXMSW__\r
+               m_comment = wxT("Created by OPJViewer Win32 - OpenJPEG  version ");\r
+#elif defined __WXGTK__\r
+               m_comment = wxT("Created by OPJViewer Lin32 - OpenJPEG version ");\r
+#else\r
+               m_comment = wxT("Created by OPJViewer - OpenJPEG version ");\r
+#endif\r
+\r
+#ifdef USE_JPWL\r
+               m_comment += wxString::Format("%s with JPWL", opj_version());\r
+#else\r
+               m_comment += wxString::Format("%s", opj_version());\r
+#endif\r
+       }\r
+\r
        // Create the main frame window\r
   OPJFrame *frame = new OPJFrame(NULL, wxID_ANY, OPJ_APPLICATION_TITLEBAR,\r
                                          wxDefaultPosition, wxSize(wxGetApp().m_framewidth, wxGetApp().m_frameheight),\r
@@ -310,6 +364,24 @@ int OPJViewerApp::OnExit()
        OPJconfig->Write(wxT("peekerheight"), m_peekerheight);\r
        OPJconfig->Write(wxT("framewidth"), m_framewidth);\r
        OPJconfig->Write(wxT("frameheight"), m_frameheight);\r
+\r
+       OPJconfig->Write(wxT("subsampling"), m_subsampling);\r
+       OPJconfig->Write(wxT("origin"), m_origin);\r
+       OPJconfig->Write(wxT("rates"), m_rates);\r
+       OPJconfig->Write(wxT("quality"), m_quality);\r
+       OPJconfig->Write(wxT("irreversible"), m_irreversible);\r
+       OPJconfig->Write(wxT("resolutions"), m_resolutions);\r
+       OPJconfig->Write(wxT("cbsize"), m_cbsize);\r
+       OPJconfig->Write(wxT("prsize"), m_prsize);\r
+       OPJconfig->Write(wxT("tiles"), m_tsize);\r
+       OPJconfig->Write(wxT("torigin"), m_torigin);\r
+       OPJconfig->Write(wxT("enablesop"), m_enablesop);\r
+       OPJconfig->Write(wxT("enableeph"), m_enableeph);\r
+       OPJconfig->Write(wxT("enableidx"), m_enableidx);\r
+       OPJconfig->Write(wxT("index"), m_index);\r
+       OPJconfig->Write(wxT("enablecomm"), m_enablecomm);\r
+       OPJconfig->Write(wxT("comment"), m_comment);\r
+\r
 #endif // OPJ_INICONFIG\r
 \r
        return 1;\r
@@ -332,6 +404,8 @@ void OPJViewerApp::ShowCmdLine(const wxCmdLineParser& parser)
 BEGIN_EVENT_TABLE(OPJFrame, wxMDIParentFrame)\r
     EVT_MENU(OPJFRAME_HELPABOUT, OPJFrame::OnAbout)\r
     EVT_MENU(OPJFRAME_FILEOPEN, OPJFrame::OnFileOpen)\r
+    EVT_MENU(OPJFRAME_FILESAVEAS, OPJFrame::OnFileSaveAs)\r
+    EVT_MENU(OPJFRAME_MEMORYOPEN, OPJFrame::OnMemoryOpen)\r
     EVT_SIZE(OPJFrame::OnSize)\r
     EVT_MENU(OPJFRAME_FILEEXIT, OPJFrame::OnQuit)\r
     EVT_MENU(OPJFRAME_FILECLOSE, OPJFrame::OnClose)\r
@@ -361,9 +435,19 @@ OPJFrame::OPJFrame(wxWindow *parent, const wxWindowID id, const wxString& title,
        file_menu->Append(OPJFRAME_FILEOPEN, wxT("&Open\tCtrl+O"));\r
        file_menu->SetHelpString(OPJFRAME_FILEOPEN, wxT("Open one or more files"));\r
 \r
+       file_menu->Append(OPJFRAME_MEMORYOPEN, wxT("&Memory\tCtrl+M"));\r
+       file_menu->SetHelpString(OPJFRAME_MEMORYOPEN, wxT("Open a memory buffer"));\r
+\r
+       file_menu->Append(OPJFRAME_FILECLOSE, wxT("&Close\tCtrl+C"));\r
+       file_menu->SetHelpString(OPJFRAME_FILECLOSE, wxT("Close current image"));\r
+\r
+       file_menu->AppendSeparator();\r
+\r
        file_menu->Append(OPJFRAME_FILESAVEAS, wxT("&Save as\tCtrl+S"));\r
        file_menu->SetHelpString(OPJFRAME_FILESAVEAS, wxT("Save the current image"));\r
-       file_menu->Enable(OPJFRAME_FILESAVEAS, false);\r
+       //file_menu->Enable(OPJFRAME_FILESAVEAS, false);\r
+\r
+       file_menu->AppendSeparator();\r
 \r
        file_menu->Append(OPJFRAME_FILETOGGLEB, wxT("Toggle &browser\tCtrl+B"));\r
        file_menu->SetHelpString(OPJFRAME_FILETOGGLEB, wxT("Toggle the left browsing pane"));\r
@@ -374,8 +458,7 @@ OPJFrame::OPJFrame(wxWindow *parent, const wxWindowID id, const wxString& title,
        file_menu->Append(OPJFRAME_FILETOGGLET, wxT("Toggle &toolbar\tCtrl+T"));\r
        file_menu->SetHelpString(OPJFRAME_FILETOGGLET, wxT("Toggle the toolbar"));\r
 \r
-       file_menu->Append(OPJFRAME_FILECLOSE, wxT("&Close\tCtrl+C"));\r
-       file_menu->SetHelpString(OPJFRAME_FILECLOSE, wxT("Close current image"));\r
+       file_menu->AppendSeparator();\r
 \r
        file_menu->Append(OPJFRAME_FILEEXIT, wxT("&Exit\tCtrl+Q"));\r
        file_menu->SetHelpString(OPJFRAME_FILEEXIT, wxT("Quit this program"));\r
@@ -459,7 +542,7 @@ OPJFrame::OPJFrame(wxWindow *parent, const wxWindowID id, const wxString& title,
 \r
        tool_bar->AddTool(OPJFRAME_FILEOPEN, bmpOpen, wxT("Open"));\r
        tool_bar->AddTool(OPJFRAME_FILESAVEAS, bmpSaveAs, wxT("Save as "));\r
-       tool_bar->EnableTool(OPJFRAME_FILESAVEAS, false);\r
+       //tool_bar->EnableTool(OPJFRAME_FILESAVEAS, false);\r
        tool_bar->AddSeparator();\r
        tool_bar->AddTool(OPJFRAME_VIEWZOOM, bmpZoom, wxT("Zoom"));\r
        tool_bar->AddTool(OPJFRAME_VIEWFIT, bmpFit, wxT("Zoom to fit"));\r
@@ -614,6 +697,23 @@ void OPJFrame::OnSetsEnco(wxCommandEvent& event)
 \r
     if (dialog.ShowModal() == wxID_OK) {\r
 \r
+               // load settings\r
+               wxGetApp().m_subsampling = dialog.m_subsamplingCtrl->GetValue();\r
+               wxGetApp().m_origin = dialog.m_originCtrl->GetValue();\r
+               wxGetApp().m_rates = dialog.m_rateCtrl->GetValue();\r
+               wxGetApp().m_quality = dialog.m_qualityCtrl->GetValue();\r
+               wxGetApp().m_irreversible = dialog.m_irrevCheck->GetValue();\r
+               wxGetApp().m_resolutions = dialog.m_resolutionsCtrl->GetValue();\r
+               wxGetApp().m_cbsize = dialog.m_cbsizeCtrl->GetValue();\r
+               wxGetApp().m_prsize = dialog.m_prsizeCtrl->GetValue();\r
+               wxGetApp().m_tsize = dialog.m_tsizeCtrl->GetValue();\r
+               wxGetApp().m_torigin = dialog.m_toriginCtrl->GetValue();\r
+               wxGetApp().m_enablesop = dialog.m_sopCheck->GetValue();\r
+               wxGetApp().m_enableeph = dialog.m_ephCheck->GetValue();\r
+               wxGetApp().m_enableidx = dialog.m_enableidxCheck->GetValue();\r
+               wxGetApp().m_index = dialog.m_indexCtrl->GetValue();\r
+               wxGetApp().m_enablecomm = dialog.m_enablecommCheck->GetValue();\r
+               wxGetApp().m_comment = dialog.m_commentCtrl->GetValue();\r
        };\r
 }\r
 \r
@@ -914,6 +1014,41 @@ void OPJFrame::OnSashDrag(wxSashEvent& event)
 \r
 }\r
 \r
+// physically save the file\r
+void OPJFrame::SaveFile(wxArrayString paths, wxArrayString filenames)\r
+{\r
+       size_t count = paths.GetCount();\r
+       wxString msg, s;\r
+\r
+       if (wxFile::Exists(paths[0].c_str())) {\r
+\r
+               s.Printf(wxT("File %s already exists. Do you want to overwrite it?\n"), filenames[0].c_str());\r
+               wxMessageDialog dialog3(this, s, _T("File exists"), wxYES_NO);\r
+               if (dialog3.ShowModal() == wxID_NO)\r
+                       return;\r
+       }\r
+\r
+       /*s.Printf(_T("File %d: %s (%s)\n"), (int)0, paths[0].c_str(), filenames[0].c_str());\r
+       msg += s;\r
+\r
+       wxMessageDialog dialog2(this, msg, _T("Selected files"));\r
+       dialog2.ShowModal();*/\r
+\r
+       if (!GetActiveChild())\r
+               return;\r
+\r
+       ((OPJChildFrame *) GetActiveChild())->m_canvas->m_savename = paths[0];\r
+\r
+       OPJEncoThread *ethread = ((OPJChildFrame *) GetActiveChild())->m_canvas->CreateEncoThread();\r
+\r
+    if (ethread->Run() != wxTHREAD_NO_ERROR)\r
+        wxLogMessage(wxT("Can't start enco thread!"));\r
+    else\r
+               wxLogMessage(wxT("New enco thread started."));\r
+\r
+\r
+}\r
+\r
 // physically open the files\r
 void OPJFrame::OpenFiles(wxArrayString paths, wxArrayString filenames)\r
 {\r
@@ -994,6 +1129,48 @@ void OPJFrame::OnFileOpen(wxCommandEvent& WXUNUSED(event))
 \r
 }\r
 \r
+void OPJFrame::OnFileSaveAs(wxCommandEvent& WXUNUSED(event))\r
+{\r
+    wxString wildcards =\r
+#ifdef wxUSE_LIBOPENJPEG\r
+#ifdef __WXMOTIF__\r
+       wxT("JPEG 2000 codestream (*.j2k)|*.*j*2*");\r
+#else\r
+       wxT("JPEG 2000 codestream (*.j2k)|*.j2k")\r
+       wxT("|JPEG 2000 file format (*.jp2)|*.jp2");\r
+#endif\r
+#endif\r
+\r
+    wxFileDialog dialog(this, _T("Save image file"),\r
+                        wxEmptyString, wxEmptyString, wildcards,\r
+                        wxFD_SAVE);\r
+\r
+    if (dialog.ShowModal() == wxID_OK) {\r
+        wxArrayString paths, filenames;\r
+\r
+        dialog.GetPaths(paths);\r
+        dialog.GetFilenames(filenames);\r
+\r
+               SaveFile(paths, filenames);\r
+    }\r
+\r
+\r
+}\r
+\r
+void OPJFrame::OnMemoryOpen(wxCommandEvent& WXUNUSED(event))\r
+{\r
+       wxTextEntryDialog dialog(this, wxT("Memory HEX address range: start_address-stop_address"),\r
+                                                       wxT("Decode a memory buffer"),\r
+                                                       wxT("0x-0x"),\r
+                                                       wxOK | wxCANCEL | wxCENTRE,\r
+                                                       wxDefaultPosition);\r
+\r
+       if (dialog.ShowModal() == wxID_OK) {\r
+\r
+       }\r
+\r
+}\r
+\r
 BEGIN_EVENT_TABLE(OPJCanvas, wxScrolledWindow)\r
     EVT_MOUSE_EVENTS(OPJCanvas::OnEvent)\r
 END_EVENT_TABLE()\r
@@ -1036,6 +1213,19 @@ OPJDecoThread *OPJCanvas::CreateDecoThread(void)
     return dthread;\r
 }\r
 \r
+OPJEncoThread *OPJCanvas::CreateEncoThread(void)\r
+{\r
+    OPJEncoThread *ethread = new OPJEncoThread(this);\r
+\r
+    if (ethread->Create() != wxTHREAD_NO_ERROR)\r
+               wxLogError(wxT("Can't create enco thread!"));\r
+\r
+    wxCriticalSectionLocker enter(wxGetApp().m_enco_critsect);\r
+    wxGetApp().m_enco_threads.Add(ethread);\r
+\r
+    return ethread;\r
+}\r
+\r
 #define activeoverlay 0\r
 // Define the repainting behaviour\r
 void OPJCanvas::OnDraw(wxDC& dc)\r
@@ -2055,6 +2245,95 @@ void OPJMarkerData::ShowInfo(wxTreeCtrl *tree)
                  unsigned(tree->GetChildrenCount(GetId(), false)));\r
 }\r
 \r
+/////////////////////////////////////////////////////////////////////\r
+// Encoding thread class\r
+/////////////////////////////////////////////////////////////////////\r
+\r
+OPJEncoThread::OPJEncoThread(OPJCanvas *canvas)\r
+        : wxThread()\r
+{\r
+    m_count = 0;\r
+    m_canvas = canvas;\r
+}\r
+\r
+void OPJEncoThread::WriteText(const wxString& text)\r
+{\r
+    wxString msg;\r
+\r
+    // before doing any GUI calls we must ensure that this thread is the only\r
+    // one doing it!\r
+\r
+#ifndef __WXGTK__ \r
+    wxMutexGuiEnter();\r
+#endif // __WXGTK__\r
+\r
+    msg << text;\r
+    m_canvas->WriteText(msg);\r
+\r
+#ifndef __WXGTK__ \r
+    wxMutexGuiLeave();\r
+#endif // __WXGTK__\r
+}\r
+\r
+void OPJEncoThread::OnExit()\r
+{\r
+    wxCriticalSectionLocker locker(wxGetApp().m_enco_critsect);\r
+\r
+    wxArrayThread& ethreads = wxGetApp().m_enco_threads;\r
+    ethreads.Remove(this);\r
+\r
+    if (ethreads.IsEmpty() )\r
+    {\r
+        // signal the main thread that there are no more threads left if it is\r
+        // waiting for us\r
+        if (wxGetApp().m_enco_waitingUntilAllDone) {\r
+            wxGetApp().m_enco_waitingUntilAllDone = false;\r
+            wxGetApp().m_enco_semAllDone.Post();\r
+        }\r
+    }\r
+}\r
+\r
+void *OPJEncoThread::Entry()\r
+{\r
+    wxString text;\r
+\r
+       srand(GetId());\r
+       //int m_countnum = rand() % 9;\r
+    //text.Printf(wxT("Deco thread 0x%lx started (priority = %u, time = %d)."),\r
+    //            GetId(), GetPriority(), m_countnum);\r
+    text.Printf(wxT("Enco thread %d started"), m_canvas->m_childframe->m_winnumber);\r
+    WriteText(text);\r
+\r
+       // set handler properties\r
+       wxJ2KHandler *j2kkkhandler = (wxJ2KHandler *) wxImage::FindHandler( wxBITMAP_TYPE_J2K);\r
+       j2kkkhandler->m_subsampling = wxGetApp().m_subsampling;\r
+       j2kkkhandler->m_origin = wxGetApp().m_origin;\r
+       j2kkkhandler->m_rates = wxGetApp().m_rates;\r
+       j2kkkhandler->m_quality = wxGetApp().m_quality;\r
+       j2kkkhandler->m_irreversible = wxGetApp().m_irreversible;\r
+       j2kkkhandler->m_resolutions = wxGetApp().m_resolutions;\r
+       j2kkkhandler->m_cbsize = wxGetApp().m_cbsize;\r
+       j2kkkhandler->m_prsize = wxGetApp().m_prsize;\r
+       j2kkkhandler->m_tsize = wxGetApp().m_tsize;\r
+       j2kkkhandler->m_torigin = wxGetApp().m_torigin;\r
+       j2kkkhandler->m_enablesop = wxGetApp().m_enablesop;\r
+       j2kkkhandler->m_enableeph = wxGetApp().m_enableeph;\r
+       j2kkkhandler->m_enableidx = wxGetApp().m_enableidx;\r
+       j2kkkhandler->m_index = m_canvas->m_savename.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxGetApp().m_index;\r
+       j2kkkhandler->m_enablecomm = wxGetApp().m_enablecomm;\r
+       j2kkkhandler->m_comment = wxGetApp().m_comment;\r
+\r
+       // save the file\r
+       if (!m_canvas->m_image100.SaveFile(m_canvas->m_savename.GetFullPath(), wxBITMAP_TYPE_J2K)) {\r
+               WriteText(wxT("Can't save image"));\r
+               return NULL;\r
+       }\r
+\r
+    text.Printf(wxT("Enco thread %d finished"), m_canvas->m_childframe->m_winnumber);\r
+    WriteText(text);\r
+    return NULL;\r
+}\r
+\r
 /////////////////////////////////////////////////////////////////////\r
 // Decoding thread class\r
 /////////////////////////////////////////////////////////////////////\r
@@ -2698,6 +2977,8 @@ IMPLEMENT_CLASS(OPJEncoderDialog, wxPropertySheetDialog)
 BEGIN_EVENT_TABLE(OPJEncoderDialog, wxPropertySheetDialog)\r
 #ifdef USE_JPWL\r
        EVT_CHECKBOX(OPJENCO_ENABLEJPWL, OPJEncoderDialog::OnEnableJPWL)\r
+       EVT_CHECKBOX(OPJENCO_ENABLECOMM, OPJEncoderDialog::OnEnableComm)\r
+       EVT_CHECKBOX(OPJENCO_ENABLEINDEX, OPJEncoderDialog::OnEnableIdx)\r
 #endif // USE_JPWL\r
 END_EVENT_TABLE()\r
 \r
@@ -2714,27 +2995,12 @@ OPJEncoderDialog::OPJEncoderDialog(wxWindow* win, int dialogType)
 \r
        m_settingsNotebook = GetBookCtrl();\r
 \r
-       wxPanel* mainSettings = CreateMainSettingsPage(m_settingsNotebook);\r
        wxPanel* jpeg2000Settings = CreatePart1SettingsPage(m_settingsNotebook);\r
-/*     if (!wxGetApp().m_enabledeco)\r
-               jpeg2000Settings->Enable(false);\r
-       wxPanel* mjpeg2000Settings = CreatePart3SettingsPage(m_settingsNotebook);\r
-       if (!wxGetApp().m_enabledeco)\r
-               mjpeg2000Settings->Enable(false);\r
-#ifdef USE_JPWL\r
-       wxPanel* jpwlSettings = CreatePart11SettingsPage(m_settingsNotebook);\r
-       if (!wxGetApp().m_enabledeco)\r
-               jpwlSettings->Enable(false);\r
-#endif // USE_JPWL\r
-*/\r
+       wxPanel* mainSettings = CreateMainSettingsPage(m_settingsNotebook);\r
 \r
-       m_settingsNotebook->AddPage(mainSettings, wxT("General"), false);\r
        m_settingsNotebook->AddPage(jpeg2000Settings, wxT("JPEG 2000"), false);\r
-/*     m_settingsNotebook->AddPage(mjpeg2000Settings, wxT("MJPEG 2000"), false);\r
-#ifdef USE_JPWL\r
-       m_settingsNotebook->AddPage(jpwlSettings, wxT("JPWL"), false);\r
-#endif // USE_JPWL\r
-*/\r
+       m_settingsNotebook->AddPage(mainSettings, wxT("General"), false);\r
+\r
        LayoutDialog();\r
 }\r
 \r
@@ -2772,7 +3038,7 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
        //topSizer->AddSpacer(5);\r
 \r
                // sub top sizer\r
-               wxFlexGridSizer *subtopSizer = new wxFlexGridSizer(2, 3, 3);\r
+               wxFlexGridSizer *subtopSizer = new wxFlexGridSizer(4, 3, 3);\r
 \r
                        // image settings, column\r
                        wxStaticBox* imageBox = new wxStaticBox(panel, wxID_ANY, wxT("Image"));\r
@@ -2790,8 +3056,8 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                                // add the value control\r
                                subsSizer->Add(\r
-                                       /*m_rateCtrl = */new wxTextCtrl(panel, OPJENCO_SUBSAMPLING,\r
-                                                               wxT("1,1"),\r
+                                       m_subsamplingCtrl = new wxTextCtrl(panel, OPJENCO_SUBSAMPLING,\r
+                                                               wxGetApp().m_subsampling,\r
                                                                wxDefaultPosition, wxSize(120, wxDefaultCoord),\r
                                                                wxTE_LEFT),\r
                                        0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3);\r
@@ -2810,8 +3076,8 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                                // add the value control\r
                                imorigSizer->Add(\r
-                                       /*m_rateCtrl = */new wxTextCtrl(panel, OPJENCO_IMORIG,\r
-                                                               wxT("0,0"),\r
+                                       m_originCtrl = new wxTextCtrl(panel, OPJENCO_IMORIG,\r
+                                                               wxGetApp().m_origin,\r
                                                                wxDefaultPosition, wxSize(120, wxDefaultCoord),\r
                                                                wxTE_LEFT),\r
                                        0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3);\r
@@ -2821,7 +3087,7 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
                subtopSizer->Add(imageSizer, 0, wxGROW | wxALL, 3);\r
 \r
                        // layer settings, column\r
-                       wxStaticBox* layerBox = new wxStaticBox(panel, wxID_ANY, wxT("Layers"));\r
+                       wxStaticBox* layerBox = new wxStaticBox(panel, wxID_ANY, wxT("Layers/compression"));\r
                        wxBoxSizer* layerSizer = new wxStaticBoxSizer(layerBox, wxVERTICAL);\r
 \r
                                // rate factor sizer, row\r
@@ -2836,8 +3102,8 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                                // add the value control\r
                                rateSizer->Add(\r
-                                       /*m_rateCtrl = */new wxTextCtrl(panel, OPJENCO_RATEFACTOR,\r
-                                                               wxT("20,10,5"),\r
+                                       m_rateCtrl = new wxTextCtrl(panel, OPJENCO_RATEFACTOR,\r
+                                                               wxGetApp().m_rates,\r
                                                                wxDefaultPosition, wxSize(120, wxDefaultCoord),\r
                                                                wxTE_LEFT),\r
                                        0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3);\r
@@ -2856,8 +3122,8 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                                // add the value control\r
                                qualitySizer->Add(\r
-                                       /*m_rateCtrl = */new wxTextCtrl(panel, OPJENCO_QUALITYFACTOR,\r
-                                                               wxT("30,35,40"),\r
+                                       m_qualityCtrl = new wxTextCtrl(panel, OPJENCO_QUALITYFACTOR,\r
+                                                               wxGetApp().m_quality,\r
                                                                wxDefaultPosition, wxSize(120, wxDefaultCoord),\r
                                                                wxTE_LEFT),\r
                                        0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3);\r
@@ -2867,15 +3133,15 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
                subtopSizer->Add(layerSizer, 0, wxGROW | wxALL, 3);\r
 \r
                        // wavelet settings, column\r
-                       wxStaticBox* waveletBox = new wxStaticBox(panel, wxID_ANY, wxT("Transform"));\r
+                       wxStaticBox* waveletBox = new wxStaticBox(panel, wxID_ANY, wxT("Wavelet transform"));\r
                        wxBoxSizer* waveletSizer = new wxStaticBoxSizer(waveletBox, wxVERTICAL);\r
 \r
                        // irreversible check box\r
                        waveletSizer->Add(\r
-                               /*m_enabledecoCheck =*/ new wxCheckBox(panel, OPJENCO_ENABLEIRREV, wxT("Irreversible"),\r
+                               m_irrevCheck = new wxCheckBox(panel, OPJENCO_ENABLEIRREV, wxT("Irreversible"),\r
                                wxDefaultPosition, wxDefaultSize),\r
                                0, wxGROW | wxALL, 3);\r
-                       /*m_enabledecoCheck->SetValue(wxGetApp().m_enabledeco);*/\r
+                       m_irrevCheck->SetValue(wxGetApp().m_irreversible);\r
 \r
                                // resolution number sizer, row\r
                                wxBoxSizer* resnumSizer = new wxBoxSizer(wxHORIZONTAL);\r
@@ -2889,8 +3155,8 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                                // add the value control\r
                                resnumSizer->Add(\r
-                                       /*m_layerCtrl =*/ new wxSpinCtrl(panel, OPJENCO_RESNUMBER,\r
-                                                               wxT("6"),\r
+                                       m_resolutionsCtrl = new wxSpinCtrl(panel, OPJENCO_RESNUMBER,\r
+                                                               wxString::Format("%d", wxGetApp().m_resolutions),\r
                                                                wxDefaultPosition, wxSize(80, wxDefaultCoord),\r
                                                                wxSP_ARROW_KEYS,\r
                                                                0, 256, 6),\r
@@ -2898,6 +3164,12 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                        waveletSizer->Add(resnumSizer, 0, wxGROW | wxALL, 3);\r
 \r
+               subtopSizer->Add(waveletSizer, 0, wxGROW | wxALL, 3);\r
+\r
+                       // codestream settings, column\r
+                       wxStaticBox* codestreamBox = new wxStaticBox(panel, wxID_ANY, wxT("Codestream"));\r
+                       wxBoxSizer* codestreamSizer = new wxStaticBoxSizer(codestreamBox, wxVERTICAL);\r
+\r
                                // codeblock sizer, row\r
                                wxBoxSizer* codeblockSizer = new wxBoxSizer(wxHORIZONTAL);\r
 \r
@@ -2910,13 +3182,13 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                                // add the value control\r
                                codeblockSizer->Add(\r
-                                       /*m_rateCtrl = */new wxTextCtrl(panel, OPJENCO_CODEBLOCKSIZE,\r
-                                                               wxT("32,32"),\r
+                                       m_cbsizeCtrl = new wxTextCtrl(panel, OPJENCO_CODEBLOCKSIZE,\r
+                                                               wxGetApp().m_cbsize,\r
                                                                wxDefaultPosition, wxSize(120, wxDefaultCoord),\r
                                                                wxTE_LEFT),\r
                                        0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3);\r
 \r
-                       waveletSizer->Add(codeblockSizer, 0, wxGROW | wxALL, 3);\r
+                       codestreamSizer->Add(codeblockSizer, 0, wxGROW | wxALL, 3);\r
 \r
                                // precinct sizer, row\r
                                wxBoxSizer* precinctSizer = new wxBoxSizer(wxHORIZONTAL);\r
@@ -2930,15 +3202,15 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                                // add the value control\r
                                precinctSizer->Add(\r
-                                       /*m_rateCtrl = */new wxTextCtrl(panel, OPJENCO_PRECINCTSIZE,\r
-                                                               wxT("[128,128],[128,128]"),\r
+                                       m_prsizeCtrl = new wxTextCtrl(panel, OPJENCO_PRECINCTSIZE,\r
+                                                               wxGetApp().m_prsize,\r
                                                                wxDefaultPosition, wxSize(120, wxDefaultCoord),\r
                                                                wxTE_LEFT),\r
                                        0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3);\r
 \r
-                       waveletSizer->Add(precinctSizer, 0, wxGROW | wxALL, 3);\r
+                       codestreamSizer->Add(precinctSizer, 0, wxGROW | wxALL, 3);\r
 \r
-               subtopSizer->Add(waveletSizer, 0, wxGROW | wxALL, 3);\r
+               subtopSizer->Add(codestreamSizer, 0, wxGROW | wxALL, 3);\r
 \r
                        // tile settings, column\r
                        wxStaticBox* tileBox = new wxStaticBox(panel, wxID_ANY, wxT("Tiles"));\r
@@ -2956,8 +3228,8 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                                // add the value control\r
                                tilesizeSizer->Add(\r
-                                       /*m_rateCtrl = */new wxTextCtrl(panel, OPJENCO_TILESIZE,\r
-                                                               wxT(""),\r
+                                       m_tsizeCtrl = new wxTextCtrl(panel, OPJENCO_TILESIZE,\r
+                                                               wxGetApp().m_tsize,\r
                                                                wxDefaultPosition, wxSize(120, wxDefaultCoord),\r
                                                                wxTE_LEFT),\r
                                        0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3);\r
@@ -2976,8 +3248,8 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                                // add the value control\r
                                tilorigSizer->Add(\r
-                                       /*m_rateCtrl = */new wxTextCtrl(panel, OPJENCO_TILORIG,\r
-                                                               wxT("0,0"),\r
+                                       m_toriginCtrl = new wxTextCtrl(panel, OPJENCO_TILORIG,\r
+                                                               wxGetApp().m_torigin,\r
                                                                wxDefaultPosition, wxSize(120, wxDefaultCoord),\r
                                                                wxTE_LEFT),\r
                                        0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3);\r
@@ -2989,7 +3261,7 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
                        // progression settings, column\r
                        wxString choices[] = {wxT("LRCP"), wxT("RLCP"), wxT("RPCL"), wxT("PCRL"), wxT("CPRL")};\r
                        wxRadioBox *progressionBox = new wxRadioBox(panel, OPJENCO_PROGRESSION,\r
-                               wxT("Progression"),\r
+                               wxT("Progression order"),\r
                                wxDefaultPosition, wxDefaultSize,\r
                                WXSIZEOF(choices),\r
                                choices,\r
@@ -3000,7 +3272,7 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
                subtopSizer->Add(progressionBox, 0, wxGROW | wxALL, 3);\r
 \r
                        // resilience settings, column\r
-                       wxStaticBox* resilBox = new wxStaticBox(panel, wxID_ANY, wxT("Resilience"));\r
+                       wxStaticBox* resilBox = new wxStaticBox(panel, wxID_ANY, wxT("Error resilience"));\r
                        wxBoxSizer* resilSizer = new wxStaticBoxSizer(resilBox, wxVERTICAL);\r
 \r
                                // resil2 sizer, row\r
@@ -3008,17 +3280,17 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                                // SOP check box\r
                                resil2Sizer->Add(\r
-                                       /*m_enabledecoCheck =*/ new wxCheckBox(panel, OPJENCO_ENABLESOP, wxT("SOP"),\r
-                                       wxDefaultPosition, wxDefaultSize),\r
-                                       0, wxGROW | wxALL, 3);\r
-                               /*m_enabledecoCheck->SetValue(wxGetApp().m_enabledeco);*/\r
+                                       m_sopCheck = new wxCheckBox(panel, OPJENCO_ENABLESOP, wxT("SOP"),\r
+                                               wxDefaultPosition, wxDefaultSize),\r
+                                               0, wxGROW | wxALL, 3);\r
+                               m_sopCheck->SetValue(wxGetApp().m_enablesop);\r
 \r
                                // EPH check box\r
                                resil2Sizer->Add(\r
-                                       /*m_enabledecoCheck =*/ new wxCheckBox(panel, OPJENCO_ENABLEEPH, wxT("EPH"),\r
-                                       wxDefaultPosition, wxDefaultSize),\r
-                                       0, wxGROW | wxALL, 3);\r
-                               /*m_enabledecoCheck->SetValue(wxGetApp().m_enabledeco);*/\r
+                                       m_ephCheck = new wxCheckBox(panel, OPJENCO_ENABLEEPH, wxT("EPH"),\r
+                                               wxDefaultPosition, wxDefaultSize),\r
+                                               0, wxGROW | wxALL, 3);\r
+                               m_ephCheck->SetValue(wxGetApp().m_enableeph);\r
 \r
                        resilSizer->Add(resil2Sizer, 0, wxGROW | wxALL, 3);\r
 \r
@@ -3075,7 +3347,7 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
                subtopSizer->Add(resilSizer, 0, wxGROW | wxALL, 3);\r
 \r
                        // ROI settings, column\r
-                       wxStaticBox* roiBox = new wxStaticBox(panel, wxID_ANY, wxT("ROI"));\r
+                       wxStaticBox* roiBox = new wxStaticBox(panel, wxID_ANY, wxT("Region Of Interest"));\r
                        wxBoxSizer* roiSizer = new wxStaticBoxSizer(roiBox, wxVERTICAL);\r
 \r
                                // component number sizer, row\r
@@ -3128,10 +3400,10 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                        // indexing check box\r
                        indexSizer->Add(\r
-                               /*m_enabledecoCheck =*/ new wxCheckBox(panel, OPJENCO_ENABLEINDEX, wxT("Enabled"),\r
+                               m_enableidxCheck = new wxCheckBox(panel, OPJENCO_ENABLEINDEX, wxT("Enabled"),\r
                                wxDefaultPosition, wxDefaultSize),\r
                                0, wxGROW | wxALL, 3);\r
-                       /*m_enabledecoCheck->SetValue(wxGetApp().m_enabledeco);*/\r
+                       m_enableidxCheck->SetValue(wxGetApp().m_enableidx);\r
 \r
                                // index file sizer, row\r
                                wxBoxSizer* indexnameSizer = new wxBoxSizer(wxHORIZONTAL);\r
@@ -3145,44 +3417,42 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
 \r
                                // add the value control\r
                                indexnameSizer->Add(\r
-                                       /*m_rateCtrl = */new wxTextCtrl(panel, OPJENCO_INDEXNAME,\r
-                                                               wxT(""),\r
+                                       m_indexCtrl = new wxTextCtrl(panel, OPJENCO_INDEXNAME,\r
+                                                               wxGetApp().m_index,\r
                                                                wxDefaultPosition, wxSize(120, wxDefaultCoord),\r
                                                                wxTE_LEFT),\r
                                        0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3);\r
+                               m_indexCtrl->Enable(wxGetApp().m_enableidx);\r
 \r
                        indexSizer->Add(indexnameSizer, 0, wxGROW | wxALL, 3);\r
 \r
                subtopSizer->Add(indexSizer, 0, wxGROW | wxALL, 3);\r
 \r
-/*                     // component settings, column\r
-                       wxStaticBox* compoBox = new wxStaticBox(panel, wxID_ANY, wxT("Components"));\r
-                       wxBoxSizer* compoSizer = new wxStaticBoxSizer(compoBox, wxVERTICAL);\r
-\r
-                               // quality layers sizer, row\r
-                               wxBoxSizer* numcompsSizer = new wxBoxSizer(wxHORIZONTAL);\r
+                       // Comment settings, column\r
+                       wxStaticBox* commentBox = new wxStaticBox(panel, wxID_ANY, wxT("Comment"));\r
+                       wxBoxSizer* commentSizer = new wxStaticBoxSizer(commentBox, wxVERTICAL);\r
 \r
-                               // add some text\r
-                               numcompsSizer->Add(new wxStaticText(panel, wxID_ANY, wxT("&Component displayed:")),\r
-                                                               0, wxALL | wxALIGN_CENTER_VERTICAL, 5);\r
+                       // commenting check box\r
+                       commentSizer->Add(\r
+                               m_enablecommCheck = new wxCheckBox(panel, OPJENCO_ENABLECOMM, wxT("Enabled"),\r
+                               wxDefaultPosition, wxDefaultSize),\r
+                               0, wxGROW | wxALL, 3);\r
+                       m_enablecommCheck->SetValue(wxGetApp().m_enablecomm);\r
 \r
-                               // add some horizontal space\r
-                               numcompsSizer->Add(5, 5, 1, wxALL, 0);\r
+                       // add some horizontal space\r
+                       commentSizer->Add(3, 3, 1, wxALL, 0);\r
 \r
-                               // add the value control\r
-                               numcompsSizer->Add(\r
-                                       m_numcompsCtrl = new wxSpinCtrl(panel, OPJDECO_NUMCOMPS,\r
-                                                               wxString::Format(wxT("%d"), wxGetApp().m_components),\r
-                                                               wxDefaultPosition, wxSize(80, wxDefaultCoord),\r
-                                                               wxSP_ARROW_KEYS,\r
-                                                               0, 100000, wxGetApp().m_components),\r
-                                       0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);\r
-                               m_numcompsCtrl->Enable(true);\r
+                       // add the value control\r
+                       commentSizer->Add(\r
+                               m_commentCtrl = new wxTextCtrl(panel, OPJENCO_COMMENTTEXT,\r
+                                                       wxGetApp().m_comment,\r
+                                                       wxDefaultPosition, wxSize(wxDefaultCoord, 60),\r
+                                                       wxTE_LEFT | wxTE_MULTILINE),\r
+                               0, wxGROW | wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 3);\r
+                       m_commentCtrl->Enable(wxGetApp().m_enablecomm);\r
 \r
-                       compoSizer->Add(numcompsSizer, 0, wxGROW | wxALL, 5);\r
+               subtopSizer->Add(commentSizer, 0, wxGROW | wxALL, 3);\r
 \r
-               subtopSizer->Add(compoSizer, 0, wxGROW | wxALL, 5);\r
-*/\r
        topSizer->Add(subtopSizer, 1, wxGROW | wxALIGN_CENTRE | wxALL, 5);\r
 \r
        // assign top and fit it\r
@@ -3192,6 +3462,29 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
     return panel;\r
 }\r
 \r
+void OPJEncoderDialog::OnEnableComm(wxCommandEvent& event)\r
+{\r
+       if (event.IsChecked()) {\r
+               wxLogMessage(wxT("Comment enabled"));\r
+               m_commentCtrl->Enable(true);\r
+       } else {\r
+               wxLogMessage(wxT("Comment disabled"));\r
+               m_commentCtrl->Enable(false);\r
+       }\r
+\r
+}\r
+\r
+void OPJEncoderDialog::OnEnableIdx(wxCommandEvent& event)\r
+{\r
+       if (event.IsChecked()) {\r
+               wxLogMessage(wxT("Index enabled"));\r
+               m_indexCtrl->Enable(true);\r
+       } else {\r
+               wxLogMessage(wxT("Index disabled"));\r
+               m_indexCtrl->Enable(false);\r
+       }\r
+}\r
+\r
 #ifdef USE_JPWL\r
 void OPJEncoderDialog::OnEnableJPWL(wxCommandEvent& event)\r
 {\r
index 8904c9ee9c60fc6073f2907b473bafd1ebdd60e6..0c29af4d84e22f087aa90596a66de07b2846e625 100644 (file)
@@ -151,6 +151,7 @@ typedef unsigned long long int8byte;
 #define OPJ_CANVAS_COLOUR *wxWHITE\r
 \r
 class OPJDecoThread;\r
+class OPJEncoThread;\r
 class OPJParseThread;\r
 WX_DEFINE_ARRAY_PTR(wxThread *, wxArrayThread);\r
 class OPJChildFrame;\r
@@ -175,17 +176,17 @@ class OPJViewerApp: public wxApp
 \r
                // all the threads currently alive - as soon as the thread terminates, it's\r
                // removed from the array\r
-               wxArrayThread m_deco_threads, m_parse_threads;\r
+               wxArrayThread m_deco_threads, m_parse_threads, m_enco_threads;\r
 \r
                // crit section protects access to all of the arrays below\r
-               wxCriticalSection m_deco_critsect, m_parse_critsect;\r
+               wxCriticalSection m_deco_critsect, m_parse_critsect, m_enco_critsect;\r
 \r
                // semaphore used to wait for the threads to exit, see OPJFrame::OnQuit()\r
-               wxSemaphore m_deco_semAllDone, m_parse_semAllDone;\r
+               wxSemaphore m_deco_semAllDone, m_parse_semAllDone, m_enco_semAllDone;\r
 \r
                // the last exiting thread should post to m_semAllDone if this is true\r
                // (protected by the same m_critsect)\r
-               bool m_deco_waitingUntilAllDone, m_parse_waitingUntilAllDone;\r
+               bool m_deco_waitingUntilAllDone, m_parse_waitingUntilAllDone, m_enco_waitingUntilAllDone;\r
 \r
                // the list of all filenames written in the command line\r
                wxArrayString m_filelist;\r
@@ -202,6 +203,12 @@ class OPJViewerApp: public wxApp
                int m_framewidth, m_frameheight;\r
 #endif // USE_JPWL\r
 \r
+               // encoding engine parameters\r
+               wxString m_subsampling, m_origin, m_rates, m_comment, m_index, m_quality;\r
+               wxString m_cbsize, m_prsize, m_tsize, m_torigin;\r
+               bool m_enablecomm, m_enableidx, m_irreversible, m_enablesop, m_enableeph;\r
+               int m_resolutions;\r
+\r
                // some layout settings\r
                bool m_showtoolbar, m_showbrowser, m_showpeeker;\r
                int m_browserwidth, m_peekerheight;\r
@@ -240,10 +247,11 @@ class OPJCanvas: public wxScrolledWindow
 #endif //__WXGTK__\r
                }\r
                OPJDecoThread *CreateDecoThread(void);\r
+               OPJEncoThread *CreateEncoThread(void);\r
                OPJChildFrame *m_childframe;\r
 \r
                wxBitmap  m_image, m_image100;\r
-               wxFileName m_fname;\r
+               wxFileName m_fname, m_savename;\r
                long m_zooml;\r
 \r
        DECLARE_EVENT_TABLE()\r
@@ -383,6 +391,8 @@ class OPJFrame: public wxMDIParentFrame
        void OnSize(wxSizeEvent& WXUNUSED(event));\r
     void OnAbout(wxCommandEvent& WXUNUSED(event));\r
     void OnFileOpen(wxCommandEvent& WXUNUSED(event));\r
+    void OnFileSaveAs(wxCommandEvent& WXUNUSED(event));\r
+    void OnMemoryOpen(wxCommandEvent& WXUNUSED(event));\r
     void OnQuit(wxCommandEvent& WXUNUSED(event));\r
     void OnClose(wxCommandEvent& WXUNUSED(event));\r
     void OnZoom(wxCommandEvent& WXUNUSED(event));\r
@@ -398,6 +408,7 @@ class OPJFrame: public wxMDIParentFrame
        void OnSetsDeco(wxCommandEvent& event);\r
        void OnSashDrag(wxSashEvent& event);\r
        void OpenFiles(wxArrayString paths, wxArrayString filenames);\r
+       void SaveFile(wxArrayString paths, wxArrayString filenames);\r
        void OnNotebook(wxNotebookEvent& event);\r
        void Rescale(int scale, OPJChildFrame *child);\r
 \r
@@ -453,6 +464,7 @@ enum {
        OPJFRAME_FILEEXIT = wxID_EXIT,\r
        OPJFRAME_HELPABOUT = wxID_ABOUT,\r
        OPJFRAME_FILEOPEN,\r
+       OPJFRAME_MEMORYOPEN,\r
        OPJFRAME_FILESAVEAS,\r
        OPJFRAME_FILETOGGLEB,\r
        OPJFRAME_FILETOGGLEP,\r
@@ -524,6 +536,26 @@ enum
        LEFT_NOTEBOOK_ID\r
 };\r
 \r
+class OPJEncoThread : public wxThread\r
+{\r
+public:\r
+    OPJEncoThread(OPJCanvas *canvas);\r
+\r
+    // thread execution starts here\r
+    virtual void *Entry();\r
+\r
+    // called when the thread exits - whether it terminates normally or is\r
+    // stopped with Delete() (but not when it is Kill()ed!)\r
+    virtual void OnExit();\r
+\r
+    // write something to the text control\r
+    void WriteText(const wxString& text);\r
+\r
+public:\r
+    unsigned m_count;\r
+    OPJCanvas *m_canvas;\r
+};\r
+\r
 class OPJDecoThread : public wxThread\r
 {\r
 public:\r
@@ -603,10 +635,17 @@ public:
 /*    wxPanel* CreatePart3SettingsPage(wxWindow* parent);*/\r
 #ifdef USE_JPWL\r
        void OnEnableJPWL(wxCommandEvent& event);\r
+       void OnEnableComm(wxCommandEvent& event);\r
+       void OnEnableIdx(wxCommandEvent& event);\r
 /*    wxPanel* CreatePart11SettingsPage(wxWindow* parent);\r
        wxCheckBox *m_enablejpwlCheck;*/\r
 #endif // USE_JPWL\r
 \r
+       wxTextCtrl *m_subsamplingCtrl, *m_originCtrl, *m_rateCtrl, *m_commentCtrl;\r
+       wxTextCtrl *m_indexCtrl, *m_qualityCtrl, *m_cbsizeCtrl, *m_prsizeCtrl;\r
+       wxTextCtrl *m_tsizeCtrl, *m_toriginCtrl;\r
+       wxCheckBox *m_enablecommCheck, *m_enableidxCheck, *m_irrevCheck, *m_sopCheck, *m_ephCheck;\r
+       wxSpinCtrl *m_resolutionsCtrl;\r
 \r
 protected:\r
 \r
@@ -634,7 +673,9 @@ protected:
                OPJENCO_TILORIG,\r
                OPJENCO_ENABLEIRREV,\r
                OPJENCO_ENABLEINDEX,\r
-               OPJENCO_INDEXNAME\r
+               OPJENCO_INDEXNAME,\r
+               OPJENCO_ENABLECOMM,\r
+               OPJENCO_COMMENTTEXT\r
     };\r
 \r
 DECLARE_EVENT_TABLE()\r
index 42c7d4dbee9077c80aeb3b80a7e2674a4d4d0228..fce4f83bfc08f8ee2a2c2653fdfaa817b97f2857 100644 (file)
@@ -1 +1 @@
-wxT("59") \r
+wxT("200") \r
index 7897ee3ce10a97eb0609921f2f3699221eb3bf4c..6dc57fac0ace84c11beb2114063e4fc7b5bff134 100644 (file)
@@ -231,17 +231,275 @@ bool wxJ2KHandler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
 }\r
 \r
 // save the j2k codestream\r
-bool wxJ2KHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose )\r
+bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbose )\r
 {\r
+       opj_cparameters_t parameters;   /* compression parameters */\r
+       opj_event_mgr_t event_mgr;              /* event manager */\r
+       opj_image_t *oimage = NULL;\r
+       opj_image_cmptparm_t *cmptparm; \r
+       opj_cio_t *cio = NULL;\r
+       int codestream_length;\r
+       bool bSuccess;\r
+       int i;\r
+\r
+       /*\r
+       configure the event callbacks (not required)\r
+       setting of each callback is optionnal\r
+       */\r
+       memset(&event_mgr, 0, sizeof(opj_event_mgr_t));\r
+       event_mgr.error_handler = j2k_error_callback;\r
+       event_mgr.warning_handler = j2k_warning_callback;\r
+       event_mgr.info_handler = j2k_info_callback;\r
+\r
+       /* set encoding parameters to default values */\r
+       opj_set_default_encoder_parameters(&parameters);\r
+\r
+       /* load parameters */\r
+\r
+       /* subsampling */\r
+       if (sscanf(m_subsampling.c_str(), wxT("%d,%d"), &(parameters.subsampling_dx), &(parameters.subsampling_dy)) != 2) {\r
+               wxLogError(wxT("Wrong sub-sampling encoder setting: dx,dy"));\r
+               return false;\r
+       }\r
+\r
+       /* compression rates */\r
+       if (m_rates != wxT("")) {\r
+               char *s1 = (char *) m_rates.c_str();\r
+               wxLogMessage("rates %s", s1);\r
+               while (sscanf(s1, "%f", &(parameters.tcp_rates[parameters.tcp_numlayers])) == 1) {\r
+                       parameters.tcp_numlayers++;\r
+                       while (*s1 && *s1 != ',') {\r
+                               s1++;\r
+                       }\r
+                       if (!*s1)\r
+                               break;\r
+                       s1++;\r
+               }\r
+               wxLogMessage("%d layers", parameters.tcp_numlayers);\r
+               parameters.cp_disto_alloc = 1;\r
+       }\r
+\r
+       /* image quality, dB */\r
+       if (m_rates == wxT("")) {\r
+               char *s2 = (char *) m_quality.c_str();\r
+               wxLogMessage("qualities %s", s2);\r
+               while (sscanf(s2, "%f", &parameters.tcp_distoratio[parameters.tcp_numlayers]) == 1) {\r
+                       parameters.tcp_numlayers++;\r
+                       while (*s2 && *s2 != ',') {\r
+                               s2++;\r
+                       }\r
+                       if (!*s2)\r
+                               break;\r
+                       s2++;\r
+               }\r
+               wxLogMessage("%d layers", parameters.tcp_numlayers);\r
+               parameters.cp_fixed_quality = 1;\r
+       }\r
+\r
+       /* image origin */\r
+       if (sscanf(m_origin.c_str(), "%d,%d", &parameters.image_offset_x0, &parameters.image_offset_y0) != 2) {\r
+               wxLogError(wxT("bad coordinate of the image origin: x0,y0"));\r
+               return false;\r
+       }\r
+                               \r
+       /* Create comment for codestream */\r
+       if(m_enablecomm) {\r
+               parameters.cp_comment = (char *) malloc(strlen(m_comment.c_str()) + 1);\r
+               if(parameters.cp_comment) {\r
+                       strcpy(parameters.cp_comment, m_comment.c_str());\r
+               }\r
+       } else {\r
+               parameters.cp_comment = NULL;\r
+       }\r
+\r
+       /* indexing file */\r
+       if (m_enableidx) {\r
+               strncpy(parameters.index, m_index.c_str(), m_index.Len());\r
+               wxLogMessage("index file is %s", parameters.index);\r
+               parameters.index_on = 1;\r
+       } else {\r
+               parameters.index_on = 0;\r
+       }\r
+\r
+       /* if no rate entered, lossless by default */\r
+       if (parameters.tcp_numlayers == 0) {\r
+               parameters.tcp_rates[0] = 0;    /* MOD antonin : losslessbug */\r
+               parameters.tcp_numlayers++;\r
+               parameters.cp_disto_alloc = 1;\r
+       }\r
+\r
+       /* irreversible transform */\r
+       parameters.irreversible = (m_irreversible == true) ? 1 : 0;\r
+\r
+       /* resolutions */\r
+       parameters.numresolution = m_resolutions;\r
+\r
+       /* codeblocks size */\r
+       if (m_cbsize != wxT("")) {\r
+               int cblockw_init = 0, cblockh_init = 0;\r
+               sscanf(m_cbsize.c_str(), "%d,%d", &cblockw_init, &cblockh_init);\r
+               if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024 || cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {\r
+                       wxLogError("!! Size of code_block error !! Restrictions:\n  width*height<=4096\n  4<=width,height<= 1024");\r
+                       return false;\r
+               }\r
+               parameters.cblockw_init = cblockw_init;\r
+               parameters.cblockh_init = cblockh_init;\r
+       }\r
+\r
+       /* precincts size */\r
+       if (m_prsize != wxT("")) {\r
+               char sep;\r
+               int res_spec = 0;\r
+               char *s = (char *) m_prsize.c_str();\r
+               do {\r
+                       sep = 0;\r
+                       sscanf(s, "[%d,%d]%c", &parameters.prcw_init[res_spec], &parameters.prch_init[res_spec], &sep);\r
+                       parameters.csty |= 0x01;\r
+                       res_spec++;\r
+                       s = strpbrk(s, "]") + 2;\r
+               } while (sep == ',');\r
+               parameters.res_spec = res_spec;\r
+       }\r
+\r
+       /* tiles */\r
+       if (m_tsize != wxT("")) {\r
+               sscanf(m_tsize.c_str(), "%d,%d", &parameters.cp_tdx, &parameters.cp_tdy);\r
+               parameters.tile_size_on = true;\r
+       }\r
+\r
+       /* tile origin */\r
+       if (sscanf(m_torigin.c_str(), "%d,%d", &parameters.cp_tx0, &parameters.cp_ty0) != 2) {\r
+               wxLogError("tile offset setting error: X0,Y0");\r
+               return false;\r
+       }\r
+\r
+       /* use SOP */\r
+       if (m_enablesop)\r
+               parameters.csty |= 0x02;\r
+\r
+       /* use EPH */\r
+       if (m_enableeph)\r
+               parameters.csty |= 0x04;\r
+\r
+\r
+\r
+       /* compression settings */\r
+       //parameters.tcp_numlayers = 1;\r
+       //parameters.tcp_rates[0] = 10.0;\r
+       //parameters.cp_disto_alloc = 1;\r
+       //parameters.irreversible = 1;\r
+       parameters.tcp_mct = 1;\r
+\r
+       /* convert wx image into opj image */\r
+       cmptparm = (opj_image_cmptparm_t*) malloc(3 * sizeof(opj_image_cmptparm_t));\r
+\r
+       /* initialize opj image components */   \r
+       memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t));\r
+       for(i = 0; i < 3; i++) {                \r
+               cmptparm[i].prec = 8;\r
+               cmptparm[i].bpp = 8;\r
+               cmptparm[i].sgnd = false;\r
+               cmptparm[i].dx = parameters.subsampling_dx;\r
+               cmptparm[i].dy = parameters.subsampling_dy;\r
+               cmptparm[i].w = wimage->GetWidth();\r
+               cmptparm[i].h = wimage->GetHeight();\r
+       }\r
+\r
+       /* create the image */\r
+       oimage = opj_image_create(3, &cmptparm[0], CLRSPC_SRGB);\r
+       if(!oimage) {\r
+               if (cmptparm)\r
+                       free(cmptparm);\r
+               return false;\r
+       }\r
+\r
+       /* set image offset and reference grid */\r
+       oimage->x0 = parameters.image_offset_x0;\r
+       oimage->y0 = parameters.image_offset_y0;\r
+       oimage->x1 = parameters.image_offset_x0 + (wimage->GetWidth() - 1) * 1 + 1;\r
+       oimage->y1 = parameters.image_offset_y0 + (wimage->GetHeight() - 1) * 1 + 1;\r
+\r
+       /* load image data */\r
+       unsigned char *value = wimage->GetData(); \r
+       int area = wimage->GetWidth() * wimage->GetHeight();\r
+       for (i = 0; i < area; i++) {\r
+                       oimage->comps[0].data[i] = *(value++);\r
+                       oimage->comps[1].data[i] = *(value++);\r
+                       oimage->comps[2].data[i] = *(value++);\r
+       }\r
+\r
+       /* get a J2K compressor handle */\r
+       opj_cinfo_t* cinfo = opj_create_compress(CODEC_J2K);\r
+\r
+       /* catch events using our callbacks and give a local context */\r
+       opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);\r
+\r
+       /* setup the encoder parameters using the current image and user parameters */\r
+       opj_setup_encoder(cinfo, &parameters, oimage);\r
+\r
+       /* open a byte stream for writing */\r
+       /* allocate memory for all tiles */\r
+       cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);\r
+\r
+       /* encode the image */\r
+       bSuccess = opj_encode(cinfo, cio, oimage, parameters.index);\r
+       if (!bSuccess) {\r
+\r
+               opj_cio_close(cio);\r
+               opj_destroy_compress(cinfo);\r
+               opj_image_destroy(oimage);\r
+               if (cmptparm)\r
+                       free(cmptparm);\r
+               if(parameters.cp_comment)\r
+                       free(parameters.cp_comment);\r
+               if(parameters.cp_matrice)\r
+                       free(parameters.cp_matrice);\r
+\r
 #ifndef __WXGTK__ \r
     wxMutexGuiEnter();\r
 #endif /* __WXGTK__ */\r
-    wxLogError(wxT("J2K: Couldn't save image -> not implemented."));\r
+\r
+               wxLogError(wxT("failed to encode image"));\r
+\r
+#ifndef __WXGTK__ \r
+    wxMutexGuiLeave();\r
+#endif /* __WXGTK__ */\r
+\r
+               return false;\r
+       }\r
+       codestream_length = cio_tell(cio);\r
+       wxLogMessage(wxT("Codestream: %d bytes"), codestream_length);\r
+\r
+       /* write the buffer to stream */\r
+       stream.Write(cio->buffer, codestream_length);\r
+\r
+       /* close and free the byte stream */\r
+       opj_cio_close(cio);\r
+\r
+       /* free remaining compression structures */\r
+       opj_destroy_compress(cinfo);\r
+\r
+       /* free image data */\r
+       opj_image_destroy(oimage);\r
+\r
+       if (cmptparm)\r
+               free(cmptparm);\r
+       if(parameters.cp_comment)\r
+               free(parameters.cp_comment);\r
+       if(parameters.cp_matrice)\r
+               free(parameters.cp_matrice);\r
+\r
+#ifndef __WXGTK__ \r
+    wxMutexGuiEnter();\r
+#endif /* __WXGTK__ */\r
+\r
+    wxLogMessage(wxT("J2K: Image encoded!"));\r
+\r
 #ifndef __WXGTK__ \r
     wxMutexGuiLeave();\r
 #endif /* __WXGTK__ */\r
 \r
-    return false;\r
+    return true;\r
 }\r
 \r
 #ifdef __VISUALC__\r
index b262ec6bdec533adfcc13c4e7d50edecc0087358..9b6f63a91b41e511c0e282ce494cf1db0937a136 100644 (file)
@@ -67,6 +67,7 @@ public:
         m_type = wxBITMAP_TYPE_J2K;\r
         m_mime = wxT("image/j2k");\r
 \r
+               /* decoding */\r
                m_reducefactor = 0;\r
                m_qualitylayers = 0;\r
                m_components = 0;\r
@@ -75,15 +76,75 @@ public:
                m_expcomps = JPWL_EXPECTED_COMPONENTS;\r
                m_maxtiles = JPWL_MAXIMUM_TILES;\r
 #endif // USE_JPWL\r
+\r
+               /* encoding */\r
+               m_subsampling = wxT("1,1");\r
+               m_origin = wxT("0,0");\r
+               m_rates = wxT("20,10,5");\r
+               m_quality = wxT("30,35,40");\r
+               m_irreversible = false;\r
+               m_resolutions = 6;\r
+               m_cbsize = wxT("32,32");\r
+               m_prsize = wxT("[128,128],[128,128]");\r
+               m_tsize = wxT("");\r
+               m_torigin = wxT("0,0");\r
+               /*m_progression\r
+               m_resilience*/\r
+               m_enablesop = false;\r
+               m_enableeph = false;\r
+               /*m_roicompo\r
+               m_roiup\r
+               m_indexfname*/\r
+               m_enableidx = false;\r
+               m_index = wxT("index.txt");\r
+               m_enablecomm = true;\r
+\r
+#if defined __WXMSW__\r
+               m_comment = wxT("Created by OPJViewer Win32 - OpenJPEG  version ");\r
+#elif defined __WXGTK__\r
+               m_comment = wxT("Created by OPJViewer Lin32 - OpenJPEG version ");\r
+#else\r
+               m_comment = wxT("Created by OPJViewer - OpenJPEG version ");\r
+#endif\r
+\r
+#ifdef USE_JPWL\r
+               m_comment += wxString::Format("%s with JPWL", opj_version());\r
+#else\r
+               m_comment += wxString::Format("%s", opj_version());\r
+#endif\r
+\r
     }\r
 \r
-               // decoding engine parameters\r
-               int m_reducefactor, m_qualitylayers, m_components;\r
+       // decoding engine parameters\r
+       int m_reducefactor, m_qualitylayers, m_components;\r
 #ifdef USE_JPWL\r
-               bool m_enablejpwl;\r
-               int m_expcomps, m_maxtiles;\r
+       bool m_enablejpwl;\r
+       int m_expcomps, m_maxtiles;\r
 #endif // USE_JPWL\r
 \r
+       // encoding engine parameters\r
+       wxString m_subsampling;\r
+       wxString m_origin;\r
+       wxString m_rates;\r
+       wxString m_quality;\r
+       bool m_irreversible;\r
+       int m_resolutions;\r
+       wxString m_cbsize;\r
+       wxString m_prsize;\r
+       wxString m_tsize;\r
+       wxString m_torigin;\r
+       /*m_progression\r
+       m_resilience*/\r
+       bool m_enablesop;\r
+       bool m_enableeph;\r
+       /*m_roicompo\r
+       m_roiup\r
+       m_indexfname*/\r
+       bool m_enableidx;\r
+       wxString m_index;\r
+       bool m_enablecomm;\r
+       wxString m_comment;\r
+\r
 #if wxUSE_STREAMS\r
     virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );\r
     virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );\r
index afacd394d4477e39e1f4191e4b067e07a17142e1..6e89390a1bae8615ff8eee357b6ecf7c28c00433 100644 (file)
@@ -60,6 +60,8 @@ typedef enum {
                        TRAK_BOX,\r
                        TKHD_BOX,\r
                        MDIA_BOX,\r
+                       MDHD_BOX,\r
+                       HDLR_BOX,\r
                        MINF_BOX,\r
                        VMHD_BOX,\r
                        STBL_BOX,\r
@@ -102,6 +104,8 @@ struct boxdef {
 #define TRAK_SIGN           "trak"\r
 #define TKHD_SIGN           "tkhd"\r
 #define MDIA_SIGN           "mdia"\r
+#define MDHD_SIGN           "mdhd"\r
+#define HDLR_SIGN           "hdlr"\r
 #define MINF_SIGN           "minf"\r
 #define VMHD_SIGN           "vmhd"\r
 #define STBL_SIGN           "stbl"\r
@@ -231,6 +235,22 @@ struct boxdef j22box[] =
 /* req */      {1, 1, 1},\r
 /* ins */      TRAK_BOX},\r
 \r
+/* sign */     {MDHD_SIGN,\r
+/* short */    "Media Header box",\r
+/* long */     "The media header declares overall information which is media-independent, and relevant to characteristics "\r
+                       "of the media in a track",\r
+/* sbox */     0,\r
+/* req */      {1, 1, 1},\r
+/* ins */      MDIA_BOX},\r
+\r
+/* sign */     {HDLR_SIGN,\r
+/* short */    "Handler Reference box",\r
+/* long */     "This box within a Media Box declares the process by which the media-data in the track may be presented, "\r
+                       "and thus, the nature of the media in a track",\r
+/* sbox */     0,\r
+/* req */      {1, 1, 1},\r
+/* ins */      MDIA_BOX},\r
+\r
 /* sign */     {MINF_SIGN,\r
 /* short */    "Media Information box",\r
 /* long */     "This box contains all the objects which declare characteristic information of the media in the track",\r
@@ -829,7 +849,114 @@ int OPJParseThread::box_handler_function(int boxtype, wxFile *fileid, wxFileOffs
                };\r
                break;\r
 \r
+               /* Media Header box */\r
+       case (MDHD_BOX): {\r
+                       unsigned long int version;\r
+                       unsigned short int language;\r
+                       fileid->Read(&version, sizeof(unsigned long int));\r
+                       version = BYTE_SWAP4(version);\r
+                       if (version == 0) {\r
+                               unsigned long int creation_time, modification_time, timescale, duration;\r
+                               fileid->Read(&creation_time, sizeof(unsigned long int));\r
+                               creation_time = BYTE_SWAP4(creation_time);\r
+                               fileid->Read(&modification_time, sizeof(unsigned long int));\r
+                               modification_time = BYTE_SWAP4(modification_time);\r
+                               fileid->Read(&timescale, sizeof(unsigned long int));\r
+                               timescale = BYTE_SWAP4(timescale);\r
+                               fileid->Read(&duration, sizeof(unsigned long int));\r
+                               duration = BYTE_SWAP4(duration);\r
+                               const long unix_time = creation_time - 2082844800L;\r
+                               wxTreeItemId currid = m_tree->AppendItem(parentid,\r
+                                       wxString::Format(wxT("Creation time: %u (%.24s)"), creation_time, ctime(&unix_time)),\r
+                                       m_tree->TreeCtrlIcon_File, m_tree->TreeCtrlIcon_File + 1,\r
+                                       new OPJMarkerData(wxT("INFO"))\r
+                                       );\r
+                               const long unix_time1 = modification_time - 2082844800L;\r
+                               currid = m_tree->AppendItem(parentid,\r
+                                       wxString::Format(wxT("Modification time: %u (%.24s)"), modification_time, ctime(&unix_time1)),\r
+                                       m_tree->TreeCtrlIcon_File, m_tree->TreeCtrlIcon_File + 1,\r
+                                       new OPJMarkerData(wxT("INFO"))\r
+                                       );\r
+                               currid = m_tree->AppendItem(parentid,\r
+                                       wxString::Format(wxT("Timescale: %u (%.6fs)"), timescale, 1.0 / (float) timescale),\r
+                                       m_tree->TreeCtrlIcon_File, m_tree->TreeCtrlIcon_File + 1,\r
+                                       new OPJMarkerData(wxT("INFO"))\r
+                                       );\r
+                               currid = m_tree->AppendItem(parentid,\r
+                                       wxString::Format(wxT("Duration: %u (%.3fs)"), duration, (float) duration / (float) timescale),\r
+                                       m_tree->TreeCtrlIcon_File, m_tree->TreeCtrlIcon_File + 1,\r
+                                       new OPJMarkerData(wxT("INFO"))\r
+                                       );\r
+                       } else {\r
+                               int8byte creation_time, modification_time, duration;\r
+                               unsigned long int timescale;\r
+                               fileid->Read(&creation_time, sizeof(int8byte));\r
+                               creation_time = BYTE_SWAP8(creation_time);\r
+                               fileid->Read(&modification_time, sizeof(int8byte));\r
+                               modification_time = BYTE_SWAP8(modification_time);\r
+                               fileid->Read(&timescale, sizeof(unsigned long int));\r
+                               timescale = BYTE_SWAP4(timescale);\r
+                               fileid->Read(&duration, sizeof(int8byte));\r
+                               duration = BYTE_SWAP8(duration);\r
+                               wxTreeItemId currid = m_tree->AppendItem(parentid,\r
+                                       wxString::Format(wxT("Creation time: %u"), creation_time),\r
+                                       m_tree->TreeCtrlIcon_File, m_tree->TreeCtrlIcon_File + 1,\r
+                                       new OPJMarkerData(wxT("INFO"))\r
+                                       );\r
+                               currid = m_tree->AppendItem(parentid,\r
+                                       wxString::Format(wxT("Modification time: %u"), modification_time),\r
+                                       m_tree->TreeCtrlIcon_File, m_tree->TreeCtrlIcon_File + 1,\r
+                                       new OPJMarkerData(wxT("INFO"))\r
+                                       );\r
+                               currid = m_tree->AppendItem(parentid,\r
+                                       wxString::Format(wxT("Timescale: %u"), timescale),\r
+                                       m_tree->TreeCtrlIcon_File, m_tree->TreeCtrlIcon_File + 1,\r
+                                       new OPJMarkerData(wxT("INFO"))\r
+                                       );\r
+                               currid = m_tree->AppendItem(parentid,\r
+                                       wxString::Format(wxT("Duration: %u"), duration),\r
+                                       m_tree->TreeCtrlIcon_File, m_tree->TreeCtrlIcon_File + 1,\r
+                                       new OPJMarkerData(wxT("INFO"))\r
+                                       );\r
+                       }\r
+                       fileid->Read(&language, sizeof(unsigned short int));\r
+\r
+                       wxTreeItemId currid = m_tree->AppendItem(parentid,\r
+                               wxString::Format(wxT("Language: %d (%c%c%c)"), language & 0xEFFF,\r
+                               0x60 + (char) ((language >> 10) & 0x001F), 0x60 + (char) ((language >> 5) & 0x001F), 0x60 + (char) ((language >> 0) & 0x001F)),\r
+                               m_tree->TreeCtrlIcon_File, m_tree->TreeCtrlIcon_File + 1,\r
+                               new OPJMarkerData(wxT("INFO"))\r
+                               );\r
+               };\r
+               break;\r
                \r
+               /* Media Handler box */\r
+       case (HDLR_BOX): {\r
+                       unsigned long int version, predefined, temp[3];\r
+                       char handler[4], name[256];\r
+                       int namelen = wxMin(256, (filelimit - filepoint - 24));\r
+                       fileid->Read(&version, sizeof(unsigned long int));\r
+                       version = BYTE_SWAP4(version);\r
+                       fileid->Read(&predefined, sizeof(unsigned long int));\r
+                       fileid->Read(handler, 4 * sizeof(char));\r
+                       fileid->Read(&temp, 3 * sizeof(unsigned long int));\r
+                       fileid->Read(name, namelen * sizeof(char));\r
+\r
+                       wxTreeItemId currid = m_tree->AppendItem(parentid,\r
+                               wxString::Format(wxT("Handler: %.4s"), handler),\r
+                               m_tree->TreeCtrlIcon_File, m_tree->TreeCtrlIcon_File + 1,\r
+                               new OPJMarkerData(wxT("INFO"))\r
+                               );\r
+                                        \r
+                       currid = m_tree->AppendItem(parentid,\r
+                               wxString::Format(wxT("Name: %.255s"), name),\r
+                               m_tree->TreeCtrlIcon_File, m_tree->TreeCtrlIcon_File + 1,\r
+                               new OPJMarkerData(wxT("INFO"))\r
+                               );\r
+                                                                        \r
+               }\r
+               break;\r
+\r
        /* not yet implemented */\r
        default:\r
                break;\r