mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 14:43:55 +00:00
add more color processing and conversion
This commit is contained in:
parent
bb7518a04a
commit
4f85eb5056
41
robotgo.go
41
robotgo.go
@ -62,7 +62,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version string = "v0.47.0.460, Mount Cook!"
|
version string = "v0.47.0.461, Mount Cook!"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -114,6 +114,40 @@ func Try(fun func(), handler func(interface{})) {
|
|||||||
|_______/ \______|| _| `._____||_______||_______||__| \__|
|
|_______/ \______|| _| `._____||_______||_______||__| \__|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// ToMMRGBHex trans CHex to C.MMRGBHex
|
||||||
|
func ToMMRGBHex(hex CHex) C.MMRGBHex {
|
||||||
|
return C.MMRGBHex(hex)
|
||||||
|
}
|
||||||
|
|
||||||
|
// U32ToHex trans C.uint32_t to C.MMRGBHex
|
||||||
|
func U32ToHex(hex C.uint32_t) C.MMRGBHex {
|
||||||
|
return C.MMRGBHex(hex)
|
||||||
|
}
|
||||||
|
|
||||||
|
// U8ToHex teans *C.uint8_t to C.MMRGBHex
|
||||||
|
func U8ToHex(hex *C.uint8_t) C.MMRGBHex {
|
||||||
|
return C.MMRGBHex(*hex)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PadHex trans C.MMRGBHex to string
|
||||||
|
func PadHex(hex C.MMRGBHex) string {
|
||||||
|
color := C.pad_hex(hex)
|
||||||
|
gcolor := C.GoString(color)
|
||||||
|
defer C.free(unsafe.Pointer(color))
|
||||||
|
|
||||||
|
return gcolor
|
||||||
|
}
|
||||||
|
|
||||||
|
// HexToRgb trans hex to rgb
|
||||||
|
func HexToRgb(hex uint32) *C.uint8_t {
|
||||||
|
return C.color_hex_to_rgb(C.uint32_t(hex))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RgbToHex trans rgb to hex
|
||||||
|
func RgbToHex(r, g, b uint8) C.uint32_t {
|
||||||
|
return C.color_rgb_to_hex(C.uint8_t(r), C.uint8_t(g), C.uint8_t(b))
|
||||||
|
}
|
||||||
|
|
||||||
// GetPxColor get pixel color return C.MMRGBHex
|
// GetPxColor get pixel color return C.MMRGBHex
|
||||||
func GetPxColor(x, y int) C.MMRGBHex {
|
func GetPxColor(x, y int) C.MMRGBHex {
|
||||||
cx := C.size_t(x)
|
cx := C.size_t(x)
|
||||||
@ -123,11 +157,6 @@ func GetPxColor(x, y int) C.MMRGBHex {
|
|||||||
return color
|
return color
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToMMRGBHex trans CHex to C.MMRGBhex
|
|
||||||
func ToMMRGBHex(hex CHex) C.MMRGBHex {
|
|
||||||
return C.MMRGBHex(hex)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPixelColor get pixel color return string
|
// GetPixelColor get pixel color return string
|
||||||
func GetPixelColor(x, y int) string {
|
func GetPixelColor(x, y int) string {
|
||||||
cx := C.size_t(x)
|
cx := C.size_t(x)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#include "../base/types.h"
|
#include "../base/types.h"
|
||||||
|
#include "../base/rgb.h"
|
||||||
#include "screengrab_c.h"
|
#include "screengrab_c.h"
|
||||||
#include "screen_c.h"
|
#include "screen_c.h"
|
||||||
// #include "../MMBitmap_c.h"
|
// #include "../MMBitmap_c.h"
|
||||||
@ -19,6 +20,31 @@ void padHex(MMRGBHex color, char* hex){
|
|||||||
snprintf(hex, 7, "%06x", color);
|
snprintf(hex, 7, "%06x", color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* pad_hex(MMRGBHex color){
|
||||||
|
char hex[7];
|
||||||
|
padHex(color, hex);
|
||||||
|
|
||||||
|
// destroyMMBitmap(bitmap);
|
||||||
|
|
||||||
|
char* str = (char*)calloc(100, sizeof(char*));
|
||||||
|
if(str)strcpy(str, hex);
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t rgb[3];
|
||||||
|
|
||||||
|
uint8_t *color_hex_to_rgb(uint32_t h){
|
||||||
|
rgb[0] = RED_FROM_HEX(h);
|
||||||
|
rgb[1] = GREEN_FROM_HEX(h);
|
||||||
|
rgb[2] = BLUE_FROM_HEX(h);
|
||||||
|
return rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t color_rgb_to_hex(uint8_t r, uint8_t g, uint8_t b){
|
||||||
|
return RGB_TO_HEX(r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
MMRGBHex get_Pixel_Color(size_t x, size_t y){
|
MMRGBHex get_Pixel_Color(size_t x, size_t y){
|
||||||
MMBitmapRef bitmap;
|
MMBitmapRef bitmap;
|
||||||
MMRGBHex color;
|
MMRGBHex color;
|
||||||
@ -97,8 +123,7 @@ MMBitmapRef capture_screen(size_t x, size_t y, size_t w, size_t h){
|
|||||||
// if (){
|
// if (){
|
||||||
// x = 0;
|
// x = 0;
|
||||||
// y = 0;
|
// y = 0;
|
||||||
|
// // Get screen size.
|
||||||
// //Get screen size.
|
|
||||||
// MMSize displaySize = getMainDisplaySize();
|
// MMSize displaySize = getMainDisplaySize();
|
||||||
// w = displaySize.width;
|
// w = displaySize.width;
|
||||||
// h = displaySize.height;
|
// h = displaySize.height;
|
||||||
|
Loading…
Reference in New Issue
Block a user