/************************************************************************** /* This class implements an image viewer based on JAI. /* /* Copyright (c) 2006 by Bernhard Bablok (mail@bablokb.de) /* /* This program is free software; you can redistribute it and/or modify /* it under the terms of the GNU General Public License as published /* by the Free Software Foundation; either version 2 of the License or /* (at your option) any later version. /* /* This program is distributed in the hope that it will be useful, but /* WITHOUT ANY WARRANTY; without even the implied warranty of /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /* GNU General Public License for more details. /* /* You should have received a copy of the GNU General Public License /* along with this program; see the file COPYING. If not, write to /* the Free Software Foundation Inc., 59 Temple Place - Suite 330, /* Boston, MA 02111-1307 USA /**************************************************************************/ import java.io.*; import java.awt.*; import java.awt.geom.*; import java.awt.image.*; import java.awt.image.renderable.*; import java.awt.event.*; import javax.swing.*; import javax.media.jai.*; /** This class implements implements an image viewer based on JAI. @version $Revision: 1.4 $ @author $Author: bablokb $ */ public class ImageViewer3 extends JFrame { public static final int WIDTH = 600, HEIGHT = 400; /////////////////////3///////////////////////////////////////////////////////// /** Image-files. */ private RRArray iFiles = null; /** Image-Panel. */ private ImagePanel3 iImagePanel3 = null; /** Scroll-pane. */ private JScrollPane iScrollPane = null; ////////////////////////////////////////////////////////////////////////////// /** Constructor. */ public ImageViewer3(String title, ImagePanel3 panel) { super(title); setJMenuBar(getMenu()); iImagePanel3 = panel; iScrollPane = new JScrollPane(iImagePanel3); getContentPane().add(iScrollPane); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocation(100, 100); setVisible(false); } ////////////////////////////////////////////////////////////////////////////// /** Create JMenuBar. */ private JMenuBar getMenu() { JMenu menu = new JMenu("Image"); menu.add(new JMenuItem(new AbstractAction("Prev") { public void actionPerformed(ActionEvent e) { setPrevImage(); }; })); menu.add(new JMenuItem(new AbstractAction("Next") { public void actionPerformed(ActionEvent e) { setNextImage(); }; })); menu.addSeparator(); menu.add(new JMenuItem(new AbstractAction("Exit") { public void actionPerformed(ActionEvent e) { System.exit(0); }; })); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); menu = new JMenu("Transformation"); menu.add(new JMenuItem(new AbstractAction("Scale") { public void actionPerformed(ActionEvent e) { RenderedImage srcImg = (RenderedImage) getImage(); setImage(scaleImage(srcImg,0.75f)); }; })); menu.add(new JMenuItem(new AbstractAction("Sharpen") { public void actionPerformed(ActionEvent e) { RenderedImage srcImg = (RenderedImage) getImage(); setImage(sharpenImage(srcImg)); }; })); menuBar.add(menu); return menuBar; } ////////////////////////////////////////////////////////////////////////////// /** Scale image. */ private RenderedImage scaleImage(RenderedImage srcImg,float scale) { ParameterBlock pblock = new ParameterBlock(); pblock.addSource(srcImg); pblock.add(scale); // x-scale pblock.add(scale); // y-scale pblock.add(0.0f); // x-translation pblock.add(0.0f); // y-translation pblock.add(new InterpolationNearest()); return JAI.create("scale",pblock,null); } ////////////////////////////////////////////////////////////////////////////// /** Sharpen current image. */ public RenderedImage sharpenImage(RenderedImage srcImg) { final float[] kernelMatrix = { 0.f, -1.f, 0.f, -1.f, 5.0f, -1.f, 0.f, -1.f, 0.f}; KernelJAI kernel = new KernelJAI(3,3,1,1,kernelMatrix); return JAI.create("convolve",srcImg,kernel); } ////////////////////////////////////////////////////////////////////////////// /** Set images to round-robin array. */ protected void setFiles(Object[] obj) { iFiles = new RRArray(obj); } ////////////////////////////////////////////////////////////////////////////// /** Set image-files. */ protected void setImages(String[] filenames) throws IOException { RenderedImage[] imgArray = new RenderedImage[filenames.length]; for (int i=0;i