From 94122476faac6c31d676c68b01b54461f1699291 Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Sat, 10 May 2025 11:10:30 +0800 Subject: [PATCH] =?UTF-8?q?6.6.3=20-=20Alpha3=20-=20=E6=96=B0=E5=A2=9E=20i?= =?UTF-8?q?mages.detectMultiColors=20=E6=96=B9=E6=B3=95=20(issue=20#374)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changelog/lang_zh-Hans.json | 3 ++- .../autojs/autojs/core/image/ColorFinder.java | 16 ++++++++---- .../autojs/core/image/RhinoColorFinder.java | 4 +-- .../runtime/api/augment/images/Images.kt | 25 +++++++++++++++---- .../autojs/ui/project/BuildActivity.java | 1 + version.properties | 6 ++--- 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json index 13a6bf16..329f433a 100644 --- a/.changelog/lang_zh-Hans.json +++ b/.changelog/lang_zh-Hans.json @@ -5,7 +5,8 @@ "feature": [ "版本历史功能, 可查看发行版本历史更新记录 (多语言) 与统计数据", "timers.keepAlive 方法 (已全局化), 用于保持脚本活跃状态", - "engines.on('start/stop/error', callback) 等事件监听方法, 用于监听脚本引擎全局事件" + "engines.on('start/stop/error', callback) 等事件监听方法, 用于监听脚本引擎全局事件", + "images.detectMultiColors 方法, 用于多点颜色校验 _[`issue #374`](http://issues.autojs6.com/374)_" ], "fix": [ "主页文档标签显示在线文档时部分内容被系统导航栏遮挡的问题", diff --git a/app/src/main/java/org/autojs/autojs/core/image/ColorFinder.java b/app/src/main/java/org/autojs/autojs/core/image/ColorFinder.java index 6f9cc66b..f28ff53f 100644 --- a/app/src/main/java/org/autojs/autojs/core/image/ColorFinder.java +++ b/app/src/main/java/org/autojs/autojs/core/image/ColorFinder.java @@ -135,7 +135,6 @@ public class ColorFinder { @Deprecated @ScriptInterface - @SuppressWarnings("deprecation") @CodeAuthor(name = "LYS86", homepage = "https://github.com/LYS86") public Point[] findAllMultiColors(ImageWrapper image, int firstColor, int threshold, Rect rect, int[] points) { Point[] firstPoints = findAllPointsForColor(image, firstColor, threshold, rect); @@ -151,14 +150,23 @@ public class ColorFinder { return resultPoints.toArray(new Point[0]); } + public boolean detectMultiColors(ImageWrapper image, int x, int y, int firstColor, int threshold, Rect region, int[] points) { + int pixel = image.pixel(x, y); + ColorDetector colorDetector = new ColorDetector.DifferenceDetector(firstColor, threshold); + if (!colorDetector.detectColor(Color.red(pixel), Color.green(pixel), Color.blue(pixel))) { + return false; + } + return checksPath(image, new Point(x, y), threshold, points); + } + private boolean checksPath(ImageWrapper image, Point startingPoint, int threshold, int[] points) { for (int i = 0; i < points.length; i += 3) { int x = points[i]; int y = points[i + 1]; int color = points[i + 2]; ColorDetector colorDetector = new ColorDetector.DifferenceDetector(color, threshold); - x += startingPoint.x; - y += startingPoint.y; + x += (int) startingPoint.x; + y += (int) startingPoint.y; if (x >= image.getWidth() || y >= image.getHeight() || x < 0 || y < 0) { return false; } @@ -173,7 +181,6 @@ public class ColorFinder { @Nullable @Deprecated @ScriptInterface - @SuppressWarnings("deprecation") public Point findColorEquals(ImageWrapper imageWrapper, int color) { return findColorEquals(imageWrapper, color, null); } @@ -181,7 +188,6 @@ public class ColorFinder { @Nullable @Deprecated @ScriptInterface - @SuppressWarnings("deprecation") public Point findColorEquals(ImageWrapper imageWrapper, int color, Rect region) { return findColor(imageWrapper, color, 0, region); } diff --git a/app/src/main/java/org/autojs/autojs/core/image/RhinoColorFinder.java b/app/src/main/java/org/autojs/autojs/core/image/RhinoColorFinder.java index 91915276..264d2d51 100644 --- a/app/src/main/java/org/autojs/autojs/core/image/RhinoColorFinder.java +++ b/app/src/main/java/org/autojs/autojs/core/image/RhinoColorFinder.java @@ -40,8 +40,8 @@ public class RhinoColorFinder extends ColorFinder { return new Rect(x, y, width, height); } throw new IllegalArgumentException("out of region: " + - "region = [" + Arrays.toString(new Integer[]{x, y, width, height}) + "], " + - "image.size = [" + imageWrapper.getWidth() + ", " + imageWrapper.getHeight() + ']'); + "region = [" + Arrays.toString(new Integer[]{x, y, width, height}) + "], " + + "image.size = [" + imageWrapper.getWidth() + ", " + imageWrapper.getHeight() + ']'); } private Object getOrNull(NativeArray nativeArray, int index) { diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/images/Images.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/images/Images.kt index 6e965104..ddf2bcf9 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/images/Images.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/images/Images.kt @@ -613,7 +613,7 @@ class Images(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime), AsEmitt initOpenCvIfNeeded() scriptRuntime.images.flip(image, horizontal, vertical) } - + private fun parseFlipOrientations(o: Any?): Pair = when { o.isJsNullish() -> false to false o is Boolean -> o to false @@ -677,13 +677,28 @@ class Images(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime), AsEmitt detectColor(scriptRuntime, it) } - // @Reference to module __images__.js from Auto.js Pro 9.3.11 by SuperMonster003 on Dec 19. 2023. + // @Reference to module __images__.js from Auto.js Pro 9.3.11 by SuperMonster003 on May 10. 2025. @JvmStatic @RhinoRuntimeFunctionInterface fun detectMultiColors(scriptRuntime: ScriptRuntime, args: Array): Boolean = ensureArgumentsLengthInRange(args, 5..6) { - - TODO("detectMultiColors 尚未实现") - + val (o, x, y, firstColor, paths, options) = it + val image = if (o is String) read(scriptRuntime, arrayOf(o, true)) else o + require(image is ImageWrapper) { "Argument image for images.detectMultiColors must be a ImageWrapper" } + require(paths is NativeArray) { "Argument paths for images.detectMultiColors must be a JavaScript Array" } + initOpenCvIfNeeded() + val opt = options as? NativeObject ?: newNativeObject() + scriptRuntime.images.colorFinder.detectMultiColors( + image, + coerceIntNumber(x), + coerceIntNumber(y), + Colors.toIntRhino(firstColor), + parseThreshold(opt).roundToInt(), + opt.inquire("region") { region -> buildRegionInternal(image, region) }, + paths.flatMap { path -> + val (px, py, color) = path as NativeArray + listOf(coerceIntNumber(px), coerceIntNumber(py), Colors.toIntRhino(color)) + }.toIntArray(), + ) } @Deprecated("Deprecated in Java", ReplaceWith("detectMultiColors(image, x, y, firstColor, paths, options)")) diff --git a/app/src/main/java/org/autojs/autojs/ui/project/BuildActivity.java b/app/src/main/java/org/autojs/autojs/ui/project/BuildActivity.java index e5252fe4..66d5a12b 100644 --- a/app/src/main/java/org/autojs/autojs/ui/project/BuildActivity.java +++ b/app/src/main/java/org/autojs/autojs/ui/project/BuildActivity.java @@ -539,6 +539,7 @@ public class BuildActivity extends BaseActivity implements ApkBuilder.ProgressCa checkBox.setAlpha(0.87f); checkBox.setText(permission + "\n" + getString(descriptionResId)); checkBox.setButtonDrawable(R.drawable.round_checkbox); + checkBox.setBackground(null); checkBox.setGravity(Gravity.CENTER_VERTICAL); checkBox.setTextSize(12); int marginInPixels = (int) (8 * getResources().getDisplayMetrics().density); diff --git a/version.properties b/version.properties index 87abc8ef..f6ae261e 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ -#Fri May 09 18:20:25 CST 2025 -BUILD_TIME=1746786025154 +#Sat May 10 10:59:26 CST 2025 +BUILD_TIME=1746845966689 COMPILE_SDK_VERSION=35 JAVA_VERSION=23 JAVA_VERSION_MIN_RADICAL=0 @@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13 RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 TARGET_SDK_VERSION=35 TARGET_SDK_VERSION_INRT=29 -VERSION_BUILD=3212 +VERSION_BUILD=3213 VERSION_NAME=6.6.3 Alpha3 VSCODE_EXT_REQUIRED_VERSION=1.0.8