Mercurial > mercurial > hgweb_golang.cgi
diff 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 |
line wrap: on
line diff
--- a/src/kaigo/horori/alloc/alloc.cpp Fri Dec 25 20:48:01 2020 +0900 +++ b/src/kaigo/horori/alloc/alloc.cpp Fri May 20 06:30:34 2022 +0900 @@ -1,15 +1,20 @@ // Filename : alloc.cpp -// Last Change: 2020-05-21 木 15:17:26. +// Last Change: 2021-05-10 月 10:53:23. // #include <wx/dir.h> #include <wx/filefn.h> #include <wx/textfile.h> #include <wx/utils.h> #include <wx/msgdlg.h> +#include <wx/progdlg.h> +#include <wx/filename.h> #include <wx/fileconf.h> #include "alloc.h" +#define WIDTH 2480 +#define HEIGHT 3508 + AllocFrame::AllocFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(parent, id, title, pos, size, style) @@ -47,12 +52,23 @@ 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); fgSizer->Add(m_filePickerPdf2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); + fgSizer->Add(0, 0, 1, wxEXPAND, 5); + + m_checkBoxSkipPdf = new wxCheckBox(this, wxID_ANY, wxT("PDFからの変換をスキップする"), wxDefaultPosition, wxDefaultSize, 0); + fgSizer->Add(m_checkBoxSkipPdf, 0, wxALL, 5); + m_staticTextTif = new wxStaticText(this, wxID_ANY, wxT("TIFフォルダ"), wxDefaultPosition, wxDefaultSize, 0); fgSizer->Add(m_staticTextTif, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5); m_dirPickerTif = new wxDirPickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, pksz, wxDIRP_DIR_MUST_EXIST|wxDIRP_SMALL|wxDIRP_USE_TEXTCTRL); fgSizer->Add(m_dirPickerTif, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); + fgSizer->Add(0, 0, 1, wxEXPAND, 5); + + m_checkBoxJ2T = new wxCheckBox(this, wxID_ANY, wxT("JPEGから変換する"), wxDefaultPosition, wxDefaultSize, 0); + //m_checkBoxJ2T->SetValue(true); + fgSizer->Add(m_checkBoxJ2T, 0, wxALL, 5); + m_staticTextWork = new wxStaticText(this, wxID_ANY, wxT("作業フォルダ"), wxDefaultPosition, wxDefaultSize, 0); fgSizer->Add(m_staticTextWork, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5); @@ -94,7 +110,7 @@ m_dirPickerWork->SetPath(work); } -void AllocFrame::Pdf2Tif() +void AllocFrame::Pdf2Jpg() { wxString kanso = m_filePickerPdf1->GetPath(); wxString normal = m_filePickerPdf2->GetPath(); @@ -130,21 +146,64 @@ wxExecute(batchfile, wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE, NULL, NULL); } -void AllocFrame::AllocateTif() +bool AllocFrame::AllocateTif() { wxArrayString files; - wxDir::GetAllFiles(m_dirPickerTif->GetPath(), &files, wxT("*.tif"), wxDIR_FILES); + if (m_checkBoxJ2T->IsChecked()) // scansnap ix1400 + wxDir::GetAllFiles(m_dirPickerTif->GetPath(), &files, wxT("*.jpg"), wxDIR_FILES); + else { // im c6000 + wxDir::GetAllFiles(m_dirPickerTif->GetPath(), &files, wxT("*.tif"), wxDIR_FILES); + if (files.GetCount() == 0) + wxDir::GetAllFiles(m_dirPickerTif->GetPath(), &files, wxT("*.tiff"), wxDIR_FILES); + } files.Sort(); + 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); + bool cout = true; for (int i = 0; i < files.GetCount(); i++ ) { - wxString path = m_dirPickerWork->GetPath() + wxFILE_SEP_PATH + wxString::Format(wxT("%02d"), i / 8 + 1); - if (i % 8 == 0) wxFileName::Mkdir(path, wxS_DIR_DEFAULT, 0); - + wxString work_path = m_dirPickerWork->GetPath() + wxFILE_SEP_PATH + wxString::Format(wxT("%02d"), i / 8 + 1); + if (i % 8 == 0) wxFileName::Mkdir(work_path, wxS_DIR_DEFAULT, 0); if (i % 8 == 3 || i % 8 == 5 || i % 8 == 7) continue; - wxString to = files[i]; - to.Replace(m_dirPickerTif->GetPath(), wxEmptyString, false); - wxCopyFile(files[i], path + wxFILE_SEP_PATH + to); + + wxFileName f(files[i]); + wxString outtif = work_path + wxFILE_SEP_PATH + f.GetName() + wxT(".tif"); + + if (m_checkBoxJ2T->IsChecked()) { // scansnap ix1400 + wxImage jpg(files[i], wxBITMAP_TYPE_JPEG); + wxImage tif = jpg.Resize(wxSize(WIDTH, HEIGHT), wxPoint(0, 0), 255, 255, 255); + //wxImage tif = jpg.Scale(WIDTH, HEIGHT, wxIMAGE_QUALITY_NORMAL); + tif.SetOption(wxIMAGE_OPTION_RESOLUTIONUNIT, wxIMAGE_RESOLUTION_INCHES); + tif.SetOption(wxIMAGE_OPTION_RESOLUTION, 300); + tif.SetOption(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, 8); // ビットの深さ 1(b/w) or 8(rgb, greyscale) + tif.SetOption(wxIMAGE_OPTION_TIFF_PHOTOMETRIC, 1); // 2(rgb) or 0(greyscale) or 1(grayscale) + tif.SetOption(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, 1); // チャンネル数 1(greyscale) or 3(rgb) + 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圧縮) + + /* + tif.SetOption(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, 1); // ビットの深さ 1(b/w) or 8(rgb, greyscale) + tif.SetOption(wxIMAGE_OPTION_TIFF_PHOTOMETRIC, 0); // 2(rgb) or 0(greyscale) or 1(grayscale) + //tif.SetOption(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, 3); // チャンネル数 1(greyscale) or 3(rgb) + 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圧縮) + tif.ConvertToGreyscale(); + */ + tif.SaveFile(outtif, wxBITMAP_TYPE_TIFF); + } else { // im c6000 (.tiff -> .tif) + wxCopyFile(f.GetFullPath(), outtif); + } + + if (i == files.GetCount()) + cout = pd.Update(i, wxT("Thanks !")); + if (i == files.GetCount() / 2) + cout = pd.Update(i, wxT("Only a half left !")); + else + cout = pd.Update(i); + if (!cout) { + if (wxMessageBox(wxT("Do you really want to cancel ?"), wxT("Question"), wxYES_NO|wxICON_QUESTION) == wxYES) + break; + pd.Resume(); + } } + return cout; } /* Event Handlers */ @@ -153,14 +212,13 @@ wxFileName::Rmdir(m_dirPickerWork->GetPath(), wxPATH_RMDIR_RECURSIVE); wxFileName::Mkdir(m_dirPickerWork->GetPath(), wxS_DIR_DEFAULT, 0); - Pdf2Tif(); - AllocateTif(); - wxMessageBox(wxT("コピー終了")); - - wxMessageDialog dlg(this, wxT("Mover を起動しますか?"), wxT("Question ?"), wxYES_NO); - if (dlg.ShowModal() == wxID_YES) { - wxExecute(wxT("mover.exe"), wxEXEC_ASYNC, NULL, NULL); + if (AllocateTif()) { + wxMessageDialog dlg(this, wxT("Mover を起動しますか?"), wxT("Question ?"), wxYES_NO); + if (dlg.ShowModal() == wxID_YES) { + wxExecute(wxT("mover.exe"), wxEXEC_ASYNC, NULL, NULL); + } } - Close(); + if (!m_checkBoxSkipPdf->IsChecked()) Pdf2Jpg(); + wxMessageBox(wxT("コピー完了")); }