diff --git a/bitmap/goBitmap.h b/bitmap/goBitmap.h index 98efc3c..432a66e 100644 --- a/bitmap/goBitmap.h +++ b/bitmap/goBitmap.h @@ -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); +} diff --git a/robotgo.go b/robotgo.go index 01be98f..c023081 100644 --- a/robotgo.go +++ b/robotgo.go @@ -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 +} + /* ___________ ____ _______ .__ __. .___________. | ____\ \ / / | ____|| \ | | | |