Returns specifed element of n-D array given linear index
| 1908 | |
| 1909 | // Returns specifed element of n-D array given linear index |
| 1910 | CV_IMPL CvScalar |
| 1911 | cvGet1D( const CvArr* arr, int idx ) |
| 1912 | { |
| 1913 | CvScalar scalar = {{0,0,0,0}}; |
| 1914 | int type = 0; |
| 1915 | uchar* ptr; |
| 1916 | |
| 1917 | if( CV_IS_MAT( arr ) && CV_IS_MAT_CONT( ((CvMat*)arr)->type )) |
| 1918 | { |
| 1919 | CvMat* mat = (CvMat*)arr; |
| 1920 | |
| 1921 | type = CV_MAT_TYPE(mat->type); |
| 1922 | int pix_size = CV_ELEM_SIZE(type); |
| 1923 | |
| 1924 | // the first part is mul-free sufficient check |
| 1925 | // that the index is within the matrix |
| 1926 | if( (unsigned)idx >= (unsigned)(mat->rows + mat->cols - 1) && |
| 1927 | (unsigned)idx >= (unsigned)(mat->rows*mat->cols)) |
| 1928 | CV_Error( CV_StsOutOfRange, "index is out of range" ); |
| 1929 | |
| 1930 | ptr = mat->data.ptr + (size_t)idx*pix_size; |
| 1931 | } |
| 1932 | else if( !CV_IS_SPARSE_MAT( arr ) || ((CvSparseMat*)arr)->dims > 1 ) |
| 1933 | ptr = cvPtr1D( arr, idx, &type ); |
| 1934 | else |
| 1935 | ptr = icvGetNodePtr( (CvSparseMat*)arr, &idx, &type, 0, 0 ); |
| 1936 | |
| 1937 | if( ptr ) |
| 1938 | cvRawDataToScalar( ptr, type, &scalar ); |
| 1939 | |
| 1940 | return scalar; |
| 1941 | } |
| 1942 | |
| 1943 | |
| 1944 | // Returns specifed element of 2D array |
nothing calls this directly
no test coverage detected