@@ -615,6 +615,42 @@ NAN_METHOD(captureScreen)
615
615
info.GetReturnValue ().Set (obj);
616
616
}
617
617
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
+
618
654
NAN_MODULE_INIT (InitAll)
619
655
{
620
656
@@ -659,6 +695,9 @@ NAN_MODULE_INIT(InitAll)
659
695
660
696
Nan::Set (target, Nan::New (" captureScreen" ).ToLocalChecked (),
661
697
Nan::GetFunction (Nan::New<FunctionTemplate>(captureScreen)).ToLocalChecked ());
698
+
699
+ Nan::Set (target, Nan::New (" getColor" ).ToLocalChecked (),
700
+ Nan::GetFunction (Nan::New<FunctionTemplate>(getColor)).ToLocalChecked ());
662
701
}
663
702
664
703
NODE_MODULE (robotjs, InitAll)
0 commit comments