diff options
| author | Kaori Hagihara <khagihara@users.noreply.github.com> | 2011-10-19 23:29:57 +0000 |
|---|---|---|
| committer | Kaori Hagihara <khagihara@users.noreply.github.com> | 2011-10-19 23:29:57 +0000 |
| commit | 255fcbc3a5fc991316e9fda1a3398c55e82d0f21 (patch) | |
| tree | 108619e23e356373adaa35118f9290ff34be71ac /applications/jpip/util/opj_viewer/src/ImageManager.java | |
| parent | 47d93279ff813e0d22bfe83b881d1cd5045835db (diff) | |
start using API style in openJPIP library
Diffstat (limited to 'applications/jpip/util/opj_viewer/src/ImageManager.java')
| -rw-r--r-- | applications/jpip/util/opj_viewer/src/ImageManager.java | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/applications/jpip/util/opj_viewer/src/ImageManager.java b/applications/jpip/util/opj_viewer/src/ImageManager.java new file mode 100644 index 00000000..5634123f --- /dev/null +++ b/applications/jpip/util/opj_viewer/src/ImageManager.java @@ -0,0 +1,116 @@ +/* + * $Id$ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +import java.awt.Image; + +public class ImageManager extends JPIPHttpClient +{ + private PnmImage pnmimage; + + public ImageManager( String uri) + { + super( uri); + pnmimage = null; + } + + public int getOrigWidth(){ return pnmimage.get_width();} + public int getOrigHeight(){ return pnmimage.get_height();} + + public Image getImage( String j2kfilename, int reqfw, int reqfh, boolean reqcnew, boolean reqJPP, boolean reqJPT) + { + System.err.println(); + + String refcid = null; + byte[] jpipstream; + + // Todo: check if the cid is for the same stream type + if( reqcnew) + refcid = ImgdecClient.query_cid( j2kfilename); + + if( refcid == null){ + String reftid = ImgdecClient.query_tid( j2kfilename); + if( reftid == null) + jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, reqcnew, reqJPP, reqJPT); + else + jpipstream = super.requestViewWindow( j2kfilename, reftid, reqfw, reqfh, reqcnew, reqJPP, reqJPT); + } + else + jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, reqcnew, reqJPP, reqJPT); + + System.err.println( "decoding to PNM image"); + if((pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh))!=null){ + System.err.println( " done"); + return pnmimage.createROIImage( rx, ry, rw, rh); + } + else{ + System.err.println( " failed"); + return null; + } + } + + public Image getImage( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh) + { + System.err.println(); + + 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){ + System.err.println( " done"); + return pnmimage.createROIImage( rx, ry, rw, rh); + } + else{ + System.err.println( " failed"); + return null; + } + } + + public byte[] getXML() + { + System.err.println(); + + byte []xmldata = null; + byte[] jpipstream = super.requestXML(); + + if( jpipstream != null){ + ImgdecClient.send_JPIPstream( jpipstream); + + xmldata = ImgdecClient.get_XMLstream( cid); + } + return xmldata; + } + public void closeChannel() + { + if( cid != null){ + ImgdecClient.destroy_cid( cid); + super.closeChannel(); + } + } +}
\ No newline at end of file |
