Allocates underlying array data
| 792 | |
| 793 | // Allocates underlying array data |
| 794 | CV_IMPL void |
| 795 | cvCreateData( CvArr* arr ) |
| 796 | { |
| 797 | if( CV_IS_MAT_HDR_Z( arr )) |
| 798 | { |
| 799 | size_t step, total_size; |
| 800 | CvMat* mat = (CvMat*)arr; |
| 801 | step = mat->step; |
| 802 | |
| 803 | if( mat->rows == 0 || mat->cols == 0 ) |
| 804 | return; |
| 805 | |
| 806 | if( mat->data.ptr != 0 ) |
| 807 | CV_Error( CV_StsError, "Data is already allocated" ); |
| 808 | |
| 809 | if( step == 0 ) |
| 810 | step = CV_ELEM_SIZE(mat->type)*mat->cols; |
| 811 | |
| 812 | int64 _total_size = (int64)step*mat->rows + sizeof(int) + CV_MALLOC_ALIGN; |
| 813 | total_size = (size_t)_total_size; |
| 814 | if(_total_size != (int64)total_size) |
| 815 | CV_Error(CV_StsNoMem, "Too big buffer is allocated" ); |
| 816 | mat->refcount = (int*)cvAlloc( (size_t)total_size ); |
| 817 | mat->data.ptr = (uchar*)cvAlignPtr( mat->refcount + 1, CV_MALLOC_ALIGN ); |
| 818 | *mat->refcount = 1; |
| 819 | } |
| 820 | else if( CV_IS_IMAGE_HDR(arr)) |
| 821 | { |
| 822 | IplImage* img = (IplImage*)arr; |
| 823 | |
| 824 | if( img->imageData != 0 ) |
| 825 | CV_Error( CV_StsError, "Data is already allocated" ); |
| 826 | |
| 827 | if( !CvIPL.allocateData ) |
| 828 | { |
| 829 | img->imageData = img->imageDataOrigin = |
| 830 | (char*)cvAlloc( (size_t)img->imageSize ); |
| 831 | } |
| 832 | else |
| 833 | { |
| 834 | int depth = img->depth; |
| 835 | int width = img->width; |
| 836 | |
| 837 | if( img->depth == IPL_DEPTH_32F || img->depth == IPL_DEPTH_64F ) |
| 838 | { |
| 839 | img->width *= img->depth == IPL_DEPTH_32F ? sizeof(float) : sizeof(double); |
| 840 | img->depth = IPL_DEPTH_8U; |
| 841 | } |
| 842 | |
| 843 | CvIPL.allocateData( img, 0, 0 ); |
| 844 | |
| 845 | img->width = width; |
| 846 | img->depth = depth; |
| 847 | } |
| 848 | } |
| 849 | else if( CV_IS_MATND_HDR( arr )) |
| 850 | { |
| 851 | CvMatND* mat = (CvMatND*)arr; |
no test coverage detected