diff --git a/applications/jpip/CHANGES b/applications/jpip/CHANGES index a50407cf..33570d16 100644 --- a/applications/jpip/CHANGES +++ b/applications/jpip/CHANGES @@ -7,6 +7,7 @@ What's New for OpenJPIP February 9, 2012 * [kaori] fixed Doxygen configuration file to document the utilities ++ [kaori] added execution argument to set port number for opj_dec_server, opj_viewer* January 26, 2012 ! [kaori] unapplied auxtrans_manager to the local mode diff --git a/applications/jpip/README b/applications/jpip/README index 219e0c41..68befe36 100644 --- a/applications/jpip/README +++ b/applications/jpip/README @@ -96,7 +96,7 @@ Server: Client: 1. Launch image decoding server, and keep it alive as long as image viewers are open - % ./opj_dec_server + % ./opj_dec_server [portnumber (50000 by default)] You might prefer to implement this program from another directory since cache files are saved in the working directory. % mkdir cache @@ -104,10 +104,12 @@ Client: % ../opj_dec_server 2. Open image viewers (as many as needed) - % java -jar opj_viewer.jar http://hostname/myFCGI path/filename.jp2 [stateless/session] [jptstream/jppstream] [tcp/udp] + % java -jar opj_viewer.jar http://hostname/myFCGI path/filename.jp2 [hostname] [portnumber] [stateless/session] [jptstream/jppstream] [tcp/udp] ( The arguments - http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting) - path/filename.jp2 is the server local path or URL of a JP2 file + - host name of opj_dec_server, localhost by default + - portnumber of opj_dec_server, 50000 by default - request type stateless for no caching, session (default) for caching - return media type, JPT-stream tile based stream, or JPP-stream (default) precinct based stream - auxiliary return protocol, tcp or udp (udp is not implemented yet), if not given, return data is filled in http chunk diff --git a/applications/jpip/util/opj_dec_server.c b/applications/jpip/util/opj_dec_server.c index 0ad3a052..d94d8c9b 100644 --- a/applications/jpip/util/opj_dec_server.c +++ b/applications/jpip/util/opj_dec_server.c @@ -33,11 +33,12 @@ * * \section impinst Implementing instructions * Launch opj_dec_server from a terminal in the same machine as JPIP client image viewers. \n - * % ./opj_dec_server \n + * % ./opj_dec_server [portnumber]\n + * ( portnumber=50000 by default)\n * Keep it alive as long as image viewers are open.\n * * To quite the opj_dec_server, send a message "quit" through the telnet.\n - * % telnet localhost 5000\n + * % telnet localhost 50000\n * quit\n * Be sure all image viewers are closed.\n * Cache file in JPT format is stored in the working directly before it quites. @@ -45,6 +46,7 @@ */ #include +#include #include "openjpip.h" #ifdef _WIN32 @@ -55,6 +57,10 @@ int main(int argc, char *argv[]){ dec_server_record_t *server_record; client_t client; + int port = 50000; + + if( argc > 1) + port = atoi( argv[1]); #ifdef _WIN32 int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32); @@ -64,7 +70,7 @@ int main(int argc, char *argv[]){ printf( "Initialisation Winsock\n"); #endif //_WIN32 - server_record = init_dec_server( 50000); + server_record = init_dec_server( port); while(( client = accept_connection( server_record)) != -1 ) if(!handle_clientreq( client, server_record)) diff --git a/applications/jpip/util/opj_viewer/src/ImageManager.java b/applications/jpip/util/opj_viewer/src/ImageManager.java index 5251d03c..aad3ffaa 100644 --- a/applications/jpip/util/opj_viewer/src/ImageManager.java +++ b/applications/jpip/util/opj_viewer/src/ImageManager.java @@ -35,10 +35,12 @@ public class ImageManager extends JPIPHttpClient private PnmImage pnmimage; private int origwidth; private int origheight; + private ImgdecClient imgdecoder; - public ImageManager( String uri) + public ImageManager( String uri, String host, int port) { super( uri); + imgdecoder = new ImgdecClient( host, port); pnmimage = null; origwidth = 0; origheight = 0; @@ -47,7 +49,7 @@ public class ImageManager extends JPIPHttpClient public int getOrigWidth(){ if( origwidth == 0){ if( cid != null || tid != null){ - java.awt.Dimension dim = ImgdecClient.query_imagesize( cid, tid); + java.awt.Dimension dim = imgdecoder.query_imagesize( cid, tid); if( dim != null){ origwidth = dim.width; origheight = dim.height; @@ -69,10 +71,10 @@ public class ImageManager extends JPIPHttpClient // Todo: check if the cid is for the same stream type if( reqcnew) - refcid = ImgdecClient.query_cid( j2kfilename); + refcid = imgdecoder.query_cid( j2kfilename); if( refcid == null){ - String reftid = ImgdecClient.query_tid( j2kfilename); + String reftid = imgdecoder.query_tid( j2kfilename); if( reftid == null) jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, reqcnew, reqaux, reqJPP, reqJPT); else @@ -82,7 +84,7 @@ public class ImageManager extends JPIPHttpClient jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, reqcnew, reqaux, reqJPP, reqJPT); System.err.println( "decoding to PNM image"); - if((pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh))!=null){ + if((pnmimage = imgdecoder.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh))!=null){ System.err.println( " done"); return pnmimage.createROIImage( rx, ry, rw, rh); } @@ -99,7 +101,7 @@ public class ImageManager extends JPIPHttpClient byte[] jpipstream = super.requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh); System.err.println( "decoding to PNM image"); - if((pnmimage = ImgdecClient.decode_jpipstream( jpipstream, tid, cid, fw, fh)) != null){ + if((pnmimage = imgdecoder.decode_jpipstream( jpipstream, tid, cid, fw, fh)) != null){ System.err.println( " done"); return pnmimage.createROIImage( rx, ry, rw, rh); } @@ -117,9 +119,9 @@ public class ImageManager extends JPIPHttpClient byte[] jpipstream = super.requestXML(); if( jpipstream != null){ - ImgdecClient.send_JPIPstream( jpipstream); + imgdecoder.send_JPIPstream( jpipstream); - xmldata = ImgdecClient.get_XMLstream( cid); + xmldata = imgdecoder.get_XMLstream( cid); } return xmldata; } @@ -127,7 +129,7 @@ public class ImageManager extends JPIPHttpClient public void closeChannel() { if( cid != null){ - ImgdecClient.destroy_cid( cid); + imgdecoder.destroy_cid( cid); super.closeChannel(); } } diff --git a/applications/jpip/util/opj_viewer/src/ImageWindow.java b/applications/jpip/util/opj_viewer/src/ImageWindow.java index 5cf94db6..9a236e4a 100644 --- a/applications/jpip/util/opj_viewer/src/ImageWindow.java +++ b/applications/jpip/util/opj_viewer/src/ImageWindow.java @@ -37,11 +37,11 @@ public class ImageWindow extends JFrame private ImageViewer imgviewer; private ImageManager imgmanager; - public ImageWindow( String uri, String j2kfilename, boolean session, boolean jppstream, int aux) + public ImageWindow( String uri, String j2kfilename, String host, int port, boolean session, boolean jppstream, int aux) { super( j2kfilename); - imgmanager = new ImageManager( uri); + imgmanager = new ImageManager( uri, host, port); imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream, aux); imgviewer.setOpaque(true); //content panes must be opaque @@ -66,25 +66,36 @@ public class ImageWindow extends JFrame public static void main(String s[]) { - String j2kfilename, uri; + String j2kfilename, uri, host; boolean session, jppstream; - int aux; // 0: none, 1: tcp, 2: udp - + int port, aux; // 0: none, 1: tcp, 2: udp + if(s.length >= 2){ uri = s[0]; j2kfilename = s[1]; + if( s.length > 2) - session = !s[2].equalsIgnoreCase( "stateless"); + host = s[2]; + else + host = "localhost"; + + if( s.length > 3) + port = Integer.valueOf( s[3]).intValue(); + else + port = 50000; + + if( s.length > 4) + session = !s[4].equalsIgnoreCase( "stateless"); else session = true; - - if( s.length > 3) - jppstream = !s[3].equalsIgnoreCase( "JPT"); + + if( s.length > 5) + jppstream = !s[5].equalsIgnoreCase( "JPT"); else jppstream = true; - - if( s.length > 4){ - if( s[4].equalsIgnoreCase("udp")) + + if( s.length > 6){ + if( s[6].equalsIgnoreCase("udp")) aux = 2; else aux = 1; @@ -93,10 +104,10 @@ public class ImageWindow extends JFrame aux = 0; } else{ - System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [stateless/session] [JPT/JPP] [tcp/udp]"); + System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [hostname] [portnumber] [stateless/session] [JPT/JPP] [tcp/udp]"); return; } - ImageWindow frame = new ImageWindow( uri, j2kfilename, session, jppstream, aux); + ImageWindow frame = new ImageWindow( uri, j2kfilename, host, port, session, jppstream, aux); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); diff --git a/applications/jpip/util/opj_viewer/src/ImgdecClient.java b/applications/jpip/util/opj_viewer/src/ImgdecClient.java index 27750de7..edb64ded 100644 --- a/applications/jpip/util/opj_viewer/src/ImgdecClient.java +++ b/applications/jpip/util/opj_viewer/src/ImgdecClient.java @@ -32,24 +32,33 @@ import java.io.*; import java.net.*; public class ImgdecClient{ + + private String hostname; + private int portNo; - public static PnmImage decode_jpipstream( byte[] jpipstream, String tid, String cid, int fw, int fh) + public ImgdecClient( String host, int port) + { + hostname = host; + portNo = port; + } + + public PnmImage decode_jpipstream( byte[] jpipstream, String tid, String cid, int fw, int fh) { if( jpipstream != null) send_JPIPstream( jpipstream); return get_PNMstream( cid, tid, fw, fh); } - public static PnmImage decode_jpipstream( byte[] jpipstream, String j2kfilename, String tid, String cid, int fw, int fh) + public PnmImage decode_jpipstream( byte[] jpipstream, String j2kfilename, String tid, String cid, int fw, int fh) { send_JPIPstream( jpipstream, j2kfilename, tid, cid); return get_PNMstream( cid, tid, fw, fh); } - public static void send_JPIPstream( byte[] jpipstream) + public void send_JPIPstream( byte[] jpipstream) { try{ - Socket imgdecSocket = new Socket( "localhost", 50000); + Socket imgdecSocket = new Socket( hostname, portNo); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); @@ -71,10 +80,10 @@ public class ImgdecClient{ } } - public static void send_JPIPstream( byte[] jpipstream, String j2kfilename, String tid, String cid) + public void send_JPIPstream( byte[] jpipstream, String j2kfilename, String tid, String cid) { try{ - Socket imgdecSocket = new Socket( "localhost", 50000); + Socket imgdecSocket = new Socket( hostname, portNo); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); int length = 0; @@ -109,12 +118,12 @@ public class ImgdecClient{ } } - public static PnmImage get_PNMstream( String cid, String tid, int fw, int fh) + public PnmImage get_PNMstream( String cid, String tid, int fw, int fh) { PnmImage pnmstream = null; try { - Socket imgdecSocket = new Socket( "localhost", 50000); + Socket imgdecSocket = new Socket( hostname, portNo); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); byte []header = new byte[7]; @@ -166,12 +175,12 @@ public class ImgdecClient{ return pnmstream; } - public static byte [] get_XMLstream( String cid) + public byte [] get_XMLstream( String cid) { byte []xmldata = null; try{ - Socket imgdecSocket = new Socket( "localhost", 50000); + Socket imgdecSocket = new Socket( hostname, portNo); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); byte []header = new byte[5]; @@ -197,7 +206,7 @@ public class ImgdecClient{ return xmldata; } - public static String query_cid( String j2kfilename) + public String query_cid( String j2kfilename) { int []retmsglabel = new int[3]; retmsglabel[0] = 67; @@ -207,7 +216,7 @@ public class ImgdecClient{ return query_id( "CID request", j2kfilename, retmsglabel); } - public static String query_tid( String j2kfilename) + public String query_tid( String j2kfilename) { int []retmsglabel = new int[3]; retmsglabel[0] = 84; @@ -217,12 +226,12 @@ public class ImgdecClient{ return query_id( "TID request", j2kfilename, retmsglabel); } - public static String query_id( String reqmsghead, String j2kfilename, int[] retmsglabel) + public String query_id( String reqmsghead, String j2kfilename, int[] retmsglabel) { String id = null; try{ - Socket imgdecSocket = new Socket( "localhost", 50000); + Socket imgdecSocket = new Socket( hostname, portNo); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); byte []header = new byte[4]; @@ -254,12 +263,12 @@ public class ImgdecClient{ return id; } - public static java.awt.Dimension query_imagesize( String cid, String tid) + public java.awt.Dimension query_imagesize( String cid, String tid) { java.awt.Dimension dim = null; try{ - Socket imgdecSocket = new Socket( "localhost", 50000); + Socket imgdecSocket = new Socket( hostname, portNo); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); byte []header = new byte[3]; @@ -297,7 +306,7 @@ public class ImgdecClient{ return dim; } - public static void read_stream( DataInputStream is, byte []stream, int length) + private static void read_stream( DataInputStream is, byte []stream, int length) { int remlen = length; int off = 0; @@ -318,10 +327,10 @@ public class ImgdecClient{ } } - public static void destroy_cid( String cid) + public void destroy_cid( String cid) { try{ - Socket imgdecSocket = new Socket( "localhost", 50000); + Socket imgdecSocket = new Socket( hostname, portNo); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); diff --git a/applications/jpip/util/opj_viewer_xerces/src/ImageWindow.java b/applications/jpip/util/opj_viewer_xerces/src/ImageWindow.java index a7c8abd9..ae3f54c5 100644 --- a/applications/jpip/util/opj_viewer_xerces/src/ImageWindow.java +++ b/applications/jpip/util/opj_viewer_xerces/src/ImageWindow.java @@ -38,11 +38,11 @@ public class ImageWindow extends JFrame private OptionPanel optpanel; private ImageManager imgmanager; - public ImageWindow( String uri, String j2kfilename, boolean session, boolean jppstream, int aux) + public ImageWindow( String uri, String j2kfilename, String host, int port, boolean session, boolean jppstream, int aux) { super( j2kfilename); - imgmanager = new ImageManager( uri); + imgmanager = new ImageManager( uri, host, port); imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream, aux); imgviewer.setOpaque(true); //content panes must be opaque @@ -70,25 +70,36 @@ public class ImageWindow extends JFrame public static void main(String s[]) { - String j2kfilename, uri; + String j2kfilename, uri, host; boolean session, jppstream; - int aux; // 0: none, 1: tcp, 2: udp - + int port, aux; // 0: none, 1: tcp, 2: udp + if(s.length >= 2){ uri = s[0]; j2kfilename = s[1]; + if( s.length > 2) - session = !s[2].equalsIgnoreCase( "stateless"); + host = s[2]; + else + host = "localhost"; + + if( s.length > 3) + port = Integer.valueOf( s[3]).intValue(); + else + port = 50000; + + if( s.length > 4) + session = !s[4].equalsIgnoreCase( "stateless"); else session = true; - - if( s.length > 3) - jppstream = !s[3].equalsIgnoreCase( "JPT"); + + if( s.length > 5) + jppstream = !s[5].equalsIgnoreCase( "JPT"); else jppstream = true; - if( s.length > 4){ - if( s[4].equalsIgnoreCase("udp")) + if( s.length > 6){ + if( s[6].equalsIgnoreCase("udp")) aux = 2; else aux = 1; @@ -97,10 +108,10 @@ public class ImageWindow extends JFrame aux = 0; } else{ - System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [stateless/session] [JPT/JPP] [tcp/udp]"); + System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [hostname] [portnumber] [stateless/session] [JPT/JPP] [tcp/udp]"); return; } - ImageWindow frame = new ImageWindow( uri, j2kfilename, session, jppstream, aux); + ImageWindow frame = new ImageWindow( uri, j2kfilename, host, port, session, jppstream, aux); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -110,4 +121,4 @@ public class ImageWindow extends JFrame frame.setLocation( 0, 50); frame.setVisible(true); } -} \ No newline at end of file +}