/hg/gfx-test: Add image zooming capability into gfx-test harness.
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Thu Jul 21 02:29:47 PDT 2011
changeset f4113de94b6f in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=f4113de94b6f
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Thu Jul 21 11:31:09 2011 +0200
Add image zooming capability into gfx-test harness.
diffstat:
ChangeLog | 5 +
src/org/gfxtest/ImageDiffer/ImageUtils.java | 22 ++++
src/org/gfxtest/harness/MainWindow.java | 153 +++++++++++++++++++++++----
3 files changed, 157 insertions(+), 23 deletions(-)
diffs (337 lines):
diff -r 70dddc9b0917 -r f4113de94b6f ChangeLog
--- a/ChangeLog Thu Jul 21 10:19:13 2011 +0200
+++ b/ChangeLog Thu Jul 21 11:31:09 2011 +0200
@@ -1,3 +1,8 @@
+2011-07-21 Pavel Tisnovsky <ptisnovs at redhat.com>
+ * src/org/gfxtest/ImageDiffer/ImageUtils.java:
+ * src/org/gfxtest/harness/MainWindow.java:
+ Add image zooming capability into gfx-test harness.
+
2011-07-21 Pavel Tisnovsky <ptisnovs at redhat.com>
* AUTHORS: added footer
diff -r 70dddc9b0917 -r f4113de94b6f src/org/gfxtest/ImageDiffer/ImageUtils.java
--- a/src/org/gfxtest/ImageDiffer/ImageUtils.java Thu Jul 21 10:19:13 2011 +0200
+++ b/src/org/gfxtest/ImageDiffer/ImageUtils.java Thu Jul 21 11:31:09 2011 +0200
@@ -41,6 +41,8 @@
package org.gfxtest.ImageDiffer;
import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@@ -132,5 +134,25 @@
}
return images;
}
+
+ /**
+ * Return new scaled image. When the image is scaled up, nearest neighbor
+ * algorithm is used to not to "hide" one-pixel errors.
+ *
+ * @param inputImage source image to be scaled
+ * @param scale scale factor
+ * @return new scaled image
+ */
+ public static BufferedImage scaleImage(BufferedImage inputImage, float scale)
+ {
+ int width = (int) Math.ceil(inputImage.getWidth() * scale);
+ int height = (int) Math.ceil(inputImage.getHeight() * scale);
+ BufferedImage scaledImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D graphics2D = scaledImage.createGraphics();
+ graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
+ graphics2D.drawImage(inputImage, 0, 0, width, height, null);
+ graphics2D.dispose();
+ return scaledImage;
+ }
}
diff -r 70dddc9b0917 -r f4113de94b6f src/org/gfxtest/harness/MainWindow.java
--- a/src/org/gfxtest/harness/MainWindow.java Thu Jul 21 10:19:13 2011 +0200
+++ b/src/org/gfxtest/harness/MainWindow.java Thu Jul 21 11:31:09 2011 +0200
@@ -57,6 +57,7 @@
import org.gfxtest.ImageDiffer.ComparisonResult;
import org.gfxtest.ImageDiffer.ImageComparator;
+import org.gfxtest.ImageDiffer.ImageUtils;
/**
* Main window code and basic application logic for graphic test harness.
@@ -65,7 +66,6 @@
* TODO: dialog for setting verbose output
* TODO: image comparator
* TODO: image viewer
- * TODO: image zoomer
* TODO: grid
* TODO: refactoring!
*
@@ -94,7 +94,12 @@
private Dialogs dialogs = null;
private Configuration configuration = null;
+ private BufferedImage sampleImage = null;
+ private BufferedImage testImage = null;
+ private BufferedImage diffImage = null;
+
private boolean tableIsErasing;
+ private float scale = 1.0f;
private JMenuBar createMainMenuBar()
{
@@ -219,6 +224,44 @@
{
JMenu zoomMenu = new JMenu("Zoom");
zoomMenu.setMnemonic(KeyEvent.VK_Z);
+
+ JMenuItem zoomMenuZoomIn = new JMenuItem("Zoom In", KeyEvent.VK_Z);
+ zoomMenuZoomIn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, ActionEvent.CTRL_MASK));
+ zoomMenuZoomIn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, ActionEvent.CTRL_MASK));
+ zoomMenuZoomIn.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ onZoomInSelected();
+ }
+ });
+ zoomMenu.add(zoomMenuZoomIn);
+
+ JMenuItem zoomMenuZoomOut = new JMenuItem("Zoom Out", KeyEvent.VK_O);
+ zoomMenuZoomOut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, ActionEvent.CTRL_MASK));
+ zoomMenuZoomOut.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ onZoomOutSelected();
+ }
+ });
+ zoomMenu.add(zoomMenuZoomOut);
+
+ JMenuItem zoomMenuReset = new JMenuItem("Normal Size", KeyEvent.VK_N);
+ zoomMenuReset.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0, ActionEvent.CTRL_MASK));
+ zoomMenuReset.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ onResetZoomMenuSelected();
+ }
+ });
+ zoomMenu.add(zoomMenuReset);
+
return zoomMenu;
}
@@ -227,9 +270,9 @@
JMenu helpMenu = new JMenu("Help");
helpMenu.setMnemonic(KeyEvent.VK_H);
- JMenuItem fileHelpAbout = new JMenuItem("About", KeyEvent.VK_A);
- fileHelpAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
- fileHelpAbout.addActionListener(new ActionListener()
+ JMenuItem menuHelpAbout = new JMenuItem("About", KeyEvent.VK_A);
+ menuHelpAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
+ menuHelpAbout.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
@@ -237,7 +280,7 @@
onHelpAboutMenuSelected();
}
});
- helpMenu.add(fileHelpAbout);
+ helpMenu.add(menuHelpAbout);
return helpMenu;
}
@@ -393,18 +436,42 @@
topRightPanel.setMinimumSize(new Dimension(320, 240));
//topRightPanel.setBackground(Color.green);
topRightPanel.add(this.topRightLabel);
+ topRightPanel.addMouseWheelListener(new MouseWheelListener()
+ {
+ @Override
+ public void mouseWheelMoved(MouseWheelEvent e)
+ {
+ onMouseWheelRotated(e);
+ }
+ });
rightVerticalSplitPane.add(topRightPanel);
JPanel bottomLeftPanel = new JPanel();
bottomLeftPanel.setMinimumSize(new Dimension(320, 240));
//bottomLeftPanel.setBackground(Color.blue);
bottomLeftPanel.add(this.bottomLeftLabel);
+ bottomLeftPanel.addMouseWheelListener(new MouseWheelListener()
+ {
+ @Override
+ public void mouseWheelMoved(MouseWheelEvent e)
+ {
+ onMouseWheelRotated(e);
+ }
+ });
leftVerticalSplitPane.add(bottomLeftPanel);
JPanel bottomRightPanel = new JPanel();
bottomRightPanel.setMinimumSize(new Dimension(320, 240));
//bottomRightPanel.setBackground(Color.yellow);
bottomRightPanel.add(this.bottomRightLabel);
+ bottomRightPanel.addMouseWheelListener(new MouseWheelListener()
+ {
+ @Override
+ public void mouseWheelMoved(MouseWheelEvent e)
+ {
+ onMouseWheelRotated(e);
+ }
+ });
rightVerticalSplitPane.add(bottomRightPanel);
window.getContentPane().add(horizontalSplitPane);
@@ -474,9 +541,9 @@
+ ".png";
String sampleFileName = FileSystemTools.constructTestDirectoryName(this.configuration.getOutputDirectory(), this.selectedTestSuite);
String testFileName = FileSystemTools.constructTestDirectoryName(this.configuration.getOutputDirectory(), this.selectedTestSuite);
- BufferedImage sampleImage = loadAndShowSampleImage(testName, sampleFileName);
- BufferedImage testImage = loadAndShowTestImage(testName, testFileName);
- computeAndShowImagesDifference(testName, sampleImage, testImage);
+ loadAndShowSampleImage(testName, sampleFileName);
+ loadAndShowTestImage(testName, testFileName);
+ computeAndShowImagesDifference(testName);
/*
* JOptionPane.showMessageDialog(this.mainWindow, "Selected test: "
* + testName, WINDOW_TITLE, JOptionPane.INFORMATION_MESSAGE);
@@ -484,16 +551,16 @@
}
}
- private BufferedImage loadAndShowTestImage(String testName, String testFileName)
+ private void loadAndShowTestImage(String testName, String testFileName)
{
- BufferedImage testImage = null;
+ this.testImage = null;
File testImageFile = new File(testFileName, testName);
if (testImageFile.exists() && testImageFile.isFile())
{
try
{
- testImage = ImageIO.read(new File(testFileName, testName));
- this.bottomRightLabel.setIcon(new ImageIcon(testImage));
+ this.testImage = ImageIO.read(new File(testFileName, testName));
+ this.bottomRightLabel.setIcon(new ImageIcon(this.testImage));
this.bottomRightLabel.setText("");
}
catch (IOException e)
@@ -502,19 +569,19 @@
this.bottomRightLabel.setText(e.getMessage());
}
}
- return testImage;
}
- private BufferedImage loadAndShowSampleImage(String testName, String sampleFileName)
+ private void loadAndShowSampleImage(String testName, String sampleFileName)
{
- BufferedImage sampleImage = null;
+ this.sampleImage = null;
File sampleImageFile = new File(sampleFileName, testName);
if (sampleImageFile.exists() && sampleImageFile.isFile())
{
try
{
- sampleImage = ImageIO.read(new File(sampleFileName, testName));
- this.topRightLabel.setIcon(new ImageIcon(sampleImage));
+ this.sampleImage = ImageIO.read(new File(sampleFileName, testName));
+
+ this.topRightLabel.setIcon(new ImageIcon(this.sampleImage));
this.topRightLabel.setText("");
}
catch (IOException e)
@@ -523,17 +590,17 @@
this.topRightLabel.setText(e.getMessage());
}
}
- return sampleImage;
}
- private void computeAndShowImagesDifference(String testName, BufferedImage sampleImage, BufferedImage testImage)
+ private void computeAndShowImagesDifference(String testName)
{
- if (testImage != null && sampleImage != null)
+ if (this.testImage != null && this.sampleImage != null)
{
ImageComparator comparator = new ImageComparator();
org.gfxtest.ImageDiffer.Configuration cfg = new org.gfxtest.ImageDiffer.Configuration();
- ComparisonResult result = comparator.diffImages(testName, new BufferedImage[] { testImage, sampleImage }, cfg);
- this.bottomLeftLabel.setIcon(new ImageIcon(result.getDiffImage()));
+ ComparisonResult result = comparator.diffImages(testName, new BufferedImage[] { this.testImage, this.sampleImage }, cfg);
+ this.diffImage = result.getDiffImage();
+ this.bottomLeftLabel.setIcon(new ImageIcon(this.diffImage));
this.bottomLeftLabel.setText("");
}
else
@@ -614,6 +681,28 @@
this.tableIsErasing = false;
}
+ protected void onMouseWheelRotated(MouseWheelEvent e)
+ {
+ int rotation = e.getWheelRotation();
+ if (rotation < 0)
+ {
+ this.scale *= 1.2;
+ redrawImages();
+ }
+ else if (rotation > 0)
+ {
+ this.scale /= 1.2;
+ redrawImages();
+ }
+ }
+
+ private void redrawImages()
+ {
+ this.topRightLabel.setIcon(new ImageIcon(ImageUtils.scaleImage(this.sampleImage, this.scale)));
+ this.bottomRightLabel.setIcon(new ImageIcon(ImageUtils.scaleImage(this.testImage, this.scale)));
+ this.bottomLeftLabel.setIcon(new ImageIcon(ImageUtils.scaleImage(this.diffImage, this.scale)));
+ }
+
protected void onCompilationVerboseCheckBoxChanged(boolean verboseCompile)
{
this.configuration.setVerboseCompile(verboseCompile);
@@ -671,6 +760,24 @@
this.dialogs.showAboutDialog();
}
+ protected void onResetZoomMenuSelected()
+ {
+ this.scale = 1.0f;
+ redrawImages();
+ }
+
+ protected void onZoomInSelected()
+ {
+ this.scale *= 1.2f;
+ redrawImages();
+ }
+
+ protected void onZoomOutSelected()
+ {
+ this.scale /= 1.2f;
+ redrawImages();
+ }
+
protected void onCompileButtonPressed()
{
if (this.selectedTestSuite == null)
@@ -746,7 +853,7 @@
{
this.dialogs.showNoTestSelectedMessage();
}
- String outputDirectory = this.configuration.getTestClassesDirectory();
+ String outputDirectory = Configuration.getTestClassesDirectory();
if (outputDirectory == null)
{
this.dialogs.showErrorMessage("Output directory is not set");
More information about the distro-pkg-dev
mailing list