mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
core: rework getContinuousSize() for vector-col/row support
This commit is contained in:
+10
-15
@@ -287,23 +287,19 @@ void Mat::copyTo( OutputArray _dst ) const
|
||||
|
||||
if( rows > 0 && cols > 0 )
|
||||
{
|
||||
// For some cases (with vector) dst.size != src.size, so force to column-based form
|
||||
// It prevents memory corruption in case of column-based src
|
||||
if (_dst.isVector() && dst.size() != size()) // https://github.com/opencv/opencv/pull/4159
|
||||
dst = dst.reshape(0, (int)dst.total());
|
||||
Mat src = *this;
|
||||
Size sz = getContinuousSize2D(src, dst, (int)elemSize());
|
||||
CV_CheckGE(sz.width, 0, "");
|
||||
|
||||
const uchar* sptr = data;
|
||||
const uchar* sptr = src.data;
|
||||
uchar* dptr = dst.data;
|
||||
|
||||
#if IPP_VERSION_X100 >= 201700
|
||||
CV_IPP_RUN_FAST(CV_INSTRUMENT_FUN_IPP(ippiCopy_8u_C1R_L, sptr, (int)step, dptr, (int)dst.step, ippiSizeL((int)(cols*elemSize()), rows)) >= 0)
|
||||
CV_IPP_RUN_FAST(CV_INSTRUMENT_FUN_IPP(ippiCopy_8u_C1R_L, sptr, (int)src.step, dptr, (int)dst.step, ippiSizeL(sz.width, sz.height)) >= 0)
|
||||
#endif
|
||||
|
||||
Size sz = getContinuousSize(*this, dst);
|
||||
size_t len = sz.width*elemSize();
|
||||
|
||||
for( ; sz.height--; sptr += step, dptr += dst.step )
|
||||
memcpy( dptr, sptr, len );
|
||||
for (; sz.height--; sptr += src.step, dptr += dst.step)
|
||||
memcpy(dptr, sptr, sz.width);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -403,10 +399,9 @@ void Mat::copyTo( OutputArray _dst, InputArray _mask ) const
|
||||
|
||||
if( dims <= 2 )
|
||||
{
|
||||
if (_dst.isVector() && dst.size() != size()) // https://github.com/opencv/opencv/pull/4159
|
||||
dst = dst.reshape(0, (int)dst.total());
|
||||
Size sz = getContinuousSize(*this, dst, mask, mcn);
|
||||
copymask(data, step, mask.data, mask.step, dst.data, dst.step, sz, &esz);
|
||||
Mat src = *this;
|
||||
Size sz = getContinuousSize2D(src, dst, mask, mcn);
|
||||
copymask(src.data, src.step, mask.data, mask.step, dst.data, dst.step, sz, &esz);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user