From 809b5eba500e8ffe8dc6088235f57ada9ea1f42e Mon Sep 17 00:00:00 2001 From: Peter Braden Date: Mon, 24 Sep 2012 15:38:12 -0700 Subject: [PATCH] WIP on proper get/set --- src/Matrix.cc | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index c1da7da..004d6f0 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -123,8 +123,26 @@ Matrix::Get(const Arguments& args){ int i = args[0]->IntegerValue(); int j = args[1]->IntegerValue(); + double val = 0; - return scope.Close(Number::New(self->mat.at(i,j))); + cv::Vec3b pix; + unsigned int pint = 0; + + switch(self->mat.type()){ + case CV_32FC3: + pix = self->mat.at(i, j); + pint &= (uchar) pix.val[2]; + pint &= ((uchar) pix.val[1]) << 8; + pint &= ((uchar) pix.val[0]) << 16; + val = (double) pint; + break; + + default: + val = self->mat.at(i,j); + break; + } + + return scope.Close(Number::New(val)); } @@ -140,9 +158,15 @@ Matrix::Set(const Arguments& args){ self->mat.at(i,j)[args[3]->NumberValue()] = val; } else if(args.Length() == 3) { - self->mat.at(i,j)[0] = val; - self->mat.at(i,j)[1] = val; - self->mat.at(i,j)[2] = val; + switch(self->mat.type()){ + + case CV_32FC3: + self->mat.at(i,j)[0] = static_cast (val + 0.5) >> 16; + self->mat.at(i,j)[1] = static_cast (val + 0.5) >> 8; + self->mat.at(i,j)[2] = static_cast (val + 0.5); + break; + } + } else { return v8::ThrowException(v8::Exception::TypeError(String::New("Invalid number of arguments")));