From 18e81f71ba1179d329f1e5896244cbc93fbb48f7 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sun, 25 Aug 2024 17:57:22 +0900 Subject: [PATCH] Use backward search in the screen time --- WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs | 15 ++++++++++++--- settings.example.ini | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs b/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs index 7cb265b..ea2c98f 100644 --- a/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs +++ b/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs @@ -296,15 +296,24 @@ public class ScreenMatch Point bestMatch = Point.Empty; maxCorrelation = 0; - for (int x = 0; x <= mainWidth - templateWidth; x++) + bool searchFromEnd = _params.Contains("backward"); + + int startX = searchFromEnd ? mainWidth - templateWidth : 0; + int endX = searchFromEnd ? -1 : mainWidth - templateWidth + 1; + int stepX = searchFromEnd ? -1 : 1; + + int startY = searchFromEnd ? mainHeight - templateHeight : 0; + int endY = searchFromEnd ? -1 : mainHeight - templateHeight + 1; + int stepY = searchFromEnd ? -1 : 1; + + for (int x = startX; x != endX; x += stepX) { - for (int y = 0; y <= mainHeight - templateHeight; y++) + for (int y = startY; y != endY; y += stepY) { if (IsTemplateMatch(mainImage, templateImage, x, y, threshold)) { bestMatch = new Point(x, y); maxCorrelation = 1.0; - return bestMatch; } } diff --git a/settings.example.ini b/settings.example.ini index 336e298..3c49ba7 100644 --- a/settings.example.ini +++ b/settings.example.ini @@ -11,9 +11,9 @@ NONFREE_STRICT=false DISABLE_SCREEN_TIME=false DISABLE_FILE_MONITOR=false ; screen or window -SCREEN_TIME_MODE=screen +SCREEN_TIME_MODE=screen ;filename.exe -SCREEN_TIME_PARAMS= +SCREEN_TIME_PARAMS=backward GRPC_HOST=http://localhost:50051 ES_HOST=http://localhost:9200 ES_USER=elastic