mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
This commit is contained in:
@@ -228,6 +228,152 @@ UMatDataAutoLock::~UMatDataAutoLock()
|
||||
getUMatDataAutoLocker().release(u1, u2);
|
||||
}
|
||||
|
||||
//////////////////////////////// UMat ////////////////////////////////
|
||||
|
||||
UMat::UMat(UMatUsageFlags _usageFlags)
|
||||
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
|
||||
{}
|
||||
|
||||
UMat::UMat(int _rows, int _cols, int _type, UMatUsageFlags _usageFlags)
|
||||
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
|
||||
{
|
||||
create(_rows, _cols, _type);
|
||||
}
|
||||
|
||||
UMat::UMat(int _rows, int _cols, int _type, const Scalar& _s, UMatUsageFlags _usageFlags)
|
||||
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
|
||||
{
|
||||
create(_rows, _cols, _type);
|
||||
*this = _s;
|
||||
}
|
||||
|
||||
UMat::UMat(Size _sz, int _type, UMatUsageFlags _usageFlags)
|
||||
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
|
||||
{
|
||||
create( _sz.height, _sz.width, _type );
|
||||
}
|
||||
|
||||
UMat::UMat(Size _sz, int _type, const Scalar& _s, UMatUsageFlags _usageFlags)
|
||||
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
|
||||
{
|
||||
create(_sz.height, _sz.width, _type);
|
||||
*this = _s;
|
||||
}
|
||||
|
||||
UMat::UMat(int _dims, const int* _sz, int _type, UMatUsageFlags _usageFlags)
|
||||
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
|
||||
{
|
||||
create(_dims, _sz, _type);
|
||||
}
|
||||
|
||||
UMat::UMat(int _dims, const int* _sz, int _type, const Scalar& _s, UMatUsageFlags _usageFlags)
|
||||
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
|
||||
{
|
||||
create(_dims, _sz, _type);
|
||||
*this = _s;
|
||||
}
|
||||
|
||||
UMat::UMat(const UMat& m)
|
||||
: flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator),
|
||||
usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows)
|
||||
{
|
||||
addref();
|
||||
if( m.dims <= 2 )
|
||||
{
|
||||
step[0] = m.step[0]; step[1] = m.step[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
dims = 0;
|
||||
copySize(m);
|
||||
}
|
||||
}
|
||||
|
||||
UMat& UMat::operator=(const UMat& m)
|
||||
{
|
||||
if( this != &m )
|
||||
{
|
||||
const_cast<UMat&>(m).addref();
|
||||
release();
|
||||
flags = m.flags;
|
||||
if( dims <= 2 && m.dims <= 2 )
|
||||
{
|
||||
dims = m.dims;
|
||||
rows = m.rows;
|
||||
cols = m.cols;
|
||||
step[0] = m.step[0];
|
||||
step[1] = m.step[1];
|
||||
}
|
||||
else
|
||||
copySize(m);
|
||||
allocator = m.allocator;
|
||||
if (usageFlags == USAGE_DEFAULT)
|
||||
usageFlags = m.usageFlags;
|
||||
u = m.u;
|
||||
offset = m.offset;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
UMat UMat::clone() const
|
||||
{
|
||||
UMat m;
|
||||
copyTo(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
void UMat::assignTo(UMat& m, int _type) const
|
||||
{
|
||||
if( _type < 0 )
|
||||
m = *this;
|
||||
else
|
||||
convertTo(m, _type);
|
||||
}
|
||||
|
||||
void UMat::create(int _rows, int _cols, int _type, UMatUsageFlags _usageFlags)
|
||||
{
|
||||
_type &= TYPE_MASK;
|
||||
if( dims <= 2 && rows == _rows && cols == _cols && type() == _type && u )
|
||||
return;
|
||||
int sz[] = {_rows, _cols};
|
||||
create(2, sz, _type, _usageFlags);
|
||||
}
|
||||
|
||||
void UMat::create(Size _sz, int _type, UMatUsageFlags _usageFlags)
|
||||
{
|
||||
create(_sz.height, _sz.width, _type, _usageFlags);
|
||||
}
|
||||
|
||||
void UMat::addref()
|
||||
{
|
||||
if( u )
|
||||
CV_XADD(&(u->urefcount), 1);
|
||||
}
|
||||
|
||||
void UMat::release()
|
||||
{
|
||||
if( u && CV_XADD(&(u->urefcount), -1) == 1 )
|
||||
deallocate();
|
||||
for(int i = 0; i < dims; i++)
|
||||
size.p[i] = 0;
|
||||
u = 0;
|
||||
}
|
||||
|
||||
bool UMat::empty() const
|
||||
{
|
||||
return u == 0 || total() == 0 || dims == 0;
|
||||
}
|
||||
|
||||
size_t UMat::total() const
|
||||
{
|
||||
if( dims <= 2 )
|
||||
return (size_t)rows * cols;
|
||||
size_t p = 1;
|
||||
for( int i = 0; i < dims; i++ )
|
||||
p *= size[i];
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
MatAllocator* UMat::getStdAllocator()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user