view src/testtune.cpp @ 1:214f2908b8e4

test now.
author pyon@macmini
date Thu, 29 Sep 2011 07:47:06 +0900
parents 2344703d786b
children 1ea4f7981ff5
line wrap: on
line source

#include "wx/utils.h"
#include "wx/string.h"
#include "wx/image.h"

bool IsBlack( int r, int g, int b ) 
{
    if ( r == 0 && g == 0 && b == 0 ) {
        return true;
    }
    return false;
}

wxString GuessHhs( void ) 
{
    wxString hhs;
    wxImage img( wxT("img/img361.jpg"), 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 = -1;
    float max = 0.0;
    float bk;
    for ( int c=0; c<9; c++ ) {
        for ( int n=0; n<9; 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("%f"),bk));
            black = 0;
        }
        hhs.Append( wxString::Format( wxT("%1d"), max_n ) );
    }

    return hhs;
}

int main( int argc, char **argv ) 
{
    wxInitAllImageHandlers();
    wxString hhs = GuessHhs();

    wxPuts(hhs);
}