/hg/icedtea-web: Modularised initialization of AwtHelper and imp...

jvanek at icedtea.classpath.org jvanek at icedtea.classpath.org
Mon Apr 29 07:24:21 PDT 2013


changeset e34db561b7b9 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=e34db561b7b9
author: Jiri Vanek <jvanek at redhat.com>
date: Mon Apr 29 16:24:37 2013 +0200

	Modularised initialization of AwtHelper and improoved performance of ImageSeeker. Added masking to ImageSeeker


diffstat:

 ChangeLog                                                                   |  20 ++
 tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java                |   6 +-
 tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java               |  36 +++-
 tests/test-extensions/net/sourceforge/jnlp/awt/imagesearch/ImageSeeker.java |  77 ++++++++-
 4 files changed, 120 insertions(+), 19 deletions(-)

diffs (192 lines):

diff -r 105f8cb6d988 -r e34db561b7b9 ChangeLog
--- a/ChangeLog	Mon Apr 29 15:29:46 2013 +0200
+++ b/ChangeLog	Mon Apr 29 16:24:37 2013 +0200
@@ -1,3 +1,23 @@
+2013-04-29  Jiri Vanek  <jvanek at redhat.com>
+
+	More granular initialization of AwtHelper
+	* tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java: added 
+	(executeBrowser) which can work upon fully constructed url
+	* tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java:
+	(captureScreenAndFindAppletByIconTryKTimes) split to three:
+	(captureScreenAndFindAppletByIconTryKTimes) - unchanged, now using following
+	(initialiseOnScreenshot) initialize from given buffered image, creating area
+	(initialiseOnScreenshotAndArea) initialize from two given buffered images
+
+2013-04-29  Jiri Vanek  <jvanek at redhat.com>
+
+	Improved performance of scanning images, added masking of images
+	* tests/test-extensions/net/sourceforge/jnlp/awt/imagesearch/ImageSeeker.java:
+	(findExactImage) now using masks and is iterating over rows
+	(getMaskImage) new method to visualize mask
+	(getMask)  new method to create mask
+	(getPixels) method to extract pixels from image to int array
+
 2013-04-29  Jana Fabrikova  <jfabriko at redhat.com>
 
 	* tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java:
diff -r 105f8cb6d988 -r e34db561b7b9 tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java
--- a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java	Mon Apr 29 15:29:46 2013 +0200
+++ b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java	Mon Apr 29 16:24:37 2013 +0200
@@ -598,7 +598,11 @@
     }
 
     public ProcessResult executeBrowser(List<String> otherargs, String resource) throws Exception {
-        ProcessWrapper rpw = new ProcessWrapper(getBrowserLocation(), otherargs, getUrlUponThisInstance(resource));
+        return executeBrowser(otherargs, getUrlUponThisInstance(resource));        
+    }
+    
+     public ProcessResult executeBrowser(List<String> otherargs, URL url) throws Exception {
+        ProcessWrapper rpw = new ProcessWrapper(getBrowserLocation(), otherargs, url);
         rpw.setReactingProcess(getCurrentBrowser());//current browser may be null, but it does not metter
         return rpw.execute();
     }
diff -r 105f8cb6d988 -r e34db561b7b9 tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java
--- a/tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java	Mon Apr 29 15:29:46 2013 +0200
+++ b/tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java	Mon Apr 29 16:24:37 2013 +0200
@@ -354,24 +354,42 @@
         int count = 0;
         appletFound = false;
         while ((count < K) && !appletFound) {
-                robot.delay(defaultWaitForApplet);
-                screenshot = robot.createScreenCapture( new Rectangle( Toolkit.getDefaultToolkit().getScreenSize() ) );
-                screenshotTaken = true;
-                actionArea = ComponentFinder.findWindowByIcon(icon, iconPosition, width, height, screenshot);
-                if (ImageSeeker.isRectangleValid(actionArea)) {
-                    appletFound = true;
-                }
-                count++;
+            robot.delay(defaultWaitForApplet);
+            try {
+                screenshot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
+                initialiseOnScreenshot(icon, iconPosition, width, height, screenshot);
+            } catch (ComponentNotFoundException ex) {
+                //keeping silent and try more-times
+            }
+            count++;
         }
 
         if (ImageSeeker.isRectangleValid(actionArea)) {
             appletFound = true;
         } else {
-            throw new ComponentNotFoundException("Applet not found in the screenshot!");
+            throw new ComponentNotFoundException("Object not found in the screenshot!");
         }
 
     }
     
+    public void initialiseOnScreenshot(BufferedImage icon, Point iconPosition, int width, int height, BufferedImage screenshot) throws ComponentNotFoundException {
+        Rectangle r = ComponentFinder.findWindowByIcon(icon, iconPosition, width, height, screenshot);
+        initialiseOnScreenshotAndArea(screenshot, r);
+        
+    }
+    
+    public void initialiseOnScreenshotAndArea(BufferedImage screenshot, Rectangle actionArea) throws ComponentNotFoundException {
+        this.screenshot = screenshot;
+        screenshotTaken = true;
+        this.actionArea = actionArea;
+        if (ImageSeeker.isRectangleValid(actionArea)) {
+            appletFound = true;
+        } else {
+            throw new ComponentNotFoundException("set invalid area!");
+        }
+    }
+
+    
     /**
      * auxiliary method writeAppletScreen for writing Buffered image into png
      * 
diff -r 105f8cb6d988 -r e34db561b7b9 tests/test-extensions/net/sourceforge/jnlp/awt/imagesearch/ImageSeeker.java
--- a/tests/test-extensions/net/sourceforge/jnlp/awt/imagesearch/ImageSeeker.java	Mon Apr 29 15:29:46 2013 +0200
+++ b/tests/test-extensions/net/sourceforge/jnlp/awt/imagesearch/ImageSeeker.java	Mon Apr 29 16:24:37 2013 +0200
@@ -50,17 +50,28 @@
         return findExactImage(marker, screen, new Rectangle(0,0,screen.getWidth(), screen.getHeight()));
     }
     
-    public static Rectangle findExactImage(BufferedImage marker, BufferedImage screen, Rectangle actionArea){
-        Rectangle result = new Rectangle(0,0,0,0);
+    public static Rectangle findExactImage(BufferedImage marker /*usually small*/, BufferedImage screen, Rectangle actionArea) {
+        Rectangle result = new Rectangle(0, 0, 0, 0);
         boolean found = false;
         boolean ok = true;
-        
-        for(int x = actionArea.x; (x < (actionArea.x + actionArea.width - marker.getWidth()) ) && !found; x++){
-            for(int y= actionArea.y; (y < (actionArea.y + actionArea.height - marker.getHeight()) ) && !found; y++){
-                
-                for(int mx = 0; (mx < marker.getWidth()) && ok; mx++){
-                    for(int my = 0; (my < marker.getHeight()) && ok; my++){
-                        if(marker.getRGB(mx, my) != screen.getRGB(x+mx,y+my)){
+        //to filter out values with alpha
+        boolean[][] mask = getMask(marker);
+        //accessing those too often, copying
+        int[][] markerPixels = getPixels(marker);
+        int mw = marker.getWidth();
+        int mh = marker.getHeight();
+        for (int y = actionArea.y; (y < (actionArea.y + actionArea.height - marker.getHeight())) && !found; y++) {
+            for (int x = actionArea.x; (x < (actionArea.x + actionArea.width - marker.getWidth())) && !found; x++) {
+
+
+                for (int my = 0; (my < mh) && ok; my++) {
+                    for (int mx = 0; (mx < mw) && ok; mx++) {
+
+                        //ignore masked (having alpha) values
+                        if (!mask[mx][my]) {
+                            continue;
+                        }
+                        if (markerPixels[mx][my] != screen.getRGB(x + mx, y + my)) {
                             ok = false;
                         }
                     }
@@ -325,4 +336,52 @@
         return (r.width != 0)&&(r.height != 0)&&(r.x != Integer.MIN_VALUE)&&(r.y != Integer.MIN_VALUE);
     }
 
+    public static BufferedImage getMaskImage(BufferedImage icon) {
+        int w = icon.getWidth();
+        int h = icon.getHeight();
+        boolean[][] b = getMask(icon);
+        BufferedImage mask = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY);
+        for (int y = 0; y < h; y++) {
+            for (int x = 0; x < w; x++) {
+                if (b[x][y]) {
+                    mask.setRGB(x, y, Color.white.getRGB());
+                } else {
+                    mask.setRGB(x, y, Color.black.getRGB());
+                }
+            }
+        }
+        return mask;
+    }
+
+    public static boolean[][] getMask(BufferedImage icon) {
+        int w = icon.getWidth();
+        int h = icon.getHeight();
+        boolean[][] r = new boolean[w][h];
+        for (int y = 0; y < h; y++) {
+            for (int x = 0; x < w; x++) {
+                int i = icon.getRGB(x, y);
+                int alpha = (i >> 24) & 0xff;
+                if (alpha == 255) {
+                    r[x][y] = true;
+                } else {
+                    r[x][y] = false;
+                }
+            }
+        }
+        return r;
+    }
+
+    public static int[][] getPixels(BufferedImage icon) {
+        int w = icon.getWidth();
+        int h = icon.getHeight();
+        int[][] r = new int[w][h];
+        for (int x = 0; x < w; x++) {
+            for (int y = 0; y < h; y++) {
+                int i = icon.getRGB(x, y);
+                //remove mask? not yet...
+                r[x][y] = i;
+            }
+        }
+        return r;
+    }
 }



More information about the distro-pkg-dev mailing list