void UMat::create(int d, const int* _sizes, int _type, UMatUsageFlags _usageFlags) { this->usageFlags = _usageFlags; int i; CV_Assert(0 <= d && d <= CV_MAX_DIM && _sizes); _type = CV_MAT_TYPE(_type); if( u && (d == dims || (d == 1 && dims <= 2)) && _type == type() ) { if( d == 2 && rows == _sizes[0] && cols == _sizes[1] ) return; for( i = 0; i < d; i++ ) if( size[i] != _sizes[i] ) break; if( i == d && (d > 1 || size[1] == 1)) return; } int _sizes_backup[CV_MAX_DIM]; // #5991 if (_sizes == (this->size.p)) { for(i = 0; i < d; i++ ) _sizes_backup[i] = _sizes[i]; _sizes = _sizes_backup; } release(); if( d == 0 ) return; flags = (_type & CV_MAT_TYPE_MASK) | MAGIC_VAL; setSize(*this, d, _sizes, 0, true); offset = 0; if( total() > 0 ) { MatAllocator *a = allocator, *a0 = getStdAllocator(); if (!a) { a = a0; a0 = Mat::getDefaultAllocator(); } try { u = a->allocate(dims, size, _type, 0, step.p, 0, usageFlags); CV_Assert(u != 0); } catch(...) { if(a != a0) u = a0->allocate(dims, size, _type, 0, step.p, 0, usageFlags); CV_Assert(u != 0); } CV_Assert( step[dims-1] == (size_t)CV_ELEM_SIZE(flags) ); } finalizeHdr(*this); addref(); }
MatAllocator* Mat::getDefaultAllocator() { if (g_matAllocator == NULL) { cv::AutoLock lock(cv::getInitializationMutex()); if (g_matAllocator == NULL) { g_matAllocator = getStdAllocator(); } } return g_matAllocator; }
void UMat::create(int d, const int* _sizes, int _type) { int i; CV_Assert(0 <= d && d <= CV_MAX_DIM && _sizes); _type = CV_MAT_TYPE(_type); if( u && (d == dims || (d == 1 && dims <= 2)) && _type == type() ) { if( d == 2 && rows == _sizes[0] && cols == _sizes[1] ) return; for( i = 0; i < d; i++ ) if( size[i] != _sizes[i] ) break; if( i == d && (d > 1 || size[1] == 1)) return; } release(); if( d == 0 ) return; flags = (_type & CV_MAT_TYPE_MASK) | MAGIC_VAL; setSize(*this, d, _sizes, 0, true); offset = 0; if( total() > 0 ) { MatAllocator *a = allocator, *a0 = getStdAllocator(); if(!a) a = a0; try { u = a->allocate(dims, size, _type, 0, step.p, 0); CV_Assert(u != 0); } catch(...) { if(a != a0) u = a0->allocate(dims, size, _type, 0, step.p, 0); CV_Assert(u != 0); } CV_Assert( step[dims-1] == (size_t)CV_ELEM_SIZE(flags) ); } finalizeHdr(*this); }
UMat Mat::getUMat(int accessFlags) const { UMat hdr; if(!data) return hdr; UMatData* temp_u = u; if(!temp_u) { MatAllocator *a = allocator, *a0 = getStdAllocator(); if(!a) a = a0; temp_u = a->allocate(dims, size.p, type(), data, step.p, accessFlags); } UMat::getStdAllocator()->allocate(temp_u, accessFlags); hdr.flags = flags; setSize(hdr, dims, size.p, step.p); finalizeHdr(hdr); hdr.u = temp_u; hdr.offset = data - datastart; return hdr; }
UMat Mat::getUMat(int accessFlags, UMatUsageFlags usageFlags) const { UMat hdr; if(!data) return hdr; UMatData* temp_u = u; if(!temp_u) { MatAllocator *a = allocator, *a0 = getStdAllocator(); if(!a) a = a0; temp_u = a->allocate(dims, size.p, type(), data, step.p, accessFlags, usageFlags); temp_u->refcount = 1; } UMat::getStdAllocator()->allocate(temp_u, accessFlags, usageFlags); // TODO result is not checked hdr.flags = flags; setSize(hdr, dims, size.p, step.p); finalizeHdr(hdr); hdr.u = temp_u; hdr.offset = data - datastart; hdr.addref(); return hdr; }