Clean up C API

This commit is contained in:
Suleyman TURKMEN
2021-03-03 00:26:50 +03:00
parent 178240ccf1
commit 703dea4817
23 changed files with 0 additions and 2351 deletions

View File

@@ -324,200 +324,6 @@ cvCloneMatND( const CvMatND* src )
}
static CvMatND*
cvGetMatND( const CvArr* arr, CvMatND* matnd, int* coi )
{
CvMatND* result = 0;
if( coi )
*coi = 0;
if( !matnd || !arr )
CV_Error( CV_StsNullPtr, "NULL array pointer is passed" );
if( CV_IS_MATND_HDR(arr))
{
if( !((CvMatND*)arr)->data.ptr )
CV_Error( CV_StsNullPtr, "The matrix has NULL data pointer" );
result = (CvMatND*)arr;
}
else
{
CvMat stub, *mat = (CvMat*)arr;
if( CV_IS_IMAGE_HDR( mat ))
mat = cvGetMat( mat, &stub, coi );
if( !CV_IS_MAT_HDR( mat ))
CV_Error( CV_StsBadArg, "Unrecognized or unsupported array type" );
if( !mat->data.ptr )
CV_Error( CV_StsNullPtr, "Input array has NULL data pointer" );
matnd->data.ptr = mat->data.ptr;
matnd->refcount = 0;
matnd->hdr_refcount = 0;
matnd->type = mat->type;
matnd->dims = 2;
matnd->dim[0].size = mat->rows;
matnd->dim[0].step = mat->step;
matnd->dim[1].size = mat->cols;
matnd->dim[1].step = CV_ELEM_SIZE(mat->type);
result = matnd;
}
return result;
}
// returns number of dimensions to iterate.
/*
Checks whether <count> arrays have equal type, sizes (mask is optional array
that needs to have the same size, but 8uC1 or 8sC1 type - feature has been disabled).
Returns number of dimensions to iterate through:
0 means that all arrays are continuous,
1 means that all arrays are vectors of continuous arrays etc.
and the size of largest common continuous part of the arrays
*/
CV_IMPL int
cvInitNArrayIterator( int count, CvArr** arrs,
const CvArr* mask, CvMatND* stubs,
CvNArrayIterator* iterator, int flags )
{
int dims = -1;
int i, j, size, dim0 = -1;
int64 step;
CvMatND* hdr0 = 0;
if( count < 1 || count > CV_MAX_ARR )
CV_Error( CV_StsOutOfRange, "Incorrect number of arrays" );
if( !arrs || !stubs )
CV_Error( CV_StsNullPtr, "Some of required array pointers is NULL" );
if( !iterator )
CV_Error( CV_StsNullPtr, "Iterator pointer is NULL" );
if (mask)
CV_Error( CV_StsBadArg, "Iterator with mask is not supported" );
for( i = 0; i < count; i++ )
{
const CvArr* arr = arrs[i];
CvMatND* hdr;
if( !arr )
CV_Error( CV_StsNullPtr, "Some of required array pointers is NULL" );
if( CV_IS_MATND( arr ))
hdr = (CvMatND*)arr;
else
{
int coi = 0;
hdr = cvGetMatND( arr, stubs + i, &coi );
if( coi != 0 )
CV_Error( CV_BadCOI, "COI set is not allowed here" );
}
iterator->hdr[i] = hdr;
if( i > 0 )
{
if( hdr->dims != hdr0->dims )
CV_Error( CV_StsUnmatchedSizes,
"Number of dimensions is the same for all arrays" );
switch( flags & (CV_NO_DEPTH_CHECK|CV_NO_CN_CHECK))
{
case 0:
if( !CV_ARE_TYPES_EQ( hdr, hdr0 ))
CV_Error( CV_StsUnmatchedFormats,
"Data type is not the same for all arrays" );
break;
case CV_NO_DEPTH_CHECK:
if( !CV_ARE_CNS_EQ( hdr, hdr0 ))
CV_Error( CV_StsUnmatchedFormats,
"Number of channels is not the same for all arrays" );
break;
case CV_NO_CN_CHECK:
if( !CV_ARE_CNS_EQ( hdr, hdr0 ))
CV_Error( CV_StsUnmatchedFormats,
"Depth is not the same for all arrays" );
break;
}
if( !(flags & CV_NO_SIZE_CHECK) )
{
for( j = 0; j < hdr->dims; j++ )
if( hdr->dim[j].size != hdr0->dim[j].size )
CV_Error( CV_StsUnmatchedSizes,
"Dimension sizes are the same for all arrays" );
}
}
else
hdr0 = hdr;
step = CV_ELEM_SIZE(hdr->type);
for( j = hdr->dims - 1; j > dim0; j-- )
{
if( step != hdr->dim[j].step )
break;
step *= hdr->dim[j].size;
}
if( j == dim0 && step > INT_MAX )
j++;
if( j > dim0 )
dim0 = j;
iterator->hdr[i] = (CvMatND*)hdr;
iterator->ptr[i] = (uchar*)hdr->data.ptr;
}
size = 1;
for( j = hdr0->dims - 1; j > dim0; j-- )
size *= hdr0->dim[j].size;
dims = dim0 + 1;
iterator->dims = dims;
iterator->count = count;
iterator->size = cvSize(size,1);
for( i = 0; i < dims; i++ )
iterator->stack[i] = hdr0->dim[i].size;
return dims;
}
// returns zero value if iteration is finished, non-zero otherwise
CV_IMPL int cvNextNArraySlice( CvNArrayIterator* iterator )
{
assert( iterator != 0 );
int i, dims;
for( dims = iterator->dims; dims > 0; dims-- )
{
for( i = 0; i < iterator->count; i++ )
iterator->ptr[i] += iterator->hdr[i]->dim[dims-1].step;
if( --iterator->stack[dims-1] > 0 )
break;
const int size = iterator->hdr[0]->dim[dims-1].size;
for( i = 0; i < iterator->count; i++ )
iterator->ptr[i] -= (size_t)size*iterator->hdr[i]->dim[dims-1].step;
iterator->stack[dims-1] = size;
}
return dims > 0;
}
/****************************************************************************************\
* CvSparseMat creation and basic operations *
\****************************************************************************************/
@@ -1387,67 +1193,6 @@ cvGetCols( const CvArr* arr, CvMat* submat, int start_col, int end_col )
}
// Selects array diagonal
CV_IMPL CvMat*
cvGetDiag( const CvArr* arr, CvMat* submat, int diag )
{
CvMat* res = 0;
CvMat stub, *mat = (CvMat*)arr;
int len, pix_size;
if( !CV_IS_MAT( mat ))
mat = cvGetMat( mat, &stub );
if( !submat )
CV_Error( CV_StsNullPtr, "" );
pix_size = CV_ELEM_SIZE(mat->type);
/*{
int* refcount = mat->refcount;
if( refcount )
++*refcount;
cvDecRefData( submat );
}*/
if( diag >= 0 )
{
len = mat->cols - diag;
if( len <= 0 )
CV_Error( CV_StsOutOfRange, "" );
len = CV_IMIN( len, mat->rows );
submat->data.ptr = mat->data.ptr + diag*pix_size;
}
else
{
len = mat->rows + diag;
if( len <= 0 )
CV_Error( CV_StsOutOfRange, "" );
len = CV_IMIN( len, mat->cols );
submat->data.ptr = mat->data.ptr - diag*mat->step;
}
submat->rows = len;
submat->cols = 1;
submat->step = mat->step + (submat->rows > 1 ? pix_size : 0);
submat->type = mat->type;
if( submat->rows > 1 )
submat->type &= ~CV_MAT_CONT_FLAG;
else
submat->type |= CV_MAT_CONT_FLAG;
submat->refcount = 0;
submat->hdr_refcount = 0;
res = submat;
return res;
}
/****************************************************************************************\
* Operations on CvScalar and accessing array elements *
\****************************************************************************************/
@@ -2498,214 +2243,6 @@ cvGetMat( const CvArr* array, CvMat* mat,
}
CV_IMPL CvArr*
cvReshapeMatND( const CvArr* arr,
int sizeof_header, CvArr* _header,
int new_cn, int new_dims, int* new_sizes )
{
CvArr* result = 0;
int dims, coi = 0;
if( !arr || !_header )
CV_Error( CV_StsNullPtr, "NULL pointer to array or destination header" );
if( new_cn == 0 && new_dims == 0 )
CV_Error( CV_StsBadArg, "None of array parameters is changed: dummy call?" );
dims = cvGetDims( arr );
if( new_dims == 0 )
{
new_sizes = 0;
new_dims = dims;
}
else if( new_dims == 1 )
{
new_sizes = 0;
}
else
{
if( new_dims <= 0 || new_dims > CV_MAX_DIM )
CV_Error( CV_StsOutOfRange, "Non-positive or too large number of dimensions" );
if( !new_sizes )
CV_Error( CV_StsNullPtr, "New dimension sizes are not specified" );
}
if( new_dims <= 2 )
{
CvMat* mat = (CvMat*)arr;
CvMat header;
int* refcount = 0;
int hdr_refcount = 0;
int total_width, new_rows, cn;
if( sizeof_header != sizeof(CvMat) && sizeof_header != sizeof(CvMatND) )
CV_Error( CV_StsBadArg, "The output header should be CvMat or CvMatND" );
if( mat == (CvMat*)_header )
{
refcount = mat->refcount;
hdr_refcount = mat->hdr_refcount;
}
if( !CV_IS_MAT( mat ))
mat = cvGetMat( mat, &header, &coi, 1 );
cn = CV_MAT_CN( mat->type );
total_width = mat->cols * cn;
if( new_cn == 0 )
new_cn = cn;
if( new_sizes )
new_rows = new_sizes[0];
else if( new_dims == 1 )
new_rows = total_width*mat->rows/new_cn;
else
{
new_rows = mat->rows;
if( new_cn > total_width )
new_rows = mat->rows * total_width / new_cn;
}
if( new_rows != mat->rows )
{
int total_size = total_width * mat->rows;
if( !CV_IS_MAT_CONT( mat->type ))
CV_Error( CV_BadStep,
"The matrix is not continuous so the number of rows can not be changed" );
total_width = total_size / new_rows;
if( total_width * new_rows != total_size )
CV_Error( CV_StsBadArg, "The total number of matrix elements "
"is not divisible by the new number of rows" );
}
header.rows = new_rows;
header.cols = total_width / new_cn;
if( header.cols * new_cn != total_width ||
(new_sizes && header.cols != new_sizes[1]) )
CV_Error( CV_StsBadArg, "The total matrix width is not "
"divisible by the new number of columns" );
header.type = (mat->type & ~CV_MAT_TYPE_MASK) | CV_MAKETYPE(mat->type, new_cn);
header.step = header.cols * CV_ELEM_SIZE(mat->type);
header.step &= new_rows > 1 ? -1 : 0;
header.refcount = refcount;
header.hdr_refcount = hdr_refcount;
if( sizeof_header == sizeof(CvMat) )
*(CvMat*)_header = header;
else
{
CvMatND* __header = (CvMatND*)_header;
cvGetMatND(&header, __header, 0);
if( new_dims > 0 )
__header->dims = new_dims;
}
}
else
{
CvMatND* header = (CvMatND*)_header;
if( sizeof_header != sizeof(CvMatND))
CV_Error( CV_StsBadSize, "The output header should be CvMatND" );
if( !new_sizes )
{
if( !CV_IS_MATND( arr ))
CV_Error( CV_StsBadArg, "The input array must be CvMatND" );
{
CvMatND* mat = (CvMatND*)arr;
assert( new_cn > 0 );
int last_dim_size = mat->dim[mat->dims-1].size*CV_MAT_CN(mat->type);
int new_size = last_dim_size/new_cn;
if( new_size*new_cn != last_dim_size )
CV_Error( CV_StsBadArg,
"The last dimension full size is not divisible by new number of channels");
if( mat != header )
{
memcpy( header, mat, sizeof(*header));
header->refcount = 0;
header->hdr_refcount = 0;
}
header->dim[header->dims-1].size = new_size;
header->type = (header->type & ~CV_MAT_TYPE_MASK) | CV_MAKETYPE(header->type, new_cn);
}
}
else
{
CvMatND stub;
CvMatND* mat = (CvMatND*)arr;
int i, size1, size2;
int step;
if( new_cn != 0 )
CV_Error( CV_StsBadArg,
"Simultaneous change of shape and number of channels is not supported. "
"Do it by 2 separate calls" );
if( !CV_IS_MATND( mat ))
{
cvGetMatND( mat, &stub, &coi );
mat = &stub;
}
if( CV_IS_MAT_CONT( mat->type ))
CV_Error( CV_StsBadArg, "Non-continuous nD arrays are not supported" );
size1 = mat->dim[0].size;
for( i = 1; i < dims; i++ )
size1 *= mat->dim[i].size;
size2 = 1;
for( i = 0; i < new_dims; i++ )
{
if( new_sizes[i] <= 0 )
CV_Error( CV_StsBadSize,
"One of new dimension sizes is non-positive" );
size2 *= new_sizes[i];
}
if( size1 != size2 )
CV_Error( CV_StsBadSize,
"Number of elements in the original and reshaped array is different" );
if( header != mat )
{
header->refcount = 0;
header->hdr_refcount = 0;
}
header->dims = new_dims;
header->type = mat->type;
header->data.ptr = mat->data.ptr;
step = CV_ELEM_SIZE(header->type);
for( i = new_dims - 1; i >= 0; i-- )
{
header->dim[i].size = new_sizes[i];
header->dim[i].step = step;
step *= new_sizes[i];
}
}
}
if( coi )
CV_Error( CV_BadCOI, "COI is not supported by this operation" );
result = _header;
return result;
}
CV_IMPL CvMat*
cvReshape( const CvArr* array, CvMat* header,
int new_cn, int new_rows )
@@ -3279,20 +2816,5 @@ cvRelease( void** struct_ptr )
}
}
void* cvClone( const void* struct_ptr )
{
void* ptr = 0;
if( !struct_ptr )
CV_Error( CV_StsNullPtr, "NULL structure pointer" );
if( CV_IS_MAT(struct_ptr) )
ptr = cvCloneMat((const CvMat*)struct_ptr);
else if( CV_IS_IMAGE(struct_ptr))
ptr = cvCloneImage((const IplImage*)struct_ptr);
else
CV_Error( CV_StsError, "Unknown object type" );
return ptr;
}
/* End of file. */