Mercurial > mercurial > hgweb_mover2.cgi
changeset 7:a43adb9537b2
start impletent cache.
author | pyon@macmini |
---|---|
date | Wed, 19 Oct 2011 07:49:32 +0900 |
parents | 9c85d71cad7c |
children | 550c143ab194 |
files | include/marksheet.h include/utils.h |
diffstat | 2 files changed, 110 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/include/marksheet.h Tue Oct 18 22:43:46 2011 +0900 +++ b/include/marksheet.h Wed Oct 19 07:49:32 2011 +0900 @@ -1,15 +1,9 @@ // Filename : marksheet.h -// Last Change: 15-Oct-2011. +// Last Change: 19-Oct-2011. // #ifndef __MARKSHEET__ #define __MARKSHEET__ - -#include "wx/utils.h" -#include "wx/file.h" -#include "wx/string.h" -#include "wx/image.h" - bool IsBlack( int r, int g, int b ) { if ( r == 0 && g == 0 && b == 0 ) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/utils.h Wed Oct 19 07:49:32 2011 +0900 @@ -0,0 +1,109 @@ +// Filename : utils.h +// Last Change: 19-Oct-2011. +// +#ifndef __utils__ +#define __utils__ + +/********** Marksheet **********/ +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 ) +{ + 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; +}; + +/********** Cache **********/ +class Cache +{ +public: + wxString filename; // key + wxString z, b; + bool marksheet; +}; + +WX_DECLARE_HASH_MAP( wxString, Cache*, wxStringHash, wxStringEqual, CacheHash ) + +bool IsCached( wxString file ) +{ + Cache i = new Cache; +}; +#endif // __utils__ +