Skip to content

Commit

Permalink
Started getColor function.
Browse files Browse the repository at this point in the history
  • Loading branch information
octalmage committed Oct 6, 2015
1 parent 5dc3557 commit df737d1
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/robotjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,42 @@ NAN_METHOD(captureScreen)
info.GetReturnValue().Set(obj);
}

NAN_METHOD(getColor)
{
MMBitmapRef bitmap;
MMRGBHex color;

size_t x = info[0]->Int32Value();
size_t y = info[1]->Int32Value();

//Get our image object from JavaScript.
Local<Object> obj = Nan::To<v8::Object>(info[0]).ToLocalChecked();

unsigned int width = obj->Get(Nan::New("width").ToLocalChecked())->Uint32Value();
unsigned int height = obj->Get(Nan::New("height").ToLocalChecked())->Uint32Value();
unsigned int byteWidth = obj->Get(Nan::New("byteWidth").ToLocalChecked())->Uint32Value();
unsigned int bitsPerPixel = obj->Get(Nan::New("bitsPerPixel").ToLocalChecked())->Uint32Value();
unsigned int bytesPerPixel = obj->Get(Nan::New("bytesPerPixel").ToLocalChecked())->Uint32Value();

char* buf = node::Buffer::Data(obj->Get(Nan::New("image").ToLocalChecked()));

bitmap = createMMBitmap((uint8_t *)buf, width, height, byteWidth, bitsPerPixel, bytesPerPixel);

color = MMRGBHexAtPoint(bitmap, 300, 300);

char hex [7];

snprintf(hex, 7, "%06x", color);

printf("2: %s\n", hex);

//FIXME: Currently causes an error.
//destroyMMBitmap(bitmap);

info.GetReturnValue().Set(Nan::New(hex).ToLocalChecked());

}

NAN_MODULE_INIT(InitAll)
{

Expand Down Expand Up @@ -659,6 +695,9 @@ NAN_MODULE_INIT(InitAll)

Nan::Set(target, Nan::New("captureScreen").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(captureScreen)).ToLocalChecked());

Nan::Set(target, Nan::New("getColor").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(getColor)).ToLocalChecked());
}

NODE_MODULE(robotjs, InitAll)

0 comments on commit df737d1

Please sign in to comment.