diff --git a/src/Matrix.cc b/src/Matrix.cc index 149778b..ff8297f 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -27,6 +27,7 @@ Matrix::Init(Handle target) { NODE_SET_PROTOTYPE_METHOD(ctor, "empty", Empty); NODE_SET_PROTOTYPE_METHOD(ctor, "get", Get); NODE_SET_PROTOTYPE_METHOD(ctor, "set", Set); + NODE_SET_PROTOTYPE_METHOD(ctor, "put", Put); NODE_SET_PROTOTYPE_METHOD(ctor, "pixel", Pixel); NODE_SET_PROTOTYPE_METHOD(ctor, "width", Width); NODE_SET_PROTOTYPE_METHOD(ctor, "height", Height); @@ -271,6 +272,21 @@ NAN_METHOD(Matrix::Set){ NanReturnUndefined(); } +// @author tualo +// put node buffer directly into the image data +// img.put(new Buffer([0,100,0,100,100...])); +NAN_METHOD(Matrix::Put){ + SETUP_FUNCTION(Matrix) + + if (!Buffer::HasInstance(args[0])) { + NanThrowTypeError( "Not a buffer" ); + } + const char* buffer_data = Buffer::Data(args[0]); + size_t buffer_length = Buffer::Length(args[0]); + memcpy(self->mat.data, buffer_data, buffer_length); + NanReturnUndefined(); +} + NAN_METHOD(Matrix::Size){ SETUP_FUNCTION(Matrix) diff --git a/src/Matrix.h b/src/Matrix.h index 5461975..04cf1d6 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -20,6 +20,7 @@ class Matrix: public node::ObjectWrap { JSFUNC(Get) // at JSFUNC(Set) + JSFUNC(Put) JSFUNC(Row) JSFUNC(PixelRow)