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")));