Adapted the JPWL and OPJViewer code to new interface; fixed a samll bug in JPWL which created large EPBs even when null protection was specified

This commit is contained in:
Giuseppe Baruffa 2007-09-07 23:16:31 +00:00
parent 3816e0edf4
commit d70a0415b9
11 changed files with 220 additions and 125 deletions

View File

@ -5,6 +5,9 @@ What's New for OpenJPEG
! : changed ! : changed
+ : added + : added
September 8, 2007
* [GB] Adapted the JPWL and OPJViewer code to new interface; fixed a samll bug in JPWL which created large EPBs even when null protection was specified
September 7, 2007 September 7, 2007
+ [FOD] Indexes can now be generated when decoding J2K codestreams. + [FOD] Indexes can now be generated when decoding J2K codestreams.
* [Mathieu Malaterre] Upon failure, properly return error code (!=0). * [Mathieu Malaterre] Upon failure, properly return error code (!=0).

View File

@ -42,15 +42,15 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0 # PROP Ignore_Export_Lib 0
# PROP Target_Dir "" # PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # 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 "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 "USE_JPSEC" /D "OPJ_HTMLABOUT" /D "OPJ_MANYFORMATS" /D "OPJ_INICONFIG" /FR /FD /c
# ADD BASE RSC /l 0x410 /d "NDEBUG" # ADD BASE RSC /l 0x410 /d "NDEBUG"
# ADD RSC /l 0x409 /i "d:\programmi\wxWidgets-2.8.0\include" /d "NDEBUG" # ADD RSC /l 0x409 /i "c:\programmi\wxWidgets-2.8.0\include" /d "NDEBUG"
BSC32=bscmake.exe BSC32=bscmake.exe
# ADD BASE BSC32 /nologo # ADD BASE BSC32 /nologo
# ADD BSC32 /nologo # ADD BSC32 /nologo
LINK32=link.exe 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 /machine:I386 # 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
# 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 # 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
# SUBTRACT LINK32 /pdb:none # SUBTRACT LINK32 /pdb:none
# Begin Special Build Tool # Begin Special Build Tool
SOURCE="$(InputPath)" SOURCE="$(InputPath)"
@ -72,15 +72,15 @@ PostBuild_Cmds=buildupdate.bat
# PROP Ignore_Export_Lib 0 # PROP Ignore_Export_Lib 0
# PROP Target_Dir "" # 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 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 "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 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 BASE RSC /l 0x410 /d "_DEBUG" # ADD BASE RSC /l 0x410 /d "_DEBUG"
# ADD RSC /l 0x410 /i "c:\programmi\wxWidgets-2.8.0\include" /d "_DEBUG" # ADD RSC /l 0x410 /i "d:\programmi\wxWidgets-2.8.0\include" /d "_DEBUG"
BSC32=bscmake.exe BSC32=bscmake.exe
# ADD BASE BSC32 /nologo # ADD BASE BSC32 /nologo
# ADD BSC32 /nologo # ADD BSC32 /nologo
LINK32=link.exe 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 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:"c:\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:"d:\programmi\wxWidgets-2.8.0\lib\vc_lib" /libpath:"..\jpwl\Debug"
# SUBTRACT LINK32 /pdb:none # SUBTRACT LINK32 /pdb:none
!ENDIF !ENDIF

View File

@ -2995,11 +2995,19 @@ OPJEncoderDialog::OPJEncoderDialog(wxWindow* win, int dialogType)
m_settingsNotebook = GetBookCtrl(); m_settingsNotebook = GetBookCtrl();
wxPanel* jpeg2000Settings = CreatePart1SettingsPage(m_settingsNotebook); wxPanel* jpeg2000_1Settings = CreatePart1_1SettingsPage(m_settingsNotebook);
wxPanel* jpeg2000_2Settings = CreatePart1_2SettingsPage(m_settingsNotebook);
wxPanel* mainSettings = CreateMainSettingsPage(m_settingsNotebook); wxPanel* mainSettings = CreateMainSettingsPage(m_settingsNotebook);
#ifdef USE_JPWL
wxPanel* jpwlSettings = CreatePart11SettingsPage(m_settingsNotebook);
#endif // USE_JPWL
m_settingsNotebook->AddPage(jpeg2000Settings, wxT("JPEG 2000"), false); 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); m_settingsNotebook->AddPage(mainSettings, wxT("General"), false);
#ifdef USE_JPWL
m_settingsNotebook->AddPage(jpwlSettings, wxT("JPWL"), false);
#endif // USE_JPWL
LayoutDialog(); LayoutDialog();
} }
@ -3027,7 +3035,28 @@ wxPanel* OPJEncoderDialog::CreateMainSettingsPage(wxWindow* parent)
return panel; return panel;
} }
wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent) #ifdef USE_JPWL
wxPanel* OPJEncoderDialog::CreatePart11SettingsPage(wxWindow* parent)
{
wxPanel* panel = new wxPanel(parent, wxID_ANY);
// top sizer
wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
// sub top sizer
wxBoxSizer *subtopSizer = new wxBoxSizer(wxVERTICAL);
topSizer->Add(subtopSizer, 1, wxGROW | wxALIGN_CENTRE | wxALL, 5);
// assign top and fit it
panel->SetSizer(topSizer);
topSizer->Fit(panel);
return panel;
}
#endif // USE_JPWL
wxPanel* OPJEncoderDialog::CreatePart1_1SettingsPage(wxWindow* parent)
{ {
wxPanel* panel = new wxPanel(parent, wxID_ANY); wxPanel* panel = new wxPanel(parent, wxID_ANY);
@ -3038,7 +3067,7 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
//topSizer->AddSpacer(5); //topSizer->AddSpacer(5);
// sub top sizer // sub top sizer
wxFlexGridSizer *subtopSizer = new wxFlexGridSizer(4, 3, 3); wxFlexGridSizer *subtopSizer = new wxFlexGridSizer(2, 3, 3);
// image settings, column // image settings, column
wxStaticBox* imageBox = new wxStaticBox(panel, wxID_ANY, wxT("Image")); wxStaticBox* imageBox = new wxStaticBox(panel, wxID_ANY, wxT("Image"));
@ -3258,19 +3287,42 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
subtopSizer->Add(tileSizer, 0, wxGROW | wxALL, 3); subtopSizer->Add(tileSizer, 0, wxGROW | wxALL, 3);
// progression settings, column // progression and profile settings, column
wxString choices[] = {wxT("LRCP"), wxT("RLCP"), wxT("RPCL"), wxT("PCRL"), wxT("CPRL")}; wxString choices[] = {wxT("LRCP"), wxT("RLCP"), wxT("RPCL"), wxT("PCRL"), wxT("CPRL"),
wxT("DCI2K24"), wxT("DCI2K48"), wxT("DCI4K")};
wxRadioBox *progressionBox = new wxRadioBox(panel, OPJENCO_PROGRESSION, wxRadioBox *progressionBox = new wxRadioBox(panel, OPJENCO_PROGRESSION,
wxT("Progression order"), wxT("Progression order/profile"),
wxDefaultPosition, wxDefaultSize, wxDefaultPosition, wxDefaultSize,
WXSIZEOF(choices), WXSIZEOF(choices),
choices, choices,
4, 3,
wxRA_SPECIFY_COLS); wxRA_SPECIFY_COLS);
progressionBox->SetSelection(0); progressionBox->SetSelection(0);
subtopSizer->Add(progressionBox, 0, wxGROW | wxALL, 3); subtopSizer->Add(progressionBox, 0, wxGROW | wxALL, 3);
topSizer->Add(subtopSizer, 1, wxGROW | wxALIGN_CENTRE | wxALL, 5);
// assign top and fit it
panel->SetSizer(topSizer);
topSizer->Fit(panel);
return panel;
}
wxPanel* OPJEncoderDialog::CreatePart1_2SettingsPage(wxWindow* parent)
{
wxPanel* panel = new wxPanel(parent, wxID_ANY);
// top sizer
wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
// add some space
//topSizer->AddSpacer(5);
// sub top sizer
wxFlexGridSizer *subtopSizer = new wxFlexGridSizer(2, 3, 3);
// resilience settings, column // resilience settings, column
wxStaticBox* resilBox = new wxStaticBox(panel, wxID_ANY, wxT("Error resilience")); wxStaticBox* resilBox = new wxStaticBox(panel, wxID_ANY, wxT("Error resilience"));
wxBoxSizer* resilSizer = new wxStaticBoxSizer(resilBox, wxVERTICAL); wxBoxSizer* resilSizer = new wxStaticBoxSizer(resilBox, wxVERTICAL);
@ -3394,7 +3446,7 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
subtopSizer->Add(roiSizer, 0, wxGROW | wxALL, 3); subtopSizer->Add(roiSizer, 0, wxGROW | wxALL, 3);
// ROI settings, column // Index file settings, column
wxStaticBox* indexBox = new wxStaticBox(panel, wxID_ANY, wxT("Indexing")); wxStaticBox* indexBox = new wxStaticBox(panel, wxID_ANY, wxT("Indexing"));
wxBoxSizer* indexSizer = new wxStaticBoxSizer(indexBox, wxVERTICAL); wxBoxSizer* indexSizer = new wxStaticBoxSizer(indexBox, wxVERTICAL);
@ -3453,6 +3505,40 @@ wxPanel* OPJEncoderDialog::CreatePart1SettingsPage(wxWindow* parent)
subtopSizer->Add(commentSizer, 0, wxGROW | wxALL, 3); 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); topSizer->Add(subtopSizer, 1, wxGROW | wxALIGN_CENTRE | wxALL, 5);
// assign top and fit it // assign top and fit it

View File

@ -631,20 +631,22 @@ public:
wxBookCtrlBase* m_settingsNotebook; wxBookCtrlBase* m_settingsNotebook;
wxPanel* CreateMainSettingsPage(wxWindow* parent); wxPanel* CreateMainSettingsPage(wxWindow* parent);
wxPanel* CreatePart1SettingsPage(wxWindow* parent); wxPanel* CreatePart1_1SettingsPage(wxWindow* parent);
wxPanel* CreatePart1_2SettingsPage(wxWindow* parent);
/* wxPanel* CreatePart3SettingsPage(wxWindow* parent);*/ /* wxPanel* CreatePart3SettingsPage(wxWindow* parent);*/
#ifdef USE_JPWL #ifdef USE_JPWL
void OnEnableJPWL(wxCommandEvent& event); void OnEnableJPWL(wxCommandEvent& event);
void OnEnableComm(wxCommandEvent& event); void OnEnableComm(wxCommandEvent& event);
void OnEnableIdx(wxCommandEvent& event); void OnEnableIdx(wxCommandEvent& event);
/* wxPanel* CreatePart11SettingsPage(wxWindow* parent); wxPanel* CreatePart11SettingsPage(wxWindow* parent);
wxCheckBox *m_enablejpwlCheck;*/ /*wxCheckBox *m_enablejpwlCheck;*/
#endif // USE_JPWL #endif // USE_JPWL
wxTextCtrl *m_subsamplingCtrl, *m_originCtrl, *m_rateCtrl, *m_commentCtrl; wxTextCtrl *m_subsamplingCtrl, *m_originCtrl, *m_rateCtrl, *m_commentCtrl;
wxTextCtrl *m_indexCtrl, *m_qualityCtrl, *m_cbsizeCtrl, *m_prsizeCtrl; wxTextCtrl *m_indexCtrl, *m_qualityCtrl, *m_cbsizeCtrl, *m_prsizeCtrl, *m_pocCtrl;
wxTextCtrl *m_tsizeCtrl, *m_toriginCtrl; wxTextCtrl *m_tsizeCtrl, *m_toriginCtrl;
wxCheckBox *m_enablecommCheck, *m_enableidxCheck, *m_irrevCheck, *m_sopCheck, *m_ephCheck; wxCheckBox *m_enablecommCheck, *m_enableidxCheck, *m_irrevCheck, *m_sopCheck, *m_ephCheck;
wxCheckBox *m_enablepocCheck;
wxSpinCtrl *m_resolutionsCtrl; wxSpinCtrl *m_resolutionsCtrl;
protected: protected:
@ -667,6 +669,7 @@ protected:
OPJENCO_ENABLEVSC, OPJENCO_ENABLEVSC,
OPJENCO_ENABLEERTERM, OPJENCO_ENABLEERTERM,
OPJENCO_ENABLESEGMARK, OPJENCO_ENABLESEGMARK,
OPJENCO_ENABLEPOC,
OPJENCO_ROICOMP, OPJENCO_ROICOMP,
OPJENCO_ROISHIFT, OPJENCO_ROISHIFT,
OPJENCO_IMORIG, OPJENCO_IMORIG,
@ -674,6 +677,7 @@ protected:
OPJENCO_ENABLEIRREV, OPJENCO_ENABLEIRREV,
OPJENCO_ENABLEINDEX, OPJENCO_ENABLEINDEX,
OPJENCO_INDEXNAME, OPJENCO_INDEXNAME,
OPJENCO_POCSPEC,
OPJENCO_ENABLECOMM, OPJENCO_ENABLECOMM,
OPJENCO_COMMENTTEXT OPJENCO_COMMENTTEXT
}; };

View File

@ -1 +1 @@
wxT("207") wxT("219")

View File

@ -131,6 +131,7 @@ bool wxJ2KHandler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
unsigned char *src = NULL; unsigned char *src = NULL;
unsigned char *ptr; unsigned char *ptr;
int file_length; int file_length;
opj_codestream_info_t cstr_info; /* Codestream information structure */
// destroy the image // destroy the image
image->Destroy(); image->Destroy();
@ -188,7 +189,7 @@ bool wxJ2KHandler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */ /* decode the stream and fill the image structure */
opjimage = opj_decode(dinfo, cio); opjimage = opj_decode(dinfo, cio, &cstr_info);
if (!opjimage) { if (!opjimage) {
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiEnter(); wxMutexGuiEnter();
@ -242,6 +243,7 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
int codestream_length; int codestream_length;
bool bSuccess; bool bSuccess;
int i; int i;
char indexfilename[OPJ_PATH_LEN] = ""; /* index file name */
/* /*
configure the event callbacks (not required) configure the event callbacks (not required)
@ -316,11 +318,8 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
/* indexing file */ /* indexing file */
if (m_enableidx) { if (m_enableidx) {
strncpy(parameters.index, m_index.c_str(), m_index.Len()); strncpy(indexfilename, m_index.c_str(), OPJ_PATH_LEN);
wxLogMessage("index file is %s", parameters.index); wxLogMessage("index file is %s", indexfilename);
parameters.index_on = 1;
} else {
parameters.index_on = 0;
} }
/* if no rate entered, lossless by default */ /* if no rate entered, lossless by default */
@ -479,8 +478,8 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
opj_cio_close(cio); opj_cio_close(cio);
/* Write the index to disk */ /* Write the index to disk */
if (parameters.index_on) { if (*indexfilename) {
bSuccess = write_index_file(&cstr_info, parameters.index); bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) { if (bSuccess) {
wxLogError(wxT("Failed to output index file")); wxLogError(wxT("Failed to output index file"));
} }
@ -536,67 +535,72 @@ Create an index and write it to a file
bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *index) { bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *index) {
int tileno, compno, layno, resno, precno, pack_nb, x, y; int tileno, compno, layno, resno, precno, pack_nb, x, y;
FILE *stream = NULL; FILE *stream = NULL;
double total_disto = 0; int tilepartno;
if (!cstr_info) if (!cstr_info)
return false; return 1;
stream = fopen(index, "w"); stream = fopen(index, "w");
if (!stream) { if (!stream) {
wxLogError(wxT("failed to open index file [%s] for writing"), index); fprintf(stderr, "failed to open index file [%s] for writing\n", index);
return false; return 1;
} }
fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h); fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
fprintf(stream, "%d\n", cstr_info->prog); 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->tile_x, cstr_info->tile_y);
fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th); fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th);
fprintf(stream, "%d\n", cstr_info->comp); fprintf(stream, "%d\n", cstr_info->numcomps);
fprintf(stream, "%d\n", cstr_info->layer); fprintf(stream, "%d\n", cstr_info->numlayers);
fprintf(stream, "%d\n", cstr_info->decomposition); fprintf(stream, "%d\n", cstr_info->numdecompos);
for (resno = cstr_info->decomposition; resno >= 0; resno--) { for (resno = cstr_info->numdecompos; resno >= 0; resno--) {
fprintf(stream, "[%d,%d] ", fprintf(stream, "[%d,%d] ",
(1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 */ (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 */
} }
fprintf(stream, "\n"); 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->main_head_end);
fprintf(stream, "%d\n", cstr_info->codestream_size); fprintf(stream, "%d\n", cstr_info->codestream_size);
fprintf(stream, "\nINFO ON TILES\n"); fprintf(stream, "\nINFO ON TILES\n");
fprintf(stream, "tileno start_pos end_hd end_tile disto nbpix disto/nbpix\n"); fprintf(stream, "tileno start_pos end_hd end_tile nbparts\n");
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "%4d %9d %9d %9d %9e %9d %9e\n", fprintf(stream, "%4d %9d %9d %9d %9d\n",
cstr_info->tile[tileno].num_tile, cstr_info->tile[tileno].tileno,
cstr_info->tile[tileno].start_pos, cstr_info->tile[tileno].start_pos,
cstr_info->tile[tileno].end_header, cstr_info->tile[tileno].end_header,
cstr_info->tile[tileno].end_pos, cstr_info->tile[tileno].end_pos,
cstr_info->tile[tileno].distotile, cstr_info->tile[tileno].nbpix, cstr_info->tile[tileno].num_tps);
cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].nbpix);
} }
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
int start_pos, end_ph_pos, end_pos; int start_pos, end_ph_pos, end_pos;
double disto = 0;
pack_nb = 0; pack_nb = 0;
fprintf(stream, "\nTILE %d DETAILS\n", tileno); fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream, "part_nb tileno 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 %11d %9d\n",
tilepartno, tileno,
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 */ if (cstr_info->prog == LRCP) { /* LRCP */
fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos\n");
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 < cstr_info->numdecompos + 1; resno++) {
for (layno = 0; layno < cstr_info->layer; layno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {
for (compno = 0; compno < cstr_info->comp; compno++) {
int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) { for (precno = 0; precno < prec_max; precno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; 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_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_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\n",
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);
pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos, disto);
total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
@ -605,20 +609,18 @@ bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *inde
} /* LRCP */ } /* LRCP */
else if (cstr_info->prog == RLCP) { /* RLCP */ 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"); fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");
for (resno = 0; resno < cstr_info->decomposition + 1; resno++) { for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) {
for (layno = 0; layno < cstr_info->layer; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (compno = 0; compno < cstr_info->comp; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) { for (precno = 0; precno < prec_max; precno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; 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_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_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\n",
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);
pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos, disto);
total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
@ -627,34 +629,32 @@ bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *inde
} /* RLCP */ } /* RLCP */
else if (cstr_info->prog == RPCL) { /* RPCL */ 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"); fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos\n");
for (resno = 0; resno < cstr_info->decomposition + 1; resno++) { for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) {
/* I suppose components have same XRsiz, YRsiz */ /* 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 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 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 x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y; int y1 = y0 + cstr_info->tile_y;
for (compno = 0; compno < cstr_info->comp; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) { for (precno = 0; precno < prec_max; precno++) {
int pcnx = cstr_info->tile[tileno].pw[resno]; int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->decomposition - resno ); int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->decomposition - resno ); int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx ); int precno_y = (int) floor( (float)precno/(float)pcnx );
for(y = y0; y < y1; y++) { for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) { if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) { for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) { if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->layer; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; 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_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_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\n",
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);
pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos, disto);
total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
@ -672,29 +672,27 @@ bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *inde
int x1 = x0 + cstr_info->tile_x; int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y; 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"); fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos\n");
for (compno = 0; compno < cstr_info->comp; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
for (resno = 0; resno < cstr_info->decomposition + 1; resno++) { for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) {
int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) { for (precno = 0; precno < prec_max; precno++) {
int pcnx = cstr_info->tile[tileno].pw[resno]; int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->decomposition - resno ); int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->decomposition - resno ); int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx ); int precno_y = (int) floor( (float)precno/(float)pcnx );
for(y = y0; y < y1; y++) { for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) { if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) { for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) { if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->layer; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; 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_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_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\n",
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);
pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos, disto);
total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
@ -707,35 +705,33 @@ bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *inde
} /* PCRL */ } /* PCRL */
else { /* CPRL */ else { /* CPRL */
fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos disto\n"); fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos\n");
for (compno = 0; compno < cstr_info->comp; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
/* I suppose components have same XRsiz, YRsiz */ /* 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 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 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 x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y; int y1 = y0 + cstr_info->tile_y;
for (resno = 0; resno < cstr_info->decomposition + 1; resno++) { for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) {
int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) { for (precno = 0; precno < prec_max; precno++) {
int pcnx = cstr_info->tile[tileno].pw[resno]; int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->decomposition - resno ); int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->decomposition - resno ); int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx ); int precno_y = (int) floor( (float)precno/(float)pcnx );
for(y = y0; y < y1; y++) { for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) { if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) { for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) { if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->layer; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; 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_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_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\n",
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);
pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos, disto);
total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
@ -748,11 +744,9 @@ bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *inde
} /* CPRL */ } /* CPRL */
} /* tileno */ } /* tileno */
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */
fclose(stream); fclose(stream);
wxLogError(wxT("Generated index file %s"), index); fprintf(stderr,"Generated index file %s\n", index);
return true; return true;
} }

View File

@ -135,6 +135,7 @@ bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
unsigned char *src = NULL; unsigned char *src = NULL;
unsigned char *ptr; unsigned char *ptr;
int file_length; int file_length;
opj_codestream_info_t cstr_info; /* Codestream information structure */
// destroy the image // destroy the image
image->Destroy(); image->Destroy();
@ -193,7 +194,7 @@ bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */ /* decode the stream and fill the image structure */
opjimage = opj_decode(dinfo, cio); opjimage = opj_decode(dinfo, cio, &cstr_info);
if (!opjimage) { if (!opjimage) {
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiEnter(); wxMutexGuiEnter();

View File

@ -618,6 +618,7 @@ bool wxMJ2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
unsigned char *ptr; unsigned char *ptr;
int file_length, jp2c_point, jp2h_point; int file_length, jp2c_point, jp2h_point;
unsigned long int jp2hboxlen, jp2cboxlen; unsigned long int jp2hboxlen, jp2cboxlen;
opj_codestream_info_t cstr_info; /* Codestream information structure */
// destroy the image // destroy the image
image->Destroy(); image->Destroy();
@ -699,7 +700,7 @@ bool wxMJ2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
cio = opj_cio_open((opj_common_ptr)dinfo, src, my_jPheadSIZE + jp2hboxlen + jp2cboxlen); cio = opj_cio_open((opj_common_ptr)dinfo, src, my_jPheadSIZE + jp2hboxlen + jp2cboxlen);
/* decode the stream and fill the image structure */ /* decode the stream and fill the image structure */
opjimage = opj_decode(dinfo, cio); opjimage = opj_decode(dinfo, cio, &cstr_info);
if (!opjimage) { if (!opjimage) {
wxMutexGuiEnter(); wxMutexGuiEnter();
wxLogError(wxT("MJ2: failed to decode image!")); wxLogError(wxT("MJ2: failed to decode image!"));

View File

@ -1289,7 +1289,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
/* we need to enable indexing */ /* we need to enable indexing */
if (!indexfilename) { if (!indexfilename) {
strncpy(parameters->index, JPWL_PRIVATEINDEX_NAME, sizeof(parameters->index)-1); strncpy(indexfilename, JPWL_PRIVATEINDEX_NAME, OPJ_PATH_LEN);
} }
/* search for different protection methods */ /* search for different protection methods */

View File

@ -232,7 +232,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
unsigned long int left_THmarks_len; unsigned long int left_THmarks_len;
/******* sot_pos = j2k->cstr_info->tile[tileno].start_pos; */ /******* sot_pos = j2k->cstr_info->tile[tileno].start_pos; */
sot_pos = j2k->cstr_info->tile[tileno].tp_start_pos[tpno]; sot_pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos;
cio_seek(cio, sot_pos + 2); cio_seek(cio, sot_pos + 2);
sot_len = cio_read(cio, 2); /* SOT Len */ sot_len = cio_read(cio, 2); /* SOT Len */
cio_skip(cio, 2); cio_skip(cio, 2);
@ -240,7 +240,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
Psot = cio_read(cio, 4); /* tile length */ Psot = cio_read(cio, 4); /* tile length */
/******* post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1; */ /******* post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1; */
post_sod_pos = j2k->cstr_info->tile[tileno].tp_end_header[tpno] + 1; post_sod_pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_end_header + 1;
left_THmarks_len = post_sod_pos - sot_pos; left_THmarks_len = post_sod_pos - sot_pos;
/* add all the lengths of the markers which are len-ready and stay within SOT and SOD */ /* add all the lengths of the markers which are len-ready and stay within SOT and SOD */
@ -282,7 +282,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */ jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */
jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */ jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */
/****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */ /****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */
jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp_start_pos[tpno] + sot_len + 2; /* after SOT */ jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */
jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */ jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */
jwmarker[jwmarker_num].len_ready = true; /* ready, yet */ jwmarker[jwmarker_num].len_ready = true; /* ready, yet */
@ -403,12 +403,12 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
int sot_len, Psot, Psotp, mm, epb_index = 0, prot_len = 0; int sot_len, Psot, Psotp, mm, epb_index = 0, prot_len = 0;
unsigned long sot_pos, post_sod_pos; unsigned long sot_pos, post_sod_pos;
unsigned long int left_THmarks_len, epbs_len = 0; unsigned long int left_THmarks_len, epbs_len = 0;
int startpack = 0, stoppack = j2k->cstr_info->num; int startpack = 0, stoppack = j2k->cstr_info->packno;
int first_tp_pack, last_tp_pack; int first_tp_pack, last_tp_pack;
jpwl_epb_ms_t *tph_epb = NULL; jpwl_epb_ms_t *tph_epb = NULL;
/****** sot_pos = j2k->cstr_info->tile[tileno].start_pos; */ /****** sot_pos = j2k->cstr_info->tile[tileno].start_pos; */
sot_pos = j2k->cstr_info->tile[tileno].tp_start_pos[tpno]; sot_pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos;
cio_seek(cio, sot_pos + 2); cio_seek(cio, sot_pos + 2);
sot_len = cio_read(cio, 2); /* SOT Len */ sot_len = cio_read(cio, 2); /* SOT Len */
cio_skip(cio, 2); cio_skip(cio, 2);
@ -417,7 +417,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
/* a-priori length of the data dwelling between SOT and SOD */ /* a-priori length of the data dwelling between SOT and SOD */
/****** post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1; */ /****** post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1; */
post_sod_pos = j2k->cstr_info->tile[tileno].tp_end_header[tpno] + 1; post_sod_pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_end_header + 1;
left_THmarks_len = post_sod_pos - (sot_pos + sot_len + 2); left_THmarks_len = post_sod_pos - (sot_pos + sot_len + 2);
/* add all the lengths of the JPWL markers which are len-ready and stay within SOT and SOD */ /* add all the lengths of the JPWL markers which are len-ready and stay within SOT and SOD */
@ -458,7 +458,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */ jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */
jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */ jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */
/****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */ /****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */
jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp_start_pos[tpno] + sot_len + 2; /* after SOT */ jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */ jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */
jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */ jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */
jwmarker[jwmarker_num].len_ready = true; /* ready */ jwmarker[jwmarker_num].len_ready = true; /* ready */
@ -493,9 +493,9 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
startpack = 0; startpack = 0;
/* EPB MSs for UEP packet data protection in Tile Parts */ /* EPB MSs for UEP packet data protection in Tile Parts */
/****** for (packno = 0; packno < j2k->cstr_info->num; packno++) { */ /****** for (packno = 0; packno < j2k->cstr_info->num; packno++) { */
first_tp_pack = (tpno > 0) ? (first_tp_pack + j2k->cstr_info->tile[tileno].tp_num[tpno - 1]) : 0; first_tp_pack = (tpno > 0) ? (first_tp_pack + j2k->cstr_info->tile[tileno].tp[tpno - 1].tp_numpacks) : 0;
last_tp_pack = first_tp_pack + j2k->cstr_info->tile[tileno].tp_num[tpno] - 1; last_tp_pack = first_tp_pack + j2k->cstr_info->tile[tileno].tp[tpno].tp_numpacks - 1;
for (packno = 0; packno < j2k->cstr_info->tile[tileno].tp_num[tpno]; packno++) { for (packno = 0; packno < j2k->cstr_info->tile[tileno].tp[tpno].tp_numpacks; packno++) {
/******** if ((packspec < JPWL_MAX_NO_PACKSPECS) && /******** if ((packspec < JPWL_MAX_NO_PACKSPECS) &&
(j2k->cp->pprot_tileno[packspec] == tileno) && (j2k->cp->pprot_packno[packspec] == packno)) { */ (j2k->cp->pprot_tileno[packspec] == tileno) && (j2k->cp->pprot_packno[packspec] == packno)) { */
@ -547,7 +547,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
&epb_index, /* pointer to EPB index */ &epb_index, /* pointer to EPB index */
pprot, /* protection type */ pprot, /* protection type */
/****** (double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, */ /* position */ /****** (double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, */ /* position */
(double) (j2k->cstr_info->tile[tileno].tp_start_pos[tpno] + sot_len + 2) + 0.0001, /* position */ (double) (j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2) + 0.0001, /* position */
tileno, /* number of tile */ tileno, /* number of tile */
0, /* length of pre-data */ 0, /* length of pre-data */
prot_len /*4000*/ /* length of post-data */ prot_len /*4000*/ /* length of post-data */
@ -607,7 +607,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
&epb_index, /* pointer to EPB index */ &epb_index, /* pointer to EPB index */
pprot, /* protection type */ pprot, /* protection type */
/***** (double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001,*/ /* position */ /***** (double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001,*/ /* position */
(double) (j2k->cstr_info->tile[tileno].tp_start_pos[tpno] + sot_len + 2) + 0.0001, /* position */ (double) (j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2) + 0.0001, /* position */
tileno, /* number of tile */ tileno, /* number of tile */
0, /* length of pre-data */ 0, /* length of pre-data */
prot_len /*4000*/ /* length of post-data */ prot_len /*4000*/ /* length of post-data */

View File

@ -32,6 +32,7 @@
#ifdef USE_JPWL #ifdef USE_JPWL
#include "../libopenjpeg/opj_includes.h" #include "../libopenjpeg/opj_includes.h"
#include <limits.h>
/** Minimum and maximum values for the double->pfp conversion */ /** Minimum and maximum values for the double->pfp conversion */
#define MIN_V1 0.0 #define MIN_V1 0.0
@ -143,6 +144,11 @@ int jpwl_epbs_add(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int *jwmarker_num,
/* (message word size) * (number of containable parity words) */ /* (message word size) * (number of containable parity words) */
max_postlen = k_post * (unsigned long int) floor((double) JPWL_MAXIMUM_EPB_ROOM / (double) (n_post - k_post)); max_postlen = k_post * (unsigned long int) floor((double) JPWL_MAXIMUM_EPB_ROOM / (double) (n_post - k_post));
/* null protection case */
/* the max post length can be as large as the LDPepb field can host */
if (hprot == 0)
max_postlen = INT_MAX;
/* length to use */ /* length to use */
dL4 = min(max_postlen, post_len); dL4 = min(max_postlen, post_len);
@ -651,7 +657,7 @@ bool jpwl_correct(opj_j2k_t *j2k) {
j2k->state = J2K_STATE_MHSOC; j2k->state = J2K_STATE_MHSOC;
/* cycle all over the markers */ /* cycle all over the markers */
while (cio_tell(cio) < cio->length) { while ((unsigned int) cio_tell(cio) < cio->length) {
/* read the marker */ /* read the marker */
mark_pos = cio_tell(cio); mark_pos = cio_tell(cio);
@ -1225,7 +1231,7 @@ jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comp, unsigned char addrm, un
/* auto sense address size */ /* auto sense address size */
if (ad_size == 0) if (ad_size == 0)
/* if there are more than 2^16 - 1 packets, switch to 4 bytes */ /* if there are more than 2^16 - 1 packets, switch to 4 bytes */
ad_size = (j2k->cstr_info->num > 65535) ? 4 : 2; ad_size = (j2k->cstr_info->packno > 65535) ? 4 : 2;
esd->sensval_size = ad_size + ad_size + se_size; esd->sensval_size = ad_size + ad_size + se_size;
break; break;
@ -1246,17 +1252,17 @@ jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comp, unsigned char addrm, un
/* just based on the portions of a codestream */ /* just based on the portions of a codestream */
case (0): case (0):
/* MH + no. of THs + no. of packets */ /* MH + no. of THs + no. of packets */
svalnum = 1 + (j2k->cstr_info->tw * j2k->cstr_info->th) * (1 + j2k->cstr_info->num); svalnum = 1 + (j2k->cstr_info->tw * j2k->cstr_info->th) * (1 + j2k->cstr_info->packno);
break; break;
/* all the ones that are based on the packets */ /* all the ones that are based on the packets */
default: default:
if (tileno < 0) if (tileno < 0)
/* MH: all the packets and all the tiles info is written */ /* MH: all the packets and all the tiles info is written */
svalnum = j2k->cstr_info->tw * j2k->cstr_info->th * j2k->cstr_info->num; svalnum = j2k->cstr_info->tw * j2k->cstr_info->th * j2k->cstr_info->packno;
else else
/* TPH: only that tile info is written */ /* TPH: only that tile info is written */
svalnum = j2k->cstr_info->num; svalnum = j2k->cstr_info->packno;
break; break;
} }
@ -1356,9 +1362,9 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) {
buf += 7; buf += 7;
/* let's fill the data fields */ /* let's fill the data fields */
for (vv = (esd->tileno < 0) ? 0 : (j2k->cstr_info->num * esd->tileno); vv < esd->svalnum; vv++) { for (vv = (esd->tileno < 0) ? 0 : (j2k->cstr_info->packno * esd->tileno); vv < esd->svalnum; vv++) {
int thistile = vv / j2k->cstr_info->num, thispacket = vv % j2k->cstr_info->num; int thistile = vv / j2k->cstr_info->packno, thispacket = vv % j2k->cstr_info->packno;
/* skip for the hack some lines below */ /* skip for the hack some lines below */
if (thistile == j2k->cstr_info->tw * j2k->cstr_info->th) if (thistile == j2k->cstr_info->tw * j2k->cstr_info->th)
@ -1367,7 +1373,7 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) {
/* starting tile distortion */ /* starting tile distortion */
if (thispacket == 0) { if (thispacket == 0) {
TSE = j2k->cstr_info->tile[thistile].distotile; TSE = j2k->cstr_info->tile[thistile].distotile;
oldMSE = TSE / j2k->cstr_info->tile[thistile].nbpix; oldMSE = TSE / j2k->cstr_info->tile[thistile].numpix;
oldPSNR = 10.0 * log10(Omax2 / oldMSE); oldPSNR = 10.0 * log10(Omax2 / oldMSE);
} }
@ -1375,7 +1381,7 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) {
TSE -= j2k->cstr_info->tile[thistile].packet[thispacket].disto; TSE -= j2k->cstr_info->tile[thistile].packet[thispacket].disto;
/* MSE */ /* MSE */
MSE = TSE / j2k->cstr_info->tile[thistile].nbpix; MSE = TSE / j2k->cstr_info->tile[thistile].numpix;
/* PSNR */ /* PSNR */
PSNR = 10.0 * log10(Omax2 / MSE); PSNR = 10.0 * log10(Omax2 / MSE);
@ -1484,7 +1490,7 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) {
else else
/* packet: first is most important, and then in decreasing order /* packet: first is most important, and then in decreasing order
down to the last, which counts for 1 */ down to the last, which counts for 1 */
dvalue = jpwl_pfp_to_double((unsigned short) (j2k->cstr_info->num - thispacket), esd->se_size); dvalue = jpwl_pfp_to_double((unsigned short) (j2k->cstr_info->packno - thispacket), esd->se_size);
break; break;
/* MSE */ /* MSE */
@ -1658,7 +1664,7 @@ bool jpwl_update_info(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int jwmarker_num)
unsigned long int addlen; unsigned long int addlen;
opj_codestream_info_t *info = j2k->cstr_info; opj_codestream_info_t *info = j2k->cstr_info;
int tileno, tpno, packno, numtiles = info->th * info->tw, numpacks = info->num; int tileno, tpno, packno, numtiles = info->th * info->tw, numpacks = info->packno;
if (!j2k || !jwmarker ) { if (!j2k || !jwmarker ) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "J2K handle or JPWL markers list badly allocated\n"); opj_event_msg(j2k->cinfo, EVT_ERROR, "J2K handle or JPWL markers list badly allocated\n");
@ -1709,23 +1715,23 @@ bool jpwl_update_info(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int jwmarker_num)
/* start_pos: increment with markers before SOT */ /* start_pos: increment with markers before SOT */
addlen = 0; addlen = 0;
for (mm = 0; mm < jwmarker_num; mm++) for (mm = 0; mm < jwmarker_num; mm++)
if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].tp_start_pos[tpno]) if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].tp[tpno].tp_start_pos)
addlen += jwmarker[mm].len + 2; addlen += jwmarker[mm].len + 2;
info->tile[tileno].tp_start_pos[tpno] += addlen; info->tile[tileno].tp[tpno].tp_start_pos += addlen;
/* end_header: increment with markers before of it */ /* end_header: increment with markers before of it */
addlen = 0; addlen = 0;
for (mm = 0; mm < jwmarker_num; mm++) for (mm = 0; mm < jwmarker_num; mm++)
if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].tp_end_header[tpno]) if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].tp[tpno].tp_end_header)
addlen += jwmarker[mm].len + 2; addlen += jwmarker[mm].len + 2;
info->tile[tileno].tp_end_header[tpno] += addlen; info->tile[tileno].tp[tpno].tp_end_header += addlen;
/* end_pos: increment with markers before the end of this tile part */ /* end_pos: increment with markers before the end of this tile part */
addlen = 0; addlen = 0;
for (mm = 0; mm < jwmarker_num; mm++) for (mm = 0; mm < jwmarker_num; mm++)
if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].tp_end_pos[tpno]) if (jwmarker[mm].pos < (unsigned long int) info->tile[tileno].tp[tpno].tp_end_pos)
addlen += jwmarker[mm].len + 2; addlen += jwmarker[mm].len + 2;
info->tile[tileno].tp_end_pos[tpno] += addlen; info->tile[tileno].tp[tpno].tp_end_pos += addlen;
} }