From 31dba0b4e9be32a5d8e0052e2bf16e7eb4e02534 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Thu, 14 Apr 2011 18:37:47 +0000 Subject: initial commit of OpenJPIP 1.0, a JPIP client-server architecture based on OpenJPEG (see README file in jpip directory for more details) --- .../opj_client/opj_viewer/src/ImageViewer.java | 267 +++++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 applications/jpip/opj_client/opj_viewer/src/ImageViewer.java (limited to 'applications/jpip/opj_client/opj_viewer/src/ImageViewer.java') diff --git a/applications/jpip/opj_client/opj_viewer/src/ImageViewer.java b/applications/jpip/opj_client/opj_viewer/src/ImageViewer.java new file mode 100644 index 00000000..9fab7f0a --- /dev/null +++ b/applications/jpip/opj_client/opj_viewer/src/ImageViewer.java @@ -0,0 +1,267 @@ +/* + * $Id$ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.awt.image.*; +import java.awt.geom.*; +import java.net.URL; +import javax.swing.border.*; +import java.util.*; +import java.io.*; + +public class ImageViewer extends JPanel +{ + private MML myMML; + private ResizeListener myRL; + private ImageManager imgmanager; + private int vw, vh; + private int iw, ih; + private int selected = 0; + private Image img; + + private String cmdline = new String(); + private boolean fullRefresh = false; + private Point offset = new Point(0,0); + private Rectangle rect = new Rectangle(); + private Rectangle roirect[] = null; + private String roiname[] = null; + + public ImageViewer( String j2kfilename, ImageManager manager) + { + String str; + + this.setSize( 200, 200); + Dimension asz = this.getSize(); + + vw = asz.width; + vh = asz.height; + + setBackground(Color.black); + myMML = new MML(this); + myRL = new ResizeListener(this); + + imgmanager = manager; + img = imgmanager.getImage( j2kfilename, vw, vh); + + addMouseListener(myMML); + addMouseMotionListener(myMML); + addComponentListener(myRL); + } + + public Image getImage() + { + return img; + } + + public void zoomIn() + { + roirect = null; + roiname = null; + + double scalex = vw/(double)rect.width; + double scaley = vh/(double)rect.height; + + int fw = (int)(imgmanager.getFw()*scalex); + int fh = (int)(imgmanager.getFh()*scaley); + int rx = (int)((imgmanager.getRx()+rect.x)*scalex); + int ry = (int)((imgmanager.getRy()+rect.y)*scaley); + + img = imgmanager.getImage( fw, fh, rx, ry, vw, vh); + + rect.x = rect.y = rect.width = rect.height = 0; + + selected = 0; + fullRefresh = true; + repaint(); + } + + public void enlarge() + { + roirect = null; + roiname = null; + + Dimension asz = this.getSize(); + + vw = asz.width; + vh = asz.height; + + double scalex = vw/(double)imgmanager.getRw(); + double scaley = vh/(double)imgmanager.getRh(); + + int fw = (int)(imgmanager.getFw()*scalex); + int fh = (int)(imgmanager.getFh()*scaley); + int rx = (int)(imgmanager.getRx()*scalex); + int ry = (int)(imgmanager.getRy()*scaley); + + img = imgmanager.getImage( fw, fh, rx, ry, vw, vh); + + fullRefresh = true; + repaint(); + } + + public void setSelected(int state) + { + roirect = null; + roiname = null; + + if (state != selected) { + + selected = state; + repaint(); + } + } + + public boolean isInsideRect(int x, int y) + { + return rect.contains(x - offset.x, y - offset.y); + } + + public void setRGeom(int x1, int y1, int x2, int y2) + { + rect.x = Math.min(x1,x2) - offset.x; + rect.y = Math.min(y1,y2) - offset.y; + rect.width = Math.abs(x2-x1); + rect.height = Math.abs(y2-y1); + } + + public void annotate( JP2XMLparser.ROIparams roi[]) + { + int numofroi = roi.length; + + roirect = new Rectangle [numofroi]; + roiname = new String [numofroi]; + + double scale_x = imgmanager.getFw()/(double)imgmanager.getOrigWidth(); + double scale_y = imgmanager.getFh()/(double)imgmanager.getOrigHeight(); + int rx = imgmanager.getRx(); + int ry = imgmanager.getRy(); + int rw = imgmanager.getRw(); + int rh = imgmanager.getRh(); + + for( int i=0; i 0) && (rect.height > 0)) + big.draw(rect); + + if( roirect != null){ + for( int i=0; i