📄 cvutils.cpp
字号:
idst[j + srcroi.width] = idst[k];
}
}
isrc -= srcroi.height*srcstep;
idst -= (top - srcroi.height)*dststep;
}
else
{
dst += top*dststep;
for( i = 0; i < srcroi.height; i++, src += srcstep, dst += dststep )
{
if( dst + left != src )
for( j = 0; j < srcroi.width; j++ )
dst[j + left] = src[j];
for( j = 0; i < left; j++ )
{
k = tab[j];
dst[j] = dst[k];
}
for( ; j < tab_size; j++ )
{
k = tab[j];
dst[j + srcroi.width] = dst[k];
}
}
src -= srcroi.height*srcstep;
dst -= (top - srcroi.height)*dststep;
}
for( t = 0; t < 2; t++ )
{
int i1, i2, di;
if( t == 0 )
i1 = top-1, i2 = 0, di = -1, j = 1, dj = 1;
else
i1 = top+srcroi.height, i2=dstroi.height, di = 1, j = srcroi.height-2, dj = -1;
for( i = i1; i != i2; i += di )
{
if( int_mode )
{
const int* s = idst + i*dststep;
int* d = idst + (j+top)*dststep;
for( k = 0; k < dstroi.width; k++ )
d[k] = s[k];
}
else
{
const uchar* s = dst + i*dststep;
uchar* d = dst + (j+top)*dststep;
for( k = 0; k < dstroi.width; k++ )
d[k] = s[k];
}
if( (unsigned)(j += dj) >= (unsigned)srcroi.height )
j -= 2*dj, dj = -dj;
}
}
return CV_OK;
}
static CvStatus CV_STDCALL
icvCopyConstBorder_8u( const uchar* src, int srcstep, CvSize srcroi,
uchar* dst, int dststep, CvSize dstroi,
int top, int left, int cn, const uchar* value )
{
const int isz = (int)sizeof(int);
int i, j, k;
if( (cn | srcstep | dststep | (size_t)src | (size_t)dst | (size_t)value) % isz == 0 )
{
const int* isrc = (const int*)src;
int* idst = (int*)dst;
const int* ivalue = (const int*)value;
int v0 = ivalue[0];
cn /= isz;
srcstep /= isz;
dststep /= isz;
srcroi.width *= cn;
dstroi.width *= cn;
left *= cn;
for( j = 1; j < cn; j++ )
if( ivalue[j] != ivalue[0] )
break;
if( j == cn )
cn = 1;
if( dstroi.width <= 0 )
return CV_OK;
for( i = 0; i < dstroi.height; i++, idst += dststep )
{
if( i < top || i >= top + srcroi.height )
{
if( cn == 1 )
{
for( j = 0; j < dstroi.width; j++ )
idst[j] = v0;
}
else
{
for( j = 0; j < cn; j++ )
idst[j] = ivalue[j];
for( ; j < dstroi.width; j++ )
idst[j] = idst[j - cn];
}
continue;
}
if( cn == 1 )
{
for( j = 0; j < left; j++ )
idst[j] = v0;
for( j = srcroi.width + left; j < dstroi.width; j++ )
idst[j] = v0;
}
else
{
for( k = 0; k < cn; k++ )
{
for( j = 0; j < left; j += cn )
idst[j+k] = ivalue[k];
for( j = srcroi.width + left; j < dstroi.width; j += cn )
idst[j+k] = ivalue[k];
}
}
if( idst + left != isrc )
for( j = 0; j < srcroi.width; j++ )
idst[j + left] = isrc[j];
isrc += srcstep;
}
}
else
{
uchar v0 = value[0];
srcroi.width *= cn;
dstroi.width *= cn;
left *= cn;
for( j = 1; j < cn; j++ )
if( value[j] != value[0] )
break;
if( j == cn )
cn = 1;
if( dstroi.width <= 0 )
return CV_OK;
for( i = 0; i < dstroi.height; i++, dst += dststep )
{
if( i < top || i >= top + srcroi.height )
{
if( cn == 1 )
{
for( j = 0; j < dstroi.width; j++ )
dst[j] = v0;
}
else
{
for( j = 0; j < cn; j++ )
dst[j] = value[j];
for( ; j < dstroi.width; j++ )
dst[j] = dst[j - cn];
}
continue;
}
if( cn == 1 )
{
for( j = 0; j < left; j++ )
dst[j] = v0;
for( j = srcroi.width + left; j < dstroi.width; j++ )
dst[j] = v0;
}
else
{
for( k = 0; k < cn; k++ )
{
for( j = 0; j < left; j += cn )
dst[j+k] = value[k];
for( j = srcroi.width + left; j < dstroi.width; j += cn )
dst[j+k] = value[k];
}
}
if( dst + left != src )
for( j = 0; j < srcroi.width; j++ )
dst[j + left] = src[j];
src += srcstep;
}
}
return CV_OK;
}
CV_IMPL void
cvCopyMakeBorder( const CvArr* srcarr, CvArr* dstarr, CvPoint offset,
int bordertype, CvScalar value )
{
CV_FUNCNAME( "cvCopyMakeBorder" );
__BEGIN__;
CvMat srcstub, *src = (CvMat*)srcarr;
CvMat dststub, *dst = (CvMat*)dstarr;
CvSize srcsize, dstsize;
int srcstep, dststep;
int pix_size, type;
if( !CV_IS_MAT(src) )
CV_CALL( src = cvGetMat( src, &srcstub ));
if( !CV_IS_MAT(dst) )
CV_CALL( dst = cvGetMat( dst, &dststub ));
if( offset.x < 0 || offset.y < 0 )
CV_ERROR( CV_StsOutOfRange, "Offset (left/top border width) is negative" );
if( src->rows + offset.y > dst->rows || src->cols + offset.x > dst->cols )
CV_ERROR( CV_StsBadSize, "Source array is too big or destination array is too small" );
if( !CV_ARE_TYPES_EQ( src, dst ))
CV_ERROR( CV_StsUnmatchedFormats, "" );
type = CV_MAT_TYPE(src->type);
pix_size = CV_ELEM_SIZE(type);
srcsize = cvGetMatSize(src);
dstsize = cvGetMatSize(dst);
srcstep = src->step;
dststep = dst->step;
if( srcstep == 0 )
srcstep = CV_STUB_STEP;
if( dststep == 0 )
dststep = CV_STUB_STEP;
if( bordertype == IPL_BORDER_REPLICATE )
{
icvCopyReplicateBorder_8u( src->data.ptr, srcstep, srcsize,
dst->data.ptr, dststep, dstsize,
offset.y, offset.x, pix_size );
}
else if( bordertype == IPL_BORDER_REFLECT_101 )
{
icvCopyReflect101Border_8u( src->data.ptr, srcstep, srcsize,
dst->data.ptr, dststep, dstsize,
offset.y, offset.x, pix_size );
}
else if( bordertype == IPL_BORDER_CONSTANT )
{
double buf[4];
cvScalarToRawData( &value, buf, src->type, 0 );
icvCopyConstBorder_8u( src->data.ptr, srcstep, srcsize,
dst->data.ptr, dststep, dstsize,
offset.y, offset.x, pix_size, (uchar*)buf );
}
else
CV_ERROR( CV_StsBadFlag, "Unknown/unsupported border type" );
__END__;
}/* End of file. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -