temporal commit to resort the opj_viewer
This commit is contained in:
parent
42e5077688
commit
5b1dc83382
|
@ -1,35 +0,0 @@
|
|||
<project name="opj_viewer" default="dist" basedir=".">
|
||||
<description>OpenJPIP client image viewer</description>
|
||||
<property name="src" location="src" />
|
||||
<property name="build" location="build"/>
|
||||
<property name="dist" location="dist" />
|
||||
|
||||
<target name="init">
|
||||
<tstamp/>
|
||||
<mkdir dir="${build}"/>
|
||||
</target>
|
||||
<target name="compile" depends="init">
|
||||
<javac srcdir="${src}" destdir="${build}"/>
|
||||
</target>
|
||||
<target name="dist" depends="compile">
|
||||
<mkdir dir="${dist}"/>
|
||||
<jar jarfile="${dist}/opj_viewer-${DSTAMP}.jar"
|
||||
basedir="${build}" manifest="${dist}/manifest.txt"/>
|
||||
<exec dir="${dist}" executable="ln">
|
||||
<arg line="-sf opj_viewer-${DSTAMP}.jar opj_viewer.jar"/>
|
||||
</exec>
|
||||
</target>
|
||||
<target name="clean">
|
||||
<delete dir="${build}"/>
|
||||
<delete dir="${dist}"/>
|
||||
</target>
|
||||
<target name="test" depends="dist">
|
||||
<exec executable="appletviewer"><arg line="dist.html"/></exec>
|
||||
</target>
|
||||
<target name="build_test" depends="compile">
|
||||
<exec executable="appletviewer"><arg line="compile.html"/></exec>
|
||||
</target>
|
||||
<target name="build_testj" depends="compile">
|
||||
<exec executable="java"><arg line="-classpath build ImageWindow girl"/></exec>
|
||||
</target>
|
||||
</project>
|
|
@ -1,5 +0,0 @@
|
|||
Manifest-Version: 1.0
|
||||
Ant-Version: Apache Ant 1.7.0
|
||||
Created-By: Kaori Hagihara
|
||||
Main-Class: ImageWindow
|
||||
Class-Path: /usr/share/java/xerces-j2.jar
|
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
opj_viewer-20110218.jar
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* $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.Image;
|
||||
|
||||
public class ImageManager extends JPIPHttpClient
|
||||
{
|
||||
private PnmImage pnmimage;
|
||||
|
||||
public ImageManager( String uri)
|
||||
{
|
||||
super( uri);
|
||||
pnmimage = null;
|
||||
}
|
||||
|
||||
public int getOrigWidth(){ return pnmimage.width;}
|
||||
public int getOrigHeight(){ return pnmimage.height;}
|
||||
|
||||
public Image getImage( String j2kfilename, int reqfw, int reqfh)
|
||||
{
|
||||
System.err.println();
|
||||
|
||||
String refcid = ImgdecClient.query_cid( j2kfilename);
|
||||
byte[] jptstream;
|
||||
|
||||
if( refcid == null)
|
||||
jptstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, true);
|
||||
else
|
||||
jptstream = super.requestViewWindow( reqfw, reqfh, refcid, true);
|
||||
|
||||
System.err.println( "decoding to PNM image");
|
||||
pnmimage = ImgdecClient.decode_jptstream( jptstream, j2kfilename, cid, fw, fh);
|
||||
System.err.println( " done");
|
||||
|
||||
// System.out.println( "fw: " + fw + " fh: " + fh + "pnm w: ");
|
||||
|
||||
return pnmimage.createROIImage( rx, ry, rw, rh);
|
||||
}
|
||||
|
||||
public Image getImage( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh)
|
||||
{
|
||||
System.err.println();
|
||||
|
||||
byte[] jptstream = super.requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh);
|
||||
|
||||
System.err.println( "decoding to PNM image");
|
||||
pnmimage = ImgdecClient.decode_jptstream( jptstream, cid, fw, fh);
|
||||
System.err.println( " done");
|
||||
|
||||
return pnmimage.createROIImage( rx, ry, rw, rh);
|
||||
}
|
||||
|
||||
public byte[] getXML()
|
||||
{
|
||||
System.err.println();
|
||||
|
||||
byte []xmldata = null;
|
||||
byte[] jptstream = super.requestXML();
|
||||
|
||||
if( jptstream != null){
|
||||
ImgdecClient.send_JPTstream( jptstream);
|
||||
|
||||
xmldata = ImgdecClient.get_XMLstream( cid);
|
||||
}
|
||||
return xmldata;
|
||||
}
|
||||
public void closeChannel()
|
||||
{
|
||||
ImgdecClient.destroy_cid( cid);
|
||||
super.closeChannel();
|
||||
}
|
||||
}
|
|
@ -1,267 +0,0 @@
|
|||
/*
|
||||
* $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<numofroi ; i++){
|
||||
int x = (int)(roi[i].x*scale_x) - rx;
|
||||
int y = (int)(roi[i].y*scale_y) - ry;
|
||||
int w = (int)(roi[i].w*scale_x);
|
||||
int h = (int)(roi[i].h*scale_y);
|
||||
if( 0<=x && 0<=y && x+w<=rw && y+h<=rh){ // can be optimized
|
||||
roirect[i] = new Rectangle( x, y, w, h);
|
||||
roiname[i] = new String( roi[i].name);
|
||||
}
|
||||
else{
|
||||
roirect[i] = null;
|
||||
roiname[i] = null;
|
||||
}
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
public boolean hasAnnotation()
|
||||
{
|
||||
if( roirect == null)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isInsideROIRect(int x, int y)
|
||||
{
|
||||
for( int i=0; i<roirect.length; i++)
|
||||
if( roirect[i] != null)
|
||||
if( roirect[i].contains(x - offset.x, y - offset.y)){
|
||||
rect = roirect[i];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
BufferedImage bi;
|
||||
Graphics2D big;
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
if (fullRefresh) {
|
||||
g2.clearRect(0, 0, vw, vh);
|
||||
fullRefresh = false;
|
||||
}
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHint(RenderingHints.KEY_RENDERING,
|
||||
RenderingHints.VALUE_RENDER_QUALITY);
|
||||
|
||||
offset.x = 0;
|
||||
offset.y = 0;
|
||||
|
||||
iw = img.getWidth(this);
|
||||
ih = img.getHeight(this);
|
||||
|
||||
bi = new BufferedImage( iw, ih, BufferedImage.TYPE_INT_RGB);
|
||||
big = bi.createGraphics();
|
||||
|
||||
big.drawImage(img, 0, 0, this);
|
||||
big.setPaint(Color.red);
|
||||
if ((rect.width > 0) && (rect.height > 0))
|
||||
big.draw(rect);
|
||||
|
||||
if( roirect != null){
|
||||
for( int i=0; i<roirect.length; i++)
|
||||
if( roirect[i] != null){
|
||||
big.draw( roirect[i]);
|
||||
big.drawString( roiname[i], roirect[i].x+3, roirect[i].y+roirect[i].height*2/3);
|
||||
}
|
||||
}
|
||||
if (selected == 1)
|
||||
shadeExt(big, 0, 0, 0, 64);
|
||||
else if (selected == 2) {
|
||||
shadeExt(big, 0, 0, 0, 255);
|
||||
selected = 1;
|
||||
}
|
||||
g2.drawImage(bi, offset.x, offset.y, this);
|
||||
}
|
||||
|
||||
private void shadeRect(Graphics2D g2, int r, int g, int b, int a)
|
||||
{
|
||||
g2.setPaint(new Color(r, g, b, a));
|
||||
g2.fillRect(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1);
|
||||
}
|
||||
|
||||
private void shadeExt(Graphics2D g2, int r, int g, int b, int a)
|
||||
{
|
||||
g2.setPaint(new Color(r, g, b, a));
|
||||
g2.fillRect(0, 0, iw, rect.y); /* _N_ */
|
||||
g2.fillRect(rect.x + rect.width + 1, rect.y,
|
||||
iw - rect.x - rect.width - 1, rect.height + 1); /* E */
|
||||
g2.fillRect(0, rect.y, rect.x, rect.height + 1); /* W */
|
||||
g2.fillRect(0, rect.y + rect.height + 1,
|
||||
iw, ih - rect.y - rect.height - 1); /* _S_ */
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* $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 javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class ImageWindow extends JFrame
|
||||
{
|
||||
private ImageViewer imgviewer;
|
||||
private OptionPanel optpanel;
|
||||
private ImageManager imgmanager;
|
||||
|
||||
public ImageWindow( String uri, String j2kfilename)
|
||||
{
|
||||
super( j2kfilename);
|
||||
|
||||
imgmanager = new ImageManager( uri);
|
||||
|
||||
imgviewer = new ImageViewer( j2kfilename, imgmanager);
|
||||
imgviewer.setOpaque(true); //content panes must be opaque
|
||||
|
||||
optpanel = new OptionPanel( imgmanager, imgviewer);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
panel.add( imgviewer, BorderLayout.CENTER);
|
||||
panel.add( optpanel, BorderLayout.EAST);
|
||||
|
||||
setContentPane( panel);
|
||||
|
||||
addWindowListener(new WindowMyAdapter());
|
||||
}
|
||||
|
||||
class WindowMyAdapter extends WindowAdapter
|
||||
{
|
||||
public void windowClosing(WindowEvent arg)
|
||||
{
|
||||
imgmanager.closeChannel();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String s[])
|
||||
{
|
||||
String j2kfilename, uri;
|
||||
|
||||
if(s.length > 0){
|
||||
uri = s[0];
|
||||
j2kfilename = s[1];
|
||||
}
|
||||
else{
|
||||
System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2");
|
||||
return;
|
||||
}
|
||||
ImageWindow frame = new ImageWindow( uri, j2kfilename);
|
||||
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
//Display the window.
|
||||
frame.pack();
|
||||
frame.setSize(new Dimension(400,200));
|
||||
frame.setLocation( 0, 50);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
|
@ -1,268 +0,0 @@
|
|||
/*
|
||||
* $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.io.*;
|
||||
import java.net.*;
|
||||
|
||||
public class ImgdecClient{
|
||||
|
||||
public static PnmImage decode_jptstream( byte[] jptstream, String cid, int fw, int fh)
|
||||
{
|
||||
if( jptstream != null)
|
||||
send_JPTstream( jptstream);
|
||||
return get_PNMstream( cid, fw, fh);
|
||||
}
|
||||
|
||||
public static PnmImage decode_jptstream( byte[] jptstream, String j2kfilename, String cid, int fw, int fh)
|
||||
{
|
||||
send_JPTstream( jptstream, j2kfilename, cid);
|
||||
return get_PNMstream( cid, fw, fh);
|
||||
}
|
||||
|
||||
public static void send_JPTstream( byte[] jptstream)
|
||||
{
|
||||
try{
|
||||
Socket imgdecSocket = new Socket( "localhost", 5000);
|
||||
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
|
||||
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
|
||||
|
||||
System.err.println("Sending " + jptstream.length + "Data Bytes to decodingServer");
|
||||
|
||||
os.writeBytes("JPT-stream\n");
|
||||
os.writeBytes("version 1.0\n");
|
||||
os.writeBytes( jptstream.length + "\n");
|
||||
os.write( jptstream, 0, jptstream.length);
|
||||
|
||||
byte signal = is.readByte();
|
||||
|
||||
if( signal == 0)
|
||||
System.err.println(" failed");
|
||||
} catch (UnknownHostException e) {
|
||||
System.err.println("Trying to connect to unknown host: " + e);
|
||||
} catch (IOException e) {
|
||||
System.err.println("IOException: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void send_JPTstream( byte[] jptstream, String j2kfilename, String cid)
|
||||
{
|
||||
try{
|
||||
Socket imgdecSocket = new Socket( "localhost", 5000);
|
||||
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
|
||||
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
|
||||
int length = 0;
|
||||
|
||||
if( jptstream != null)
|
||||
length = jptstream.length;
|
||||
|
||||
System.err.println("Sending " + length + "Data Bytes to decodingServer");
|
||||
|
||||
os.writeBytes("JPT-stream\n");
|
||||
os.writeBytes("version 1.0\n");
|
||||
os.writeBytes( j2kfilename + "\n");
|
||||
os.writeBytes( cid + "\n");
|
||||
os.writeBytes( length + "\n");
|
||||
os.write( jptstream, 0, length);
|
||||
|
||||
byte signal = is.readByte();
|
||||
|
||||
if( signal == 0)
|
||||
System.err.println(" failed");
|
||||
} catch (UnknownHostException e) {
|
||||
System.err.println("Trying to connect to unknown host: " + e);
|
||||
} catch (IOException e) {
|
||||
System.err.println("IOException: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static PnmImage get_PNMstream( String cid, int fw, int fh)
|
||||
{
|
||||
PnmImage pnmstream = new PnmImage();
|
||||
try {
|
||||
Socket imgdecSocket = new Socket( "localhost", 5000);
|
||||
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
|
||||
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
|
||||
byte []header = new byte[7];
|
||||
|
||||
os.writeBytes("PNM request\n");
|
||||
os.writeBytes( cid + "\n");
|
||||
os.writeBytes( fw + "\n");
|
||||
os.writeBytes( fh + "\n");
|
||||
|
||||
read_stream( is, header, 7);
|
||||
|
||||
if( header[0] == 80){
|
||||
// P5: gray, P6: color
|
||||
byte magicknum = header[1];
|
||||
if( magicknum == 5 || magicknum == 6){
|
||||
int length;
|
||||
boolean iscolor = magicknum==6 ? true:false;
|
||||
if( iscolor)
|
||||
pnmstream.channel = 3;
|
||||
else
|
||||
pnmstream.channel = 1;
|
||||
pnmstream.width = (header[2]&0xff)<<8 | (header[3]&0xff);
|
||||
pnmstream.height = (header[4]&0xff)<<8 | (header[5]&0xff);
|
||||
int maxval = header[6]&0xff;
|
||||
|
||||
if( maxval == 255){
|
||||
length = pnmstream.width*pnmstream.height*pnmstream.channel;
|
||||
pnmstream.data = new byte [ length];
|
||||
read_stream( is, pnmstream.data, length);
|
||||
}
|
||||
else
|
||||
System.err.println("Error in get_PNMstream(), only 255 is accepted");
|
||||
}
|
||||
else
|
||||
System.err.println("Error in get_PNMstream(), wrong magick number" + header[1]);
|
||||
}
|
||||
else
|
||||
System.err.println("Error in get_PNMstream(), Not starting with P");
|
||||
os.close();
|
||||
is.close();
|
||||
imgdecSocket.close();
|
||||
} catch (UnknownHostException e) {
|
||||
System.err.println("Trying to connect to unknown host: " + e);
|
||||
} catch (IOException e) {
|
||||
System.err.println("IOException: " + e);
|
||||
}
|
||||
return pnmstream;
|
||||
}
|
||||
|
||||
public static byte [] get_XMLstream( String cid)
|
||||
{
|
||||
byte []xmldata = null;
|
||||
|
||||
try{
|
||||
Socket imgdecSocket = new Socket( "localhost", 5000);
|
||||
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
|
||||
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
|
||||
byte []header = new byte[5];
|
||||
|
||||
os.writeBytes("XML request\n");
|
||||
os.writeBytes( cid + "\n");
|
||||
|
||||
read_stream( is, header, 5);
|
||||
|
||||
if( header[0] == 88 && header[1] == 77 && header[2] == 76){
|
||||
int length = (header[3]&0xff)<<8 | (header[4]&0xff);
|
||||
|
||||
xmldata = new byte[ length];
|
||||
read_stream( is, xmldata, length);
|
||||
}
|
||||
else
|
||||
System.err.println("Error in get_XMLstream(), not starting with XML");
|
||||
} catch (UnknownHostException e) {
|
||||
System.err.println("Trying to connect to unknown host: " + e);
|
||||
} catch (IOException e) {
|
||||
System.err.println("IOException: " + e);
|
||||
}
|
||||
return xmldata;
|
||||
}
|
||||
|
||||
public static String query_cid( String j2kfilename)
|
||||
{
|
||||
String cid = null;
|
||||
|
||||
try{
|
||||
Socket imgdecSocket = new Socket( "localhost", 5000);
|
||||
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
|
||||
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
|
||||
byte []header = new byte[4];
|
||||
|
||||
os.writeBytes("CID request\n");
|
||||
os.writeBytes( j2kfilename + "\n");
|
||||
|
||||
read_stream( is, header, 4);
|
||||
|
||||
if( header[0] == 67 && header[1] == 73 && header[2] == 68){
|
||||
int length = header[3]&0xff;
|
||||
|
||||
if( length > 0){
|
||||
|
||||
byte []ciddata = new byte[ length];
|
||||
read_stream( is, ciddata, length);
|
||||
cid = new String( ciddata);
|
||||
}
|
||||
}
|
||||
else
|
||||
System.err.println("Error in query_cid(), not starting with CID");
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
System.err.println("Trying to connect to unknown host: " + e);
|
||||
} catch (IOException e) {
|
||||
System.err.println("IOException: " + e);
|
||||
}
|
||||
|
||||
return cid;
|
||||
}
|
||||
|
||||
public static void read_stream( DataInputStream is, byte []stream, int length)
|
||||
{
|
||||
int remlen = length;
|
||||
int off = 0;
|
||||
|
||||
try{
|
||||
while( remlen > 0){
|
||||
int redlen = is.read( stream, off, remlen);
|
||||
|
||||
if( redlen == -1){
|
||||
System.err.println(" failed to read_stream()");
|
||||
break;
|
||||
}
|
||||
off += redlen;
|
||||
remlen -= redlen;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("IOException: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void destroy_cid( String cid)
|
||||
{
|
||||
try{
|
||||
Socket imgdecSocket = new Socket( "localhost", 5000);
|
||||
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
|
||||
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
|
||||
|
||||
os.writeBytes("CID destroy\n");
|
||||
os.writeBytes( cid + "\n");
|
||||
|
||||
byte signal = is.readByte();
|
||||
|
||||
if( signal == 0)
|
||||
System.err.println(" failed");
|
||||
} catch (UnknownHostException e) {
|
||||
System.err.println("Trying to connect to unknown host: " + e);
|
||||
} catch (IOException e) {
|
||||
System.err.println("IOException: " + e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
/*
|
||||
* $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 org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.apache.xerces.parsers.DOMParser;
|
||||
import org.xml.sax.InputSource;
|
||||
import java.io.*;
|
||||
import java.lang.Integer;
|
||||
|
||||
public class JP2XMLparser
|
||||
{
|
||||
Document document;
|
||||
|
||||
public static class ROIparams{
|
||||
public String name = null;
|
||||
public int x = 0;
|
||||
public int y = 0;
|
||||
public int w = 0;
|
||||
public int h = 0;
|
||||
}
|
||||
|
||||
public static class IRTparams{
|
||||
public String refimg = null;
|
||||
public double []mat = { 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
|
||||
}
|
||||
|
||||
public JP2XMLparser( byte[] buf)
|
||||
{
|
||||
try{
|
||||
InputSource source = new InputSource( new ByteArrayInputStream( buf));
|
||||
DOMParser parser = new DOMParser();
|
||||
parser.setErrorHandler(new MyHandler());
|
||||
parser.parse( source);
|
||||
document = parser.getDocument();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public ROIparams [] getROIparams()
|
||||
{
|
||||
ROIparams roi[];
|
||||
NodeList elements = document.getElementsByTagName("roi");
|
||||
int elementCount = elements.getLength();
|
||||
|
||||
roi = new ROIparams [elementCount];
|
||||
|
||||
for( int i = 0; i < elementCount; i++) {
|
||||
Element element = (Element)elements.item(i);
|
||||
|
||||
roi[i] = new ROIparams();
|
||||
roi[i].name = element.getAttribute( "name");
|
||||
roi[i].x = Integer.parseInt( element.getAttribute( "x")) ;
|
||||
roi[i].y = Integer.parseInt( element.getAttribute( "y")) ;
|
||||
roi[i].w = Integer.parseInt( element.getAttribute( "w")) ;
|
||||
roi[i].h = Integer.parseInt( element.getAttribute( "h")) ;
|
||||
}
|
||||
return roi;
|
||||
}
|
||||
|
||||
public IRTparams getIRTparams()
|
||||
{
|
||||
IRTparams irt = new IRTparams();
|
||||
NodeList elements = document.getElementsByTagName("irt");
|
||||
int elementCount = elements.getLength();
|
||||
|
||||
Element element = (Element)elements.item(0);
|
||||
irt.refimg = element.getAttribute( "refimg");
|
||||
for( int i=1; i<=9; i++)
|
||||
irt.mat[i-1] = Double.parseDouble( element.getAttribute("m" + i));
|
||||
|
||||
return irt;
|
||||
}
|
||||
}
|
||||
|
||||
class MyHandler implements ErrorHandler {
|
||||
public void warning(SAXParseException e) {
|
||||
System.out.println("Warning: line" + e.getLineNumber());
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
public void error(SAXParseException e) {
|
||||
System.out.println("Error: line" + e.getLineNumber());
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
public void fatalError(SAXParseException e) {
|
||||
System.out.println("Critical error: line" + e.getLineNumber());
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
|
@ -1,301 +0,0 @@
|
|||
/*
|
||||
* $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.net.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class JPIPHttpClient
|
||||
{
|
||||
private String comURL;
|
||||
protected int fw, fh;
|
||||
protected int rx, ry;
|
||||
protected int rw, rh;
|
||||
protected String cid;
|
||||
|
||||
public JPIPHttpClient( String URI)
|
||||
{
|
||||
comURL = URI + "?";
|
||||
fw = fh = -1;
|
||||
rx = ry = -1;
|
||||
rw = rh = -1;
|
||||
cid = null;
|
||||
}
|
||||
|
||||
public int getFw(){ return fw;}
|
||||
public int getFh(){ return fh;}
|
||||
public int getRx(){ return rx;}
|
||||
public int getRy(){ return ry;}
|
||||
public int getRw(){ return rw;}
|
||||
public int getRh(){ return rh;}
|
||||
|
||||
public byte[] requestViewWindow( int reqfw, int reqfh)
|
||||
{
|
||||
if( cid != null)
|
||||
return requestViewWindow( reqfw, reqfh, cid);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] requestViewWindow( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh)
|
||||
{
|
||||
if( cid != null)
|
||||
return requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh, cid);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid)
|
||||
{
|
||||
return requestViewWindow( null, reqfw, reqfh, -1, -1, -1, -1, reqcid, false);
|
||||
}
|
||||
|
||||
public byte[] requestViewWindow( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh, String reqcid)
|
||||
{
|
||||
return requestViewWindow( null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, false);
|
||||
}
|
||||
|
||||
public byte[] requestViewWindow( String target, int reqfw, int reqfh)
|
||||
{
|
||||
return requestViewWindow( target, reqfw, reqfh, -1, -1, -1, -1, null, false);
|
||||
}
|
||||
|
||||
public byte[] requestViewWindow( String target, int reqfw, int reqfh, boolean reqcnew)
|
||||
{
|
||||
if( cid == null) // 1 channel allocation only
|
||||
return requestViewWindow( target, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] requestViewWindow( String target, int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh)
|
||||
{
|
||||
return requestViewWindow( target, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, null, false);
|
||||
}
|
||||
|
||||
|
||||
public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid, boolean reqcnew)
|
||||
{
|
||||
return requestViewWindow( null, reqfw, reqfh, -1, -1, -1, -1, reqcid, reqcnew);
|
||||
}
|
||||
|
||||
public byte[] requestViewWindow( String target,
|
||||
int reqfw, int reqfh,
|
||||
int reqrx, int reqry,
|
||||
int reqrw, int reqrh,
|
||||
String reqcid, boolean reqcnew)
|
||||
{
|
||||
String urlstring = const_urlstring( target, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, reqcnew);
|
||||
return GETrequest( urlstring);
|
||||
}
|
||||
|
||||
public byte[] requestXML()
|
||||
{
|
||||
String urlstring = comURL;
|
||||
|
||||
if( cid == null)
|
||||
return null;
|
||||
|
||||
urlstring = urlstring.concat( "cid=" + cid);
|
||||
urlstring = urlstring.concat( "&metareq=[xml_]");
|
||||
|
||||
return GETrequest( urlstring);
|
||||
}
|
||||
|
||||
private byte[] GETrequest( String urlstring)
|
||||
{
|
||||
int buflen = 0;
|
||||
URL url = null;
|
||||
HttpURLConnection urlconn = null;
|
||||
byte[] jptstream = null;
|
||||
|
||||
try{
|
||||
url = new URL( urlstring);
|
||||
|
||||
System.err.println("Requesting: " + url);
|
||||
|
||||
urlconn = (HttpURLConnection)url.openConnection();
|
||||
urlconn.setRequestMethod("GET");
|
||||
urlconn.setInstanceFollowRedirects(false);
|
||||
urlconn.connect();
|
||||
|
||||
Map<String,java.util.List<String>> headers = urlconn.getHeaderFields();
|
||||
java.util.List<String> hvaluelist;
|
||||
|
||||
if(( hvaluelist = headers.get("JPIP-fsiz")) != null){
|
||||
String hvalueline = hvaluelist.get(0);
|
||||
fw = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue();
|
||||
fh = Integer.valueOf( hvalueline.substring( hvalueline.indexOf(',')+1 )).intValue();
|
||||
|
||||
System.err.println("fw,fh: " + fw + "," + fh);
|
||||
}
|
||||
|
||||
if(( hvaluelist = headers.get("JPIP-roff")) != null){
|
||||
String hvalueline = hvaluelist.get(0);
|
||||
rx = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue();
|
||||
ry = Integer.valueOf( hvalueline.substring( hvalueline.indexOf(',')+1 )).intValue();
|
||||
System.err.println("rx,ry: " + rx + "," + ry);
|
||||
}
|
||||
|
||||
if(( hvaluelist = headers.get("JPIP-rsiz")) != null){
|
||||
String hvalueline = hvaluelist.get(0);
|
||||
rw = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue();
|
||||
rh = Integer.valueOf( hvalueline.substring( hvalueline.indexOf(',')+1 )).intValue();
|
||||
System.err.println("rw,rh: " + rw + "," + rh);
|
||||
}
|
||||
|
||||
if(( hvaluelist = headers.get("JPIP-cnew")) != null){
|
||||
String hvalueline = hvaluelist.get(0);
|
||||
cid = hvalueline.substring( hvalueline.indexOf('=')+1, hvalueline.indexOf(','));
|
||||
System.err.println("cid: " + cid);
|
||||
}
|
||||
|
||||
InputStream input = urlconn.getInputStream();
|
||||
buflen = input.available();
|
||||
|
||||
if( buflen > 0){
|
||||
ByteArrayOutputStream tmpstream = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[ 1024];
|
||||
|
||||
System.err.println("reading jptstream...");
|
||||
|
||||
int redlen;
|
||||
do{
|
||||
redlen = input.read( buf);
|
||||
|
||||
if( redlen == -1)
|
||||
break;
|
||||
tmpstream.write( buf, 0, redlen);
|
||||
}while( redlen > 0);
|
||||
|
||||
buflen = tmpstream.size();
|
||||
|
||||
jptstream = tmpstream.toByteArray();
|
||||
|
||||
tmpstream = null;
|
||||
|
||||
System.err.println("jptlen: " + buflen);
|
||||
System.err.println(" succeeded");
|
||||
}
|
||||
else{
|
||||
System.err.println("No new jptstream");
|
||||
}
|
||||
input.close();
|
||||
}
|
||||
catch ( MalformedURLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch ( ProtocolException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch( ClassCastException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch( NullPointerException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch( UnknownServiceException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch ( IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
urlconn.disconnect();
|
||||
|
||||
return jptstream;
|
||||
}
|
||||
|
||||
private String const_urlstring( String target,
|
||||
int reqfw, int reqfh,
|
||||
int reqrx, int reqry,
|
||||
int reqrw, int reqrh,
|
||||
String reqcid, boolean reqcnew)
|
||||
{
|
||||
String urlstring = comURL;
|
||||
|
||||
if( target != null){
|
||||
if( !urlstring.endsWith("?"))
|
||||
urlstring = urlstring.concat( "&");
|
||||
urlstring = urlstring.concat( "target=" + target);
|
||||
}
|
||||
if( reqfw != -1 && reqfh != -1){
|
||||
if( !urlstring.endsWith("?"))
|
||||
urlstring = urlstring.concat( "&");
|
||||
urlstring = urlstring.concat( "fsiz=" + reqfw + "," + reqfh);
|
||||
}
|
||||
if( reqrx != -1 && reqry != -1){
|
||||
if( !urlstring.endsWith("?"))
|
||||
urlstring = urlstring.concat( "&");
|
||||
urlstring = urlstring.concat( "roff=" + reqrx + "," + reqry);
|
||||
}
|
||||
if( reqrw != -1 && reqrh != -1){
|
||||
if( !urlstring.endsWith("?"))
|
||||
urlstring = urlstring.concat( "&");
|
||||
urlstring = urlstring.concat( "rsiz=" + reqrw + "," + reqrh);
|
||||
}
|
||||
if( reqcid != null){
|
||||
if( !urlstring.endsWith("?"))
|
||||
urlstring = urlstring.concat( "&");
|
||||
urlstring = urlstring.concat( "cid=" + reqcid);
|
||||
}
|
||||
if( reqcnew){
|
||||
if( !urlstring.endsWith("?"))
|
||||
urlstring = urlstring.concat( "&");
|
||||
urlstring = urlstring.concat( "cnew=http");
|
||||
}
|
||||
return urlstring;
|
||||
}
|
||||
|
||||
public void closeChannel()
|
||||
{
|
||||
if( cid == null)
|
||||
return;
|
||||
|
||||
try{
|
||||
URL url = new URL( comURL + "cclose=" + cid);
|
||||
System.err.println( "closing cid: " + cid);
|
||||
|
||||
HttpURLConnection urlconn = (HttpURLConnection)url.openConnection();
|
||||
urlconn.setRequestMethod("GET");
|
||||
urlconn.setInstanceFollowRedirects(false);
|
||||
urlconn.connect();
|
||||
|
||||
Map headers = urlconn.getHeaderFields();
|
||||
|
||||
urlconn.disconnect();
|
||||
} catch ( MalformedURLException e){
|
||||
e.printStackTrace();
|
||||
} catch ( IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
/*
|
||||
* $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.event.*;
|
||||
|
||||
class MML implements MouseMotionListener, MouseListener
|
||||
{
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
public void mouseClicked(MouseEvent e) {}
|
||||
|
||||
private ImageViewer iv;
|
||||
private int x1, y1, x2, y2, zf, btn;
|
||||
private boolean zoomrq;
|
||||
|
||||
public MML(ImageViewer imageviewer)
|
||||
{
|
||||
x1 = y1 = -1;
|
||||
iv = imageviewer;
|
||||
zoomrq = false;
|
||||
zf = 0;
|
||||
}
|
||||
|
||||
private boolean isInside(int x, int y)
|
||||
{
|
||||
x -= iv.getX();
|
||||
y -= iv.getY();
|
||||
return (x >= 0) && (x < iv.getWidth())
|
||||
&& (y >= 0) && (y < iv.getHeight());
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e)
|
||||
{
|
||||
btn = e.getButton();
|
||||
|
||||
if( iv.hasAnnotation()){
|
||||
if( iv.isInsideROIRect(e.getX(), e.getY())){
|
||||
iv.zoomIn();
|
||||
System.out.println("annotation click");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (iv.isInsideRect(e.getX(), e.getY())) {
|
||||
iv.setSelected(2);
|
||||
iv.repaint();
|
||||
zoomrq = true;
|
||||
} else {
|
||||
iv.setRGeom(0, 0, 0, 0);
|
||||
iv.setSelected(0);
|
||||
iv.repaint();
|
||||
x1 = y1 = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e)
|
||||
{
|
||||
if(e.getButton() == 1) {
|
||||
if (zoomrq) {
|
||||
iv.zoomIn();
|
||||
zoomrq = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseMoved(MouseEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void mouseDragged(MouseEvent e)
|
||||
{
|
||||
if (btn == 1) {
|
||||
x2 = e.getX();
|
||||
y2 = e.getY();
|
||||
|
||||
iv.setSelected(0);
|
||||
zoomrq = false;
|
||||
|
||||
if (isInside(x2, y2)) {
|
||||
if (x1 == -1) {
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
} else {
|
||||
iv.setRGeom(x1, y1, x2, y2);
|
||||
iv.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* $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.*;
|
||||
|
||||
public class OptionPanel extends JPanel implements ActionListener
|
||||
{
|
||||
private JButton roibutton;
|
||||
private JButton imregbutton;
|
||||
private ImageManager imgmanager;
|
||||
private ImageViewer iv;
|
||||
private JP2XMLparser xmlparser;
|
||||
private JFrame regimwindow;
|
||||
private RegimViewer regimgviewer;
|
||||
|
||||
public OptionPanel( ImageManager manager, ImageViewer imgviewer)
|
||||
{
|
||||
this.setLayout(new BoxLayout( this, BoxLayout.Y_AXIS));
|
||||
|
||||
roibutton = new JButton("Region Of Interest");
|
||||
imregbutton = new JButton("Image Registration");
|
||||
|
||||
roibutton.setAlignmentX( Component.CENTER_ALIGNMENT);
|
||||
imregbutton.setAlignmentX( Component.CENTER_ALIGNMENT);
|
||||
|
||||
add( roibutton);
|
||||
add( imregbutton);
|
||||
roibutton.addActionListener(this);
|
||||
imregbutton.addActionListener(this);
|
||||
|
||||
imgmanager = manager;
|
||||
iv = imgviewer;
|
||||
xmlparser = null;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
if( xmlparser == null){
|
||||
byte []xmldata = imgmanager.getXML();
|
||||
if( xmldata != null)
|
||||
xmlparser = new JP2XMLparser( xmldata);
|
||||
}
|
||||
if( e.getSource() == roibutton){
|
||||
if( xmlparser != null){
|
||||
JP2XMLparser.ROIparams roi[] = xmlparser.getROIparams();
|
||||
iv.annotate( roi);
|
||||
}
|
||||
}
|
||||
if( e.getSource() == imregbutton){
|
||||
if( xmlparser != null){
|
||||
if( regimwindow == null){
|
||||
JP2XMLparser.IRTparams irt = xmlparser.getIRTparams();
|
||||
|
||||
regimgviewer = new RegimViewer( irt.refimg, irt.mat);
|
||||
regimgviewer.setOpaque(false);
|
||||
|
||||
regimwindow = new JFrame("Registered Image");
|
||||
regimwindow.getContentPane().add("Center", regimgviewer);
|
||||
regimwindow.pack();
|
||||
regimwindow.setLocation( 500, 50);
|
||||
regimwindow.setVisible(true);
|
||||
}
|
||||
regimgviewer.projection( iv.getImage(), (double)imgmanager.getRw()/(double)imgmanager.getOrigWidth());
|
||||
regimwindow.setSize( regimgviewer.get_imsize());
|
||||
regimwindow.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
/*
|
||||
* $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.image.*;
|
||||
import java.io.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class PnmImage extends Component
|
||||
{
|
||||
public byte[] data = null;
|
||||
public int width = 0;
|
||||
public int height = 0;
|
||||
public int channel = 0;
|
||||
|
||||
public Image createROIImage( int rx, int ry, int rw, int rh)
|
||||
{
|
||||
int []pix = new int[ rw*rh];
|
||||
|
||||
for( int i=0; i<rh; i++)
|
||||
for( int j=0; j<rw; j++){
|
||||
pix[i*rw+j] = 0xFF << 24; // transparency
|
||||
if( channel == 1){
|
||||
Byte lum = data[(ry+i)*width+rx+j];
|
||||
short slum;
|
||||
|
||||
if( lum < 0)
|
||||
slum = (short)(2*128+lum);
|
||||
else
|
||||
slum = (short)lum;
|
||||
|
||||
for( int c=0; c<3; c++){
|
||||
pix[i*rw+j] = pix[i*rw+j] | slum << (8*c);
|
||||
}
|
||||
}
|
||||
else
|
||||
for( int c=0; c<3; c++){
|
||||
Byte lum = data[ ((ry+i)*width+rx+j)*channel+(2-c)];
|
||||
short slum;
|
||||
|
||||
if( lum < 0)
|
||||
slum = (short)(2*128+lum);
|
||||
else
|
||||
slum = (short)lum;
|
||||
|
||||
pix[i*rw+j] = pix[i*rw+j] | slum << (8*c);
|
||||
}
|
||||
}
|
||||
return createImage(new MemoryImageSource( rw, rh, pix, 0, rw));
|
||||
}
|
||||
|
||||
public Image createScaleImage( double scale)
|
||||
{
|
||||
Image src = createROIImage( 0, 0, width, height);
|
||||
ImageFilter replicate = new ReplicateScaleFilter( (int)(width*scale), (int)(height*scale));
|
||||
ImageProducer prod = new FilteredImageSource( src.getSource(), replicate);
|
||||
|
||||
return createImage(prod);
|
||||
}
|
||||
|
||||
public void openimage( String filename)
|
||||
{
|
||||
String str;
|
||||
Pattern pat;
|
||||
Matcher mat;
|
||||
int bytes;
|
||||
int r, offset = 0;
|
||||
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream( new File(filename));
|
||||
DataInputStream is = new DataInputStream( fis);
|
||||
|
||||
pat = Pattern.compile("^P([56])$");
|
||||
mat = pat.matcher(str = is.readLine());
|
||||
if( !mat.matches()){
|
||||
System.out.println("PNM header format error");
|
||||
return;
|
||||
}
|
||||
|
||||
if( (mat.group(1)).compareTo("5") == 0)
|
||||
channel = 1;
|
||||
else
|
||||
channel = 3;
|
||||
|
||||
pat = Pattern.compile("^(\\d+) (\\d+)$");
|
||||
mat = pat.matcher(str = is.readLine());
|
||||
if( !mat.matches()){
|
||||
System.out.println("PNM header format error");
|
||||
return;
|
||||
}
|
||||
width = Integer.parseInt( mat.group(1));
|
||||
height = Integer.parseInt( mat.group(2));
|
||||
|
||||
str = is.readLine(); // 255
|
||||
|
||||
bytes = width*height*channel;
|
||||
data = new byte[bytes];
|
||||
|
||||
while( bytes > 0){
|
||||
try {
|
||||
r = is.read(data, offset, bytes);
|
||||
if( r == -1){
|
||||
System.err.println(" failed to read()");
|
||||
break;
|
||||
}
|
||||
offset += r;
|
||||
bytes -= r;
|
||||
}
|
||||
catch (IOException e) { e.printStackTrace(); }
|
||||
}
|
||||
fis.close();
|
||||
} catch (IOException e) { e.printStackTrace(); }
|
||||
}
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* $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 javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
public class RegimViewer extends JPanel
|
||||
{
|
||||
private PnmImage refpnm;
|
||||
private int vw, vh;
|
||||
private Image refimg;
|
||||
private Image jpipImg;
|
||||
private double[] affine_matrix;
|
||||
private AffineTransform affine;
|
||||
|
||||
public RegimViewer( String refname, double[] mat)
|
||||
{
|
||||
refpnm = new PnmImage();
|
||||
refpnm.openimage(refname.replaceFirst("jp2", "pgm")); // decoding not realized
|
||||
affine_matrix = new double[6];
|
||||
|
||||
affine_matrix[0] = mat[0];
|
||||
affine_matrix[1] = mat[3];
|
||||
affine_matrix[2] = mat[1];
|
||||
affine_matrix[3] = mat[4];
|
||||
affine_matrix[4] = mat[2];
|
||||
affine_matrix[5] = mat[5];
|
||||
|
||||
affine = new AffineTransform();
|
||||
|
||||
for( int i=0; i<3; i++){
|
||||
for( int j=0; j<3; j++)
|
||||
System.out.print( mat[i*3+j] + " ");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
public void projection( Image jpipimg, double scale)
|
||||
{
|
||||
jpipImg = jpipimg;
|
||||
refimg = refpnm.createScaleImage( scale);
|
||||
vw = refimg.getWidth(this);
|
||||
vh = refimg.getHeight(this);
|
||||
this.setSize( vw, vh);
|
||||
|
||||
affine.setTransform( affine_matrix[0], affine_matrix[1], affine_matrix[2], affine_matrix[3], affine_matrix[4], affine_matrix[5]);
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
int iw, ih;
|
||||
BufferedImage bi, bi2;
|
||||
Graphics2D big, big2;
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
g2.clearRect(0, 0, vw, vh);
|
||||
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHint(RenderingHints.KEY_RENDERING,
|
||||
RenderingHints.VALUE_RENDER_QUALITY);
|
||||
|
||||
iw = refimg.getWidth(this);
|
||||
ih = refimg.getHeight(this);
|
||||
|
||||
bi = new BufferedImage( iw, ih, BufferedImage.TYPE_INT_RGB);
|
||||
big = bi.createGraphics();
|
||||
big.drawImage(refimg, 0, 0, this);
|
||||
|
||||
g2.drawImage(bi, 0, 0, this);
|
||||
|
||||
bi2 = new BufferedImage( jpipImg.getWidth(this), jpipImg.getHeight(this), BufferedImage.TYPE_INT_RGB);
|
||||
big2 = bi2.createGraphics();
|
||||
big2.drawImage( jpipImg, 0, 0, this);
|
||||
|
||||
g2.setTransform(affine);
|
||||
|
||||
g2.drawImage(bi2, 0, 0, this);
|
||||
}
|
||||
|
||||
public Dimension get_imsize()
|
||||
{
|
||||
return (new Dimension( vw, vh));
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* $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.*;
|
||||
|
||||
class ResizeListener implements ComponentListener
|
||||
{
|
||||
private ImageViewer iv;
|
||||
private Dimension largest;
|
||||
|
||||
public ResizeListener( ImageViewer _iv)
|
||||
{
|
||||
iv = _iv;
|
||||
largest = iv.getSize();
|
||||
}
|
||||
|
||||
public void componentHidden(ComponentEvent e) {}
|
||||
|
||||
public void componentMoved(ComponentEvent e) {}
|
||||
|
||||
public void componentResized(ComponentEvent e) {
|
||||
Dimension cursize = iv.getSize();
|
||||
if( largest.getWidth() < cursize.getWidth() || largest.getHeight() < cursize.getHeight()){
|
||||
largest = cursize;
|
||||
iv.enlarge();
|
||||
}
|
||||
}
|
||||
|
||||
public void componentShown(ComponentEvent e) {}
|
||||
}
|
Loading…
Reference in New Issue