mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
implemented rb_cvCreateMemStorage and replaced cvCreateMemStorage with rb_cvCreateMemStorage to create CvMemStorage as much as possible
This commit is contained in:
parent
d9a7960949
commit
1ca99720c5
6 changed files with 36 additions and 6 deletions
|
@ -91,7 +91,7 @@ rb_initialize(int argc, VALUE *argv, VALUE self)
|
|||
storage = CVMEMSTORAGE(storage_value);
|
||||
}
|
||||
else
|
||||
storage = cvCreateMemStorage(0);
|
||||
storage = rb_cvCreateMemStorage(0);
|
||||
|
||||
DATA_PTR(self) = (CvChain*)cvCreateSeq(CV_SEQ_ELTYPE_CODE, sizeof(CvChain),
|
||||
sizeof(char), storage);
|
||||
|
|
|
@ -104,7 +104,7 @@ rb_initialize(int argc, VALUE *argv, VALUE self)
|
|||
storage = CVMEMSTORAGE(storage_value);
|
||||
}
|
||||
else
|
||||
storage = cvCreateMemStorage(0);
|
||||
storage = rb_cvCreateMemStorage(0);
|
||||
|
||||
DATA_PTR(self) = (CvContour*)cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvContour),
|
||||
sizeof(CvPoint), storage);
|
||||
|
|
|
@ -41,7 +41,7 @@ define_ruby_class()
|
|||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
CvMemStorage *storage = cvCreateMemStorage();
|
||||
CvMemStorage *storage = rb_cvCreateMemStorage(0);
|
||||
return Data_Wrap_Struct(klass, 0, cvmemstorage_free, storage);
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ cvmemstorage_free(void *ptr)
|
|||
VALUE
|
||||
new_object(int blocksize)
|
||||
{
|
||||
CvMemStorage *storage = cvCreateMemStorage(blocksize);
|
||||
CvMemStorage *storage = rb_cvCreateMemStorage(blocksize);
|
||||
return Data_Wrap_Struct(rb_klass, 0, cvmemstorage_free, storage);
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ rb_initialize(int argc, VALUE *argv, VALUE self)
|
|||
storage = CVMEMSTORAGE(storage_value);
|
||||
}
|
||||
else
|
||||
storage = cvCreateMemStorage(0);
|
||||
storage = rb_cvCreateMemStorage(0);
|
||||
|
||||
if(!rb_obj_is_kind_of(klass, rb_cClass))
|
||||
rb_raise(rb_eTypeError, "argument 1 (sequence-block class) should be %s.", rb_class2name(rb_cClass));
|
||||
|
|
|
@ -247,6 +247,35 @@ rb_cvCreateStructuringElementEx(int cols, int rows,
|
|||
return ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates memory storage
|
||||
* When memory allocation is failed, run GC and retry it
|
||||
*/
|
||||
CvMemStorage*
|
||||
rb_cvCreateMemStorage(int block_size)
|
||||
{
|
||||
CvMemStorage* ptr = NULL;
|
||||
try {
|
||||
ptr = cvCreateMemStorage(block_size);
|
||||
}
|
||||
catch(cv::Exception& e) {
|
||||
if (e.code != CV_StsNoMem)
|
||||
rb_raise(rb_eRuntimeError, "%s", e.what());
|
||||
|
||||
rb_gc_start();
|
||||
try {
|
||||
ptr = cvCreateMemStorage(block_size);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
if (e.code == CV_StsNoMem)
|
||||
rb_raise(rb_eNoMemError, "%s", e.what());
|
||||
else
|
||||
rb_raise(rb_eRuntimeError, "%s", e.what());
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
VALUE rb_module;
|
||||
VALUE rb_opencv_constants;
|
||||
|
||||
|
|
|
@ -189,6 +189,7 @@ void* rb_cvAlloc(size_t size);
|
|||
CvMat* rb_cvCreateMat(int height, int width, int type);
|
||||
IplImage* rb_cvCreateImage(CvSize size, int depth, int channels);
|
||||
IplConvKernel* rb_cvCreateStructuringElementEx(int cols, int rows, int anchorX, int anchorY, int shape, int *values);
|
||||
CvMemStorage* rb_cvCreateMemStorage(int block_size);
|
||||
|
||||
// Ruby/OpenCV inline functions
|
||||
inline CvArr*
|
||||
|
|
Loading…
Reference in a new issue