MCPcopy Create free account
hub / github.com/creatale/node-dv / cvPtr2D

Function cvPtr2D

deps/opencv/modules/core/src/array.cpp:1743–1834  ·  view source on GitHub ↗

Returns pointer to specified element of 2d array

Source from the content-addressed store, hash-verified

1741
1742// Returns pointer to specified element of 2d array
1743CV_IMPL uchar*
1744cvPtr2D( const CvArr* arr, int y, int x, int* _type )
1745{
1746 uchar* ptr = 0;
1747 if( CV_IS_MAT( arr ))
1748 {
1749 CvMat* mat = (CvMat*)arr;
1750 int type;
1751
1752 if( (unsigned)y >= (unsigned)(mat->rows) ||
1753 (unsigned)x >= (unsigned)(mat->cols) )
1754 CV_Error( CV_StsOutOfRange, "index is out of range" );
1755
1756 type = CV_MAT_TYPE(mat->type);
1757 if( _type )
1758 *_type = type;
1759
1760 ptr = mat->data.ptr + (size_t)y*mat->step + x*CV_ELEM_SIZE(type);
1761 }
1762 else if( CV_IS_IMAGE( arr ))
1763 {
1764 IplImage* img = (IplImage*)arr;
1765 int pix_size = (img->depth & 255) >> 3;
1766 int width, height;
1767 ptr = (uchar*)img->imageData;
1768
1769 if( img->dataOrder == 0 )
1770 pix_size *= img->nChannels;
1771
1772 if( img->roi )
1773 {
1774 width = img->roi->width;
1775 height = img->roi->height;
1776
1777 ptr += img->roi->yOffset*img->widthStep +
1778 img->roi->xOffset*pix_size;
1779
1780 if( img->dataOrder )
1781 {
1782 int coi = img->roi->coi;
1783 if( !coi )
1784 CV_Error( CV_BadCOI,
1785 "COI must be non-null in case of planar images" );
1786 ptr += (coi - 1)*img->imageSize;
1787 }
1788 }
1789 else
1790 {
1791 width = img->width;
1792 height = img->height;
1793 }
1794
1795 if( (unsigned)y >= (unsigned)height ||
1796 (unsigned)x >= (unsigned)width )
1797 CV_Error( CV_StsOutOfRange, "index is out of range" );
1798
1799 ptr += y*img->widthStep + x*pix_size;
1800

Callers 7

cvGetRawDataFunction · 0.85
cvPtr1DFunction · 0.85
cvPtrNDFunction · 0.85
cvGet2DFunction · 0.85
cvGetReal2DFunction · 0.85
cvSet2DFunction · 0.85
cvSetReal2DFunction · 0.85

Calls 1

icvGetNodePtrFunction · 0.85

Tested by

no test coverage detected