Skip to content

Commit

Permalink
Starting Bitmap module, #13.
Browse files Browse the repository at this point in the history
  • Loading branch information
octalmage committed Mar 29, 2015
1 parent e141593 commit 60a3566
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
25 changes: 24 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
module.exports = require('./build/Release/robotjs.node');
var robotjs = require('./build/Release/robotjs.node');

module.exports = robotjs;

module.exports.screen = {};

function bitmap (imagedata, width, height)
{
this.imagedata = imagedata;
this.width = width;
this.height = height;
}

bitmap.prototype.save = function(path)
{
console.log("saving");
//robotjs.saveBitmap(this.imagedata, path);
};

module.exports.screen.capture = function()
{
b = robotjs.captureScreen();
return new bitmap(b.image, b.width, b.height);
}
61 changes: 60 additions & 1 deletion src/robotjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "keypress.h"
#include "screen.h"
#include "screengrab.h"
#include "str_io.h"
#include "MMBitmap.h"

using namespace v8;
Expand Down Expand Up @@ -288,6 +289,59 @@ NAN_METHOD(getPixelColor)
NanReturnValue(NanNew(hex));
}

/*
____ _ _
| __ )(_) |_ _ __ ___ __ _ _ __
| _ \| | __| '_ ` _ \ / _` | '_ \
| |_) | | |_| | | | | | (_| | |_) |
|____/|_|\__|_| |_| |_|\__,_| .__/
|_|
*/

NAN_METHOD(captureScreen)
{
NanScope();

MMRect rect;
MMBitmapRef bitmap;
MMBMPStringError err;
MMSize displaySize = getMainDisplaySize();

rect = MMRectMake(0, 0, displaySize.width, displaySize.height);

bitmap = copyMMBitmapFromDisplayInRect(rect);

Local<Object> obj = NanNew<Object>();
obj->Set(NanNew<String>("width"), NanNew<Number>(displaySize.width));
obj->Set(NanNew<String>("height"), NanNew<Number>(displaySize.height));
obj->Set(NanNew<String>("image"), NanNew<String>(createStringFromMMBitmap(bitmap, &err)));

destroyMMBitmap(bitmap);

NanReturnValue(obj);
}

NAN_METHOD(getColor)
{
NanScope();

MMBitmapRef bitmap;
MMBMPStringError err;

uint8_t *str = (*v8::String::Utf8Value(args[0]->ToString()));
size_t len = strlen(str);

bitmap = createMMBitmapFromString(str, len, &err));

/*Local<Object> obj = NanNew<Object>();
obj->Set(NanNew<String>("width"), NanNew<Number>(displaySize.width));
obj->Set(NanNew<String>("height"), NanNew<Number>(displaySize.height));
obj->Set(NanNew<String>("image"), NanNew<String>(createStringFromMMBitmap(bitmap, &err)));
NanReturnValue(obj);*/

NanReturnValue(NanNew("1"));
}

void init(Handle<Object> target)
{

Expand All @@ -314,7 +368,12 @@ void init(Handle<Object> target)

target->Set(NanNew<String>("getPixelColor"),
NanNew<FunctionTemplate>(getPixelColor)->GetFunction());


target->Set(NanNew<String>("captureScreen"),
NanNew<FunctionTemplate>(captureScreen)->GetFunction());

target->Set(NanNew<String>("getColor"),
NanNew<FunctionTemplate>(getColor)->GetFunction());
}

NODE_MODULE(robotjs, init)

0 comments on commit 60a3566

Please sign in to comment.