Array<To> cast(const Array<Ti> &in) { CastWrapper<To, Ti> cast_op; return cast_op(in); }
void getRectSubPix_Cn_(const _Tp* src, size_t src_step, Size src_size, _DTp* dst, size_t dst_step, Size win_size, Point2f center, int cn ) { ScaleOp scale_op; CastOp cast_op; Point ip; _WTp a11, a12, a21, a22, b1, b2; float a, b; int i, j, c; center.x -= (win_size.width-1)*0.5f; center.y -= (win_size.height-1)*0.5f; ip.x = cvFloor( center.x ); ip.y = cvFloor( center.y ); a = center.x - ip.x; b = center.y - ip.y; a11 = scale_op((1.f-a)*(1.f-b)); a12 = scale_op(a*(1.f-b)); a21 = scale_op((1.f-a)*b); a22 = scale_op(a*b); b1 = scale_op(1.f - b); b2 = scale_op(b); src_step /= sizeof(src[0]); dst_step /= sizeof(dst[0]); if( 0 <= ip.x && ip.x < src_size.width - win_size.width && 0 <= ip.y && ip.y < src_size.height - win_size.height) { // extracted rectangle is totally inside the image src += ip.y * src_step + ip.x*cn; win_size.width *= cn; for( i = 0; i < win_size.height; i++, src += src_step, dst += dst_step ) { for( j = 0; j <= win_size.width - 2; j += 2 ) { _WTp s0 = src[j]*a11 + src[j+cn]*a12 + src[j+src_step]*a21 + src[j+src_step+cn]*a22; _WTp s1 = src[j+1]*a11 + src[j+cn+1]*a12 + src[j+src_step+1]*a21 + src[j+src_step+cn+1]*a22; dst[j] = cast_op(s0); dst[j+1] = cast_op(s1); } for( ; j < win_size.width; j++ ) { _WTp s0 = src[j]*a11 + src[j+cn]*a12 + src[j+src_step]*a21 + src[j+src_step+cn]*a22; dst[j] = cast_op(s0); } } } else { Rect r; src = (const _Tp*)adjustRect( (const uchar*)src, src_step*sizeof(*src), sizeof(*src)*cn, src_size, win_size, ip, &r); for( i = 0; i < win_size.height; i++, dst += dst_step ) { const _Tp *src2 = src + src_step; _WTp s0; if( i < r.y || i >= r.height ) src2 -= src_step; for( c = 0; c < cn; c++ ) { s0 = src[r.x*cn + c]*b1 + src2[r.x*cn + c]*b2; for( j = 0; j < r.x; j++ ) dst[j*cn + c] = cast_op(s0); s0 = src[r.width*cn + c]*b1 + src2[r.width*cn + c]*b2; for( j = r.width; j < win_size.width; j++ ) dst[j*cn + c] = cast_op(s0); } for( j = r.x*cn; j < r.width*cn; j++ ) { s0 = src[j]*a11 + src[j+cn]*a12 + src2[j]*a21 + src2[j+cn]*a22; dst[j] = cast_op(s0); } if( i < r.height ) src = src2; } } }