1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00

implemented rb_cvAlloc and replaced cvAlloc with rb_cvAlloc to allocate memory buffer as much as possible

This commit is contained in:
ser1zw 2011-04-28 00:11:46 +09:00
parent 196c567ee0
commit 586f2161eb
6 changed files with 94 additions and 29 deletions

View file

@ -181,16 +181,18 @@ CVPOINTS_FROM_POINT_SET(VALUE object, CvPoint **pointset)
CvPoint2D32f p32;
if(rb_obj_is_kind_of(object, cCvSeq::rb_class())){
if(CV_IS_SEQ_POINT_SET(CVSEQ(object))){
*pointset = (CvPoint*)cvCvtSeqToArray(CVSEQ(object), cvAlloc(CVSEQ(object)->total * CVSEQ(object)->elem_size));
*pointset = (CvPoint*)cvCvtSeqToArray(CVSEQ(object),
rb_cvAlloc(CVSEQ(object)->total * CVSEQ(object)->elem_size));
return CVSEQ(object)->total;
}else{
rb_raise(rb_eTypeError, "sequence is not contain %s or %s.", rb_class2name(cCvPoint::rb_class()), rb_class2name(cCvPoint2D32f::rb_class()));
rb_raise(rb_eTypeError, "sequence is not contain %s or %s.",
rb_class2name(cCvPoint::rb_class()), rb_class2name(cCvPoint2D32f::rb_class()));
}
}else if(rb_obj_is_kind_of(object, cCvMat::rb_class())){
/* to do */
rb_raise(rb_eNotImpError, "CvMat to CvSeq conversion not implemented.");
}else if(rb_obj_is_kind_of(object, rb_cArray)){
*pointset = (CvPoint*)cvAlloc(RARRAY_LEN(object) * sizeof(CvPoint));
*pointset = (CvPoint*)rb_cvAlloc(RARRAY_LEN(object) * sizeof(CvPoint));
for(int i = 0; i < RARRAY_LEN(object); i++){
(*pointset)[i].x = NUM2INT(rb_funcall(rb_ary_entry(object, i), rb_intern("x"), 0));
(*pointset)[i].y = NUM2INT(rb_funcall(rb_ary_entry(object, i), rb_intern("y"), 0));