mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-07 17:13:57 +00:00
add free and find all point function
This commit is contained in:
parent
5c45871af7
commit
488a81253f
@ -67,24 +67,19 @@ MMPoint find_bitmap(MMBitmapRef bitmap, MMBitmapRef sbit, float tolerance){
|
|||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
MMPoint *find_every_bitmap(MMBitmapRef bitmap, MMBitmapRef sbit, float tolerance, MMPoint *list){
|
MMPointArrayRef find_every_bitmap(MMBitmapRef bitmap, MMBitmapRef sbit, float tolerance, MMPoint *list){
|
||||||
if (!bitmap_ready(bitmap) || !bitmap_ready(sbit)) { return NULL; }
|
if (!bitmap_ready(bitmap) || !bitmap_ready(sbit)) { return NULL; }
|
||||||
|
|
||||||
MMPoint point;
|
MMPoint point;
|
||||||
MMPointArrayRef pointArray;
|
MMPointArrayRef pointArray;
|
||||||
MMRect rect = MMBitmapGetBounds(bitmap);
|
MMRect rect = MMBitmapGetBounds(sbit);
|
||||||
|
|
||||||
if (findBitmapInRect(bitmap, sbit, &point, rect, tolerance) == 0) {
|
if (findBitmapInRect(bitmap, sbit, &point, rect, tolerance) == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pointArray = findAllBitmapInRect(bitmap, sbit, rect, tolerance);
|
pointArray = findAllBitmapInRect(bitmap, sbit, rect, tolerance);
|
||||||
if (pointArray == NULL) { return NULL; }
|
return pointArray;
|
||||||
|
|
||||||
memcpy(list, pointArray->array, sizeof(MMPoint) * pointArray->count);
|
|
||||||
destroyMMPointArray(pointArray);
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int count_of_bitmap(MMBitmapRef bitmap, MMBitmapRef sbit, float tolerance){
|
int count_of_bitmap(MMBitmapRef bitmap, MMBitmapRef sbit, float tolerance){
|
||||||
@ -192,19 +187,13 @@ MMPoint bitmap_find_color(MMBitmapRef bitmap, MMRGBHex color, float tolerance){
|
|||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
MMPoint *bitmap_find_every_color(MMBitmapRef bitmap, MMRGBHex color, float tolerance, MMPoint *list){
|
MMPointArrayRef bitmap_find_every_color(MMBitmapRef bitmap, MMRGBHex color, float tolerance, MMPoint *list){
|
||||||
if (!bitmap_ready(bitmap)) { return NULL; }
|
if (!bitmap_ready(bitmap)) { return NULL; }
|
||||||
MMRect rect = MMBitmapGetBounds(bitmap);
|
MMRect rect = MMBitmapGetBounds(bitmap);
|
||||||
MMPointArrayRef pointArray;
|
MMPointArrayRef pointArray;
|
||||||
|
|
||||||
pointArray = findAllColorInRect(bitmap, color, rect, tolerance);
|
pointArray = findAllColorInRect(bitmap, color, rect, tolerance);
|
||||||
if (pointArray == NULL) { return NULL; }
|
return pointArray;
|
||||||
|
|
||||||
memcpy(list, pointArray->array, sizeof(MMPoint) * pointArray->count);
|
|
||||||
destroyMMPointArray(pointArray);
|
|
||||||
if (list == NULL) { return NULL; }
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int bitmap_count_of_color(MMBitmapRef bitmap, MMRGBHex color, float tolerance){
|
int bitmap_count_of_color(MMBitmapRef bitmap, MMRGBHex color, float tolerance){
|
||||||
|
35
robotgo.go
35
robotgo.go
@ -1017,8 +1017,13 @@ func FindPic(path string, args ...interface{}) (int, int) {
|
|||||||
return fx, fy
|
return fx, fy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FreeMMPointArr free MMPoint array
|
||||||
|
func FreeMMPointArr(pointArray C.MMPointArrayRef) {
|
||||||
|
C.destroyMMPointArray(pointArray)
|
||||||
|
}
|
||||||
|
|
||||||
// FindEveryBitmap find the every bitmap
|
// FindEveryBitmap find the every bitmap
|
||||||
func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int) {
|
func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) (posArr []MPoint) {
|
||||||
var (
|
var (
|
||||||
sbit C.MMBitmapRef
|
sbit C.MMBitmapRef
|
||||||
tolerance C.float = 0.01
|
tolerance C.float = 0.01
|
||||||
@ -1050,12 +1055,23 @@ func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int) {
|
|||||||
|
|
||||||
pos := C.find_every_bitmap(bit, sbit, tolerance, &lpos)
|
pos := C.find_every_bitmap(bit, sbit, tolerance, &lpos)
|
||||||
// FreeBitmap(bit)
|
// FreeBitmap(bit)
|
||||||
|
defer FreeMMPointArr(pos)
|
||||||
if len(args) <= 0 {
|
if len(args) <= 0 {
|
||||||
FreeBitmap(sbit)
|
FreeBitmap(sbit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cSize := pos.count
|
||||||
|
cArray := pos.array
|
||||||
|
gSlice := (*[1 << 30]C.MMPoint)(unsafe.Pointer(cArray))[:cSize:cSize]
|
||||||
|
for i := 0; i < len(gSlice); i++ {
|
||||||
|
posArr = append(posArr, MPoint{
|
||||||
|
x: int(gSlice[i].x),
|
||||||
|
y: int(gSlice[i].y),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// fmt.Println("pos----", pos)
|
// fmt.Println("pos----", pos)
|
||||||
return int(pos.x), int(pos.y)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountBitmap count of the bitmap
|
// CountBitmap count of the bitmap
|
||||||
@ -1299,7 +1315,7 @@ func FindColorCS(color CHex, x, y, w, h int, args ...float64) (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FindEveryColor find every color
|
// FindEveryColor find every color
|
||||||
func FindEveryColor(color CHex, args ...interface{}) (int, int) {
|
func FindEveryColor(color CHex, args ...interface{}) (posArr []MPoint) {
|
||||||
var (
|
var (
|
||||||
bitmap C.MMBitmapRef
|
bitmap C.MMBitmapRef
|
||||||
tolerance C.float = 0.01
|
tolerance C.float = 0.01
|
||||||
@ -1330,11 +1346,22 @@ func FindEveryColor(color CHex, args ...interface{}) (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pos := C.bitmap_find_every_color(bitmap, C.MMRGBHex(color), tolerance, &lpos)
|
pos := C.bitmap_find_every_color(bitmap, C.MMRGBHex(color), tolerance, &lpos)
|
||||||
|
defer FreeMMPointArr(pos)
|
||||||
if len(args) <= 0 {
|
if len(args) <= 0 {
|
||||||
FreeBitmap(bitmap)
|
FreeBitmap(bitmap)
|
||||||
}
|
}
|
||||||
|
|
||||||
return int(pos.x), int(pos.y)
|
cSize := pos.count
|
||||||
|
cArray := pos.array
|
||||||
|
gSlice := (*[1 << 30]C.MMPoint)(unsafe.Pointer(cArray))[:cSize:cSize]
|
||||||
|
for i := 0; i < len(gSlice); i++ {
|
||||||
|
posArr = append(posArr, MPoint{
|
||||||
|
x: int(gSlice[i].x),
|
||||||
|
y: int(gSlice[i].y),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountColor count bitmap color
|
// CountColor count bitmap color
|
||||||
|
Loading…
Reference in New Issue
Block a user