Mercurial > mercurial > hgweb_searcher03.cgi
diff src/marksheet.cpp @ 2:c066fde99517
Added Batch Print Mode.
author | pyon@macmini |
---|---|
date | Fri, 23 Aug 2013 18:32:09 +0900 |
parents | |
children | fdba695b99f1 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/marksheet.cpp Fri Aug 23 18:32:09 2013 +0900 @@ -0,0 +1,181 @@ +// Filename : marksheet.cpp +// Last Change: 23-Aug-2013. +// + +#include "common.h" +#include "marksheet.h" + +bool IsBlack( int r, int g, int b ) +{ + if ( r == 0 && g == 0 && b == 0 ) { + return true; + } + return false; +} + +wxString GuessHhs( wxString& file ) +{ + wxString hhs; + wxImage img( file, wxBITMAP_TYPE_JPEG ); + int sx = 1800; // start x + int sy = 315;; // start y + int bw = 60; // block width + int bh = 50; // block height + int area = bw * bh; + int black = 0; + int x, y; + unsigned char r, g, b; + + int max_n; + float max; + float bk; + for ( int c=0; c<10; c++ ) { + max = 0.0; + max_n = -1; + for ( int n=0; n<10; n++ ) { + + for ( x=sx+bw*c; x<sx+bw*(c+1); x++ ) { + for ( y=sy+bh*n; y<sy+bh*(n+1); 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++; + } + } + + bk = (float)black / area; + if ( max < bk ) { + max = bk; + max_n = n; + } + //wxPuts(wxString::Format(wxT("%d %f"),n,bk)); + black = 0; + } + hhs.Append( wxString::Format( wxT("%d"), max_n ) ); + } + + return hhs; +} + +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; + 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; + + wxFile f( file ); + long l = f.Length(); + + *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; +} + +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; +} + +wxString GetHhsName( wxString& hhsno ) +{ + wxString name; + + wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("hhs.db"); + wxSQLite3Database hhsdb; + hhsdb.Open( gszFile ); + + wxSQLite3Statement stmt = hhsdb.PrepareStatement("SELECT name FROM hhs_master WHERE hhsno = ?"); + stmt.Bind( 1, hhsno ); + wxSQLite3ResultSet q = stmt.ExecuteQuery(); + if ( !q.IsNull(0) ) { + while ( q.NextRow() ) { + name = q.GetString(0); + } + } + stmt.Finalize(); + hhsdb.Close(); + + return name; +} + +int IsHhsno( wxString& hhsno, wxString& name ) +{ + wxRegEx reHhs(wxT("^0[1238][0-9]{8}$")); // 被保番チェック + + if ( reHhs.Matches( hhsno) ) { + name = GetHhsName( hhsno ); + if ( name.IsEmpty() ) { // DBにない + return 1; + } + return 2; + } + else { + return 0; + } +} + +int GetMarksheetVersion( wxString file ) +{ + 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; + + if ( z > 0.120 ) { + return 2; // 0.130 - 0.140 + } + else { + return 1; // 0.099 - 0.110 + } +} +