added mat.put(buffer) function

This commit is contained in:
Thomas Hoffmann 2015-04-22 07:51:46 +02:00
parent e65202575a
commit 150fc4a66d
2 changed files with 17 additions and 0 deletions

View File

@ -27,6 +27,7 @@ Matrix::Init(Handle<Object> 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)

View File

@ -20,6 +20,7 @@ class Matrix: public node::ObjectWrap {
JSFUNC(Get) // at
JSFUNC(Set)
JSFUNC(Put)
JSFUNC(Row)
JSFUNC(PixelRow)