opj_viewer enabled stateless requests

This commit is contained in:
Kaori Hagihara 2011-09-16 14:17:45 +00:00
parent 6a1573c228
commit 1475cabfa0
8 changed files with 47 additions and 24 deletions

View File

@ -1 +1 @@
opj_viewer-20110825.jar opj_viewer-20110916.jar

View File

@ -43,22 +43,25 @@ public class ImageManager extends JPIPHttpClient
public int getOrigWidth(){ return pnmimage.width;} public int getOrigWidth(){ return pnmimage.width;}
public int getOrigHeight(){ return pnmimage.height;} public int getOrigHeight(){ return pnmimage.height;}
public Image getImage( String j2kfilename, int reqfw, int reqfh) public Image getImage( String j2kfilename, int reqfw, int reqfh, boolean reqcnew)
{ {
System.err.println(); System.err.println();
String refcid = ImgdecClient.query_cid( j2kfilename); String refcid = null;
byte[] jpipstream; byte[] jpipstream;
if( reqcnew)
refcid = ImgdecClient.query_cid( j2kfilename);
if( refcid == null){ if( refcid == null){
String reftid = ImgdecClient.query_tid( j2kfilename); String reftid = ImgdecClient.query_tid( j2kfilename);
if( reftid == null) if( reftid == null)
jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, true); jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, reqcnew);
else else
jpipstream = super.requestViewWindow( j2kfilename, reftid, reqfw, reqfh, true); jpipstream = super.requestViewWindow( j2kfilename, reftid, reqfw, reqfh, reqcnew);
} }
else else
jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, true); jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, reqcnew);
System.err.println( "decoding to PNM image"); System.err.println( "decoding to PNM image");
pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh); pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh);
@ -74,7 +77,7 @@ public class ImageManager extends JPIPHttpClient
byte[] jpipstream = super.requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh); byte[] jpipstream = super.requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh);
System.err.println( "decoding to PNM image"); System.err.println( "decoding to PNM image");
pnmimage = ImgdecClient.decode_jpipstream( jpipstream, cid, fw, fh); pnmimage = ImgdecClient.decode_jpipstream( jpipstream, tid, cid, fw, fh);
System.err.println( " done"); System.err.println( " done");
return pnmimage.createROIImage( rx, ry, rw, rh); return pnmimage.createROIImage( rx, ry, rw, rh);
@ -96,7 +99,9 @@ public class ImageManager extends JPIPHttpClient
} }
public void closeChannel() public void closeChannel()
{ {
if( cid != null){
ImgdecClient.destroy_cid( cid); ImgdecClient.destroy_cid( cid);
super.closeChannel(); super.closeChannel();
} }
}
} }

View File

@ -55,7 +55,7 @@ public class ImageViewer extends JPanel
private Rectangle roirect[] = null; private Rectangle roirect[] = null;
private String roiname[] = null; private String roiname[] = null;
public ImageViewer( String j2kfilename, ImageManager manager) public ImageViewer( String j2kfilename, ImageManager manager, boolean session)
{ {
String str; String str;
@ -70,7 +70,7 @@ public class ImageViewer extends JPanel
myRL = new ResizeListener(this); myRL = new ResizeListener(this);
imgmanager = manager; imgmanager = manager;
img = imgmanager.getImage( j2kfilename, vw, vh); img = imgmanager.getImage( j2kfilename, vw, vh, session);
addMouseListener(myMML); addMouseListener(myMML);
addMouseMotionListener(myMML); addMouseMotionListener(myMML);

View File

@ -38,13 +38,13 @@ public class ImageWindow extends JFrame
// private OptionPanel optpanel; // private OptionPanel optpanel;
private ImageManager imgmanager; private ImageManager imgmanager;
public ImageWindow( String uri, String j2kfilename) public ImageWindow( String uri, String j2kfilename, boolean session)
{ {
super( j2kfilename); super( j2kfilename);
imgmanager = new ImageManager( uri); imgmanager = new ImageManager( uri);
imgviewer = new ImageViewer( j2kfilename, imgmanager); imgviewer = new ImageViewer( j2kfilename, imgmanager, session);
imgviewer.setOpaque(true); //content panes must be opaque imgviewer.setOpaque(true); //content panes must be opaque
// optpanel = new OptionPanel( imgmanager, imgviewer); // optpanel = new OptionPanel( imgmanager, imgviewer);
@ -71,16 +71,21 @@ public class ImageWindow extends JFrame
public static void main(String s[]) public static void main(String s[])
{ {
String j2kfilename, uri; String j2kfilename, uri;
boolean session;
if(s.length > 0){ if(s.length > 0){
uri = s[0]; uri = s[0];
j2kfilename = s[1]; j2kfilename = s[1];
if( s.length > 2)
session = !s[2].equalsIgnoreCase( "stateless");
else
session = true;
} }
else{ else{
System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2"); System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [stateless/session]");
return; return;
} }
ImageWindow frame = new ImageWindow( uri, j2kfilename); ImageWindow frame = new ImageWindow( uri, j2kfilename, session);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

View File

@ -33,17 +33,17 @@ import java.net.*;
public class ImgdecClient{ public class ImgdecClient{
public static PnmImage decode_jpipstream( byte[] jpipstream, String cid, int fw, int fh) public static PnmImage decode_jpipstream( byte[] jpipstream, String tid, String cid, int fw, int fh)
{ {
if( jpipstream != null) if( jpipstream != null)
send_JPIPstream( jpipstream); send_JPIPstream( jpipstream);
return get_PNMstream( cid, fw, fh); 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 static PnmImage decode_jpipstream( byte[] jpipstream, String j2kfilename, String tid, String cid, int fw, int fh)
{ {
send_JPIPstream( jpipstream, j2kfilename, tid, cid); send_JPIPstream( jpipstream, j2kfilename, tid, cid);
return get_PNMstream( cid, fw, fh); return get_PNMstream( cid, tid, fw, fh);
} }
public static void send_JPIPstream( byte[] jpipstream) public static void send_JPIPstream( byte[] jpipstream)
@ -91,6 +91,9 @@ public class ImgdecClient{
os.writeBytes( "0\n"); os.writeBytes( "0\n");
else else
os.writeBytes( tid + "\n"); os.writeBytes( tid + "\n");
if( cid == null)
os.writeBytes( "0\n");
else
os.writeBytes( cid + "\n"); os.writeBytes( cid + "\n");
os.writeBytes( length + "\n"); os.writeBytes( length + "\n");
os.write( jpipstream, 0, length); os.write( jpipstream, 0, length);
@ -106,7 +109,7 @@ public class ImgdecClient{
} }
} }
public static PnmImage get_PNMstream( String cid, int fw, int fh) public static PnmImage get_PNMstream( String cid, String tid, int fw, int fh)
{ {
PnmImage pnmstream = new PnmImage(); PnmImage pnmstream = new PnmImage();
try { try {
@ -116,7 +119,13 @@ public class ImgdecClient{
byte []header = new byte[7]; byte []header = new byte[7];
os.writeBytes("PNM request\n"); os.writeBytes("PNM request\n");
if( cid != null)
os.writeBytes( cid + "\n"); os.writeBytes( cid + "\n");
else
if( tid != null)
os.writeBytes( tid + "\n");
else
os.writeBytes( "0\n");
os.writeBytes( fw + "\n"); os.writeBytes( fw + "\n");
os.writeBytes( fh + "\n"); os.writeBytes( fh + "\n");

View File

@ -71,6 +71,10 @@ public class JPIPHttpClient
{ {
if( cid != null) if( cid != null)
return requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh, cid); return requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh, cid);
else
// return null;
if( tid != null)
return requestViewWindow( null, tid, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, null, false);
else else
return null; return null;
} }