6.6.3 - Alpha3 - 新增 images.detectMultiColors 方法 (issue #374)

This commit is contained in:
SuperMonster003
2025-05-10 11:10:30 +08:00
parent c2b98af9d5
commit 94122476fa
6 changed files with 39 additions and 16 deletions

View File

@@ -5,7 +5,8 @@
"feature": [ "feature": [
"版本历史功能, 可查看发行版本历史更新记录 (多语言) 与统计数据", "版本历史功能, 可查看发行版本历史更新记录 (多语言) 与统计数据",
"timers.keepAlive 方法 (已全局化), 用于保持脚本活跃状态", "timers.keepAlive 方法 (已全局化), 用于保持脚本活跃状态",
"engines.on('start/stop/error', callback) 等事件监听方法, 用于监听脚本引擎全局事件" "engines.on('start/stop/error', callback) 等事件监听方法, 用于监听脚本引擎全局事件",
"images.detectMultiColors 方法, 用于多点颜色校验 _[`issue #374`](http://issues.autojs6.com/374)_"
], ],
"fix": [ "fix": [
"主页文档标签显示在线文档时部分内容被系统导航栏遮挡的问题", "主页文档标签显示在线文档时部分内容被系统导航栏遮挡的问题",

View File

@@ -135,7 +135,6 @@ public class ColorFinder {
@Deprecated @Deprecated
@ScriptInterface @ScriptInterface
@SuppressWarnings("deprecation")
@CodeAuthor(name = "LYS86", homepage = "https://github.com/LYS86") @CodeAuthor(name = "LYS86", homepage = "https://github.com/LYS86")
public Point[] findAllMultiColors(ImageWrapper image, int firstColor, int threshold, Rect rect, int[] points) { public Point[] findAllMultiColors(ImageWrapper image, int firstColor, int threshold, Rect rect, int[] points) {
Point[] firstPoints = findAllPointsForColor(image, firstColor, threshold, rect); Point[] firstPoints = findAllPointsForColor(image, firstColor, threshold, rect);
@@ -151,14 +150,23 @@ public class ColorFinder {
return resultPoints.toArray(new Point[0]); 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) { private boolean checksPath(ImageWrapper image, Point startingPoint, int threshold, int[] points) {
for (int i = 0; i < points.length; i += 3) { for (int i = 0; i < points.length; i += 3) {
int x = points[i]; int x = points[i];
int y = points[i + 1]; int y = points[i + 1];
int color = points[i + 2]; int color = points[i + 2];
ColorDetector colorDetector = new ColorDetector.DifferenceDetector(color, threshold); ColorDetector colorDetector = new ColorDetector.DifferenceDetector(color, threshold);
x += startingPoint.x; x += (int) startingPoint.x;
y += startingPoint.y; y += (int) startingPoint.y;
if (x >= image.getWidth() || y >= image.getHeight() || x < 0 || y < 0) { if (x >= image.getWidth() || y >= image.getHeight() || x < 0 || y < 0) {
return false; return false;
} }
@@ -173,7 +181,6 @@ public class ColorFinder {
@Nullable @Nullable
@Deprecated @Deprecated
@ScriptInterface @ScriptInterface
@SuppressWarnings("deprecation")
public Point findColorEquals(ImageWrapper imageWrapper, int color) { public Point findColorEquals(ImageWrapper imageWrapper, int color) {
return findColorEquals(imageWrapper, color, null); return findColorEquals(imageWrapper, color, null);
} }
@@ -181,7 +188,6 @@ public class ColorFinder {
@Nullable @Nullable
@Deprecated @Deprecated
@ScriptInterface @ScriptInterface
@SuppressWarnings("deprecation")
public Point findColorEquals(ImageWrapper imageWrapper, int color, Rect region) { public Point findColorEquals(ImageWrapper imageWrapper, int color, Rect region) {
return findColor(imageWrapper, color, 0, region); return findColor(imageWrapper, color, 0, region);
} }

View File

@@ -40,8 +40,8 @@ public class RhinoColorFinder extends ColorFinder {
return new Rect(x, y, width, height); return new Rect(x, y, width, height);
} }
throw new IllegalArgumentException("out of region: " + throw new IllegalArgumentException("out of region: " +
"region = [" + Arrays.toString(new Integer[]{x, y, width, height}) + "], " + "region = [" + Arrays.toString(new Integer[]{x, y, width, height}) + "], " +
"image.size = [" + imageWrapper.getWidth() + ", " + imageWrapper.getHeight() + ']'); "image.size = [" + imageWrapper.getWidth() + ", " + imageWrapper.getHeight() + ']');
} }
private Object getOrNull(NativeArray nativeArray, int index) { private Object getOrNull(NativeArray nativeArray, int index) {

View File

@@ -613,7 +613,7 @@ class Images(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime), AsEmitt
initOpenCvIfNeeded() initOpenCvIfNeeded()
scriptRuntime.images.flip(image, horizontal, vertical) scriptRuntime.images.flip(image, horizontal, vertical)
} }
private fun parseFlipOrientations(o: Any?): Pair<Boolean, Boolean> = when { private fun parseFlipOrientations(o: Any?): Pair<Boolean, Boolean> = when {
o.isJsNullish() -> false to false o.isJsNullish() -> false to false
o is Boolean -> o to false o is Boolean -> o to false
@@ -677,13 +677,28 @@ class Images(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime), AsEmitt
detectColor(scriptRuntime, it) 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 @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface
fun detectMultiColors(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Boolean = ensureArgumentsLengthInRange(args, 5..6) { fun detectMultiColors(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Boolean = ensureArgumentsLengthInRange(args, 5..6) {
val (o, x, y, firstColor, paths, options) = it
TODO("detectMultiColors 尚未实现") val image = if (o is String) read(scriptRuntime, arrayOf<Any>(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)")) @Deprecated("Deprecated in Java", ReplaceWith("detectMultiColors(image, x, y, firstColor, paths, options)"))

View File

@@ -539,6 +539,7 @@ public class BuildActivity extends BaseActivity implements ApkBuilder.ProgressCa
checkBox.setAlpha(0.87f); checkBox.setAlpha(0.87f);
checkBox.setText(permission + "\n" + getString(descriptionResId)); checkBox.setText(permission + "\n" + getString(descriptionResId));
checkBox.setButtonDrawable(R.drawable.round_checkbox); checkBox.setButtonDrawable(R.drawable.round_checkbox);
checkBox.setBackground(null);
checkBox.setGravity(Gravity.CENTER_VERTICAL); checkBox.setGravity(Gravity.CENTER_VERTICAL);
checkBox.setTextSize(12); checkBox.setTextSize(12);
int marginInPixels = (int) (8 * getResources().getDisplayMetrics().density); int marginInPixels = (int) (8 * getResources().getDisplayMetrics().density);

View File

@@ -1,5 +1,5 @@
#Fri May 09 18:20:25 CST 2025 #Sat May 10 10:59:26 CST 2025
BUILD_TIME=1746786025154 BUILD_TIME=1746845966689
COMPILE_SDK_VERSION=35 COMPILE_SDK_VERSION=35
JAVA_VERSION=23 JAVA_VERSION=23
JAVA_VERSION_MIN_RADICAL=0 JAVA_VERSION_MIN_RADICAL=0
@@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
TARGET_SDK_VERSION=35 TARGET_SDK_VERSION=35
TARGET_SDK_VERSION_INRT=29 TARGET_SDK_VERSION_INRT=29
VERSION_BUILD=3212 VERSION_BUILD=3213
VERSION_NAME=6.6.3 Alpha3 VERSION_NAME=6.6.3 Alpha3
VSCODE_EXT_REQUIRED_VERSION=1.0.8 VSCODE_EXT_REQUIRED_VERSION=1.0.8