Skip to content

Commit df737d1

Browse files
committed
Started getColor function.
1 parent 5dc3557 commit df737d1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/robotjs.cc

+39
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,42 @@ NAN_METHOD(captureScreen)
615615
info.GetReturnValue().Set(obj);
616616
}
617617

618+
NAN_METHOD(getColor)
619+
{
620+
MMBitmapRef bitmap;
621+
MMRGBHex color;
622+
623+
size_t x = info[0]->Int32Value();
624+
size_t y = info[1]->Int32Value();
625+
626+
//Get our image object from JavaScript.
627+
Local<Object> obj = Nan::To<v8::Object>(info[0]).ToLocalChecked();
628+
629+
unsigned int width = obj->Get(Nan::New("width").ToLocalChecked())->Uint32Value();
630+
unsigned int height = obj->Get(Nan::New("height").ToLocalChecked())->Uint32Value();
631+
unsigned int byteWidth = obj->Get(Nan::New("byteWidth").ToLocalChecked())->Uint32Value();
632+
unsigned int bitsPerPixel = obj->Get(Nan::New("bitsPerPixel").ToLocalChecked())->Uint32Value();
633+
unsigned int bytesPerPixel = obj->Get(Nan::New("bytesPerPixel").ToLocalChecked())->Uint32Value();
634+
635+
char* buf = node::Buffer::Data(obj->Get(Nan::New("image").ToLocalChecked()));
636+
637+
bitmap = createMMBitmap((uint8_t *)buf, width, height, byteWidth, bitsPerPixel, bytesPerPixel);
638+
639+
color = MMRGBHexAtPoint(bitmap, 300, 300);
640+
641+
char hex [7];
642+
643+
snprintf(hex, 7, "%06x", color);
644+
645+
printf("2: %s\n", hex);
646+
647+
//FIXME: Currently causes an error.
648+
//destroyMMBitmap(bitmap);
649+
650+
info.GetReturnValue().Set(Nan::New(hex).ToLocalChecked());
651+
652+
}
653+
618654
NAN_MODULE_INIT(InitAll)
619655
{
620656

@@ -659,6 +695,9 @@ NAN_MODULE_INIT(InitAll)
659695

660696
Nan::Set(target, Nan::New("captureScreen").ToLocalChecked(),
661697
Nan::GetFunction(Nan::New<FunctionTemplate>(captureScreen)).ToLocalChecked());
698+
699+
Nan::Set(target, Nan::New("getColor").ToLocalChecked(),
700+
Nan::GetFunction(Nan::New<FunctionTemplate>(getColor)).ToLocalChecked());
662701
}
663702

664703
NODE_MODULE(robotjs, InitAll)

0 commit comments

Comments
 (0)