changeset 24:5c99c6fa50df v2.2dev v2.2

fix changing selected image color
author pyon@macmini
date Wed, 02 Nov 2011 20:47:18 +0900
parents a2dd16b70c08
children b3b3b8e97b54
files TODO include/common.h include/marksheet.h makefile src/myframe.cpp
diffstat 5 files changed, 78 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/TODO	Tue Nov 01 22:26:41 2011 +0900
+++ b/TODO	Wed Nov 02 20:47:18 2011 +0900
@@ -2,14 +2,17 @@
  TODO
 ======================================================================
 * d&d image
+* auto cache rebuild off
+
 * ccn folder make
-* error check hhsno
+
 * hhs explore & file count
 * hhs name from db
-* auto cache rebuild off
+
+* error check hhsno
 * color red if guess hhsno failed
+
 * help
-* building cache time
 * F5 detect
 * F7 move
 
--- a/include/common.h	Tue Nov 01 22:26:41 2011 +0900
+++ b/include/common.h	Wed Nov 02 20:47:18 2011 +0900
@@ -1,5 +1,5 @@
 // Filename   : common.h
-// Last Change: 26-Oct-2011.
+// Last Change: 02-Nov-2011.
 //
 #ifndef __COMMON__
 #define __COMMON__
@@ -33,6 +33,8 @@
     #include <wx/progdlg.h>
     #include <wx/frame.h>
     #include <wx/textfile.h>
+    #include <wx/stopwatch.h>
+    #include "wx/regex.h"
 #endif
 
 enum {
--- a/include/marksheet.h	Tue Nov 01 22:26:41 2011 +0900
+++ b/include/marksheet.h	Wed Nov 02 20:47:18 2011 +0900
@@ -1,5 +1,5 @@
 // Filename   : marksheet.h
-// Last Change: 21-Oct-2011.
+// Last Change: 02-Nov-2011.
 //
 #ifndef __marksheet__
 #define __marksheet__
@@ -56,7 +56,7 @@
     return hhs;
 };
 
-bool IsMarksheet( wxString& file, float* brate, long* len )
+bool IsMarksheet( wxString& file, float* brate, long* len, double zmin, double zmax, long lmin, long lmax )
 {
     wxImage img( file, wxBITMAP_TYPE_JPEG );
     int black = 0;
@@ -71,13 +71,9 @@
         if( IsBlack( (int)r, (int)g, (int)b ) ) black++;
     }
     float z = (float)black / h;
-    float zmin = 0.095713;
-    float zmax = 0.108600;
 
     wxFile f( file );
     long l = f.Length();
-    float lmin = 2072393;
-    float lmax = 2346082;
 
     *brate = z;
     *len = l;
@@ -89,5 +85,51 @@
     return false;
 };
 
+bool _IsMarksheet( wxString& file, float* brate, long* len )
+{
+    wxImage img( file, wxBITMAP_TYPE_JPEG );
+    int black = 0;
+    int x = 2465;
+    int h = 3500;
+    unsigned char r, g, b;
+
+    for ( int y=0; y<h; y++ ) {
+        r = img.GetRed(   x, y );
+        g = img.GetGreen( x, y );
+        b = img.GetBlue(  x, y );
+        if( IsBlack( (int)r, (int)g, (int)b ) ) black++;
+    }
+    float z = (float)black / h;
+    float zmin = 0.095713; float zmax = 0.108600;
+
+    wxFile f( file );
+    long l = f.Length();
+    float lmin = 2072393; float lmax = 2346082;
+
+    *brate = z;
+    *len = l;
+    //wxPuts(wxString::Format(wxT("z = %f, len = %d"),z,len));
+    if ( zmin < z && z < zmax
+      && lmin < l && l < lmax ) {
+        return true;
+    }
+    return false;
+};
+
+int IsHhsno( wxString& hhsno, wxString& name )
+{
+	wxRegEx reHhs(wxT("^0[1238][0-9]{8}$"));	// $BHoJ]HV%A%'%C%/(B
+
+    if ( reHhs.Matches( hhsno) ) {
+        if ( 0 ) {  // DB$B$K$"$k(B
+            return 2;
+        }
+        return 1;
+    }
+    else {
+        return 0;
+    }
+};
+
 #endif // __marksheet__
 
--- a/makefile	Tue Nov 01 22:26:41 2011 +0900
+++ b/makefile	Wed Nov 02 20:47:18 2011 +0900
@@ -1,6 +1,6 @@
 #
 # Makefile for wxWidgets Application
-#  Last Change: 27-Oct-2011.
+#  Last Change: 02-Nov-2011.
 #  by Takayuki Mutoh
 #
 
@@ -108,7 +108,7 @@
 $(OBJDIR)/param.o: param.cpp param.h common.h main.h
 	$(CXX) -c $< -o $@ $(CPPFLAGS)
 
-#$(OBJDIR)/dirview.o: dirview.cpp dirview.h common.h
+#$(OBJDIR)/wxsqilte3.o: wxsqlite3.cpp
 #	$(CXX) -c $< -o $@ $(CPPFLAGS)
 
 testtune: testtune.cpp
--- a/src/myframe.cpp	Tue Nov 01 22:26:41 2011 +0900
+++ b/src/myframe.cpp	Wed Nov 02 20:47:18 2011 +0900
@@ -1,5 +1,5 @@
 // Filename   : myframe.cpp
-// Last Change: 01-Nov-2011.
+// Last Change: 02-Nov-2011.
 //
 
 #include "main.h"
@@ -177,7 +177,7 @@
 	this->Layout();
 
     // ステータスバー
-    int widths[] = { 150, 250, -1, 120 };
+    int widths[] = { 250, 250, -1, 120 };
     m_statusBar = this->CreateStatusBar( WXSIZEOF(widths), wxST_SIZEGRIP );
     m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths );
     m_statusBar->SetStatusText( wxEmptyString, 0 );
@@ -340,6 +340,7 @@
     m_listCtrlView->DeleteAllItems();
     m_imageList->RemoveAll();
     wxListItem item;
+    m_textCtrlGuess->SetBackgroundColour(*wxWHITE);
 
     wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 7, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
     pd.SetSize( wxSize(320,140) );
@@ -383,6 +384,10 @@
 
             wxString hhsno = GuessHhs( ci->fullpath );
             m_textCtrlGuess->SetValue( hhsno );
+            wxString name;
+            int judge = IsHhsno( hhsno, name );
+	        if (      judge == 0 )  m_textCtrlGuess->SetBackgroundColour(*wxRED);       // not hhsno-style
+            //else if ( judge == 1 )  m_textCtrlGuess->SetBackgroundColour(wxT("YELLOW"));    // not in DB
             SetStatusText( wxString::Format(wxT("1st image : z = %f, l = %d"),ci->z,ci->l), 1 );
             m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
         }
@@ -460,9 +465,17 @@
 /* キャッシュ作成&更新 */
 void MyFrame::UpdateCache()
 {
+    double zmin, zmax; long lmin, lmax;
+    wxGetApp().zmin.ToDouble( &zmin );
+    wxGetApp().zmax.ToDouble( &zmax );
+    wxGetApp().lmin.ToLong( &lmin );
+    wxGetApp().lmax.ToLong( &lmax );
+
     m_buttonDetect->Enable(false);
     wxGetApp().WriteLog( wxT("start updating cache") );
     SetStatusText( wxT("rebuiling cache..."), 0 );
+    wxStopWatch sw;
+    sw.Start(0);
 
     /* キャッシュ存在フラグOFF */
     for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
@@ -493,12 +506,13 @@
             continue;
         }
         /* 新しいファイルはキャッシュ */
-        float z; long l; bool m = IsMarksheet( fullpath, &z, &l );
+        //float z; long l; bool m = IsMarksheet( fullpath, &z, &l );
+        float z; long l; bool m = IsMarksheet( fullpath, &z, &l, zmin, zmax, lmin, lmax );
         wxImage image( fullpath, wxBITMAP_TYPE_JPEG );
         wxImage thumbnail = image.Scale( 160, 226, wxIMAGE_QUALITY_HIGH );
         wxBitmap bmp( thumbnail );
         unsigned char *data = thumbnail.GetData();
-        for ( int y=0; y<226; y++ ) for ( int x=0; x<160; x++ ) data[(y*226+x)*3+2] = 255;  // 文字色:黒(0,0,0)->青(0,0.255)
+        for ( int y=0; y<226; y++ ) for ( int x=0; x<160; x++ ) data[(y*160+x)*3+2] = 255;  // 文字色:黒(0,0,0)->青(0,0.255)
         wxBitmap bmp_mask( thumbnail );
 
         ci->filename     = file;
@@ -512,6 +526,7 @@
         ci->modtime      = wxEmptyString; // TODO.
 
         CH[ci->filename] = ci;  // add hash
+        SetStatusText( wxString::Format( wxT("rebuiling cache...(%.1fsec passed)"), (float)sw.Time()/1000 ), 0 );
         wxGetApp().WriteLog( file + wxT(" appended.") + wxString::Format(wxT(" ( m=%d z=%f l=%d )"), m ? 1 : 0, z, l ) );
     }