2 * Copyright (c) 2007, Digital Signal Processing Laboratory, Universit� degli studi di Perugia (UPG), Italy
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
8 * 1. Redistributions of source code must retain the above copyright
\r
9 * notice, this list of conditions and the following disclaimer.
\r
10 * 2. Redistributions in binary form must reproduce the above copyright
\r
11 * notice, this list of conditions and the following disclaimer in the
\r
12 * documentation and/or other materials provided with the distribution.
\r
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
\r
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
\r
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
\r
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
\r
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
\r
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
24 * POSSIBILITY OF SUCH DAMAGE.
\r
26 /////////////////////////////////////////////////////////////////////////////
\r
28 // Purpose: Layout window/sash sample
\r
29 // Author: Julian Smart
\r
31 // Created: 04/01/98
\r
32 // RCS-ID: $Id: sashtest.h,v 1.5 2005/06/02 12:04:24 JS Exp $
\r
33 // Copyright: (c) Julian Smart
\r
34 // Licence: wxWindows license
\r
35 /////////////////////////////////////////////////////////////////////////////
\r
36 /////////////////////////////////////////////////////////////////////////////
\r
38 // Purpose: wxTreeCtrl sample
\r
39 // Author: Julian Smart
\r
41 // Created: 04/01/98
\r
42 // RCS-ID: $Id: treetest.h,v 1.50 2006/11/04 11:26:51 VZ Exp $
\r
43 // Copyright: (c) Julian Smart
\r
44 // Licence: wxWindows license
\r
45 /////////////////////////////////////////////////////////////////////////////
\r
46 /////////////////////////////////////////////////////////////////////////////
\r
48 // Purpose: Common dialogs demo
\r
49 // Author: Julian Smart
\r
50 // Modified by: ABX (2004) - adjustementd for conditional building
\r
51 // Created: 04/01/98
\r
52 // RCS-ID: $Id: dialogs.h,v 1.50 2006/10/08 14:12:59 VZ Exp $
\r
53 // Copyright: (c) Julian Smart
\r
54 // Licence: wxWindows license
\r
55 /////////////////////////////////////////////////////////////////////////////
\r
57 #ifndef __OPJ_VIEWER_H__
\r
58 #define __OPJ_VIEWER_H__
\r
60 // For compilers that support precompilation, includes "wx/wx.h".
\r
61 #include "wx/wxprec.h"
\r
72 #include "wx/toolbar.h"
\r
73 #include "wx/laywin.h"
\r
74 #include "wx/treectrl.h"
\r
76 #include "icon1.xpm"
\r
77 #include "icon2.xpm"
\r
78 #include "icon3.xpm"
\r
79 #include "icon4.xpm"
\r
80 #include "icon5.xpm"
\r
82 #include "wx/filedlg.h"
\r
83 #include "wx/toolbar.h"
\r
84 #include <wx/filename.h>
\r
85 #include <wx/busyinfo.h>
\r
86 #include <wx/cmdline.h>
\r
87 #include <wx/file.h>
\r
88 #include "wx/notebook.h"
\r
89 #include <wx/numdlg.h>
\r
91 #include "wx/propdlg.h"
\r
92 #include "wx/spinctrl.h"
\r
95 #include "wx/wxhtml.h"
\r
96 #include "wx/statline.h"
\r
98 #include "libopenjpeg\openjpeg.h"
\r
100 #include "imagj2k.h"
\r
101 #include "imagjp2.h"
\r
102 #include "imagmj2.h"
\r
105 typedef unsigned __int64 int8byte;
\r
106 #endif // __WXMSW__
\r
109 typedef unsigned long long int8byte;
\r
110 #endif // __WXGTK__
\r
112 #define USE_GENERIC_TREECTRL 0
\r
114 #if USE_GENERIC_TREECTRL
\r
115 #include "wx/generic/treectlg.h"
\r
117 #define wxTreeCtrl wxGenericTreeCtrl
\r
118 #define sm_classwxTreeCtrl sm_classwxGenericTreeCtrl
\r
122 #define OPJ_APPLICATION_NAME wxT("OpenJPEG Viewer")
\r
123 #define OPJ_APPLICATION_VERSION wxT("0.2 alpha")
\r
124 #define OPJ_APPLICATION_TITLEBAR OPJ_APPLICATION_NAME wxT(" ") OPJ_APPLICATION_VERSION
\r
125 #define OPJ_APPLICATION_COPYRIGHT wxT("(C) 2007, Giuseppe Baruffa")
\r
127 #define OPJ_CANVAS_BORDER 10
\r
128 #define OPJ_CANVAS_COLOUR *wxWHITE
\r
130 class OPJDecoThread;
\r
131 class OPJParseThread;
\r
132 WX_DEFINE_ARRAY_PTR(wxThread *, wxArrayThread);
\r
133 class OPJChildFrame;
\r
135 //////////////////////////////////
\r
136 // this is our main application //
\r
137 //////////////////////////////////
\r
138 class OPJViewerApp: public wxApp
\r
140 // public methods and variables
\r
143 // class constructor
\r
144 OPJViewerApp() { m_showImages = true; m_showButtons = false; }
\r
148 void SetShowImages(bool show) { m_showImages = show; }
\r
149 bool ShowImages() const { return m_showImages; }
\r
150 void ShowCmdLine(const wxCmdLineParser& parser);
\r
152 // all the threads currently alive - as soon as the thread terminates, it's
\r
153 // removed from the array
\r
154 wxArrayThread m_deco_threads, m_parse_threads;
\r
156 // crit section protects access to all of the arrays below
\r
157 wxCriticalSection m_deco_critsect, m_parse_critsect;
\r
159 // semaphore used to wait for the threads to exit, see OPJFrame::OnQuit()
\r
160 wxSemaphore m_deco_semAllDone, m_parse_semAllDone;
\r
162 // the last exiting thread should post to m_semAllDone if this is true
\r
163 // (protected by the same m_critsect)
\r
164 bool m_deco_waitingUntilAllDone, m_parse_waitingUntilAllDone;
\r
166 // the list of all filenames written in the command line
\r
167 wxArrayString m_filelist;
\r
169 // decoding engine parameters
\r
170 int m_reducefactor, m_qualitylayers, m_components;
\r
173 int m_expcomps, m_maxtiles;
\r
176 // private methods and variables
\r
178 bool m_showImages, m_showButtons;
\r
182 DECLARE_APP(OPJViewerApp)
\r
184 ///////////////////////////////////////////
\r
185 // this canvas is used to draw the image //
\r
186 ///////////////////////////////////////////
\r
187 class OPJCanvas: public wxScrolledWindow
\r
189 // public methods and variables
\r
192 // class constructor
\r
193 OPJCanvas(wxFileName fname, wxWindow *parent, const wxPoint& pos, const wxSize& size);
\r
195 virtual void OnDraw(wxDC& dc);
\r
196 void OnEvent(wxMouseEvent& event);
\r
197 void WriteText(const wxString& text) { wxMutexGuiEnter(); wxLogMessage(text); wxMutexGuiLeave();}
\r
198 OPJDecoThread *CreateDecoThread(void);
\r
199 OPJChildFrame *m_childframe;
\r
201 wxBitmap m_image, m_image100;
\r
202 wxFileName m_fname;
\r
205 DECLARE_EVENT_TABLE()
\r
208 ///////////////////////////////////////////////////
\r
209 // the data associated to each tree leaf or node //
\r
210 ///////////////////////////////////////////////////
\r
211 class OPJMarkerData : public wxTreeItemData
\r
213 // public methods and variables
\r
216 // class constructor
\r
217 OPJMarkerData(const wxString& desc, const wxString& fname = wxT(""), wxFileOffset start = 0, wxFileOffset length = 0) : m_desc(desc), m_filestring(fname) { m_start = start; m_length = length; }
\r
219 void ShowInfo(wxTreeCtrl *tree);
\r
220 const wxChar *GetDesc1() const { return m_desc.c_str(); }
\r
221 const wxChar *GetDesc2() const { return m_filestring.c_str(); }
\r
222 wxFileOffset m_start, m_length;
\r
224 // private methods and variables
\r
227 wxString m_filestring;
\r
231 class OPJMarkerTree : public wxTreeCtrl
\r
237 TreeCtrlIcon_FileSelected,
\r
238 TreeCtrlIcon_Folder,
\r
239 TreeCtrlIcon_FolderSelected,
\r
240 TreeCtrlIcon_FolderOpened
\r
243 OPJMarkerTree() { };
\r
244 OPJMarkerTree(wxWindow *parent, wxFileName fname, wxString name, const wxWindowID id,
\r
245 const wxPoint& pos, const wxSize& size,
\r
247 virtual ~OPJMarkerTree(){};
\r
248 OPJParseThread *CreateParseThread(wxTreeItemId parentid = 0x00);
\r
249 void WriteText(const wxString& text) { wxMutexGuiEnter(); wxLogMessage(text); wxMutexGuiLeave(); }
\r
251 wxFileName m_fname;
\r
252 wxTextCtrl *m_peektextCtrl;
\r
254 /*void OnBeginDrag(wxTreeEvent& event);
\r
255 void OnBeginRDrag(wxTreeEvent& event);
\r
256 void OnEndDrag(wxTreeEvent& event);*/
\r
257 /*void OnBeginLabelEdit(wxTreeEvent& event);
\r
258 void OnEndLabelEdit(wxTreeEvent& event);*/
\r
259 /*void OnDeleteItem(wxTreeEvent& event);*/
\r
260 /*void OnContextMenu(wxContextMenuEvent& event);*/
\r
261 void OnItemMenu(wxTreeEvent& event);
\r
262 /*void OnGetInfo(wxTreeEvent& event);
\r
263 void OnSetInfo(wxTreeEvent& event);*/
\r
264 /*void OnItemExpanded(wxTreeEvent& event);*/
\r
265 void OnItemExpanding(wxTreeEvent& event);
\r
266 /*void OnItemCollapsed(wxTreeEvent& event);
\r
267 void OnItemCollapsing(wxTreeEvent& event);*/
\r
268 void OnSelChanged(wxTreeEvent& event);
\r
269 /*void OnSelChanging(wxTreeEvent& event);*/
\r
270 /*void OnTreeKeyDown(wxTreeEvent& event);*/
\r
271 /*void OnItemActivated(wxTreeEvent& event);*/
\r
272 /*void OnItemRClick(wxTreeEvent& event);*/
\r
273 /*void OnRMouseDown(wxMouseEvent& event);
\r
274 void OnRMouseUp(wxMouseEvent& event);
\r
275 void OnRMouseDClick(wxMouseEvent& event);*/
\r
276 /*void GetItemsRecursively(const wxTreeItemId& idParent,
\r
277 wxTreeItemIdValue cookie = 0);*/
\r
279 void CreateImageList(int size = 16);
\r
280 void CreateButtonsImageList(int size = 11);
\r
282 /*void AddTestItemsToTree(size_t numChildren, size_t depth);*/
\r
283 /*void DoSortChildren(const wxTreeItemId& item, bool reverse = false)
\r
284 { m_reverseSort = reverse; wxTreeCtrl::SortChildren(item); }*/
\r
285 /*void DoEnsureVisible() { if (m_lastItem.IsOk()) EnsureVisible(m_lastItem); }*/
\r
286 /*void DoToggleIcon(const wxTreeItemId& item);*/
\r
287 /*void ShowMenu(wxTreeItemId id, const wxPoint& pt);*/
\r
289 int ImageSize(void) const { return m_imageSize; }
\r
291 void SetLastItem(wxTreeItemId id) { m_lastItem = id; }
\r
294 /*virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);*/
\r
296 // is this the test item which we use in several event handlers?
\r
297 /*bool IsTestItem(const wxTreeItemId& item)
\r
299 // the test item is the first child folder
\r
300 return GetItemParent(item) == GetRootItem() && !GetPrevSibling(item);
\r
304 /*void AddItemsRecursively(const wxTreeItemId& idParent,
\r
309 void LogEvent(const wxChar *name, const wxTreeEvent& event);
\r
311 int m_imageSize; // current size of images
\r
312 bool m_reverseSort; // flag for OnCompareItems
\r
313 wxTreeItemId m_lastItem, // for OnEnsureVisible()
\r
314 m_draggedItem; // item being dragged right now
\r
316 // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS()
\r
317 // if you want your overloaded OnCompareItems() to be called.
\r
318 // OTOH, if you don't want it you may omit the next line - this will
\r
319 // make default (alphabetical) sorting much faster under wxMSW.
\r
320 DECLARE_DYNAMIC_CLASS(OPJMarkerTree)
\r
321 DECLARE_EVENT_TABLE()
\r
324 // this hash map stores all the trees of currently opened images, with an integer key
\r
325 WX_DECLARE_HASH_MAP(int, OPJMarkerTree*, wxIntegerHash, wxIntegerEqual, OPJMarkerTreeHash);
\r
327 // this hash map stores all the children of currently opened images, with an integer key
\r
328 WX_DECLARE_HASH_MAP(int, OPJChildFrame*, wxIntegerHash, wxIntegerEqual, OPJChildFrameHash);
\r
330 // Define a new frame
\r
331 class OPJFrame: public wxMDIParentFrame
\r
335 OPJFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
\r
338 void OnSize(wxSizeEvent& event);
\r
339 void OnAbout(wxCommandEvent& WXUNUSED(event));
\r
340 void OnFileOpen(wxCommandEvent& WXUNUSED(event));
\r
341 void OnQuit(wxCommandEvent& WXUNUSED(event));
\r
342 void OnClose(wxCommandEvent& WXUNUSED(event));
\r
343 void OnZoom(wxCommandEvent& WXUNUSED(event));
\r
344 void OnFit(wxCommandEvent& WXUNUSED(event));
\r
345 void OnToggleWindow(wxCommandEvent& WXUNUSED(event));
\r
346 void OnSetsDeco(wxCommandEvent& event);
\r
347 void OnSashDrag(wxSashEvent& event);
\r
348 void OpenFiles(wxArrayString paths, wxArrayString filenames);
\r
349 void OnNotebook(wxNotebookEvent& event);
\r
350 void Rescale(int scale, OPJChildFrame *child);
\r
352 OPJMarkerTreeHash m_treehash;
\r
353 OPJChildFrameHash m_childhash;
\r
354 wxSashLayoutWindow* markerTreeWindow;
\r
355 wxSashLayoutWindow* loggingWindow;
\r
356 void Resize(int number);
\r
357 wxNotebook *m_bookCtrl;
\r
358 wxNotebook *m_bookCtrlbottom;
\r
359 wxTextCtrl *m_textCtrlbrowse;
\r
362 void TogStyle(int id, long flag);
\r
364 void DoSort(bool reverse = false);
\r
367 wxTextCtrl *m_textCtrl;
\r
369 void DoSetBold(bool bold = true);
\r
372 wxSashLayoutWindow* m_topWindow;
\r
373 wxSashLayoutWindow* m_leftWindow2;
\r
375 DECLARE_EVENT_TABLE()
\r
378 class OPJChildFrame: public wxMDIChildFrame
\r
381 OPJCanvas *m_canvas;
\r
382 OPJChildFrame(OPJFrame *parent, wxFileName fname, int winnumber, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
\r
383 ~OPJChildFrame(void);
\r
384 void OnActivate(wxActivateEvent& event);
\r
385 /*void OnQuit(wxCommandEvent& WXUNUSED(event));*/
\r
386 void OnClose(wxCloseEvent& event);
\r
387 void OnGotFocus(wxFocusEvent& event);
\r
388 void OnLostFocus(wxFocusEvent& event);
\r
390 wxFileName m_fname;
\r
393 DECLARE_EVENT_TABLE()
\r
396 // frame and main menu ids
\r
398 OPJFRAME_FILEEXIT = wxID_EXIT,
\r
399 OPJFRAME_HELPABOUT = wxID_ABOUT,
\r
401 OPJFRAME_FILETOGGLE,
\r
404 OPJFRAME_FILECLOSE,
\r
407 OPJFRAME_BROWSEWIN = 10000,
\r
412 // menu and control ids
\r
415 TreeTest_Quit = wxID_EXIT,
\r
416 TreeTest_About = wxID_ABOUT,
\r
417 TreeTest_TogButtons = wxID_HIGHEST,
\r
421 TreeTest_TogHideRoot,
\r
422 TreeTest_TogRootLines,
\r
423 TreeTest_TogBorder,
\r
424 TreeTest_TogFullHighlight,
\r
425 TreeTest_SetFgColour,
\r
426 TreeTest_SetBgColour,
\r
427 TreeTest_ResetStyle,
\r
428 TreeTest_Highlight,
\r
430 TreeTest_DumpSelected,
\r
436 TreeTest_ClearBold,
\r
439 TreeTest_DeleteChildren,
\r
440 TreeTest_DeleteAll,
\r
442 TreeTest_ToggleImages,
\r
443 TreeTest_ToggleButtons,
\r
444 TreeTest_SetImageSize,
\r
445 TreeTest_ToggleSel,
\r
446 TreeTest_CollapseAndReset,
\r
447 TreeTest_EnsureVisible,
\r
449 TreeTest_InsertItem,
\r
450 TreeTest_IncIndent,
\r
451 TreeTest_DecIndent,
\r
452 TreeTest_IncSpacing,
\r
453 TreeTest_DecSpacing,
\r
454 TreeTest_ToggleIcon,
\r
457 TreeTest_SelectRoot,
\r
458 TreeTest_Ctrl = 1000,
\r
459 BOTTOM_NOTEBOOK_ID,
\r
463 class OPJDecoThread : public wxThread
\r
466 OPJDecoThread(OPJCanvas *canvas);
\r
468 // thread execution starts here
\r
469 virtual void *Entry();
\r
471 // called when the thread exits - whether it terminates normally or is
\r
472 // stopped with Delete() (but not when it is Kill()ed!)
\r
473 virtual void OnExit();
\r
475 // write something to the text control
\r
476 void WriteText(const wxString& text);
\r
480 OPJCanvas *m_canvas;
\r
483 class OPJParseThread : public wxThread
\r
486 OPJParseThread(OPJMarkerTree *tree, wxTreeItemId parentid = 0x00);
\r
488 // thread execution starts here
\r
489 virtual void *Entry();
\r
491 // called when the thread exits - whether it terminates normally or is
\r
492 // stopped with Delete() (but not when it is Kill()ed!)
\r
493 virtual void OnExit();
\r
495 // write something to the text control
\r
496 void WriteText(const wxString& text);
\r
497 void LoadFile(wxFileName fname);
\r
498 void ParseJ2KFile(wxFile *m_file, wxFileOffset offset, wxFileOffset length, wxTreeItemId parentid);
\r
499 void ParseJP2File(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit, wxTreeItemId parentid);
\r
502 OPJMarkerTree *m_tree;
\r
503 wxTreeItemId m_parentid;
\r
506 int jpeg2000parse(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit,
\r
507 wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
\r
508 int box_handler_function(int boxtype, wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit,
\r
509 wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
\r
514 // Drag and drop files target
\r
515 class OPJDnDFile: public wxFileDropTarget
\r
518 OPJDnDFile(OPJFrame *pOwner) { m_pOwner = pOwner; }
\r
519 virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
\r
522 OPJFrame *m_pOwner;
\r
527 // Property sheet dialog
\r
528 class OPJDecoderDialog: public wxPropertySheetDialog
\r
530 DECLARE_CLASS(OPJDecoderDialog)
\r
532 OPJDecoderDialog(wxWindow* parent, int dialogType);
\r
533 ~OPJDecoderDialog();
\r
535 wxSpinCtrl *m_reduceCtrl, *m_layerCtrl, *m_numcompsCtrl;
\r
537 wxPanel* CreateMainSettingsPage(wxWindow* parent);
\r
539 void OnEnableJPWL(wxCommandEvent& event);
\r
540 wxPanel* CreateJPWLSettingsPage(wxWindow* parent);
\r
541 wxSpinCtrl *m_expcompsCtrl, *m_maxtilesCtrl;
\r
542 wxCheckBox *m_enablejpwlCheck;
\r
549 OPJDECO_REDUCEFACTOR = 100,
\r
550 OPJDECO_QUALITYLAYERS,
\r
552 OPJDECO_ENABLEJPWL,
\r
557 wxImageList* m_imageList;
\r
559 DECLARE_EVENT_TABLE()
\r
562 #endif //__OPJ_VIEWER_H__
\r