aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2010-11-15 07:18:56 -0800
committerAndroid Code Review <code-review@android.com>2010-11-15 07:18:56 -0800
commit6420b490b26047e05c890c4fb0db65f687142fce (patch)
tree48b85e493a9fe7fd61824af157289a4379e65109 /eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android
parent09324606fa602d352271004655d1020df29c2a59 (diff)
parent0fef3efc3e317fcfecefb2e5376a3613479e6dbd (diff)
downloadsdk-6420b490b26047e05c890c4fb0db65f687142fce.zip
sdk-6420b490b26047e05c890c4fb0db65f687142fce.tar.gz
sdk-6420b490b26047e05c890c4fb0db65f687142fce.tar.bz2
Merge "Use view bounds to speed up image cropping"
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java74
1 files changed, 66 insertions, 8 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java
index 7ed5f1f..30bb82e 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java
@@ -16,6 +16,8 @@
package com.android.ide.eclipse.adt.internal.editors.layout.gle2;
+import com.android.ide.common.api.Rect;
+
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.widgets.Display;
@@ -35,7 +37,18 @@ public class SwtUtilsTest extends TestCase {
g.fillRect(0, 0, image.getWidth(), image.getHeight());
g.dispose();
- BufferedImage crop = SwtUtils.cropBlank(image);
+ BufferedImage crop = SwtUtils.cropBlank(image, null);
+ assertNull(crop);
+ }
+
+ public void testCropBlankPre() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = SwtUtils.cropBlank(image, new Rect(5, 5, 80, 80));
assertNull(crop);
}
@@ -46,7 +59,7 @@ public class SwtUtilsTest extends TestCase {
g.fillRect(0, 0, image.getWidth(), image.getHeight());
g.dispose();
- BufferedImage crop = SwtUtils.cropBlank(image);
+ BufferedImage crop = SwtUtils.cropBlank(image, null);
assertNotNull(crop);
assertEquals(image.getWidth(), crop.getWidth());
assertEquals(image.getHeight(), crop.getHeight());
@@ -61,7 +74,41 @@ public class SwtUtilsTest extends TestCase {
g.fillRect(25, 25, 50, 50);
g.dispose();
- BufferedImage crop = SwtUtils.cropBlank(image);
+ BufferedImage crop = SwtUtils.cropBlank(image, null);
+ assertNotNull(crop);
+ assertEquals(50, crop.getWidth());
+ assertEquals(50, crop.getHeight());
+ assertEquals(0xFF00FF00, crop.getRGB(0, 0));
+ assertEquals(0xFF00FF00, crop.getRGB(49, 49));
+ }
+
+ public void testCropSomethingPre() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(25, 25, 50, 50);
+ g.dispose();
+
+ BufferedImage crop = SwtUtils.cropBlank(image, new Rect(0, 0, 100, 100));
+ assertNotNull(crop);
+ assertEquals(50, crop.getWidth());
+ assertEquals(50, crop.getHeight());
+ assertEquals(0xFF00FF00, crop.getRGB(0, 0));
+ assertEquals(0xFF00FF00, crop.getRGB(49, 49));
+ }
+
+ public void testCropSomethingPre2() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(25, 25, 50, 50);
+ g.dispose();
+
+ BufferedImage crop = SwtUtils.cropBlank(image, new Rect(5, 5, 80, 80));
assertNotNull(crop);
assertEquals(50, crop.getWidth());
assertEquals(50, crop.getHeight());
@@ -76,7 +123,7 @@ public class SwtUtilsTest extends TestCase {
g.fillRect(0, 0, image.getWidth(), image.getHeight());
g.dispose();
- BufferedImage crop = SwtUtils.cropColor(image, 0xFF00FF00);
+ BufferedImage crop = SwtUtils.cropColor(image, 0xFF00FF00, null);
assertNull(crop);
}
@@ -87,7 +134,7 @@ public class SwtUtilsTest extends TestCase {
g.fillRect(0, 0, image.getWidth(), image.getHeight());
g.dispose();
- BufferedImage crop = SwtUtils.cropColor(image, 0xFFFF0000);
+ BufferedImage crop = SwtUtils.cropColor(image, 0xFFFF0000, null);
assertNotNull(crop);
assertEquals(image.getWidth(), crop.getWidth());
assertEquals(image.getHeight(), crop.getHeight());
@@ -102,7 +149,7 @@ public class SwtUtilsTest extends TestCase {
g.fillRect(25, 25, 50, 50);
g.dispose();
- BufferedImage crop = SwtUtils.cropColor(image, 0xFF00FF00);
+ BufferedImage crop = SwtUtils.cropColor(image, 0xFF00FF00, null);
assertEquals(50, crop.getWidth());
assertEquals(50, crop.getHeight());
assertEquals(0xFFFF0000, crop.getRGB(0, 0));
@@ -110,8 +157,8 @@ public class SwtUtilsTest extends TestCase {
}
public void testNullOk() throws Exception {
- SwtUtils.cropBlank(null);
- SwtUtils.cropColor(null, 0);
+ SwtUtils.cropBlank(null, null);
+ SwtUtils.cropColor(null, 0, null);
}
public void testImageConvertNoAlpha() throws Exception {
@@ -208,4 +255,15 @@ public class SwtUtilsTest extends TestCase {
}
}
+ public void testNothingTodo() throws Exception {
+ BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics g = image.getGraphics();
+ g.setColor(new Color(0xFF00FF00, true));
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+
+ BufferedImage crop = SwtUtils.cropColor(image, 0xFFFF0000, new Rect(40, 40, 0, 0));
+ assertNull(crop);
+ }
+
}