In opjviewer, unification of JPEG 2000 family handlers (*.jp2, *.mj2, *.j2k) in a single file

This commit is contained in:
Giuseppe Baruffa 2008-01-31 14:36:06 +00:00
parent 04966097fc
commit e21d865440
18 changed files with 1842 additions and 2190 deletions

View File

@ -5,6 +5,9 @@ What's New for OpenJPEG
! : changed ! : changed
+ : added + : added
January 31, 2008
! [GB] In opjviewer, unification of JPEG 2000 family handlers (*.jp2, *.mj2, *.j2k) in a single file
January 22, 2008 January 22, 2008
! [FOD] In image.c, changed the opj_image_create0() memory allocation from malloc() to calloc() in order ! [FOD] In image.c, changed the opj_image_create0() memory allocation from malloc() to calloc() in order
to avoid segfaults when freeing the memory allocated for the coding of bad images. to avoid segfaults when freeing the memory allocated for the coding of bad images.

View File

@ -42,16 +42,16 @@ 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 ".." /I "../libopenjpeg" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D WINVER=0x400 /D "_MT" /D wxUSE_GUI=1 /D "wxUSE_LIBOPENJPEG" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /D "USE_MXF" /D "OPJ_HTMLABOUT" /D "OPJ_MANYFORMATS" /D "OPJ_INICONFIG" /FR /FD /c # ADD CPP /nologo /G6 /MD /W3 /GX /O2 /I "$(WXWIN28)\lib\vc_lib\msw" /I "$(WXWIN28)\include" /I ".." /I "..\libopenjpeg" /I "$(MXFLIB)" /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 /Zm200 /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 "$(WXWIN28)\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 mxflib.lib /nologo /subsystem:windows /machine:I386 /nodefaultlib:"libcmt.lib" /libpath:"$(WXWIN28)\lib\vc_lib" /libpath:"..\jpwl\Release" /libpath:"$(MXFLIB)\build\msvc\Release" /IGNORE:4089
# SUBTRACT LINK32 /pdb:none # SUBTRACT LINK32 /pdb:none /nodefaultlib
# Begin Special Build Tool # Begin Special Build Tool
SOURCE="$(InputPath)" SOURCE="$(InputPath)"
PostBuild_Desc=Update build number PostBuild_Desc=Update build number
@ -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 "$(WXWIN28)\INCLUDE" /I "$(WXWIN28)\lib\vc_lib\msw" /I "$(WXWIN28)\include" /I ".." /I "..\libopenjpeg" /I "$(MXFLIB)" /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" /D "OPJ_INICONFIG" /D "OPJ_MANYFORMATS" /D "USE_JPSEC" /FR /FD /GZ /Zm200 /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 "$(WXWIN28)\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 mxflib.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"libcmtd.lib" /pdbtype:sept /libpath:"$(WXWIN28)\lib\vc_lib" /libpath:"..\jpwl\Debug" /libpath:"$(MXFLIB)\build\msvc\Debug"
# SUBTRACT LINK32 /pdb:none # SUBTRACT LINK32 /pdb:none
!ENDIF !ENDIF
@ -94,20 +94,7 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File # Begin Source File
SOURCE=.\source\imagj2k.cpp
# End Source File
# Begin Source File
SOURCE=.\source\imagjp2.cpp
# End Source File
# Begin Source File
SOURCE=.\source\imagjpeg2000.cpp SOURCE=.\source\imagjpeg2000.cpp
# PROP Exclude_From_Build 1
# End Source File
# Begin Source File
SOURCE=.\source\imagmj2.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
@ -152,27 +139,11 @@ SOURCE=.\source\about_htm.h
# Begin Source File # Begin Source File
SOURCE=.\source\build.h SOURCE=.\source\build.h
!IF "$(CFG)" == "OPJViewer - Win32 Release"
# PROP Exclude_From_Build 1 # PROP Exclude_From_Build 1
!ELSEIF "$(CFG)" == "OPJViewer - Win32 Debug"
!ENDIF
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\source\imagj2k.h SOURCE=.\source\imagjpeg2000.h
# End Source File
# Begin Source File
SOURCE=.\source\imagjp2.h
# End Source File
# Begin Source File
SOURCE=.\source\imagmj2.h
# End Source File # End Source File
# Begin Source File # Begin Source File

View File

@ -30,6 +30,18 @@ Package=<4>
############################################################################### ###############################################################################
Project: "mxflib"="..\..\..\..\mxflib-1.0.0\build\msvc\mxflib.dsp" - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global: Global:
Package=<5> Package=<5>

View File

@ -0,0 +1,87 @@
/*
* Copyright (c) 2007, Digital Signal Processing Laboratory, Universita'  degli studi di Perugia (UPG), Italy
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef USE_MXF
#include "mxflib/mxflib.h"
#endif // USE_MXF
#include "OPJViewer.h"
// about window for the frame
void OPJFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
#ifdef OPJ_HTMLABOUT
#include "about_htm.h"
#include "opj_logo.xpm"
wxBoxSizer *topsizer;
wxHtmlWindow *html;
wxDialog dlg(this, wxID_ANY, wxString(_("About")));
wxMemoryFSHandler::AddFile(wxT("opj_logo.xpm"), wxBitmap(opj_logo), wxBITMAP_TYPE_XPM);
topsizer = new wxBoxSizer(wxVERTICAL);
html = new wxHtmlWindow(&dlg, wxID_ANY, wxDefaultPosition, wxSize(320, 250), wxHW_SCROLLBAR_NEVER);
html->SetBorders(0);
//html->LoadPage(wxT("about/about.htm"));
//html->SetPage("<html><body>Hello, world!</body></html>");
html->SetPage(htmlaboutpage);
html->SetSize(html->GetInternalRepresentation()->GetWidth(),
html->GetInternalRepresentation()->GetHeight());
topsizer->Add(html, 1, wxALL, 10);
topsizer->Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
wxButton *bu1 = new wxButton(&dlg, wxID_OK, wxT("OK"));
bu1->SetDefault();
topsizer->Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15);
dlg.SetSizer(topsizer);
topsizer->Fit(&dlg);
dlg.ShowModal();
#else
wxMessageBox(wxString::Format(OPJ_APPLICATION_TITLEBAR
wxT("\n\n")
wxT("Built with %s and OpenJPEG ")
wxT(OPENJPEG_VERSION)
wxT("\non ") wxT(__DATE__) wxT(", ") wxT(__TIME__)
wxT("\nRunning under %s\n\n")
OPJ_APPLICATION_COPYRIGHT,
wxVERSION_STRING,
wxGetOsDescription().c_str()),
wxT("About ") OPJ_APPLICATION_NAME,
wxOK | wxICON_INFORMATION,
this
);
#endif
}

View File

@ -86,37 +86,37 @@ void *OPJEncoThread::Entry()
WriteText(text); WriteText(text);
// set handler properties // set handler properties
wxJ2KHandler *j2kkkhandler = (wxJ2KHandler *) wxImage::FindHandler( wxBITMAP_TYPE_J2K); wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(wxBITMAP_TYPE_JPEG2000);
j2kkkhandler->m_subsampling = wxGetApp().m_subsampling; jpeg2000handler->m_subsampling = wxGetApp().m_subsampling;
j2kkkhandler->m_origin = wxGetApp().m_origin; jpeg2000handler->m_origin = wxGetApp().m_origin;
j2kkkhandler->m_rates = wxGetApp().m_rates; jpeg2000handler->m_rates = wxGetApp().m_rates;
j2kkkhandler->m_quality = wxGetApp().m_quality; jpeg2000handler->m_quality = wxGetApp().m_quality;
j2kkkhandler->m_enablequality = wxGetApp().m_enablequality; jpeg2000handler->m_enablequality = wxGetApp().m_enablequality;
j2kkkhandler->m_multicomp = wxGetApp().m_multicomp; jpeg2000handler->m_multicomp = wxGetApp().m_multicomp;
j2kkkhandler->m_irreversible = wxGetApp().m_irreversible; jpeg2000handler->m_irreversible = wxGetApp().m_irreversible;
j2kkkhandler->m_resolutions = wxGetApp().m_resolutions; jpeg2000handler->m_resolutions = wxGetApp().m_resolutions;
j2kkkhandler->m_progression = wxGetApp().m_progression; jpeg2000handler->m_progression = wxGetApp().m_progression;
j2kkkhandler->m_cbsize = wxGetApp().m_cbsize; jpeg2000handler->m_cbsize = wxGetApp().m_cbsize;
j2kkkhandler->m_prsize = wxGetApp().m_prsize; jpeg2000handler->m_prsize = wxGetApp().m_prsize;
j2kkkhandler->m_tsize = wxGetApp().m_tsize; jpeg2000handler->m_tsize = wxGetApp().m_tsize;
j2kkkhandler->m_torigin = wxGetApp().m_torigin; jpeg2000handler->m_torigin = wxGetApp().m_torigin;
j2kkkhandler->m_enablesop = wxGetApp().m_enablesop; jpeg2000handler->m_enablesop = wxGetApp().m_enablesop;
j2kkkhandler->m_enableeph = wxGetApp().m_enableeph; jpeg2000handler->m_enableeph = wxGetApp().m_enableeph;
j2kkkhandler->m_enablebypass = wxGetApp().m_enablebypass; jpeg2000handler->m_enablebypass = wxGetApp().m_enablebypass;
j2kkkhandler->m_enablerestart = wxGetApp().m_enablerestart; jpeg2000handler->m_enablerestart = wxGetApp().m_enablerestart;
j2kkkhandler->m_enablereset = wxGetApp().m_enablereset; jpeg2000handler->m_enablereset = wxGetApp().m_enablereset;
j2kkkhandler->m_enablesegmark = wxGetApp().m_enablesegmark; jpeg2000handler->m_enablesegmark = wxGetApp().m_enablesegmark;
j2kkkhandler->m_enableerterm = wxGetApp().m_enableerterm; jpeg2000handler->m_enableerterm = wxGetApp().m_enableerterm;
j2kkkhandler->m_enablevsc = wxGetApp().m_enablevsc; jpeg2000handler->m_enablevsc = wxGetApp().m_enablevsc;
j2kkkhandler->m_enableidx = wxGetApp().m_enableidx; jpeg2000handler->m_enableidx = wxGetApp().m_enableidx;
j2kkkhandler->m_index = m_canvas->m_savename.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxGetApp().m_index; jpeg2000handler->m_index = m_canvas->m_savename.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxGetApp().m_index;
j2kkkhandler->m_enablecomm = wxGetApp().m_enablecomm; jpeg2000handler->m_enablecomm = wxGetApp().m_enablecomm;
j2kkkhandler->m_comment = wxGetApp().m_comment; jpeg2000handler->m_comment = wxGetApp().m_comment;
j2kkkhandler->m_enablepoc = wxGetApp().m_enablepoc; jpeg2000handler->m_enablepoc = wxGetApp().m_enablepoc;
j2kkkhandler->m_poc = wxGetApp().m_poc; 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_J2K)) { if (!m_canvas->m_image100.SaveFile(m_canvas->m_savename.GetFullPath(), (wxBitmapType) wxBITMAP_TYPE_JPEG2000)) {
WriteText(wxT("Can't save image")); WriteText(wxT("Can't save image"));
return NULL; return NULL;
} }
@ -196,7 +196,7 @@ void *OPJDecoThread::Entry()
// set handler properties // set handler properties
wxJ2KHandler *j2kkkhandler = (wxJ2KHandler *) wxImage::FindHandler( wxBITMAP_TYPE_J2K); /* wxJ2KHandler *j2kkkhandler = (wxJ2KHandler *) wxImage::FindHandler( wxBITMAP_TYPE_J2K);
j2kkkhandler->m_reducefactor = wxGetApp().m_reducefactor; j2kkkhandler->m_reducefactor = wxGetApp().m_reducefactor;
j2kkkhandler->m_qualitylayers = wxGetApp().m_qualitylayers; j2kkkhandler->m_qualitylayers = wxGetApp().m_qualitylayers;
j2kkkhandler->m_components = wxGetApp().m_components; j2kkkhandler->m_components = wxGetApp().m_components;
@ -204,9 +204,9 @@ void *OPJDecoThread::Entry()
j2kkkhandler->m_enablejpwl = wxGetApp().m_enablejpwl; j2kkkhandler->m_enablejpwl = wxGetApp().m_enablejpwl;
j2kkkhandler->m_expcomps = wxGetApp().m_expcomps; j2kkkhandler->m_expcomps = wxGetApp().m_expcomps;
j2kkkhandler->m_maxtiles = wxGetApp().m_maxtiles; j2kkkhandler->m_maxtiles = wxGetApp().m_maxtiles;
#endif // USE_JPWL #endif // USE_JPWL*/
wxJP2Handler *jp222handler = (wxJP2Handler *) wxImage::FindHandler( wxBITMAP_TYPE_JP2); /* wxJP2Handler *jp222handler = (wxJP2Handler *) wxImage::FindHandler( wxBITMAP_TYPE_JP2);
jp222handler->m_reducefactor = wxGetApp().m_reducefactor; jp222handler->m_reducefactor = wxGetApp().m_reducefactor;
jp222handler->m_qualitylayers = wxGetApp().m_qualitylayers; jp222handler->m_qualitylayers = wxGetApp().m_qualitylayers;
jp222handler->m_components = wxGetApp().m_components; jp222handler->m_components = wxGetApp().m_components;
@ -214,9 +214,9 @@ void *OPJDecoThread::Entry()
jp222handler->m_enablejpwl = wxGetApp().m_enablejpwl; jp222handler->m_enablejpwl = wxGetApp().m_enablejpwl;
jp222handler->m_expcomps = wxGetApp().m_expcomps; jp222handler->m_expcomps = wxGetApp().m_expcomps;
jp222handler->m_maxtiles = wxGetApp().m_maxtiles; jp222handler->m_maxtiles = wxGetApp().m_maxtiles;
#endif // USE_JPWL #endif // USE_JPWL*/
wxMJ2Handler *mj222handler = (wxMJ2Handler *) wxImage::FindHandler( wxBITMAP_TYPE_MJ2); /* wxMJ2Handler *mj222handler = (wxMJ2Handler *) wxImage::FindHandler( wxBITMAP_TYPE_MJ2);
mj222handler->m_reducefactor = wxGetApp().m_reducefactor; mj222handler->m_reducefactor = wxGetApp().m_reducefactor;
mj222handler->m_qualitylayers = wxGetApp().m_qualitylayers; mj222handler->m_qualitylayers = wxGetApp().m_qualitylayers;
mj222handler->m_components = wxGetApp().m_components; mj222handler->m_components = wxGetApp().m_components;
@ -225,8 +225,33 @@ void *OPJDecoThread::Entry()
mj222handler->m_enablejpwl = wxGetApp().m_enablejpwl; mj222handler->m_enablejpwl = wxGetApp().m_enablejpwl;
mj222handler->m_expcomps = wxGetApp().m_expcomps; mj222handler->m_expcomps = wxGetApp().m_expcomps;
mj222handler->m_maxtiles = wxGetApp().m_maxtiles; mj222handler->m_maxtiles = wxGetApp().m_maxtiles;
#endif // USE_JPWL*/
wxJPEG2000Handler *jpeg2000handler = (wxJPEG2000Handler *) wxImage::FindHandler(wxBITMAP_TYPE_JPEG2000);
jpeg2000handler->m_reducefactor = wxGetApp().m_reducefactor;
jpeg2000handler->m_qualitylayers = wxGetApp().m_qualitylayers;
jpeg2000handler->m_components = wxGetApp().m_components;
jpeg2000handler->m_framenum = wxGetApp().m_framenum;
#ifdef USE_JPWL
jpeg2000handler->m_enablejpwl = wxGetApp().m_enablejpwl;
jpeg2000handler->m_expcomps = wxGetApp().m_expcomps;
jpeg2000handler->m_maxtiles = wxGetApp().m_maxtiles;
#endif // USE_JPWL #endif // USE_JPWL
#ifdef USE_MXF
wxMXFHandler *mxfffhandler = (wxMXFHandler *) wxImage::FindHandler( wxBITMAP_TYPE_MXF);
mxfffhandler->m_reducefactor = wxGetApp().m_reducefactor;
mxfffhandler->m_qualitylayers = wxGetApp().m_qualitylayers;
mxfffhandler->m_components = wxGetApp().m_components;
mxfffhandler->m_framenum = wxGetApp().m_framenum;
mxfffhandler->m_filename = m_canvas->m_fname;
#ifdef USE_JPWL
mxfffhandler->m_enablejpwl = wxGetApp().m_enablejpwl;
mxfffhandler->m_expcomps = wxGetApp().m_expcomps;
mxfffhandler->m_maxtiles = wxGetApp().m_maxtiles;
#endif // USE_JPWL
#endif // USE_MXF
if (wxGetApp().m_enabledeco) { if (wxGetApp().m_enabledeco) {
// load the file // load the file
@ -237,7 +262,7 @@ void *OPJDecoThread::Entry()
} else { } else {
// display a macaron // 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;

View File

@ -189,14 +189,15 @@ bool OPJViewerApp::OnInit(void)
#if wxUSE_LIBJPEG #if wxUSE_LIBJPEG
wxImage::AddHandler( new wxJPEGHandler ); wxImage::AddHandler( new wxJPEGHandler );
#endif #endif
#if wxUSE_LIBOPENJPEG
//wxImage::AddHandler( new wxJ2KHandler );
//wxImage::AddHandler( new wxJP2Handler );
//wxImage::AddHandler( new wxMJ2Handler );
wxImage::AddHandler( new wxJPEG2000Handler );
#endif
#if USE_MXF #if USE_MXF
wxImage::AddHandler( new wxMXFHandler ); wxImage::AddHandler( new wxMXFHandler );
#endif // USE_MXF #endif // USE_MXF
#if wxUSE_LIBOPENJPEG
wxImage::AddHandler( new wxJ2KHandler );
wxImage::AddHandler( new wxJP2Handler );
wxImage::AddHandler( new wxMJ2Handler );
#endif
#if OPJ_MANYFORMATS #if OPJ_MANYFORMATS
wxImage::AddHandler( new wxBMPHandler ); wxImage::AddHandler( new wxBMPHandler );
wxImage::AddHandler( new wxPNGHandler ); wxImage::AddHandler( new wxPNGHandler );
@ -474,6 +475,11 @@ void OPJViewerApp::ShowCmdLine(const wxCmdLineParser& parser)
} }
// OPJFrame events // OPJFrame events
// Event class for sending text messages between worker and GUI threads
DECLARE_EVENT_TYPE(wxEVT_LOGMSG_EVENT, -1)
DEFINE_EVENT_TYPE(wxEVT_LOGMSG_EVENT)
BEGIN_EVENT_TABLE(OPJFrame, wxMDIParentFrame) BEGIN_EVENT_TABLE(OPJFrame, wxMDIParentFrame)
EVT_MENU(OPJFRAME_HELPABOUT, OPJFrame::OnAbout) EVT_MENU(OPJFRAME_HELPABOUT, OPJFrame::OnAbout)
EVT_MENU(OPJFRAME_FILEOPEN, OPJFrame::OnFileOpen) EVT_MENU(OPJFRAME_FILEOPEN, OPJFrame::OnFileOpen)
@ -504,6 +510,7 @@ BEGIN_EVENT_TABLE(OPJFrame, wxMDIParentFrame)
EVT_MENU(OPJFRAME_SETSDECO, OPJFrame::OnSetsDeco) EVT_MENU(OPJFRAME_SETSDECO, OPJFrame::OnSetsDeco)
EVT_SASH_DRAGGED_RANGE(OPJFRAME_BROWSEWIN, OPJFRAME_LOGWIN, OPJFrame::OnSashDrag) EVT_SASH_DRAGGED_RANGE(OPJFRAME_BROWSEWIN, OPJFRAME_LOGWIN, OPJFrame::OnSashDrag)
EVT_NOTEBOOK_PAGE_CHANGED(LEFT_NOTEBOOK_ID, OPJFrame::OnNotebook) EVT_NOTEBOOK_PAGE_CHANGED(LEFT_NOTEBOOK_ID, OPJFrame::OnNotebook)
EVT_COMMAND(wxID_ANY, wxEVT_LOGMSG_EVENT, OPJFrame::OnLogmsgEvent)
END_EVENT_TABLE() END_EVENT_TABLE()
// this is the frame constructor // this is the frame constructor
@ -1462,6 +1469,16 @@ void OPJFrame::OnSize(wxSizeEvent& WXUNUSED(event))
layout.LayoutMDIFrame(this); layout.LayoutMDIFrame(this);
} }
void OPJFrame::OnLogmsgEvent(wxCommandEvent &event)
{
// receive string
wxString text = event.GetString();
// show it on the log
wxLogMessage(text);
}
// Note that OPJFRAME_FILEOPEN and OPJFRAME_HELPABOUT commands get passed // Note that OPJFRAME_FILEOPEN and OPJFRAME_HELPABOUT commands get passed
// to the parent window for processing, so no need to // to the parent window for processing, so no need to
// duplicate event handlers here. // duplicate event handlers here.

View File

@ -103,9 +103,10 @@
#include "libopenjpeg/openjpeg.h" #include "libopenjpeg/openjpeg.h"
#include "imagj2k.h" //#include "imagj2k.h"
#include "imagjp2.h" //#include "imagjp2.h"
#include "imagmj2.h" //#include "imagmj2.h"
#include "imagjpeg2000.h"
#ifdef USE_MXF #ifdef USE_MXF
#include "imagmxf.h" #include "imagmxf.h"
#endif // USE_MXF #endif // USE_MXF
@ -131,9 +132,9 @@ typedef unsigned long long int8byte;
#define OPJ_APPLICATION wxT("OPJViewer") #define OPJ_APPLICATION wxT("OPJViewer")
#define OPJ_APPLICATION_NAME wxT("OpenJPEG Viewer") #define OPJ_APPLICATION_NAME wxT("OpenJPEG Viewer")
#define OPJ_APPLICATION_VERSION wxT("0.3 alpha") #define OPJ_APPLICATION_VERSION wxT("0.4 beta")
#define OPJ_APPLICATION_TITLEBAR OPJ_APPLICATION_NAME wxT(" ") OPJ_APPLICATION_VERSION #define OPJ_APPLICATION_TITLEBAR OPJ_APPLICATION_NAME wxT(" ") OPJ_APPLICATION_VERSION
#define OPJ_APPLICATION_COPYRIGHT wxT("(C) 2007, Giuseppe Baruffa") #define OPJ_APPLICATION_COPYRIGHT wxT("(C) 2007-2008, Giuseppe Baruffa")
#define OPJ_APPLICATION_VENDOR wxT("OpenJPEG") #define OPJ_APPLICATION_VENDOR wxT("OpenJPEG")
#ifdef __WXMSW__ #ifdef __WXMSW__
@ -442,6 +443,7 @@ class OPJFrame: public wxMDIParentFrame
void SaveFile(wxArrayString paths, wxArrayString filenames); void SaveFile(wxArrayString paths, wxArrayString filenames);
void OnNotebook(wxNotebookEvent& event); void OnNotebook(wxNotebookEvent& event);
void Rescale(int scale, OPJChildFrame *child); void Rescale(int scale, OPJChildFrame *child);
void OnLogmsgEvent(wxCommandEvent &event);
OPJMarkerTreeHash m_treehash; OPJMarkerTreeHash m_treehash;
OPJChildFrameHash m_childhash; OPJChildFrameHash m_childhash;

View File

@ -20,18 +20,23 @@ OPJ_APPLICATION " " OPJ_APPLICATION_VERSION
"<tr>" "<tr>"
"<td align=justify>" "<td align=justify>"
"<center><font size=+0 color=#000000><a href=\"http://www.openjpeg.org/\">OpenJPEG</a></font></center>" "<center><font size=+0 color=#000000><a href=\"http://www.openjpeg.org/\">OpenJPEG</a></font></center>"
"<font size=-1 color=#000000>The OpenJPEG library is an open-source JPEG 2000 codec written in C language. " "<p><font size=-1 color=#000000>The OpenJPEG library is an open-source JPEG 2000 codec written in C language. "
"In addition to the basic codec, various other features are under development.</font><br>" "In addition to the basic codec, various other features are under development.</font></p><br>"
"<font size=-2 color=red>* Build: ") "<font size=-2 color=red>* Build: ")
#include "build.h" #include "build.h"
wxT(", " __DATE__ ", " __TIME__ "</font><br>") wxT(", " __DATE__ ", " __TIME__ "</font><br>")
wxT("<font size=-2 color=red>* " wxVERSION_STRING "</font><br>") wxT("<font size=-2 color=red>* " wxVERSION_STRING "</font><br>")
wxT("<font size=-2 color=red>* OpenJPEG " OPENJPEG_VERSION " (")
#ifdef USE_JPWL #ifdef USE_JPWL
wxT("<font size=-2 color=green>- Compiled with JPWL support</font><br>") wxT("<font size=-2 color=green>JPWL</font> ")
#endif // USE_JPWL #endif // USE_JPWL
#ifdef USE_JPSEC #ifdef USE_JPSEC
wxT("<font size=-2 color=green>- Compiled with JPSEC support</font>") wxT("<font size=-2 color=green>JPSEC</font> ")
#endif // USE_JPSEC #endif // USE_JPSEC
wxT(")</font><br>")
#ifdef USE_MXF
wxT("<font size=-2 color=red>* MXFLib " MXFLIB_VERSION_MAJOR "." MXFLIB_VERSION_MINOR "." MXFLIB_VERSION_TWEAK " (" MXFLIB_VERSION_BUILD ")</font><br>")
#endif // USE_MXF
wxT("</td>" wxT("</td>"
"</tr>" "</tr>"
"<tr>" "<tr>"
@ -39,8 +44,8 @@ wxT("</td>"
"</tr>" "</tr>"
"<tr>" "<tr>"
"<td colspan=2>" "<td colspan=2>"
"<font size=-2 color=#444444>OpenJPEG is &copy; 2002-2007 <a href=\"http://www.tele.ucl.ac.be/\">TELE</a> - <a href=\"http://www.uclouvain.be/\">Universite' Catholique de Louvain</a></font><br>" "<font size=-2 color=#444444>OpenJPEG is &copy; 2002-2008 <a href=\"http://www.tele.ucl.ac.be/\">TELE</a> - <a href=\"http://www.uclouvain.be/\">Universite' Catholique de Louvain</a></font><br>"
"<font size=-2 color=#444444>OPJViewer is also &copy; 2007 <a href=\"http://dsplab.diei.unipg.it/\">DSPLab</a> - <a href=\"http://www.unipg.it/\">Universita' degli studi di Perugia</a></font>" "<font size=-2 color=#444444>OPJViewer is &copy; 2007-2008 <a href=\"http://dsplab.diei.unipg.it/\">DSPLab</a> - <a href=\"http://www.unipg.it/\">Universita' degli studi di Perugia</a></font>"
"</td>" "</td>"
"</tr>" "</tr>"
"</table>" "</table>"

View File

@ -1 +1 @@
wxT("404") wxT("468")

View File

@ -1,721 +0,0 @@
/*
* Copyright (c) 2007, Digital Signal Processing Laboratory, Università degli studi di Perugia (UPG), Italy
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/////////////////////////////////////////////////////////////////////////////
// Name: imagj2k.cpp
// Purpose: wxImage JPEG 2000 codestream handler
// Author: Giuseppe Baruffa - based on imagjpeg.cpp, Vaclav Slavik
// RCS-ID: $Id: imagj2k.cpp,v 0.00 2007/02/08 23:59:00 MW Exp $
// Copyright: (c) Giuseppe Baruffa
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_IMAGE && wxUSE_LIBOPENJPEG
#include "imagj2k.h"
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/app.h"
#include "wx/intl.h"
#include "wx/bitmap.h"
#include "wx/module.h"
#endif
#include "wx/filefn.h"
#include "wx/wfstream.h"
// ----------------------------------------------------------------------------
// types
// ----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// wxJ2KHandler
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxJ2KHandler,wxImageHandler)
#if wxUSE_STREAMS
//------------- JPEG 2000 Data Source Manager
#define J2K_CFMT 0
#define JP2_CFMT 1
#define JPT_CFMT 2
#define MJ2_CFMT 3
#define PXM_DFMT 0
#define PGX_DFMT 1
#define BMP_DFMT 2
#define YUV_DFMT 3
#define MAX_MESSAGE_LEN 200
/* sample error callback expecting a FILE* client object */
void j2k_error_callback(const char *msg, void *client_data) {
int message_len = strlen(msg) - 1;
if (msg[message_len] != '\n')
message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("[ERROR] %.*s"), message_len, msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
/* sample warning callback expecting a FILE* client object */
void j2k_warning_callback(const char *msg, void *client_data) {
int message_len = strlen(msg) - 1;
if (msg[message_len] != '\n')
message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("[WARNING] %.*s"), message_len, msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
/* sample debug callback expecting no client object */
void j2k_info_callback(const char *msg, void *client_data) {
int message_len = strlen(msg) - 1;
if (msg[message_len] != '\n')
message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("[INFO] %.*s"), message_len, msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
// load the j2k codestream
bool wxJ2KHandler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, int index)
{
opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_image_t *opjimage = NULL;
unsigned char *src = NULL;
unsigned char *ptr;
int file_length;
opj_codestream_info_t cstr_info; /* Codestream information structure */
// destroy the image
image->Destroy();
/* handle to a decompressor */
opj_dinfo_t* dinfo = NULL;
opj_cio_t *cio = NULL;
/* configure the event callbacks (not required) */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = j2k_error_callback;
event_mgr.warning_handler = j2k_warning_callback;
event_mgr.info_handler = j2k_info_callback;
/* set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters);
/* prepare parameters */
strncpy(parameters.infile, "", sizeof(parameters.infile)-1);
strncpy(parameters.outfile, "", sizeof(parameters.outfile)-1);
parameters.decod_format = J2K_CFMT;
parameters.cod_format = BMP_DFMT;
if (m_reducefactor)
parameters.cp_reduce = m_reducefactor;
if (m_qualitylayers)
parameters.cp_layer = m_qualitylayers;
/* JPWL only */
#ifdef USE_JPWL
parameters.jpwl_exp_comps = m_expcomps;
parameters.jpwl_max_tiles = m_maxtiles;
parameters.jpwl_correct = m_enablejpwl;
#endif /* USE_JPWL */
/* get a decoder handle */
dinfo = opj_create_decompress(CODEC_J2K);
/* find length of the stream */
stream.SeekI(0, wxFromEnd);
file_length = (int) stream.TellI();
/* get data */
stream.SeekI(0, wxFromStart);
src = (unsigned char *) malloc(file_length);
stream.Read(src, file_length);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, &parameters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */
opjimage = opj_decode_with_info(dinfo, cio, &cstr_info);
if (!opjimage) {
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogError(wxT("J2K: failed to decode image!"));
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
opj_image_destroy(opjimage);
free(src);
return false;
}
/* close the byte stream */
opj_cio_close(cio);
/* common rendering method */
#include "imagjpeg2000.cpp"
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("J2K: image loaded."));
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
/* close openjpeg structs */
opj_destroy_decompress(dinfo);
opj_image_destroy(opjimage);
free(src);
if (!image->Ok())
return false;
else
return true;
}
#define CINEMA_24_CS 1302083 /* Codestream length for 24fps */
#define CINEMA_48_CS 651041 /* Codestream length for 48fps */
#define COMP_24_CS 1041666 /* Maximum size per color component for 2K & 4K @ 24fps */
#define COMP_48_CS 520833 /* Maximum size per color component for 2K @ 48fps */
// save the j2k codestream
bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbose )
{
opj_cparameters_t parameters; /* compression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_image_t *oimage = NULL;
opj_image_cmptparm_t *cmptparm;
opj_cio_t *cio = NULL;
opj_codestream_info_t cstr_info;
int codestream_length;
bool bSuccess;
int i;
char indexfilename[OPJ_PATH_LEN] = ""; /* index file name */
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = j2k_error_callback;
event_mgr.warning_handler = j2k_warning_callback;
event_mgr.info_handler = j2k_info_callback;
/* set encoding parameters to default values */
opj_set_default_encoder_parameters(&parameters);
/* load parameters */
parameters.cp_cinema = OFF;
/* subsampling */
if (sscanf(m_subsampling.ToAscii(), "%d,%d", &(parameters.subsampling_dx), &(parameters.subsampling_dy)) != 2) {
wxLogError(wxT("Wrong sub-sampling encoder setting: dx,dy"));
return false;
}
/* compression rates */
if ((m_rates != wxT("")) && (!m_enablequality)) {
const char *s1 = m_rates.ToAscii();
wxLogMessage(wxT("rates %s"), s1);
while (sscanf(s1, "%f", &(parameters.tcp_rates[parameters.tcp_numlayers])) == 1) {
parameters.tcp_numlayers++;
while (*s1 && *s1 != ',') {
s1++;
}
if (!*s1)
break;
s1++;
}
wxLogMessage(wxT("%d layers"), parameters.tcp_numlayers);
parameters.cp_disto_alloc = 1;
}
/* image quality, dB */
if ((m_quality != wxT("")) && (m_enablequality)) {
const char *s2 = m_quality.ToAscii();
wxLogMessage(wxT("qualities %s"), s2);
while (sscanf(s2, "%f", &parameters.tcp_distoratio[parameters.tcp_numlayers]) == 1) {
parameters.tcp_numlayers++;
while (*s2 && *s2 != ',') {
s2++;
}
if (!*s2)
break;
s2++;
}
wxLogMessage(wxT("%d layers"), parameters.tcp_numlayers);
parameters.cp_fixed_quality = 1;
}
/* image origin */
if (sscanf(m_origin.ToAscii(), "%d,%d", &parameters.image_offset_x0, &parameters.image_offset_y0) != 2) {
wxLogError(wxT("bad coordinate of the image origin: x0,y0"));
return false;
}
/* Create comment for codestream */
if(m_enablecomm) {
parameters.cp_comment = (char *) malloc(strlen(m_comment.ToAscii()) + 1);
if(parameters.cp_comment) {
strcpy(parameters.cp_comment, m_comment.ToAscii());
}
} else {
parameters.cp_comment = NULL;
}
/* indexing file */
if (m_enableidx) {
strncpy(indexfilename, m_index.ToAscii(), OPJ_PATH_LEN);
wxLogMessage(wxT("index file is %s"), indexfilename);
}
/* if no rate entered, lossless by default */
if (parameters.tcp_numlayers == 0) {
parameters.tcp_rates[0] = 0; /* MOD antonin : losslessbug */
parameters.tcp_numlayers++;
parameters.cp_disto_alloc = 1;
}
/* irreversible transform */
parameters.irreversible = (m_irreversible == true) ? 1 : 0;
/* resolutions */
parameters.numresolution = m_resolutions;
/* codeblocks size */
if (m_cbsize != wxT("")) {
int cblockw_init = 0, cblockh_init = 0;
sscanf(m_cbsize.ToAscii(), "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024 || cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {
wxLogError(wxT("!! Size of code_block error !! Restrictions:\n width*height<=4096\n 4<=width,height<= 1024"));
return false;
}
parameters.cblockw_init = cblockw_init;
parameters.cblockh_init = cblockh_init;
}
/* precincts size */
if (m_prsize != wxT("")) {
char sep;
int res_spec = 0;
char *s = (char *) m_prsize.c_str();
do {
sep = 0;
sscanf(s, "[%d,%d]%c", &parameters.prcw_init[res_spec], &parameters.prch_init[res_spec], &sep);
parameters.csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
} while (sep == ',');
parameters.res_spec = res_spec;
}
/* tiles */
if (m_tsize != wxT("")) {
sscanf(m_tsize.ToAscii(), "%d,%d", &parameters.cp_tdx, &parameters.cp_tdy);
parameters.tile_size_on = true;
}
/* tile origin */
if (sscanf(m_torigin.ToAscii(), "%d,%d", &parameters.cp_tx0, &parameters.cp_ty0) != 2) {
wxLogError(wxT("tile offset setting error: X0,Y0"));
return false;
}
/* use SOP */
if (m_enablesop)
parameters.csty |= 0x02;
/* use EPH */
if (m_enableeph)
parameters.csty |= 0x04;
/* multiple component transform */
if (m_multicomp)
parameters.tcp_mct = 1;
else
parameters.tcp_mct = 0;
/* mode switch */
parameters.mode = (m_enablebypass ? 1 : 0) + (m_enablereset ? 2 : 0)
+ (m_enablerestart ? 4 : 0) + (m_enablevsc ? 8 : 0)
+ (m_enableerterm ? 16 : 0) + (m_enablesegmark ? 32 : 0);
/* progression order */
switch (m_progression) {
/* LRCP */
case 0:
parameters.prog_order = LRCP;
break;
/* RLCP */
case 1:
parameters.prog_order = RLCP;
break;
/* RPCL */
case 2:
parameters.prog_order = RPCL;
break;
/* PCRL */
case 3:
parameters.prog_order = PCRL;
break;
/* CPRL */
case 4:
parameters.prog_order = CPRL;
break;
/* DCI2K24 */
case 5:
parameters.cp_cinema = CINEMA2K_24;
parameters.cp_rsiz = CINEMA2K;
break;
/* DCI2K48 */
case 6:
parameters.cp_cinema = CINEMA2K_48;
parameters.cp_rsiz = CINEMA2K;
break;
/* DCI4K */
case 7:
parameters.cp_cinema = CINEMA4K_24;
parameters.cp_rsiz = CINEMA4K;
break;
default:
break;
}
/* check cinema */
if (parameters.cp_cinema) {
/* set up */
parameters.tile_size_on = false;
parameters.cp_tdx=1;
parameters.cp_tdy=1;
/*Tile part*/
parameters.tp_flag = 'C';
parameters.tp_on = 1;
/*Tile and Image shall be at (0,0)*/
parameters.cp_tx0 = 0;
parameters.cp_ty0 = 0;
parameters.image_offset_x0 = 0;
parameters.image_offset_y0 = 0;
/*Codeblock size= 32*32*/
parameters.cblockw_init = 32;
parameters.cblockh_init = 32;
parameters.csty |= 0x01;
/*The progression order shall be CPRL*/
parameters.prog_order = CPRL;
/* No ROI */
parameters.roi_compno = -1;
parameters.subsampling_dx = 1;
parameters.subsampling_dy = 1;
/* 9-7 transform */
parameters.irreversible = 1;
}
/* convert wx image into opj image */
cmptparm = (opj_image_cmptparm_t*) malloc(3 * sizeof(opj_image_cmptparm_t));
/* initialize opj image components */
memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t));
for(i = 0; i < 3; i++) {
cmptparm[i].prec = 8;
cmptparm[i].bpp = 8;
cmptparm[i].sgnd = false;
cmptparm[i].dx = parameters.subsampling_dx;
cmptparm[i].dy = parameters.subsampling_dy;
cmptparm[i].w = wimage->GetWidth();
cmptparm[i].h = wimage->GetHeight();
}
/* create the image */
oimage = opj_image_create(3, &cmptparm[0], CLRSPC_SRGB);
if(!oimage) {
if (cmptparm)
free(cmptparm);
return false;
}
/* set image offset and reference grid */
oimage->x0 = parameters.image_offset_x0;
oimage->y0 = parameters.image_offset_y0;
oimage->x1 = parameters.image_offset_x0 + (wimage->GetWidth() - 1) * 1 + 1;
oimage->y1 = parameters.image_offset_y0 + (wimage->GetHeight() - 1) * 1 + 1;
/* load image data */
unsigned char *value = wimage->GetData();
int area = wimage->GetWidth() * wimage->GetHeight();
for (i = 0; i < area; i++) {
oimage->comps[0].data[i] = *(value++);
oimage->comps[1].data[i] = *(value++);
oimage->comps[2].data[i] = *(value++);
}
/* check cinema again */
if (parameters.cp_cinema) {
int i;
float temp_rate;
opj_poc_t *POC = NULL;
switch (parameters.cp_cinema) {
case CINEMA2K_24:
case CINEMA2K_48:
if (parameters.numresolution > 6) {
parameters.numresolution = 6;
}
if (!((oimage->comps[0].w == 2048) | (oimage->comps[0].h == 1080))) {
wxLogWarning(wxT("Image coordinates %d x %d is not 2K compliant. JPEG Digital Cinema Profile-3 "
"(2K profile) compliance requires that at least one of coordinates match 2048 x 1080"),
oimage->comps[0].w, oimage->comps[0].h);
parameters.cp_rsiz = STD_RSIZ;
}
break;
case CINEMA4K_24:
if (parameters.numresolution < 1) {
parameters.numresolution = 1;
} else if (parameters.numresolution > 7) {
parameters.numresolution = 7;
}
if (!((oimage->comps[0].w == 4096) | (oimage->comps[0].h == 2160))) {
wxLogWarning(wxT("Image coordinates %d x %d is not 4K compliant. JPEG Digital Cinema Profile-4"
"(4K profile) compliance requires that at least one of coordinates match 4096 x 2160"),
oimage->comps[0].w, oimage->comps[0].h);
parameters.cp_rsiz = STD_RSIZ;
}
parameters.POC[0].tile = 1;
parameters.POC[0].resno0 = 0;
parameters.POC[0].compno0 = 0;
parameters.POC[0].layno1 = 1;
parameters.POC[0].resno1 = parameters.numresolution - 1;
parameters.POC[0].compno1 = 3;
parameters.POC[0].prg1 = CPRL;
parameters.POC[1].tile = 1;
parameters.POC[1].resno0 = parameters.numresolution - 1;
parameters.POC[1].compno0 = 0;
parameters.POC[1].layno1 = 1;
parameters.POC[1].resno1 = parameters.numresolution;
parameters.POC[1].compno1 = 3;
parameters.POC[1].prg1 = CPRL;
parameters.numpocs = 2;
break;
}
switch (parameters.cp_cinema) {
case CINEMA2K_24:
case CINEMA4K_24:
for (i = 0 ; i < parameters.tcp_numlayers; i++) {
temp_rate = 0;
if (parameters.tcp_rates[i] == 0) {
parameters.tcp_rates[0] = ((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) /
(CINEMA_24_CS * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
}else{
temp_rate = ((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) /
(parameters.tcp_rates[i] * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
if (temp_rate > CINEMA_24_CS ) {
parameters.tcp_rates[i]= ((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) /
(CINEMA_24_CS * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
} else {
/* do nothing */
}
}
}
parameters.max_comp_size = COMP_24_CS;
break;
case CINEMA2K_48:
for (i = 0; i < parameters.tcp_numlayers; i++) {
temp_rate = 0 ;
if (parameters.tcp_rates[i] == 0) {
parameters.tcp_rates[0] = ((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) /
(CINEMA_48_CS * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
}else{
temp_rate =((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) /
(parameters.tcp_rates[i] * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
if (temp_rate > CINEMA_48_CS ){
parameters.tcp_rates[0]= ((float) (oimage->numcomps * oimage->comps[0].w * oimage->comps[0].h * oimage->comps[0].prec)) /
(CINEMA_48_CS * 8 * oimage->comps[0].dx * oimage->comps[0].dy);
}else{
/* do nothing */
}
}
}
parameters.max_comp_size = COMP_48_CS;
break;
}
parameters.cp_disto_alloc = 1;
}
/* get a J2K compressor handle */
opj_cinfo_t* cinfo = opj_create_compress(CODEC_J2K);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
/* setup the encoder parameters using the current image and user parameters */
opj_setup_encoder(cinfo, &parameters, oimage);
/* open a byte stream for writing */
/* allocate memory for all tiles */
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
/* encode the image */
bSuccess = opj_encode_with_info(cinfo, cio, oimage, &cstr_info);
if (!bSuccess) {
opj_cio_close(cio);
opj_destroy_compress(cinfo);
opj_image_destroy(oimage);
if (cmptparm)
free(cmptparm);
if(parameters.cp_comment)
free(parameters.cp_comment);
if(parameters.cp_matrice)
free(parameters.cp_matrice);
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogError(wxT("failed to encode image"));
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
return false;
}
codestream_length = cio_tell(cio);
wxLogMessage(wxT("Codestream: %d bytes"), codestream_length);
/* write the buffer to stream */
stream.Write(cio->buffer, codestream_length);
/* close and free the byte stream */
opj_cio_close(cio);
/* Write the index to disk */
if (*indexfilename) {
if (write_index_file(&cstr_info, indexfilename)) {
wxLogError(wxT("Failed to output index file"));
}
}
/* free remaining compression structures */
opj_destroy_compress(cinfo);
/* free image data */
opj_image_destroy(oimage);
if (cmptparm)
free(cmptparm);
if(parameters.cp_comment)
free(parameters.cp_comment);
if(parameters.cp_matrice)
free(parameters.cp_matrice);
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("J2K: Image encoded!"));
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
return true;
}
#ifdef __VISUALC__
#pragma warning(default:4611)
#endif /* VC++ */
// recognize the 0xFF4F JPEG 2000 SOC marker
bool wxJ2KHandler::DoCanRead( wxInputStream& stream )
{
unsigned char hdr[2];
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
return false;
return hdr[0] == 0xFF && hdr[1] == 0x4F;
}
#endif // wxUSE_STREAMS
#endif // wxUSE_LIBOPENJPEG

View File

@ -1,279 +0,0 @@
/*
* Copyright (c) 2007, Digital Signal Processing Laboratory, Università degli studi di Perugia (UPG), Italy
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/////////////////////////////////////////////////////////////////////////////
// Name: imagjp2.cpp
// Purpose: wxImage JPEG 2000 file format handler
// Author: Giuseppe Baruffa - based on imagjpeg.cpp, Vaclav Slavik
// RCS-ID: $Id: imagjp2.cpp,v 0.00 2007/02/08 23:59:00 MW Exp $
// Copyright: (c) Giuseppe Baruffa
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_IMAGE && wxUSE_LIBOPENJPEG
#include "imagjp2.h"
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/app.h"
#include "wx/intl.h"
#include "wx/bitmap.h"
#include "wx/module.h"
#endif
#include "libopenjpeg/openjpeg.h"
#include "wx/filefn.h"
#include "wx/wfstream.h"
// ----------------------------------------------------------------------------
// types
// ----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// wxJP2Handler
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxJP2Handler,wxImageHandler)
#if wxUSE_STREAMS
//------------- JPEG 2000 Data Source Manager
#define J2K_CFMT 0
#define JP2_CFMT 1
#define JPT_CFMT 2
#define MJ2_CFMT 3
#define PXM_DFMT 0
#define PGX_DFMT 1
#define BMP_DFMT 2
#define YUV_DFMT 3
#define MAX_MESSAGE_LEN 200
/* sample error callback expecting a FILE* client object */
void jp2_error_callback(const char *msg, void *client_data) {
int message_len = strlen(msg) - 1;
if (msg[message_len] != '\n')
message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("[ERROR] %.*s"), message_len, msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
/* sample warning callback expecting a FILE* client object */
void jp2_warning_callback(const char *msg, void *client_data) {
int message_len = strlen(msg) - 1;
if (msg[message_len] != '\n')
message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("[WARNING] %.*s"), message_len, msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
/* sample debug callback expecting no client object */
void jp2_info_callback(const char *msg, void *client_data) {
int message_len = strlen(msg) - 1;
if (msg[message_len] != '\n')
message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("[INFO] %.*s"), message_len, msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
// load the jp2 file format
bool wxJP2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, int index)
{
opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_image_t *opjimage = NULL;
unsigned char *src = NULL;
unsigned char *ptr;
int file_length;
opj_codestream_info_t cstr_info; /* Codestream information structure */
// destroy the image
image->Destroy();
/* handle to a decompressor */
opj_dinfo_t* dinfo = NULL;
opj_cio_t *cio = NULL;
/* configure the event callbacks (not required) */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = jp2_error_callback;
event_mgr.warning_handler = jp2_warning_callback;
event_mgr.info_handler = jp2_info_callback;
/* set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters);
/* prepare parameters */
strncpy(parameters.infile, "", sizeof(parameters.infile)-1);
strncpy(parameters.outfile, "", sizeof(parameters.outfile)-1);
parameters.decod_format = JP2_CFMT;
parameters.cod_format = BMP_DFMT;
if (m_reducefactor)
parameters.cp_reduce = m_reducefactor;
if (m_qualitylayers)
parameters.cp_layer = m_qualitylayers;
/*if (n_components)
parameters. = n_components;*/
/* JPWL only */
#ifdef USE_JPWL
parameters.jpwl_exp_comps = m_expcomps;
parameters.jpwl_max_tiles = m_maxtiles;
parameters.jpwl_correct = m_enablejpwl;
#endif /* USE_JPWL */
/* get a decoder handle */
dinfo = opj_create_decompress(CODEC_JP2);
/* find length of the stream */
stream.SeekI(0, wxFromEnd);
file_length = (int) stream.TellI();
/* get data */
stream.SeekI(0, wxFromStart);
src = (unsigned char *) malloc(file_length);
stream.Read(src, file_length);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, &parameters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */
opjimage = opj_decode_with_info(dinfo, cio, &cstr_info);
if (!opjimage) {
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogError(wxT("JP2: failed to decode image!"));
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
free(src);
return false;
}
/* close the byte stream */
opj_cio_close(cio);
/* common rendering method */
#include "imagjpeg2000.cpp"
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("JP2: image loaded."));
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
/* close openjpeg structs */
opj_destroy_decompress(dinfo);
opj_image_destroy(opjimage);
free(src);
if (!image->Ok())
return false;
else
return true;
}
// save the jp2 file format
bool wxJP2Handler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose )
{
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogError(wxT("JP2: Couldn't save image -> not implemented."));
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
return false;
}
#ifdef __VISUALC__
#pragma warning(default:4611)
#endif /* VC++ */
// recognize the JPEG 2000 starting box
bool wxJP2Handler::DoCanRead( wxInputStream& stream )
{
unsigned char hdr[23];
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
return false;
return (hdr[0] == 0x00 &&
hdr[1] == 0x00 &&
hdr[2] == 0x00 &&
hdr[3] == 0x0C &&
hdr[4] == 0x6A &&
hdr[5] == 0x50 &&
hdr[6] == 0x20 &&
hdr[7] == 0x20 &&
hdr[20] == 0x6A &&
hdr[21] == 0x70 &&
hdr[22] == 0x32);
}
#endif // wxUSE_STREAMS
#endif // wxUSE_LIBOPENJPEG

View File

@ -1,92 +0,0 @@
/*
* Copyright (c) 2007, Digital Signal Processing Laboratory, Università degli studi di Perugia (UPG), Italy
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/////////////////////////////////////////////////////////////////////////////
// Name: imagjp2.h
// Purpose: wxImage JPEG 2000 file format handler
// Author: G. Baruffa - based on imagjpeg.h, Vaclav Slavik
// RCS-ID: $Id: imagjp2.h,v 0.0 2007/02/08 23:45:00 VZ Exp $
// Copyright: (c) Giuseppe Baruffa
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_IMAGJP2_H_
#define _WX_IMAGJP2_H_
#include "wx/defs.h"
//-----------------------------------------------------------------------------
// wxJP2Handler
//-----------------------------------------------------------------------------
#if wxUSE_LIBOPENJPEG
#include "wx/image.h"
#include "libopenjpeg/openjpeg.h"
#define wxBITMAP_TYPE_JP2 48
class WXDLLEXPORT wxJP2Handler: public wxImageHandler
{
public:
inline wxJP2Handler()
{
m_name = wxT("JPEG 2000 file format");
m_extension = wxT("jp2");
m_type = wxBITMAP_TYPE_JP2;
m_mime = wxT("image/jp2");
m_reducefactor = 0;
m_qualitylayers = 0;
m_components = 0;
#ifdef USE_JPWL
m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES;
#endif // USE_JPWL
}
// decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components;
#ifdef USE_JPWL
bool m_enablejpwl;
int m_expcomps, m_maxtiles;
#endif // USE_JPWL
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );
protected:
virtual bool DoCanRead( wxInputStream& stream );
#endif
private:
DECLARE_DYNAMIC_CLASS(wxJP2Handler)
};
#endif // wxUSE_LIBOPENJPEG
#endif // _WX_IMAGJP2_H_

File diff suppressed because it is too large Load Diff

View File

@ -24,21 +24,21 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: imagj2k.h // Name: imagalljpeg2000.h
// Purpose: wxImage JPEG 2000 raw codestream handler // Purpose: wxImage JPEG 2000 family file format handler
// Author: G. Baruffa - based on imagjpeg.h, Vaclav Slavik // Author: G. Baruffa - based on imagjpeg.h, Vaclav Slavik
// RCS-ID: $Id: imagj2k.h,v 0.0 2007/02/08 23:45:00 VZ Exp $ // RCS-ID: $Id: imagalljpeg2000.h,v 0.0 2008/01/31 11:22:00 VZ Exp $
// Copyright: (c) Giuseppe Baruffa // Copyright: (c) Giuseppe Baruffa
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_IMAGJ2K_H_ #ifndef _WX_IMAGJPEG2000_H_
#define _WX_IMAGJ2K_H_ #define _WX_IMAGJPEG2000_H_
#include "wx/defs.h" #include "wx/defs.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxJ2KHandler // wxJPEG2000Handler
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#if wxUSE_LIBOPENJPEG #if wxUSE_LIBOPENJPEG
@ -47,26 +47,17 @@
#include "libopenjpeg/openjpeg.h" #include "libopenjpeg/openjpeg.h"
#include "codec/index.h" #include "codec/index.h"
#define wxBITMAP_TYPE_J2K 47 #define wxBITMAP_TYPE_JPEG2000 50
#define wxIMAGE_OPTION_REDUCEFACTOR wxString(_T("reducefactor")) class WXDLLEXPORT wxJPEG2000Handler: public wxImageHandler
#define wxIMAGE_OPTION_QUALITYLAYERS wxString(_T("qualitylayers"))
#define wxIMAGE_OPTION_MAXCOMPS wxString(_T("maxcomps"))
#ifdef USE_JPWL
#define wxIMAGE_OPTION_ENABLEJPWL wxString(_T("enablejpwl"))
#define wxIMAGE_OPTION_EXPCOMPS wxString(_T("expcomps"))
#define wxIMAGE_OPTION_MAXTILES wxString(_T("maxtiles"))
#endif // USE_JPWL
class WXDLLEXPORT wxJ2KHandler: public wxImageHandler
{ {
public: public:
inline wxJ2KHandler() inline wxJPEG2000Handler()
{ {
m_name = wxT("JPEG 2000 codestream file"); m_name = wxT("JPEG 2000 family file format");
m_extension = wxT("j2k"); m_extension = wxT("mj2");
m_type = wxBITMAP_TYPE_J2K; m_type = wxBITMAP_TYPE_JPEG2000;
m_mime = wxT("image/j2k"); m_mime = wxT("image/mj2");
/* decoding */ /* decoding */
m_reducefactor = 0; m_reducefactor = 0;
@ -128,7 +119,7 @@ public:
} }
// decoding engine parameters // decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components; int m_reducefactor, m_qualitylayers, m_components, m_framenum;
#ifdef USE_JPWL #ifdef USE_JPWL
bool m_enablejpwl; bool m_enablejpwl;
int m_expcomps, m_maxtiles; int m_expcomps, m_maxtiles;
@ -169,18 +160,18 @@ public:
wxString m_poc; wxString m_poc;
#if wxUSE_STREAMS #if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 ); virtual bool LoadFile(wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1);
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true ); virtual bool SaveFile(wxImage *image, wxOutputStream& stream, bool verbose=true);
protected: protected:
virtual bool DoCanRead( wxInputStream& stream ); virtual bool DoCanRead(wxInputStream& stream);
#endif #endif
private: private:
OPJ_PROG_ORDER give_progression(char progression[4]); OPJ_PROG_ORDER give_progression(char progression[4]);
DECLARE_DYNAMIC_CLASS(wxJ2KHandler) DECLARE_DYNAMIC_CLASS(wxJPEG2000Handler)
}; };
#endif // wxUSE_LIBOPENJPEG #endif // wxUSE_LIBOPENJPEG
#endif // _WX_IMAGJ2K_H_ #endif // _WX_IMAGJPEG2000_H_

View File

@ -1,771 +0,0 @@
/*
* Copyright (c) 2007, Digital Signal Processing Laboratory, Università degli studi di Perugia (UPG), Italy
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/////////////////////////////////////////////////////////////////////////////
// Name: imagmj2.cpp
// Purpose: wxImage Motion JPEG 2000 file format handler
// Author: Giuseppe Baruffa - based on imagjpeg.cpp, Vaclav Slavik
// RCS-ID: $Id: imagmj2.cpp,v 0.00 2007/02/18 23:59:00 MW Exp $
// Copyright: (c) Giuseppe Baruffa
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_IMAGE && wxUSE_LIBOPENJPEG
#include "imagmj2.h"
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/app.h"
#include "wx/intl.h"
#include "wx/bitmap.h"
#include "wx/module.h"
#endif
#include "libopenjpeg/openjpeg.h"
#include "wx/filefn.h"
#include "wx/wfstream.h"
// ----------------------------------------------------------------------------
// types
// ----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// wxMJ2Handler
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMJ2Handler,wxImageHandler)
#if wxUSE_STREAMS
//------------- JPEG 2000 Data Source Manager
#define J2K_CFMT 0
#define JP2_CFMT 1
#define JPT_CFMT 2
#define MJ2_CFMT 3
#define PXM_DFMT 0
#define PGX_DFMT 1
#define BMP_DFMT 2
#define YUV_DFMT 3
#define MAX_MESSAGE_LEN 200
/* sample error callback expecting a FILE* client object */
void mj2_error_callback(const char *msg, void *client_data) {
int message_len = strlen(msg) - 1;
if (msg[message_len] != '\n')
message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("[ERROR] %.*s"), message_len, msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
/* sample warning callback expecting a FILE* client object */
void mj2_warning_callback(const char *msg, void *client_data) {
int message_len = strlen(msg) - 1;
if (msg[message_len] != '\n')
message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("[WARNING] %.*s"), message_len, msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
/* sample debug callback expecting no client object */
void mj2_info_callback(const char *msg, void *client_data) {
int message_len = strlen(msg) - 1;
if (msg[message_len] != '\n')
message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("[INFO] %.*s"), message_len, msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
/* macro functions */
/* From little endian to big endian, 2 and 4 bytes */
#define BYTE_SWAP2(X) ((X & 0x00FF) << 8) | ((X & 0xFF00) >> 8)
#define BYTE_SWAP4(X) ((X & 0x000000FF) << 24) | ((X & 0x0000FF00) << 8) | ((X & 0x00FF0000) >> 8) | ((X & 0xFF000000) >> 24)
#ifdef __WXGTK__
#define BYTE_SWAP8(X) ((X & 0x00000000000000FFULL) << 56) | ((X & 0x000000000000FF00ULL) << 40) | \
((X & 0x0000000000FF0000ULL) << 24) | ((X & 0x00000000FF000000ULL) << 8) | \
((X & 0x000000FF00000000ULL) >> 8) | ((X & 0x0000FF0000000000ULL) >> 24) | \
((X & 0x00FF000000000000ULL) >> 40) | ((X & 0xFF00000000000000ULL) >> 56)
#else
#define BYTE_SWAP8(X) ((X & 0x00000000000000FF) << 56) | ((X & 0x000000000000FF00) << 40) | \
((X & 0x0000000000FF0000) << 24) | ((X & 0x00000000FF000000) << 8) | \
((X & 0x000000FF00000000) >> 8) | ((X & 0x0000FF0000000000) >> 24) | \
((X & 0x00FF000000000000) >> 40) | ((X & 0xFF00000000000000) >> 56)
#endif
/* From codestream to int values */
#define STREAM_TO_UINT32(C, P) (((unsigned long int) (C)[(P) + 0] << 24) + \
((unsigned long int) (C)[(P) + 1] << 16) + \
((unsigned long int) (C)[(P) + 2] << 8) + \
((unsigned long int) (C)[(P) + 3] << 0))
#define STREAM_TO_UINT16(C, P) (((unsigned long int) (C)[(P) + 0] << 8) + \
((unsigned long int) (C)[(P) + 1] << 0))
/* defines */
#define SHORT_DESCR_LEN 32
#define LONG_DESCR_LEN 256
/* enumeration for file formats */
#define J2FILENUM 4
typedef enum {
JP2_FILE,
J2K_FILE,
MJ2_FILE,
UNK_FILE
} my_j2filetype;
/* enumeration for the box types */
#define J2BOXNUM 23
typedef enum {
FILE_BOX,
JP_BOX,
FTYP_BOX,
JP2H_BOX,
IHDR_BOX,
COLR_BOX,
JP2C_BOX,
JP2I_BOX,
XML_BOX,
UUID_BOX,
UINF_BOX,
MOOV_BOX,
MVHD_BOX,
TRAK_BOX,
TKHD_BOX,
MDIA_BOX,
MINF_BOX,
STBL_BOX,
STSD_BOX,
MJP2_BOX,
MDAT_BOX,
ANY_BOX,
UNK_BOX
} my_j2boxtype;
/* jp2 family box signatures */
#define FILE_SIGN ""
#define JP_SIGN "jP\040\040"
#define FTYP_SIGN "ftyp"
#define JP2H_SIGN "jp2h"
#define IHDR_SIGN "ihdr"
#define COLR_SIGN "colr"
#define JP2C_SIGN "jp2c"
#define JP2I_SIGN "jp2i"
#define XML_SIGN "xml\040"
#define UUID_SIGN "uuid"
#define UINF_SIGN "uinf"
#define MOOV_SIGN "moov"
#define MVHD_SIGN "mvhd"
#define TRAK_SIGN "trak"
#define TKHD_SIGN "tkhd"
#define MDIA_SIGN "mdia"
#define MINF_SIGN "minf"
#define VMHD_SIGN "vmhd"
#define STBL_SIGN "stbl"
#define STSD_SIGN "stsd"
#define MJP2_SIGN "mjp2"
#define MDAT_SIGN "mdat"
#define ANY_SIGN ""
#define UNK_SIGN ""
/* the box structure itself */
struct my_boxdef {
char value[5]; /* hexadecimal value/string*/
char name[SHORT_DESCR_LEN]; /* short description */
char descr[LONG_DESCR_LEN]; /* long description */
int sbox; /* is it a superbox? */
int req[J2FILENUM]; /* mandatory box */
my_j2boxtype ins; /* contained in box... */
};
/* the possible boxes */
struct my_boxdef j2box[] =
{
/* sign */ {FILE_SIGN,
/* short */ "placeholder for nothing",
/* long */ "Nothing to say",
/* sbox */ 0,
/* req */ {1, 1, 1},
/* ins */ FILE_BOX},
/* sign */ {JP_SIGN,
/* short */ "JPEG 2000 Signature box",
/* long */ "This box uniquely identifies the file as being part of the JPEG 2000 family of files",
/* sbox */ 0,
/* req */ {1, 1, 1},
/* ins */ FILE_BOX},
/* sign */ {FTYP_SIGN,
/* short */ "File Type box",
/* long */ "This box specifies file type, version and compatibility information, including specifying if this file "
"is a conforming JP2 file or if it can be read by a conforming JP2 reader",
/* sbox */ 0,
/* req */ {1, 1, 1},
/* ins */ FILE_BOX},
/* sign */ {JP2H_SIGN,
/* short */ "JP2 Header box",
/* long */ "This box contains a series of boxes that contain header-type information about the file",
/* sbox */ 1,
/* req */ {1, 1, 1},
/* ins */ FILE_BOX},
/* sign */ {IHDR_SIGN,
/* short */ "Image Header box",
/* long */ "This box specifies the size of the image and other related fields",
/* sbox */ 0,
/* req */ {1, 1, 1},
/* ins */ JP2H_BOX},
/* sign */ {COLR_SIGN,
/* short */ "Colour Specification box",
/* long */ "This box specifies the colourspace of the image",
/* sbox */ 0,
/* req */ {1, 1, 1},
/* ins */ JP2H_BOX},
/* sign */ {JP2C_SIGN,
/* short */ "Contiguous Codestream box",
/* long */ "This box contains the codestream as defined by Annex A",
/* sbox */ 0,
/* req */ {1, 1, 1},
/* ins */ FILE_BOX},
/* sign */ {JP2I_SIGN,
/* short */ "Intellectual Property box",
/* long */ "This box contains intellectual property information about the image",
/* sbox */ 0,
/* req */ {0, 0, 0},
/* ins */ FILE_BOX},
/* sign */ {XML_SIGN,
/* short */ "XML box",
/* long */ "This box provides a tool by which vendors can add XML formatted information to a JP2 file",
/* sbox */ 0,
/* req */ {0, 0, 0},
/* ins */ FILE_BOX},
/* sign */ {UUID_SIGN,
/* short */ "UUID box",
/* long */ "This box provides a tool by which vendors can add additional information to a file "
"without risking conflict with other vendors",
/* sbox */ 0,
/* req */ {0, 0, 0},
/* ins */ FILE_BOX},
/* sign */ {UINF_SIGN,
/* short */ "UUID Info box",
/* long */ "This box provides a tool by which a vendor may provide access to additional information associated with a UUID",
/* sbox */ 0,
/* req */ {0, 0, 0},
/* ins */ FILE_BOX},
/* sign */ {MOOV_SIGN,
/* short */ "Movie box",
/* long */ "This box contains the media data. In video tracks, this box would contain JPEG2000 video frames",
/* sbox */ 1,
/* req */ {1, 1, 1},
/* ins */ FILE_BOX},
/* sign */ {MVHD_SIGN,
/* short */ "Movie Header box",
/* long */ "This box defines overall information which is media-independent, and relevant to the entire presentation "
"considered as a whole",
/* sbox */ 0,
/* req */ {1, 1, 1},
/* ins */ MOOV_BOX},
/* sign */ {TRAK_SIGN,
/* short */ "Track box",
/* long */ "This is a container box for a single track of a presentation. A presentation may consist of one or more tracks",
/* sbox */ 1,
/* req */ {1, 1, 1},
/* ins */ MOOV_BOX},
/* sign */ {TKHD_SIGN,
/* short */ "Track Header box",
/* long */ "This box specifies the characteristics of a single track. Exactly one Track Header Box is contained in a track",
/* sbox */ 0,
/* req */ {1, 1, 1},
/* ins */ TRAK_BOX},
/* sign */ {MDIA_SIGN,
/* short */ "Media box",
/* long */ "The media declaration container contains all the objects which declare information about the media data "
"within a track",
/* sbox */ 1,
/* req */ {1, 1, 1},
/* ins */ TRAK_BOX},
/* sign */ {MINF_SIGN,
/* short */ "Media Information box",
/* long */ "This box contains all the objects which declare characteristic information of the media in the track",
/* sbox */ 1,
/* req */ {1, 1, 1},
/* ins */ MDIA_BOX},
/* sign */ {STBL_SIGN,
/* short */ "Sample Table box",
/* long */ "The sample table contains all the time and data indexing of the media samples in a track",
/* sbox */ 1,
/* req */ {1, 1, 1},
/* ins */ MINF_BOX},
/* sign */ {STSD_SIGN,
/* short */ "Sample Description box",
/* long */ "The sample description table gives detailed information about the coding type used, and any initialization "
"information needed for that coding",
/* sbox */ 0,
/* req */ {1, 1, 1},
/* ins */ MINF_BOX},
/* sign */ {MJP2_SIGN,
/* short */ "MJP2 Sample Description box",
/* long */ "The MJP2 sample description table gives detailed information about the coding type used, and any initialization "
"information needed for that coding",
/* sbox */ 0,
/* req */ {1, 1, 1},
/* ins */ MINF_BOX},
/* sign */ {MDAT_SIGN,
/* short */ "Media Data box",
/* long */ "The meta-data for a presentation is stored in the single Movie Box which occurs at the top-level of a file",
/* sbox */ 1,
/* req */ {1, 1, 1},
/* ins */ FILE_BOX},
/* sign */ {ANY_SIGN,
/* short */ "Any box",
/* long */ "All the existing boxes",
/* sbox */ 0,
/* req */ {0, 0, 0},
/* ins */ FILE_BOX},
/* sign */ {UNK_SIGN,
/* short */ "Unknown Type box",
/* long */ "The signature is not recognised to be that of an existing box",
/* sbox */ 0,
/* req */ {0, 0, 0},
/* ins */ ANY_BOX}
};
/* declaration */
int
my_box_handler_function(my_j2boxtype boxtype, wxInputStream& stream, unsigned long int filepoint, unsigned long int filelimit, int level,
char *scansign, unsigned long int *scanpoint);
#ifdef __WXMSW__
typedef unsigned __int64 int8byte;
#endif // __WXMSW__
#ifdef __WXGTK__
typedef unsigned long long int8byte;
#endif // __WXGTK__
/* internal mini-search for a box signature */
int
my_jpeg2000parse(wxInputStream& stream, unsigned long int filepoint, unsigned long int filelimit, int level,
char *scansign, unsigned long int *scanpoint)
{
unsigned long int LBox = 0x00000000;
//int LBox_read;
char TBox[5] = "\0\0\0\0";
//int TBox_read;
int8byte XLBox = 0x0000000000000000;
//int XLBox_read;
unsigned long int box_length = 0;
int last_box = 0, box_num = 0;
int box_type = ANY_BOX;
unsigned char /*onebyte[1], twobytes[2],*/ fourbytes[4];
int box_number = 0;
/* cycle all over the file */
box_num = 0;
last_box = 0;
while (!last_box) {
/* do not exceed file limit */
if (filepoint >= filelimit)
return (0);
/* seek on file */
if (stream.SeekI(filepoint, wxFromStart) == wxInvalidOffset)
return (-1);
/* read the mandatory LBox, 4 bytes */
if (!stream.Read(fourbytes, 4)) {
(wxT("Problem reading LBox from the file (file ended?)"));
return -1;
};
LBox = STREAM_TO_UINT32(fourbytes, 0);
/* read the mandatory TBox, 4 bytes */
if (!stream.Read(TBox, 4)) {
wxLogError(wxT("Problem reading TBox from the file (file ended?)"));
return -1;
};
/* look if scansign is got */
if ((scansign != NULL) && (memcmp(TBox, scansign, 4) == 0)) {
/* hack/exploit */
// stop as soon as you find the level-th codebox
if (box_number == level) {
memcpy(scansign, " ", 4);
*scanpoint = filepoint;
return (0);
} else
box_number++;
};
/* determine the box type */
for (box_type = JP_BOX; box_type < UNK_BOX; box_type++)
if (memcmp(TBox, j2box[box_type].value, 4) == 0)
break;
/* read the optional XLBox, 8 bytes */
if (LBox == 1) {
if (!stream.Read(&XLBox, 8)) {
wxLogError(wxT("Problem reading XLBox from the file (file ended?)"));
return -1;
};
box_length = (unsigned long int) BYTE_SWAP8(XLBox);
} else if (LBox == 0x00000000) {
/* last box in file */
last_box = 1;
box_length = filelimit - filepoint;
} else
box_length = LBox;
/* go deep in the box */
my_box_handler_function((my_j2boxtype) box_type, stream, (LBox == 1) ? (filepoint + 16) : (filepoint + 8), filepoint + box_length, level,
scansign, scanpoint);
/* if it's a superbox go inside it */
if (j2box[box_type].sbox)
my_jpeg2000parse(stream, (LBox == 1) ? (filepoint + 16) : (filepoint + 8), filepoint + box_length,
level, scansign, scanpoint);
/* increment box number and filepoint*/
box_num++;
filepoint += box_length;
};
/* all good */
return (0);
}
// search first contiguos codestream box in an mj2 file
unsigned long int
searchjp2c(wxInputStream& stream, unsigned long int fsize, int number)
{
char scansign[] = "jp2c";
unsigned long int scanpoint = 0L;
wxLogMessage(wxT("MJ2: searching jp2c box... "));
/* do the parsing */
if (my_jpeg2000parse(stream, 0, fsize, number, scansign, &scanpoint) < 0)
wxLogMessage(wxT("MJ2: Unrecoverable error during file parsing: stopping"));
if (strcmp(scansign, " "))
wxLogMessage(wxT("MJ2: not found"));
else {
wxLogMessage(wxString::Format(wxT("MJ2: found at byte %d"), scanpoint));
};
return (scanpoint);
}
// search the jp2h box in the file
unsigned long int
searchjpegheaderbox(wxInputStream& stream, unsigned long int fsize)
{
char scansign[] = "jp2h";
unsigned long int scanpoint = 0L;
wxLogMessage(wxT("MJ2: searching jp2h box... "));
/* do the parsing */
if (my_jpeg2000parse(stream, 0, fsize, 0, scansign, &scanpoint) < 0)
wxLogMessage(wxT("Unrecoverable error during file parsing: stopping"));
if (strcmp(scansign, " "))
wxLogMessage(wxT("MJ2: not found"));
else
wxLogMessage(wxString::Format(wxT("MJ2: found at byte %d"), scanpoint));
return (scanpoint);
}
/* handling functions */
#define ITEM_PER_ROW 10
/* Box handler function */
int
my_box_handler_function(my_j2boxtype boxtype, wxInputStream& stream, unsigned long int filepoint, unsigned long int filelimit, int level,
char *scansign, unsigned long int *scanpoint)
{
switch (boxtype) {
/* Sample Description box */
case (STSD_BOX):
my_jpeg2000parse(stream, filepoint + 8, filelimit, level, scansign, scanpoint);
break;
/* MJP2 Sample Description box */
case (MJP2_BOX):
my_jpeg2000parse(stream, filepoint + 78, filelimit, level, scansign, scanpoint);
break;
/* not yet implemented */
default:
break;
};
return (0);
}
// the jP and ftyp parts of the header
#define my_jPheadSIZE 32
unsigned char my_jPhead[my_jPheadSIZE] = {
0x00, 0x00, 0x00, 0x0C, 'j', 'P', ' ', ' ',
0x0D, 0x0A, 0x87, 0x0A, 0x00, 0x00, 0x00, 0x14,
'f', 't', 'y', 'p', 'j', 'p', '2', ' ',
0x00, 0x00, 0x00, 0x00, 'j', 'p', '2', ' '
};
/////////////////////////////////////////////////
/////////////////////////////////////////////////
// load the mj2 file format
bool wxMJ2Handler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, int index)
{
opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_image_t *opjimage = NULL;
unsigned char *src = NULL;
unsigned char *ptr;
int file_length, jp2c_point, jp2h_point;
unsigned long int jp2hboxlen, jp2cboxlen;
opj_codestream_info_t cstr_info; /* Codestream information structure */
// destroy the image
image->Destroy();
/* handle to a decompressor */
opj_dinfo_t* dinfo = NULL;
opj_cio_t *cio = NULL;
/* configure the event callbacks (not required) */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = mj2_error_callback;
event_mgr.warning_handler = mj2_warning_callback;
event_mgr.info_handler = mj2_info_callback;
/* set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters);
/* prepare parameters */
strncpy(parameters.infile, "", sizeof(parameters.infile)-1);
strncpy(parameters.outfile, "", sizeof(parameters.outfile)-1);
parameters.decod_format = JP2_CFMT;
parameters.cod_format = BMP_DFMT;
if (m_reducefactor)
parameters.cp_reduce = m_reducefactor;
if (m_qualitylayers)
parameters.cp_layer = m_qualitylayers;
/*if (n_components)
parameters. = n_components;*/
/* JPWL only */
#ifdef USE_JPWL
parameters.jpwl_exp_comps = m_expcomps;
parameters.jpwl_max_tiles = m_maxtiles;
parameters.jpwl_correct = m_enablejpwl;
#endif /* USE_JPWL */
/* get a decoder handle */
dinfo = opj_create_decompress(CODEC_JP2);
/* find length of the stream */
stream.SeekI(0, wxFromEnd);
file_length = (int) stream.TellI();
/* search for the first codestream box and the movie header box */
jp2c_point = searchjp2c(stream, file_length, m_framenum);
jp2h_point = searchjpegheaderbox(stream, file_length);
// read the jp2h box and store it
stream.SeekI(jp2h_point, wxFromStart);
stream.Read(&jp2hboxlen, sizeof(unsigned long int));
jp2hboxlen = BYTE_SWAP4(jp2hboxlen);
// read the jp2c box and store it
stream.SeekI(jp2c_point, wxFromStart);
stream.Read(&jp2cboxlen, sizeof(unsigned long int));
jp2cboxlen = BYTE_SWAP4(jp2cboxlen);
// malloc memory source
src = (unsigned char *) malloc(my_jPheadSIZE + jp2hboxlen + jp2cboxlen);
// copy the jP and ftyp
memcpy(src, my_jPhead, my_jPheadSIZE);
// copy the jp2h
stream.SeekI(jp2h_point, wxFromStart);
stream.Read(&src[my_jPheadSIZE], jp2hboxlen);
// copy the jp2c
stream.SeekI(jp2c_point, wxFromStart);
stream.Read(&src[my_jPheadSIZE + jp2hboxlen], jp2cboxlen);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, &parameters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, src, my_jPheadSIZE + jp2hboxlen + jp2cboxlen);
/* decode the stream and fill the image structure */
opjimage = opj_decode_with_info(dinfo, cio, &cstr_info);
if (!opjimage) {
wxMutexGuiEnter();
wxLogError(wxT("MJ2: failed to decode image!"));
wxMutexGuiLeave();
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
free(src);
return false;
}
/* close the byte stream */
opj_cio_close(cio);
/* common rendering method */
#include "imagjpeg2000.cpp"
wxMutexGuiEnter();
wxLogMessage(wxT("MJ2: image loaded."));
wxMutexGuiLeave();
/* close openjpeg structs */
opj_destroy_decompress(dinfo);
opj_image_destroy(opjimage);
free(src);
if (!image->Ok())
return false;
else
return true;
}
// save the mj2 file format
bool wxMJ2Handler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose )
{
wxLogError(wxT("MJ2: Couldn't save movie -> not implemented."));
return false;
}
#ifdef __VISUALC__
#pragma warning(default:4611)
#endif /* VC++ */
// recognize the Motion JPEG 2000 starting box
bool wxMJ2Handler::DoCanRead( wxInputStream& stream )
{
unsigned char hdr[24];
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
return false;
return (hdr[0] == 0x00 &&
hdr[1] == 0x00 &&
hdr[2] == 0x00 &&
hdr[3] == 0x0C &&
hdr[4] == 0x6A &&
hdr[5] == 0x50 &&
hdr[6] == 0x20 &&
hdr[7] == 0x20 &&
hdr[20] == 0x6D &&
hdr[21] == 0x6A &&
hdr[22] == 0x70 &&
hdr[23] == 0x32);
}
#endif // wxUSE_STREAMS
#endif // wxUSE_LIBOPENJPEG

View File

@ -1,92 +0,0 @@
/*
* Copyright (c) 2007, Digital Signal Processing Laboratory, Università degli studi di Perugia (UPG), Italy
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/////////////////////////////////////////////////////////////////////////////
// Name: imagmj2.h
// Purpose: wxImage Motion JPEG 2000 file format handler
// Author: G. Baruffa - based on imagjpeg.h, Vaclav Slavik
// RCS-ID: $Id: imagmj2.h,v 0.0 2007/02/18 23:45:00 VZ Exp $
// Copyright: (c) Giuseppe Baruffa
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_IMAGMJ2_H_
#define _WX_IMAGMJ2_H_
#include "wx/defs.h"
//-----------------------------------------------------------------------------
// wxMJ2Handler
//-----------------------------------------------------------------------------
#if wxUSE_LIBOPENJPEG
#include "wx/image.h"
#include "libopenjpeg/openjpeg.h"
#define wxBITMAP_TYPE_MJ2 49
class WXDLLEXPORT wxMJ2Handler: public wxImageHandler
{
public:
inline wxMJ2Handler()
{
m_name = wxT("Motion JPEG 2000 file format");
m_extension = wxT("mj2");
m_type = wxBITMAP_TYPE_MJ2;
m_mime = wxT("image/mj2");
m_reducefactor = 0;
m_qualitylayers = 0;
m_components = 0;
#ifdef USE_JPWL
m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES;
#endif // USE_JPWL
}
// decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
#ifdef USE_JPWL
bool m_enablejpwl;
int m_expcomps, m_maxtiles;
#endif // USE_JPWL
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );
protected:
virtual bool DoCanRead( wxInputStream& stream );
#endif
private:
DECLARE_DYNAMIC_CLASS(wxMJ2Handler)
};
#endif // wxUSE_LIBOPENJPEG
#endif // _WX_IMAGMJ2_H_

View File

@ -34,6 +34,30 @@
#ifdef USE_MXF #ifdef USE_MXF
#include "mxflib/mxflib.h"
using namespace mxflib;
namespace
{
//! Structure holding information about the essence in each body stream
struct EssenceInfo
{
UMIDPtr PackageID;
PackagePtr Package;
MDObjectPtr Descriptor;
};
//! Map of EssenceInfo structures indexed by BodySID
typedef std::map<UInt32, EssenceInfo> EssenceInfoMap;
//! The map of essence info for this file
EssenceInfoMap EssenceLookup;
};
//! Build an EssenceInfoMap for the essence in a given file
/*! \return True if al OK, else false
*/
bool BuildEssenceInfo(MXFFilePtr &File, EssenceInfoMap &EssenceLookup);
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
@ -73,6 +97,81 @@ IMPLEMENT_DYNAMIC_CLASS(wxMXFHandler,wxImageHandler)
#if wxUSE_STREAMS #if wxUSE_STREAMS
#include <stdarg.h>
#define MAX_MESSAGE_LEN 200
//------------- MXF Manager
// Debug and error messages
//! Display a warning message
void mxflib::warning(const char *Fmt, ...)
{
char msg[MAX_MESSAGE_LEN];
va_list args;
va_start(args, Fmt);
_vsnprintf(msg, MAX_MESSAGE_LEN, Fmt, args);
va_end(args);
int message_len = strlen(msg) - 1;
if (msg[message_len] != '\n')
message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("[WARNING_MXF] %.*s"), message_len, msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
//! Display an error message
void mxflib::error(const char *Fmt, ...)
{
char msg[MAX_MESSAGE_LEN];
va_list args;
va_start(args, Fmt);
_vsnprintf(msg, MAX_MESSAGE_LEN, Fmt, args);
va_end(args);
int message_len = strlen(msg) - 1;
if (msg[message_len] != '\n')
message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("[ERROR_MXF] %.*s"), message_len, msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
//! Display an error message
void mxflib::debug(const char *Fmt, ...)
{
char msg[MAX_MESSAGE_LEN];
va_list args;
va_start(args, Fmt);
_vsnprintf(msg, MAX_MESSAGE_LEN, Fmt, args);
va_end(args);
int message_len = strlen(msg) - 1;
if (msg[message_len] != '\n')
message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif /* __WXGTK__ */
wxLogMessage(wxT("[DEBUG_MXF] %.*s"), message_len, msg);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
//------------- JPEG 2000 Data Source Manager //------------- JPEG 2000 Data Source Manager
#define J2K_CFMT 0 #define J2K_CFMT 0
@ -84,8 +183,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxMXFHandler,wxImageHandler)
#define BMP_DFMT 2 #define BMP_DFMT 2
#define YUV_DFMT 3 #define YUV_DFMT 3
#define MAX_MESSAGE_LEN 200
/* sample error callback expecting a FILE* client object */ /* sample error callback expecting a FILE* client object */
void mxf_error_callback(const char *msg, void *client_data) { void mxf_error_callback(const char *msg, void *client_data) {
int message_len = strlen(msg) - 1; int message_len = strlen(msg) - 1;
@ -142,7 +239,33 @@ bool wxMXFHandler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
unsigned char *ptr; unsigned char *ptr;
int file_length, j2k_point, j2k_len; int file_length, j2k_point, j2k_len;
opj_codestream_info_t cstr_info; /* Codestream information structure */ opj_codestream_info_t cstr_info; /* Codestream information structure */
// simply display the version of the library
wxLogMessage(wxT("Version of MXF: %s "), wxString::FromAscii(LibraryVersion().c_str()));
//wxLogMessage(wxT("MXF file name: %s"), m_filename.GetFullPath());
// open MXF file
MXFFilePtr TestFile = new MXFFile;
if (! TestFile->Open(m_filename.GetFullPath().c_str(), true))
{
wxLogError(wxT("Could not find %s"), m_filename.GetFullPath().c_str());
return false;
} else
wxLogMessage(wxT("Found %s"), m_filename.GetFullPath().c_str());
// Get the size
TestFile->SeekEnd();
wxLogMessage(wxT("Size is %d bytes"), TestFile->Tell());
TestFile->Seek(0);
// essence information
//BuildEssenceInfo(TestFile, EssenceLookup);
// close MXF file
TestFile->Close();
return false;
// destroy the image // destroy the image
image->Destroy(); image->Destroy();
@ -266,6 +389,111 @@ bool wxMXFHandler::DoCanRead( wxInputStream& stream )
hdr[3] == 0x34); hdr[3] == 0x34);
} }
//! Build an EssenceInfoMap for the essence in a given file
/*! \return True if al OK, else false
*/
bool BuildEssenceInfo(MXFFilePtr &File, EssenceInfoMap &EssenceLookup)
{
// Empty any old data
EssenceLookup.clear();
// Get the master metadata set (or the header if we must)
PartitionPtr MasterPartition = File->ReadMasterPartition();
if(!MasterPartition)
{
File->Seek(0);
MasterPartition = File->ReadPartition();
warning("File %s does not contain a cloased copy of header metadata - using the open copy in the file header\n", File->Name.c_str());
}
if(!MasterPartition)
{
error("Could not read header metadata from file %s\n", File->Name.c_str());
return false;
}
// Read and parse the metadata
MasterPartition->ReadMetadata();
MetadataPtr HMeta = MasterPartition->ParseMetadata();
if(!HMeta)
{
error("Could not read header metadata from file %s\n", File->Name.c_str());
return false;
}
/* Scan the Essence container data sets to get PackageID to BodySID mapping */
MDObjectPtr ECDSet = HMeta[ContentStorage_UL];
if(ECDSet) ECDSet = ECDSet->GetLink();
if(ECDSet) ECDSet = ECDSet[EssenceContainerDataBatch_UL];
if(!ECDSet)
{
error("Header metadata in file %s does not contain an EssenceContainerData set\n", File->Name.c_str());
return false;
}
MDObject::iterator it = ECDSet->begin();
while(it != ECDSet->end())
{
MDObjectPtr ThisECDSet = (*it).second->GetLink();
MDObjectPtr PackageID;
if(ThisECDSet) PackageID = ThisECDSet->Child(LinkedPackageUID_UL);
if(PackageID)
{
EssenceInfo NewEI;
NewEI.PackageID = new UMID(PackageID->PutData()->Data);
// Inset the basic essence info - but not if this is external essence (BodySID == 0)
UInt32 BodySID = ThisECDSet->GetUInt(BodySID_UL);
if(BodySID) EssenceLookup[BodySID] = NewEI;
}
it++;
}
/* Now find the other items for the essence lookup map */
if(EssenceLookup.size())
{
PackageList::iterator it = HMeta->Packages.begin();
while(it != HMeta->Packages.end())
{
// Only Source Packages are of interest
if((*it)->IsA(SourcePackage_UL))
{
MDObjectPtr Descriptor = (*it)->Child(Descriptor_UL);
if(Descriptor) Descriptor = Descriptor->GetLink();
if(Descriptor)
{
MDObjectPtr PackageID = (*it)->Child(PackageUID_UL);
if(PackageID)
{
UMIDPtr TheID = new UMID(PackageID->PutData()->Data);
/* Now do a lookup in the essence lookup map (it will need to be done the long way here */
EssenceInfoMap::iterator EL_it = EssenceLookup.begin();
while(EL_it != EssenceLookup.end())
{
if((*((*EL_it).second.PackageID)) == (*TheID))
{
// If found, set the missing items and stop searching
(*EL_it).second.Package = (*it);
(*EL_it).second.Descriptor = Descriptor;
break;
}
EL_it++;
}
}
}
}
it++;
}
}
return true;
}
#endif // wxUSE_STREAMS #endif // wxUSE_STREAMS
#endif // wxUSE_LIBOPENJPEG #endif // wxUSE_LIBOPENJPEG

View File

@ -38,6 +38,7 @@
#ifdef USE_MXF #ifdef USE_MXF
#include "wx/defs.h" #include "wx/defs.h"
#include "wx/filename.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxMXFHandler // wxMXFHandler
@ -48,7 +49,7 @@
#include "wx/image.h" #include "wx/image.h"
#include "libopenjpeg/openjpeg.h" #include "libopenjpeg/openjpeg.h"
#define wxBITMAP_TYPE_MXF 50 #define wxBITMAP_TYPE_MXF 51
class WXDLLEXPORT wxMXFHandler: public wxImageHandler class WXDLLEXPORT wxMXFHandler: public wxImageHandler
{ {
@ -63,6 +64,7 @@ public:
m_reducefactor = 0; m_reducefactor = 0;
m_qualitylayers = 0; m_qualitylayers = 0;
m_components = 0; m_components = 0;
m_filename = wxT("");
#ifdef USE_JPWL #ifdef USE_JPWL
m_enablejpwl = true; m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS; m_expcomps = JPWL_EXPECTED_COMPONENTS;
@ -72,6 +74,7 @@ public:
// decoding engine parameters // decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum; int m_reducefactor, m_qualitylayers, m_components, m_framenum;
wxFileName m_filename;
#ifdef USE_JPWL #ifdef USE_JPWL
bool m_enablejpwl; bool m_enablejpwl;
int m_expcomps, m_maxtiles; int m_expcomps, m_maxtiles;