Selects array diagonal
| 1381 | |
| 1382 | // Selects array diagonal |
| 1383 | CV_IMPL CvMat* |
| 1384 | cvGetDiag( const CvArr* arr, CvMat* submat, int diag ) |
| 1385 | { |
| 1386 | CvMat* res = 0; |
| 1387 | CvMat stub, *mat = (CvMat*)arr; |
| 1388 | int len, pix_size; |
| 1389 | |
| 1390 | if( !CV_IS_MAT( mat )) |
| 1391 | mat = cvGetMat( mat, &stub ); |
| 1392 | |
| 1393 | if( !submat ) |
| 1394 | CV_Error( CV_StsNullPtr, "" ); |
| 1395 | |
| 1396 | pix_size = CV_ELEM_SIZE(mat->type); |
| 1397 | |
| 1398 | /*{ |
| 1399 | int* refcount = mat->refcount; |
| 1400 | |
| 1401 | if( refcount ) |
| 1402 | ++*refcount; |
| 1403 | |
| 1404 | cvDecRefData( submat ); |
| 1405 | }*/ |
| 1406 | |
| 1407 | if( diag >= 0 ) |
| 1408 | { |
| 1409 | len = mat->cols - diag; |
| 1410 | |
| 1411 | if( len <= 0 ) |
| 1412 | CV_Error( CV_StsOutOfRange, "" ); |
| 1413 | |
| 1414 | len = CV_IMIN( len, mat->rows ); |
| 1415 | submat->data.ptr = mat->data.ptr + diag*pix_size; |
| 1416 | } |
| 1417 | else |
| 1418 | { |
| 1419 | len = mat->rows + diag; |
| 1420 | |
| 1421 | if( len <= 0 ) |
| 1422 | CV_Error( CV_StsOutOfRange, "" ); |
| 1423 | |
| 1424 | len = CV_IMIN( len, mat->cols ); |
| 1425 | submat->data.ptr = mat->data.ptr - diag*mat->step; |
| 1426 | } |
| 1427 | |
| 1428 | submat->rows = len; |
| 1429 | submat->cols = 1; |
| 1430 | submat->step = mat->step + (submat->rows > 1 ? pix_size : 0); |
| 1431 | submat->type = mat->type; |
| 1432 | if( submat->rows > 1 ) |
| 1433 | submat->type &= ~CV_MAT_CONT_FLAG; |
| 1434 | else |
| 1435 | submat->type |= CV_MAT_CONT_FLAG; |
| 1436 | submat->refcount = 0; |
| 1437 | submat->hdr_refcount = 0; |
| 1438 | res = submat; |
| 1439 | |
| 1440 | return res; |
nothing calls this directly
no test coverage detected