-float CriKey::diff_uint8(uint8_t *dp)
-{
- float scale = 1./255., v = 0;
- for( int i=0; i<comp; ++i,++dp )
- v += fabs(*dp * scale - target[i]);
- return v / comp;
-}
-float CriKey::diff_float(uint8_t *dp)
-{
- float *fp = (float *)dp, v = 0;
- for( int i=0; i<comp; ++i,++fp )
- v += fabs(*fp - target[i]);
- return v / comp;
-}
-
-void CriKey::min_key(int &ix, int &iy)
-{
- float mv = 1;
- uint8_t **src_rows = src->get_rows();
- for( int y=0; y<h; ++y ) {
- uint8_t *sp = src_rows[y];
- for( int x=0; x<w; ++x,sp+=bpp ) {
- float v = (this->*diff_pixel)(sp);
- if( v >= mv ) continue;
- mv = v; ix = x; iy = y;
- }
- }
-}
-bool CriKey::find_key(int &ix, int &iy, float thr)
-{
- uint8_t **src_rows = src->get_rows();
- uint8_t **msk_rows = msk->get_rows();
- int x = ix, y = iy;
- for( ; y<h; ++y ) {
- uint8_t *sp = src_rows[y] + x*bpp;
- uint8_t *mp = msk_rows[y] + x;
- for( ; x<w; ++x,++mp,sp+=bpp ) {
- if( !*mp ) continue;
- float v = (this->*diff_pixel)(sp);
- if( v < thr ) {
- ix = x; iy = y;
- return true;
- }
- }
- x = 0;
- }
- return false;
-}
-