Mercurial > mercurial > hgweb_imcv.cgi
changeset 0:ebc42d7a0010
First Release.
author | pyon@macmini |
---|---|
date | Fri, 24 Jan 2014 20:35:59 +0900 |
parents | |
children | 593c93e904b5 |
files | Makefile common.h dndfile.h main.cpp main.h myframe.cpp myframe.h sample.ico sample.rc sample.xpm |
diffstat | 10 files changed, 684 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Fri Jan 24 20:35:59 2014 +0900 @@ -0,0 +1,92 @@ +# Makefile for wxWidgets Application +# Last Change: 16-Jan-2014. +# by Takayuki Mutoh +# + +PROGNAME = imcv + +### Variables ### +OBJDIR = ./obj +CXX = g++ +vpath %.cpp ./src +vpath %.h ./include + +# For Microsoft Windows +ifdef COMSPEC +WXCXXFLAGS = -I/local/lib/wx/include/msw-unicode-static-3.0 -I/local/include/wx-3.0 -D_LARGEFILE_SOURCE=unknown -D__WXMSW__ -mthreads +WXLIBS = -L/local/lib -Wl,--subsystem,windows -mwindows /local/lib/libwx_mswu_richtext-3.0.a /local/lib/libwx_mswu_xrc-3.0.a /local/lib/libwx_mswu_webview-3.0.a /local/lib/libwx_mswu_qa-3.0.a /local/lib/libwx_baseu_net-3.0.a /local/lib/libwx_mswu_html-3.0.a /local/lib/libwx_mswu_adv-3.0.a /local/lib/libwx_mswu_core-3.0.a /local/lib/libwx_baseu_xml-3.0.a /local/lib/libwx_baseu-3.0.a -lwxregexu-3.0 -lwxexpat-3.0 -lwxtiff-3.0 -lwxjpeg-3.0 -lwxpng-3.0 -lwxzlib-3.0 -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm -lshell32 -lcomctl32 -lcomdlg32 -ladvapi32 -lwsock32 -lgdi32 +EXECUTABLE = $(PROGNAME).exe + +# For Apple OSX +else +WXCXXFLAGS = -I/opt/local/lib/wx/include/osx_cocoa-unicode-2.9 -I/opt/local/include/wx-2.9 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMAC__ -D__WXOSX__ -D__WXOSX_COCOA__ +WXLIBS = -L/opt/local/lib -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -framework OpenGL -framework QuickTime -lwx_osx_cocoau_richtext-2.9 -lwx_osx_cocoau_xrc-2.9 -lwx_osx_cocoau_webview-2.9 -lwx_osx_cocoau_html-2.9 -lwx_osx_cocoau_qa-2.9 -lwx_osx_cocoau_adv-2.9 -lwx_osx_cocoau_core-2.9 -lwx_baseu_xml-2.9 -lwx_baseu_net-2.9 -lwx_baseu-2.9 + +EXECUTABLE = $(PROGNAME).app/Contents/Pkginfo + +endif + +CXXFLAGS = $(WXCXXFLAGS) -I./include -I./image +LIBS = $(WXLIBS) -static-libgcc -static-libstdc++ + + +OBJ = $(OBJDIR)/main.o \ + $(OBJDIR)/myframe.o + +ifdef COMSPEC +OBJMSW = $(OBJ) $(OBJDIR)/sample_rc.o +endif + + +### Targets ### + +all: $(EXECUTABLE) + + +$(PROGNAME): $(OBJMSW) + $(CXX) $^ -o $@ $(LIBS) + + +$(OBJDIR)/main.o: main.cpp main.h common.h myframe.h + -mkdir -p $(OBJDIR) + $(CXX) -c $< -o $@ $(CXXFLAGS) + +$(OBJDIR)/myframe.o: myframe.cpp myframe.h common.h dndfile.h + $(CXX) -c $< -o $@ $(CXXFLAGS) + + +# for icon +ifdef COMSPEC +$(OBJDIR)/sample_rc.o: sample.rc + windres -i sample.rc -o $@ -I/local/include/wx-3.0 +endif + +$(EXECUTABLE): $(PROGNAME) +ifdef COMSPEC + strip --strip-all $(EXECUTABLE) + ./$(PROGNAME).exe +else + -mkdir -p $(PROGNAME).app/Contents + -mkdir -p $(PROGNAME).app/Contents/MacOS + -mkdir -p $(PROGNAME).app/Contents/Resources + + sed -e "s/IDENTIFIER/$(PROGNAME)/" \ + -e "s/EXECUTABLE/$(PROGNAME)/" \ + -e "s/VERSION/0.0/" \ + Info.plist.in > $(PROGNAME).app/Contents/Info.plist + + echo -n "APPL????" > $(EXECUTABLE) + + ln -f $(PROGNAME) $(PROGNAME).app/Contents/MacOS/$(PROGNAME) + cp -f wxmac.icns $(PROGNAME).app/Contents/Resources/wxmac.icns + + open $(PROGNAME).app +endif + +clean: + rm -f $(PROGNAME) $(PROGNAME).exe + rm -f $(OBJDIR)/*.o + rm -rf $(PROGNAME).app + +.PHONY: all clean +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common.h Fri Jan 24 20:35:59 2014 +0900 @@ -0,0 +1,38 @@ +// Filename : common.h +// Last Change: 17-Jan-2014. +// +#ifndef __COMMON_H__ +#define __COMMON_H__ + +#include "wx/wxprec.h" + +#ifndef WX_PRECOMP + +#include <wx/artprov.h> +#include <wx/bitmap.h> +#include <wx/button.h> +#include <wx/colour.h> +#include <wx/dialog.h> +#include <wx/font.h> +#include <wx/frame.h> +#include <wx/gdicmn.h> +#include <wx/icon.h> +#include <wx/image.h> +#include <wx/listctrl.h> +#include <wx/panel.h> +#include <wx/settings.h> +#include <wx/sizer.h> +#include <wx/stattext.h> +#include <wx/statusbr.h> +#include <wx/string.h> +#include <wx/textctrl.h> +#include <wx/textfile.h> +#include <wx/msgdlg.h> +#include <wx/dir.h> +#include <wx/dnd.h> +#include <wx/xrc/xmlres.h> + +#endif + +#endif // __COMMON_H__ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dndfile.h Fri Jan 24 20:35:59 2014 +0900 @@ -0,0 +1,30 @@ +// Filename : dndfile.h +// Last Change: 16-Jan-2014. +// +#ifndef __DNDFILE_H__ +#define __DNDFILE_H__ + +#include "common.h" + +class DnDFile : public wxFileDropTarget +{ + public: + DnDFile( wxTextCtrl *textCtrl ) + { + m_textCtrl = textCtrl; + } + virtual bool OnDropFiles( wxCoord x, wxCoord y, const wxArrayString& filenames ) + { + size_t nFiles = filenames.GetCount(); + if ( nFiles != 1 ) return false; + m_textCtrl->SetValue( filenames[0] ); + + return true; + } + + private: + wxTextCtrl* m_textCtrl; +}; + +#endif //__DNDFILE_H__ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jan 24 20:35:59 2014 +0900 @@ -0,0 +1,42 @@ +// Filename : main.cpp +// Last Change: 21-Jan-2014. +// +#include "main.h" +#include "myframe.h" + +IMPLEMENT_APP(MyApp) + +IMPLEMENT_CLASS( MyApp, wxApp ) + +MyApp::MyApp() +{ +} +MyApp::~MyApp() +{ +} + +bool MyApp::OnInit() +{ + if ( !wxApp::OnInit() ) return false; + + wxImage::AddHandler( new wxJPEGHandler ); + wxImage::AddHandler( new wxPNGHandler ); + wxImage::AddHandler( new wxXPMHandler ); + wxImage::AddHandler( new wxGIFHandler ); + wxImage::AddHandler( new wxICOHandler ); + wxImage::AddHandler( new wxBMPHandler ); + wxImage::AddHandler( new wxTIFFHandler ); + + long style = wxDEFAULT_FRAME_STYLE; + style = style & ~( wxMAXIMIZE_BOX ); + MyFrame *mainframe = new MyFrame( NULL, wxID_ANY, wxT("IMCV - ImageConverter -"), wxDefaultPosition, wxSize( 450, 200 ), style ); + mainframe->Show(true); + + return true; +} + +int MyApp::OnExit() +{ + return 0; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Fri Jan 24 20:35:59 2014 +0900 @@ -0,0 +1,20 @@ +// Filename : main.h +// Last Change: 15-Jan-2014. +// +#include "wx/wx.h" + +// private classes +// Define a new application type, each program should derive a class from wxApp +class MyApp : public wxApp +{ + DECLARE_CLASS( MyApp ) +public: + MyApp(); + ~MyApp(); + + virtual bool OnInit(); + virtual int OnExit(); +}; + +DECLARE_APP(MyApp) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myframe.cpp Fri Jan 24 20:35:59 2014 +0900 @@ -0,0 +1,320 @@ +// Filename : myframe.cpp +// Last Change: 24-Jan-2014. +// + +#include "myframe.h" +#include "dndfile.h" +#include "sample.xpm" + +MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) + : wxFrame( parent, id, title, pos, size, style ) +{ + this->SetIcon( wxIcon( wxT("sample") ) ); + this->SetSizeHints( wxSize( 450, 200 ), wxSize( 450, 200 ) ); + this->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); + this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) ); + + wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL ); + + // Source + wxBoxSizer* bSizerSource = new wxBoxSizer( wxHORIZONTAL ); + + m_staticTextSource = new wxStaticText( this, wxID_ANY, wxT("Source"), wxDefaultPosition, wxSize( 90,-1 ), wxALIGN_RIGHT ); + m_staticTextSource->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) ); + m_staticTextSource->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DDKSHADOW ) ); + + bSizerSource->Add( m_staticTextSource, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_textCtrlSource = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 200,-1 ), wxTAB_TRAVERSAL ); + bSizerSource->Add( m_textCtrlSource, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + bSizerTop->Add( bSizerSource, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 5 ); + + // Config + // Type + wxBoxSizer* bSizerConfig = new wxBoxSizer( wxHORIZONTAL ); + + m_staticTextConfig = new wxStaticText( this, wxID_ANY, wxT("Config"), wxDefaultPosition, wxSize( 90,-1 ), wxALIGN_RIGHT ); + m_staticTextConfig->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) ); + m_staticTextConfig->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DDKSHADOW ) ); + bSizerConfig->Add( m_staticTextConfig, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_staticTextType = new wxStaticText( this, wxID_ANY, wxT("Type"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT ); + m_staticTextType->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) ); + m_staticTextType->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DDKSHADOW ) ); + bSizerConfig->Add( m_staticTextType, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_comboBoxType = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY|wxTAB_TRAVERSAL ); + m_comboBoxType->Append( wxT("Not change") ); + m_comboBoxType->Append( wxT("PNG") ); + m_comboBoxType->Append( wxT("XPM") ); + m_comboBoxType->Append( wxT("GIF") ); + m_comboBoxType->Append( wxT("ICON") ); + m_comboBoxType->Append( wxT("BMP") ); + m_comboBoxType->Append( wxT("TIFF") ); + m_comboBoxType->SetSelection( 0 ); + bSizerConfig->Add( m_comboBoxType, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + // Size + m_staticTextSize = new wxStaticText( this, wxID_ANY, wxT("Size"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT ); + m_staticTextSize->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) ); + m_staticTextSize->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DDKSHADOW ) ); + bSizerConfig->Add( m_staticTextSize, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_staticTextWidth = new wxStaticText( this, wxID_ANY, wxT("Width"), wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + m_staticTextWidth->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) ); + m_staticTextWidth->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DDKSHADOW ) ); + bSizerConfig->Add( m_staticTextWidth, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); + + m_textCtrlWidth = new wxTextCtrl( this, wxID_ANY, wxT("0"), wxDefaultPosition, wxSize( 40, -1 ), wxTE_CENTRE ); + bSizerConfig->Add( m_textCtrlWidth, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_staticTextHeight = new wxStaticText( this, wxID_ANY, wxT("Height"), wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + m_staticTextHeight->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) ); + m_staticTextHeight->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DDKSHADOW ) ); + bSizerConfig->Add( m_staticTextHeight, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); + + m_textCtrlHeight = new wxTextCtrl( this, wxID_ANY, wxT("0"), wxDefaultPosition, wxSize( 50, -1 ), wxTE_CENTRE ); + bSizerConfig->Add( m_textCtrlHeight, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + bSizerTop->Add( bSizerConfig, 1, wxEXPAND, 5 ); + + // Output + wxBoxSizer* bSizerOutput = new wxBoxSizer( wxHORIZONTAL ); + + m_staticTextOutput = new wxStaticText( this, wxID_ANY, wxT("Output folder"), wxDefaultPosition, wxSize( 90,-1 ), wxALIGN_RIGHT ); + m_staticTextOutput->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) ); + m_staticTextOutput->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DDKSHADOW ) ); + bSizerOutput->Add( m_staticTextOutput, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_dirPicker = new wxDirPickerCtrl( this, wxID_ANY, wxGetCwd(), wxT("Select a folder"), wxDefaultPosition, wxSize( 200,-1 ), wxDIRP_DEFAULT_STYLE ); + m_dirPicker->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DDKSHADOW ) ); + bSizerOutput->Add( m_dirPicker, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + bSizerTop->Add( bSizerOutput, 1, wxEXPAND, 5 ); + + // Button + wxBoxSizer* bSizerButton = new wxBoxSizer( wxHORIZONTAL ); + + m_buttonExec = new wxButton( this, ID_EXEC, wxT("Exec"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerButton->Add( m_buttonExec, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_buttonExit = new wxButton( this, ID_EXIT, wxT("Exit"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerButton->Add( m_buttonExit, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + bSizerTop->Add( bSizerButton, 1, wxALIGN_RIGHT|wxALL, 5 ); + + // + this->SetSizer( bSizerTop ); + this->Layout(); + + this->SetDropTarget( new DnDFile( m_textCtrlSource ) ); + + this->Centre( wxBOTH ); +} + +MyFrame::~MyFrame() +{ +} + +// Event Table +BEGIN_EVENT_TABLE( MyFrame, wxFrame ) + EVT_BUTTON( ID_EXEC, MyFrame::OnExec ) + EVT_BUTTON( ID_EXIT, MyFrame::OnExit ) +END_EVENT_TABLE() + +void MyFrame::OnExec( wxCommandEvent& WXUNUSED(event) ) +{ + wxString buf; + + wxString file, path; + buf = m_textCtrlSource->GetValue(); + if ( wxFileName::FileExists( buf ) ) file = buf; + if ( wxFileName::DirExists( buf ) ) path = buf; + if ( file.IsEmpty() && path.IsEmpty() ) { + WarnMessage( wxT("no input !") ); + return; + } + + choice_type = m_comboBoxType->GetSelection(); + + buf = m_textCtrlWidth->GetValue(); + buf.ToLong( &w, 10 ); + buf = m_textCtrlHeight->GetValue(); + buf.ToLong( &h, 10 ); + + if ( choice_type == 0 && w == 0 && h == 0 ) { + WarnMessage( wxT("no change !") ); + return; + } + + buf = m_dirPicker->GetPath(); + if ( buf.IsEmpty() ) { + WarnMessage( wxT("no output directory !") ); + return; + } + out_dir = buf; + + bool result; + if ( file.IsEmpty() ) { + result = ConvertFiles( path ); + } + else { + result = ConvertAFile( file ); + } + if ( !result ) return; + + wxMessageDialog *md = new wxMessageDialog( this, wxT("Done !"), wxT("Message"), wxICON_INFORMATION|wxOK ); + md->ShowModal(); + md->Destroy(); +} + +void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) +{ + Close(); +} + +void MyFrame::WarnMessage( wxString msg ) +{ + wxMessageDialog *md = new wxMessageDialog( this, msg, wxT("Warning"), wxICON_ERROR|wxOK ); + md->ShowModal(); + md->Destroy(); +} + +bool MyFrame::ConvertAFile( wxString file ) +{ + wxFileName f( file ); + wxString ext = f.GetExt(); + wxString name = f.GetName(); + int in_type; + + if ( ext.IsSameAs( wxT("jpg"), false ) ) in_type = wxBITMAP_TYPE_JPEG; + else if ( ext.IsSameAs( wxT("jpeg"), false ) ) in_type = wxBITMAP_TYPE_JPEG; + else if ( ext.IsSameAs( wxT("png"), false ) ) in_type = wxBITMAP_TYPE_PNG; + else if ( ext.IsSameAs( wxT("xpm"), false ) ) in_type = wxBITMAP_TYPE_XPM; + else if ( ext.IsSameAs( wxT("gif"), false ) ) in_type = wxBITMAP_TYPE_GIF; + else if ( ext.IsSameAs( wxT("ico"), false ) ) in_type = wxBITMAP_TYPE_ICO; + else if ( ext.IsSameAs( wxT("bmp"), false ) ) in_type = wxBITMAP_TYPE_BMP; + else if ( ext.IsSameAs( wxT("tif"), false ) ) in_type = wxBITMAP_TYPE_TIFF; + else if ( ext.IsSameAs( wxT("tiff"), false ) ) in_type = wxBITMAP_TYPE_TIFF; + + int out_type = in_type; + if ( choice_type == 1 ) { + out_type = wxBITMAP_TYPE_PNG; + ext = wxT("png"); + } + else if ( choice_type == 2 ) { + out_type = wxBITMAP_TYPE_XPM; + ext = wxT("xpm"); + } + else if ( choice_type == 3 ) { + out_type = wxBITMAP_TYPE_GIF; + ext = wxT("gif"); + } + else if ( choice_type == 4 ) { + out_type = wxBITMAP_TYPE_ICO; + ext = wxT("ico"); + } + else if ( choice_type == 5 ) { + out_type = wxBITMAP_TYPE_BMP; + ext = wxT("bmp"); + } + else if ( choice_type == 6 ) { + out_type = wxBITMAP_TYPE_TIFF; + ext = wxT("tiff"); + } + + wxImage image( file, in_type ); + if ( w == 0 || h == 0 ) { + w = (long)(image.GetWidth()); + h = (long)(image.GetHeight()); + } + wxImage output = image.Scale( (int)w, (int)h, wxIMAGE_QUALITY_HIGH ); + wxString outfile = out_dir + wxFILE_SEP_PATH + name + wxT(".") + ext; + + if ( file.IsSameAs( outfile ) ) { + WarnMessage( wxT("Output file is same as input file !") ); + return false; + } + + output.SaveFile( outfile, out_type ); + return true; +} + +bool MyFrame::ConvertFiles( wxString dir ) +{ + wxFileName dn( dir ); + + if ( out_dir.IsSameAs( dn.GetPath() ) ) { + WarnMessage( wxT("Output directory is same as input directory !") ); + return false; + } + + int out_type = wxBITMAP_TYPE_INVALID; + wxString out_ext; + if ( choice_type == 1 ) { + out_type = wxBITMAP_TYPE_PNG; + out_ext = wxT("png"); + } + else if ( choice_type == 2 ) { + out_type = wxBITMAP_TYPE_XPM; + out_ext = wxT("xpm"); + } + else if ( choice_type == 3 ) { + out_type = wxBITMAP_TYPE_GIF; + out_ext = wxT("gif"); + } + else if ( choice_type == 4 ) { + out_type = wxBITMAP_TYPE_ICO; + out_ext = wxT("ico"); + } + else if ( choice_type == 5 ) { + out_type = wxBITMAP_TYPE_BMP; + out_ext = wxT("bmp"); + } + else if ( choice_type == 6 ) { + out_type = wxBITMAP_TYPE_TIFF; + out_ext = wxT("tiff"); + } + + wxArrayString files; + wxDir::GetAllFiles( dir, &files, wxT("*.*"), wxDIR_DEFAULT ); + + for ( int i = 0; i < files.GetCount(); i++ ) { + + wxFileName fn( files[i] ); + wxString in_ext = fn.GetExt(); + int in_type; + + if ( in_ext.IsSameAs( wxT("jpg"), false ) ) in_type = wxBITMAP_TYPE_JPEG; + else if ( in_ext.IsSameAs( wxT("jpeg"), false ) ) in_type = wxBITMAP_TYPE_JPEG; + else if ( in_ext.IsSameAs( wxT("png"), false ) ) in_type = wxBITMAP_TYPE_PNG; + else if ( in_ext.IsSameAs( wxT("xpm"), false ) ) in_type = wxBITMAP_TYPE_XPM; + else if ( in_ext.IsSameAs( wxT("gif"), false ) ) in_type = wxBITMAP_TYPE_GIF; + else if ( in_ext.IsSameAs( wxT("ico"), false ) ) in_type = wxBITMAP_TYPE_ICO; + else if ( in_ext.IsSameAs( wxT("bmp"), false ) ) in_type = wxBITMAP_TYPE_BMP; + else if ( in_ext.IsSameAs( wxT("tif"), false ) ) in_type = wxBITMAP_TYPE_TIFF; + else if ( in_ext.IsSameAs( wxT("tiff"), false ) ) in_type = wxBITMAP_TYPE_TIFF; + + if ( out_type == wxBITMAP_TYPE_INVALID ) out_type = in_type; + + wxString fullpath = fn.GetPath() + wxFILE_SEP_PATH + fn.GetName(); + + fullpath.Replace( dn.GetPath(), wxEmptyString, false ); + fullpath = out_dir + fullpath + wxT(".") + out_ext; + + wxFileName tf( fullpath ); + if ( !tf.Exists() ) tf.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ); + + wxImage image( files[i], in_type ); + if ( w == 0 || h == 0 ) { + w = (long)(image.GetWidth()); + h = (long)(image.GetHeight()); + } + wxImage output = image.Scale( (int)w, (int)h, wxIMAGE_QUALITY_HIGH ); + output.SaveFile( fullpath, out_type ); + } + + return true; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myframe.h Fri Jan 24 20:35:59 2014 +0900 @@ -0,0 +1,69 @@ +// Filename : myframe.h +// Last Change: 21-Jan-2014. +// +#ifndef __MYFRAME_H__ +#define __MYFRAME_H__ + +#include <wx/artprov.h> +#include <wx/xrc/xmlres.h> +#include <wx/string.h> +#include <wx/stattext.h> +#include <wx/gdicmn.h> +#include <wx/font.h> +#include <wx/colour.h> +#include <wx/settings.h> +#include <wx/textctrl.h> +#include <wx/sizer.h> +#include <wx/combobox.h> +#include <wx/filepicker.h> +#include <wx/button.h> +#include <wx/statusbr.h> +#include <wx/frame.h> + +/////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +/// Class MainFrame +/////////////////////////////////////////////////////////////////////////////// +class MyFrame : public wxFrame +{ + DECLARE_EVENT_TABLE() + private: + long w, h; + int choice_type; + wxString out_dir; + + protected: + wxStaticText* m_staticTextSource; + wxTextCtrl* m_textCtrlSource; + wxStaticText* m_staticTextConfig; + wxStaticText* m_staticTextType; + wxComboBox* m_comboBoxType; + wxStaticText* m_staticTextSize; + wxStaticText* m_staticTextWidth; + wxTextCtrl* m_textCtrlWidth; + wxStaticText* m_staticTextHeight; + wxTextCtrl* m_textCtrlHeight; + wxStaticText* m_staticTextOutput; + wxDirPickerCtrl* m_dirPicker; + wxButton* m_buttonExec; + wxButton* m_buttonExit; + + public: + MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ); + ~MyFrame(); + void OnExec( wxCommandEvent& WXUNUSED(event) ); + void OnExit( wxCommandEvent& WXUNUSED(event) ); + void WarnMessage( wxString msg ); + bool ConvertAFile( wxString file ); + bool ConvertFiles( wxString dir ); +}; + +enum +{ + ID_EXEC = wxID_HIGHEST + 1, + ID_EXIT, +}; + +#endif //__MYFRAME_H__ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sample.rc Fri Jan 24 20:35:59 2014 +0900 @@ -0,0 +1,32 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: samples/samples.rc +// Purpose: a standard Win32 .rc file for the wxWindows samples +// Author: Vadim Zeitlin +// Modified by: +// Created: 04.08.03 +// RCS-ID: $Id: sample.rc 22863 2003-08-14 14:08:53Z VS $ +// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org> +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// this minimal resource file is all what is needed for most of the wxWindows +// samples + +// note that the icon used by the Explorer (i.e. the programs icon) is the +// first icon in the executable and the icons are sorted both by their order +// (Win9x) and by alphabetically (!) (NT), so put this icon first and give it +// a name starting with "a" +aaaaaaaa ICON "sample.ico" + +// this icon is used with wxFrame::SetIcon() +sample ICON "sample.ico" + +// set this to 1 if you don't want to use manifest resource (manifest resource +// is needed to enable visual styles on Windows XP - see docs/msw/winxp.txt +// for more information) +#define wxUSE_NO_MANIFEST 0 + +// this is not always needed but doesn't hurt (except making the executable +// very slightly larger): this file contains the standard icons, cursors, ... +#include "wx/msw/wx.rc" +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sample.xpm Fri Jan 24 20:35:59 2014 +0900 @@ -0,0 +1,41 @@ +/* XPM */ +static const char *sample_xpm[] = { +/* columns rows colors chars-per-pixel */ +"32 32 3 1", +" c Black", +"X c #FFFFFF", +". c #3F48CC", +/* pixels */ +" ", +" ", +" .. ", +" .. ", +" .... ", +" ...... ", +" ........ ", +" ........ ", +" ..XXXXXX.. ", +" ..........XXXXXXXX.......... ", +" ........XXXXXXXXXX........ ", +" ........XXXXXXXXXX........ ", +" ......XXXXXXXXXXXX...... ", +" .....XXXXXXXXXXXX..... ", +" .....XXXXXXXXXXXX..... ", +" ....XXXXXXXXXXXX.... ", +" ....XXXXXXXXXXXX.... ", +" .....XXXXXXXXXXXX..... ", +" .....XXXXXXXXXXXX..... ", +" ......XXXXXXXXXXXX...... ", +" ........XXXXXXXXXX........ ", +" ........XXXXXXXXXX........ ", +" ..........XXXXXXXX.......... ", +" ..XXXXXX.. ", +" ........ ", +" ........ ", +" ...... ", +" .... ", +" .. ", +" .. ", +" ", +" " +};