Add find some color

This commit is contained in:
vcaesar 2017-09-14 23:02:43 +08:00
parent 6d2317ee69
commit ea0b910646
2 changed files with 29 additions and 1 deletions

View File

@ -158,3 +158,14 @@ MMRGBHex bitmap_get_color(MMBitmapRef bitmap, size_t x, size_t y){
return MMRGBHexAtPoint(bitmap, point.x, point.y);
}
MMPoint bitmap_find_color(MMBitmapRef bitmap, MMRGBHex color, float tolerance){
MMRect rect = MMBitmapGetBounds(bitmap);
MMPoint point = {-1, -1};
if (findColorInRect(bitmap, color, &point, rect, tolerance) == 0) {
return point;
}
return point;
}

View File

@ -55,7 +55,7 @@ import (
)
const (
version string = "v0.46.0.382, Pyrenees Mountains!"
version string = "v0.46.0.385, Pyrenees Mountains!"
)
// GetVersion get version
@ -736,6 +736,23 @@ func GetColor(bitmap C.MMBitmapRef, x, y int) C.MMRGBHex {
return color
}
// FindColor find bitmap color
func FindColor(bitmap C.MMBitmapRef, color C.MMRGBHex, args ...float32) (int, int) {
var tolerance C.float
if len(args) > 2 {
tolerance = C.float(args[2])
} else {
tolerance = 0.5
}
pos := C.bitmap_find_color(bitmap, color, tolerance)
x := int(pos.x)
y := int(pos.y)
return x, y
}
/*
___________ ____ _______ .__ __. .___________.
| ____\ \ / / | ____|| \ | | | |