From 96d0eb88241b9b7cf8e57ab800e39411871ad9ab Mon Sep 17 00:00:00 2001 From: Simon Hailes Date: Sun, 12 Nov 2017 16:03:17 +0000 Subject: [PATCH] Matrix: add mtx.addref() and mtx.getrefCount() --- src/Matrix.cc | 37 +++++++++++++++++++++++++++++++++++++ src/Matrix.h | 3 +++ 2 files changed, 40 insertions(+) diff --git a/src/Matrix.cc b/src/Matrix.cc index 319853d..70c79fa 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -117,7 +117,9 @@ void Matrix::Init(Local target) { Nan::SetPrototypeMethod(ctor, "mean", Mean); Nan::SetPrototypeMethod(ctor, "shift", Shift); Nan::SetPrototypeMethod(ctor, "reshape", Reshape); + Nan::SetPrototypeMethod(ctor, "addref", Addref); Nan::SetPrototypeMethod(ctor, "release", Release); + Nan::SetPrototypeMethod(ctor, "getrefCount", GetrefCount); Nan::SetPrototypeMethod(ctor, "subtract", Subtract); Nan::SetPrototypeMethod(ctor, "compare", Compare); Nan::SetPrototypeMethod(ctor, "mul", Mul); @@ -3025,6 +3027,41 @@ NAN_METHOD(Matrix::Release) { return; } +NAN_METHOD(Matrix::Addref) { + Nan::HandleScope scope; + + Matrix *self = Nan::ObjectWrap::Unwrap(info.This()); + self->mat.addref(); + + return; +} + + +NAN_METHOD(Matrix::GetrefCount) { + Nan::HandleScope scope; + Matrix *self = Nan::ObjectWrap::Unwrap(info.This()); + + int refcount = -1; + +#if CV_MAJOR_VERSION >= 3 + if (self->mat.u){ + refcount = self->mat.u->refcount; + } else { + refcount = -1; + } +#else + if (self->mat.refcount){ + refcount = *self->mat.refcount); + } else { + refcount = -1; + } +#endif + + info.GetReturnValue().Set(Nan::New(refcount)); + return; +} + + NAN_METHOD(Matrix::Subtract) { SETUP_FUNCTION(Matrix) diff --git a/src/Matrix.h b/src/Matrix.h index 5033c61..e904344 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -134,7 +134,10 @@ public: JSFUNC(Shift) JSFUNC(Reshape) + + JSFUNC(Addref) JSFUNC(Release) + JSFUNC(GetrefCount) JSFUNC(Subtract) JSFUNC(Compare)