Mercurial > mercurial > hgweb_golang.cgi
comparison src/kaigo/horori/alloc/alloc.cpp @ 65:0369656be06c default tip
many changes.
author | pyon@macmini |
---|---|
date | Fri, 20 May 2022 06:30:34 +0900 |
parents | 665f92c37b72 |
children |
comparison
equal
deleted
inserted
replaced
64:ad5c30ee5cf1 | 65:0369656be06c |
---|---|
1 // Filename : alloc.cpp | 1 // Filename : alloc.cpp |
2 // Last Change: 2020-05-21 木 15:17:26. | 2 // Last Change: 2021-05-10 月 10:53:23. |
3 // | 3 // |
4 #include <wx/dir.h> | 4 #include <wx/dir.h> |
5 #include <wx/filefn.h> | 5 #include <wx/filefn.h> |
6 #include <wx/textfile.h> | 6 #include <wx/textfile.h> |
7 #include <wx/utils.h> | 7 #include <wx/utils.h> |
8 #include <wx/msgdlg.h> | 8 #include <wx/msgdlg.h> |
9 #include <wx/progdlg.h> | |
10 #include <wx/filename.h> | |
9 #include <wx/fileconf.h> | 11 #include <wx/fileconf.h> |
10 | 12 |
11 #include "alloc.h" | 13 #include "alloc.h" |
14 | |
15 #define WIDTH 2480 | |
16 #define HEIGHT 3508 | |
12 | 17 |
13 | 18 |
14 AllocFrame::AllocFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) | 19 AllocFrame::AllocFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) |
15 : wxFrame(parent, id, title, pos, size, style) | 20 : wxFrame(parent, id, title, pos, size, style) |
16 { | 21 { |
45 fgSizer->Add(0, 0, 1, wxEXPAND, 5); | 50 fgSizer->Add(0, 0, 1, wxEXPAND, 5); |
46 | 51 |
47 m_filePickerPdf2 = new wxFilePickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a file"), wxT("*.pdf"), wxDefaultPosition, pksz, wxFLP_FILE_MUST_EXIST|wxFLP_SMALL|wxFLP_USE_TEXTCTRL); | 52 m_filePickerPdf2 = new wxFilePickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a file"), wxT("*.pdf"), wxDefaultPosition, pksz, wxFLP_FILE_MUST_EXIST|wxFLP_SMALL|wxFLP_USE_TEXTCTRL); |
48 fgSizer->Add(m_filePickerPdf2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | 53 fgSizer->Add(m_filePickerPdf2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); |
49 | 54 |
55 fgSizer->Add(0, 0, 1, wxEXPAND, 5); | |
56 | |
57 m_checkBoxSkipPdf = new wxCheckBox(this, wxID_ANY, wxT("PDFからの変換をスキップする"), wxDefaultPosition, wxDefaultSize, 0); | |
58 fgSizer->Add(m_checkBoxSkipPdf, 0, wxALL, 5); | |
59 | |
50 m_staticTextTif = new wxStaticText(this, wxID_ANY, wxT("TIFフォルダ"), wxDefaultPosition, wxDefaultSize, 0); | 60 m_staticTextTif = new wxStaticText(this, wxID_ANY, wxT("TIFフォルダ"), wxDefaultPosition, wxDefaultSize, 0); |
51 fgSizer->Add(m_staticTextTif, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5); | 61 fgSizer->Add(m_staticTextTif, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5); |
52 | 62 |
53 m_dirPickerTif = new wxDirPickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, pksz, wxDIRP_DIR_MUST_EXIST|wxDIRP_SMALL|wxDIRP_USE_TEXTCTRL); | 63 m_dirPickerTif = new wxDirPickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, pksz, wxDIRP_DIR_MUST_EXIST|wxDIRP_SMALL|wxDIRP_USE_TEXTCTRL); |
54 fgSizer->Add(m_dirPickerTif, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | 64 fgSizer->Add(m_dirPickerTif, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); |
65 | |
66 fgSizer->Add(0, 0, 1, wxEXPAND, 5); | |
67 | |
68 m_checkBoxJ2T = new wxCheckBox(this, wxID_ANY, wxT("JPEGから変換する"), wxDefaultPosition, wxDefaultSize, 0); | |
69 //m_checkBoxJ2T->SetValue(true); | |
70 fgSizer->Add(m_checkBoxJ2T, 0, wxALL, 5); | |
55 | 71 |
56 m_staticTextWork = new wxStaticText(this, wxID_ANY, wxT("作業フォルダ"), wxDefaultPosition, wxDefaultSize, 0); | 72 m_staticTextWork = new wxStaticText(this, wxID_ANY, wxT("作業フォルダ"), wxDefaultPosition, wxDefaultSize, 0); |
57 fgSizer->Add(m_staticTextWork, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5); | 73 fgSizer->Add(m_staticTextWork, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5); |
58 | 74 |
59 m_dirPickerWork = new wxDirPickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, pksz, wxDIRP_DIR_MUST_EXIST|wxDIRP_SMALL|wxDIRP_USE_TEXTCTRL); | 75 m_dirPickerWork = new wxDirPickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, pksz, wxDIRP_DIR_MUST_EXIST|wxDIRP_SMALL|wxDIRP_USE_TEXTCTRL); |
92 m_filePickerPdf2->SetPath(pdf2); | 108 m_filePickerPdf2->SetPath(pdf2); |
93 m_dirPickerTif->SetPath(tiff); | 109 m_dirPickerTif->SetPath(tiff); |
94 m_dirPickerWork->SetPath(work); | 110 m_dirPickerWork->SetPath(work); |
95 } | 111 } |
96 | 112 |
97 void AllocFrame::Pdf2Tif() | 113 void AllocFrame::Pdf2Jpg() |
98 { | 114 { |
99 wxString kanso = m_filePickerPdf1->GetPath(); | 115 wxString kanso = m_filePickerPdf1->GetPath(); |
100 wxString normal = m_filePickerPdf2->GetPath(); | 116 wxString normal = m_filePickerPdf2->GetPath(); |
101 | 117 |
102 if (!kanso.IsEmpty()) | 118 if (!kanso.IsEmpty()) |
128 textfile.Close(); | 144 textfile.Close(); |
129 | 145 |
130 wxExecute(batchfile, wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE, NULL, NULL); | 146 wxExecute(batchfile, wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE, NULL, NULL); |
131 } | 147 } |
132 | 148 |
133 void AllocFrame::AllocateTif() | 149 bool AllocFrame::AllocateTif() |
134 { | 150 { |
135 wxArrayString files; | 151 wxArrayString files; |
136 wxDir::GetAllFiles(m_dirPickerTif->GetPath(), &files, wxT("*.tif"), wxDIR_FILES); | 152 if (m_checkBoxJ2T->IsChecked()) // scansnap ix1400 |
153 wxDir::GetAllFiles(m_dirPickerTif->GetPath(), &files, wxT("*.jpg"), wxDIR_FILES); | |
154 else { // im c6000 | |
155 wxDir::GetAllFiles(m_dirPickerTif->GetPath(), &files, wxT("*.tif"), wxDIR_FILES); | |
156 if (files.GetCount() == 0) | |
157 wxDir::GetAllFiles(m_dirPickerTif->GetPath(), &files, wxT("*.tiff"), wxDIR_FILES); | |
158 } | |
137 files.Sort(); | 159 files.Sort(); |
138 | 160 |
161 wxProgressDialog pd(wxT("Progress Dialog"), wxT("Wait a moment..."), files.GetCount(), this, wxPD_CAN_ABORT|wxPD_APP_MODAL|wxPD_ELAPSED_TIME|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME); | |
162 bool cout = true; | |
139 for (int i = 0; i < files.GetCount(); i++ ) { | 163 for (int i = 0; i < files.GetCount(); i++ ) { |
140 wxString path = m_dirPickerWork->GetPath() + wxFILE_SEP_PATH + wxString::Format(wxT("%02d"), i / 8 + 1); | 164 wxString work_path = m_dirPickerWork->GetPath() + wxFILE_SEP_PATH + wxString::Format(wxT("%02d"), i / 8 + 1); |
141 if (i % 8 == 0) wxFileName::Mkdir(path, wxS_DIR_DEFAULT, 0); | 165 if (i % 8 == 0) wxFileName::Mkdir(work_path, wxS_DIR_DEFAULT, 0); |
142 | |
143 if (i % 8 == 3 || i % 8 == 5 || i % 8 == 7) continue; | 166 if (i % 8 == 3 || i % 8 == 5 || i % 8 == 7) continue; |
144 wxString to = files[i]; | 167 |
145 to.Replace(m_dirPickerTif->GetPath(), wxEmptyString, false); | 168 wxFileName f(files[i]); |
146 wxCopyFile(files[i], path + wxFILE_SEP_PATH + to); | 169 wxString outtif = work_path + wxFILE_SEP_PATH + f.GetName() + wxT(".tif"); |
147 } | 170 |
171 if (m_checkBoxJ2T->IsChecked()) { // scansnap ix1400 | |
172 wxImage jpg(files[i], wxBITMAP_TYPE_JPEG); | |
173 wxImage tif = jpg.Resize(wxSize(WIDTH, HEIGHT), wxPoint(0, 0), 255, 255, 255); | |
174 //wxImage tif = jpg.Scale(WIDTH, HEIGHT, wxIMAGE_QUALITY_NORMAL); | |
175 tif.SetOption(wxIMAGE_OPTION_RESOLUTIONUNIT, wxIMAGE_RESOLUTION_INCHES); | |
176 tif.SetOption(wxIMAGE_OPTION_RESOLUTION, 300); | |
177 tif.SetOption(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, 8); // ビットの深さ 1(b/w) or 8(rgb, greyscale) | |
178 tif.SetOption(wxIMAGE_OPTION_TIFF_PHOTOMETRIC, 1); // 2(rgb) or 0(greyscale) or 1(grayscale) | |
179 tif.SetOption(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, 1); // チャンネル数 1(greyscale) or 3(rgb) | |
180 tif.SetOption(wxIMAGE_OPTION_TIFF_COMPRESSION, 5); // 1(非圧縮), 2(ITU-T), 3(ファクシミリ互換のITU-T Group 3), 4(ファクシミリ互換のITU-T Group 4), 5(固定長コードLZW圧縮), 6(JPEG), 7(JPEG圧縮-2), 8(ZIP圧縮), 32773(Packbits圧縮) | |
181 | |
182 /* | |
183 tif.SetOption(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, 1); // ビットの深さ 1(b/w) or 8(rgb, greyscale) | |
184 tif.SetOption(wxIMAGE_OPTION_TIFF_PHOTOMETRIC, 0); // 2(rgb) or 0(greyscale) or 1(grayscale) | |
185 //tif.SetOption(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, 3); // チャンネル数 1(greyscale) or 3(rgb) | |
186 tif.SetOption(wxIMAGE_OPTION_TIFF_COMPRESSION, 4); // 1(非圧縮), 2(ITU-T), 3(ファクシミリ互換のITU-T Group 3), 4(ファクシミリ互換のITU-T Group 4), 5(固定長コードLZW圧縮), 6(JPEG), 7(JPEG圧縮-2), 8(ZIP圧縮), 32773(Packbits圧縮) | |
187 tif.ConvertToGreyscale(); | |
188 */ | |
189 tif.SaveFile(outtif, wxBITMAP_TYPE_TIFF); | |
190 } else { // im c6000 (.tiff -> .tif) | |
191 wxCopyFile(f.GetFullPath(), outtif); | |
192 } | |
193 | |
194 if (i == files.GetCount()) | |
195 cout = pd.Update(i, wxT("Thanks !")); | |
196 if (i == files.GetCount() / 2) | |
197 cout = pd.Update(i, wxT("Only a half left !")); | |
198 else | |
199 cout = pd.Update(i); | |
200 if (!cout) { | |
201 if (wxMessageBox(wxT("Do you really want to cancel ?"), wxT("Question"), wxYES_NO|wxICON_QUESTION) == wxYES) | |
202 break; | |
203 pd.Resume(); | |
204 } | |
205 } | |
206 return cout; | |
148 } | 207 } |
149 | 208 |
150 /* Event Handlers */ | 209 /* Event Handlers */ |
151 void AllocFrame::OnAlloc(wxCommandEvent& WXUNUSED(event)) | 210 void AllocFrame::OnAlloc(wxCommandEvent& WXUNUSED(event)) |
152 { | 211 { |
153 wxFileName::Rmdir(m_dirPickerWork->GetPath(), wxPATH_RMDIR_RECURSIVE); | 212 wxFileName::Rmdir(m_dirPickerWork->GetPath(), wxPATH_RMDIR_RECURSIVE); |
154 wxFileName::Mkdir(m_dirPickerWork->GetPath(), wxS_DIR_DEFAULT, 0); | 213 wxFileName::Mkdir(m_dirPickerWork->GetPath(), wxS_DIR_DEFAULT, 0); |
155 | 214 |
156 Pdf2Tif(); | 215 if (AllocateTif()) { |
157 AllocateTif(); | 216 wxMessageDialog dlg(this, wxT("Mover を起動しますか?"), wxT("Question ?"), wxYES_NO); |
158 wxMessageBox(wxT("コピー終了")); | 217 if (dlg.ShowModal() == wxID_YES) { |
159 | 218 wxExecute(wxT("mover.exe"), wxEXEC_ASYNC, NULL, NULL); |
160 wxMessageDialog dlg(this, wxT("Mover を起動しますか?"), wxT("Question ?"), wxYES_NO); | 219 } |
161 if (dlg.ShowModal() == wxID_YES) { | 220 } |
162 wxExecute(wxT("mover.exe"), wxEXEC_ASYNC, NULL, NULL); | 221 if (!m_checkBoxSkipPdf->IsChecked()) Pdf2Jpg(); |
163 } | 222 wxMessageBox(wxT("コピー完了")); |
164 Close(); | 223 } |
165 } | 224 |
166 |