add files and docs of files and images
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
|
||||
module.exports = function(__runtime__, scope){
|
||||
var images = {};
|
||||
var colors = Object.create(android.graphics.Color);
|
||||
colors.toString = function(color){
|
||||
return '#' + (color >>> 0).toString(16);
|
||||
}
|
||||
if(android.os.Build.VERSION.SDK_INT < 19){
|
||||
return images;
|
||||
}
|
||||
@@ -17,25 +21,28 @@ module.exports = function(__runtime__, scope){
|
||||
|
||||
images.pixel = rtImages.pixel;
|
||||
|
||||
images.detectsColor = rtImages.detectsColor.bind(rtImages);
|
||||
images.detectsColor = function(img, color, x, y, threshold, algorithm){
|
||||
color = parseColor(color);
|
||||
algorithm = algorithm || "rgb";
|
||||
threshold = threshold || 16;
|
||||
var colorDetector = getColorDetector(color, algorithm, threshold);
|
||||
var pixel = images.pixel(img, x, y);
|
||||
return colorDetector.detectsColor(colors.red(pixel), colors.green(pixel), colors.blue(pixel));
|
||||
}
|
||||
|
||||
images.findColor = function(img, color, options){
|
||||
if(typeof(color) == 'string'){
|
||||
if(color.startsWith('#')){
|
||||
color = parseInt('0x' + color.substring(1));
|
||||
}else{
|
||||
color = parseInt('0x' + color);
|
||||
}
|
||||
}
|
||||
color = parseColor(color);
|
||||
options = options || {};
|
||||
var region = options.region || [];
|
||||
x = region[0] || 0;
|
||||
y = region[1] || 0;
|
||||
width = region[2] || (img.getWidth() - x);
|
||||
height = region[3] || (img.getHeight() - y);
|
||||
threads = options.threads || 2;
|
||||
if(options.threshold !== 0){
|
||||
threshold = options.threshold || 8;
|
||||
var x = region[0] || 0;
|
||||
var y = region[1] || 0;
|
||||
var width = region[2] || (img.getWidth() - x);
|
||||
var height = region[3] || (img.getHeight() - y);
|
||||
var threads = options.threads || 2;
|
||||
if(options.similarity){
|
||||
var threshold = parseInt(255 * (1 - options.similarity));
|
||||
}else{
|
||||
var threshold = options.threshold || 16;
|
||||
}
|
||||
algorithm = options.algorithm || "rgb";
|
||||
var rect = new android.graphics.Rect(x, y, width + x, height + y);
|
||||
@@ -76,7 +83,20 @@ module.exports = function(__runtime__, scope){
|
||||
throw new Error("Unknown algorithm: " + algorithm);
|
||||
}
|
||||
|
||||
function parseColor(color){
|
||||
if(typeof(color) == 'string'){
|
||||
if(color.startsWith('#')){
|
||||
return parseInt('0x' + color.substring(1));
|
||||
}else{
|
||||
return parseInt('0x' + color);
|
||||
}
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
scope.__asGlobal__(images, ['requestScreenCapture', 'captureScreen', 'findColor', 'findColorInRegion', 'findColorEquals']);
|
||||
|
||||
scope.colors = colors;
|
||||
|
||||
return images;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
module.exports = function(__runtime__, scope){
|
||||
scope.files = com.stardust.pio.PFile;
|
||||
scope.open = function(path, mode, encoding, bufferSize){
|
||||
if(arguments.length == 1){
|
||||
return com.stardust.pio.PFile.open(path);
|
||||
|
||||
@@ -40,19 +40,17 @@ public interface ColorDetector {
|
||||
|
||||
class DifferenceDetector extends AbstractColorDetector {
|
||||
|
||||
private final int mRThreshold, mGThreshold, mBThreshold;
|
||||
private final int mThreshold;
|
||||
|
||||
public DifferenceDetector(int color, int threshold) {
|
||||
super(color);
|
||||
mRThreshold = Color.red(threshold);
|
||||
mGThreshold = Color.green(threshold);
|
||||
mBThreshold = Color.blue(threshold);
|
||||
mThreshold = threshold * 3;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean detectsColor(int R, int G, int B) {
|
||||
return Math.abs(R - mR) <= mRThreshold && Math.abs(G - mG) <= mGThreshold &&
|
||||
Math.abs(B - mB) <= mBThreshold;
|
||||
return Math.abs(R - mR) + Math.abs(G - mG) + Math.abs(B - mB) <= mThreshold;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +75,7 @@ public interface ColorDetector {
|
||||
|
||||
public RGBDistanceDetector(int color, int threshold) {
|
||||
super(color);
|
||||
mThreshold = threshold * threshold;
|
||||
mThreshold = threshold * threshold * 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,7 +98,7 @@ public interface ColorDetector {
|
||||
mR = (color & 0xff0000) >> 16;
|
||||
mG = (color & 0x00ff00) >> 8;
|
||||
mB = color & 0xff;
|
||||
mThreshold = threshold * threshold;
|
||||
mThreshold = threshold * threshold * 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,7 +161,11 @@ public interface ColorDetector {
|
||||
long HS = getHS(mR, mG, mB);
|
||||
mH = (int) (HS & 0xffffffffL);
|
||||
mS = (int) ((HS >> 32) & 0xffffffffL);
|
||||
mThreshold = threshold * threshold;
|
||||
mThreshold = threshold * 3729600 / 255;
|
||||
}
|
||||
|
||||
public HSDistanceDetector(int color, float similarity) {
|
||||
this(color, (int) (1.0f - similarity) * 255);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,9 +193,9 @@ public interface ColorDetector {
|
||||
H = 240 + (R - G) / (max - min) * 60;
|
||||
}
|
||||
if (H < 0) H = H + 360;
|
||||
int S = (max - min) / max;
|
||||
int S = (max - min) * 100 / max;
|
||||
return H & ((long) S << 32);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.stardust.autojs.runtime.api.image;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.media.Image;
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Point;
|
||||
import android.media.Image;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.RequiresApi;
|
||||
@@ -71,6 +72,9 @@ public class Images {
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public Image captureScreen() {
|
||||
mScriptRuntime.requiresApi(21);
|
||||
if(mScreenCapturer == null){
|
||||
throw new SecurityException("No screen capture permission");
|
||||
}
|
||||
colorFinder.prestartThreads();
|
||||
return mScreenCapturer.capture();
|
||||
}
|
||||
@@ -122,19 +126,6 @@ public class Images {
|
||||
return bitmap.getPixel(x, y);
|
||||
}
|
||||
|
||||
public boolean detectsColor(Image image, int x, int y, int color) {
|
||||
if (image == null)
|
||||
return false;
|
||||
int pixel = pixel(image, x, y);
|
||||
return colorFinder.defaultColorDetector(color).detectsColor(Color.red(pixel), Color.green(pixel), Color.blue(pixel));
|
||||
}
|
||||
|
||||
public boolean detectsColor(Image image, int x, int y, int color, int threshold) {
|
||||
if (image == null)
|
||||
return false;
|
||||
int pixel = pixel(image, x, y);
|
||||
return colorFinder.defaultColorDetector(color, threshold).detectsColor(Color.red(pixel), Color.green(pixel), Color.blue(pixel));
|
||||
}
|
||||
|
||||
public static Bitmap read(String path) {
|
||||
return BitmapFactory.decodeFile(path);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:accessibilityEventTypes="typeContextClicked|typeViewClicked|typeViewHoverEnter|typeViewHoverExit|typeViewFocused|typeViewLongClicked|typeViewScrolled|typeViewSelected|typeViewTextChanged|typeViewTextSelectionChanged|typeWindowContentChanged|typeWindowsChanged|typeWindowStateChanged"
|
||||
android:accessibilityEventTypes="typeAllMask"
|
||||
android:accessibilityFeedbackType="feedbackGeneric"
|
||||
android:accessibilityFlags="flagIncludeNotImportantViews|flagReportViewIds|flagRequestEnhancedWebAccessibility"
|
||||
android:accessibilityFlags="flagIncludeNotImportantViews|flagReportViewIds|flagRetrieveInteractiveWindows|flagRequestEnhancedWebAccessibility"
|
||||
android:canPerformGestures="true"
|
||||
android:canRequestEnhancedWebAccessibility="true"
|
||||
android:canRetrieveWindowContent="true"
|
||||
|
||||
Reference in New Issue
Block a user