Mercurial > mercurial > hgweb_mover2.cgi
comparison include/utils.h @ 7:a43adb9537b2
start impletent cache.
| author | pyon@macmini |
|---|---|
| date | Wed, 19 Oct 2011 07:49:32 +0900 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 6:9c85d71cad7c | 7:a43adb9537b2 |
|---|---|
| 1 // Filename : utils.h | |
| 2 // Last Change: 19-Oct-2011. | |
| 3 // | |
| 4 #ifndef __utils__ | |
| 5 #define __utils__ | |
| 6 | |
| 7 /********** Marksheet **********/ | |
| 8 bool IsBlack( int r, int g, int b ) | |
| 9 { | |
| 10 if ( r == 0 && g == 0 && b == 0 ) { | |
| 11 return true; | |
| 12 } | |
| 13 return false; | |
| 14 }; | |
| 15 | |
| 16 wxString GuessHhs( wxString& file ) | |
| 17 { | |
| 18 wxString hhs; | |
| 19 wxImage img( file, wxBITMAP_TYPE_JPEG ); | |
| 20 int sx = 1800; // start x | |
| 21 int sy = 315;; // start y | |
| 22 int bw = 60; // block width | |
| 23 int bh = 50; // block height | |
| 24 int area = bw * bh; | |
| 25 int black = 0; | |
| 26 int x, y; | |
| 27 unsigned char r, g, b; | |
| 28 | |
| 29 int max_n; | |
| 30 float max; | |
| 31 float bk; | |
| 32 for ( int c=0; c<10; c++ ) { | |
| 33 max = 0.0; | |
| 34 max_n = -1; | |
| 35 for ( int n=0; n<10; n++ ) { | |
| 36 | |
| 37 for ( x=sx+bw*c; x<sx+bw*(c+1); x++ ) { | |
| 38 for ( y=sy+bh*n; y<sy+bh*(n+1); y++ ) { | |
| 39 r = img.GetRed( x, y ); | |
| 40 g = img.GetGreen( x, y ); | |
| 41 b = img.GetBlue( x, y ); | |
| 42 if( IsBlack( (int)r, (int)g, (int)b ) ) black++; | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 bk = (float)black / area; | |
| 47 if ( max < bk ) { | |
| 48 max = bk; | |
| 49 max_n = n; | |
| 50 } | |
| 51 //wxPuts(wxString::Format(wxT("%d %f"),n,bk)); | |
| 52 black = 0; | |
| 53 } | |
| 54 hhs.Append( wxString::Format( wxT("%d"), max_n ) ); | |
| 55 } | |
| 56 | |
| 57 return hhs; | |
| 58 }; | |
| 59 | |
| 60 bool IsMarksheet( wxString& file, float* brate, long* len ) | |
| 61 { | |
| 62 wxImage img( file, wxBITMAP_TYPE_JPEG ); | |
| 63 int black = 0; | |
| 64 int x = 2465; | |
| 65 int h = 3500; | |
| 66 unsigned char r, g, b; | |
| 67 | |
| 68 for ( int y=0; y<h; y++ ) { | |
| 69 r = img.GetRed( x, y ); | |
| 70 g = img.GetGreen( x, y ); | |
| 71 b = img.GetBlue( x, y ); | |
| 72 if( IsBlack( (int)r, (int)g, (int)b ) ) black++; | |
| 73 } | |
| 74 float z = (float)black / h; | |
| 75 float zmin = 0.095713; | |
| 76 float zmax = 0.108600; | |
| 77 | |
| 78 wxFile f( file ); | |
| 79 long l = f.Length(); | |
| 80 float lmin = 2072393; | |
| 81 float lmax = 2346082; | |
| 82 | |
| 83 *brate = z; | |
| 84 *len = l; | |
| 85 //wxPuts(wxString::Format(wxT("z = %f, len = %d"),z,len)); | |
| 86 if ( zmin < z && z < zmax | |
| 87 && lmin < l && l < lmax ) { | |
| 88 return true; | |
| 89 } | |
| 90 return false; | |
| 91 }; | |
| 92 | |
| 93 /********** Cache **********/ | |
| 94 class Cache | |
| 95 { | |
| 96 public: | |
| 97 wxString filename; // key | |
| 98 wxString z, b; | |
| 99 bool marksheet; | |
| 100 }; | |
| 101 | |
| 102 WX_DECLARE_HASH_MAP( wxString, Cache*, wxStringHash, wxStringEqual, CacheHash ) | |
| 103 | |
| 104 bool IsCached( wxString file ) | |
| 105 { | |
| 106 Cache i = new Cache; | |
| 107 }; | |
| 108 #endif // __utils__ | |
| 109 |
