Reformat src/bin/wx/OPJViewer/source/OPJThreads.cpp src/bin/wx/OPJViewer/source/imagjpeg2000.cpp wrapping/java/openjp2/JavaOpenJPEG.c

This commit is contained in:
Even Rouault 2017-07-26 21:04:01 +02:00
parent 94cc97c58a
commit 2be20ce7d9
3 changed files with 3660 additions and 3347 deletions

View File

@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@ -36,7 +36,7 @@
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
OPJEncoThread::OPJEncoThread(OPJCanvas *canvas) OPJEncoThread::OPJEncoThread(OPJCanvas *canvas)
: wxThread() : wxThread()
{ {
m_count = 0; m_count = 0;
m_canvas = canvas; m_canvas = canvas;
@ -49,14 +49,14 @@ void OPJEncoThread::WriteText(const wxString& text)
// before doing any GUI calls we must ensure that this thread is the only // before doing any GUI calls we must ensure that this thread is the only
// one doing it! // one doing it!
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiEnter(); wxMutexGuiEnter();
#endif // __WXGTK__ #endif // __WXGTK__
msg << text; msg << text;
m_canvas->WriteText(msg); m_canvas->WriteText(msg);
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiLeave(); wxMutexGuiLeave();
#endif // __WXGTK__ #endif // __WXGTK__
} }
@ -68,8 +68,7 @@ void OPJEncoThread::OnExit()
wxArrayThread& ethreads = wxGetApp().m_enco_threads; wxArrayThread& ethreads = wxGetApp().m_enco_threads;
ethreads.Remove(this); ethreads.Remove(this);
if (ethreads.IsEmpty() ) if (ethreads.IsEmpty()) {
{
// signal the main thread that there are no more threads left if it is // signal the main thread that there are no more threads left if it is
// waiting for us // waiting for us
if (wxGetApp().m_enco_waitingUntilAllDone) { if (wxGetApp().m_enco_waitingUntilAllDone) {
@ -83,50 +82,54 @@ void *OPJEncoThread::Entry()
{ {
wxString text; wxString text;
srand(GetId()); srand(GetId());
//int m_countnum = rand() % 9; //int m_countnum = rand() % 9;
//text.Printf(wxT("Deco thread 0x%lx started (priority = %u, time = %d)."), //text.Printf(wxT("Deco thread 0x%lx started (priority = %u, time = %d)."),
// GetId(), GetPriority(), m_countnum); // GetId(), GetPriority(), m_countnum);
text.Printf(wxT("Enco thread %d started"), m_canvas->m_childframe->m_winnumber); text.Printf(wxT("Enco thread %d started"), m_canvas->m_childframe->m_winnumber);
WriteText(text); WriteText(text);
// set handler properties // set handler properties
wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(wxBITMAP_TYPE_JPEG2000); wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(
jpeg2000handler->m_subsampling = wxGetApp().m_subsampling; wxBITMAP_TYPE_JPEG2000);
jpeg2000handler->m_origin = wxGetApp().m_origin; jpeg2000handler->m_subsampling = wxGetApp().m_subsampling;
jpeg2000handler->m_rates = wxGetApp().m_rates; jpeg2000handler->m_origin = wxGetApp().m_origin;
jpeg2000handler->m_quality = wxGetApp().m_quality; jpeg2000handler->m_rates = wxGetApp().m_rates;
jpeg2000handler->m_enablequality = wxGetApp().m_enablequality; jpeg2000handler->m_quality = wxGetApp().m_quality;
jpeg2000handler->m_multicomp = wxGetApp().m_multicomp; jpeg2000handler->m_enablequality = wxGetApp().m_enablequality;
jpeg2000handler->m_irreversible = wxGetApp().m_irreversible; jpeg2000handler->m_multicomp = wxGetApp().m_multicomp;
jpeg2000handler->m_resolutions = wxGetApp().m_resolutions; jpeg2000handler->m_irreversible = wxGetApp().m_irreversible;
jpeg2000handler->m_progression = wxGetApp().m_progression; jpeg2000handler->m_resolutions = wxGetApp().m_resolutions;
jpeg2000handler->m_cbsize = wxGetApp().m_cbsize; jpeg2000handler->m_progression = wxGetApp().m_progression;
jpeg2000handler->m_prsize = wxGetApp().m_prsize; jpeg2000handler->m_cbsize = wxGetApp().m_cbsize;
jpeg2000handler->m_tsize = wxGetApp().m_tsize; jpeg2000handler->m_prsize = wxGetApp().m_prsize;
jpeg2000handler->m_torigin = wxGetApp().m_torigin; jpeg2000handler->m_tsize = wxGetApp().m_tsize;
jpeg2000handler->m_enablesop = wxGetApp().m_enablesop; jpeg2000handler->m_torigin = wxGetApp().m_torigin;
jpeg2000handler->m_enableeph = wxGetApp().m_enableeph; jpeg2000handler->m_enablesop = wxGetApp().m_enablesop;
jpeg2000handler->m_enablebypass = wxGetApp().m_enablebypass; jpeg2000handler->m_enableeph = wxGetApp().m_enableeph;
jpeg2000handler->m_enablerestart = wxGetApp().m_enablerestart; jpeg2000handler->m_enablebypass = wxGetApp().m_enablebypass;
jpeg2000handler->m_enablereset = wxGetApp().m_enablereset; jpeg2000handler->m_enablerestart = wxGetApp().m_enablerestart;
jpeg2000handler->m_enablesegmark = wxGetApp().m_enablesegmark; jpeg2000handler->m_enablereset = wxGetApp().m_enablereset;
jpeg2000handler->m_enableerterm = wxGetApp().m_enableerterm; jpeg2000handler->m_enablesegmark = wxGetApp().m_enablesegmark;
jpeg2000handler->m_enablevsc = wxGetApp().m_enablevsc; jpeg2000handler->m_enableerterm = wxGetApp().m_enableerterm;
jpeg2000handler->m_enableidx = wxGetApp().m_enableidx; jpeg2000handler->m_enablevsc = wxGetApp().m_enablevsc;
jpeg2000handler->m_index = m_canvas->m_savename.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxGetApp().m_index; jpeg2000handler->m_enableidx = wxGetApp().m_enableidx;
jpeg2000handler->m_enablecomm = wxGetApp().m_enablecomm; jpeg2000handler->m_index = m_canvas->m_savename.GetPath(
jpeg2000handler->m_comment = wxGetApp().m_comment; wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxGetApp().m_index;
jpeg2000handler->m_enablepoc = wxGetApp().m_enablepoc; jpeg2000handler->m_enablecomm = wxGetApp().m_enablecomm;
jpeg2000handler->m_poc = wxGetApp().m_poc; jpeg2000handler->m_comment = wxGetApp().m_comment;
jpeg2000handler->m_enablepoc = wxGetApp().m_enablepoc;
jpeg2000handler->m_poc = wxGetApp().m_poc;
// save the file // save the file
if (!m_canvas->m_image100.SaveFile(m_canvas->m_savename.GetFullPath(), (wxBitmapType) wxBITMAP_TYPE_JPEG2000)) { if (!m_canvas->m_image100.SaveFile(m_canvas->m_savename.GetFullPath(),
WriteText(wxT("Can't save image")); (wxBitmapType) wxBITMAP_TYPE_JPEG2000)) {
return NULL; WriteText(wxT("Can't save image"));
} return NULL;
}
text.Printf(wxT("Enco thread %d finished"), m_canvas->m_childframe->m_winnumber); text.Printf(wxT("Enco thread %d finished"),
m_canvas->m_childframe->m_winnumber);
WriteText(text); WriteText(text);
return NULL; return NULL;
} }
@ -136,7 +139,7 @@ void *OPJEncoThread::Entry()
// Decoding thread class // Decoding thread class
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
OPJDecoThread::OPJDecoThread(OPJCanvas *canvas) OPJDecoThread::OPJDecoThread(OPJCanvas *canvas)
: wxThread() : wxThread()
{ {
m_count = 0; m_count = 0;
m_canvas = canvas; m_canvas = canvas;
@ -145,29 +148,29 @@ OPJDecoThread::OPJDecoThread(OPJCanvas *canvas)
void OPJDecoThread::WriteText(const wxString& text) void OPJDecoThread::WriteText(const wxString& text)
{ {
wxString msg; wxString msg;
// we use a fake event and post it for inter-thread gui communication // we use a fake event and post it for inter-thread gui communication
wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, OPJFRAME_THREADLOGMSG); wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, OPJFRAME_THREADLOGMSG);
event.SetInt(-1); event.SetInt(-1);
msg << text; msg << text;
event.SetString(msg); event.SetString(msg);
wxPostEvent(this->m_canvas->m_childframe->m_frame, event); wxPostEvent(this->m_canvas->m_childframe->m_frame, event);
/* /*
// before doing any GUI calls we must ensure that this thread is the only // before doing any GUI calls we must ensure that this thread is the only
// one doing it! // one doing it!
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiEnter(); wxMutexGuiEnter();
#endif // __WXGTK__ #endif // __WXGTK__
msg << text; msg << text;
m_canvas->WriteText(msg); m_canvas->WriteText(msg);
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiLeave(); wxMutexGuiLeave();
#endif // __WXGTK__ #endif // __WXGTK__
*/ */
} }
void OPJDecoThread::OnExit() void OPJDecoThread::OnExit()
@ -177,8 +180,7 @@ void OPJDecoThread::OnExit()
wxArrayThread& dthreads = wxGetApp().m_deco_threads; wxArrayThread& dthreads = wxGetApp().m_deco_threads;
dthreads.Remove(this); dthreads.Remove(this);
if (dthreads.IsEmpty() ) if (dthreads.IsEmpty()) {
{
// signal the main thread that there are no more threads left if it is // signal the main thread that there are no more threads left if it is
// waiting for us // waiting for us
if (wxGetApp().m_deco_waitingUntilAllDone) { if (wxGetApp().m_deco_waitingUntilAllDone) {
@ -193,95 +195,98 @@ void *OPJDecoThread::Entry()
wxString text; wxString text;
//srand(GetId()); //srand(GetId());
//int m_countnum = rand() % 9; //int m_countnum = rand() % 9;
//text.Printf(wxT("Deco thread 0x%lx started (priority = %u, time = %d)."), //text.Printf(wxT("Deco thread 0x%lx started (priority = %u, time = %d)."),
// GetId(), GetPriority(), m_countnum); // GetId(), GetPriority(), m_countnum);
// we have started // we have started
text.Printf(wxT("Deco thread %d started"), m_canvas->m_childframe->m_winnumber); text.Printf(wxT("Deco thread %d started"), m_canvas->m_childframe->m_winnumber);
WriteText(text); WriteText(text);
// prepare dummy wximage // prepare dummy wximage
wxBitmap bitmap(100, 100); wxBitmap bitmap(100, 100);
wxImage image(100, 100, true); //= bitmap.ConvertToImage(); wxImage image(100, 100, true); //= bitmap.ConvertToImage();
image.Destroy(); image.Destroy();
// show image full name // show image full name
WriteText(m_canvas->m_fname.GetFullPath()); WriteText(m_canvas->m_fname.GetFullPath());
// set handler properties // set handler properties
wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(wxBITMAP_TYPE_JPEG2000); wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(
jpeg2000handler->m_reducefactor = wxGetApp().m_reducefactor; wxBITMAP_TYPE_JPEG2000);
jpeg2000handler->m_qualitylayers = wxGetApp().m_qualitylayers; jpeg2000handler->m_reducefactor = wxGetApp().m_reducefactor;
jpeg2000handler->m_components = wxGetApp().m_components; jpeg2000handler->m_qualitylayers = wxGetApp().m_qualitylayers;
jpeg2000handler->m_framenum = wxGetApp().m_framenum; jpeg2000handler->m_components = wxGetApp().m_components;
jpeg2000handler->m_framenum = wxGetApp().m_framenum;
#ifdef USE_JPWL #ifdef USE_JPWL
jpeg2000handler->m_enablejpwl = wxGetApp().m_enablejpwl; jpeg2000handler->m_enablejpwl = wxGetApp().m_enablejpwl;
jpeg2000handler->m_expcomps = wxGetApp().m_expcomps; jpeg2000handler->m_expcomps = wxGetApp().m_expcomps;
jpeg2000handler->m_maxtiles = wxGetApp().m_maxtiles; jpeg2000handler->m_maxtiles = wxGetApp().m_maxtiles;
#endif // USE_JPWL #endif // USE_JPWL
#ifdef USE_MXF #ifdef USE_MXF
wxMXFHandler *mxfffhandler = (wxMXFHandler *) wxImage::FindHandler(wxBITMAP_TYPE_MXF); wxMXFHandler *mxfffhandler = (wxMXFHandler *) wxImage::FindHandler(
mxfffhandler->m_reducefactor = wxGetApp().m_reducefactor; wxBITMAP_TYPE_MXF);
mxfffhandler->m_qualitylayers = wxGetApp().m_qualitylayers; mxfffhandler->m_reducefactor = wxGetApp().m_reducefactor;
mxfffhandler->m_components = wxGetApp().m_components; mxfffhandler->m_qualitylayers = wxGetApp().m_qualitylayers;
mxfffhandler->m_framenum = wxGetApp().m_framenum; mxfffhandler->m_components = wxGetApp().m_components;
mxfffhandler->m_filename = m_canvas->m_fname; mxfffhandler->m_framenum = wxGetApp().m_framenum;
mxfffhandler->m_filename = m_canvas->m_fname;
#ifdef USE_JPWL #ifdef USE_JPWL
mxfffhandler->m_enablejpwl = wxGetApp().m_enablejpwl; mxfffhandler->m_enablejpwl = wxGetApp().m_enablejpwl;
mxfffhandler->m_expcomps = wxGetApp().m_expcomps; mxfffhandler->m_expcomps = wxGetApp().m_expcomps;
mxfffhandler->m_maxtiles = wxGetApp().m_maxtiles; mxfffhandler->m_maxtiles = wxGetApp().m_maxtiles;
#endif // USE_JPWL #endif // USE_JPWL
#endif // USE_MXF #endif // USE_MXF
// if decoding is enabled... // if decoding is enabled...
if (wxGetApp().m_enabledeco) { if (wxGetApp().m_enabledeco) {
// load the file // load the file
if (!image.LoadFile(m_canvas->m_fname.GetFullPath(), wxBITMAP_TYPE_ANY, 0)) { if (!image.LoadFile(m_canvas->m_fname.GetFullPath(), wxBITMAP_TYPE_ANY, 0)) {
WriteText(wxT("Can't load image!")); WriteText(wxT("Can't load image!"));
return NULL; return NULL;
} }
} else { } else {
// display a warning // display a warning
if (!image.Create(300, 5, false)) { if (!image.Create(300, 5, false)) {
WriteText(wxT("Can't create image!")); WriteText(wxT("Can't create image!"));
return NULL; return NULL;
} }
} }
// assign 100% image // assign 100% image
m_canvas->m_image100 = wxBitmap(image); m_canvas->m_image100 = wxBitmap(image);
// signal the frame to refresh the canvas // signal the frame to refresh the canvas
wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, OPJFRAME_VIEWFIT); wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, OPJFRAME_VIEWFIT);
event.SetString(wxT("Fit me")); event.SetString(wxT("Fit me"));
event.SetInt(m_canvas->m_childframe->m_winnumber); event.SetInt(m_canvas->m_childframe->m_winnumber);
wxPostEvent(m_canvas->m_childframe->m_frame, event); wxPostEvent(m_canvas->m_childframe->m_frame, event);
// find a fit-to-width zoom // find a fit-to-width zoom
/*int zooml, wzooml, hzooml; /*int zooml, wzooml, hzooml;
wxSize clientsize = m_canvas->GetClientSize(); wxSize clientsize = m_canvas->GetClientSize();
wzooml = (int) floor(100.0 * (double) clientsize.GetWidth() / (double) (2 * OPJ_CANVAS_BORDER + image.GetWidth())); wzooml = (int) floor(100.0 * (double) clientsize.GetWidth() / (double) (2 * OPJ_CANVAS_BORDER + image.GetWidth()));
hzooml = (int) floor(100.0 * (double) clientsize.GetHeight() / (double) (2 * OPJ_CANVAS_BORDER + image.GetHeight())); hzooml = (int) floor(100.0 * (double) clientsize.GetHeight() / (double) (2 * OPJ_CANVAS_BORDER + image.GetHeight()));
zooml = wxMin(100, wxMin(wzooml, hzooml));*/ zooml = wxMin(100, wxMin(wzooml, hzooml));*/
// fit to width // fit to width
#ifndef __WXGTK__ #ifndef __WXGTK__
//m_canvas->m_childframe->m_frame->Rescale(zooml, m_canvas->m_childframe); //m_canvas->m_childframe->m_frame->Rescale(zooml, m_canvas->m_childframe);
#endif // __WXGTK__ #endif // __WXGTK__
//m_canvas->m_image = m_canvas->m_image100; //m_canvas->m_image = m_canvas->m_image100;
//m_canvas->Refresh(); //m_canvas->Refresh();
//m_canvas->SetScrollbars(20, 20, (int)(0.5 + (double) image.GetWidth() / 20.0), (int)(0.5 + (double) image.GetHeight() / 20.0)); //m_canvas->SetScrollbars(20, 20, (int)(0.5 + (double) image.GetWidth() / 20.0), (int)(0.5 + (double) image.GetHeight() / 20.0));
//text.Printf(wxT("Deco thread 0x%lx finished."), GetId()); //text.Printf(wxT("Deco thread 0x%lx finished."), GetId());
text.Printf(wxT("Deco thread %d finished"), m_canvas->m_childframe->m_winnumber); text.Printf(wxT("Deco thread %d finished"),
m_canvas->m_childframe->m_winnumber);
WriteText(text); WriteText(text);
return NULL; return NULL;
@ -292,37 +297,37 @@ void *OPJDecoThread::Entry()
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
OPJParseThread::OPJParseThread(OPJMarkerTree *tree, wxTreeItemId parentid) OPJParseThread::OPJParseThread(OPJMarkerTree *tree, wxTreeItemId parentid)
: wxThread() : wxThread()
{ {
m_count = 0; m_count = 0;
m_tree = tree; m_tree = tree;
m_parentid = parentid; m_parentid = parentid;
} }
void OPJParseThread::WriteText(const wxString& text) void OPJParseThread::WriteText(const wxString& text)
{ {
wxString msg; wxString msg;
// we use a fake event and post it for inter-thread gui communication // we use a fake event and post it for inter-thread gui communication
wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, OPJFRAME_THREADLOGMSG); wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, OPJFRAME_THREADLOGMSG);
event.SetInt(-1); event.SetInt(-1);
msg << text; msg << text;
event.SetString(msg); event.SetString(msg);
wxPostEvent(this->m_tree->m_childframe->m_frame, event); wxPostEvent(this->m_tree->m_childframe->m_frame, event);
/* // before doing any GUI calls we must ensure that this thread is the only /* // before doing any GUI calls we must ensure that this thread is the only
// one doing it! // one doing it!
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiEnter(); wxMutexGuiEnter();
#endif // __WXGTK #endif // __WXGTK
msg << text; msg << text;
m_tree->WriteText(msg); m_tree->WriteText(msg);
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiLeave(); wxMutexGuiLeave();
#endif // __WXGTK*/ #endif // __WXGTK*/
} }
void OPJParseThread::OnExit() void OPJParseThread::OnExit()
@ -345,14 +350,14 @@ void OPJParseThread::OnExit()
void *OPJParseThread::Entry() void *OPJParseThread::Entry()
{ {
printf("Entering\n\n"); printf("Entering\n\n");
wxString text; wxString text;
srand(GetId()); srand(GetId());
int m_countnum = rand() % 9; int m_countnum = rand() % 9;
text.Printf(wxT("Parse thread 0x%lx started (priority = %u, time = %d)."), text.Printf(wxT("Parse thread 0x%lx started (priority = %u, time = %d)."),
GetId(), GetPriority(), m_countnum); GetId(), GetPriority(), m_countnum);
WriteText(text); WriteText(text);
LoadFile(m_tree->m_fname); LoadFile(m_tree->m_fname);
text.Printf(wxT("Parse thread 0x%lx finished."), GetId()); text.Printf(wxT("Parse thread 0x%lx finished."), GetId());
@ -361,8 +366,8 @@ void *OPJParseThread::Entry()
//wxLogMessage(wxT("Entering\n")); //test wxLog thread safeness //wxLogMessage(wxT("Entering\n")); //test wxLog thread safeness
//wxBusyCursor wait; //wxBusyCursor wait;
//wxBusyInfo wait(wxT("Decoding image ...")); //wxBusyInfo wait(wxT("Decoding image ..."));
/*for ( m_count = 0; m_count < m_countnum; m_count++ ) /*for ( m_count = 0; m_count < m_countnum; m_count++ )
@ -380,7 +385,7 @@ void *OPJParseThread::Entry()
// wxLogMessage(text); -- test wxLog thread safeness // wxLogMessage(text); -- test wxLog thread safeness
printf("Exiting\n\n"); printf("Exiting\n\n");
return NULL; return NULL;
} }
@ -393,7 +398,7 @@ void *OPJParseThread::Entry()
#if USE_GENERIC_TREECTRL #if USE_GENERIC_TREECTRL
BEGIN_EVENT_TABLE(OPJMarkerTree, wxGenericTreeCtrl) BEGIN_EVENT_TABLE(OPJMarkerTree, wxGenericTreeCtrl)
#else #else
BEGIN_EVENT_TABLE(OPJMarkerTree, wxTreeCtrl) BEGIN_EVENT_TABLE(OPJMarkerTree, wxTreeCtrl)
#endif #endif
/*EVT_TREE_BEGIN_DRAG(TreeTest_Ctrl, OPJMarkerTree::OnBeginDrag) /*EVT_TREE_BEGIN_DRAG(TreeTest_Ctrl, OPJMarkerTree::OnBeginDrag)
EVT_TREE_BEGIN_RDRAG(TreeTest_Ctrl, OPJMarkerTree::OnBeginRDrag) EVT_TREE_BEGIN_RDRAG(TreeTest_Ctrl, OPJMarkerTree::OnBeginRDrag)
@ -435,14 +440,16 @@ IMPLEMENT_DYNAMIC_CLASS(OPJMarkerTree, wxGenericTreeCtrl)
IMPLEMENT_DYNAMIC_CLASS(OPJMarkerTree, wxTreeCtrl) IMPLEMENT_DYNAMIC_CLASS(OPJMarkerTree, wxTreeCtrl)
#endif #endif
OPJMarkerTree::OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileName fname, wxString name, const wxWindowID id, OPJMarkerTree::OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe,
const wxPoint& pos, const wxSize& size, long style) wxFileName fname, wxString name, const wxWindowID id,
: wxTreeCtrl(parent, id, pos, size, style) const wxPoint& pos, const wxSize& size, long style)
: wxTreeCtrl(parent, id, pos, size, style)
{ {
m_reverseSort = false; m_reverseSort = false;
m_fname = fname; m_fname = fname;
m_peektextCtrl = ((OPJFrame *) (parent->GetParent()->GetParent()))->m_textCtrlbrowse; m_peektextCtrl = ((OPJFrame *)(
parent->GetParent()->GetParent()))->m_textCtrlbrowse;
CreateImageList(); CreateImageList();
// Add some items to the tree // Add some items to the tree
@ -453,12 +460,13 @@ OPJMarkerTree::OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileNa
new OPJMarkerData(name)); new OPJMarkerData(name));
OPJParseThread *pthread = CreateParseThread(0x00, subframe); OPJParseThread *pthread = CreateParseThread(0x00, subframe);
if (pthread->Run() != wxTHREAD_NO_ERROR) if (pthread->Run() != wxTHREAD_NO_ERROR) {
wxLogMessage(wxT("Can't start parse thread!")); wxLogMessage(wxT("Can't start parse thread!"));
else } else {
wxLogMessage(wxT("New parse thread started.")); wxLogMessage(wxT("New parse thread started."));
}
m_childframe = subframe; m_childframe = subframe;
} }
void OPJMarkerTree::CreateImageList(int size) void OPJMarkerTree::CreateImageList(int size)
@ -467,10 +475,11 @@ void OPJMarkerTree::CreateImageList(int size)
SetImageList(NULL); SetImageList(NULL);
return; return;
} }
if (size == 0) if (size == 0) {
size = m_imageSize; size = m_imageSize;
else } else {
m_imageSize = size; m_imageSize = size;
}
// Make an image list containing small icons // Make an image list containing small icons
wxImageList *images = new wxImageList(size, size, true); wxImageList *images = new wxImageList(size, size, true);
@ -499,7 +508,7 @@ void OPJMarkerTree::CreateImageList(int size)
#if USE_GENERIC_TREECTRL || !defined(__WXMSW__) #if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
void OPJMarkerTree::CreateButtonsImageList(int size) void OPJMarkerTree::CreateButtonsImageList(int size)
{ {
if ( size == -1 ) { if (size == -1) {
SetButtonsImageList(NULL); SetButtonsImageList(NULL);
return; return;
} }
@ -515,9 +524,9 @@ void OPJMarkerTree::CreateButtonsImageList(int size)
icons[2] = wxIcon(icon5_xpm); // open icons[2] = wxIcon(icon5_xpm); // open
icons[3] = wxIcon(icon5_xpm); // open, selected icons[3] = wxIcon(icon5_xpm); // open, selected
for ( size_t i = 0; i < WXSIZEOF(icons); i++ ) { for (size_t i = 0; i < WXSIZEOF(icons); i++) {
int sizeOrig = icons[i].GetWidth(); int sizeOrig = icons[i].GetWidth();
if ( size == sizeOrig ) { if (size == sizeOrig) {
images->Add(icons[i]); images->Add(icons[i]);
} else { } else {
images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size))); images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
@ -533,77 +542,79 @@ void OPJMarkerTree::CreateButtonsImageList(int WXUNUSED(size))
void OPJParseThread::LoadFile(wxFileName fname) void OPJParseThread::LoadFile(wxFileName fname)
{ {
wxTreeItemId rootid; wxTreeItemId rootid;
// this is the root node // this is the root node
int image = wxGetApp().ShowImages() ? m_tree->TreeCtrlIcon_Folder : -1; int image = wxGetApp().ShowImages() ? m_tree->TreeCtrlIcon_Folder : -1;
if (this->m_parentid) { if (this->m_parentid) {
// leaf of a tree // leaf of a tree
rootid = m_parentid; rootid = m_parentid;
m_tree->SetItemText(rootid, wxT("Parsing...")); m_tree->SetItemText(rootid, wxT("Parsing..."));
} else { } else {
// delete the existing tree hierarchy // delete the existing tree hierarchy
m_tree->DeleteAllItems(); m_tree->DeleteAllItems();
// new tree // new tree
rootid = m_tree->AddRoot(wxT("Parsing..."), rootid = m_tree->AddRoot(wxT("Parsing..."),
image, image,
image, image,
new OPJMarkerData(fname.GetFullPath()) new OPJMarkerData(fname.GetFullPath())
); );
//m_tree->SetItemFont(rootid, *wxITALIC_FONT); //m_tree->SetItemFont(rootid, *wxITALIC_FONT);
m_tree->SetItemBold(rootid); m_tree->SetItemBold(rootid);
} }
// open the file // open the file
wxFile m_file(fname.GetFullPath().c_str(), wxFile::read); wxFile m_file(fname.GetFullPath().c_str(), wxFile::read);
// parsing enabled? // parsing enabled?
if (wxGetApp().m_enableparse) { if (wxGetApp().m_enableparse) {
// what is the extension? // what is the extension?
if ((fname.GetExt() == wxT("j2k")) || (fname.GetExt() == wxT("j2c"))) { if ((fname.GetExt() == wxT("j2k")) || (fname.GetExt() == wxT("j2c"))) {
// parse the file // parse the file
ParseJ2KFile(&m_file, 0, m_file.Length(), rootid); ParseJ2KFile(&m_file, 0, m_file.Length(), rootid);
} else if ((fname.GetExt() == wxT("jp2")) || (fname.GetExt() == wxT("mj2"))) { } else if ((fname.GetExt() == wxT("jp2")) || (fname.GetExt() == wxT("mj2"))) {
// parse the file // parse the file
if (this->m_parentid) { if (this->m_parentid) {
//WriteText(wxT("Only a subsection of jp2")); //WriteText(wxT("Only a subsection of jp2"));
OPJMarkerData *data = (OPJMarkerData *) m_tree->GetItemData(rootid); OPJMarkerData *data = (OPJMarkerData *) m_tree->GetItemData(rootid);
ParseJ2KFile(&m_file, data->m_start, data->m_length, rootid); ParseJ2KFile(&m_file, data->m_start, data->m_length, rootid);
m_tree->Expand(rootid); m_tree->Expand(rootid);
} else { } else {
// as usual // as usual
ParseJP2File(&m_file, 0, m_file.Length(), rootid); ParseJP2File(&m_file, 0, m_file.Length(), rootid);
} }
} else { } else {
// unknown extension // unknown extension
WriteText(wxT("Unknown file format!")); WriteText(wxT("Unknown file format!"));
} }
} }
// this is the root node // this is the root node
if (this->m_parentid) if (this->m_parentid) {
m_tree->SetItemText(rootid, wxT("Codestream")); m_tree->SetItemText(rootid, wxT("Codestream"));
else } else
//m_tree->SetItemText(rootid, wxString::Format(wxT("%s (%d B)"), fname.GetFullName(), m_file.Length())); //m_tree->SetItemText(rootid, wxString::Format(wxT("%s (%d B)"), fname.GetFullName(), m_file.Length()));
m_tree->SetItemText(rootid, fname.GetFullName()); {
m_tree->SetItemText(rootid, fname.GetFullName());
}
// close the file // close the file
m_file.Close(); m_file.Close();
WriteText(wxT("Parsing finished!")); WriteText(wxT("Parsing finished!"));
} }
/*int OPJMarkerTree::OnCompareItems(const wxTreeItemId& item1, /*int OPJMarkerTree::OnCompareItems(const wxTreeItemId& item1,
@ -738,19 +749,22 @@ void OPJMarkerTree::LogEvent(const wxChar *name, const wxTreeEvent& event)
{ {
wxTreeItemId item = event.GetItem(); wxTreeItemId item = event.GetItem();
wxString text; wxString text;
if ( item.IsOk() ) if (item.IsOk()) {
text << wxT('"') << GetItemText(item).c_str() << wxT('"'); text << wxT('"') << GetItemText(item).c_str() << wxT('"');
else } else {
text = wxT("invalid item"); text = wxT("invalid item");
}
wxLogMessage(wxT("%s(%s)"), name, text.c_str()); wxLogMessage(wxT("%s(%s)"), name, text.c_str());
} }
OPJParseThread *OPJMarkerTree::CreateParseThread(wxTreeItemId parentid, OPJChildFrame *subframe) OPJParseThread *OPJMarkerTree::CreateParseThread(wxTreeItemId parentid,
OPJChildFrame *subframe)
{ {
OPJParseThread *pthread = new OPJParseThread(this, parentid); OPJParseThread *pthread = new OPJParseThread(this, parentid);
if (pthread->Create() != wxTHREAD_NO_ERROR) if (pthread->Create() != wxTHREAD_NO_ERROR) {
wxLogError(wxT("Can't create parse thread!")); wxLogError(wxT("Can't create parse thread!"));
}
wxCriticalSectionLocker enter(wxGetApp().m_parse_critsect); wxCriticalSectionLocker enter(wxGetApp().m_parse_critsect);
wxGetApp().m_parse_threads.Add(pthread); wxGetApp().m_parse_threads.Add(pthread);
@ -782,114 +796,122 @@ TREE_EVENT_HANDLER(OnSelChanging)*/
void OPJMarkerTree::OnItemExpanding(wxTreeEvent& event) void OPJMarkerTree::OnItemExpanding(wxTreeEvent& event)
{ {
wxTreeItemId item = event.GetItem(); wxTreeItemId item = event.GetItem();
OPJMarkerData* data = (OPJMarkerData *) GetItemData(item); OPJMarkerData* data = (OPJMarkerData *) GetItemData(item);
wxString text; wxString text;
if (item.IsOk()) if (item.IsOk()) {
text << wxT('"') << GetItemText(item).c_str() << wxT('"'); text << wxT('"') << GetItemText(item).c_str() << wxT('"');
else } else {
text = wxT("invalid item"); text = wxT("invalid item");
}
if (wxStrcmp(data->GetDesc1(), wxT("INFO-CSTREAM"))) if (wxStrcmp(data->GetDesc1(), wxT("INFO-CSTREAM"))) {
return; return;
}
wxLogMessage(wxT("Expanding... (%s -> %s, %s, %d, %d)"), wxLogMessage(wxT("Expanding... (%s -> %s, %s, %d, %d)"),
text.c_str(), data->GetDesc1(), data->GetDesc2(), text.c_str(), data->GetDesc1(), data->GetDesc2(),
data->m_start, data->m_length); data->m_start, data->m_length);
// the codestream box is being asked for expansion // the codestream box is being asked for expansion
wxTreeItemIdValue cookie; wxTreeItemIdValue cookie;
if (!GetFirstChild(item, cookie).IsOk()) { if (!GetFirstChild(item, cookie).IsOk()) {
OPJParseThread *pthread = CreateParseThread(item); OPJParseThread *pthread = CreateParseThread(item);
if (pthread->Run() != wxTHREAD_NO_ERROR) if (pthread->Run() != wxTHREAD_NO_ERROR) {
wxLogMessage(wxT("Can't start parse thread!")); wxLogMessage(wxT("Can't start parse thread!"));
else } else {
wxLogMessage(wxT("New parse thread started.")); wxLogMessage(wxT("New parse thread started."));
} }
}
} }
void OPJMarkerTree::OnSelChanged(wxTreeEvent& event) void OPJMarkerTree::OnSelChanged(wxTreeEvent& event)
{ {
int bunch_linesize = 16; int bunch_linesize = 16;
int bunch_numlines = 7; int bunch_numlines = 7;
wxTreeItemId item = event.GetItem(); wxTreeItemId item = event.GetItem();
OPJMarkerData* data = (OPJMarkerData *) GetItemData(item); OPJMarkerData* data = (OPJMarkerData *) GetItemData(item);
wxString text; wxString text;
int l, c, pos = 0, pre_pos; int l, c, pos = 0, pre_pos;
m_peektextCtrl->Clear(); m_peektextCtrl->Clear();
/*text << wxString::Format(wxT("Selected... (%s -> %s, %s, %d, %d)"), /*text << wxString::Format(wxT("Selected... (%s -> %s, %s, %d, %d)"),
text.c_str(), data->GetDesc1(), data->GetDesc2(), text.c_str(), data->GetDesc1(), data->GetDesc2(),
data->m_start, data->m_length) << wxT("\n");*/ data->m_start, data->m_length) << wxT("\n");*/
// open the file and browse a little // open the file and browse a little
wxFile *fp = new wxFile(m_fname.GetFullPath().c_str(), wxFile::read); wxFile *fp = new wxFile(m_fname.GetFullPath().c_str(), wxFile::read);
// go to position claimed // go to position claimed
fp->Seek(data->m_start, wxFromStart); fp->Seek(data->m_start, wxFromStart);
// read a bunch // read a bunch
int max_read = wxMin(wxFileOffset(bunch_linesize * bunch_numlines), data->m_length - data->m_start + 1); int max_read = wxMin(wxFileOffset(bunch_linesize * bunch_numlines),
if (data->m_desc == wxT("MARK (65380)")) { data->m_length - data->m_start + 1);
/*wxLogMessage(data->m_desc);*/ if (data->m_desc == wxT("MARK (65380)")) {
max_read = data->m_length - data->m_start + 1; /*wxLogMessage(data->m_desc);*/
bunch_numlines = (int) ceil((float) max_read / (float) bunch_linesize); max_read = data->m_length - data->m_start + 1;
} bunch_numlines = (int) ceil((float) max_read / (float) bunch_linesize);
unsigned char *buffer = new unsigned char[bunch_linesize * bunch_numlines]; }
fp->Read(buffer, max_read); unsigned char *buffer = new unsigned char[bunch_linesize * bunch_numlines];
fp->Read(buffer, max_read);
// write the file data between start and stop // write the file data between start and stop
pos = 0; pos = 0;
for (l = 0; l < bunch_numlines; l++) { for (l = 0; l < bunch_numlines; l++) {
text << wxString::Format(wxT("%010d:"), data->m_start + pos); text << wxString::Format(wxT("%010d:"), data->m_start + pos);
pre_pos = pos; pre_pos = pos;
// add hex browsing text // add hex browsing text
for (c = 0; c < bunch_linesize; c++) { for (c = 0; c < bunch_linesize; c++) {
if (!(c % 8)) if (!(c % 8)) {
text << wxT(" "); text << wxT(" ");
}
if (pos < max_read) { if (pos < max_read) {
text << wxString::Format(wxT("%02X "), buffer[pos]); text << wxString::Format(wxT("%02X "), buffer[pos]);
} else } else {
text << wxT(" "); text << wxT(" ");
pos++; }
} pos++;
}
text << wxT(" "); text << wxT(" ");
// add char browsing text // add char browsing text
for (c = 0; c < bunch_linesize; c++) { for (c = 0; c < bunch_linesize; c++) {
if (pre_pos < max_read) { if (pre_pos < max_read) {
if ((buffer[pre_pos] == '\n') || if ((buffer[pre_pos] == '\n') ||
(buffer[pre_pos] == '\t') || (buffer[pre_pos] == '\t') ||
(buffer[pre_pos] == '\0') || (buffer[pre_pos] == '\0') ||
(buffer[pre_pos] == 0x0D) || (buffer[pre_pos] == 0x0D) ||
(buffer[pre_pos] == 0x0B)) (buffer[pre_pos] == 0x0B)) {
buffer[pre_pos] = ' '; buffer[pre_pos] = ' ';
text << wxString::FromAscii((char) buffer[pre_pos]) << wxT("."); }
} else text << wxString::FromAscii((char) buffer[pre_pos]) << wxT(".");
text << wxT(" "); } else {
pre_pos++; text << wxT(" ");
} }
pre_pos++;
}
text << wxT("\n"); text << wxT("\n");
} }
// close the file // close the file
fp->Close(); fp->Close();
m_peektextCtrl->WriteText(text); m_peektextCtrl->WriteText(text);
delete [] buffer; delete [] buffer;
} }
/*void LogKeyEvent(const wxChar *name, const wxKeyEvent& event) /*void LogKeyEvent(const wxChar *name, const wxKeyEvent& event)
@ -1148,7 +1170,7 @@ void OPJMarkerTree::OnItemMenu(wxTreeEvent& event)
wxLogMessage(wxT("OnItemMenu for item \"%s\""), item ? item->GetDesc() wxLogMessage(wxT("OnItemMenu for item \"%s\""), item ? item->GetDesc()
: _T(""));*/ : _T(""));*/
//wxLogMessage(wxT("EEEEEEEEEE")); //wxLogMessage(wxT("EEEEEEEEEE"));
//event.Skip(); //event.Skip();
} }
@ -1269,5 +1291,3 @@ void OPJMarkerData::ShowInfo(wxTreeCtrl *tree)
unsigned(tree->GetChildrenCount(GetId())), unsigned(tree->GetChildrenCount(GetId())),
unsigned(tree->GetChildrenCount(GetId(), false))); unsigned(tree->GetChildrenCount(GetId(), false)));
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff