add count bitmap color func

This commit is contained in:
vcaesar 2018-01-02 21:31:33 +08:00
parent 6434928f2d
commit 97f54f7f3d
2 changed files with 39 additions and 1 deletions

View File

@ -215,3 +215,10 @@ MMPoint bitmap_find_color(MMBitmapRef bitmap, MMRGBHex color, float tolerance){
return point;
}
int bitmap_count_of_color(MMBitmapRef bitmap, MMRGBHex color, float tolerance){
if (!bitmap_ready(bitmap)) return 0;
MMRect rect = MMBitmapGetBounds(bitmap);
return countOfColorsInRect(bitmap, color, rect, tolerance);
}

View File

@ -62,7 +62,7 @@ import (
)
const (
version string = "v0.47.0.471, Mount Cook!"
version string = "v0.47.0.472, Mount Cook!"
)
type (
@ -997,6 +997,37 @@ func FindColorCS(x, y, w, h int, color CHex, args ...float32) (int, int) {
return rx, ry
}
// CountColor count bitmap color
func CountColor(bitmap C.MMBitmapRef, color CHex, args ...float32) int {
var tolerance C.float
if len(args) > 0 {
tolerance = C.float(args[0])
} else {
tolerance = 0.5
}
count := C.bitmap_count_of_color(bitmap, C.MMRGBHex(color), tolerance)
return int(count)
}
// CountColorCS count bitmap color by CaptureScreen
func CountColorCS(x, y, w, h int, color CHex, args ...float32) int {
var tolerance float32
if len(args) > 0 {
tolerance = args[0]
} else {
tolerance = 0.5
}
bitmap := CaptureScreen(x, y, w, h)
rx := CountColor(bitmap, color, tolerance)
return rx
}
/*
___________ ____ _______ .__ __. .___________.
| ____\ \ / / | ____|| \ | | | |