/* * call-seq: * sub(val[,mask]) * * Return new CvScalar if <i>val</i> is CvScalar or compatible object. * self[I] - val[I] * Or return new CvMat if <i>val</i> is CvMat or subclass. */ VALUE rb_sub(int argc, VALUE *argv, VALUE self) { VALUE val, mask; rb_scan_args(argc, argv, "11", &val, &mask); if (rb_obj_is_kind_of(val, cCvMat::rb_class())) { CvArr *val_ptr = CVARR(val); VALUE dest = Qnil; try { dest = cCvMat::new_object(cvGetSize(val_ptr), cvGetElemType(val_ptr)); cvSubRS(val_ptr, *CVSCALAR(self), CVARR(dest), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } else { CvScalar *src = CVSCALAR(self); CvScalar scl = VALUE_TO_CVSCALAR(val); return new_object(cvScalar(src->val[0] - scl.val[0], src->val[1] - scl.val[1], src->val[2] - scl.val[2], src->val[3] - scl.val[3])); } }
VALUE new_object(CvScalar scalar) { VALUE object = rb_allocate(rb_klass); *CVSCALAR(object) = scalar; return object; }
VALUE new_object() { VALUE object = rb_allocate(rb_klass); *CVSCALAR(object) = cvScalar(0); return object; }
/* * call-seq: * sub(val[,mask]) * * Return new CvScalar if <i>val</i> is CvScalar or compatible object. * self[I] - val[I] * Or return new CvMat if <i>val</i> is CvMat or subclass. */ VALUE rb_sub(int argc, VALUE *argv, VALUE self) { VALUE val, mask; rb_scan_args(argc, argv, "11", &val, &mask); if(rb_obj_is_kind_of(val, cCvMat::rb_class())){ VALUE dest = cCvMat::new_object(cvGetSize(CVARR(val)), cvGetElemType(CVARR(val))); cvSubRS(CVARR(val), *CVSCALAR(self), CVARR(dest), MASK(mask)); return dest; }else{ CvScalar *src = CVSCALAR(self), scl = VALUE_TO_CVSCALAR(val); return new_object(cvScalar(src->val[0] - scl.val[0], src->val[1] - scl.val[1], src->val[2] - scl.val[2], src->val[3] - scl.val[3])); } }
/* * call-seq: * [<i>index</i>] * * Return value of <i>index</i> dimension. */ VALUE rb_aref(VALUE self, VALUE index) { int idx = NUM2INT(index); if (idx < 0 || idx >= 4) { rb_raise(rb_eIndexError, "scalar index should be 0...4"); } return rb_float_new(CVSCALAR(self)->val[idx]); }
/* * call-seq: * new(<i>[d1][,d2][,d3][,d4]</i>) * * Create new Scalar. Argument should be Fixnum (or nil as 0). */ VALUE rb_initialize(int argc, VALUE *argv, VALUE self) { VALUE val[4]; rb_scan_args(argc, argv, "04", &val[0], &val[1], &val[2], &val[3]); for (int i = 0; i < 4; i++) { CVSCALAR(self)->val[i] = NIL_P(val[i]) ? 0 : NUM2DBL(val[i]); } return self; }
/* * call-seq: * [<i>index</i>] = <i>value</i> * * Set value of <i>index</i> dimension to <i>value</i> */ VALUE rb_aset(VALUE self, VALUE index, VALUE value) { int idx = NUM2INT(index); if (idx < 0 || idx >= 4) { rb_raise(rb_eIndexError, "scalar index should be 0...4"); } CVSCALAR(self)->val[idx] = NUM2DBL(value); return self; }
/* * call-seq: * new(<i>[d1][,d2][,d3][,d4]</i>) * * Create new Scalar. Argument should be Fixnum (or nil as 0). */ VALUE rb_initialize(int argc, VALUE *argv, VALUE self) { VALUE val[4]; rb_scan_args(argc, argv, "04", &val[0], &val[1], &val[2], &val[3]); CvScalar* self_ptr = CVSCALAR(self); for (int i = 0; i < 4; ++i) { self_ptr->val[i] = NIL_P(val[i]) ? 0 : NUM2DBL(val[i]); } return self; }
VALUE rb_initialize(int argc, VALUE *argv, VALUE self) { VALUE area, value, rect, contour; rb_scan_args(argc, argv, "04", &area, &value, &rect, &contour); if (!NIL_P(area)) CVCONNECTEDCOMP(self)->area = NUM2DBL(area); if (!NIL_P(value)) CVCONNECTEDCOMP(self)->value = *CVSCALAR(value); if (!NIL_P(rect)) CVCONNECTEDCOMP(self)->rect = *CVRECT(rect); if (!NIL_P(contour)) CVCONNECTEDCOMP(self)->contour = CVSEQ(contour); }