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
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
% ../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
*
* \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.
*/
#include <stdio.h>
+#include <stdlib.h>
#include "openjpip.h"
#ifdef _WIN32
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);
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))
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;
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;
// 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
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);
}
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);
}
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;
}
public void closeChannel()
{
if( cid != null){
- ImgdecClient.destroy_cid( cid);
+ imgdecoder.destroy_cid( cid);
super.closeChannel();
}
}
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
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
- session = true;
-
+ host = "localhost";
+
if( s.length > 3)
- jppstream = !s[3].equalsIgnoreCase( "JPT");
+ port = Integer.valueOf( s[3]).intValue();
+ else
+ port = 50000;
+
+ if( s.length > 4)
+ session = !s[4].equalsIgnoreCase( "stateless");
+ else
+ session = true;
+
+ 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;
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);
import java.net.*;
public class ImgdecClient{
+
+ private String hostname;
+ private int portNo;
+
+ public ImgdecClient( String host, int port)
+ {
+ hostname = host;
+ portNo = port;
+ }
- public static PnmImage decode_jpipstream( byte[] jpipstream, String tid, String cid, int fw, int fh)
+ 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());
}
}
- 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;
}
}
- 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];
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];
return xmldata;
}
- public static String query_cid( String j2kfilename)
+ public String query_cid( String j2kfilename)
{
int []retmsglabel = new int[3];
retmsglabel[0] = 67;
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;
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];
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];
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;
}
}
- 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());
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
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
- session = true;
-
+ host = "localhost";
+
if( s.length > 3)
- jppstream = !s[3].equalsIgnoreCase( "JPT");
+ port = Integer.valueOf( s[3]).intValue();
+ else
+ port = 50000;
+
+ if( s.length > 4)
+ session = !s[4].equalsIgnoreCase( "stateless");
+ else
+ session = true;
+
+ 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;
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);
frame.setLocation( 0, 50);
frame.setVisible(true);
}
-}
\ No newline at end of file
+}