[trunk] Import rev 1103 into trunk.
[openjpeg.git] / applications / jpip / util / opj_viewer / src / ImgdecClient.java
index 35c9712884754761b054dc398d5dda524321f5db..27750de7af87f744ab94574544539bbdb07c435e 100644 (file)
@@ -49,7 +49,7 @@ public class ImgdecClient{
     public static void send_JPIPstream( byte[] jpipstream)
     {
        try{
-           Socket imgdecSocket = new Socket( "localhost", 5000);
+           Socket imgdecSocket = new Socket( "localhost", 50000);
            DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
            DataInputStream  is = new DataInputStream( imgdecSocket.getInputStream());
       
@@ -74,7 +74,7 @@ public class ImgdecClient{
     public static void send_JPIPstream( byte[] jpipstream, String j2kfilename, String tid, String cid)
     {
        try{
-           Socket imgdecSocket = new Socket( "localhost", 5000);
+           Socket imgdecSocket = new Socket( "localhost", 50000);
            DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
            DataInputStream  is = new DataInputStream( imgdecSocket.getInputStream());
            int length = 0;
@@ -114,7 +114,7 @@ public class ImgdecClient{
        PnmImage pnmstream = null;
        
        try {
-           Socket imgdecSocket = new Socket( "localhost", 5000);
+           Socket imgdecSocket = new Socket( "localhost", 50000);
            DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
            DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
            byte []header = new byte[7];
@@ -171,7 +171,7 @@ public class ImgdecClient{
        byte []xmldata = null;
 
        try{
-           Socket imgdecSocket = new Socket( "localhost", 5000);
+           Socket imgdecSocket = new Socket( "localhost", 50000);
            DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
            DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
            byte []header = new byte[5];
@@ -222,7 +222,7 @@ public class ImgdecClient{
        String id = null;
        
        try{
-           Socket imgdecSocket = new Socket( "localhost", 5000);
+           Socket imgdecSocket = new Socket( "localhost", 50000);
            DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
            DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
            byte []header = new byte[4];
@@ -253,6 +253,49 @@ public class ImgdecClient{
 
        return id;      
     }
+
+    public static java.awt.Dimension query_imagesize( String cid, String tid)
+    {
+       java.awt.Dimension dim = null;
+
+       try{
+           Socket imgdecSocket = new Socket( "localhost", 50000);
+           DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
+           DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
+           byte []header = new byte[3];
+
+           os.writeBytes( "SIZ request\n");
+           if( tid == null)
+               os.writeBytes( "0\n");
+           else
+               os.writeBytes( tid + "\n");
+           if( cid == null)
+               os.writeBytes( "0\n");
+           else
+               os.writeBytes( cid + "\n");
+
+           read_stream( is, header, 3);
+           
+           if( header[0] == 83 && header[1] == 73 && header[2] == 90){
+               
+               byte []data = new byte[ 3];
+               read_stream( is, data, 3);
+               int w = (data[0]&0xff)<<16 | (data[1]&0xff)<<8 | (data[2]&0xff);
+               read_stream( is, data, 3);
+               int h = (data[0]&0xff)<<16 | (data[1]&0xff)<<8 | (data[2]&0xff);
+               dim = new java.awt.Dimension( w, h);
+           }
+           else
+               System.err.println("Error in query_imagesize("+ cid + ", " + tid + "), wrong to start with " + header);
+       }
+       catch (UnknownHostException e) {
+           System.err.println("Trying to connect to unknown host: " + e);
+       } catch (IOException e) {
+           System.err.println("IOException: " + e);
+       }
+
+       return dim;
+    }
   
     public static void read_stream( DataInputStream is, byte []stream, int length)
     {
@@ -278,7 +321,7 @@ public class ImgdecClient{
     public static void destroy_cid( String cid)
     {
        try{
-           Socket imgdecSocket = new Socket( "localhost", 5000);
+           Socket imgdecSocket = new Socket( "localhost", 50000);
            DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
            DataInputStream  is = new DataInputStream( imgdecSocket.getInputStream());