4 * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2011, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 import java.awt.Image;
33 public class ImageManager extends JPIPHttpClient
35 private PnmImage pnmimage;
36 private int origwidth;
37 private int origheight;
39 public ImageManager( String uri)
47 public int getOrigWidth(){
49 if( cid != null || tid != null){
50 java.awt.Dimension dim = ImgdecClient.query_imagesize( cid, tid);
52 origwidth = dim.width;
53 origheight = dim.height;
57 System.err.println("Neither cid or tid obtained before to get Original Image Dimension");
61 public int getOrigHeight(){ return origheight;}
63 public Image getImage( String j2kfilename, int reqfw, int reqfh, boolean reqcnew, int reqaux, boolean reqJPP, boolean reqJPT)
70 // Todo: check if the cid is for the same stream type
72 refcid = ImgdecClient.query_cid( j2kfilename);
75 String reftid = ImgdecClient.query_tid( j2kfilename);
77 jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, reqcnew, reqaux, reqJPP, reqJPT);
79 jpipstream = super.requestViewWindow( j2kfilename, reftid, reqfw, reqfh, reqcnew, reqaux, reqJPP, reqJPT);
82 jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, reqcnew, reqaux, reqJPP, reqJPT);
84 System.err.println( "decoding to PNM image");
85 if((pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh))!=null){
86 System.err.println( " done");
87 return pnmimage.createROIImage( rx, ry, rw, rh);
90 System.err.println( " failed");
95 public Image getImage( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh)
99 byte[] jpipstream = super.requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh);
101 System.err.println( "decoding to PNM image");
102 if((pnmimage = ImgdecClient.decode_jpipstream( jpipstream, tid, cid, fw, fh)) != null){
103 System.err.println( " done");
104 return pnmimage.createROIImage( rx, ry, rw, rh);
107 System.err.println( " failed");
112 public byte[] getXML()
114 System.err.println();
116 byte []xmldata = null;
117 byte[] jpipstream = super.requestXML();
119 if( jpipstream != null){
120 ImgdecClient.send_JPIPstream( jpipstream);
122 xmldata = ImgdecClient.get_XMLstream( cid);
127 public void closeChannel()
130 ImgdecClient.destroy_cid( cid);
131 super.closeChannel();