! : changed
+ : added
-October 14, 2011
+November 2, 2011
+* [antonin] additional patches for autotools and cmake
+
+October 26, 2011
+* [kaori] additional patches for autotool are applied
+
+October 25, 2011
+* [kaori] patches for cmake and autotool are applied
+* [kaori] fixed client viewer to be compatible with server response header both Content-type and Content-Type
+
+October 20, 2011
++ [added] API style in openJPIP library
+! [kaori] rearranged directories, applications are all under util/ directory, currently only 'make -f Makefile.nix' works
+
+October 18, 2011
! [kaori] rearranged opj_server, opj_dec_server directory
October 14, 2011
ADD_SUBDIRECTORY(libopenjpip)
-ADD_SUBDIRECTORY(opj_server)
-ADD_SUBDIRECTORY(opj_client)
-ADD_SUBDIRECTORY(tools)
\ No newline at end of file
+ADD_SUBDIRECTORY(util)
MAINTAINERCLEANFILES = Makefile.in
-SUBDIRS = libopenjpip opj_server opj_client tools
+SUBDIRS = libopenjpip util
-default: t_libopenjpip t_opj_server t_opj_dec_server t_tools
+default: t_libopenjpip t_util
t_libopenjpip:
make -C libopenjpip -f Makefile.nix
-t_opj_server:
- make -C opj_server -f Makefile.nix
-
-t_opj_dec_server:
- make -C opj_client/opj_dec_server -f Makefile.nix
-
-t_tools:
- make -C tools -f Makefile.nix
+t_util:
+ make -C util -f Makefile.nix
clean:
make clean -C libopenjpip -f Makefile.nix
- make clean -C opj_server -f Makefile.nix
- make clean -C opj_client/opj_dec_server -f Makefile.nix
- make clean -C tools -f Makefile.nix
+ make clean -C util -f Makefile.nix
INCLUDE_REGULAR_EXPRESSION("^.*$")
INCLUDE_DIRECTORIES(
+ ${OPENJPEG_SOURCE_DIR}/libopenjpeg
${FCGI_INCLUDE_DIRNAME}
)
${CMAKE_CURRENT_SOURCE_DIR}/cachemodel_manager.c
${CMAKE_CURRENT_SOURCE_DIR}/j2kheader_manager.c
${CMAKE_CURRENT_SOURCE_DIR}/jp2k_encoder.c
+${CMAKE_CURRENT_SOURCE_DIR}/openjpip.c
+${CMAKE_CURRENT_SOURCE_DIR}/query_parser.c
+${CMAKE_CURRENT_SOURCE_DIR}/channel_manager.c
+${CMAKE_CURRENT_SOURCE_DIR}/session_manager.c
+${CMAKE_CURRENT_SOURCE_DIR}/jpip_parser.c
+)
+
+SET(LOCAL_SRCS
+${CMAKE_CURRENT_SOURCE_DIR}/jp2k_decoder.c
+${CMAKE_CURRENT_SOURCE_DIR}/imgsock_manager.c
+${CMAKE_CURRENT_SOURCE_DIR}/jpipstream_manager.c
+${CMAKE_CURRENT_SOURCE_DIR}/cache_manager.c
+${CMAKE_CURRENT_SOURCE_DIR}/dec_clientmsg_handler.c
)
# Build the library
-ADD_LIBRARY(openjpip_local STATIC ${OPENJPIP_SRCS})
+ADD_LIBRARY(openjpip_local STATIC ${OPENJPIP_SRCS} ${LOCAL_SRCS})
+TARGET_LINK_LIBRARIES(openjpip_local ${OPENJPEG_LIBRARY_NAME})
ADD_LIBRARY(openjpip_server STATIC ${OPENJPIP_SRCS})
TARGET_LINK_LIBRARIES(openjpip_server ${FCGI_LIBNAME})
# Install library
-INSTALL(TARGETS openjpip_local
- EXPORT OpenJPEGTargets
- DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
-)
+ INSTALL(TARGETS openjpip_local
+ EXPORT OpenJPEGTargets
+ DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
+ )
-INSTALL(TARGETS openjpip_server
- EXPORT OpenJPEGTargets
- DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
-)
+ INSTALL(TARGETS openjpip_server
+ EXPORT OpenJPEGTargets
+ DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
+ )
lib_LTLIBRARIES = libopenjpip_server.la libopenjpip_local.la
JPIP_SRC = \
+openjpip.c \
+query_parser.c \
+channel_manager.c \
+session_manager.c \
+jpip_parser.c \
boxheader_manager.c \
codestream_manager.c \
imgreg_manager.c \
target_manager.h \
cachemodel_manager.h \
j2kheader_manager.h \
-jp2k_encoder.h
+jp2k_encoder.h \
+query_parser.h \
+channel_manager.h \
+session_manager.h \
+jpip_parser.h
+
+LOCAL_SRC = jp2k_decoder.c \
+imgsock_manager.c \
+jpipstream_manager.c \
+cache_manager.c \
+dec_clientmsg_handler.c \
+imgsock_manager.h \
+jpipstream_manager.h \
+cache_manager.h \
+dec_clientmsg_handler.h
libopenjpip_server_la_CPPFLAGS = \
-I. \
libopenjpip_local_la_CPPFLAGS = \
-I. \
+-I$(top_srcdir)/libopenjpeg \
+-I$(top_builddir)/libopenjpeg \
-I$(top_srcdir)/applications/jpip/libopenjpip \
-I$(top_builddir)/applications/jpip/libopenjpip
libopenjpip_local_la_CFLAGS =
-libopenjpip_local_la_LIBADD = -lm
+libopenjpip_local_la_LIBADD = $(top_builddir)/libopenjpeg/libopenjpeg.la -lm
libopenjpip_local_la_LDFLAGS = -no-undefined -version-info @lt_version@
-libopenjpip_local_la_SOURCES = $(JPIP_SRC)
+libopenjpip_local_la_SOURCES = $(JPIP_SRC) $(LOCAL_SRC)
install-data-hook:
@echo -e " (LA)\t$(libdir)/libopenjpip_server.la" >> $(top_builddir)/report.txt
--- /dev/null
+/*
+ * $Id: cache_manager.c 53 2011-05-09 16:55:39Z kaori $
+ *
+ * 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "cache_manager.h"
+
+//! maximum length of channel identifier
+#define MAX_LENOFCID 30
+
+cachelist_param_t * gene_cachelist()
+{
+ cachelist_param_t *cachelist;
+
+ cachelist = (cachelist_param_t *)malloc( sizeof(cachelist_param_t));
+
+ cachelist->first = NULL;
+ cachelist->last = NULL;
+
+ return cachelist;
+}
+
+void delete_cachelist(cachelist_param_t **cachelist)
+{
+ cache_param_t *cachePtr, *cacheNext;
+
+ cachePtr = (*cachelist)->first;
+ while( cachePtr != NULL){
+ cacheNext=cachePtr->next;
+ delete_cache( &cachePtr);
+ cachePtr=cacheNext;
+ }
+ free( *cachelist);
+}
+
+cache_param_t * gene_cache( char *targetname, int csn, char *tid, char *cid)
+{
+ cache_param_t *cache;
+
+ cache = (cache_param_t *)malloc( sizeof(cache_param_t));
+ strcpy( cache->filename, targetname);
+ strcpy( cache->tid, tid);
+ cache->csn = csn;
+ cache->cid = (char **)malloc( sizeof(char *));
+ *cache->cid = (char *)malloc( MAX_LENOFCID);
+ strcpy( *cache->cid, cid);
+ cache->numOfcid = 1;
+#if 1
+ cache->metadatalist = NULL;
+#else
+ cache->metadatalist = gene_metadatalist();
+#endif
+ cache->ihdrbox = NULL;
+ cache->next = NULL;
+
+ return cache;
+}
+
+void delete_cache( cache_param_t **cache)
+{
+ int i;
+
+ delete_metadatalist( &(*cache)->metadatalist);
+
+ if((*cache)->ihdrbox)
+ free((*cache)->ihdrbox);
+ for( i=0; i<(*cache)->numOfcid; i++)
+ free( (*cache)->cid[i]);
+ free( (*cache)->cid);
+ free( *cache);
+}
+
+void insert_cache_into_list( cache_param_t *cache, cachelist_param_t *cachelist)
+{
+ if( cachelist->first)
+ cachelist->last->next = cache;
+ else
+ cachelist->first = cache;
+ cachelist->last = cache;
+}
+
+cache_param_t * search_cache( char targetname[], cachelist_param_t *cachelist)
+{
+ cache_param_t *foundcache;
+
+ foundcache = cachelist->first;
+
+ while( foundcache != NULL){
+
+ if( strcmp( targetname, foundcache->filename) == 0)
+ return foundcache;
+
+ foundcache = foundcache->next;
+ }
+ return NULL;
+}
+
+cache_param_t * search_cacheBycsn( int csn, cachelist_param_t *cachelist)
+{
+ cache_param_t *foundcache;
+
+ foundcache = cachelist->first;
+
+ while( foundcache != NULL){
+
+ if( csn == foundcache->csn)
+ return foundcache;
+ foundcache = foundcache->next;
+ }
+ return NULL;
+}
+
+cache_param_t * search_cacheBycid( char cid[], cachelist_param_t *cachelist)
+{
+ cache_param_t *foundcache;
+ int i;
+
+ foundcache = cachelist->first;
+
+ while( foundcache != NULL){
+ for( i=0; i<foundcache->numOfcid; i++)
+ if( strcmp( cid, foundcache->cid[i]) == 0)
+ return foundcache;
+ foundcache = foundcache->next;
+ }
+ return NULL;
+}
+
+cache_param_t * search_cacheBytid( char tid[], cachelist_param_t *cachelist)
+{
+ cache_param_t *foundcache;
+
+ foundcache = cachelist->first;
+
+ while( foundcache != NULL){
+ if( strcmp( tid, foundcache->tid) == 0)
+ return foundcache;
+ foundcache = foundcache->next;
+ }
+ return NULL;
+}
+
+void add_cachecid( char *cid, cache_param_t *cache)
+{
+ char **tmp;
+ int i;
+
+ tmp = cache->cid;
+
+ cache->cid = (char **)malloc( (cache->numOfcid+1)*sizeof(char *));
+
+ for( i=0; i<cache->numOfcid; i++){
+ cache->cid[i] = (char *)malloc( MAX_LENOFCID);
+ strcpy( cache->cid[i], tmp[i]);
+ free( tmp[i]);
+ }
+ free( tmp);
+
+ cache->cid[ cache->numOfcid] = (char *)malloc( MAX_LENOFCID);
+ strcpy( cache->cid[ cache->numOfcid], cid);
+
+ cache->numOfcid ++;
+}
+
+void update_cachetid( char *tid, cache_param_t *cache)
+{
+ if( tid[0] != '0' && strcmp( tid, cache->tid) !=0){
+ fprintf( stderr, "tid is updated to %s for %s\n", tid, cache->filename);
+ strcpy( cache->tid, tid);
+ }
+}
+
+void remove_cidInCache( char *cid, cache_param_t *cache);
+
+void remove_cachecid( char *cid, cachelist_param_t *cachelist)
+{
+ cache_param_t *cache;
+
+ cache = search_cacheBycid( cid, cachelist);
+ remove_cidInCache( cid, cache);
+}
+
+void remove_cidInCache( char *cid, cache_param_t *cache)
+{
+ int idx = -1;
+ char **tmp;
+ int i, j;
+
+ for( i=0; i<cache->numOfcid; i++)
+ if( strcmp( cid, cache->cid[i]) == 0){
+ idx = i;
+ break;
+ }
+
+ if( idx == -1){
+ fprintf( stderr, "cid: %s not found\n", cid);
+ return;
+ }
+
+ tmp = cache->cid;
+
+ cache->cid = (char **)malloc( (cache->numOfcid-1)*sizeof(char *));
+
+ for( i=0, j=0; i<cache->numOfcid; i++){
+ if( i != idx){
+ cache->cid[j] = (char *)malloc( MAX_LENOFCID);
+ strcpy( cache->cid[j], tmp[i]);
+ j++;
+ }
+ free( tmp[i]);
+ }
+ free( tmp);
+
+ cache->numOfcid --;
+}
+
+void print_cache( cache_param_t *cache)
+{
+ int i;
+
+ fprintf( stdout,"cache\n");
+ fprintf( stdout,"\t filename: %s\n", cache->filename);
+ fprintf( stdout,"\t tid: %s\n", cache->tid);
+ fprintf( stdout,"\t csn: %d\n", cache->csn);
+ fprintf( stdout,"\t cid:");
+
+ for( i=0; i<cache->numOfcid; i++)
+ fprintf( stdout," %s", cache->cid[i]);
+ fprintf( stdout,"\n");
+}
+
+void print_allcache( cachelist_param_t *cachelist)
+{
+ cache_param_t *ptr;
+
+ fprintf( stdout,"cache list\n");
+
+ ptr = cachelist->first;
+ while( ptr != NULL){
+ print_cache( ptr);
+ ptr=ptr->next;
+ }
+}
--- /dev/null
+/*
+ * $Id: cache_manager.h 44 2011-02-15 12:32:29Z kaori $
+ *
+ * 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.
+ */
+
+#ifndef CACHE_MANAGER_H_
+# define CACHE_MANAGER_H_
+
+#include "metadata_manager.h"
+#include "ihdrbox_manager.h"
+
+//! maximum length of target name
+#define MAX_LENOFTARGET 128
+
+//! maximum length of target identifier
+#define MAX_LENOFTID 30
+
+//! cache parameters
+typedef struct cache_param{
+ char filename[MAX_LENOFTARGET]; //!< file name
+ char tid[MAX_LENOFTID]; //!< taregt identifier
+ int csn; //!< codestream number
+ char **cid; //!< dynamic array of channel identifiers
+ int numOfcid; //!< number of cids
+ metadatalist_param_t *metadatalist; //!< metadata-bin list
+ ihdrbox_param_t *ihdrbox; //!< ihdrbox
+ struct cache_param *next; //!< pointer to the next cache
+} cache_param_t;
+
+//!< cache list parameters
+typedef struct cachelist_param{
+ cache_param_t *first; //!< first cache pointer of the list
+ cache_param_t *last; //!< last cache pointer of the list
+} cachelist_param_t;
+
+
+/**
+ * generate a cache list
+ *
+ * @return pointer to the generated cache list
+ */
+cachelist_param_t * gene_cachelist();
+
+/**
+ * delete cache list
+ *
+ * @param[in,out] cachelist address of the cache list pointer
+ */
+void delete_cachelist(cachelist_param_t **cachelist);
+
+/**
+ * generate a cache
+ *
+ * @param[in] targetname target file name
+ * @param[in] csn codestream number
+ * @param[in] tid target identifier
+ * @param[in] cid channel identifier
+ * @return pointer to the generated cache
+ */
+cache_param_t * gene_cache( char *targetname, int csn, char *tid, char *cid);
+
+/**
+ * delete a cache
+ *
+ * @param[in] cache address of the cache pointer
+ */
+void delete_cache( cache_param_t **cache);
+
+/**
+ * insert a cache into list
+ *
+ * @param[in] cache cache pointer
+ * @param[in] cachelist cache list pointer
+ */
+void insert_cache_into_list( cache_param_t *cache, cachelist_param_t *cachelist);
+
+
+/**
+ * search a cache by target name
+ *
+ * @param[in] targetname target filename
+ * @param[in] cachelist cache list pointer
+ * @return found cache pointer
+ */
+cache_param_t * search_cache( char targetname[], cachelist_param_t *cachelist);
+
+
+/**
+ * search a cache by csn
+ *
+ * @param[in] csn codestream number
+ * @param[in] cachelist cache list pointer
+ * @return found cache pointer
+ */
+cache_param_t * search_cacheBycsn( int csn, cachelist_param_t *cachelist);
+
+
+/**
+ * search a cache by cid
+ *
+ * @param[in] cid channel identifer
+ * @param[in] cachelist cache list pointer
+ * @return found cache pointer
+ */
+cache_param_t * search_cacheBycid( char cid[], cachelist_param_t *cachelist);
+
+
+/**
+ * search a cache by tid
+ *
+ * @param[in] tid target identifer
+ * @param[in] cachelist cache list pointer
+ * @return found cache pointer
+ */
+cache_param_t * search_cacheBytid( char tid[], cachelist_param_t *cachelist);
+
+/**
+ * add cid into a cache
+ *
+ * @param[in] cid channel identifier
+ * @param[in] cache cache pointer
+ */
+void add_cachecid( char *cid, cache_param_t *cache);
+
+
+/**
+ * update tid of a cache
+ *
+ * @param[in] tid target identifier
+ * @param[in] cache cache pointer
+ */
+void update_cachetid( char *tid, cache_param_t *cache);
+
+
+/**
+ * remove cid in cache
+ *
+ * @param[in] cid channel identifier
+ * @param[in] cachelist cachelist pointer
+ */
+void remove_cachecid( char *cid, cachelist_param_t *cachelist);
+
+
+/**
+ * print cache parameters
+ *
+ * @param[in] cache cache pointer
+ */
+void print_cache( cache_param_t *cache);
+
+/**
+ * print all cache parameters
+ *
+ * @param[in] cachelist cache list pointer
+ */
+void print_allcache( cachelist_param_t *cachelist);
+
+#endif /* !CACHE_MANAGER_H_ */
--- /dev/null
+/*
+ * $Id: channel_manager.c 44 2011-02-15 12:32:29Z kaori $
+ *
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "channel_manager.h"
+
+#ifdef SERVER
+#include "fcgi_stdio.h"
+#define logstream FCGI_stdout
+#else
+#define FCGI_stdout stdout
+#define FCGI_stderr stderr
+#define logstream stderr
+#endif //SERVER
+
+channellist_param_t * gene_channellist()
+{
+ channellist_param_t *channellist;
+
+ channellist = (channellist_param_t *)malloc( sizeof(channellist_param_t));
+
+ channellist->first = NULL;
+ channellist->last = NULL;
+
+ return channellist;
+}
+
+channel_param_t * gene_channel( query_param_t query_param, cachemodel_param_t *cachemodel, channellist_param_t *channellist)
+{
+ channel_param_t *channel;
+
+ if( !cachemodel){
+ fprintf( FCGI_stdout, "Status: 404\r\n");
+ fprintf( FCGI_stdout, "Reason: cnew cancelled\r\n");
+ return NULL;
+ }
+
+ channel = (channel_param_t *)malloc( sizeof(channel_param_t));
+ channel->cachemodel = cachemodel;
+
+ // set channel ID and get present time
+ snprintf( channel->cid, MAX_LENOFCID, "%x%x", (unsigned int)time( &channel->start_tm), (unsigned int)rand());
+
+ channel->next=NULL;
+
+ set_channel_variable_param( query_param, channel);
+
+ if( channellist->first != NULL)
+ channellist->last->next = channel;
+ else
+ channellist->first = channel;
+ channellist->last = channel;
+
+ fprintf( FCGI_stdout, "JPIP-cnew: cid=%s", channel->cid);
+ // only http implemented for now
+ fprintf( FCGI_stdout, ",transport=http\r\n");
+
+ return channel;
+}
+
+
+void set_channel_variable_param( query_param_t query_param, channel_param_t *channel)
+{
+ // set roi information
+}
+
+
+void delete_channel( channel_param_t **channel, channellist_param_t *channellist)
+{
+ channel_param_t *ptr;
+
+ if( *channel == channellist->first)
+ channellist->first = (*channel)->next;
+ else{
+ ptr = channellist->first;
+ while( ptr->next != *channel){
+ ptr=ptr->next;
+ }
+
+ ptr->next = (*channel)->next;
+
+ if( *channel == channellist->last)
+ channellist->last = ptr;
+ }
+#ifndef SERVER
+ fprintf( logstream, "local log: channel: %s deleted\n", (*channel)->cid);
+#endif
+ free(*channel);
+}
+
+void delete_channellist( channellist_param_t **channellist)
+{
+ channel_param_t *channelPtr, *channelNext;
+
+ channelPtr = (*channellist)->first;
+ while( channelPtr != NULL){
+ channelNext=channelPtr->next;
+#ifndef SERVER
+ fprintf( logstream, "local log: channel %s deleted!\n", channelPtr->cid);
+#endif
+ free(channelPtr);
+ channelPtr=channelNext;
+ }
+ free( *channellist);
+}
+
+void print_allchannel( channellist_param_t *channellist)
+{
+ channel_param_t *ptr;
+
+ ptr = channellist->first;
+ while( ptr != NULL){
+ fprintf( logstream,"channel-ID=%s \t target=%s\n", ptr->cid, ptr->cachemodel->target->filename);
+ ptr=ptr->next;
+ }
+}
+
+channel_param_t * search_channel( char cid[], channellist_param_t *channellist)
+{
+ channel_param_t *foundchannel;
+
+ foundchannel = channellist->first;
+
+ while( foundchannel != NULL){
+
+ if( strcmp( cid, foundchannel->cid) == 0)
+ return foundchannel;
+
+ foundchannel = foundchannel->next;
+ }
+ fprintf( FCGI_stdout, "Status: 503\r\n");
+ fprintf( FCGI_stdout, "Reason: Channel %s not found in this session\r\n", cid);
+
+ return NULL;
+}
--- /dev/null
+/*
+ * $Id: channel_manager.h 44 2011-02-15 12:32:29Z kaori $
+ *
+ * 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.
+ */
+
+#ifndef CHANNEL_MANAGER_H_
+# define CHANNEL_MANAGER_H_
+
+#include <time.h>
+#include "query_parser.h"
+#include "cachemodel_manager.h"
+
+//! Channel parameters
+typedef struct channel_param{
+ cachemodel_param_t *cachemodel; //!< reference pointer to the cache model
+ char cid[MAX_LENOFCID]; //!< channel identifier
+ // - a record of the client's capabilities and preferences to the extent that the server queues requests
+ time_t start_tm; //!< starting time
+ struct channel_param *next; //!< pointer to the next channel
+} channel_param_t;
+
+
+//! Channel list parameters
+typedef struct channellist_param{
+ channel_param_t *first; //!< first channel pointer of the list
+ channel_param_t *last; //!< last channel pointer of the list
+} channellist_param_t;
+
+
+/**
+ * generate a channel list
+ *
+ * @return pointer to the generated channel list
+ */
+channellist_param_t * gene_channellist();
+
+
+/**
+ * generate a channel under the channel list
+ *
+ * @param[in] query_param query parameters
+ * @param[in] cachemodel reference cachemodel
+ * @param[in] channellist channel list pointer
+ * @return pointer to the generated channel
+ */
+channel_param_t * gene_channel( query_param_t query_param, cachemodel_param_t *cachemodel, channellist_param_t *channellist);
+
+/**
+ * set channel variable parameters
+ *
+ * @param[in] query_param query parameters
+ * @param[in,out] channel pointer to the modifying channel
+ */
+void set_channel_variable_param( query_param_t query_param, channel_param_t *channel);
+
+/**
+ * delete a channel
+ *
+ * @param[in] channel address of the deleting channel pointer
+ * @param[in,out] channellist channel list pointer
+ */
+void delete_channel( channel_param_t **channel, channellist_param_t *channellist);
+
+
+/**
+ * delete channel list
+ *
+ * @param[in,out] channellist address of the channel list pointer
+ */
+void delete_channellist( channellist_param_t **channellist);
+
+
+/**
+ * print all channel parameters
+ *
+ * @param[in] channellist channel list pointer
+ */
+void print_allchannel( channellist_param_t *channellist);
+
+
+/**
+ * search a channel by channel ID
+ *
+ * @param[in] cid channel identifier
+ * @param[in] channellist channel list pointer
+ * @return found channel pointer
+ */
+channel_param_t * search_channel( char cid[], channellist_param_t *channellist);
+#endif /* !CHANNEL_MANAGER_H_ */
CFLAGS = -O3 -Wall -m32 -DSERVER
LIBNAME = libopenjpip_server.a
else
-CFLAGS = -O3 -Wall
+J2KINCDIR = ../../../libopenjpeg
+CFLAGS = -O3 -Wall -I$(J2KINCDIR)
LIBNAME = libopenjpip_local.a
endif
all: $(LIBNAME)
-$(LIBNAME): target_manager.o byte_manager.o box_manager.o boxheader_manager.o manfbox_manager.o \
+ifdef jpipserver
+$(LIBNAME): openjpip.o target_manager.o byte_manager.o box_manager.o boxheader_manager.o manfbox_manager.o \
mhixbox_manager.o marker_manager.o codestream_manager.o faixbox_manager.o index_manager.o \
msgqueue_manager.o metadata_manager.o placeholder_manager.o ihdrbox_manager.o imgreg_manager.o \
- cachemodel_manager.o j2kheader_manager.o jp2k_encoder.o
+ cachemodel_manager.o j2kheader_manager.o jp2k_encoder.o query_parser.o channel_manager.o \
+ session_manager.o jpip_parser.o
ar r $@ $^
-
+else
+$(LIBNAME): openjpip.o target_manager.o byte_manager.o box_manager.o boxheader_manager.o manfbox_manager.o \
+ mhixbox_manager.o marker_manager.o codestream_manager.o faixbox_manager.o index_manager.o \
+ msgqueue_manager.o metadata_manager.o placeholder_manager.o ihdrbox_manager.o imgreg_manager.o \
+ cachemodel_manager.o j2kheader_manager.o jp2k_encoder.o query_parser.o channel_manager.o \
+ session_manager.o jpip_parser.o jp2k_decoder.o imgsock_manager.o jpipstream_manager.o cache_manager.o \
+ dec_clientmsg_handler.o
+ ar r $@ $^
+endif
clean:
rm -f $(LIBNAME) *.o *~
--- /dev/null
+/*
+ * $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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "dec_clientmsg_handler.h"
+#include "ihdrbox_manager.h"
+#include "jpipstream_manager.h"
+#include "jp2k_encoder.h"
+
+
+//! maximum length of channel identifier
+#define MAX_LENOFCID 30
+
+void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist,
+ Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue)
+{
+ Byte_t *newjpipstream;
+ int newstreamlen = 0;
+ cache_param_t *cache;
+ char target[MAX_LENOFTARGET], tid[MAX_LENOFTID], cid[MAX_LENOFCID];
+ metadatalist_param_t *metadatalist;
+
+ newjpipstream = receive_JPIPstream( connected_socket, target, tid, cid, &newstreamlen);
+
+ parse_JPIPstream( newjpipstream, newstreamlen, *streamlen, msgqueue);
+
+ *jpipstream = update_JPIPstream( newjpipstream, newstreamlen, *jpipstream, streamlen);
+ free( newjpipstream);
+
+ metadatalist = gene_metadatalist();
+ parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist);
+
+ // cid registration
+ if( target[0] != 0){
+ if((cache = search_cache( target, cachelist))){
+ if( tid[0] != 0)
+ update_cachetid( tid, cache);
+ if( cid[0] != 0)
+ add_cachecid( cid, cache);
+ }
+ else{
+ cache = gene_cache( target, msgqueue->last->csn, tid, cid);
+ insert_cache_into_list( cache, cachelist);
+ }
+ }
+ else
+ cache = search_cacheBycsn( msgqueue->last->csn, cachelist);
+
+ if( cache->metadatalist)
+ delete_metadatalist( &cache->metadatalist);
+ cache->metadatalist = metadatalist;
+
+ response_signal( connected_socket, true);
+}
+
+void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_param_t *msgqueue, cachelist_param_t *cachelist)
+{
+ Byte_t *pnmstream;
+ ihdrbox_param_t *ihdrbox;
+ char cid[MAX_LENOFCID], tmp[10];
+ cache_param_t *cache;
+ int fw, fh;
+
+ receive_line( connected_socket, cid);
+ if(!(cache = search_cacheBycid( cid, cachelist)))
+ if(!(cache = search_cacheBytid( cid, cachelist)))
+ return;
+
+ receive_line( connected_socket, tmp);
+ fw = atoi( tmp);
+
+ receive_line( connected_socket, tmp);
+ fh = atoi( tmp);
+
+ pnmstream = jpipstream_to_pnm( jpipstream, msgqueue, cache->csn, fw, fh, &cache->ihdrbox);
+ ihdrbox = cache->ihdrbox;
+
+ send_PNMstream( connected_socket, pnmstream, ihdrbox->width, ihdrbox->height, ihdrbox->nc, ihdrbox->bpc > 8 ? 255 : (1 << ihdrbox->bpc) - 1);
+
+ free( pnmstream);
+}
+
+void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist)
+{
+ char cid[MAX_LENOFCID];
+ cache_param_t *cache;
+
+ receive_line( connected_socket, cid);
+ if(!(cache = search_cacheBycid( cid, cachelist)))
+ return;
+
+ boxcontents_param_t *boxcontents = cache->metadatalist->last->boxcontents;
+ Byte_t *xmlstream = (Byte_t *)malloc( boxcontents->length);
+ memcpy( xmlstream, jpipstream+boxcontents->offset, boxcontents->length);
+ send_XMLstream( connected_socket, xmlstream, boxcontents->length);
+ free( xmlstream);
+}
+
+void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
+{
+ char target[MAX_LENOFTARGET], *tid = NULL;
+ cache_param_t *cache;
+ int tidlen = 0;
+
+ receive_line( connected_socket, target);
+ cache = search_cache( target, cachelist);
+
+ if( cache){
+ tid = cache->tid;
+ tidlen = strlen(tid);
+ }
+ send_TIDstream( connected_socket, tid, tidlen);
+}
+
+void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
+{
+ char target[MAX_LENOFTARGET], *cid = NULL;
+ cache_param_t *cache;
+ int cidlen = 0;
+
+ receive_line( connected_socket, target);
+ cache = search_cache( target, cachelist);
+
+ if( cache){
+ if( cache->numOfcid > 0){
+ cid = cache->cid[ cache->numOfcid-1];
+ cidlen = strlen(cid);
+ }
+ }
+ send_CIDstream( connected_socket, cid, cidlen);
+}
+
+void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
+{
+ char cid[MAX_LENOFCID];
+
+ receive_line( connected_socket, cid);
+ remove_cachecid( cid, cachelist);
+ response_signal( connected_socket, true);
+}
+
+void handle_JP2saveMSG( SOCKET connected_socket, cachelist_param_t *cachelist, msgqueue_param_t *msgqueue, Byte_t *jpipstream)
+{
+ char cid[MAX_LENOFCID];
+ cache_param_t *cache;
+ Byte_t *jp2stream;
+ Byte8_t jp2len;
+
+ receive_line( connected_socket, cid);
+ if(!(cache = search_cacheBycid( cid, cachelist)))
+ return;
+
+ jp2stream = recons_jp2( msgqueue, jpipstream, cache->csn, &jp2len);
+
+ if( jp2stream){
+ save_codestream( jp2stream, jp2len, "jp2");
+ free( jp2stream);
+ }
+}
--- /dev/null
+/*
+ * $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
+ * Copyright (c) 2011, Lucian Corlaciu, GSoC
+ * 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.
+ */
+
+#ifndef DEC_CLIENTMSG_HANDLER_H_
+# define DEC_CLIENTMSG_HANDLER_H_
+
+#include "imgsock_manager.h"
+#include "cache_manager.h"
+#include "byte_manager.h"
+#include "msgqueue_manager.h"
+
+/**
+ * handle JPT- JPP- stream message
+ *
+ * @param[in] connected_socket socket descriptor
+ * @param[in] cachelist cache list pointer
+ * @param[in,out] jpipstream address of JPT- JPP- stream pointer
+ * @param[in,out] streamlen address of stream length
+ * @param[in,out] msgqueue message queue pointer
+ */
+void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist, Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue);
+
+/**
+ * handle PNM request message
+ *
+ * @param[in] connected_socket socket descriptor
+ * @param[in] jpipstream jpipstream pointer
+ * @param[in] msgqueue message queue pointer
+ * @param[in] cachelist cache list pointer
+ */
+void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_param_t *msgqueue, cachelist_param_t *cachelist);
+
+/**
+ * handle XML request message
+ *
+ * @param[in] connected_socket socket descriptor
+ * @param[in] jpipstream address of caching jpipstream pointer
+ * @param[in] cachelist cache list pointer
+ */
+void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist);
+
+/**
+ * handle TargetID request message
+ *
+ * @param[in] connected_socket socket descriptor
+ * @param[in] cachelist cache list pointer
+ */
+void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
+
+/**
+ * handle ChannelID request message
+ *
+ * @param[in] connected_socket socket descriptor
+ * @param[in] cachelist cache list pointer
+ */
+void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
+
+/**
+ * handle distroy ChannelID message
+ *
+ * @param[in] connected_socket socket descriptor
+ * @param[in,out] cachelist cache list pointer
+ */
+void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
+
+/**
+ * handle saving JP2 file request message
+ *
+ * @param[in] connected_socket socket descriptor
+ * @param[in] cachelist cache list pointer
+ * @param[in] msgqueue message queue pointer
+ * @param[in] jpipstream address of caching jpipstream pointer
+ */
+void handle_JP2saveMSG( SOCKET connected_socket, cachelist_param_t *cachelist, msgqueue_param_t *msgqueue, Byte_t *jpipstream);
+
+
+#endif /* !DEC_CLIENTMSG_HANDLER_H_ */
--- /dev/null
+/*
+ * $Id: imgsock_manager.c 54 2011-05-10 13:22:47Z kaori $
+ *
+ * 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.
+ */
+
+#ifdef _WIN32
+#include <windows.h>
+#define strcasecmp _stricmp
+#else
+#include <strings.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "imgsock_manager.h"
+
+#define BUF_LEN 256
+
+SOCKET open_listeningsocket()
+{
+ SOCKET listening_socket;
+ struct sockaddr_in sin;
+ int sock_optval = 1;
+ int port = 5000;
+
+ listening_socket = socket(AF_INET, SOCK_STREAM, 0);
+ if ( listening_socket == -1 ){
+ perror("socket");
+ exit(1);
+ }
+
+ if ( setsockopt(listening_socket, SOL_SOCKET, SO_REUSEADDR,
+ &sock_optval, sizeof(sock_optval)) == -1 ){
+ perror("setsockopt");
+ exit(1);
+ }
+
+ memset(&sin, 0, sizeof(sin));
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(port);
+ sin.sin_addr.s_addr = htonl(INADDR_ANY);
+
+ if ( bind(listening_socket, (struct sockaddr *)&sin, sizeof(sin)) < 0 ){
+ perror("bind");
+ close_socket(listening_socket);
+ exit(1);
+ }
+
+ if( listen(listening_socket, SOMAXCONN) == -1){
+ perror("listen");
+ close_socket(listening_socket);
+ exit(1);
+ }
+ printf("port %d is listened\n", port);
+
+ return listening_socket;
+}
+
+SOCKET accept_socket( SOCKET listening_socket)
+{
+ struct sockaddr_in peer_sin;
+ unsigned int addrlen = sizeof(peer_sin);
+
+ return accept( listening_socket, (struct sockaddr *)&peer_sin, &addrlen);
+}
+
+msgtype_t identify_clientmsg( SOCKET connected_socket)
+{
+ int receive_size;
+ char buf[BUF_LEN];
+ char *magicid[] = { "JPIP-stream", "PNM request", "XML request", "TID request", "CID request", "CID destroy", "JP2 save", "QUIT"};
+ int i;
+
+ receive_size = receive_line( connected_socket, buf);
+
+ if( receive_size == 0){
+ fprintf( stderr, "Error to receive the header of client message\n");
+ return MSGERROR;
+ }
+
+ for( i=0; i<NUM_OF_MSGTYPES; i++){
+ if( strncasecmp( magicid[i], buf, strlen(magicid[i])) == 0){
+ printf("%s\n", magicid[i]);
+ return i;
+ }
+ }
+
+ fprintf( stderr, "Cannot identify client message type %s\n", buf);
+ return MSGERROR;
+}
+
+Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *tid, char *cid, int *streamlen)
+{
+ Byte_t *jpipstream=NULL, *ptr;
+ char buf[BUF_LEN], versionstring[] = "version 1.2";
+ int linelen, redlen, remlen;
+
+ target[0] = 0;
+ cid[0] = 0;
+ tid[0] = 0;
+
+ if((linelen = receive_line( connected_socket, buf)) == 0)
+ return NULL;
+ if( strncmp( versionstring, buf, strlen(versionstring))!=0){
+ fprintf( stderr, "Wrong format\n");
+ return NULL;
+ }
+
+ if((linelen = receive_line( connected_socket, buf)) == 0)
+ return NULL;
+
+ if( strstr( buf, "jp2")){
+ // register cid option
+ strcpy( target, buf);
+
+ if((linelen = receive_line( connected_socket, buf)) == 0)
+ return NULL;
+ if( strcmp( buf, "0") != 0)
+ strcpy( tid, buf);
+
+ if((linelen = receive_line( connected_socket, buf)) == 0)
+ return NULL;
+ if( strcmp( buf, "0") != 0)
+ strcpy( cid, buf);
+
+ if((linelen = receive_line( connected_socket, buf)) == 0)
+ return NULL;
+ }
+
+ *streamlen = atoi( buf);
+ fprintf( stderr, "Receive Data: %d Bytes\n", *streamlen);
+
+ jpipstream = (unsigned char *)malloc( (*streamlen));
+ ptr = jpipstream;
+ remlen = (*streamlen);
+ while( remlen > 0){
+ redlen = recv( connected_socket, ptr, remlen, 0);
+ if( redlen == -1){
+ fprintf( stderr, "receive JPT- JPP- stream error\n");
+ break;
+ }
+ remlen -= redlen;
+ ptr = ptr + redlen;
+ }
+
+ return jpipstream;
+}
+
+void send_stream( SOCKET connected_socket, void *stream, int length);
+
+void send_XMLstream( SOCKET connected_socket, Byte_t *xmlstream, int length)
+{
+ Byte_t header[5];
+
+ header[0] = 'X';
+ header[1] = 'M';
+ header[2] = 'L';
+ header[3] = (length >> 8) & 0xff;
+ header[4] = length & 0xff;
+
+ send_stream( connected_socket, header, 5);
+ send_stream( connected_socket, xmlstream, length);
+}
+
+void send_IDstream( SOCKET connected_socket, char *id, int idlen, char *label);
+
+void send_CIDstream( SOCKET connected_socket, char *cid, int cidlen)
+{
+ send_IDstream( connected_socket, cid, cidlen, "CID");
+}
+
+void send_TIDstream( SOCKET connected_socket, char *tid, int tidlen)
+{
+ send_IDstream( connected_socket, tid, tidlen, "TID");
+}
+
+void send_IDstream( SOCKET connected_socket, char *id, int idlen, char *label)
+{
+ Byte_t header[4];
+
+ header[0] = label[0];
+ header[1] = label[1];
+ header[2] = label[2];
+ header[3] = idlen & 0xff;
+
+ send_stream( connected_socket, header, 4);
+ send_stream( connected_socket, id, idlen);
+}
+
+void send_PNMstream( SOCKET connected_socket, Byte_t *pnmstream, unsigned int width, unsigned int height, unsigned int numofcomp, Byte_t maxval)
+{
+ int pnmlen = 0;
+ Byte_t header[7];
+
+ pnmlen = width*height*numofcomp;
+
+ header[0] = 'P';
+ header[1] = numofcomp==3 ? 6:5;
+ header[2] = (width >> 8) & 0xff;
+ header[3] = width & 0xff;
+ header[4] = (height >> 8) & 0xff;
+ header[5] = height & 0xff;
+ header[6] = maxval;
+
+ send_stream( connected_socket, header, 7);
+ send_stream( connected_socket, pnmstream, pnmlen);
+}
+
+void send_stream( SOCKET connected_socket, void *stream, int length)
+{
+ void *ptr = stream;
+ int remlen = length;
+
+ while( remlen > 0){
+ int sentlen = send( connected_socket, ptr, remlen, 0);
+ if( sentlen == -1){
+ fprintf( stderr, "sending stream error\n");
+ break;
+ }
+ remlen = remlen - sentlen;
+ ptr = ptr + sentlen;
+ }
+}
+
+int receive_line(SOCKET connected_socket, char *p)
+{
+ int len = 0;
+ while (1){
+ int ret;
+ ret = recv( connected_socket, p, 1, 0);
+ if ( ret == -1 ){
+ perror("receive");
+ exit(1);
+ } else if ( ret == 0 ){
+ break;
+ }
+ if ( *p == '\n' )
+ break;
+ p++;
+ len++;
+ }
+ *p = '\0';
+
+ if( len == 0)
+ fprintf( stderr, "Header receive error\n");
+
+ return len;
+}
+
+void response_signal( SOCKET connected_socket, bool succeed)
+{
+ Byte_t code;
+
+ if( succeed)
+ code = 1;
+ else
+ code = 0;
+
+ if( send( connected_socket, &code, 1, 0) != 1)
+ fprintf( stderr, "Response signalling error\n");
+}
+
+int close_socket( SOCKET sock)
+{
+#ifdef _WIN32
+ return closesocket( sock);
+#else
+ return close( sock);
+#endif
+}
--- /dev/null
+/*
+ * $Id: imgsock_manager.h 54 2011-05-10 13:22:47Z kaori $
+ *
+ * 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.
+ */
+
+#ifndef IMGSOCK_MANAGER_H_
+# define IMGSOCK_MANAGER_H_
+
+#include "bool.h"
+#include "byte_manager.h"
+
+#ifdef _WIN32
+#include <winsock2.h>
+#else
+typedef int SOCKET;
+#endif //_WIN32
+
+/**
+ * open listening socket
+ *
+ * @return new socket
+ */
+SOCKET open_listeningsocket();
+
+/**
+ * accept a new connection to the listenning socket
+ *
+ * @param listening_socket listenning socket
+ * @return connected socket (-1 if error occurs)
+ */
+SOCKET accept_socket( SOCKET listening_socket);
+
+
+#define NUM_OF_MSGTYPES 8
+typedef enum eMSGTYPE{ JPIPSTREAM, PNMREQ, XMLREQ, TIDREQ, CIDREQ, CIDDST, JP2SAVE, QUIT, MSGERROR} msgtype_t;
+
+/**
+ * indeitify client message type
+ *
+ * @param [in] connected_socket file descriptor of the connected socket
+ * @return message type
+ */
+msgtype_t identify_clientmsg( SOCKET connected_socket);
+
+/**
+ * receive a JPT- JPP- stream from client
+ *
+ * @param [in] connected_socket file descriptor of the connected socket
+ * @param [out] target received target file name (if not received, null string)
+ * @param [out] tid received target identifier (if not received, null string)
+ * @param [out] cid received channel identifier (if not received, null string)
+ * @param [out] streamlen length of the received codestream
+ * @return JPT- JPP- codestream
+ */
+Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *tid, char *cid, int *streamlen);
+
+/**
+ * send PGM/PPM image stream to the client
+ *
+ * @param [in] connected_socket file descriptor of the connected socket
+ * @param [in] pnmstream PGM/PPM image codestream
+ * @param [in] width width of the image
+ * @param [in] height height of the image
+ * @param [in] numofcomp number of components of the image
+ * @param [in] maxval maximum value of the image (only 255 supported)
+ */
+void send_PNMstream( SOCKET connected_socket, Byte_t *pnmstream, unsigned int width, unsigned int height, unsigned int numofcomp, Byte_t maxval);
+
+/**
+ * send XML data stream to the client
+ *
+ * @param [in] connected_socket file descriptor of the connected socket
+ * @param [in] xmlstream xml data stream
+ * @param [in] length legnth of the xml data stream
+ */
+void send_XMLstream( SOCKET connected_socket, Byte_t *xmlstream, int length);
+
+/**
+ * send TID data stream to the client
+ *
+ * @param [in] connected_socket file descriptor of the connected socket
+ * @param [in] tid tid string
+ * @param [in] tidlen legnth of the tid string
+ */
+void send_TIDstream( SOCKET connected_socket, char *tid, int tidlen);
+
+/**
+ * send CID data stream to the client
+ *
+ * @param [in] connected_socket file descriptor of the connected socket
+ * @param [in] cid cid string
+ * @param [in] cidlen legnth of the cid string
+ */
+void send_CIDstream( SOCKET connected_socket, char *cid, int cidlen);
+
+/**
+ * send response signal to the client
+ *
+ * @param [in] connected_socket file descriptor of the connected socket
+ * @param [in] succeed whether if the requested process succeeded
+ */
+void response_signal( SOCKET connected_socket, bool succeed);
+
+/**
+ * receive a string line (ending with '\n') from client
+ *
+ * @param [in] connected_socket file descriptor of the connected socket
+ * @param [out] buf string to be stored
+ * @return red size
+ */
+int receive_line(SOCKET connected_socket, char *buf);
+
+/**
+ * close socket
+ *
+ * @param [in] sock closing socket
+ * @return 0 if succeed, -1 if failed
+ */
+int close_socket( SOCKET sock);
+
+#endif /* !IMGSOCK_MANAGER_H_ */
+
+/*! \file
+ * PROTOCOL specification to communicate with opj_dec_server
+ *
+ *\section sec1 JPIP-stream
+ * Cache JPT- JPP- stream in server
+ *
+ * client -> server: JPIP-stream\\n version 1.1\\n (optional for cid registration: targetnamestring\\n tidstring\\n cidstring\\n) bytelengthvalue\\n data \n
+ * server -> client: 1 or 0 (of 1Byte response signal)
+ *
+ *\section sec2 PNM request
+ * Get decoded PGM/PPM image
+ *
+ * client -> server: PNM request\\n [cid/tid]string\\n fw\\n fh\\n \n
+ * server -> client: P6 or P5 (2Byte) width (2Byte Big endian) height (2Byte Big endian) maxval (1Byte) data
+ *
+ *\section sec3 XML request
+ * Get XML data
+ *
+ * client -> server: XML request\\n \n
+ * server -> client: XML (3Byte) length (2Byte Big endian) data
+ *
+ *\section sec4 TID request
+ * Get target ID of target image
+ *
+ * client -> server: TID request\\n targetname\\n \n
+ * server -> client: TID (3Byte) length (1Byte) tiddata
+ *
+ *\section sec5 CID request
+ * Get Channel ID of identical target image
+ *
+ * client -> server: CID request\\n targetname\\n \n
+ * server -> client: CID (3Byte) length (1Byte) ciddata
+ *
+ *\section sec6 CID destroy
+ * Close Channel ID
+ *
+ * client -> server: CID destroy\\n ciddata \n
+ * server -> client: 1 or 0 (of 1Byte response signal)
+ *
+ *\section sec7 JP2 save
+ * Save in JP2 file format
+ *
+ * client -> server: JP2 save\\n ciddata \n
+ * server -> client: 1 or 0 (of 1Byte response signal)
+ *
+ *\section sec8 QUIT
+ * Quit the opj_dec_server program
+ *
+ * client -> server: quit or QUIT
+ */
--- /dev/null
+/*
+ * $Id: jp2k_decoder.c 53 2011-05-09 16:55:39Z kaori $
+ *
+ * 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.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "jp2k_decoder.h"
+#include "openjpeg.h"
+
+
+void error_callback(const char *msg, void *client_data);
+void warning_callback(const char *msg, void *client_data);
+void info_callback(const char *msg, void *client_data);
+
+Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox);
+
+Byte_t * j2k_to_pnm( Byte_t *j2kstream, Byte8_t j2klen, ihdrbox_param_t **ihdrbox)
+{
+ Byte_t *pnmstream = NULL;
+ opj_dparameters_t parameters; /* decompression parameters */
+ opj_event_mgr_t event_mgr; /* event manager */
+ opj_image_t *image = NULL;
+ opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
+ opj_cio_t *cio = NULL;
+
+ /* configure the event callbacks (not required) */
+ memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
+ event_mgr.error_handler = error_callback;
+ event_mgr.warning_handler = warning_callback;
+ event_mgr.info_handler = info_callback;
+
+ /* set decoding parameters to default values */
+ opj_set_default_decoder_parameters(¶meters);
+
+ /* decode the code-stream */
+ /* ---------------------- */
+
+ /* JPEG-2000 codestream */
+ /* get a decoder handle */
+ dinfo = opj_create_decompress( CODEC_J2K);
+
+ /* catch events using our callbacks and give a local context */
+ opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
+
+ /* setup the decoder decoding parameters using user parameters */
+ opj_setup_decoder(dinfo, ¶meters);
+ /* open a byte stream */
+ cio = opj_cio_open((opj_common_ptr)dinfo, j2kstream, j2klen);
+
+ fprintf( stderr, "opj_decode dinfo:%p cio:%p\n", dinfo, cio);
+ /* decode the stream and fill the image structure */
+ image = opj_decode(dinfo, cio);
+
+ fprintf( stderr, "done\n");
+ if(!image) {
+ fprintf(stderr, "ERROR -> jp2_to_image: failed to decode image!\n");
+ opj_destroy_decompress(dinfo);
+ opj_cio_close(cio);
+ return NULL;
+ }
+
+ /* close the byte stream */
+ opj_cio_close(cio);
+
+ /* create output image */
+ /* ------------------- */
+ if( (pnmstream = imagetopnm( image, ihdrbox))==NULL)
+ fprintf( stderr, "PNM image not generated\n");
+
+ /* free remaining structures */
+ if(dinfo) {
+ opj_destroy_decompress(dinfo);
+ }
+
+ /* free image data structure */
+ opj_image_destroy(image);
+
+ return pnmstream;
+}
+
+
+/**
+ sample error callback expecting a FILE* client object
+*/
+void error_callback(const char *msg, void *client_data) {
+ FILE *stream = (FILE*)client_data;
+ fprintf(stream, "[ERROR] %s", msg);
+}
+/**
+ sample warning callback expecting a FILE* client object
+*/
+void warning_callback(const char *msg, void *client_data) {
+ FILE *stream = (FILE*)client_data;
+ fprintf(stream, "[WARNING] %s", msg);
+}
+/**
+ sample debug callback expecting no client object
+*/
+void info_callback(const char *msg, void *client_data) {
+ (void)client_data;
+ // fprintf(stdout, "[INFO] %s", msg);
+}
+
+
+Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox)
+{
+ int adjustR, adjustG=0, adjustB=0;
+ int datasize;
+ Byte_t *pix=NULL, *ptr=NULL;
+ int i;
+
+ if(*ihdrbox){
+ if( (*ihdrbox)->nc != image->numcomps)
+ fprintf( stderr, "Exception: num of components not identical, codestream: %d, ihdrbox: %d\n", image->numcomps, (*ihdrbox)->nc);
+
+ if( (*ihdrbox)->width != image->comps[0].w)
+ (*ihdrbox)->width = image->comps[0].w;
+
+ if( (*ihdrbox)->height != image->comps[0].h)
+ (*ihdrbox)->height = image->comps[0].h;
+
+ if( (*ihdrbox)->bpc != image->comps[0].prec)
+ fprintf( stderr, "Exception: bits per component not identical, codestream: %d, ihdrbox: %d\n", image->comps[0].prec, (*ihdrbox)->bpc);
+ }
+ else{
+ *ihdrbox = (ihdrbox_param_t *)malloc( sizeof(ihdrbox_param_t));
+ (*ihdrbox)->width = image->comps[0].w;
+ (*ihdrbox)->height = image->comps[0].h;
+ (*ihdrbox)->bpc = image->comps[0].prec;
+ (*ihdrbox)->nc = image->numcomps;
+ }
+
+ datasize = (image->numcomps)*(image->comps[0].w)*(image->comps[0].h);
+
+ if (image->comps[0].prec > 8) {
+ adjustR = image->comps[0].prec - 8;
+ printf("PNM CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec);
+ }
+ else
+ adjustR = 0;
+
+ if( image->numcomps == 3){
+ if (image->comps[1].prec > 8) {
+ adjustG = image->comps[1].prec - 8;
+ printf("PNM CONVERSION: Truncating component 1 from %d bits to 8 bits\n", image->comps[1].prec);
+ }
+ else
+ adjustG = 0;
+
+ if (image->comps[2].prec > 8) {
+ adjustB = image->comps[2].prec - 8;
+ printf("PNM CONVERSION: Truncating component 2 from %d bits to 8 bits\n", image->comps[2].prec);
+ }
+ else
+ adjustB = 0;
+ }
+
+ pix = (Byte_t *)malloc( datasize);
+ ptr = pix;
+
+ for( i = 0; i < image->comps[0].w * image->comps[0].h; i++){
+ int r, g, b;
+ r = image->comps[0].data[i];
+ r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
+
+ // if( adjustR > 0)
+ *(ptr++) = (Byte_t) ((r >> adjustR)+((r >> (adjustR-1))%2));
+
+ if( image->numcomps == 3){
+ g = image->comps[1].data[i];
+ g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
+ *(ptr++) = (Byte_t) ((g >> adjustG)+((g >> (adjustG-1))%2));
+
+ b = image->comps[2].data[i];
+ b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0);
+ *(ptr++) = (Byte_t) ((b >> adjustB)+((b >> (adjustB-1))%2));
+ }
+ }
+
+ return pix;
+}
--- /dev/null
+/*
+ * $Id: jp2k_decoder.h 44 2011-02-15 12:32:29Z kaori $
+ *
+ * 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.
+ */
+
+#ifndef JP2K_DECODER_H_
+# define JP2K_DECODER_H_
+
+#include "byte_manager.h"
+#include "ihdrbox_manager.h"
+
+Byte_t * j2k_to_pnm( Byte_t *j2kstream, Byte8_t j2klen, ihdrbox_param_t **ihdrbox);
+
+#endif /* !JP2K_DECODER_H_ */
--- /dev/null
+/*
+ * $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
+ * Copyright (c) 2011, Lucian Corlaciu, GSoC
+ * 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.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "jpip_parser.h"
+#include "channel_manager.h"
+#include "imgreg_manager.h"
+
+#ifdef SERVER
+#include "fcgi_stdio.h"
+#define logstream FCGI_stdout
+#else
+#define FCGI_stdout stdout
+#define FCGI_stderr stderr
+#define logstream stderr
+#endif //SERVER
+
+
+bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target)
+{
+ if( query_param.tid[0] !='\0' && strcmp( query_param.tid, "0") != 0 ){
+ if( query_param.cid[0] != '\0'){
+ fprintf( FCGI_stdout, "Reason: Target can not be specified both through tid and cid\r\n");
+ fprintf( FCGI_stdout, "Status: 400\r\n");
+ return false;
+ }
+ if( ( *target = search_targetBytid( query_param.tid, targetlist)))
+ return true;
+ }
+
+ if( query_param.target[0] !='\0')
+ if( !( *target = search_target( query_param.target, targetlist)))
+ if(!( *target = gene_target( targetlist, query_param.target)))
+ return false;
+
+ if( *target){
+ fprintf( FCGI_stdout, "JPIP-tid: %s\r\n", (*target)->tid);
+ return true;
+ }
+ else{
+ fprintf( FCGI_stdout, "Reason: target not found\r\n");
+ fprintf( FCGI_stdout, "Status: 400\r\n");
+ return false;
+ }
+}
+
+bool associate_channel( query_param_t query_param,
+ sessionlist_param_t *sessionlist,
+ session_param_t **cursession,
+ channel_param_t **curchannel)
+{
+ if( search_session_and_channel( query_param.cid, sessionlist, cursession, curchannel)){
+
+ if( !query_param.cnew)
+ set_channel_variable_param( query_param, *curchannel);
+ }
+ else{
+ fprintf( FCGI_stderr, "Error: process canceled\n");
+ return false;
+ }
+ return true;
+}
+
+bool open_channel( query_param_t query_param,
+ sessionlist_param_t *sessionlist,
+ target_param_t *target,
+ session_param_t **cursession,
+ channel_param_t **curchannel)
+{
+ cachemodel_param_t *cachemodel = NULL;
+
+ if( target){
+ if( !(*cursession))
+ *cursession = gene_session( sessionlist);
+ if( !( cachemodel = search_cachemodel( target, (*cursession)->cachemodellist)))
+ if( !(cachemodel = gene_cachemodel( (*cursession)->cachemodellist, target, query_param.return_type==JPPstream)))
+ return false;
+ }
+ else
+ if( *curchannel)
+ cachemodel = (*curchannel)->cachemodel;
+
+ *curchannel = gene_channel( query_param, cachemodel, (*cursession)->channellist);
+ if( *curchannel == NULL)
+ return false;
+
+ return true;
+}
+
+bool close_channel( query_param_t query_param,
+ sessionlist_param_t *sessionlist,
+ session_param_t **cursession,
+ channel_param_t **curchannel)
+{
+ if( query_param.cclose[0][0] =='*'){
+#ifndef SERVER
+ fprintf( logstream, "local log: close all\n");
+#endif
+ // all channels associatd with the session will be closed
+ if( !delete_session( cursession, sessionlist))
+ return false;
+ }
+ else{
+ // check if all entry belonging to the same session
+ int i=0;
+ while( query_param.cclose[i][0] !='\0'){
+
+ // In case of the first entry of close cid
+ if( *cursession == NULL){
+ if( !search_session_and_channel( query_param.cclose[i], sessionlist, cursession, curchannel))
+ return false;
+ }
+ else // second or more entry of close cid
+ if( !(*curchannel=search_channel( query_param.cclose[i], (*cursession)->channellist))){
+ fprintf( FCGI_stdout, "Reason: Cclose id %s is from another session\r\n", query_param.cclose[i]);
+ return false;
+ }
+ i++;
+ }
+ // delete channels
+ i=0;
+ while( query_param.cclose[i][0] !='\0'){
+
+ *curchannel = search_channel( query_param.cclose[i], (*cursession)->channellist);
+ delete_channel( curchannel, (*cursession)->channellist);
+ i++;
+ }
+
+ if( (*cursession)->channellist->first == NULL || (*cursession)->channellist->last == NULL)
+ // In case of empty session
+ delete_session( cursession, sessionlist);
+ }
+ return true;
+}
+
+
+/**
+ * enqueue tiles or precincts into the message queue
+ *
+ * @param[in] query_param structured query
+ * @param[in] msgqueue message queue pointer
+ */
+void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue);
+
+/**
+ * enqueue metadata bins into the message queue
+ *
+ * @param[in] query_param structured query
+ * @param[in] metadatalist pointer to metadata bin list
+ * @param[in,out] msgqueue message queue pointer
+ */
+void enqueue_metabins( query_param_t query_param, metadatalist_param_t *metadatalist, msgqueue_param_t *msgqueue);
+
+
+bool gene_JPIPstream( query_param_t query_param,
+ target_param_t *target,
+ session_param_t *cursession,
+ channel_param_t *curchannel,
+ msgqueue_param_t **msgqueue)
+{
+ index_param_t *codeidx;
+ cachemodel_param_t *cachemodel;
+
+ if( !cursession || !curchannel){ // stateless
+ if( !target)
+ return false;
+ if( !(cachemodel = gene_cachemodel( NULL, target, query_param.return_type==JPPstream)))
+ return false;
+ *msgqueue = gene_msgqueue( true, cachemodel);
+ }
+ else{ // session
+ cachemodel = curchannel->cachemodel;
+ target = cachemodel->target;
+ *msgqueue = gene_msgqueue( false, cachemodel);
+ }
+
+ codeidx = target->codeidx;
+
+ if( cachemodel->jppstream)
+ fprintf( FCGI_stdout, "Content-type: image/jpp-stream\r\n");
+ else
+ fprintf( FCGI_stdout, "Content-type: image/jpt-stream\r\n");
+
+ if( query_param.layers != -1){
+ if( query_param.layers > codeidx->COD.numOflayers){
+ fprintf( FCGI_stdout, "JPIP-layers: %d\r\n", codeidx->COD.numOflayers);
+ query_param.layers = codeidx->COD.numOflayers;
+ }
+ }
+
+ //meta
+ if( query_param.box_type[0][0] != 0 && query_param.len != 0)
+ enqueue_metabins( query_param, codeidx->metadatalist, *msgqueue);
+
+ // image codestream
+ if( query_param.fx > 0 && query_param.fy > 0){
+ if( !cachemodel->mhead_model && query_param.len != 0)
+ enqueue_mainheader( *msgqueue);
+ enqueue_imagedata( query_param, *msgqueue);
+ }
+ return true;
+}
+
+
+/**
+ * enqueue precinct data-bins into the queue
+ *
+ * @param[in] xmin min x coordinate in the tile at the decomposition level
+ * @param[in] xmax max x coordinate in the tile at the decomposition level
+ * @param[in] ymin min y coordinate in the tile at the decomposition level
+ * @param[in] ymax max y coordinate in the tile at the decomposition level
+ * @param[in] tile_id tile index
+ * @param[in] level decomposition level
+ * @param[in] lastcomp last component number
+ * @param[in] comps pointer to the array that stores the requested components
+ * @param[in] layers number of quality layers
+ * @param[in] msgqueue message queue
+ * @return
+ */
+void enqueue_precincts( int xmin, int xmax, int ymin, int ymax, int tile_id, int level, int lastcomp, bool *comps, int layers, msgqueue_param_t *msgqueue);
+
+/**
+ * enqueue all precincts inside a tile into the queue
+ *
+ * @param[in] tile_id tile index
+ * @param[in] level decomposition level
+ * @param[in] lastcomp last component number
+ * @param[in] comps pointer to the array that stores the requested components
+ * @param[in] layers number of quality layers
+ * @param[in] msgqueue message queue
+ * @return
+ */
+void enqueue_allprecincts( int tile_id, int level, int lastcomp, bool *comps, int layers, msgqueue_param_t *msgqueue);
+
+void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
+{
+ index_param_t *codeidx;
+ imgreg_param_t imgreg;
+ range_param_t tile_Xrange, tile_Yrange;
+ int u, v, tile_id;
+ int xmin, xmax, ymin, ymax;
+ int numOfreslev;
+
+ codeidx = msgqueue->cachemodel->target->codeidx;
+
+ if( !(msgqueue->cachemodel->jppstream) && get_nmax( codeidx->tilepart) == 1) // normally not the case
+ numOfreslev = 1;
+ else
+ numOfreslev = codeidx->COD.numOfdecomp+1;
+
+ imgreg = map_viewin2imgreg( query_param.fx, query_param.fy,
+ query_param.rx, query_param.ry, query_param.rw, query_param.rh,
+ codeidx->SIZ.XOsiz, codeidx->SIZ.YOsiz, codeidx->SIZ.Xsiz, codeidx->SIZ.Ysiz,
+ numOfreslev );
+
+ if( query_param.len == 0)
+ return;
+
+ for( u=0, tile_id=0; u<codeidx->SIZ.YTnum; u++){
+ tile_Yrange = get_tile_Yrange( codeidx->SIZ, tile_id, imgreg.level);
+
+ for( v=0; v<codeidx->SIZ.XTnum; v++, tile_id++){
+ tile_Xrange = get_tile_Xrange( codeidx->SIZ, tile_id, imgreg.level);
+
+ if( tile_Xrange.minvalue < tile_Xrange.maxvalue && tile_Yrange.minvalue < tile_Yrange.maxvalue){
+ if( tile_Xrange.maxvalue <= imgreg.xosiz + imgreg.ox ||
+ tile_Xrange.minvalue >= imgreg.xosiz + imgreg.ox + imgreg.sx ||
+ tile_Yrange.maxvalue <= imgreg.yosiz + imgreg.oy ||
+ tile_Yrange.minvalue >= imgreg.yosiz + imgreg.oy + imgreg.sy) {
+ //printf("Tile completely excluded from view-window %d\n", tile_id);
+ // Tile completely excluded from view-window
+ }
+ else if( tile_Xrange.minvalue >= imgreg.xosiz + imgreg.ox &&
+ tile_Xrange.maxvalue <= imgreg.xosiz + imgreg.ox + imgreg.sx &&
+ tile_Yrange.minvalue >= imgreg.yosiz + imgreg.oy &&
+ tile_Yrange.maxvalue <= imgreg.yosiz + imgreg.oy + imgreg.sy) {
+ // Tile completely contained within view-window
+ // high priority
+ //printf("Tile completely contained within view-window %d\n", tile_id);
+ if( msgqueue->cachemodel->jppstream){
+ enqueue_tileheader( tile_id, msgqueue);
+ enqueue_allprecincts( tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue);
+ }
+ else
+ enqueue_tile( tile_id, imgreg.level, msgqueue);
+ }
+ else{
+ // Tile partially overlaps view-window
+ // low priority
+ //printf("Tile partially overlaps view-window %d\n", tile_id);
+ if( msgqueue->cachemodel->jppstream){
+ enqueue_tileheader( tile_id, msgqueue);
+
+ xmin = tile_Xrange.minvalue >= imgreg.xosiz + imgreg.ox ? 0 : imgreg.xosiz + imgreg.ox - tile_Xrange.minvalue;
+ xmax = tile_Xrange.maxvalue <= imgreg.xosiz + imgreg.ox + imgreg.sx ? tile_Xrange.maxvalue - tile_Xrange.minvalue -1 : imgreg.xosiz + imgreg.ox + imgreg.sx - tile_Xrange.minvalue -1;
+ ymin = tile_Yrange.minvalue >= imgreg.yosiz + imgreg.oy ? 0 : imgreg.yosiz + imgreg.oy - tile_Yrange.minvalue;
+ ymax = tile_Yrange.maxvalue <= imgreg.yosiz + imgreg.oy + imgreg.sy ? tile_Yrange.maxvalue - tile_Yrange.minvalue -1 : imgreg.yosiz + imgreg.oy + imgreg.sy - tile_Yrange.minvalue -1;
+ enqueue_precincts( xmin, xmax, ymin, ymax, tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue);
+ }
+ else
+ enqueue_tile( tile_id, imgreg.level, msgqueue);
+ }
+ }
+ }
+ }
+}
+
+
+void enqueue_precincts( int xmin, int xmax, int ymin, int ymax, int tile_id, int level, int lastcomp, bool *comps, int layers, msgqueue_param_t *msgqueue)
+{
+ index_param_t *codeidx;
+ int c, u, v, res_lev, dec_lev;
+ int seq_id;
+ Byte4_t XTsiz, YTsiz;
+ Byte4_t XPsiz, YPsiz;
+ Byte4_t xminP, xmaxP, yminP, ymaxP;
+
+ codeidx = msgqueue->cachemodel->target->codeidx;
+
+ for( c=0; c<codeidx->SIZ.Csiz; c++)
+ if( lastcomp == -1 /*all*/ || ( c<=lastcomp && comps[c])){
+ seq_id = 0;
+ for( res_lev=0, dec_lev=codeidx->COD.numOfdecomp; dec_lev>=level; res_lev++, dec_lev--){
+
+ XTsiz = get_tile_XSiz( codeidx->SIZ, tile_id, dec_lev);
+ YTsiz = get_tile_YSiz( codeidx->SIZ, tile_id, dec_lev);
+
+ XPsiz = ( codeidx->COD.Scod & 0x01) ? codeidx->COD.XPsiz[ res_lev] : XTsiz;
+ YPsiz = ( codeidx->COD.Scod & 0x01) ? codeidx->COD.YPsiz[ res_lev] : YTsiz;
+
+ for( u=0; u<ceil((double)YTsiz/(double)YPsiz); u++){
+ yminP = u*YPsiz;
+ ymaxP = (u+1)*YPsiz-1;
+ if( YTsiz <= ymaxP)
+ ymaxP = YTsiz-1;
+
+ for( v=0; v<ceil((double)XTsiz/(double)XPsiz); v++, seq_id++){
+ xminP = v*XPsiz;
+ xmaxP = (v+1)*XPsiz-1;
+ if( XTsiz <= xmaxP)
+ xmaxP = XTsiz-1;
+
+ if( xmaxP < xmin || xminP > xmax || ymaxP < ymin || yminP > ymax){
+ // Precinct completely excluded from view-window
+ }
+ else if( xminP >= xmin && xmaxP <= xmax && yminP >= ymin && ymaxP <= ymax){
+ // Precinct completely contained within view-window
+ // high priority
+ enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue);
+ }
+ else{
+ // Precinct partially overlaps view-window
+ // low priority
+ enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue);
+ }
+ }
+ }
+ }
+ }
+}
+
+void enqueue_allprecincts( int tile_id, int level, int lastcomp, bool *comps, int layers, msgqueue_param_t *msgqueue)
+{
+ index_param_t *codeidx;
+ int c, i, res_lev, dec_lev;
+ int seq_id;
+ Byte4_t XTsiz, YTsiz;
+ Byte4_t XPsiz, YPsiz;
+
+ codeidx = msgqueue->cachemodel->target->codeidx;
+
+ for( c=0; c<codeidx->SIZ.Csiz; c++)
+ if( lastcomp == -1 /*all*/ || ( c<=lastcomp && comps[c])){
+ seq_id = 0;
+ for( res_lev=0, dec_lev=codeidx->COD.numOfdecomp; dec_lev>=level; res_lev++, dec_lev--){
+
+ XTsiz = get_tile_XSiz( codeidx->SIZ, tile_id, dec_lev);
+ YTsiz = get_tile_YSiz( codeidx->SIZ, tile_id, dec_lev);
+
+ XPsiz = ( codeidx->COD.Scod & 0x01) ? codeidx->COD.XPsiz[ res_lev] : XTsiz;
+ YPsiz = ( codeidx->COD.Scod & 0x01) ? codeidx->COD.YPsiz[ res_lev] : YTsiz;
+
+ for( i=0; i<ceil((double)YTsiz/(double)YPsiz)*ceil((double)XTsiz/(double)XPsiz); i++, seq_id++)
+ enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue);
+ }
+ }
+}
+
+void enqueue_metabins( query_param_t query_param, metadatalist_param_t *metadatalist, msgqueue_param_t *msgqueue)
+{
+ int i;
+ for( i=0; query_param.box_type[i][0]!=0 && i<MAX_NUMOFBOX; i++){
+ if( query_param.box_type[i][0] == '*'){
+ // not implemented
+ }
+ else{
+ int idx = search_metadataidx( query_param.box_type[i], metadatalist);
+
+ if( idx != -1)
+ enqueue_metadata( idx, msgqueue);
+ }
+ }
+}
--- /dev/null
+/*
+ * $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
+ * Copyright (c) 2011, Lucian Corlaciu, GSoC
+ * 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.
+ */
+
+#ifndef JPIP_PARSER_H_
+# define JPIP_PARSER_H_
+
+#include "bool.h"
+#include "query_parser.h"
+#include "session_manager.h"
+#include "target_manager.h"
+#include "msgqueue_manager.h"
+#include "channel_manager.h"
+
+/**
+ * REQUEST: target identification by target or tid request
+ *
+ * @param[in] query_param structured query
+ * @param[in] targetlist target list pointer
+ * @param[out] target address of target pointer
+ * @return if succeeded (true) or failed (false)
+ */
+bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target);
+
+/**
+ * REQUEST: channel association
+ * this must be processed before any process
+ *
+ * @param[in] query_param structured query
+ * @param[in] sessionlist session list pointer
+ * @param[out] cursession address of the associated session pointer
+ * @param[out] curchannel address of the associated channel pointer
+ * @return if succeeded (true) or failed (false)
+ */
+bool associate_channel( query_param_t query_param,
+ sessionlist_param_t *sessionlist,
+ session_param_t **cursession,
+ channel_param_t **curchannel);
+/**
+ * REQUEST: new channel (cnew) assignment
+ *
+ * @param[in] query_param structured query
+ * @param[in] sessionlist session list pointer
+ * @param[in] target requested target pointer
+ * @param[in,out] cursession address of the associated/opened session pointer
+ * @param[in,out] curchannel address of the associated/opened channel pointer
+ * @return if succeeded (true) or failed (false)
+ */
+bool open_channel( query_param_t query_param,
+ sessionlist_param_t *sessionlist,
+ target_param_t *target,
+ session_param_t **cursession,
+ channel_param_t **curchannel);
+
+/**
+ * REQUEST: channel close (cclose)
+ *
+ * @param[in] query_param structured query
+ * @param[in] sessionlist session list pointer
+ * @param[in,out] cursession address of the session pointer of deleting channel
+ * @param[in,out] curchannel address of the deleting channel pointer
+ * @return if succeeded (true) or failed (false)
+ */
+bool close_channel( query_param_t query_param,
+ sessionlist_param_t *sessionlist,
+ session_param_t **cursession,
+ channel_param_t **curchannel);
+
+/**
+ * REQUEST: view-window (fsiz)
+ *
+ * @param[in] query_param structured query
+ * @param[in] target requested target pointer
+ * @param[in,out] cursession associated session pointer
+ * @param[in,out] curchannel associated channel pointer
+ * @param[out] msgqueue address of the message queue pointer
+ * @return if succeeded (true) or failed (false)
+ */
+bool gene_JPIPstream( query_param_t query_param,
+ target_param_t *target,
+ session_param_t *cursession,
+ channel_param_t *curchannel,
+ msgqueue_param_t **msgqueue);
+
+#endif /* !JPIP_PARSER_H_ */
--- /dev/null
+/*
+ * $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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "jpipstream_manager.h"
+#include "jp2k_encoder.h"
+#include "jp2k_decoder.h"
+
+Byte_t * update_JPIPstream( Byte_t *newstream, int newstreamlen, Byte_t *cache_stream, int *streamlen)
+{
+ Byte_t *stream = (Byte_t *)malloc( (*streamlen)+newstreamlen);
+ if( *streamlen > 0)
+ memcpy( stream, cache_stream, *streamlen);
+ memcpy( stream+(*streamlen), newstream, newstreamlen);
+ *streamlen += newstreamlen;
+
+ if(cache_stream)
+ free( cache_stream);
+
+ return stream;
+}
+
+void save_codestream( Byte_t *codestream, Byte8_t streamlen, char *fmt)
+{
+ time_t timer;
+ struct tm *t_st;
+ char filename[20];
+ FILE *fp;
+
+ time(&timer);
+ t_st = localtime( &timer);
+
+ sprintf( filename, "%4d%02d%02d%02d%02d%02d.%.3s", t_st->tm_year+1900, t_st->tm_mon+1, t_st->tm_mday, t_st->tm_hour, t_st->tm_min, t_st->tm_sec, fmt);
+
+ fp = fopen( filename, "wb");
+ fwrite( codestream, streamlen, 1, fp);
+ fclose( fp);
+}
+
+
+Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn, int fw, int fh, ihdrbox_param_t **ihdrbox)
+{
+ Byte_t *pnmstream;
+ Byte_t *j2kstream; // j2k or jp2 codestream
+ Byte8_t j2klen;
+
+ j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen);
+ pnmstream = j2k_to_pnm( j2kstream, j2klen, ihdrbox);
+
+ free( j2kstream);
+
+ return pnmstream;
+}
--- /dev/null
+/*
+ * $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.
+ */
+
+#include "byte_manager.h"
+#include "msgqueue_manager.h"
+#include "ihdrbox_manager.h"
+
+Byte_t * update_JPIPstream( Byte_t *newstream, int newstreamlen, Byte_t *cache_stream, int *streamlen);
+
+void save_codestream( Byte_t *codestream, Byte8_t streamlen, char *fmt);
+
+Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn, int fw, int fh, ihdrbox_param_t **ihdrbox);
--- /dev/null
+/*
+ * $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.
+ */
+
+#include <stdlib.h>
+#include "openjpip.h"
+#include "jpip_parser.h"
+#include "channel_manager.h"
+
+#include <stdio.h>
+#include "dec_clientmsg_handler.h"
+#include "jpipstream_manager.h"
+
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "jp2k_encoder.h"
+
+server_record_t * init_JPIPserver()
+{
+ server_record_t *record = (server_record_t *)malloc( sizeof(server_record_t));
+
+ record->sessionlist = gene_sessionlist();
+ record->targetlist = gene_targetlist();
+
+ return record;
+}
+
+void terminate_JPIPserver( server_record_t **rec)
+{
+ delete_sessionlist( &(*rec)->sessionlist);
+ delete_targetlist( &(*rec)->targetlist);
+
+ free( *rec);
+}
+
+QR_t * parse_querystring( char *query_string)
+{
+ QR_t *qr;
+
+ qr = (QR_t *)malloc( sizeof(QR_t));
+
+ qr->query = parse_query( query_string);
+
+ qr->msgqueue = NULL;
+
+ return qr;
+}
+
+bool process_JPIPrequest( server_record_t *rec, QR_t *qr)
+{
+ target_param_t *target = NULL;
+ session_param_t *cursession = NULL;
+ channel_param_t *curchannel = NULL;
+
+ if( qr->query->target[0] != '\0' || qr->query->tid[0] != '\0'){
+ if( !identify_target( *(qr->query), rec->targetlist, &target))
+ return false;
+ }
+
+ if( qr->query->cid[0] != '\0'){
+ if( !associate_channel( *(qr->query), rec->sessionlist, &cursession, &curchannel))
+ return false;
+ }
+
+ if( qr->query->cnew){
+ if( !open_channel( *(qr->query), rec->sessionlist, target, &cursession, &curchannel))
+ return false;
+ }
+ if( qr->query->cclose[0][0] != '\0')
+ if( !close_channel( *(qr->query), rec->sessionlist, &cursession, &curchannel))
+ return false;
+
+ if( (qr->query->fx > 0 && qr->query->fy > 0) || qr->query->box_type[0][0] != 0)
+ if( !gene_JPIPstream( *(qr->query), target, cursession, curchannel, &qr->msgqueue))
+ return false;
+
+ return true;
+}
+
+void send_responsedata( QR_t *qr)
+{
+ // Currently HTTP support only, find a way for TCP, UDP case
+ emit_stream_from_msgqueue( qr->msgqueue);
+}
+
+void end_QRprocess( server_record_t *rec, QR_t **qr)
+{
+ // TODO: record client preferences if necessary
+
+ delete_query( &((*qr)->query));
+ delete_msgqueue( &((*qr)->msgqueue));
+ free( *qr);
+}
+
+void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr, server_record_t *rec)
+{
+ if( query)
+ print_queryparam( *qr->query);
+
+ if( messages)
+ print_msgqueue( qr->msgqueue);
+
+ if( sessions)
+ print_allsession( rec->sessionlist);
+
+ if( targets)
+ print_alltarget( rec->targetlist);
+}
+
+#ifndef SERVER
+
+dec_server_record_t * init_dec_server()
+{
+ dec_server_record_t *record = (dec_server_record_t *)malloc( sizeof(dec_server_record_t));
+
+ record->cachelist = gene_cachelist();
+ record->jpipstream = NULL;
+ record->jpipstreamlen = 0;
+ record->msgqueue = gene_msgqueue( true, NULL);
+ record->listening_socket = open_listeningsocket();
+
+ return record;
+}
+
+void terminate_dec_server( dec_server_record_t **rec)
+{
+ delete_cachelist( &(*rec)->cachelist);
+ free( (*rec)->jpipstream);
+
+ if( (*rec)->msgqueue)
+ delete_msgqueue( &((*rec)->msgqueue));
+
+ if( close_socket( (*rec)->listening_socket) != 0)
+ perror("close");
+
+ free( *rec);
+}
+
+client_t accept_connection( dec_server_record_t *rec)
+{
+ client_t client;
+
+ client = accept_socket( rec->listening_socket);
+ if( client == -1)
+ fprintf( stderr, "error: failed to connect to client\n");
+
+ return client;
+}
+
+bool handle_clientreq( client_t client, dec_server_record_t *rec)
+{
+ bool quit = false;
+ msgtype_t msgtype = identify_clientmsg( client);
+
+ switch( msgtype){
+ case JPIPSTREAM:
+ handle_JPIPstreamMSG( client, rec->cachelist, &rec->jpipstream, &rec->jpipstreamlen, rec->msgqueue);
+ break;
+
+ case PNMREQ:
+ handle_PNMreqMSG( client, rec->jpipstream, rec->msgqueue, rec->cachelist);
+ break;
+
+ case XMLREQ:
+ handle_XMLreqMSG( client, rec->jpipstream, rec->cachelist);
+ break;
+
+ case TIDREQ:
+ handle_TIDreqMSG( client, rec->cachelist);
+ break;
+
+ case CIDREQ:
+ handle_CIDreqMSG( client, rec->cachelist);
+ break;
+
+ case CIDDST:
+ handle_dstCIDreqMSG( client, rec->cachelist);
+ break;
+
+ case JP2SAVE:
+ handle_JP2saveMSG( client, rec->cachelist, rec->msgqueue, rec->jpipstream);
+ break;
+
+ case QUIT:
+ quit = true;
+ save_codestream( rec->jpipstream, rec->jpipstreamlen, "jpt");
+ break;
+ case MSGERROR:
+ break;
+ }
+
+ printf("\t end of the connection\n\n");
+ if( close_socket(client) != 0){
+ perror("close");
+ return false;
+ }
+ if( quit)
+ return false;
+
+ return true;
+}
+
+
+jpip_dec_param_t * init_jpipdecoder( bool jp2)
+{
+ jpip_dec_param_t *dec;
+
+ dec = (jpip_dec_param_t *)calloc( 1, sizeof(jpip_dec_param_t));
+
+ dec->msgqueue = gene_msgqueue( true, NULL);
+
+ if( jp2)
+ dec->metadatalist = gene_metadatalist();
+
+ return dec;
+}
+
+
+bool fread_jpip( char fname[], jpip_dec_param_t *dec)
+{
+ int infd;
+ struct stat sb;
+
+ if(( infd = open( fname, O_RDONLY)) == -1){
+ fprintf( stderr, "file %s not exist\n", fname);
+ return false;
+ }
+
+ if( fstat( infd, &sb) == -1){
+ fprintf( stderr, "input file stream is broken\n");
+ return false;
+ }
+ dec->jpiplen = (Byte8_t)sb.st_size;
+
+ dec->jpipstream = (Byte_t *)malloc( dec->jpiplen);
+
+ if( read( infd, dec->jpipstream, dec->jpiplen) != dec->jpiplen){
+ fprintf( stderr, "file reading error\n");
+ free( dec->jpipstream);
+ return false;
+ }
+
+ close(infd);
+
+ return true;
+}
+
+void decode_jpip( jpip_dec_param_t *dec)
+{
+ parse_JPIPstream( dec->jpipstream, dec->jpiplen, 0, dec->msgqueue);
+
+ if( dec->metadatalist){ // JP2 encoding
+ parse_metamsg( dec->msgqueue, dec->jpipstream, dec->jpiplen, dec->metadatalist);
+ dec->ihdrbox = gene_ihdrbox( dec->metadatalist, dec->jpipstream);
+
+ dec->jp2kstream = recons_jp2( dec->msgqueue, dec->jpipstream, dec->msgqueue->first->csn, &dec->jp2klen);
+ }
+ else // J2k encoding
+ // Notice: arguments fw, fh need to be set for LRCP, PCRL, CPRL
+ dec->jp2kstream = recons_j2k( dec->msgqueue, dec->jpipstream, dec->msgqueue->first->csn, 0, 0, &dec->jp2klen);
+}
+
+bool fwrite_jp2k( char fname[], jpip_dec_param_t *dec)
+{
+ int outfd;
+
+#ifdef _WIN32
+ if(( outfd = open( fname, O_WRONLY|O_CREAT, _S_IREAD | _S_IWRITE)) == -1){
+#else
+ if(( outfd = open( fname, O_WRONLY|O_CREAT, S_IRWXU|S_IRWXG)) == -1){
+#endif
+ fprintf( stderr, "file %s open error\n", fname);
+ return false;
+ }
+
+ if( write( outfd, dec->jp2kstream, dec->jp2klen) != dec->jp2klen)
+ fprintf( stderr, "j2k file write error\n");
+
+ close(outfd);
+
+ return true;
+}
+
+void output_log( bool messages, bool metadata, bool ihdrbox, jpip_dec_param_t *dec)
+{
+ if( messages)
+ print_msgqueue( dec->msgqueue);
+
+ if( metadata)
+ print_allmetadata( dec->metadatalist);
+
+ if( ihdrbox){
+ printf("W*H: %d*%d\n", dec->ihdrbox->height, dec->ihdrbox->width);
+ printf("NC: %d, bpc: %d\n", dec->ihdrbox->nc, dec->ihdrbox->bpc);
+ }
+}
+
+void destroy_jpipdecoder( jpip_dec_param_t **dec)
+{
+ free( (*dec)->jpipstream);
+ delete_msgqueue( &(*dec)->msgqueue);
+ if( (*dec)->metadatalist){
+ delete_metadatalist( &(*dec)->metadatalist);
+ free( (*dec)->ihdrbox);
+ }
+
+ free( (*dec)->jp2kstream);
+ free( *dec);
+}
+
+index_t * get_index_from_JP2file( int fd)
+{
+ char *data;
+
+ // Check resource is a JP family file.
+ if( lseek( fd, 0, SEEK_SET)==-1){
+ fprintf( stderr, "Error: File broken (lseek error)\n");
+ return NULL;
+ }
+
+ data = (char *)malloc( 12); // size of header
+ if( read( fd, data, 12) != 12){
+ free( data);
+ fprintf( stderr, "Error: File broken (read error)\n");
+ return NULL;
+ }
+
+ if( *data || *(data + 1) || *(data + 2) ||
+ *(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
+ free( data);
+ fprintf( stderr, "Error: No JPEG 2000 Signature box in this file\n");
+ return NULL;
+ }
+ free( data);
+
+ return parse_jp2file( fd);
+}
+
+void destroy_index( index_t **idx)
+{
+ delete_index( idx);
+}
+
+void output_index( index_t *index)
+{
+ print_index( *index);
+}
+
+#endif //SERVER
--- /dev/null
+/*
+ * $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.
+ */
+
+#ifndef OPENJPIP_H_
+# define OPENJPIP_H_
+
+#include "session_manager.h"
+#include "target_manager.h"
+#include "query_parser.h"
+#include "msgqueue_manager.h"
+#include "bool.h"
+
+#include "cache_manager.h"
+#include "byte_manager.h"
+#include "imgsock_manager.h"
+
+#include "metadata_manager.h"
+#include "ihdrbox_manager.h"
+#include "index_manager.h"
+
+#ifdef SERVER
+#include "fcgi_stdio.h"
+#define logstream FCGI_stdout
+#else
+#define FCGI_stdout stdout
+#define FCGI_stderr stderr
+#define logstream stderr
+#endif //SERVER
+
+/*
+ *==========================================================
+ * JPIP server API
+ *==========================================================
+ */
+
+//! Server static records
+typedef struct server_record{
+ sessionlist_param_t *sessionlist; //!< list of session records
+ targetlist_param_t *targetlist; //!< list of target records
+} server_record_t;
+
+//! Query/response data for each client
+typedef struct QR{
+ query_param_t *query;
+ msgqueue_param_t *msgqueue;
+} QR_t;
+
+/**
+ * Initialize the JPIP server
+ *
+ * @return intialized server record pointer
+ */
+server_record_t * init_JPIPserver();
+
+/**
+ * Terminate the JPIP server
+ *
+ * @param[in] rec address of deleting server static record pointer
+ */
+void terminate_JPIPserver( server_record_t **rec);
+
+/**
+ * 1st process per client request; parse query string
+ *
+ * @param[in] query_string request query string
+ * @return initialized query/response data pointer
+ */
+QR_t * parse_querystring( char *query_string);
+
+/**
+ * 2nd process; process JPIP request and construct message queue
+ *
+ * @param[in] rec server static record pointer
+ * @param[in] qr query/response data pointer
+ * @return true if succeed, otherwise false
+ */
+bool process_JPIPrequest( server_record_t *rec, QR_t *qr);
+
+/**
+ * 3rd process; send response data JPT/JPP-stream
+ *
+ * @param[in] qr query/response data pointer
+ */
+void send_responsedata( QR_t *qr);
+
+/**
+ * 4th (last) process;
+ *
+ * @param[in] rec server static record pinter
+ * @param[in] qr address of query/response data pointer
+ */
+void end_QRprocess( server_record_t *rec, QR_t **qr);
+
+#ifndef SERVER
+
+/**
+ * Option for local tests; print out parameter values to logstream (stderr)
+ *
+ * @param[in] query true if query parameters are to be printed out
+ * @param[in] messages true if queue of messages is to be printed out
+ * @param[in] sessions true if session list is to be printed out
+ * @param[in] targets true if target list is to be printed out
+ * @param[in] qr query/response data pointer
+ * @param[in] rec server static record pinter
+ */
+void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr, server_record_t *rec);
+
+#endif //SERVER
+
+/*
+ *==========================================================
+ * JPIP decoding server API
+ *==========================================================
+ */
+
+#ifndef SERVER
+
+//! Decoding server static records
+typedef struct dec_server_record{
+ cachelist_param_t *cachelist; //!< cache list
+ Byte_t *jpipstream; //!< JPT/JPP stream
+ int jpipstreamlen; //!< length of jpipstream
+ msgqueue_param_t *msgqueue; //!< parsed message queue of jpipstream
+ SOCKET listening_socket; //!< listenning socket
+} dec_server_record_t;
+
+
+//! Client socket identifier
+typedef SOCKET client_t;
+
+/**
+ * Initialize the image decoding server
+ *
+ * @return intialized decoding server record pointer
+ */
+dec_server_record_t * init_dec_server();
+
+/**
+ * Terminate the image decoding server
+ *
+ * @param[in] rec address of deleting decoding server static record pointer
+ */
+void terminate_dec_server( dec_server_record_t **rec);
+
+/**
+ * Accept client connection
+ *
+ * @param[in] rec decoding server static record pointer
+ * @return client socket ID, -1 if failed
+ */
+client_t accept_connection( dec_server_record_t *rec);
+
+ /**
+ * Handle client request
+ *
+ * @param[in] client client socket ID
+ * @param[in] rec decoding server static record pointer
+ * @return true if succeed
+ */
+bool handle_clientreq( client_t client, dec_server_record_t *rec);
+
+ #endif //SERVER
+
+/*
+ *==========================================================
+ * JPIP tool API
+ *==========================================================
+ */
+
+#ifndef SERVER
+
+/*
+ * jpip to JP2 or J2K
+ */
+
+//! JPIP decoding parameters
+typedef struct jpip_dec_param{
+ Byte_t *jpipstream; //!< JPT/JPP-stream
+ Byte8_t jpiplen; //!< length of jpipstream
+ msgqueue_param_t *msgqueue; //!< message queue
+ metadatalist_param_t *metadatalist; //!< metadata list going into JP2 file
+ ihdrbox_param_t *ihdrbox; //!< ihdr box going into JP2 file
+ Byte_t *jp2kstream; //!< J2K codestream or JP2 file codestream
+ Byte8_t jp2klen; //!< length of j2kstream or JP2 file
+} jpip_dec_param_t;
+
+/**
+ * Initialize jpip decoder
+ *
+ * @param[in] jp2 true in case of jp2 file encoding, else j2k file encoding
+ * @return JPIP decoding parameters pointer
+ */
+jpip_dec_param_t * init_jpipdecoder( bool jp2);
+
+/**
+ * Destroy jpip decoding parameters
+ *
+ * @param[in] dec address of JPIP decoding parameters pointer
+ */
+void destroy_jpipdecoder( jpip_dec_param_t **dec);
+
+/**
+ * Read jpip codestream from a file
+ *
+ * @param[in] fname file name
+ * @param[in] dec JPIP decoding parameters pointer
+ * @return true if succeed
+ */
+bool fread_jpip( char fname[], jpip_dec_param_t *dec);
+
+/**
+ * Decode jpip codestream
+ *
+ * @param[in] dec JPIP decoding parameters pointer
+ */
+void decode_jpip( jpip_dec_param_t *dec);
+
+/**
+ * Write J2K/JP2 codestream to a file
+ *
+ * @param[in] fname file name
+ * @param[in] dec JPIP decoding parameters pointer
+ * @return true if succeed
+ */
+bool fwrite_jp2k( char fname[], jpip_dec_param_t *dec);
+
+/**
+ * Option; print out parameter values to stderr
+ *
+ * @param[in] messages true if queue of messages is to be printed out
+ * @param[in] metadata true if metadata is to be printed out
+ * @param[in] ihdrbox true if image header data is to be printed out
+ * @param[in] dec JPIP decoding parameters pointer
+ */
+void output_log( bool messages, bool metadata, bool ihdrbox, jpip_dec_param_t *dec);
+
+/*
+ * test the format of index (cidx) box in JP2 file
+ */
+
+//! Redefinition of index parameters
+typedef index_param_t index_t;
+
+/**
+ * Parse JP2 file and get index information from cidx box inside
+ *
+ * @param[in] fd file descriptor of the JP2 file
+ * @return pointer to the generated structure of index parameters
+ */
+index_t * get_index_from_JP2file( int fd);
+
+/**
+ * Destroy index parameters
+ *
+ * @param[in,out] idx addressof the index pointer
+ */
+void destroy_index( index_t **idx);
+
+
+/**
+ * print index parameters
+ *
+ * @param[in] index index parameters
+ */
+void output_index( index_t *index);
+
+#endif //SERVER
+
+#endif /* !OPENJPIP_H_ */
--- /dev/null
+/*
+ * $Id: query_parser.c 53 2011-05-09 16:55:39Z kaori $
+ *
+ * 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
+ * Copyright (c) 2011, Lucian Corlaciu, GSoC
+ * 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.
+ */
+
+
+#ifdef _WIN32
+#include <windows.h>
+#define strcasecmp _stricmp
+#else
+#include <strings.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "query_parser.h"
+
+#ifdef SERVER
+#include "fcgi_stdio.h"
+#define logstream FCGI_stdout
+#else
+#define FCGI_stdout stdout
+#define FCGI_stderr stderr
+#define logstream stderr
+#endif //SERVER
+
+
+/**
+ * Get initialized query parameters
+ *
+ * @return initial query parameters
+ */
+query_param_t * get_initquery();
+
+/*
+ * get a pair of field name and value from the string starting fieldname=fieldval&... format
+ *
+ * @param[in] stringptr pointer to the beginning of the parsing string
+ * @param[out] fieldname string to copy the field name, if not found, NULL
+ * @param[out] fieldval string to copy the field value, if not found, NULL
+ * @return pointer to the next field string, if there is none, NULL
+ */
+char * get_fieldparam( char *stringptr, char *fieldname, char *fieldval);
+
+/**
+ * parse string to string array
+ *
+ * @param[in] src src string
+ * @param[out] cclose parsed string array
+ */
+void str2cclose( char *src, char cclose[][MAX_LENOFCID]);
+
+void parse_metareq( char *field, query_param_t *query_param);
+
+// parse the requested components (parses forms like:a; a,b; a-b; a-b,c; a,b-c)
+void parse_comps( char *field, query_param_t *query_param);
+
+
+//! maximum length of field name
+#define MAX_LENOFFIELDNAME 10
+
+//! maximum length of field value
+#define MAX_LENOFFIELDVAL 128
+
+query_param_t * parse_query( char *query_string)
+{
+ query_param_t *query_param;
+ char *pquery, fieldname[MAX_LENOFFIELDNAME], fieldval[MAX_LENOFFIELDVAL];
+
+ query_param = get_initquery();
+
+ pquery = query_string;
+
+ while( pquery!=NULL) {
+
+ pquery = get_fieldparam( pquery, fieldname, fieldval);
+
+ if( fieldname[0] != '\0'){
+ if( strcasecmp( fieldname, "target") == 0)
+ strcpy( query_param->target,fieldval);
+
+ else if( strcasecmp( fieldname, "tid") == 0)
+ strcpy( query_param->tid, fieldval);
+
+ else if( strcasecmp( fieldname, "fsiz") == 0)
+ sscanf( fieldval, "%d,%d", &query_param->fx, &query_param->fy);
+
+ else if( strcasecmp( fieldname, "roff") == 0)
+ sscanf( fieldval, "%d,%d", &query_param->rx, &query_param->ry);
+
+ else if( strcasecmp( fieldname, "rsiz") == 0)
+ sscanf( fieldval, "%d,%d", &query_param->rw, &query_param->rh);
+
+ else if( strcasecmp( fieldname, "layers") == 0)
+ sscanf( fieldval, "%d", &query_param->layers);
+
+ else if( strcasecmp( fieldname, "cid") == 0)
+ strcpy( query_param->cid, fieldval);
+
+ else if( strcasecmp( fieldname, "cnew") == 0)
+ query_param->cnew = true;
+
+ else if( strcasecmp( fieldname, "cclose") == 0)
+ str2cclose( fieldval, query_param->cclose);
+
+ else if( strcasecmp( fieldname, "metareq") == 0)
+ parse_metareq( fieldval, query_param);
+
+ else if( strcasecmp( fieldname, "comps") == 0)
+ parse_comps( fieldval, query_param);
+
+ else if( strcasecmp( fieldname, "type") == 0){
+ if( strncasecmp( fieldval, "jpp-stream", 10) == 0)
+ query_param->return_type = JPPstream;
+ else if( strncasecmp( fieldval, "jpt-stream", 10) == 0)
+ query_param->return_type = JPTstream;
+ }
+
+ else if( strcasecmp( fieldname, "len") == 0)
+ sscanf( fieldval, "%d", &query_param->len);
+ }
+ }
+ return query_param;
+}
+
+query_param_t * get_initquery()
+{
+ query_param_t *query;
+ int i;
+
+ query = (query_param_t *)malloc( sizeof(query_param_t));
+
+ query->target[0] = '\0';
+ query->tid[0] = '\0';
+ query->fx = -1;
+ query->fy = -1;
+ query->rx = -1;
+ query->ry = -1;
+ query->rw = -1;
+ query->rh = -1;
+ query->layers = -1;
+ query->lastcomp = -1;
+ query->comps = NULL;
+ query->cid[0] = '\0';
+ query->cnew = false;
+ memset( query->cclose, 0, MAX_NUMOFCCLOSE*MAX_LENOFCID);
+ memset( query->box_type, 0, MAX_NUMOFBOX*4);
+ memset( query->limit, 0, MAX_NUMOFBOX*sizeof(int));
+ for( i=0; i<MAX_NUMOFBOX; i++){
+ query->w[i] = false;
+ query->s[i] = false;
+ query->g[i] = false;
+ query->a[i] = false;
+ query->priority[i] = false;
+ }
+ query->root_bin = 0;
+ query->max_depth = -1;
+ query->metadata_only = false;
+ query->return_type = UNKNOWN;
+ query->len = -1;
+
+ return query;
+}
+
+
+char * get_fieldparam( char *stringptr, char *fieldname, char *fieldval)
+{
+ char *eqp, *andp, *nexfieldptr;
+
+ if((eqp = strchr( stringptr, '='))==NULL){
+ fprintf( stderr, "= not found\n");
+ strcpy( fieldname, "");
+ strcpy( fieldval, "");
+ return NULL;
+ }
+ if((andp = strchr( stringptr, '&'))==NULL){
+ andp = strchr( stringptr, '\0');
+ nexfieldptr = NULL;
+ }
+ else
+ nexfieldptr = andp+1;
+
+ strncpy( fieldname, stringptr, eqp-stringptr);
+ fieldname[eqp-stringptr]='\0';
+ strncpy( fieldval, eqp+1, andp-eqp-1);
+ fieldval[andp-eqp-1]='\0';
+
+ return nexfieldptr;
+}
+
+void print_queryparam( query_param_t query_param)
+{
+ int i;
+
+ fprintf( logstream, "query parameters:\n");
+ fprintf( logstream, "\t target: %s\n", query_param.target);
+ fprintf( logstream, "\t tid: %s\n", query_param.tid);
+ fprintf( logstream, "\t fx,fy: %d, %d\n", query_param.fx, query_param.fy);
+ fprintf( logstream, "\t rx,ry: %d, %d \t rw,rh: %d, %d\n", query_param.rx, query_param.ry, query_param.rw, query_param.rh);
+ fprintf( logstream, "\t layers: %d\n", query_param.layers);
+ fprintf( logstream, "\t components: ");
+ if( query_param.lastcomp == -1)
+ fprintf( logstream, "ALL\n");
+ else{
+ for( i=0; i<=query_param.lastcomp; i++)
+ if( query_param.comps[i])
+ fprintf( logstream, "%d ", i);
+ fprintf( logstream, "\n");
+ }
+ fprintf( logstream, "\t cnew: %d\n", query_param.cnew);
+ fprintf( logstream, "\t cid: %s\n", query_param.cid);
+
+ fprintf( logstream, "\t cclose: ");
+ for( i=0; query_param.cclose[i][0]!=0 && i<MAX_NUMOFCCLOSE; i++)
+ fprintf( logstream, "%s ", query_param.cclose[i]);
+ fprintf(logstream, "\n");
+
+ fprintf( logstream, "\t req-box-prop\n");
+ for( i=0; query_param.box_type[i][0]!=0 && i<MAX_NUMOFBOX; i++){
+ fprintf( logstream, "\t\t box_type: %.4s limit: %d w:%d s:%d g:%d a:%d priority:%d\n", query_param.box_type[i], query_param.limit[i], query_param.w[i], query_param.s[i], query_param.g[i], query_param.a[i], query_param.priority[i]);
+ }
+
+ fprintf( logstream, "\t root-bin: %d\n", query_param.root_bin);
+ fprintf( logstream, "\t max-depth: %d\n", query_param.max_depth);
+ fprintf( logstream, "\t metadata-only: %d\n", query_param.metadata_only);
+ fprintf( logstream, "\t image return type: %d, [JPP-stream=0, JPT-stream=1, UNKNOWN=-1]\n", query_param.return_type);
+ fprintf( logstream, "\t len: %d\n", query_param.len);
+}
+
+void str2cclose( char *src, char cclose[][MAX_LENOFCID])
+{
+ int i, u, v;
+
+ size_t len = strlen( src);
+
+ for( i=0, u=0, v=0; i<len; i++){
+ if( src[i]==','){
+ u++;
+ v=0;
+ }
+ else
+ cclose[u][v++] = src[i];
+ }
+}
+
+void parse_req_box_prop( char *req_box_prop, int idx, query_param_t *query_param);
+
+void parse_metareq( char *field, query_param_t *query_param)
+{
+ char req_box_prop[20];
+ char *ptr, *src;
+ int numofboxreq = 0;
+
+ memset( req_box_prop, 0, 20);
+
+ // req-box-prop
+ ptr = strchr( field, '[');
+ ptr++;
+ src = ptr;
+ while( *ptr != ']'){
+ if( *ptr == ';'){
+ strncpy( req_box_prop, src, ptr-src);
+ parse_req_box_prop( req_box_prop, numofboxreq++, query_param);
+ ptr++;
+ src = ptr;
+ memset( req_box_prop, 0, 20);
+ }
+ ptr++;
+ }
+ strncpy( req_box_prop, src, ptr-src);
+
+ parse_req_box_prop( req_box_prop, numofboxreq++, query_param);
+
+ if(( ptr = strchr( field, 'R')))
+ sscanf( ptr+1, "%d", &(query_param->root_bin));
+
+ if(( ptr = strchr( field, 'D')))
+ sscanf( ptr+1, "%d", &(query_param->max_depth));
+
+ if(( ptr = strstr( field, "!!")))
+ query_param->metadata_only = true;
+}
+
+void parse_req_box_prop( char *req_box_prop, int idx, query_param_t *query_param)
+{
+ char *ptr;
+
+ if( *req_box_prop == '*')
+ query_param->box_type[idx][0]='*';
+ else
+ strncpy( query_param->box_type[idx], req_box_prop, 4);
+
+ if(( ptr = strchr( req_box_prop, ':'))){
+ if( *(ptr+1)=='r')
+ query_param->limit[idx] = -1;
+ else
+ sscanf( ptr+1, "%d", &(query_param->limit[idx]));
+ }
+
+ if(( ptr = strchr( req_box_prop, '/'))){
+ ptr++;
+ while( *ptr=='w' || *ptr=='s' || *ptr=='g' || *ptr=='a'){
+ switch( *ptr){
+ case 'w': query_param->w[idx] = true; break;
+ case 's': query_param->s[idx] = true; break;
+ case 'g': query_param->g[idx] = true; break;
+ case 'a': query_param->a[idx] = true; break;
+ }
+ ptr++;
+ }
+ }
+ else{
+ query_param->g[idx] = true;
+ query_param->s[idx] = true;
+ query_param->w[idx] = true;
+ }
+
+ if((ptr = strchr( req_box_prop, '!')))
+ query_param->priority[idx] = true;
+
+ idx++;
+}
+
+void parse_comps( char *field, query_param_t *query_param)
+{
+ int i,start,stop,aux = -1;
+ char *ptr1,*ptr2;
+
+ ptr1 = strchr( field, '-');
+ ptr2 = strchr( field, ',');
+
+ if( ptr1 && ptr2)
+ if( ptr1 > ptr2)
+ sscanf( field, "%d,%d-%d",&aux, &start, &stop);
+ else
+ sscanf( field, "%d-%d,%d", &start, &stop, &aux);
+ else
+ if(ptr1)
+ sscanf( field, "%d-%d", &start, &stop);
+ else if(ptr2){
+ sscanf( field, "%d,%d", &start, &stop);
+ aux = start;
+ start = stop;
+ }
+ else{
+ sscanf( field, "%d", &stop);
+ start = stop;
+ }
+
+ query_param->lastcomp = stop > aux ? stop : aux;
+ query_param->comps = (bool *)calloc( 1, (query_param->lastcomp+1)*sizeof(bool));
+
+ for( i=start; i<=stop; i++)
+ query_param->comps[i]=true;
+
+ if(aux!=-1)
+ query_param->comps[aux] = true;
+}
+
+void delete_query( query_param_t **query)
+{
+ free((*query)->comps);
+ free( *query);
+}
--- /dev/null
+/*
+ * $Id: query_parser.h 53 2011-05-09 16:55:39Z kaori $
+ *
+ * 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
+ * Copyright (c) 2011, Lucian Corlaciu, GSoC
+ * 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.
+ */
+
+#ifndef QUERY_PARSER_H_
+# define QUERY_PARSER_H_
+
+#include "bool.h"
+
+//! maximum length of target name
+#define MAX_LENOFTARGET 128
+
+//! maximum length of target identifier
+#define MAX_LENOFTID 30
+
+//! maximum length of channel identifier
+#define MAX_LENOFCID 30
+
+//! maximum number of closing channel
+#define MAX_NUMOFCCLOSE 10
+
+//! maximum number of meta request box
+#define MAX_NUMOFBOX 10
+
+//! image return type
+typedef enum image_return { JPPstream, JPTstream, UNKNOWN=-1} image_return_t;
+
+//! Query parameters
+typedef struct query_param{
+ char target[MAX_LENOFTARGET]; //!< target name
+ char tid[MAX_LENOFTID]; //!< target identifier
+ int fx, fy; //!< frame size (fx,fy)
+ int rx, ry, rw, rh; //!< roi region
+ int layers; //!< quality layers
+ int lastcomp; //!< last component number
+ bool *comps; //!< components (dynamic array) for jpp-stream, null means all components
+ char cid[MAX_LENOFCID]; //!< channel identifier
+ bool cnew; //!< if there is new channel request(true) or not (false)
+ char cclose[MAX_NUMOFCCLOSE][MAX_LENOFCID]; //!< closing channel identifiers
+ char box_type[MAX_NUMOFBOX][4]; //!< interested box-types
+ int limit[MAX_NUMOFBOX]; //!< limit value, -1: skeleton request "r", 0: entire contents
+ bool w[MAX_NUMOFBOX]; //!< Metadata request qualifier flags
+ bool s[MAX_NUMOFBOX];
+ bool g[MAX_NUMOFBOX];
+ bool a[MAX_NUMOFBOX];
+ bool priority[MAX_NUMOFBOX]; //!< priority flag
+ int root_bin; //!< root-bin
+ int max_depth; //!< max-depth
+ bool metadata_only; //!< metadata-only request
+ image_return_t return_type; //!< image return type
+ int len; //!< maximum response length
+} query_param_t;
+
+
+/**
+ * parse query
+ *
+ * @param[in] query_string request query string
+ * @return pointer to query parameters
+ */
+query_param_t * parse_query( char *query_string);
+
+/**
+ * print query parameters
+ *
+ * @param[in] query_param query parameters
+ */
+void print_queryparam( query_param_t query_param);
+
+
+/**
+ * delete query
+ *
+ * @param[in] query address of the deleting query pointer
+ */
+void delete_query( query_param_t **query);
+
+#endif /* !QUERY_PARSER_H_ */
--- /dev/null
+/*
+ * $Id: session_manager.c 44 2011-02-15 12:32:29Z kaori $
+ *
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "session_manager.h"
+#include "target_manager.h"
+
+#ifdef SERVER
+#include "fcgi_stdio.h"
+#define logstream FCGI_stdout
+#else
+#define FCGI_stdout stdout
+#define FCGI_stderr stderr
+#define logstream stderr
+#endif //SERVER
+
+
+sessionlist_param_t * gene_sessionlist()
+{
+ sessionlist_param_t *sessionlist;
+
+ sessionlist = (sessionlist_param_t *)malloc( sizeof(sessionlist_param_t));
+
+ sessionlist->first = NULL;
+ sessionlist->last = NULL;
+
+ return sessionlist;
+}
+
+session_param_t * gene_session( sessionlist_param_t *sessionlist)
+{
+ session_param_t *session;
+
+ session = (session_param_t *)malloc( sizeof(session_param_t));
+
+ session->channellist = gene_channellist();
+ session->cachemodellist = gene_cachemodellist();
+
+ session->next = NULL;
+
+ if( sessionlist->first) // there are one or more entries
+ sessionlist->last->next = session;
+ else // first entry
+ sessionlist->first = session;
+ sessionlist->last = session;
+
+ return session;
+}
+
+bool search_session_and_channel( char cid[],
+ sessionlist_param_t *sessionlist,
+ session_param_t **foundsession,
+ channel_param_t **foundchannel)
+{
+ *foundsession = sessionlist->first;
+
+ while( *foundsession != NULL){
+
+ *foundchannel = (*foundsession)->channellist->first;
+
+ while( *foundchannel != NULL){
+
+ if( strcmp( cid, (*foundchannel)->cid) == 0)
+ return true;
+
+ *foundchannel = (*foundchannel)->next;
+ }
+ *foundsession = (*foundsession)->next;
+ }
+
+ fprintf( FCGI_stdout, "Status: 503\r\n");
+ fprintf( FCGI_stdout, "Reason: Channel %s not found\r\n", cid);
+
+ return false;
+}
+
+void insert_cachemodel_into_session( session_param_t *session, cachemodel_param_t *cachemodel)
+{
+ if(!cachemodel)
+ return;
+
+#ifndef SERVER
+ fprintf( logstream, "local log: insert cachemodel into session\n");
+#endif
+ if( session->cachemodellist->first != NULL)
+ session->cachemodellist->last->next = cachemodel;
+ else
+ session->cachemodellist->first = cachemodel;
+ session->cachemodellist->last = cachemodel;
+}
+
+bool delete_session( session_param_t **session, sessionlist_param_t *sessionlist)
+{
+ session_param_t *ptr;
+
+ if( *session == NULL)
+ return false;
+
+
+ if( *session == sessionlist->first)
+ sessionlist->first = (*session)->next;
+ else{
+ ptr = sessionlist->first;
+ while( ptr->next != *session)
+ ptr = ptr->next;
+ ptr->next = (*session)->next;
+
+ if( *session == sessionlist->last)
+ sessionlist->last = ptr;
+ }
+
+ delete_channellist( &((*session)->channellist));
+ delete_cachemodellist( &((*session)->cachemodellist));
+
+#ifndef SERVER
+ fprintf( logstream, "local log: session: %p deleted!\n", (void *)(*session));
+#endif
+ free( *session);
+
+ return true;
+}
+
+void delete_sessionlist( sessionlist_param_t **sessionlist)
+{
+ session_param_t *sessionPtr, *sessionNext;
+
+ sessionPtr = (*sessionlist)->first;
+ while( sessionPtr != NULL){
+ sessionNext=sessionPtr->next;
+
+ delete_channellist( &(sessionPtr->channellist));
+ delete_cachemodellist( &(sessionPtr->cachemodellist));
+
+#ifndef SERVER
+ fprintf( logstream, "local log: session: %p deleted!\n", (void *)sessionPtr);
+#endif
+ free( sessionPtr);
+
+ sessionPtr=sessionNext;
+ }
+
+ (*sessionlist)->first = NULL;
+ (*sessionlist)->last = NULL;
+
+ free(*sessionlist);
+}
+
+void print_allsession( sessionlist_param_t *sessionlist)
+{
+ session_param_t *ptr;
+ cachemodel_param_t *cachemodel;
+ int i=0;
+
+ fprintf( logstream, "SESSIONS info:\n");
+
+ ptr = sessionlist->first;
+ while( ptr != NULL){
+ fprintf( logstream, "session No.%d\n", i++);
+ print_allchannel( ptr->channellist);
+ cachemodel = ptr->cachemodellist->first;
+ while( cachemodel){
+ print_target( cachemodel->target);
+ cachemodel = cachemodel->next;
+ }
+ ptr=ptr->next;
+ }
+}
--- /dev/null
+/*
+ * $Id: session_manager.h 53 2011-05-09 16:55:39Z kaori $
+ *
+ * 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.
+ */
+
+#ifndef SESSION_MANAGER_H_
+# define SESSION_MANAGER_H_
+
+#include "bool.h"
+#include "channel_manager.h"
+#include "cachemodel_manager.h"
+
+//! Session parameters
+typedef struct session_param{
+ channellist_param_t *channellist; //!< channel list pointer
+ cachemodellist_param_t *cachemodellist; //!< cache list pointer
+ struct session_param *next; //!< pointer to the next session
+} session_param_t;
+
+//! Session list parameters
+typedef struct sessionlist_param{
+ session_param_t *first; //!< first session pointer of the list
+ session_param_t *last; //!< last session pointer of the list
+} sessionlist_param_t;
+
+
+/**
+ * generate a session list
+ *
+ * @return pointer to the generated session list
+ */
+sessionlist_param_t * gene_sessionlist();
+
+
+/**
+ * generate a session under the sesion list
+ *
+ * @param[in] sessionlist session list to insert the new session
+ * @return pointer to the generated session
+ */
+session_param_t * gene_session( sessionlist_param_t *sessionlist);
+
+/**
+ * search a channel and its belonging session by channel ID
+ *
+ * @param[in] cid channel identifier
+ * @param[in] sessionlist session list pointer
+ * @param[in,out] foundsession address of the found session pointer
+ * @param[in,out] foundchannel address of the found channel pointer
+ * @return if the channel is found (true) or not (false)
+ */
+bool search_session_and_channel( char cid[],
+ sessionlist_param_t *sessionlist,
+ session_param_t **foundsession,
+ channel_param_t **foundchannel);
+
+/**
+ * insert a cache model into a session
+ *
+ * @param[in] session session pointer
+ * @param[in] cachemodel cachemodel pointer
+ */
+void insert_cachemodel_into_session( session_param_t *session, cachemodel_param_t *cachemodel);
+
+
+/**
+ * delete a session
+ *
+ * @param[in] session address of the session pointer
+ * @param[in] sessionlist session list pointer
+ * @return if succeeded (true) or failed (false)
+ */
+bool delete_session( session_param_t **session, sessionlist_param_t *sessionlist);
+
+
+/**
+ * delete session list
+ *
+ * @param[in,out] sessionlist address of the session list pointer
+ */
+void delete_sessionlist( sessionlist_param_t **sessionlist);
+
+/**
+ * print all sessions
+ *
+ * @param[in] sessionlist session list pointer
+ */
+void print_allsession( sessionlist_param_t *sessionlist);
+
+
+#endif /* !SESSION_MANAGER_H_ */
+++ /dev/null
-ADD_SUBDIRECTORY(opj_dec_server)
\ No newline at end of file
+++ /dev/null
-MAINTAINERCLEANFILES = Makefile.in
-
-SUBDIRS = opj_dec_server
+++ /dev/null
-
-SET(OPJ_DEC_SERVER_SRCS
-${CMAKE_CURRENT_SOURCE_DIR}/cache_manager.c
-${CMAKE_CURRENT_SOURCE_DIR}/opj_dec_server.c
-${CMAKE_CURRENT_SOURCE_DIR}/jp2k_decoder.c
-${CMAKE_CURRENT_SOURCE_DIR}/imgsock_manager.c
-${CMAKE_CURRENT_SOURCE_DIR}/jpipstream_manager.c
-${CMAKE_CURRENT_SOURCE_DIR}/dec_clientmsg_handler.c
-)
-
-INCLUDE_DIRECTORIES(
- ${OPENJPEG_SOURCE_DIR}/libopenjpeg
- ${OPENJPEG_SOURCE_DIR}/applications/jpip/libopenjpip
-)
-
-# Build executable
-
-ADD_EXECUTABLE(opj_dec_server ${OPJ_DEC_SERVER_SRCS})
-TARGET_LINK_LIBRARIES(opj_dec_server openjpip_local ${OPENJPEG_LIBRARY_NAME})
-
-# On unix you need to link to the math library:
-IF(UNIX)
- TARGET_LINK_LIBRARIES(opj_dec_server m)
-ENDIF(UNIX)
-# Install exe
-INSTALL(TARGETS opj_dec_server
- EXPORT OpenJPEGTargets
- DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
-)
+++ /dev/null
-MAINTAINERCLEANFILES = Makefile.in
-
-bin_PROGRAMS = opj_dec_server
-
-opj_dec_server_CPPFLAGS = \
--I. \
--I$(top_srcdir)/applications/jpip/opj_server \
--I$(top_builddir)/applications/jpip/opj_server \
--I$(top_srcdir)/applications/jpip/libopenjpip \
--I$(top_builddir)/applications/jpip/libopenjpip \
--I$(top_srcdir)/libopenjpeg \
--I$(top_builddir)/libopenjpeg \
-@FCGI_CFLAGS@ \
--DSERVER
-opj_dec_server_CFLAGS =
-opj_dec_server_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_server.la $(top_builddir)/libopenjpeg/libopenjpeg.la @FCGI_LIBS@ -lm
-opj_dec_server_SOURCES = \
-cache_manager.c \
-cache_manager.h \
-imgsock_manager.c \
-imgsock_manager.h \
-jp2k_decoder.c \
-dec_clientmsg_handler.c \
-dec_clientmsg_handler.h \
-jp2k_decoder.h \
-jpipstream_manager.c \
-jpipstream_manager.h \
-opj_dec_server.c
-
-
-install-data-hook:
- @echo -e " (B)\t$(bindir)/opj_dec_server$(EXEEXT)" >> $(top_builddir)/report.txt
+++ /dev/null
-J2KINCDIR = ../../../../libopenjpeg
-J2KLIBDIR = $(J2KINCDIR)/.libs
-JPIPLIBDIR = ../../libopenjpip
-LIBFNAME = $(JPIPLIBDIR)/libopenjpip_local.a $(J2KLIBDIR)/libopenjpeg.a
-CFLAGS = -O3 -Wall -I$(JPIPLIBDIR) -I$(J2KINCDIR)
-LDFLAGS = -L$(JPIPLIBDIR) -L$(J2KLIBDIR) -lm -lopenjpip_local
-#-lws2_32
-
-ALL = opj_dec_server
-
-all: $(ALL)
-
-opj_dec_server: opj_dec_server.o jp2k_decoder.o imgsock_manager.o jpipstream_manager.o cache_manager.o dec_clientmsg_handler.o $(LIBFNAME)
- $(CC) $(CFLAGS) $< jp2k_decoder.o imgsock_manager.o jpipstream_manager.o cache_manager.o dec_clientmsg_handler.o $(LDFLAGS) $(LIBFNAME) -o $@
-
-clean:
- rm -f $(ALL) *.o *~
+++ /dev/null
-/*
- * $Id: cache_manager.c 53 2011-05-09 16:55:39Z kaori $
- *
- * 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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "cache_manager.h"
-
-//! maximum length of channel identifier
-#define MAX_LENOFCID 30
-
-cachelist_param_t * gene_cachelist()
-{
- cachelist_param_t *cachelist;
-
- cachelist = (cachelist_param_t *)malloc( sizeof(cachelist_param_t));
-
- cachelist->first = NULL;
- cachelist->last = NULL;
-
- return cachelist;
-}
-
-void delete_cachelist(cachelist_param_t **cachelist)
-{
- cache_param_t *cachePtr, *cacheNext;
-
- cachePtr = (*cachelist)->first;
- while( cachePtr != NULL){
- cacheNext=cachePtr->next;
- delete_cache( &cachePtr);
- cachePtr=cacheNext;
- }
- free( *cachelist);
-}
-
-cache_param_t * gene_cache( char *targetname, int csn, char *tid, char *cid)
-{
- cache_param_t *cache;
-
- cache = (cache_param_t *)malloc( sizeof(cache_param_t));
- strcpy( cache->filename, targetname);
- strcpy( cache->tid, tid);
- cache->csn = csn;
- cache->cid = (char **)malloc( sizeof(char *));
- *cache->cid = (char *)malloc( MAX_LENOFCID);
- strcpy( *cache->cid, cid);
- cache->numOfcid = 1;
-#if 1
- cache->metadatalist = NULL;
-#else
- cache->metadatalist = gene_metadatalist();
-#endif
- cache->ihdrbox = NULL;
- cache->next = NULL;
-
- return cache;
-}
-
-void delete_cache( cache_param_t **cache)
-{
- int i;
-
- delete_metadatalist( &(*cache)->metadatalist);
-
- if((*cache)->ihdrbox)
- free((*cache)->ihdrbox);
- for( i=0; i<(*cache)->numOfcid; i++)
- free( (*cache)->cid[i]);
- free( (*cache)->cid);
- free( *cache);
-}
-
-void insert_cache_into_list( cache_param_t *cache, cachelist_param_t *cachelist)
-{
- if( cachelist->first)
- cachelist->last->next = cache;
- else
- cachelist->first = cache;
- cachelist->last = cache;
-}
-
-cache_param_t * search_cache( char targetname[], cachelist_param_t *cachelist)
-{
- cache_param_t *foundcache;
-
- foundcache = cachelist->first;
-
- while( foundcache != NULL){
-
- if( strcmp( targetname, foundcache->filename) == 0)
- return foundcache;
-
- foundcache = foundcache->next;
- }
- return NULL;
-}
-
-cache_param_t * search_cacheBycsn( int csn, cachelist_param_t *cachelist)
-{
- cache_param_t *foundcache;
-
- foundcache = cachelist->first;
-
- while( foundcache != NULL){
-
- if( csn == foundcache->csn)
- return foundcache;
- foundcache = foundcache->next;
- }
- return NULL;
-}
-
-cache_param_t * search_cacheBycid( char cid[], cachelist_param_t *cachelist)
-{
- cache_param_t *foundcache;
- int i;
-
- foundcache = cachelist->first;
-
- while( foundcache != NULL){
- for( i=0; i<foundcache->numOfcid; i++)
- if( strcmp( cid, foundcache->cid[i]) == 0)
- return foundcache;
- foundcache = foundcache->next;
- }
- return NULL;
-}
-
-cache_param_t * search_cacheBytid( char tid[], cachelist_param_t *cachelist)
-{
- cache_param_t *foundcache;
-
- foundcache = cachelist->first;
-
- while( foundcache != NULL){
- if( strcmp( tid, foundcache->tid) == 0)
- return foundcache;
- foundcache = foundcache->next;
- }
- return NULL;
-}
-
-void add_cachecid( char *cid, cache_param_t *cache)
-{
- char **tmp;
- int i;
-
- tmp = cache->cid;
-
- cache->cid = (char **)malloc( (cache->numOfcid+1)*sizeof(char *));
-
- for( i=0; i<cache->numOfcid; i++){
- cache->cid[i] = (char *)malloc( MAX_LENOFCID);
- strcpy( cache->cid[i], tmp[i]);
- free( tmp[i]);
- }
- free( tmp);
-
- cache->cid[ cache->numOfcid] = (char *)malloc( MAX_LENOFCID);
- strcpy( cache->cid[ cache->numOfcid], cid);
-
- cache->numOfcid ++;
-}
-
-void update_cachetid( char *tid, cache_param_t *cache)
-{
- if( tid[0] != '0' && strcmp( tid, cache->tid) !=0){
- fprintf( stderr, "tid is updated to %s for %s\n", tid, cache->filename);
- strcpy( cache->tid, tid);
- }
-}
-
-void remove_cidInCache( char *cid, cache_param_t *cache);
-
-void remove_cachecid( char *cid, cachelist_param_t *cachelist)
-{
- cache_param_t *cache;
-
- cache = search_cacheBycid( cid, cachelist);
- remove_cidInCache( cid, cache);
-}
-
-void remove_cidInCache( char *cid, cache_param_t *cache)
-{
- int idx = -1;
- char **tmp;
- int i, j;
-
- for( i=0; i<cache->numOfcid; i++)
- if( strcmp( cid, cache->cid[i]) == 0){
- idx = i;
- break;
- }
-
- if( idx == -1){
- fprintf( stderr, "cid: %s not found\n", cid);
- return;
- }
-
- tmp = cache->cid;
-
- cache->cid = (char **)malloc( (cache->numOfcid-1)*sizeof(char *));
-
- for( i=0, j=0; i<cache->numOfcid; i++){
- if( i != idx){
- cache->cid[j] = (char *)malloc( MAX_LENOFCID);
- strcpy( cache->cid[j], tmp[i]);
- j++;
- }
- free( tmp[i]);
- }
- free( tmp);
-
- cache->numOfcid --;
-}
-
-void print_cache( cache_param_t *cache)
-{
- int i;
-
- fprintf( stdout,"cache\n");
- fprintf( stdout,"\t filename: %s\n", cache->filename);
- fprintf( stdout,"\t tid: %s\n", cache->tid);
- fprintf( stdout,"\t csn: %d\n", cache->csn);
- fprintf( stdout,"\t cid:");
-
- for( i=0; i<cache->numOfcid; i++)
- fprintf( stdout," %s", cache->cid[i]);
- fprintf( stdout,"\n");
-}
-
-void print_allcache( cachelist_param_t *cachelist)
-{
- cache_param_t *ptr;
-
- fprintf( stdout,"cache list\n");
-
- ptr = cachelist->first;
- while( ptr != NULL){
- print_cache( ptr);
- ptr=ptr->next;
- }
-}
+++ /dev/null
-/*
- * $Id: cache_manager.h 44 2011-02-15 12:32:29Z kaori $
- *
- * 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.
- */
-
-#ifndef CACHE_MANAGER_H_
-# define CACHE_MANAGER_H_
-
-#include "metadata_manager.h"
-#include "ihdrbox_manager.h"
-
-//! maximum length of target name
-#define MAX_LENOFTARGET 128
-
-//! maximum length of target identifier
-#define MAX_LENOFTID 30
-
-//! cache parameters
-typedef struct cache_param{
- char filename[MAX_LENOFTARGET]; //!< file name
- char tid[MAX_LENOFTID]; //!< taregt identifier
- int csn; //!< codestream number
- char **cid; //!< dynamic array of channel identifiers
- int numOfcid; //!< number of cids
- metadatalist_param_t *metadatalist; //!< metadata-bin list
- ihdrbox_param_t *ihdrbox; //!< ihdrbox
- struct cache_param *next; //!< pointer to the next cache
-} cache_param_t;
-
-//!< cache list parameters
-typedef struct cachelist_param{
- cache_param_t *first; //!< first cache pointer of the list
- cache_param_t *last; //!< last cache pointer of the list
-} cachelist_param_t;
-
-
-/**
- * generate a cache list
- *
- * @return pointer to the generated cache list
- */
-cachelist_param_t * gene_cachelist();
-
-/**
- * delete cache list
- *
- * @param[in,out] cachelist address of the cache list pointer
- */
-void delete_cachelist(cachelist_param_t **cachelist);
-
-/**
- * generate a cache
- *
- * @param[in] targetname target file name
- * @param[in] csn codestream number
- * @param[in] tid target identifier
- * @param[in] cid channel identifier
- * @return pointer to the generated cache
- */
-cache_param_t * gene_cache( char *targetname, int csn, char *tid, char *cid);
-
-/**
- * delete a cache
- *
- * @param[in] cache address of the cache pointer
- */
-void delete_cache( cache_param_t **cache);
-
-/**
- * insert a cache into list
- *
- * @param[in] cache cache pointer
- * @param[in] cachelist cache list pointer
- */
-void insert_cache_into_list( cache_param_t *cache, cachelist_param_t *cachelist);
-
-
-/**
- * search a cache by target name
- *
- * @param[in] targetname target filename
- * @param[in] cachelist cache list pointer
- * @return found cache pointer
- */
-cache_param_t * search_cache( char targetname[], cachelist_param_t *cachelist);
-
-
-/**
- * search a cache by csn
- *
- * @param[in] csn codestream number
- * @param[in] cachelist cache list pointer
- * @return found cache pointer
- */
-cache_param_t * search_cacheBycsn( int csn, cachelist_param_t *cachelist);
-
-
-/**
- * search a cache by cid
- *
- * @param[in] cid channel identifer
- * @param[in] cachelist cache list pointer
- * @return found cache pointer
- */
-cache_param_t * search_cacheBycid( char cid[], cachelist_param_t *cachelist);
-
-
-/**
- * search a cache by tid
- *
- * @param[in] tid target identifer
- * @param[in] cachelist cache list pointer
- * @return found cache pointer
- */
-cache_param_t * search_cacheBytid( char tid[], cachelist_param_t *cachelist);
-
-/**
- * add cid into a cache
- *
- * @param[in] cid channel identifier
- * @param[in] cache cache pointer
- */
-void add_cachecid( char *cid, cache_param_t *cache);
-
-
-/**
- * update tid of a cache
- *
- * @param[in] tid target identifier
- * @param[in] cache cache pointer
- */
-void update_cachetid( char *tid, cache_param_t *cache);
-
-
-/**
- * remove cid in cache
- *
- * @param[in] cid channel identifier
- * @param[in] cachelist cachelist pointer
- */
-void remove_cachecid( char *cid, cachelist_param_t *cachelist);
-
-
-/**
- * print cache parameters
- *
- * @param[in] cache cache pointer
- */
-void print_cache( cache_param_t *cache);
-
-/**
- * print all cache parameters
- *
- * @param[in] cachelist cache list pointer
- */
-void print_allcache( cachelist_param_t *cachelist);
-
-#endif /* !CACHE_MANAGER_H_ */
+++ /dev/null
-/*
- * $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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "dec_clientmsg_handler.h"
-#include "ihdrbox_manager.h"
-#include "jpipstream_manager.h"
-#include "jp2k_encoder.h"
-
-
-//! maximum length of channel identifier
-#define MAX_LENOFCID 30
-
-/**
- * handle JPT- JPP- stream message
- *
- * @param[in] connected_socket socket descriptor
- * @param[in] cachelist cache list pointer
- * @param[in,out] jpipstream address of JPT- JPP- stream pointer
- * @param[in,out] streamlen address of stream length
- * @param[in,out] msgqueue message queue pointer
- */
-void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist, Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue);
-
-/**
- * handle PNM request message
- *
- * @param[in] connected_socket socket descriptor
- * @param[in] jpipstream jpipstream pointer
- * @param[in] msgqueue message queue pointer
- * @param[in] cachelist cache list pointer
- */
-void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_param_t *msgqueue, cachelist_param_t *cachelist);
-
-/**
- * handle XML request message
- *
- * @param[in] connected_socket socket descriptor
- * @param[in] jpipstream address of caching jpipstream pointer
- * @param[in] cachelist cache list pointer
- */
-void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist);
-
-/**
- * handle TargetID request message
- *
- * @param[in] connected_socket socket descriptor
- * @param[in] cachelist cache list pointer
- */
-void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
-
-/**
- * handle ChannelID request message
- *
- * @param[in] connected_socket socket descriptor
- * @param[in] cachelist cache list pointer
- */
-void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
-
-/**
- * handle distroy ChannelID message
- *
- * @param[in] connected_socket socket descriptor
- * @param[in,out] cachelist cache list pointer
- */
-void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
-
-/**
- * handle saving JP2 file request message
- *
- * @param[in] connected_socket socket descriptor
- * @param[in] cachelist cache list pointer
- * @param[in] msgqueue message queue pointer
- * @param[in] jpipstream address of caching jpipstream pointer
- */
-void handle_JP2saveMSG( SOCKET connected_socket, cachelist_param_t *cachelist, msgqueue_param_t *msgqueue, Byte_t *jpipstream);
-
-bool handle_clientmsg( SOCKET connected_socket, cachelist_param_t *cachelist, Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue)
-{
- bool quit = false;
- msgtype_t msgtype = identify_clientmsg( connected_socket);
-
- switch( msgtype){
- case JPIPSTREAM:
- handle_JPIPstreamMSG( connected_socket, cachelist, jpipstream, streamlen, msgqueue);
- break;
-
- case PNMREQ:
- handle_PNMreqMSG( connected_socket, *jpipstream, msgqueue, cachelist);
- break;
-
- case XMLREQ:
- handle_XMLreqMSG( connected_socket, *jpipstream, cachelist);
- break;
-
- case TIDREQ:
- handle_TIDreqMSG( connected_socket, cachelist);
- break;
-
- case CIDREQ:
- handle_CIDreqMSG( connected_socket, cachelist);
- break;
-
- case CIDDST:
- handle_dstCIDreqMSG( connected_socket, cachelist);
- break;
-
- case JP2SAVE:
- handle_JP2saveMSG( connected_socket, cachelist, msgqueue, *jpipstream);
- break;
-
- case QUIT:
- quit = true;
- save_codestream( *jpipstream, *streamlen, "jpt");
- break;
- case MSGERROR:
- break;
- }
-
- printf("\t end of the connection\n\n");
- if( close_socket(connected_socket) != 0){
- perror("close");
- return false;
- }
- if( quit)
- return false;
-
- return true;
-}
-
-
-void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist,
- Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue)
-{
- Byte_t *newjpipstream;
- int newstreamlen = 0;
- cache_param_t *cache;
- char target[MAX_LENOFTARGET], tid[MAX_LENOFTID], cid[MAX_LENOFCID];
- metadatalist_param_t *metadatalist;
-
- newjpipstream = receive_JPIPstream( connected_socket, target, tid, cid, &newstreamlen);
-
- parse_JPIPstream( newjpipstream, newstreamlen, *streamlen, msgqueue);
-
- *jpipstream = update_JPIPstream( newjpipstream, newstreamlen, *jpipstream, streamlen);
- free( newjpipstream);
-
- metadatalist = gene_metadatalist();
- parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist);
-
- // cid registration
- if( target[0] != 0){
- if((cache = search_cache( target, cachelist))){
- if( tid[0] != 0)
- update_cachetid( tid, cache);
- if( cid[0] != 0)
- add_cachecid( cid, cache);
- }
- else{
- cache = gene_cache( target, msgqueue->last->csn, tid, cid);
- insert_cache_into_list( cache, cachelist);
- }
- }
- else
- cache = search_cacheBycsn( msgqueue->last->csn, cachelist);
-
- if( cache->metadatalist)
- delete_metadatalist( &cache->metadatalist);
- cache->metadatalist = metadatalist;
-
- response_signal( connected_socket, true);
-}
-
-void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_param_t *msgqueue, cachelist_param_t *cachelist)
-{
- Byte_t *pnmstream;
- ihdrbox_param_t *ihdrbox;
- char cid[MAX_LENOFCID], tmp[10];
- cache_param_t *cache;
- int fw, fh;
-
- receive_line( connected_socket, cid);
- if(!(cache = search_cacheBycid( cid, cachelist)))
- if(!(cache = search_cacheBytid( cid, cachelist)))
- return;
-
- receive_line( connected_socket, tmp);
- fw = atoi( tmp);
-
- receive_line( connected_socket, tmp);
- fh = atoi( tmp);
-
- pnmstream = jpipstream_to_pnm( jpipstream, msgqueue, cache->csn, fw, fh, &cache->ihdrbox);
- ihdrbox = cache->ihdrbox;
-
- send_PNMstream( connected_socket, pnmstream, ihdrbox->width, ihdrbox->height, ihdrbox->nc, ihdrbox->bpc > 8 ? 255 : (1 << ihdrbox->bpc) - 1);
-
- free( pnmstream);
-}
-
-void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist)
-{
- char cid[MAX_LENOFCID];
- cache_param_t *cache;
-
- receive_line( connected_socket, cid);
- if(!(cache = search_cacheBycid( cid, cachelist)))
- return;
-
- boxcontents_param_t *boxcontents = cache->metadatalist->last->boxcontents;
- Byte_t *xmlstream = (Byte_t *)malloc( boxcontents->length);
- memcpy( xmlstream, jpipstream+boxcontents->offset, boxcontents->length);
- send_XMLstream( connected_socket, xmlstream, boxcontents->length);
- free( xmlstream);
-}
-
-void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
-{
- char target[MAX_LENOFTARGET], *tid = NULL;
- cache_param_t *cache;
- int tidlen = 0;
-
- receive_line( connected_socket, target);
- cache = search_cache( target, cachelist);
-
- if( cache){
- tid = cache->tid;
- tidlen = strlen(tid);
- }
- send_TIDstream( connected_socket, tid, tidlen);
-}
-
-void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
-{
- char target[MAX_LENOFTARGET], *cid = NULL;
- cache_param_t *cache;
- int cidlen = 0;
-
- receive_line( connected_socket, target);
- cache = search_cache( target, cachelist);
-
- if( cache){
- if( cache->numOfcid > 0){
- cid = cache->cid[ cache->numOfcid-1];
- cidlen = strlen(cid);
- }
- }
- send_CIDstream( connected_socket, cid, cidlen);
-}
-
-void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
-{
- char cid[MAX_LENOFCID];
-
- receive_line( connected_socket, cid);
- remove_cachecid( cid, cachelist);
- response_signal( connected_socket, true);
-}
-
-void handle_JP2saveMSG( SOCKET connected_socket, cachelist_param_t *cachelist, msgqueue_param_t *msgqueue, Byte_t *jpipstream)
-{
- char cid[MAX_LENOFCID];
- cache_param_t *cache;
- Byte_t *jp2stream;
- Byte8_t jp2len;
-
- receive_line( connected_socket, cid);
- if(!(cache = search_cacheBycid( cid, cachelist)))
- return;
-
- jp2stream = recons_jp2( msgqueue, jpipstream, cache->csn, &jp2len);
-
- if( jp2stream){
- save_codestream( jp2stream, jp2len, "jp2");
- free( jp2stream);
- }
-}
+++ /dev/null
-/*
- * $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
- * Copyright (c) 2011, Lucian Corlaciu, GSoC
- * 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.
- */
-
-#ifndef DEC_CLIENTMSG_HANDLER_H_
-# define DEC_CLIENTMSG_HANDLER_H_
-
-#include "bool.h"
-#include "imgsock_manager.h"
-#include "cache_manager.h"
-#include "byte_manager.h"
-#include "msgqueue_manager.h"
-
-/**
- * handle client message
- *
- * @param[in] connected_socket socket descriptor
- * @param[in] cachelist cache list pointer
- * @param[in,out] jpipstream address of JPT- JPP- stream pointer
- * @param[in,out] streamlen address of stream length
- * @param[in,out] msgqueue message queue pointer
- */
-bool handle_clientmsg( SOCKET connected_socket, cachelist_param_t *cachelist, Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue);
-
-
-#endif /* !DEC_CLIENTMSG_HANDLER_H_ */
+++ /dev/null
-/*
- * $Id: imgsock_manager.c 54 2011-05-10 13:22:47Z kaori $
- *
- * 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.
- */
-
-#ifdef _WIN32
-#include <windows.h>
-#define strcasecmp _stricmp
-#else
-#include <strings.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "imgsock_manager.h"
-
-#define BUF_LEN 256
-
-SOCKET open_listeningsocket()
-{
- SOCKET listening_socket;
- struct sockaddr_in sin;
- int sock_optval = 1;
- int port = 5000;
-
- listening_socket = socket(AF_INET, SOCK_STREAM, 0);
- if ( listening_socket == -1 ){
- perror("socket");
- exit(1);
- }
-
- if ( setsockopt(listening_socket, SOL_SOCKET, SO_REUSEADDR,
- &sock_optval, sizeof(sock_optval)) == -1 ){
- perror("setsockopt");
- exit(1);
- }
-
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_port = htons(port);
- sin.sin_addr.s_addr = htonl(INADDR_ANY);
-
- if ( bind(listening_socket, (struct sockaddr *)&sin, sizeof(sin)) < 0 ){
- perror("bind");
- close_socket(listening_socket);
- exit(1);
- }
-
- if( listen(listening_socket, SOMAXCONN) == -1){
- perror("listen");
- close_socket(listening_socket);
- exit(1);
- }
- printf("port %d is listened\n", port);
-
- return listening_socket;
-}
-
-SOCKET accept_socket( SOCKET listening_socket)
-{
- struct sockaddr_in peer_sin;
- unsigned int addrlen = sizeof(peer_sin);
-
- return accept( listening_socket, (struct sockaddr *)&peer_sin, &addrlen);
-}
-
-msgtype_t identify_clientmsg( SOCKET connected_socket)
-{
- int receive_size;
- char buf[BUF_LEN];
- char *magicid[] = { "JPIP-stream", "PNM request", "XML request", "TID request", "CID request", "CID destroy", "JP2 save", "QUIT"};
- int i;
-
- receive_size = receive_line( connected_socket, buf);
-
- if( receive_size == 0){
- fprintf( stderr, "Error to receive the header of client message\n");
- return MSGERROR;
- }
-
- for( i=0; i<NUM_OF_MSGTYPES; i++){
- if( strncasecmp( magicid[i], buf, strlen(magicid[i])) == 0){
- printf("%s\n", magicid[i]);
- return i;
- }
- }
-
- fprintf( stderr, "Cannot identify client message type %s\n", buf);
- return MSGERROR;
-}
-
-Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *tid, char *cid, int *streamlen)
-{
- Byte_t *jpipstream=NULL, *ptr;
- char buf[BUF_LEN], versionstring[] = "version 1.2";
- int linelen, redlen, remlen;
-
- target[0] = 0;
- cid[0] = 0;
- tid[0] = 0;
-
- if((linelen = receive_line( connected_socket, buf)) == 0)
- return NULL;
- if( strncmp( versionstring, buf, strlen(versionstring))!=0){
- fprintf( stderr, "Wrong format\n");
- return NULL;
- }
-
- if((linelen = receive_line( connected_socket, buf)) == 0)
- return NULL;
-
- if( strstr( buf, "jp2")){
- // register cid option
- strcpy( target, buf);
-
- if((linelen = receive_line( connected_socket, buf)) == 0)
- return NULL;
- if( strcmp( buf, "0") != 0)
- strcpy( tid, buf);
-
- if((linelen = receive_line( connected_socket, buf)) == 0)
- return NULL;
- if( strcmp( buf, "0") != 0)
- strcpy( cid, buf);
-
- if((linelen = receive_line( connected_socket, buf)) == 0)
- return NULL;
- }
-
- *streamlen = atoi( buf);
- fprintf( stderr, "Receive Data: %d Bytes\n", *streamlen);
-
- jpipstream = (unsigned char *)malloc( (*streamlen));
- ptr = jpipstream;
- remlen = (*streamlen);
- while( remlen > 0){
- redlen = recv( connected_socket, ptr, remlen, 0);
- if( redlen == -1){
- fprintf( stderr, "receive JPT- JPP- stream error\n");
- break;
- }
- remlen -= redlen;
- ptr = ptr + redlen;
- }
-
- return jpipstream;
-}
-
-void send_stream( SOCKET connected_socket, void *stream, int length);
-
-void send_XMLstream( SOCKET connected_socket, Byte_t *xmlstream, int length)
-{
- Byte_t header[5];
-
- header[0] = 'X';
- header[1] = 'M';
- header[2] = 'L';
- header[3] = (length >> 8) & 0xff;
- header[4] = length & 0xff;
-
- send_stream( connected_socket, header, 5);
- send_stream( connected_socket, xmlstream, length);
-}
-
-void send_IDstream( SOCKET connected_socket, char *id, int idlen, char *label);
-
-void send_CIDstream( SOCKET connected_socket, char *cid, int cidlen)
-{
- send_IDstream( connected_socket, cid, cidlen, "CID");
-}
-
-void send_TIDstream( SOCKET connected_socket, char *tid, int tidlen)
-{
- send_IDstream( connected_socket, tid, tidlen, "TID");
-}
-
-void send_IDstream( SOCKET connected_socket, char *id, int idlen, char *label)
-{
- Byte_t header[4];
-
- header[0] = label[0];
- header[1] = label[1];
- header[2] = label[2];
- header[3] = idlen & 0xff;
-
- send_stream( connected_socket, header, 4);
- send_stream( connected_socket, id, idlen);
-}
-
-void send_PNMstream( SOCKET connected_socket, Byte_t *pnmstream, unsigned int width, unsigned int height, unsigned int numofcomp, Byte_t maxval)
-{
- int pnmlen = 0;
- Byte_t header[7];
-
- pnmlen = width*height*numofcomp;
-
- header[0] = 'P';
- header[1] = numofcomp==3 ? 6:5;
- header[2] = (width >> 8) & 0xff;
- header[3] = width & 0xff;
- header[4] = (height >> 8) & 0xff;
- header[5] = height & 0xff;
- header[6] = maxval;
-
- send_stream( connected_socket, header, 7);
- send_stream( connected_socket, pnmstream, pnmlen);
-}
-
-void send_stream( SOCKET connected_socket, void *stream, int length)
-{
- void *ptr = stream;
- int remlen = length;
-
- while( remlen > 0){
- int sentlen = send( connected_socket, ptr, remlen, 0);
- if( sentlen == -1){
- fprintf( stderr, "sending stream error\n");
- break;
- }
- remlen = remlen - sentlen;
- ptr = ptr + sentlen;
- }
-}
-
-int receive_line(SOCKET connected_socket, char *p)
-{
- int len = 0;
- while (1){
- int ret;
- ret = recv( connected_socket, p, 1, 0);
- if ( ret == -1 ){
- perror("receive");
- exit(1);
- } else if ( ret == 0 ){
- break;
- }
- if ( *p == '\n' )
- break;
- p++;
- len++;
- }
- *p = '\0';
-
- if( len == 0)
- fprintf( stderr, "Header receive error\n");
-
- return len;
-}
-
-void response_signal( SOCKET connected_socket, bool succeed)
-{
- Byte_t code;
-
- if( succeed)
- code = 1;
- else
- code = 0;
-
- if( send( connected_socket, &code, 1, 0) != 1)
- fprintf( stderr, "Response signalling error\n");
-}
-
-int close_socket( SOCKET sock)
-{
-#ifdef _WIN32
- return closesocket( sock);
-#else
- return close( sock);
-#endif
-}
+++ /dev/null
-/*
- * $Id: imgsock_manager.h 54 2011-05-10 13:22:47Z kaori $
- *
- * 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.
- */
-
-#ifndef IMGSOCK_MANAGER_H_
-# define IMGSOCK_MANAGER_H_
-
-#include "bool.h"
-#include "byte_manager.h"
-
-#ifdef _WIN32
-#include <winsock2.h>
-#else
-typedef int SOCKET;
-#endif //_WIN32
-
-/**
- * open listening socket
- *
- * @return new socket
- */
-SOCKET open_listeningsocket();
-
-/**
- * accept a new connection to the listenning socket
- *
- * @param listening_socket listenning socket
- * @return connected socket (-1 if error occurs)
- */
-SOCKET accept_socket( SOCKET listening_socket);
-
-
-#define NUM_OF_MSGTYPES 8
-typedef enum eMSGTYPE{ JPIPSTREAM, PNMREQ, XMLREQ, TIDREQ, CIDREQ, CIDDST, JP2SAVE, QUIT, MSGERROR} msgtype_t;
-
-/**
- * indeitify client message type
- *
- * @param [in] connected_socket file descriptor of the connected socket
- * @return message type
- */
-msgtype_t identify_clientmsg( SOCKET connected_socket);
-
-/**
- * receive a JPT- JPP- stream from client
- *
- * @param [in] connected_socket file descriptor of the connected socket
- * @param [out] target received target file name (if not received, null string)
- * @param [out] tid received target identifier (if not received, null string)
- * @param [out] cid received channel identifier (if not received, null string)
- * @param [out] streamlen length of the received codestream
- * @return JPT- JPP- codestream
- */
-Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *tid, char *cid, int *streamlen);
-
-/**
- * send PGM/PPM image stream to the client
- *
- * @param [in] connected_socket file descriptor of the connected socket
- * @param [in] pnmstream PGM/PPM image codestream
- * @param [in] width width of the image
- * @param [in] height height of the image
- * @param [in] numofcomp number of components of the image
- * @param [in] maxval maximum value of the image (only 255 supported)
- */
-void send_PNMstream( SOCKET connected_socket, Byte_t *pnmstream, unsigned int width, unsigned int height, unsigned int numofcomp, Byte_t maxval);
-
-/**
- * send XML data stream to the client
- *
- * @param [in] connected_socket file descriptor of the connected socket
- * @param [in] xmlstream xml data stream
- * @param [in] length legnth of the xml data stream
- */
-void send_XMLstream( SOCKET connected_socket, Byte_t *xmlstream, int length);
-
-/**
- * send TID data stream to the client
- *
- * @param [in] connected_socket file descriptor of the connected socket
- * @param [in] tid tid string
- * @param [in] tidlen legnth of the tid string
- */
-void send_TIDstream( SOCKET connected_socket, char *tid, int tidlen);
-
-/**
- * send CID data stream to the client
- *
- * @param [in] connected_socket file descriptor of the connected socket
- * @param [in] cid cid string
- * @param [in] cidlen legnth of the cid string
- */
-void send_CIDstream( SOCKET connected_socket, char *cid, int cidlen);
-
-/**
- * send response signal to the client
- *
- * @param [in] connected_socket file descriptor of the connected socket
- * @param [in] succeed whether if the requested process succeeded
- */
-void response_signal( SOCKET connected_socket, bool succeed);
-
-/**
- * receive a string line (ending with '\n') from client
- *
- * @param [in] connected_socket file descriptor of the connected socket
- * @param [out] buf string to be stored
- * @return red size
- */
-int receive_line(SOCKET connected_socket, char *buf);
-
-/**
- * close socket
- *
- * @param [in] sock closing socket
- * @return 0 if succeed, -1 if failed
- */
-int close_socket( SOCKET sock);
-
-#endif /* !IMGSOCK_MANAGER_H_ */
-
-/*! \file
- * PROTOCOL specification to communicate with opj_dec_server
- *
- *\section sec1 JPIP-stream
- * Cache JPT- JPP- stream in server
- *
- * client -> server: JPIP-stream\\n version 1.1\\n (optional for cid registration: targetnamestring\\n tidstring\\n cidstring\\n) bytelengthvalue\\n data \n
- * server -> client: 1 or 0 (of 1Byte response signal)
- *
- *\section sec2 PNM request
- * Get decoded PGM/PPM image
- *
- * client -> server: PNM request\\n [cid/tid]string\\n fw\\n fh\\n \n
- * server -> client: P6 or P5 (2Byte) width (2Byte Big endian) height (2Byte Big endian) maxval (1Byte) data
- *
- *\section sec3 XML request
- * Get XML data
- *
- * client -> server: XML request\\n \n
- * server -> client: XML (3Byte) length (2Byte Big endian) data
- *
- *\section sec4 TID request
- * Get target ID of target image
- *
- * client -> server: TID request\\n targetname\\n \n
- * server -> client: TID (3Byte) length (1Byte) tiddata
- *
- *\section sec5 CID request
- * Get Channel ID of identical target image
- *
- * client -> server: CID request\\n targetname\\n \n
- * server -> client: CID (3Byte) length (1Byte) ciddata
- *
- *\section sec6 CID destroy
- * Close Channel ID
- *
- * client -> server: CID destroy\\n ciddata \n
- * server -> client: 1 or 0 (of 1Byte response signal)
- *
- *\section sec7 JP2 save
- * Save in JP2 file format
- *
- * client -> server: JP2 save\\n ciddata \n
- * server -> client: 1 or 0 (of 1Byte response signal)
- *
- *\section sec8 QUIT
- * Quit the opj_dec_server program
- *
- * client -> server: quit or QUIT
- */
+++ /dev/null
-/*
- * $Id: jp2k_decoder.c 53 2011-05-09 16:55:39Z kaori $
- *
- * 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.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include "jp2k_decoder.h"
-#include "openjpeg.h"
-
-
-void error_callback(const char *msg, void *client_data);
-void warning_callback(const char *msg, void *client_data);
-void info_callback(const char *msg, void *client_data);
-
-Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox);
-
-Byte_t * j2k_to_pnm( Byte_t *j2kstream, Byte8_t j2klen, ihdrbox_param_t **ihdrbox)
-{
- Byte_t *pnmstream = NULL;
- opj_dparameters_t parameters; /* decompression parameters */
- opj_event_mgr_t event_mgr; /* event manager */
- opj_image_t *image = NULL;
- opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
- opj_cio_t *cio = NULL;
-
- /* configure the event callbacks (not required) */
- memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
- event_mgr.error_handler = error_callback;
- event_mgr.warning_handler = warning_callback;
- event_mgr.info_handler = info_callback;
-
- /* set decoding parameters to default values */
- opj_set_default_decoder_parameters(¶meters);
-
- /* decode the code-stream */
- /* ---------------------- */
-
- /* JPEG-2000 codestream */
- /* get a decoder handle */
- dinfo = opj_create_decompress( CODEC_J2K);
-
- /* catch events using our callbacks and give a local context */
- opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
-
- /* setup the decoder decoding parameters using user parameters */
- opj_setup_decoder(dinfo, ¶meters);
- /* open a byte stream */
- cio = opj_cio_open((opj_common_ptr)dinfo, j2kstream, j2klen);
-
- /* decode the stream and fill the image structure */
- image = opj_decode(dinfo, cio);
- if(!image) {
- fprintf(stderr, "ERROR -> jp2_to_image: failed to decode image!\n");
- opj_destroy_decompress(dinfo);
- opj_cio_close(cio);
- return NULL;
- }
-
- /* close the byte stream */
- opj_cio_close(cio);
-
- /* create output image */
- /* ------------------- */
- if( (pnmstream = imagetopnm( image, ihdrbox))==NULL)
- fprintf( stderr, "PNM image not generated\n");
-
- /* free remaining structures */
- if(dinfo) {
- opj_destroy_decompress(dinfo);
- }
- /* free image data structure */
- opj_image_destroy(image);
-
- return pnmstream;
-}
-
-
-/**
- sample error callback expecting a FILE* client object
-*/
-void error_callback(const char *msg, void *client_data) {
- FILE *stream = (FILE*)client_data;
- fprintf(stream, "[ERROR] %s", msg);
-}
-/**
- sample warning callback expecting a FILE* client object
-*/
-void warning_callback(const char *msg, void *client_data) {
- FILE *stream = (FILE*)client_data;
- fprintf(stream, "[WARNING] %s", msg);
-}
-/**
- sample debug callback expecting no client object
-*/
-void info_callback(const char *msg, void *client_data) {
- (void)client_data;
- // fprintf(stdout, "[INFO] %s", msg);
-}
-
-
-Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox)
-{
- int adjustR, adjustG=0, adjustB=0;
- int datasize;
- Byte_t *pix=NULL, *ptr=NULL;
- int i;
-
- if(*ihdrbox){
- if( (*ihdrbox)->nc != image->numcomps)
- fprintf( stderr, "Exception: num of components not identical, codestream: %d, ihdrbox: %d\n", image->numcomps, (*ihdrbox)->nc);
-
- if( (*ihdrbox)->width != image->comps[0].w)
- (*ihdrbox)->width = image->comps[0].w;
-
- if( (*ihdrbox)->height != image->comps[0].h)
- (*ihdrbox)->height = image->comps[0].h;
-
- if( (*ihdrbox)->bpc != image->comps[0].prec)
- fprintf( stderr, "Exception: bits per component not identical, codestream: %d, ihdrbox: %d\n", image->comps[0].prec, (*ihdrbox)->bpc);
- }
- else{
- *ihdrbox = (ihdrbox_param_t *)malloc( sizeof(ihdrbox_param_t));
- (*ihdrbox)->width = image->comps[0].w;
- (*ihdrbox)->height = image->comps[0].h;
- (*ihdrbox)->bpc = image->comps[0].prec;
- (*ihdrbox)->nc = image->numcomps;
- }
-
- datasize = (image->numcomps)*(image->comps[0].w)*(image->comps[0].h);
-
- if (image->comps[0].prec > 8) {
- adjustR = image->comps[0].prec - 8;
- printf("PNM CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec);
- }
- else
- adjustR = 0;
-
- if( image->numcomps == 3){
- if (image->comps[1].prec > 8) {
- adjustG = image->comps[1].prec - 8;
- printf("PNM CONVERSION: Truncating component 1 from %d bits to 8 bits\n", image->comps[1].prec);
- }
- else
- adjustG = 0;
-
- if (image->comps[2].prec > 8) {
- adjustB = image->comps[2].prec - 8;
- printf("PNM CONVERSION: Truncating component 2 from %d bits to 8 bits\n", image->comps[2].prec);
- }
- else
- adjustB = 0;
- }
-
- pix = (Byte_t *)malloc( datasize);
- ptr = pix;
-
- for( i = 0; i < image->comps[0].w * image->comps[0].h; i++){
- int r, g, b;
- r = image->comps[0].data[i];
- r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
-
- // if( adjustR > 0)
- *(ptr++) = (Byte_t) ((r >> adjustR)+((r >> (adjustR-1))%2));
-
- if( image->numcomps == 3){
- g = image->comps[1].data[i];
- g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
- *(ptr++) = (Byte_t) ((g >> adjustG)+((g >> (adjustG-1))%2));
-
- b = image->comps[2].data[i];
- b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0);
- *(ptr++) = (Byte_t) ((b >> adjustB)+((b >> (adjustB-1))%2));
- }
- }
-
- return pix;
-}
+++ /dev/null
-/*
- * $Id: jp2k_decoder.h 44 2011-02-15 12:32:29Z kaori $
- *
- * 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.
- */
-
-#ifndef JP2K_DECODER_H_
-# define JP2K_DECODER_H_
-
-#include "byte_manager.h"
-#include "ihdrbox_manager.h"
-
-Byte_t * j2k_to_pnm( Byte_t *j2kstream, Byte8_t j2klen, ihdrbox_param_t **ihdrbox);
-
-#endif /* !JP2K_DECODER_H_ */
+++ /dev/null
-/*
- * $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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include "jpipstream_manager.h"
-#include "jp2k_encoder.h"
-#include "jp2k_decoder.h"
-
-Byte_t * update_JPIPstream( Byte_t *newstream, int newstreamlen, Byte_t *cache_stream, int *streamlen)
-{
- Byte_t *stream = (Byte_t *)malloc( (*streamlen)+newstreamlen);
- if( *streamlen > 0)
- memcpy( stream, cache_stream, *streamlen);
- memcpy( stream+(*streamlen), newstream, newstreamlen);
- *streamlen += newstreamlen;
-
- if(cache_stream)
- free( cache_stream);
-
- return stream;
-}
-
-void save_codestream( Byte_t *codestream, Byte8_t streamlen, char *fmt)
-{
- time_t timer;
- struct tm *t_st;
- char filename[20];
- FILE *fp;
-
- time(&timer);
- t_st = localtime( &timer);
-
- sprintf( filename, "%4d%02d%02d%02d%02d%02d.%.3s", t_st->tm_year+1900, t_st->tm_mon+1, t_st->tm_mday, t_st->tm_hour, t_st->tm_min, t_st->tm_sec, fmt);
-
- fp = fopen( filename, "wb");
- fwrite( codestream, streamlen, 1, fp);
- fclose( fp);
-}
-
-
-Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn, int fw, int fh, ihdrbox_param_t **ihdrbox)
-{
- Byte_t *pnmstream;
- Byte_t *j2kstream; // j2k or jp2 codestream
- Byte8_t j2klen;
-
- j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen);
-
- pnmstream = j2k_to_pnm( j2kstream, j2klen, ihdrbox);
- free( j2kstream);
-
- return pnmstream;
-}
+++ /dev/null
-/*
- * $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.
- */
-
-#include "byte_manager.h"
-#include "msgqueue_manager.h"
-#include "ihdrbox_manager.h"
-
-Byte_t * update_JPIPstream( Byte_t *newstream, int newstreamlen, Byte_t *cache_stream, int *streamlen);
-
-void save_codestream( Byte_t *codestream, Byte8_t streamlen, char *fmt);
-
-Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn, int fw, int fh, ihdrbox_param_t **ihdrbox);
+++ /dev/null
-/*
- * $Id: opj_dec_server.c 54 2011-05-10 13:22:47Z kaori $
- *
- * 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.
- */
-
-/*! \file
- * \brief opj_dec_server is a server to decode JPT-stream and communicate locally with JPIP client, which is coded in java.
- *
- * \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
- * 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
- * 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 "dec_clientmsg_handler.h"
-#include "imgsock_manager.h"
-#include "byte_manager.h"
-#include "msgqueue_manager.h"
-#include "cache_manager.h"
-
-
-#ifdef _WIN32
-WSADATA initialisation_win32;
-#endif
-
-int main(int argc, char *argv[]){
-
- SOCKET connected_socket;
- Byte_t *jpipstream = NULL;
- int jpipstreamlen = 0;
- msgqueue_param_t *msgqueue = gene_msgqueue( true, NULL);
-
-#ifdef _WIN32
- int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
- if( erreur!=0)
- fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
- else
- printf( "Initialisation Winsock\n");
-#endif //_WIN32
-
- SOCKET listening_socket = open_listeningsocket();
-
- cachelist_param_t *cachelist = gene_cachelist();
-
- while(( connected_socket = accept_socket( listening_socket)) != -1 )
- if(!(handle_clientmsg( connected_socket, cachelist, &jpipstream, &jpipstreamlen, msgqueue)))
- break;
-
- if( close_socket(listening_socket) != 0){
- perror("close");
- return -1;
- }
-
- delete_cachelist( &cachelist);
-
- if( msgqueue)
- delete_msgqueue( &msgqueue);
-
- free( jpipstream);
-
-#ifdef _WIN32
- if( WSACleanup() != 0){
- printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
- }else{
- printf("\nWSACleanup OK\n");
- }
-#endif
-
- return 0;
-}
+++ /dev/null
-<project name="opj_viewer" default="dist" basedir=".">
- <description>OpenJPIP client image viewer</description>
- <property name="src" location="src" />
- <property name="build" location="build"/>
- <property name="dist" location="dist" />
-
- <target name="init">
- <tstamp/>
- <mkdir dir="${build}"/>
- </target>
- <target name="compile" depends="init">
- <javac srcdir="${src}" destdir="${build}"/>
- </target>
- <target name="dist" depends="compile">
- <mkdir dir="${dist}"/>
- <jar jarfile="${dist}/opj_viewer-${DSTAMP}.jar"
- basedir="${build}" manifest="${dist}/manifest.txt"/>
- <exec dir="${dist}" executable="ln">
- <arg line="-sf opj_viewer-${DSTAMP}.jar opj_viewer.jar"/>
- </exec>
- </target>
- <target name="clean">
- <delete dir="${build}"/>
- <delete dir="${dist}"/>
- </target>
- <target name="test" depends="dist">
- <exec executable="appletviewer"><arg line="dist.html"/></exec>
- </target>
- <target name="build_test" depends="compile">
- <exec executable="appletviewer"><arg line="compile.html"/></exec>
- </target>
- <target name="build_testj" depends="compile">
- <exec executable="java"><arg line="-classpath build ImageWindow girl"/></exec>
- </target>
-</project>
+++ /dev/null
-Manifest-Version: 1.0
-Ant-Version: Apache Ant 1.7.0
-Created-By: Kaori Hagihara
-Main-Class: ImageWindow
+++ /dev/null
-opj_viewer-20111018.jar
\ No newline at end of file
+++ /dev/null
-/*
- * $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
+++ /dev/null
-/*
- * $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.*;
-import java.awt.event.*;
-import javax.swing.*;
-import java.awt.image.*;
-import java.awt.geom.*;
-import java.net.URL;
-import javax.swing.border.*;
-import java.util.*;
-import java.io.*;
-
-public class ImageViewer extends JPanel
-{
- private ImageManager imgmanager;
- private int vw, vh;
- private int iw, ih;
- private int selected = 0;
- private Image img;
-
- private String cmdline = new String();
- private boolean fullRefresh = false;
- private Point offset = new Point(0,0);
- private Rectangle rect = new Rectangle();
- private Rectangle roirect[] = null;
- private String roiname[] = null;
-
- public ImageViewer( String j2kfilename, ImageManager manager, boolean session, boolean jppstream)
- {
- String str;
- MML myMML;
-
- this.setSize( 170, 170);
- Dimension asz = this.getSize();
-
- vw = asz.width;
- vh = asz.height;
-
- setBackground(Color.black);
- myMML = new MML(this);
-
- imgmanager = manager;
-
- img = imgmanager.getImage( j2kfilename, vw, vh, session, jppstream, !jppstream);
-
- addMouseListener(myMML);
- addMouseMotionListener(myMML);
- addComponentListener( new ResizeListener(this));
- }
-
- public Image getImage()
- {
- return img;
- }
-
- public void zoomIn()
- {
- roirect = null;
- roiname = null;
-
- double scalex = (double)vw/(double)rect.width;
- double scaley = (double)vh/(double)rect.height;
-
- int fw = (int)(imgmanager.getFw()*scalex);
- int fh = (int)(imgmanager.getFh()*scaley);
- int rx = (int)((imgmanager.getRx()+rect.x)*scalex);
- int ry = (int)((imgmanager.getRy()+rect.y)*scaley);
-
- img = imgmanager.getImage( fw, fh, rx, ry, vw, vh);
-
- rect.x = rect.y = rect.width = rect.height = 0;
-
- selected = 0;
- fullRefresh = true;
- repaint();
- }
-
- public void enlarge()
- {
- roirect = null;
- roiname = null;
-
- Dimension asz = this.getSize();
-
- vw = asz.width;
- vh = asz.height;
-
- double scalex = vw/(double)imgmanager.getRw();
- double scaley = vh/(double)imgmanager.getRh();
-
- int fw = (int)(imgmanager.getFw()*scalex);
- int fh = (int)(imgmanager.getFh()*scaley);
- int rx = (int)(imgmanager.getRx()*scalex);
- int ry = (int)(imgmanager.getRy()*scaley);
-
- img = imgmanager.getImage( fw, fh, rx, ry, vw, vh);
-
- fullRefresh = true;
- repaint();
- }
-
- public void setSelected(int state)
- {
- roirect = null;
- roiname = null;
-
- if (state != selected) {
-
- selected = state;
- repaint();
- }
- }
-
- public boolean isInsideRect(int x, int y)
- {
- return rect.contains(x - offset.x, y - offset.y);
- }
-
- public void setRGeom(int x1, int y1, int x2, int y2)
- {
- rect.x = Math.min(x1,x2) - offset.x;
- rect.y = Math.min(y1,y2) - offset.y;
- rect.width = Math.abs(x2-x1);
- rect.height = Math.abs(y2-y1);
- }
-
- // public void annotate( JP2XMLparser.ROIparams roi[])
- // {
- // int numofroi = roi.length;
-
- // roirect = new Rectangle [numofroi];
- // roiname = new String [numofroi];
-
- // double scale_x = imgmanager.getFw()/(double)imgmanager.getOrigWidth();
- // double scale_y = imgmanager.getFh()/(double)imgmanager.getOrigHeight();
- // int rx = imgmanager.getRx();
- // int ry = imgmanager.getRy();
- // int rw = imgmanager.getRw();
- // int rh = imgmanager.getRh();
-
- // for( int i=0; i<numofroi ; i++){
- // int x = (int)(roi[i].x*scale_x) - rx;
- // int y = (int)(roi[i].y*scale_y) - ry;
- // int w = (int)(roi[i].w*scale_x);
- // int h = (int)(roi[i].h*scale_y);
- // if( 0<=x && 0<=y && x+w<=rw && y+h<=rh){ // can be optimized
- // roirect[i] = new Rectangle( x, y, w, h);
- // roiname[i] = new String( roi[i].name);
- // }
- // else{
- // roirect[i] = null;
- // roiname[i] = null;
- // }
- // }
- // repaint();
- // }
-
- public boolean hasAnnotation()
- {
- if( roirect == null)
- return false;
- else
- return true;
- }
-
- public boolean isInsideROIRect(int x, int y)
- {
- for( int i=0; i<roirect.length; i++)
- if( roirect[i] != null)
- if( roirect[i].contains(x - offset.x, y - offset.y)){
- rect = roirect[i];
- return true;
- }
- return false;
- }
-
- public void paint(Graphics g)
- {
- BufferedImage bi;
- Graphics2D big;
- Graphics2D g2 = (Graphics2D) g;
-
- if (fullRefresh) {
- g2.clearRect(0, 0, vw, vh);
- fullRefresh = false;
- }
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- g2.setRenderingHint(RenderingHints.KEY_RENDERING,
- RenderingHints.VALUE_RENDER_QUALITY);
-
- offset.x = 0;
- offset.y = 0;
-
- iw = img.getWidth(this);
- ih = img.getHeight(this);
-
- bi = new BufferedImage( iw, ih, BufferedImage.TYPE_INT_RGB);
- big = bi.createGraphics();
-
- big.drawImage(img, 0, 0, this);
- big.setPaint(Color.red);
- if ((rect.width > 0) && (rect.height > 0))
- big.draw(rect);
-
- if( roirect != null){
- for( int i=0; i<roirect.length; i++)
- if( roirect[i] != null){
- big.draw( roirect[i]);
- big.drawString( roiname[i], roirect[i].x+3, roirect[i].y+roirect[i].height*2/3);
- }
- }
- if (selected == 1)
- shadeExt(big, 0, 0, 0, 64);
- else if (selected == 2) {
- shadeExt(big, 0, 0, 0, 255);
- selected = 1;
- }
- g2.drawImage(bi, offset.x, offset.y, this);
- }
-
- private void shadeRect(Graphics2D g2, int r, int g, int b, int a)
- {
- g2.setPaint(new Color(r, g, b, a));
- g2.fillRect(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1);
- }
-
- private void shadeExt(Graphics2D g2, int r, int g, int b, int a)
- {
- g2.setPaint(new Color(r, g, b, a));
- g2.fillRect(0, 0, iw, rect.y); /* _N_ */
- g2.fillRect(rect.x + rect.width + 1, rect.y,
- iw - rect.x - rect.width - 1, rect.height + 1); /* E */
- g2.fillRect(0, rect.y, rect.x, rect.height + 1); /* W */
- g2.fillRect(0, rect.y + rect.height + 1,
- iw, ih - rect.y - rect.height - 1); /* _S_ */
- }
-}
+++ /dev/null
-/*
- * $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 javax.swing.*;
-import java.awt.event.*;
-import java.awt.*;
-
-public class ImageWindow extends JFrame
-{
- private ImageViewer imgviewer;
- private ImageManager imgmanager;
-
- public ImageWindow( String uri, String j2kfilename, boolean session, boolean jppstream)
- {
- super( j2kfilename);
-
- imgmanager = new ImageManager( uri);
-
- imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream);
- imgviewer.setOpaque(true); //content panes must be opaque
-
- JPanel panel = new JPanel();
- panel.setLayout(new BorderLayout());
- panel.add( imgviewer, BorderLayout.CENTER);
-
- setContentPane( panel);
-
- addWindowListener(new WindowMyAdapter());
- }
-
- class WindowMyAdapter extends WindowAdapter
- {
- public void windowClosing(WindowEvent arg)
- {
- imgmanager.closeChannel();
- System.exit(0);
- }
- }
-
- public static void main(String s[])
- {
- String j2kfilename, uri;
- boolean session, jppstream;
-
- if(s.length >= 2){
- uri = s[0];
- j2kfilename = s[1];
- if( s.length > 2)
- session = !s[2].equalsIgnoreCase( "stateless");
- else
- session = true;
-
- if( s.length > 3)
- jppstream = !s[3].equalsIgnoreCase( "JPT");
- else
- jppstream = true;
- }
- else{
- System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [stateless/session] [JPT/JPP]");
- return;
- }
- ImageWindow frame = new ImageWindow( uri, j2kfilename, session, jppstream);
-
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- //Display the window.
- frame.pack();
- frame.setSize(new Dimension(400,200));
- frame.setLocation( 0, 50);
- frame.setVisible(true);
- }
-}
+++ /dev/null
-/*
- * $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.io.*;
-import java.net.*;
-
-public class ImgdecClient{
-
- public static 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)
- {
- send_JPIPstream( jpipstream, j2kfilename, tid, cid);
- return get_PNMstream( cid, tid, fw, fh);
- }
-
- public static void send_JPIPstream( byte[] jpipstream)
- {
- try{
- Socket imgdecSocket = new Socket( "localhost", 5000);
- DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
- DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
-
- System.err.println("Sending " + jpipstream.length + "Data Bytes to decodingServer");
-
- os.writeBytes("JPIP-stream\n");
- os.writeBytes("version 1.2\n");
- os.writeBytes( jpipstream.length + "\n");
- os.write( jpipstream, 0, jpipstream.length);
-
- byte signal = is.readByte();
-
- if( signal == 0)
- System.err.println(" failed");
- } catch (UnknownHostException e) {
- System.err.println("Trying to connect to unknown host: " + e);
- } catch (IOException e) {
- System.err.println("IOException: " + e);
- }
- }
-
- public static void send_JPIPstream( byte[] jpipstream, String j2kfilename, String tid, String cid)
- {
- try{
- Socket imgdecSocket = new Socket( "localhost", 5000);
- DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
- DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
- int length = 0;
-
- if( jpipstream != null)
- length = jpipstream.length;
-
- System.err.println("Sending " + length + "Data Bytes to decodingServer");
-
- os.writeBytes("JPIP-stream\n");
- os.writeBytes("version 1.2\n");
- os.writeBytes( j2kfilename + "\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");
- os.writeBytes( length + "\n");
- os.write( jpipstream, 0, length);
-
- byte signal = is.readByte();
-
- if( signal == 0)
- System.err.println(" failed");
- } catch (UnknownHostException e) {
- System.err.println("Trying to connect to unknown host: " + e);
- } catch (IOException e) {
- System.err.println("IOException: " + e);
- }
- }
-
- public static PnmImage get_PNMstream( String cid, String tid, int fw, int fh)
- {
- PnmImage pnmstream = null;
-
- try {
- Socket imgdecSocket = new Socket( "localhost", 5000);
- DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
- DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
- byte []header = new byte[7];
-
- os.writeBytes("PNM request\n");
- if( cid != null)
- os.writeBytes( cid + "\n");
- else
- if( tid != null)
- os.writeBytes( tid + "\n");
- else
- os.writeBytes( "0\n");
- os.writeBytes( fw + "\n");
- os.writeBytes( fh + "\n");
-
- read_stream( is, header, 7);
-
- if( header[0] == 80){
- // P5: gray, P6: color
- byte magicknum = header[1];
- if( magicknum == 5 || magicknum == 6){
- int c = magicknum==6 ? 3: 1;
- int w = (header[2]&0xff)<<8 | (header[3]&0xff);
- int h = (header[4]&0xff)<<8 | (header[5]&0xff);
- int maxval = header[6]&0xff;
- int length = w*h*c;
-
- if( maxval == 255 && length != 0){
- pnmstream = new PnmImage( c, w, h);
- read_stream( is, pnmstream.get_data(), length);
- }
- else
- System.err.println("Error in get_PNMstream(), only 255 is accepted");
- }
- else
- System.err.println("Error in get_PNMstream(), wrong magick number" + header[1]);
- }
- else
- System.err.println("Error in get_PNMstream(), Not starting with P");
-
- os.close();
- is.close();
- imgdecSocket.close();
- } catch (UnknownHostException e) {
- System.err.println("Trying to connect to unknown host: " + e);
- } catch (IOException e) {
- System.err.println("IOException: " + e);
- }
- return pnmstream;
- }
-
- public static byte [] get_XMLstream( String cid)
- {
- byte []xmldata = null;
-
- try{
- Socket imgdecSocket = new Socket( "localhost", 5000);
- DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
- DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
- byte []header = new byte[5];
-
- os.writeBytes("XML request\n");
- os.writeBytes( cid + "\n");
-
- read_stream( is, header, 5);
-
- if( header[0] == 88 && header[1] == 77 && header[2] == 76){
- int length = (header[3]&0xff)<<8 | (header[4]&0xff);
-
- xmldata = new byte[ length];
- read_stream( is, xmldata, length);
- }
- else
- System.err.println("Error in get_XMLstream(), not starting with XML");
- } catch (UnknownHostException e) {
- System.err.println("Trying to connect to unknown host: " + e);
- } catch (IOException e) {
- System.err.println("IOException: " + e);
- }
- return xmldata;
- }
-
- public static String query_cid( String j2kfilename)
- {
- int []retmsglabel = new int[3];
- retmsglabel[0] = 67;
- retmsglabel[1] = 73;
- retmsglabel[2] = 68;
-
- return query_id( "CID request", j2kfilename, retmsglabel);
- }
-
- public static String query_tid( String j2kfilename)
- {
- int []retmsglabel = new int[3];
- retmsglabel[0] = 84;
- retmsglabel[1] = 73;
- retmsglabel[2] = 68;
-
- return query_id( "TID request", j2kfilename, retmsglabel);
- }
-
- public static String query_id( String reqmsghead, String j2kfilename, int[] retmsglabel)
- {
- String id = null;
-
- try{
- Socket imgdecSocket = new Socket( "localhost", 5000);
- DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
- DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
- byte []header = new byte[4];
-
- os.writeBytes( reqmsghead + "\n");
- os.writeBytes( j2kfilename + "\n");
-
- read_stream( is, header, 4);
-
- if( header[0] == retmsglabel[0] && header[1] == retmsglabel[1] && header[2] == retmsglabel[2]){
- int length = header[3]&0xff;
-
- if( length > 0){
-
- byte []iddata = new byte[ length];
- read_stream( is, iddata, length);
- id = new String( iddata);
- }
- }
- else
- System.err.println("Error in query_id("+ reqmsghead + "), 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 id;
- }
-
- public static void read_stream( DataInputStream is, byte []stream, int length)
- {
- int remlen = length;
- int off = 0;
-
- try{
- while( remlen > 0){
- int redlen = is.read( stream, off, remlen);
-
- if( redlen == -1){
- System.err.println(" failed to read_stream()");
- break;
- }
- off += redlen;
- remlen -= redlen;
- }
- } catch (IOException e) {
- System.err.println("IOException: " + e);
- }
- }
-
- public static void destroy_cid( String cid)
- {
- try{
- Socket imgdecSocket = new Socket( "localhost", 5000);
- DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
- DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
-
- os.writeBytes("CID destroy\n");
- os.writeBytes( cid + "\n");
-
- byte signal = is.readByte();
-
- if( signal == 0)
- System.err.println(" failed");
- } catch (UnknownHostException e) {
- System.err.println("Trying to connect to unknown host: " + e);
- } catch (IOException e) {
- System.err.println("IOException: " + e);
- }
- }
-}
+++ /dev/null
-/*
- * $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.net.*;
-import java.io.*;
-import java.util.*;
-
-
-public class JPIPHttpClient
-{
- private String comURL;
- protected int fw, fh;
- protected int rx, ry;
- protected int rw, rh;
- protected String cid;
- protected String tid;
- private boolean JPTstream;
- private boolean JPPstream;
-
- public JPIPHttpClient( String URI)
- {
- comURL = URI + "?";
- fw = fh = -1;
- rx = ry = -1;
- rw = rh = -1;
- cid = null;
- tid = null;
- JPTstream = false;
- JPPstream = false;
- }
-
- public int getFw(){ return fw;}
- public int getFh(){ return fh;}
- public int getRx(){ return rx;}
- public int getRy(){ return ry;}
- public int getRw(){ return rw;}
- public int getRh(){ return rh;}
-
- public byte[] requestViewWindow( int reqfw, int reqfh)
- {
- if( cid != null)
- return requestViewWindow( reqfw, reqfh, cid);
- else
- return null;
- }
-
- public byte[] requestViewWindow( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh)
- {
- if( cid != null)
- return requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh, cid);
- else
- if( tid != null)
- return requestViewWindow( null, tid, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, null, false, false, false);
- else
- return null;
- }
-
- public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid)
- {
- return requestViewWindow( null, null, reqfw, reqfh, -1, -1, -1, -1, reqcid, false, false, false);
- }
-
- public byte[] requestViewWindow( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh, String reqcid)
- {
- return requestViewWindow( null, null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, false, false, false);
- }
-
- public byte[] requestViewWindow( String target, int reqfw, int reqfh)
- {
- return requestViewWindow( target, null, reqfw, reqfh, -1, -1, -1, -1, null, false, false, false);
- }
-
- public byte[] requestViewWindow( String target, int reqfw, int reqfh, boolean reqcnew, boolean reqJPP, boolean reqJPT)
- {
- if( cid == null) // 1 channel allocation only
- return requestViewWindow( target, null, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew, reqJPP, reqJPT);
- else
- return null;
- }
-
- public byte[] requestViewWindow( String target, String reqtid, int reqfw, int reqfh, boolean reqcnew, boolean reqJPP, boolean reqJPT)
- {
- if( cid == null) // 1 channel allocation only
- return requestViewWindow( target, reqtid, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew, reqJPP, reqJPT);
- else
- return null;
- }
-
- public byte[] requestViewWindow( String target, int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh)
- {
- return requestViewWindow( target, null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, null, false, false, false);
- }
-
-
- public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid, boolean reqcnew, boolean reqJPP, boolean reqJPT)
- {
- return requestViewWindow( null, null, reqfw, reqfh, -1, -1, -1, -1, reqcid, reqcnew, reqJPP, reqJPT);
- }
-
- public byte[] requestViewWindow( String target,
- String reqtid,
- int reqfw, int reqfh,
- int reqrx, int reqry,
- int reqrw, int reqrh,
- String reqcid, boolean reqcnew, boolean reqJPP, boolean reqJPT)
- {
- if( reqtid != null)
- tid = reqtid;
-
- String urlstring = const_urlstring( target, reqtid, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, reqcnew, reqJPP, reqJPT);
- return GETrequest( urlstring);
- }
-
- public byte[] requestXML()
- {
- String urlstring = comURL;
-
- if( cid == null)
- return null;
-
- urlstring = urlstring.concat( "cid=" + cid);
- urlstring = urlstring.concat( "&metareq=[xml_]");
-
- return GETrequest( urlstring);
- }
-
- private byte[] GETrequest( String urlstring)
- {
- int buflen = 0;
- URL url = null;
- HttpURLConnection urlconn = null;
- byte[] jpipstream = null;
-
- try{
- url = new URL( urlstring);
-
- System.err.println("Requesting: " + url);
-
- urlconn = (HttpURLConnection)url.openConnection();
- urlconn.setRequestMethod("GET");
- urlconn.setInstanceFollowRedirects(false);
- urlconn.connect();
-
- Map<String,java.util.List<String>> headers = urlconn.getHeaderFields();
- java.util.List<String> hvaluelist;
- String hvalueline;
-
- String status = headers.get(null).get(0);
-
- System.err.println( status);
- if( !status.contains("OK"))
- System.err.println( headers.get("Reason"));
-
- hvalueline = headers.get("Content-type").get(0);
- System.err.println( hvalueline);
-
- if( hvalueline.endsWith("jpt-stream"))
- JPTstream = true;
- else if( hvalueline.endsWith("jpp-stream"))
- JPPstream = true;
-
- if(( hvaluelist = headers.get("JPIP-fsiz")) != null){
- hvalueline = hvaluelist.get(0);
- fw = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue();
- fh = Integer.valueOf( hvalueline.substring( hvalueline.indexOf(',')+1 )).intValue();
-
- System.err.println("fw,fh: " + fw + "," + fh);
- }
-
- if(( hvaluelist = headers.get("JPIP-roff")) != null){
- hvalueline = hvaluelist.get(0);
- rx = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue();
- ry = Integer.valueOf( hvalueline.substring( hvalueline.indexOf(',')+1 )).intValue();
- System.err.println("rx,ry: " + rx + "," + ry);
- }
-
- if(( hvaluelist = headers.get("JPIP-rsiz")) != null){
- hvalueline = hvaluelist.get(0);
- rw = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue();
- rh = Integer.valueOf( hvalueline.substring( hvalueline.indexOf(',')+1 )).intValue();
- System.err.println("rw,rh: " + rw + "," + rh);
- }
-
- if(( hvaluelist = headers.get("JPIP-cnew")) != null){
- hvalueline = hvaluelist.get(0);
- cid = hvalueline.substring( hvalueline.indexOf('=')+1, hvalueline.indexOf(','));
- System.err.println("cid: " + cid);
- }
-
- if(( hvaluelist = headers.get("JPIP-tid")) != null){
- hvalueline = hvaluelist.get(0);
- tid = hvalueline.substring( hvalueline.indexOf('=')+1);
- System.err.println("tid: " + tid);
- }
-
- InputStream input = urlconn.getInputStream();
- buflen = input.available();
-
- if( buflen > 0){
- ByteArrayOutputStream tmpstream = new ByteArrayOutputStream();
- byte[] buf = new byte[ 1024];
-
- System.err.println("reading jpipstream...");
-
- int redlen;
- do{
- redlen = input.read( buf);
-
- if( redlen == -1)
- break;
- tmpstream.write( buf, 0, redlen);
- }while( redlen > 0);
-
- buflen = tmpstream.size();
-
- jpipstream = tmpstream.toByteArray();
-
- tmpstream = null;
-
- System.err.println("jpiplen: " + buflen);
- System.err.println(" succeeded");
- }
- else{
- System.err.println("No new jpipstream");
- }
- input.close();
- }
- catch ( MalformedURLException e){
- e.printStackTrace();
- }
- catch ( ProtocolException e){
- e.printStackTrace();
- }
- catch( ClassCastException e){
- e.printStackTrace();
- }
- catch( NullPointerException e){
- e.printStackTrace();
- }
- catch( UnknownServiceException e){
- e.printStackTrace();
- }
- catch ( IOException e){
- e.printStackTrace();
- }
-
- urlconn.disconnect();
-
- return jpipstream;
- }
-
- private String const_urlstring( String target,
- String reqtid,
- int reqfw, int reqfh,
- int reqrx, int reqry,
- int reqrw, int reqrh,
- String reqcid, boolean reqcnew, boolean reqJPP, boolean reqJPT)
- {
- String urlstring = comURL;
-
- // C.7.3 Image Return Type
- // add type=jpp-stream(;ptype=ext) or type=jpt-stream;ttype=ext
-
- if( target != null){
- if( !urlstring.endsWith("?"))
- urlstring = urlstring.concat( "&");
- urlstring = urlstring.concat( "target=" + target);
- }
- if( reqtid != null){
- if( !urlstring.endsWith("?"))
- urlstring = urlstring.concat( "&");
- urlstring = urlstring.concat( "tid=" + reqtid);
- }
- if( reqfw != -1 && reqfh != -1){
- if( !urlstring.endsWith("?"))
- urlstring = urlstring.concat( "&");
- urlstring = urlstring.concat( "fsiz=" + reqfw + "," + reqfh);
- }
- if( reqrx != -1 && reqry != -1){
- if( !urlstring.endsWith("?"))
- urlstring = urlstring.concat( "&");
- urlstring = urlstring.concat( "roff=" + reqrx + "," + reqry);
- }
- if( reqrw != -1 && reqrh != -1){
- if( !urlstring.endsWith("?"))
- urlstring = urlstring.concat( "&");
- urlstring = urlstring.concat( "rsiz=" + reqrw + "," + reqrh);
- }
- if( reqcid != null){
- if( !urlstring.endsWith("?"))
- urlstring = urlstring.concat( "&");
- urlstring = urlstring.concat( "cid=" + reqcid);
- }
- if( reqcnew){
- if( !urlstring.endsWith("?"))
- urlstring = urlstring.concat( "&");
- urlstring = urlstring.concat( "cnew=http");
- }
-
- if( reqJPP && !JPTstream){
- if( !urlstring.endsWith("?"))
- urlstring = urlstring.concat( "&");
- urlstring = urlstring.concat( "type=jpp-stream");
- }
- else if( reqJPT && !JPPstream){
- if( !urlstring.endsWith("?"))
- urlstring = urlstring.concat( "&");
- urlstring = urlstring.concat( "type=jpt-stream");
- }
- else{ // remove this option later
- if( !urlstring.endsWith("?"))
- urlstring = urlstring.concat( "&");
- if( JPTstream)
- urlstring = urlstring.concat( "type=jpt-stream");
- else if( JPPstream)
- urlstring = urlstring.concat( "type=jpp-stream");
- }
-
- return urlstring;
- }
-
- public void closeChannel()
- {
- if( cid == null)
- return;
-
- try{
- URL url = new URL( comURL + "cclose=" + cid);
- System.err.println( "closing cid: " + cid);
-
- HttpURLConnection urlconn = (HttpURLConnection)url.openConnection();
- urlconn.setRequestMethod("GET");
- urlconn.setInstanceFollowRedirects(false);
- urlconn.connect();
-
- Map headers = urlconn.getHeaderFields();
-
- urlconn.disconnect();
- } catch ( MalformedURLException e){
- e.printStackTrace();
- } catch ( IOException e){
- e.printStackTrace();
- }
- }
-}
+++ /dev/null
-/*
- * $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.event.*;
-
-class MML implements MouseMotionListener, MouseListener
-{
- public void mouseExited(MouseEvent e) {}
- public void mouseEntered(MouseEvent e) {}
- public void mouseClicked(MouseEvent e) {}
-
- private ImageViewer iv;
- private int x1, y1, x2, y2, zf, btn;
- private boolean zoomrq;
-
- public MML(ImageViewer imageviewer)
- {
- x1 = y1 = -1;
- iv = imageviewer;
- zoomrq = false;
- zf = 0;
- }
-
- private boolean isInside(int x, int y)
- {
- x -= iv.getX();
- y -= iv.getY();
- return (x >= 0) && (x < iv.getWidth())
- && (y >= 0) && (y < iv.getHeight());
- }
-
- public void mousePressed(MouseEvent e)
- {
- btn = e.getButton();
-
- if( iv.hasAnnotation()){
- if( iv.isInsideROIRect(e.getX(), e.getY())){
- iv.zoomIn();
- System.out.println("annotation click");
- return;
- }
- }
- if (iv.isInsideRect(e.getX(), e.getY())) {
- iv.setSelected(2);
- iv.repaint();
- zoomrq = true;
- } else {
- iv.setRGeom(0, 0, 0, 0);
- iv.setSelected(0);
- iv.repaint();
- x1 = y1 = -1;
- }
- }
-
- public void mouseReleased(MouseEvent e)
- {
- if(e.getButton() == 1) {
- if (zoomrq) {
- iv.zoomIn();
- zoomrq = false;
- }
- }
- }
-
- public void mouseMoved(MouseEvent e)
- {
- }
-
- public void mouseDragged(MouseEvent e)
- {
- if (btn == 1) {
- x2 = e.getX();
- y2 = e.getY();
-
- iv.setSelected(0);
- zoomrq = false;
-
- if (isInside(x2, y2)) {
- if (x1 == -1) {
- x1 = x2;
- y1 = y2;
- } else {
- iv.setRGeom(x1, y1, x2, y2);
- iv.repaint();
- }
- }
- }
- }
-}
+++ /dev/null
-/*
- * $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.*;
-import java.awt.image.*;
-import java.io.*;
-import java.util.regex.*;
-
-public class PnmImage extends Component
-{
- private byte[] data = null;
- private int width = 0;
- private int height = 0;
- private int channel = 0;
-
- public PnmImage( int c, int w, int h)
- {
- channel = c;
- width = w;
- height = h;
- data = new byte [ w*h*c];
- }
-
- public PnmImage( String filename)
- {
- String str;
- Pattern pat;
- Matcher mat;
- int bytes;
- int r, offset = 0;
-
- try {
- FileInputStream fis = new FileInputStream( new File(filename));
- DataInputStream is = new DataInputStream( fis);
-
- pat = Pattern.compile("^P([56])$");
- mat = pat.matcher(str = is.readLine());
- if( !mat.matches()){
- System.out.println("PNM header format error");
- return;
- }
-
- if( (mat.group(1)).compareTo("5") == 0)
- channel = 1;
- else
- channel = 3;
-
- pat = Pattern.compile("^(\\d+) (\\d+)$");
- mat = pat.matcher(str = is.readLine());
- if( !mat.matches()){
- System.out.println("PNM header format error");
- return;
- }
- width = Integer.parseInt( mat.group(1));
- height = Integer.parseInt( mat.group(2));
-
- str = is.readLine(); // 255
-
- bytes = width*height*channel;
- data = new byte[bytes];
-
- while( bytes > 0){
- try {
- r = is.read(data, offset, bytes);
- if( r == -1){
- System.err.println(" failed to read()");
- break;
- }
- offset += r;
- bytes -= r;
- }
- catch (IOException e) { e.printStackTrace(); }
- }
- fis.close();
- } catch (IOException e) { e.printStackTrace(); }
- }
-
- public byte [] get_data(){ return data;}
- public int get_width() { return width;}
- public int get_height(){ return height;}
-
- public Image createROIImage( int rx, int ry, int rw, int rh)
- {
- int []pix = new int[ rw*rh];
-
- for( int i=0; i<rh; i++)
- for( int j=0; j<rw; j++){
- pix[i*rw+j] = 0xFF << 24; // transparency
- if( channel == 1){
- Byte lum = data[(ry+i)*width+rx+j];
- short slum;
-
- if( lum < 0)
- slum = (short)(2*128+lum);
- else
- slum = (short)lum;
-
- for( int c=0; c<3; c++){
- pix[i*rw+j] = pix[i*rw+j] | slum << (8*c);
- }
- }
- else
- for( int c=0; c<3; c++){
- Byte lum = data[ ((ry+i)*width+rx+j)*channel+(2-c)];
- short slum;
-
- if( lum < 0)
- slum = (short)(2*128+lum);
- else
- slum = (short)lum;
-
- pix[i*rw+j] = pix[i*rw+j] | slum << (8*c);
- }
- }
-
- return createImage(new MemoryImageSource( rw, rh, pix, 0, rw));
- }
-
- public Image createScaleImage( double scale)
- {
- Image src = createROIImage( 0, 0, width, height);
- ImageFilter replicate = new ReplicateScaleFilter( (int)(width*scale), (int)(height*scale));
- ImageProducer prod = new FilteredImageSource( src.getSource(), replicate);
-
- return createImage(prod);
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * $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 javax.swing.*;
-import java.awt.*;
-import java.awt.image.*;
-import java.awt.geom.AffineTransform;
-
-public class RegimViewer extends JPanel
-{
- private PnmImage refpnm;
- private int vw, vh;
- private Image refimg;
- private Image jpipImg;
- private double[] affine_matrix;
- private AffineTransform affine;
-
- public RegimViewer( String refname, double[] mat)
- {
- refpnm = new PnmImage( refname.replaceFirst("jp2", "pgm")); // decoding not realized
- affine_matrix = new double[6];
-
- affine_matrix[0] = mat[0];
- affine_matrix[1] = mat[3];
- affine_matrix[2] = mat[1];
- affine_matrix[3] = mat[4];
- affine_matrix[4] = mat[2];
- affine_matrix[5] = mat[5];
-
- affine = new AffineTransform();
-
- for( int i=0; i<3; i++){
- for( int j=0; j<3; j++)
- System.out.print( mat[i*3+j] + " ");
- System.out.println();
- }
- }
-
- public void projection( Image jpipimg, double scale)
- {
- jpipImg = jpipimg;
- refimg = refpnm.createScaleImage( scale);
- vw = refimg.getWidth(this);
- vh = refimg.getHeight(this);
- this.setSize( vw, vh);
-
- affine.setTransform( affine_matrix[0], affine_matrix[1], affine_matrix[2], affine_matrix[3], affine_matrix[4], affine_matrix[5]);
- repaint();
- }
-
- public void paint(Graphics g)
- {
- int iw, ih;
- BufferedImage bi, bi2;
- Graphics2D big, big2;
- Graphics2D g2 = (Graphics2D) g;
-
- g2.clearRect(0, 0, vw, vh);
-
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- g2.setRenderingHint(RenderingHints.KEY_RENDERING,
- RenderingHints.VALUE_RENDER_QUALITY);
-
- iw = refimg.getWidth(this);
- ih = refimg.getHeight(this);
-
- bi = new BufferedImage( iw, ih, BufferedImage.TYPE_INT_RGB);
- big = bi.createGraphics();
- big.drawImage(refimg, 0, 0, this);
-
- g2.drawImage(bi, 0, 0, this);
-
- bi2 = new BufferedImage( jpipImg.getWidth(this), jpipImg.getHeight(this), BufferedImage.TYPE_INT_RGB);
- big2 = bi2.createGraphics();
- big2.drawImage( jpipImg, 0, 0, this);
-
- g2.setTransform(affine);
-
- g2.drawImage(bi2, 0, 0, this);
- }
-
- public Dimension get_imsize()
- {
- return (new Dimension( vw, vh));
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * $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.*;
-import java.awt.event.*;
-import javax.swing.*;
-
-class ResizeListener implements ComponentListener
-{
- private ImageViewer iv;
- private Dimension largest;
-
- public ResizeListener( ImageViewer _iv)
- {
- iv = _iv;
- largest = iv.getSize();
- }
-
- public void componentHidden(ComponentEvent e) {}
-
- public void componentMoved(ComponentEvent e) {}
-
- public void componentResized(ComponentEvent e) {
- Dimension cursize = iv.getSize();
- if( largest.getWidth() < cursize.getWidth() || largest.getHeight() < cursize.getHeight()){
- update_largest( cursize);
- iv.enlarge();
- }
- }
-
- private void update_largest( Dimension cursize)
- {
- if( largest.getWidth() < cursize.getWidth())
- largest.setSize( cursize.getWidth(), largest.getHeight());
- if( largest.getHeight() < cursize.getHeight())
- largest.setSize( largest.getWidth(), cursize.getHeight());
- }
-
- public void componentShown(ComponentEvent e) {}
-}
\ No newline at end of file
+++ /dev/null
-<project name="opj_viewer_xerces" default="dist" basedir=".">
- <description>OpenJPIP client image viewer</description>
- <property name="src" location="src" />
- <property name="build" location="build"/>
- <property name="dist" location="dist" />
-
- <target name="init">
- <tstamp/>
- <mkdir dir="${build}"/>
- </target>
- <target name="compile" depends="init">
- <javac srcdir="${src}" destdir="${build}"/>
- </target>
- <target name="dist" depends="compile">
- <mkdir dir="${dist}"/>
- <jar jarfile="${dist}/opj_viewer_xerces-${DSTAMP}.jar"
- basedir="${build}" manifest="${dist}/manifest.txt"/>
- <exec dir="${dist}" executable="ln">
- <arg line="-sf opj_viewer_xerces-${DSTAMP}.jar opj_viewer_xerces.jar"/>
- </exec>
- </target>
- <target name="clean">
- <delete dir="${build}"/>
- <delete dir="${dist}"/>
- </target>
- <target name="test" depends="dist">
- <exec executable="appletviewer"><arg line="dist.html"/></exec>
- </target>
- <target name="build_test" depends="compile">
- <exec executable="appletviewer"><arg line="compile.html"/></exec>
- </target>
- <target name="build_testj" depends="compile">
- <exec executable="java"><arg line="-classpath build ImageWindow girl"/></exec>
- </target>
-</project>
+++ /dev/null
-Manifest-Version: 1.0
-Ant-Version: Apache Ant 1.7.0
-Created-By: Kaori Hagihara
-Main-Class: ImageWindow
-Class-Path: /usr/share/java/xerces-j2.jar
+++ /dev/null
-opj_viewer_xerces-20111010.jar
\ No newline at end of file
+++ /dev/null
-../../opj_viewer/src/ImageManager.java
\ No newline at end of file
+++ /dev/null
-/*
- * $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.*;
-import java.awt.event.*;
-import javax.swing.*;
-import java.awt.image.*;
-import java.awt.geom.*;
-import java.net.URL;
-import javax.swing.border.*;
-import java.util.*;
-import java.io.*;
-
-public class ImageViewer extends JPanel
-{
- private ImageManager imgmanager;
- private int vw, vh;
- private int iw, ih;
- private int selected = 0;
- private Image img;
-
- private String cmdline = new String();
- private boolean fullRefresh = false;
- private Point offset = new Point(0,0);
- private Rectangle rect = new Rectangle();
- private Rectangle roirect[] = null;
- private String roiname[] = null;
-
- public ImageViewer( String j2kfilename, ImageManager manager, boolean session, boolean jppstream)
- {
- String str;
- MML myMML;
-
- this.setSize( 170, 170);
- Dimension asz = this.getSize();
-
- vw = asz.width;
- vh = asz.height;
-
- setBackground(Color.black);
- myMML = new MML(this);
-
- imgmanager = manager;
-
- img = imgmanager.getImage( j2kfilename, vw, vh, session, jppstream, !jppstream);
-
- addMouseListener(myMML);
- addMouseMotionListener(myMML);
- addComponentListener( new ResizeListener(this));
- }
-
- public Image getImage()
- {
- return img;
- }
-
- public void zoomIn()
- {
- roirect = null;
- roiname = null;
-
- double scalex = (double)vw/(double)rect.width;
- double scaley = (double)vh/(double)rect.height;
-
- int fw = (int)(imgmanager.getFw()*scalex);
- int fh = (int)(imgmanager.getFh()*scaley);
- int rx = (int)((imgmanager.getRx()+rect.x)*scalex);
- int ry = (int)((imgmanager.getRy()+rect.y)*scaley);
-
- img = imgmanager.getImage( fw, fh, rx, ry, vw, vh);
-
- rect.x = rect.y = rect.width = rect.height = 0;
-
- selected = 0;
- fullRefresh = true;
- repaint();
- }
-
- public void enlarge()
- {
- roirect = null;
- roiname = null;
-
- Dimension asz = this.getSize();
-
- vw = asz.width;
- vh = asz.height;
-
- double scalex = vw/(double)imgmanager.getRw();
- double scaley = vh/(double)imgmanager.getRh();
-
- int fw = (int)(imgmanager.getFw()*scalex);
- int fh = (int)(imgmanager.getFh()*scaley);
- int rx = (int)(imgmanager.getRx()*scalex);
- int ry = (int)(imgmanager.getRy()*scaley);
-
- img = imgmanager.getImage( fw, fh, rx, ry, vw, vh);
-
- fullRefresh = true;
- repaint();
- }
-
- public void setSelected(int state)
- {
- roirect = null;
- roiname = null;
-
- if (state != selected) {
-
- selected = state;
- repaint();
- }
- }
-
- public boolean isInsideRect(int x, int y)
- {
- return rect.contains(x - offset.x, y - offset.y);
- }
-
- public void setRGeom(int x1, int y1, int x2, int y2)
- {
- rect.x = Math.min(x1,x2) - offset.x;
- rect.y = Math.min(y1,y2) - offset.y;
- rect.width = Math.abs(x2-x1);
- rect.height = Math.abs(y2-y1);
- }
-
- public void annotate( JP2XMLparser.ROIparams roi[])
- {
- int numofroi = roi.length;
-
- roirect = new Rectangle [numofroi];
- roiname = new String [numofroi];
-
- double scale_x = imgmanager.getFw()/(double)imgmanager.getOrigWidth();
- double scale_y = imgmanager.getFh()/(double)imgmanager.getOrigHeight();
- int rx = imgmanager.getRx();
- int ry = imgmanager.getRy();
- int rw = imgmanager.getRw();
- int rh = imgmanager.getRh();
-
- for( int i=0; i<numofroi ; i++){
- int x = (int)(roi[i].x*scale_x) - rx;
- int y = (int)(roi[i].y*scale_y) - ry;
- int w = (int)(roi[i].w*scale_x);
- int h = (int)(roi[i].h*scale_y);
- if( 0<=x && 0<=y && x+w<=rw && y+h<=rh){ // can be optimized
- roirect[i] = new Rectangle( x, y, w, h);
- roiname[i] = new String( roi[i].name);
- }
- else{
- roirect[i] = null;
- roiname[i] = null;
- }
- }
- repaint();
- }
-
- public boolean hasAnnotation()
- {
- if( roirect == null)
- return false;
- else
- return true;
- }
-
- public boolean isInsideROIRect(int x, int y)
- {
- for( int i=0; i<roirect.length; i++)
- if( roirect[i] != null)
- if( roirect[i].contains(x - offset.x, y - offset.y)){
- rect = roirect[i];
- return true;
- }
- return false;
- }
-
- public void paint(Graphics g)
- {
- BufferedImage bi;
- Graphics2D big;
- Graphics2D g2 = (Graphics2D) g;
-
- if (fullRefresh) {
- g2.clearRect(0, 0, vw, vh);
- fullRefresh = false;
- }
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- g2.setRenderingHint(RenderingHints.KEY_RENDERING,
- RenderingHints.VALUE_RENDER_QUALITY);
-
- offset.x = 0;
- offset.y = 0;
-
- iw = img.getWidth(this);
- ih = img.getHeight(this);
-
- bi = new BufferedImage( iw, ih, BufferedImage.TYPE_INT_RGB);
- big = bi.createGraphics();
-
- big.drawImage(img, 0, 0, this);
- big.setPaint(Color.red);
- if ((rect.width > 0) && (rect.height > 0))
- big.draw(rect);
-
- if( roirect != null){
- for( int i=0; i<roirect.length; i++)
- if( roirect[i] != null){
- big.draw( roirect[i]);
- big.drawString( roiname[i], roirect[i].x+3, roirect[i].y+roirect[i].height*2/3);
- }
- }
- if (selected == 1)
- shadeExt(big, 0, 0, 0, 64);
- else if (selected == 2) {
- shadeExt(big, 0, 0, 0, 255);
- selected = 1;
- }
- g2.drawImage(bi, offset.x, offset.y, this);
- }
-
- private void shadeRect(Graphics2D g2, int r, int g, int b, int a)
- {
- g2.setPaint(new Color(r, g, b, a));
- g2.fillRect(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1);
- }
-
- private void shadeExt(Graphics2D g2, int r, int g, int b, int a)
- {
- g2.setPaint(new Color(r, g, b, a));
- g2.fillRect(0, 0, iw, rect.y); /* _N_ */
- g2.fillRect(rect.x + rect.width + 1, rect.y,
- iw - rect.x - rect.width - 1, rect.height + 1); /* E */
- g2.fillRect(0, rect.y, rect.x, rect.height + 1); /* W */
- g2.fillRect(0, rect.y + rect.height + 1,
- iw, ih - rect.y - rect.height - 1); /* _S_ */
- }
-}
+++ /dev/null
-/*
- * $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 javax.swing.*;
-import java.awt.event.*;
-import java.awt.*;
-
-public class ImageWindow extends JFrame
-{
- private ImageViewer imgviewer;
- private OptionPanel optpanel;
- private ImageManager imgmanager;
-
- public ImageWindow( String uri, String j2kfilename, boolean session, boolean jppstream)
- {
- super( j2kfilename);
-
- imgmanager = new ImageManager( uri);
-
- imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream);
- imgviewer.setOpaque(true); //content panes must be opaque
-
- optpanel = new OptionPanel( imgmanager, imgviewer);
-
- JPanel panel = new JPanel();
- panel.setLayout(new BorderLayout());
- panel.add( imgviewer, BorderLayout.CENTER);
- panel.add( optpanel, BorderLayout.EAST);
-
- setContentPane( panel);
-
- addWindowListener(new WindowMyAdapter());
- }
-
- class WindowMyAdapter extends WindowAdapter
- {
- public void windowClosing(WindowEvent arg)
- {
- imgmanager.closeChannel();
- System.exit(0);
- }
- }
-
- public static void main(String s[])
- {
- String j2kfilename, uri;
- boolean session, jppstream;
-
- if(s.length >= 2){
- uri = s[0];
- j2kfilename = s[1];
- if( s.length > 2)
- session = !s[2].equalsIgnoreCase( "stateless");
- else
- session = true;
-
- if( s.length > 3)
- jppstream = !s[3].equalsIgnoreCase( "JPT");
- else
- jppstream = true;
- }
- else{
- System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [stateless/session] [JPT/JPP]");
- return;
- }
- ImageWindow frame = new ImageWindow( uri, j2kfilename, session, jppstream);
-
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- //Display the window.
- frame.pack();
- frame.setSize(new Dimension(400,200));
- frame.setLocation( 0, 50);
- frame.setVisible(true);
- }
-}
\ No newline at end of file
+++ /dev/null
-../../opj_viewer/src/ImgdecClient.java
\ No newline at end of file
+++ /dev/null
-/*
- * $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 org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.ErrorHandler;
-import org.apache.xerces.parsers.DOMParser;
-import org.xml.sax.InputSource;
-import java.io.*;
-import java.lang.Integer;
-
-public class JP2XMLparser
-{
- Document document;
-
- public static class ROIparams{
- public String name = null;
- public int x = 0;
- public int y = 0;
- public int w = 0;
- public int h = 0;
- }
-
- public static class IRTparams{
- public String refimg = null;
- public double []mat = { 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
- }
-
- public JP2XMLparser( byte[] buf)
- {
- try{
- InputSource source = new InputSource( new ByteArrayInputStream( buf));
- DOMParser parser = new DOMParser();
- parser.setErrorHandler(new MyHandler());
- parser.parse( source);
- document = parser.getDocument();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public ROIparams [] getROIparams()
- {
- ROIparams roi[];
- NodeList elements = document.getElementsByTagName("roi");
- int elementCount = elements.getLength();
-
- roi = new ROIparams [elementCount];
-
- for( int i = 0; i < elementCount; i++) {
- Element element = (Element)elements.item(i);
-
- roi[i] = new ROIparams();
- roi[i].name = element.getAttribute( "name");
- roi[i].x = Integer.parseInt( element.getAttribute( "x")) ;
- roi[i].y = Integer.parseInt( element.getAttribute( "y")) ;
- roi[i].w = Integer.parseInt( element.getAttribute( "w")) ;
- roi[i].h = Integer.parseInt( element.getAttribute( "h")) ;
- }
- return roi;
- }
-
- public IRTparams getIRTparams()
- {
- IRTparams irt = new IRTparams();
- NodeList elements = document.getElementsByTagName("irt");
- int elementCount = elements.getLength();
-
- Element element = (Element)elements.item(0);
- irt.refimg = element.getAttribute( "refimg");
- for( int i=1; i<=9; i++)
- irt.mat[i-1] = Double.parseDouble( element.getAttribute("m" + i));
-
- return irt;
- }
-}
-
-class MyHandler implements ErrorHandler {
- public void warning(SAXParseException e) {
- System.out.println("Warning: line" + e.getLineNumber());
- System.out.println(e.getMessage());
- }
- public void error(SAXParseException e) {
- System.out.println("Error: line" + e.getLineNumber());
- System.out.println(e.getMessage());
- }
- public void fatalError(SAXParseException e) {
- System.out.println("Critical error: line" + e.getLineNumber());
- System.out.println(e.getMessage());
- }
-}
\ No newline at end of file
+++ /dev/null
-../../opj_viewer/src/JPIPHttpClient.java
\ No newline at end of file
+++ /dev/null
-../../opj_viewer/src/MML.java
\ No newline at end of file
+++ /dev/null
-/*
- * $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.*;
-import java.awt.event.*;
-import javax.swing.*;
-
-public class OptionPanel extends JPanel implements ActionListener
-{
- private JButton roibutton;
- private JButton imregbutton;
- private ImageManager imgmanager;
- private ImageViewer iv;
- private JP2XMLparser xmlparser;
- private JFrame regimwindow;
- private RegimViewer regimgviewer;
-
- public OptionPanel( ImageManager manager, ImageViewer imgviewer)
- {
- this.setLayout(new BoxLayout( this, BoxLayout.Y_AXIS));
-
- roibutton = new JButton("Region Of Interest");
- imregbutton = new JButton("Image Registration");
-
- roibutton.setAlignmentX( Component.CENTER_ALIGNMENT);
- imregbutton.setAlignmentX( Component.CENTER_ALIGNMENT);
-
- add( roibutton);
- add( imregbutton);
- roibutton.addActionListener(this);
- imregbutton.addActionListener(this);
-
- imgmanager = manager;
- iv = imgviewer;
- xmlparser = null;
- }
-
- public void actionPerformed(ActionEvent e)
- {
- if( xmlparser == null){
- byte []xmldata = imgmanager.getXML();
- if( xmldata != null)
- xmlparser = new JP2XMLparser( xmldata);
- }
- if( e.getSource() == roibutton){
- if( xmlparser != null){
- JP2XMLparser.ROIparams roi[] = xmlparser.getROIparams();
- iv.annotate( roi);
- }
- }
- if( e.getSource() == imregbutton){
- if( xmlparser != null){
- if( regimwindow == null){
- JP2XMLparser.IRTparams irt = xmlparser.getIRTparams();
-
- regimgviewer = new RegimViewer( irt.refimg, irt.mat);
- regimgviewer.setOpaque(false);
-
- regimwindow = new JFrame("Registered Image");
- regimwindow.getContentPane().add("Center", regimgviewer);
- regimwindow.pack();
- regimwindow.setLocation( 500, 50);
- regimwindow.setVisible(true);
- }
- regimgviewer.projection( iv.getImage(), (double)imgmanager.getRw()/(double)imgmanager.getOrigWidth());
- regimwindow.setSize( regimgviewer.get_imsize());
- regimwindow.show();
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-../../opj_viewer/src/PnmImage.java
\ No newline at end of file
+++ /dev/null
-../../opj_viewer/src/RegimViewer.java
\ No newline at end of file
+++ /dev/null
-../../opj_viewer/src/ResizeListener.java
\ No newline at end of file
+++ /dev/null
-
-# Headers file are located here:
-INCLUDE_DIRECTORIES(
- ${OPENJPEG_SOURCE_DIR}/applications/jpip/libopenjpip
- ${FCGI_INCLUDE_DIRNAME}
-)
-
-SET(OPJ_SERVER_SRCS
-${CMAKE_CURRENT_SOURCE_DIR}/opj_server.c
-${CMAKE_CURRENT_SOURCE_DIR}/query_parser.c
-${CMAKE_CURRENT_SOURCE_DIR}/channel_manager.c
-${CMAKE_CURRENT_SOURCE_DIR}/session_manager.c
-${CMAKE_CURRENT_SOURCE_DIR}/jpip_parser.c
-)
-
-# Build executable
-ADD_DEFINITIONS(-DSERVER)
-ADD_EXECUTABLE(opj_server ${OPJ_SERVER_SRCS})
-TARGET_LINK_LIBRARIES(opj_server openjpip_server ${FCGI_LIBNAME})
-
-# On unix you need to link to the math library:
-IF(UNIX)
- TARGET_LINK_LIBRARIES(opj_server m)
-ENDIF(UNIX)
-
-# Install exe
-INSTALL(TARGETS opj_server
- EXPORT OpenJPEGTargets
- DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
-)
+++ /dev/null
-MAINTAINERCLEANFILES = Makefile.in
-
-bin_PROGRAMS = opj_server
-
-opj_server_CPPFLAGS = \
--I. \
--I$(top_srcdir)/applications/jpip/opj_server \
--I$(top_builddir)/applications/jpip/opj_server \
--I$(top_srcdir)/applications/jpip/libopenjpip \
--I$(top_builddir)/applications/jpip/libopenjpip \
-@FCGI_CFLAGS@ \
--DSERVER \
--DQUIT_SIGNAL=\"quitJPIP\"
-opj_server_CFLAGS =
-opj_server_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_server.la @FCGI_LIBS@ -lm
-opj_server_SOURCES = \
-channel_manager.c \
-opj_server.c \
-query_parser.c \
-session_manager.c \
-jpip_parser.c \
-channel_manager.h \
-query_parser.h \
-session_manager.h \
-jpip_parser.h
-
-install-data-hook:
- @echo -e " (B)\t$(bindir)/opj_server$(EXEEXT)" >> $(top_builddir)/report.txt
+++ /dev/null
-LIBDIR = ../libopenjpip
-
-LIBFNAME = $(LIBDIR)/libopenjpip_server.a
-CFLAGS = -O3 -Wall -m32 -DSERVER -DQUIT_SIGNAL=\"quitJPIP\" -I$(LIBDIR)
-LDFLAGS = -L$(LIBDIR) -lm -lfcgi -lopenjpip_server
-
-ALL = opj_server
-
-all: $(ALL)
-
-opj_server: opj_server.o query_parser.o channel_manager.o session_manager.o jpip_parser.o $(LIBFNAME)
- $(CC) $(CFLAGS) $< query_parser.o channel_manager.o session_manager.o jpip_parser.o $(LDFLAGS) -o $@
-
-clean:
- rm -f $(ALL) *.o *~
+++ /dev/null
-/*
- * $Id: channel_manager.c 44 2011-02-15 12:32:29Z kaori $
- *
- * 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.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include "channel_manager.h"
-
-#ifdef SERVER
-#include "fcgi_stdio.h"
-#define logstream FCGI_stdout
-#else
-#define FCGI_stdout stdout
-#define FCGI_stderr stderr
-#define logstream stderr
-#endif //SERVER
-
-channellist_param_t * gene_channellist()
-{
- channellist_param_t *channellist;
-
- channellist = (channellist_param_t *)malloc( sizeof(channellist_param_t));
-
- channellist->first = NULL;
- channellist->last = NULL;
-
- return channellist;
-}
-
-channel_param_t * gene_channel( query_param_t query_param, cachemodel_param_t *cachemodel, channellist_param_t *channellist)
-{
- channel_param_t *channel;
-
- if( !cachemodel){
- fprintf( FCGI_stdout, "Status: 404\r\n");
- fprintf( FCGI_stdout, "Reason: cnew cancelled\r\n");
- return NULL;
- }
-
- channel = (channel_param_t *)malloc( sizeof(channel_param_t));
- channel->cachemodel = cachemodel;
-
- // set channel ID and get present time
- snprintf( channel->cid, MAX_LENOFCID, "%x%x", (unsigned int)time( &channel->start_tm), (unsigned int)rand());
-
- channel->next=NULL;
-
- set_channel_variable_param( query_param, channel);
-
- if( channellist->first != NULL)
- channellist->last->next = channel;
- else
- channellist->first = channel;
- channellist->last = channel;
-
- fprintf( FCGI_stdout, "JPIP-cnew: cid=%s", channel->cid);
- // only http implemented for now
- fprintf( FCGI_stdout, ",transport=http\r\n");
-
- return channel;
-}
-
-
-void set_channel_variable_param( query_param_t query_param, channel_param_t *channel)
-{
- // set roi information
-}
-
-
-void delete_channel( channel_param_t **channel, channellist_param_t *channellist)
-{
- channel_param_t *ptr;
-
- if( *channel == channellist->first)
- channellist->first = (*channel)->next;
- else{
- ptr = channellist->first;
- while( ptr->next != *channel){
- ptr=ptr->next;
- }
-
- ptr->next = (*channel)->next;
-
- if( *channel == channellist->last)
- channellist->last = ptr;
- }
-#ifndef SERVER
- fprintf( logstream, "local log: channel: %s deleted\n", (*channel)->cid);
-#endif
- free(*channel);
-}
-
-void delete_channellist( channellist_param_t **channellist)
-{
- channel_param_t *channelPtr, *channelNext;
-
- channelPtr = (*channellist)->first;
- while( channelPtr != NULL){
- channelNext=channelPtr->next;
-#ifndef SERVER
- fprintf( logstream, "local log: channel %s deleted!\n", channelPtr->cid);
-#endif
- free(channelPtr);
- channelPtr=channelNext;
- }
- free( *channellist);
-}
-
-void print_allchannel( channellist_param_t *channellist)
-{
- channel_param_t *ptr;
-
- ptr = channellist->first;
- while( ptr != NULL){
- fprintf( logstream,"channel-ID=%s \t target=%s\n", ptr->cid, ptr->cachemodel->target->filename);
- ptr=ptr->next;
- }
-}
-
-channel_param_t * search_channel( char cid[], channellist_param_t *channellist)
-{
- channel_param_t *foundchannel;
-
- foundchannel = channellist->first;
-
- while( foundchannel != NULL){
-
- if( strcmp( cid, foundchannel->cid) == 0)
- return foundchannel;
-
- foundchannel = foundchannel->next;
- }
- fprintf( FCGI_stdout, "Status: 503\r\n");
- fprintf( FCGI_stdout, "Reason: Channel %s not found in this session\r\n", cid);
-
- return NULL;
-}
+++ /dev/null
-/*
- * $Id: channel_manager.h 44 2011-02-15 12:32:29Z kaori $
- *
- * 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.
- */
-
-#ifndef CHANNEL_MANAGER_H_
-# define CHANNEL_MANAGER_H_
-
-#include <time.h>
-#include "query_parser.h"
-#include "cachemodel_manager.h"
-
-//! Channel parameters
-typedef struct channel_param{
- cachemodel_param_t *cachemodel; //!< reference pointer to the cache model
- char cid[MAX_LENOFCID]; //!< channel identifier
- // - a record of the client's capabilities and preferences to the extent that the server queues requests
- time_t start_tm; //!< starting time
- struct channel_param *next; //!< pointer to the next channel
-} channel_param_t;
-
-
-//! Channel list parameters
-typedef struct channellist_param{
- channel_param_t *first; //!< first channel pointer of the list
- channel_param_t *last; //!< last channel pointer of the list
-} channellist_param_t;
-
-
-/**
- * generate a channel list
- *
- * @return pointer to the generated channel list
- */
-channellist_param_t * gene_channellist();
-
-
-/**
- * generate a channel under the channel list
- *
- * @param[in] query_param query parameters
- * @param[in] cachemodel reference cachemodel
- * @param[in] channellist channel list pointer
- * @return pointer to the generated channel
- */
-channel_param_t * gene_channel( query_param_t query_param, cachemodel_param_t *cachemodel, channellist_param_t *channellist);
-
-/**
- * set channel variable parameters
- *
- * @param[in] query_param query parameters
- * @param[in,out] channel pointer to the modifying channel
- */
-void set_channel_variable_param( query_param_t query_param, channel_param_t *channel);
-
-/**
- * delete a channel
- *
- * @param[in] channel address of the deleting channel pointer
- * @param[in,out] channellist channel list pointer
- */
-void delete_channel( channel_param_t **channel, channellist_param_t *channellist);
-
-
-/**
- * delete channel list
- *
- * @param[in,out] channellist address of the channel list pointer
- */
-void delete_channellist( channellist_param_t **channellist);
-
-
-/**
- * print all channel parameters
- *
- * @param[in] channellist channel list pointer
- */
-void print_allchannel( channellist_param_t *channellist);
-
-
-/**
- * search a channel by channel ID
- *
- * @param[in] cid channel identifier
- * @param[in] channellist channel list pointer
- * @return found channel pointer
- */
-channel_param_t * search_channel( char cid[], channellist_param_t *channellist);
-#endif /* !CHANNEL_MANAGER_H_ */
+++ /dev/null
-/*
- * $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
- * Copyright (c) 2011, Lucian Corlaciu, GSoC
- * 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.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include "jpip_parser.h"
-#include "channel_manager.h"
-#include "imgreg_manager.h"
-
-#ifdef SERVER
-#include "fcgi_stdio.h"
-#define logstream FCGI_stdout
-#else
-#define FCGI_stdout stdout
-#define FCGI_stderr stderr
-#define logstream stderr
-#endif //SERVER
-
-/**
- * REQUEST: target identification by target or tid request
- *
- * @param[in] query_param structured query
- * @param[in] targetlist target list pointer
- * @param[out] target address of target pointer
- * @return if succeeded (true) or failed (false)
- */
-bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target);
-
-/**
- * REQUEST: channel association
- * this must be processed before any process
- *
- * @param[in] query_param structured query
- * @param[in] sessionlist session list pointer
- * @param[out] cursession address of the associated session pointer
- * @param[out] curchannel address of the associated channel pointer
- * @return if succeeded (true) or failed (false)
- */
-bool associate_channel( query_param_t query_param,
- sessionlist_param_t *sessionlist,
- session_param_t **cursession,
- channel_param_t **curchannel);
-/**
- * REQUEST: new channel (cnew) assignment
- *
- * @param[in] query_param structured query
- * @param[in] sessionlist session list pointer
- * @param[in] target requested target pointer
- * @param[in,out] cursession address of the associated/opened session pointer
- * @param[in,out] curchannel address of the associated/opened channel pointer
- * @return if succeeded (true) or failed (false)
- */
-bool open_channel( query_param_t query_param,
- sessionlist_param_t *sessionlist,
- target_param_t *target,
- session_param_t **cursession,
- channel_param_t **curchannel);
-
-/**
- * REQUEST: channel close (cclose)
- *
- * @param[in] query_param structured query
- * @param[in] sessionlist session list pointer
- * @param[in,out] cursession address of the session pointer of deleting channel
- * @param[in,out] curchannel address of the deleting channel pointer
- * @return if succeeded (true) or failed (false)
- */
-bool close_channel( query_param_t query_param,
- sessionlist_param_t *sessionlist,
- session_param_t **cursession,
- channel_param_t **curchannel);
-
-/**
- * REQUEST: view-window (fsiz)
- *
- * @param[in] query_param structured query
- * @param[in] target requested target pointer
- * @param[in,out] cursession associated session pointer
- * @param[in,out] curchannel associated channel pointer
- * @param[out] msgqueue address of the message queue pointer
- * @return if succeeded (true) or failed (false)
- */
-bool gene_JPIPstream( query_param_t query_param,
- target_param_t *target,
- session_param_t *cursession,
- channel_param_t *curchannel,
- msgqueue_param_t **msgqueue);
-
-bool parse_JPIPrequest( query_param_t query_param,
- sessionlist_param_t *sessionlist,
- targetlist_param_t *targetlist,
- msgqueue_param_t **msgqueue)
-{
- target_param_t *target = NULL;
- session_param_t *cursession = NULL;
- channel_param_t *curchannel = NULL;
-
- if( query_param.target[0] != '\0' || query_param.tid[0] != '\0'){
- if( !identify_target( query_param, targetlist, &target))
- return false;
- }
-
- if( query_param.cid[0] != '\0'){
- if( !associate_channel( query_param, sessionlist, &cursession, &curchannel))
- return false;
- }
-
- if( query_param.cnew){
- if( !open_channel( query_param, sessionlist, target, &cursession, &curchannel))
- return false;
- }
- if( query_param.cclose[0][0] != '\0')
- if( !close_channel( query_param, sessionlist, &cursession, &curchannel))
- return false;
-
- if( (query_param.fx > 0 && query_param.fy > 0) || query_param.box_type[0][0] != 0)
- if( !gene_JPIPstream( query_param, target, cursession, curchannel, msgqueue))
- return false;
-
- return true;
-}
-
-bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target)
-{
- if( query_param.tid[0] !='\0' && strcmp( query_param.tid, "0") != 0 ){
- if( query_param.cid[0] != '\0'){
- fprintf( FCGI_stdout, "Reason: Target can not be specified both through tid and cid\r\n");
- fprintf( FCGI_stdout, "Status: 400\r\n");
- return false;
- }
- if( ( *target = search_targetBytid( query_param.tid, targetlist)))
- return true;
- }
-
- if( query_param.target[0] !='\0')
- if( !( *target = search_target( query_param.target, targetlist)))
- if(!( *target = gene_target( targetlist, query_param.target)))
- return false;
-
- if( *target){
- fprintf( FCGI_stdout, "JPIP-tid: %s\r\n", (*target)->tid);
- return true;
- }
- else{
- fprintf( FCGI_stdout, "Reason: target not found\r\n");
- fprintf( FCGI_stdout, "Status: 400\r\n");
- return false;
- }
-}
-
-bool associate_channel( query_param_t query_param,
- sessionlist_param_t *sessionlist,
- session_param_t **cursession,
- channel_param_t **curchannel)
-{
- if( search_session_and_channel( query_param.cid, sessionlist, cursession, curchannel)){
-
- if( !query_param.cnew)
- set_channel_variable_param( query_param, *curchannel);
- }
- else{
- fprintf( FCGI_stderr, "Error: process canceled\n");
- return false;
- }
- return true;
-}
-
-bool open_channel( query_param_t query_param,
- sessionlist_param_t *sessionlist,
- target_param_t *target,
- session_param_t **cursession,
- channel_param_t **curchannel)
-{
- cachemodel_param_t *cachemodel = NULL;
-
- if( target){
- if( !(*cursession))
- *cursession = gene_session( sessionlist);
- if( !( cachemodel = search_cachemodel( target, (*cursession)->cachemodellist)))
- if( !(cachemodel = gene_cachemodel( (*cursession)->cachemodellist, target, query_param.return_type==JPPstream)))
- return false;
- }
- else
- if( *curchannel)
- cachemodel = (*curchannel)->cachemodel;
-
- *curchannel = gene_channel( query_param, cachemodel, (*cursession)->channellist);
- if( *curchannel == NULL)
- return false;
-
- return true;
-}
-
-bool close_channel( query_param_t query_param,
- sessionlist_param_t *sessionlist,
- session_param_t **cursession,
- channel_param_t **curchannel)
-{
- if( query_param.cclose[0][0] =='*'){
-#ifndef SERVER
- fprintf( logstream, "local log: close all\n");
-#endif
- // all channels associatd with the session will be closed
- if( !delete_session( cursession, sessionlist))
- return false;
- }
- else{
- // check if all entry belonging to the same session
- int i=0;
- while( query_param.cclose[i][0] !='\0'){
-
- // In case of the first entry of close cid
- if( *cursession == NULL){
- if( !search_session_and_channel( query_param.cclose[i], sessionlist, cursession, curchannel))
- return false;
- }
- else // second or more entry of close cid
- if( !(*curchannel=search_channel( query_param.cclose[i], (*cursession)->channellist))){
- fprintf( FCGI_stdout, "Reason: Cclose id %s is from another session\r\n", query_param.cclose[i]);
- return false;
- }
- i++;
- }
- // delete channels
- i=0;
- while( query_param.cclose[i][0] !='\0'){
-
- *curchannel = search_channel( query_param.cclose[i], (*cursession)->channellist);
- delete_channel( curchannel, (*cursession)->channellist);
- i++;
- }
-
- if( (*cursession)->channellist->first == NULL || (*cursession)->channellist->last == NULL)
- // In case of empty session
- delete_session( cursession, sessionlist);
- }
- return true;
-}
-
-
-/**
- * enqueue tiles or precincts into the message queue
- *
- * @param[in] query_param structured query
- * @param[in] msgqueue message queue pointer
- */
-void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue);
-
-/**
- * enqueue metadata bins into the message queue
- *
- * @param[in] query_param structured query
- * @param[in] metadatalist pointer to metadata bin list
- * @param[in,out] msgqueue message queue pointer
- */
-void enqueue_metabins( query_param_t query_param, metadatalist_param_t *metadatalist, msgqueue_param_t *msgqueue);
-
-
-bool gene_JPIPstream( query_param_t query_param,
- target_param_t *target,
- session_param_t *cursession,
- channel_param_t *curchannel,
- msgqueue_param_t **msgqueue)
-{
- index_param_t *codeidx;
- cachemodel_param_t *cachemodel;
-
- if( !cursession || !curchannel){ // stateless
- if( !target)
- return false;
- if( !(cachemodel = gene_cachemodel( NULL, target, query_param.return_type==JPPstream)))
- return false;
- *msgqueue = gene_msgqueue( true, cachemodel);
- }
- else{ // session
- cachemodel = curchannel->cachemodel;
- target = cachemodel->target;
- *msgqueue = gene_msgqueue( false, cachemodel);
- }
-
- codeidx = target->codeidx;
-
- if( cachemodel->jppstream)
- fprintf( FCGI_stdout, "Content-type: image/jpp-stream\r\n");
- else
- fprintf( FCGI_stdout, "Content-type: image/jpt-stream\r\n");
-
- if( query_param.layers != -1){
- if( query_param.layers > codeidx->COD.numOflayers){
- fprintf( FCGI_stdout, "JPIP-layers: %d\r\n", codeidx->COD.numOflayers);
- query_param.layers = codeidx->COD.numOflayers;
- }
- }
-
- //meta
- if( query_param.box_type[0][0] != 0 && query_param.len != 0)
- enqueue_metabins( query_param, codeidx->metadatalist, *msgqueue);
-
- // image codestream
- if( query_param.fx > 0 && query_param.fy > 0){
- if( !cachemodel->mhead_model && query_param.len != 0)
- enqueue_mainheader( *msgqueue);
- enqueue_imagedata( query_param, *msgqueue);
- }
- return true;
-}
-
-
-/**
- * enqueue precinct data-bins into the queue
- *
- * @param[in] xmin min x coordinate in the tile at the decomposition level
- * @param[in] xmax max x coordinate in the tile at the decomposition level
- * @param[in] ymin min y coordinate in the tile at the decomposition level
- * @param[in] ymax max y coordinate in the tile at the decomposition level
- * @param[in] tile_id tile index
- * @param[in] level decomposition level
- * @param[in] lastcomp last component number
- * @param[in] comps pointer to the array that stores the requested components
- * @param[in] layers number of quality layers
- * @param[in] msgqueue message queue
- * @return
- */
-void enqueue_precincts( int xmin, int xmax, int ymin, int ymax, int tile_id, int level, int lastcomp, bool *comps, int layers, msgqueue_param_t *msgqueue);
-
-/**
- * enqueue all precincts inside a tile into the queue
- *
- * @param[in] tile_id tile index
- * @param[in] level decomposition level
- * @param[in] lastcomp last component number
- * @param[in] comps pointer to the array that stores the requested components
- * @param[in] layers number of quality layers
- * @param[in] msgqueue message queue
- * @return
- */
-void enqueue_allprecincts( int tile_id, int level, int lastcomp, bool *comps, int layers, msgqueue_param_t *msgqueue);
-
-void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
-{
- index_param_t *codeidx;
- imgreg_param_t imgreg;
- range_param_t tile_Xrange, tile_Yrange;
- int u, v, tile_id;
- int xmin, xmax, ymin, ymax;
- int numOfreslev;
-
- codeidx = msgqueue->cachemodel->target->codeidx;
-
- if( !(msgqueue->cachemodel->jppstream) && get_nmax( codeidx->tilepart) == 1) // normally not the case
- numOfreslev = 1;
- else
- numOfreslev = codeidx->COD.numOfdecomp+1;
-
- imgreg = map_viewin2imgreg( query_param.fx, query_param.fy,
- query_param.rx, query_param.ry, query_param.rw, query_param.rh,
- codeidx->SIZ.XOsiz, codeidx->SIZ.YOsiz, codeidx->SIZ.Xsiz, codeidx->SIZ.Ysiz,
- numOfreslev );
-
- if( query_param.len == 0)
- return;
-
- for( u=0, tile_id=0; u<codeidx->SIZ.YTnum; u++){
- tile_Yrange = get_tile_Yrange( codeidx->SIZ, tile_id, imgreg.level);
-
- for( v=0; v<codeidx->SIZ.XTnum; v++, tile_id++){
- tile_Xrange = get_tile_Xrange( codeidx->SIZ, tile_id, imgreg.level);
-
- if( tile_Xrange.minvalue < tile_Xrange.maxvalue && tile_Yrange.minvalue < tile_Yrange.maxvalue){
- if( tile_Xrange.maxvalue <= imgreg.xosiz + imgreg.ox ||
- tile_Xrange.minvalue >= imgreg.xosiz + imgreg.ox + imgreg.sx ||
- tile_Yrange.maxvalue <= imgreg.yosiz + imgreg.oy ||
- tile_Yrange.minvalue >= imgreg.yosiz + imgreg.oy + imgreg.sy) {
- //printf("Tile completely excluded from view-window %d\n", tile_id);
- // Tile completely excluded from view-window
- }
- else if( tile_Xrange.minvalue >= imgreg.xosiz + imgreg.ox &&
- tile_Xrange.maxvalue <= imgreg.xosiz + imgreg.ox + imgreg.sx &&
- tile_Yrange.minvalue >= imgreg.yosiz + imgreg.oy &&
- tile_Yrange.maxvalue <= imgreg.yosiz + imgreg.oy + imgreg.sy) {
- // Tile completely contained within view-window
- // high priority
- //printf("Tile completely contained within view-window %d\n", tile_id);
- if( msgqueue->cachemodel->jppstream){
- enqueue_tileheader( tile_id, msgqueue);
- enqueue_allprecincts( tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue);
- }
- else
- enqueue_tile( tile_id, imgreg.level, msgqueue);
- }
- else{
- // Tile partially overlaps view-window
- // low priority
- //printf("Tile partially overlaps view-window %d\n", tile_id);
- if( msgqueue->cachemodel->jppstream){
- enqueue_tileheader( tile_id, msgqueue);
-
- xmin = tile_Xrange.minvalue >= imgreg.xosiz + imgreg.ox ? 0 : imgreg.xosiz + imgreg.ox - tile_Xrange.minvalue;
- xmax = tile_Xrange.maxvalue <= imgreg.xosiz + imgreg.ox + imgreg.sx ? tile_Xrange.maxvalue - tile_Xrange.minvalue -1 : imgreg.xosiz + imgreg.ox + imgreg.sx - tile_Xrange.minvalue -1;
- ymin = tile_Yrange.minvalue >= imgreg.yosiz + imgreg.oy ? 0 : imgreg.yosiz + imgreg.oy - tile_Yrange.minvalue;
- ymax = tile_Yrange.maxvalue <= imgreg.yosiz + imgreg.oy + imgreg.sy ? tile_Yrange.maxvalue - tile_Yrange.minvalue -1 : imgreg.yosiz + imgreg.oy + imgreg.sy - tile_Yrange.minvalue -1;
- enqueue_precincts( xmin, xmax, ymin, ymax, tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue);
- }
- else
- enqueue_tile( tile_id, imgreg.level, msgqueue);
- }
- }
- }
- }
-}
-
-
-void enqueue_precincts( int xmin, int xmax, int ymin, int ymax, int tile_id, int level, int lastcomp, bool *comps, int layers, msgqueue_param_t *msgqueue)
-{
- index_param_t *codeidx;
- int c, u, v, res_lev, dec_lev;
- int seq_id;
- Byte4_t XTsiz, YTsiz;
- Byte4_t XPsiz, YPsiz;
- Byte4_t xminP, xmaxP, yminP, ymaxP;
-
- codeidx = msgqueue->cachemodel->target->codeidx;
-
- for( c=0; c<codeidx->SIZ.Csiz; c++)
- if( lastcomp == -1 /*all*/ || ( c<=lastcomp && comps[c])){
- seq_id = 0;
- for( res_lev=0, dec_lev=codeidx->COD.numOfdecomp; dec_lev>=level; res_lev++, dec_lev--){
-
- XTsiz = get_tile_XSiz( codeidx->SIZ, tile_id, dec_lev);
- YTsiz = get_tile_YSiz( codeidx->SIZ, tile_id, dec_lev);
-
- XPsiz = ( codeidx->COD.Scod & 0x01) ? codeidx->COD.XPsiz[ res_lev] : XTsiz;
- YPsiz = ( codeidx->COD.Scod & 0x01) ? codeidx->COD.YPsiz[ res_lev] : YTsiz;
-
- for( u=0; u<ceil((double)YTsiz/(double)YPsiz); u++){
- yminP = u*YPsiz;
- ymaxP = (u+1)*YPsiz-1;
- if( YTsiz <= ymaxP)
- ymaxP = YTsiz-1;
-
- for( v=0; v<ceil((double)XTsiz/(double)XPsiz); v++, seq_id++){
- xminP = v*XPsiz;
- xmaxP = (v+1)*XPsiz-1;
- if( XTsiz <= xmaxP)
- xmaxP = XTsiz-1;
-
- if( xmaxP < xmin || xminP > xmax || ymaxP < ymin || yminP > ymax){
- // Precinct completely excluded from view-window
- }
- else if( xminP >= xmin && xmaxP <= xmax && yminP >= ymin && ymaxP <= ymax){
- // Precinct completely contained within view-window
- // high priority
- enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue);
- }
- else{
- // Precinct partially overlaps view-window
- // low priority
- enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue);
- }
- }
- }
- }
- }
-}
-
-void enqueue_allprecincts( int tile_id, int level, int lastcomp, bool *comps, int layers, msgqueue_param_t *msgqueue)
-{
- index_param_t *codeidx;
- int c, i, res_lev, dec_lev;
- int seq_id;
- Byte4_t XTsiz, YTsiz;
- Byte4_t XPsiz, YPsiz;
-
- codeidx = msgqueue->cachemodel->target->codeidx;
-
- for( c=0; c<codeidx->SIZ.Csiz; c++)
- if( lastcomp == -1 /*all*/ || ( c<=lastcomp && comps[c])){
- seq_id = 0;
- for( res_lev=0, dec_lev=codeidx->COD.numOfdecomp; dec_lev>=level; res_lev++, dec_lev--){
-
- XTsiz = get_tile_XSiz( codeidx->SIZ, tile_id, dec_lev);
- YTsiz = get_tile_YSiz( codeidx->SIZ, tile_id, dec_lev);
-
- XPsiz = ( codeidx->COD.Scod & 0x01) ? codeidx->COD.XPsiz[ res_lev] : XTsiz;
- YPsiz = ( codeidx->COD.Scod & 0x01) ? codeidx->COD.YPsiz[ res_lev] : YTsiz;
-
- for( i=0; i<ceil((double)YTsiz/(double)YPsiz)*ceil((double)XTsiz/(double)XPsiz); i++, seq_id++)
- enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue);
- }
- }
-}
-
-void enqueue_metabins( query_param_t query_param, metadatalist_param_t *metadatalist, msgqueue_param_t *msgqueue)
-{
- int i;
- for( i=0; query_param.box_type[i][0]!=0 && i<MAX_NUMOFBOX; i++){
- if( query_param.box_type[i][0] == '*'){
- // not implemented
- }
- else{
- int idx = search_metadataidx( query_param.box_type[i], metadatalist);
-
- if( idx != -1)
- enqueue_metadata( idx, msgqueue);
- }
- }
-}
+++ /dev/null
-/*
- * $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
- * Copyright (c) 2011, Lucian Corlaciu, GSoC
- * 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.
- */
-
-#ifndef JPIP_PARSER_H_
-# define JPIP_PARSER_H_
-
-#include "bool.h"
-#include "query_parser.h"
-#include "session_manager.h"
-#include "target_manager.h"
-#include "msgqueue_manager.h"
-
-/**
- * parse JPIP request
- *
- * @param[in] query_param structured query
- * @param[in] sessionlist session list pointer
- * @param[in] targetlist target list pointer
- * @param[in,out] msgqueue address of the message queue pointer
- * @return if succeeded (true) or failed (false)
- */
-bool parse_JPIPrequest( query_param_t query_param,
- sessionlist_param_t *sessionlist,
- targetlist_param_t *targetlist,
- msgqueue_param_t **msgqueue);
-
-
-#endif /* !JPIP_PARSER_H_ */
+++ /dev/null
-/*
- * $Id: opj_server.c 53 2011-05-09 16:55:39Z kaori $
- *
- * 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
- * Copyright (c) 2011, Lucian Corlaciu, GSoC
- * 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.
- */
-
-/*! \file
- * \brief opj_server is a JPIP server program, which supports HTTP connection, JPT-stream, session, channels, and cache model managements.
- *
- * \section req Requirements
- * FastCGI development kit (http://www.fastcgi.com).
- *
- * \section impinst Implementing instructions
- * Launch opj_server from the server terminal:\n
- * % spawn-fcgi -f ./opj_server -p 3000 -n
- *
- * Note: JP2 files are stored in the working directory of opj_server\n
- * Check README for the JP2 Encoding\n
- *
- * We tested this software with a virtual server running on the same Linux machine as the clients.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <math.h>
-
-#include "query_parser.h"
-#include "jpip_parser.h"
-#include "session_manager.h"
-#include "target_manager.h"
-#include "msgqueue_manager.h"
-
-#ifndef QUIT_SIGNAL
-#define QUIT_SIGNAL "quitJPIP"
-#endif
-
-#ifdef SERVER
-#include "fcgi_stdio.h"
-#define logstream FCGI_stdout
-#else
-#define FCGI_stdout stdout
-#define FCGI_stderr stderr
-#define logstream stderr
-#endif //SERVER
-
-int main(void)
-{
- sessionlist_param_t *sessionlist;
- targetlist_param_t *targetlist;
- bool parse_status;
-
- sessionlist = gene_sessionlist();
- targetlist = gene_targetlist();
-
-#ifdef SERVER
-
- char *query_string;
- while(FCGI_Accept() >= 0)
-#else
-
- char query_string[128];
- while( fgets( query_string, 128, stdin) && query_string[0]!='\n')
-#endif
- {
-
-#ifdef SERVER
- query_string = getenv("QUERY_STRING");
-#endif //SERVER
-
- if( strcmp( query_string, QUIT_SIGNAL) == 0)
- break;
-
- query_param_t query_param;
- msgqueue_param_t *msgqueue;
-
- parse_query( query_string, &query_param);
-
-#ifndef SERVER
- print_queryparam( query_param);
-#endif
-
- msgqueue = NULL;
- if( !(parse_status = parse_JPIPrequest( query_param, sessionlist, targetlist, &msgqueue)))
- fprintf( FCGI_stderr, "Error: JPIP request failed\n");
-
- fprintf( FCGI_stdout, "\r\n");
-
-#ifndef SERVER
- // if( parse_status)
- // print_allsession( sessionlist);
- print_msgqueue( msgqueue);
-#endif
-
- emit_stream_from_msgqueue( msgqueue);
-
- delete_msgqueue( &msgqueue);
- }
-
- fprintf( FCGI_stderr, "JPIP server terminated by a client request\n");
-
- delete_sessionlist( &sessionlist);
- delete_targetlist( &targetlist);
-
- return 0;
-}
+++ /dev/null
-/*
- * $Id: query_parser.c 53 2011-05-09 16:55:39Z kaori $
- *
- * 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
- * Copyright (c) 2011, Lucian Corlaciu, GSoC
- * 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.
- */
-
-
-#ifdef _WIN32
-#include <windows.h>
-#define strcasecmp _stricmp
-#else
-#include <strings.h>
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include "query_parser.h"
-
-#ifdef SERVER
-#include "fcgi_stdio.h"
-#define logstream FCGI_stdout
-#else
-#define FCGI_stdout stdout
-#define FCGI_stderr stderr
-#define logstream stderr
-#endif //SERVER
-
-
-/**
- * initialize query parameters
- *
- * @param[in,out] query_param query parameters
- */
-void init_queryparam( query_param_t *query_param);
-
-/*
- * get a pair of field name and value from the string starting fieldname=fieldval&... format
- *
- * @param[in] stringptr pointer to the beginning of the parsing string
- * @param[out] fieldname string to copy the field name, if not found, NULL
- * @param[out] fieldval string to copy the field value, if not found, NULL
- * @return pointer to the next field string, if there is none, NULL
- */
-char * get_fieldparam( char *stringptr, char *fieldname, char *fieldval);
-
-/**
- * parse string to string array
- *
- * @param[in] src src string
- * @param[out] cclose parsed string array
- */
-void str2cclose( char *src, char cclose[][MAX_LENOFCID]);
-
-void parse_metareq( char *field, query_param_t *query_param);
-
-// parse the requested components (parses forms like:a; a,b; a-b; a-b,c; a,b-c)
-void parse_comps( char *field, query_param_t *query_param);
-
-
-//! maximum length of field name
-#define MAX_LENOFFIELDNAME 10
-
-//! maximum length of field value
-#define MAX_LENOFFIELDVAL 128
-
-void parse_query( char *query_string, query_param_t *query_param)
-{
- char *pquery, fieldname[MAX_LENOFFIELDNAME], fieldval[MAX_LENOFFIELDVAL];
-
- init_queryparam( query_param);
-
- pquery = query_string;
-
- while( pquery!=NULL) {
-
- pquery = get_fieldparam( pquery, fieldname, fieldval);
-
- if( fieldname[0] != '\0'){
- if( strcasecmp( fieldname, "target") == 0)
- strcpy( query_param->target,fieldval);
-
- else if( strcasecmp( fieldname, "tid") == 0)
- strcpy( query_param->tid, fieldval);
-
- else if( strcasecmp( fieldname, "fsiz") == 0)
- sscanf( fieldval, "%d,%d", &query_param->fx, &query_param->fy);
-
- else if( strcasecmp( fieldname, "roff") == 0)
- sscanf( fieldval, "%d,%d", &query_param->rx, &query_param->ry);
-
- else if( strcasecmp( fieldname, "rsiz") == 0)
- sscanf( fieldval, "%d,%d", &query_param->rw, &query_param->rh);
-
- else if( strcasecmp( fieldname, "layers") == 0)
- sscanf( fieldval, "%d", &query_param->layers);
-
- else if( strcasecmp( fieldname, "cid") == 0)
- strcpy( query_param->cid, fieldval);
-
- else if( strcasecmp( fieldname, "cnew") == 0)
- query_param->cnew = true;
-
- else if( strcasecmp( fieldname, "cclose") == 0)
- str2cclose( fieldval, query_param->cclose);
-
- else if( strcasecmp( fieldname, "metareq") == 0)
- parse_metareq( fieldval, query_param);
-
- else if( strcasecmp( fieldname, "comps") == 0)
- parse_comps( fieldval, query_param);
-
- else if( strcasecmp( fieldname, "type") == 0){
- if( strncasecmp( fieldval, "jpp-stream", 10) == 0)
- query_param->return_type = JPPstream;
- else if( strncasecmp( fieldval, "jpt-stream", 10) == 0)
- query_param->return_type = JPTstream;
- }
-
- else if( strcasecmp( fieldname, "len") == 0)
- sscanf( fieldval, "%d", &query_param->len);
- }
- }
-}
-
-void init_queryparam( query_param_t *query_param)
-{
- int i;
-
- query_param->target[0] = '\0';
- query_param->tid[0] = '\0';
- query_param->fx = -1;
- query_param->fy = -1;
- query_param->rx = -1;
- query_param->ry = -1;
- query_param->rw = -1;
- query_param->rh = -1;
- query_param->layers = -1;
- query_param->lastcomp = -1;
- query_param->comps = NULL;
- query_param->cid[0] = '\0';
- query_param->cnew = false;
- memset( query_param->cclose, 0, MAX_NUMOFCCLOSE*MAX_LENOFCID);
- memset( query_param->box_type, 0, MAX_NUMOFBOX*4);
- memset( query_param->limit, 0, MAX_NUMOFBOX*sizeof(int));
- for( i=0; i<MAX_NUMOFBOX; i++){
- query_param->w[i] = false;
- query_param->s[i] = false;
- query_param->g[i] = false;
- query_param->a[i] = false;
- query_param->priority[i] = false;
- }
- query_param->root_bin = 0;
- query_param->max_depth = -1;
- query_param->metadata_only = false;
- query_param->return_type = UNKNOWN;
- query_param->len = -1;
-}
-
-
-char * get_fieldparam( char *stringptr, char *fieldname, char *fieldval)
-{
- char *eqp, *andp, *nexfieldptr;
-
- if((eqp = strchr( stringptr, '='))==NULL){
- fprintf( stderr, "= not found\n");
- strcpy( fieldname, "");
- strcpy( fieldval, "");
- return NULL;
- }
- if((andp = strchr( stringptr, '&'))==NULL){
- andp = strchr( stringptr, '\0');
- nexfieldptr = NULL;
- }
- else
- nexfieldptr = andp+1;
-
- strncpy( fieldname, stringptr, eqp-stringptr);
- fieldname[eqp-stringptr]='\0';
- strncpy( fieldval, eqp+1, andp-eqp-1);
- fieldval[andp-eqp-1]='\0';
-
- return nexfieldptr;
-}
-
-void print_queryparam( query_param_t query_param)
-{
- int i;
-
- fprintf( logstream, "query parameters:\n");
- fprintf( logstream, "\t target: %s\n", query_param.target);
- fprintf( logstream, "\t tid: %s\n", query_param.tid);
- fprintf( logstream, "\t fx,fy: %d, %d\n", query_param.fx, query_param.fy);
- fprintf( logstream, "\t rx,ry: %d, %d \t rw,rh: %d, %d\n", query_param.rx, query_param.ry, query_param.rw, query_param.rh);
- fprintf( logstream, "\t layers: %d\n", query_param.layers);
- fprintf( logstream, "\t components: ");
- if( query_param.lastcomp == -1)
- fprintf( logstream, "ALL\n");
- else{
- for( i=0; i<=query_param.lastcomp; i++)
- if( query_param.comps[i])
- fprintf( logstream, "%d ", i);
- fprintf( logstream, "\n");
- }
- fprintf( logstream, "\t cnew: %d\n", query_param.cnew);
- fprintf( logstream, "\t cid: %s\n", query_param.cid);
-
- fprintf( logstream, "\t cclose: ");
- for( i=0; query_param.cclose[i][0]!=0 && i<MAX_NUMOFCCLOSE; i++)
- fprintf( logstream, "%s ", query_param.cclose[i]);
- fprintf(logstream, "\n");
-
- fprintf( logstream, "\t req-box-prop\n");
- for( i=0; query_param.box_type[i][0]!=0 && i<MAX_NUMOFBOX; i++){
- fprintf( logstream, "\t\t box_type: %.4s limit: %d w:%d s:%d g:%d a:%d priority:%d\n", query_param.box_type[i], query_param.limit[i], query_param.w[i], query_param.s[i], query_param.g[i], query_param.a[i], query_param.priority[i]);
- }
-
- fprintf( logstream, "\t root-bin: %d\n", query_param.root_bin);
- fprintf( logstream, "\t max-depth: %d\n", query_param.max_depth);
- fprintf( logstream, "\t metadata-only: %d\n", query_param.metadata_only);
- fprintf( logstream, "\t image return type: %d, [JPP-stream=0, JPT-stream=1, UNKNOWN=-1]\n", query_param.return_type);
- fprintf( logstream, "\t len: %d\n", query_param.len);
-}
-
-void str2cclose( char *src, char cclose[][MAX_LENOFCID])
-{
- int i, u, v;
-
- size_t len = strlen( src);
-
- for( i=0, u=0, v=0; i<len; i++){
- if( src[i]==','){
- u++;
- v=0;
- }
- else
- cclose[u][v++] = src[i];
- }
-}
-
-void parse_req_box_prop( char *req_box_prop, int idx, query_param_t *query_param);
-
-void parse_metareq( char *field, query_param_t *query_param)
-{
- char req_box_prop[20];
- char *ptr, *src;
- int numofboxreq = 0;
-
- memset( req_box_prop, 0, 20);
-
- // req-box-prop
- ptr = strchr( field, '[');
- ptr++;
- src = ptr;
- while( *ptr != ']'){
- if( *ptr == ';'){
- strncpy( req_box_prop, src, ptr-src);
- parse_req_box_prop( req_box_prop, numofboxreq++, query_param);
- ptr++;
- src = ptr;
- memset( req_box_prop, 0, 20);
- }
- ptr++;
- }
- strncpy( req_box_prop, src, ptr-src);
-
- parse_req_box_prop( req_box_prop, numofboxreq++, query_param);
-
- if(( ptr = strchr( field, 'R')))
- sscanf( ptr+1, "%d", &(query_param->root_bin));
-
- if(( ptr = strchr( field, 'D')))
- sscanf( ptr+1, "%d", &(query_param->max_depth));
-
- if(( ptr = strstr( field, "!!")))
- query_param->metadata_only = true;
-}
-
-void parse_req_box_prop( char *req_box_prop, int idx, query_param_t *query_param)
-{
- char *ptr;
-
- if( *req_box_prop == '*')
- query_param->box_type[idx][0]='*';
- else
- strncpy( query_param->box_type[idx], req_box_prop, 4);
-
- if(( ptr = strchr( req_box_prop, ':'))){
- if( *(ptr+1)=='r')
- query_param->limit[idx] = -1;
- else
- sscanf( ptr+1, "%d", &(query_param->limit[idx]));
- }
-
- if(( ptr = strchr( req_box_prop, '/'))){
- ptr++;
- while( *ptr=='w' || *ptr=='s' || *ptr=='g' || *ptr=='a'){
- switch( *ptr){
- case 'w': query_param->w[idx] = true; break;
- case 's': query_param->s[idx] = true; break;
- case 'g': query_param->g[idx] = true; break;
- case 'a': query_param->a[idx] = true; break;
- }
- ptr++;
- }
- }
- else{
- query_param->g[idx] = true;
- query_param->s[idx] = true;
- query_param->w[idx] = true;
- }
-
- if((ptr = strchr( req_box_prop, '!')))
- query_param->priority[idx] = true;
-
- idx++;
-}
-
-void parse_comps( char *field, query_param_t *query_param)
-{
- int i,start,stop,aux = -1;
- char *ptr1,*ptr2;
-
- ptr1 = strchr( field, '-');
- ptr2 = strchr( field, ',');
-
- if( ptr1 && ptr2)
- if( ptr1 > ptr2)
- sscanf( field, "%d,%d-%d",&aux, &start, &stop);
- else
- sscanf( field, "%d-%d,%d", &start, &stop, &aux);
- else
- if(ptr1)
- sscanf( field, "%d-%d", &start, &stop);
- else if(ptr2){
- sscanf( field, "%d,%d", &start, &stop);
- aux = start;
- start = stop;
- }
- else{
- sscanf( field, "%d", &stop);
- start = stop;
- }
-
- query_param->lastcomp = stop > aux ? stop : aux;
- query_param->comps = (bool *)calloc( 1, (query_param->lastcomp+1)*sizeof(bool));
-
- for( i=start; i<=stop; i++)
- query_param->comps[i]=true;
-
- if(aux!=-1)
- query_param->comps[aux] = true;
-}
+++ /dev/null
-/*
- * $Id: query_parser.h 53 2011-05-09 16:55:39Z kaori $
- *
- * 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
- * Copyright (c) 2011, Lucian Corlaciu, GSoC
- * 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.
- */
-
-#ifndef QUERY_PARSER_H_
-# define QUERY_PARSER_H_
-
-#include "bool.h"
-
-//! maximum length of target name
-#define MAX_LENOFTARGET 128
-
-//! maximum length of target identifier
-#define MAX_LENOFTID 30
-
-//! maximum length of channel identifier
-#define MAX_LENOFCID 30
-
-//! maximum number of closing channel
-#define MAX_NUMOFCCLOSE 10
-
-//! maximum number of meta request box
-#define MAX_NUMOFBOX 10
-
-//! image return type
-typedef enum image_return { JPPstream, JPTstream, UNKNOWN=-1} image_return_t;
-
-//! Query parameters
-typedef struct query_param{
- char target[MAX_LENOFTARGET]; //!< target name
- char tid[MAX_LENOFTID]; //!< target identifier
- int fx, fy; //!< frame size (fx,fy)
- int rx, ry, rw, rh; //!< roi region
- int layers; //!< quality layers
- int lastcomp; //!< last component number
- bool *comps; //!< components for jpp-stream, null means all components
- char cid[MAX_LENOFCID]; //!< channel identifier
- bool cnew; //!< if there is new channel request(true) or not (false)
- char cclose[MAX_NUMOFCCLOSE][MAX_LENOFCID]; //!< closing channel identifiers
- char box_type[MAX_NUMOFBOX][4]; //!< interested box-types
- int limit[MAX_NUMOFBOX]; //!< limit value, -1: skeleton request "r", 0: entire contents
- bool w[MAX_NUMOFBOX]; //!< Metadata request qualifier flags
- bool s[MAX_NUMOFBOX];
- bool g[MAX_NUMOFBOX];
- bool a[MAX_NUMOFBOX];
- bool priority[MAX_NUMOFBOX]; //!< priority flag
- int root_bin; //!< root-bin
- int max_depth; //!< max-depth
- bool metadata_only; //!< metadata-only request
- image_return_t return_type; //!< image return type
- int len; //!< maximum response length
-} query_param_t;
-
-
-/**
- * parse query
- *
- * @param[in] query_string request query string
- * @param[out] query_param query parameters
- */
-void parse_query( char *query_string, query_param_t *query_param);
-
-/**
- * print query parameters
- *
- * @param[in] query_param query parameters
- */
-void print_queryparam( query_param_t query_param);
-
-#endif /* !QUERY_PARSER_H_ */
+++ /dev/null
-/*
- * $Id: session_manager.c 44 2011-02-15 12:32:29Z kaori $
- *
- * 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.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include "session_manager.h"
-#include "target_manager.h"
-
-#ifdef SERVER
-#include "fcgi_stdio.h"
-#define logstream FCGI_stdout
-#else
-#define FCGI_stdout stdout
-#define FCGI_stderr stderr
-#define logstream stderr
-#endif //SERVER
-
-
-sessionlist_param_t * gene_sessionlist()
-{
- sessionlist_param_t *sessionlist;
-
- sessionlist = (sessionlist_param_t *)malloc( sizeof(sessionlist_param_t));
-
- sessionlist->first = NULL;
- sessionlist->last = NULL;
-
- return sessionlist;
-}
-
-session_param_t * gene_session( sessionlist_param_t *sessionlist)
-{
- session_param_t *session;
-
- session = (session_param_t *)malloc( sizeof(session_param_t));
-
- session->channellist = gene_channellist();
- session->cachemodellist = gene_cachemodellist();
-
- session->next = NULL;
-
- if( sessionlist->first) // there are one or more entries
- sessionlist->last->next = session;
- else // first entry
- sessionlist->first = session;
- sessionlist->last = session;
-
- return session;
-}
-
-bool search_session_and_channel( char cid[],
- sessionlist_param_t *sessionlist,
- session_param_t **foundsession,
- channel_param_t **foundchannel)
-{
- *foundsession = sessionlist->first;
-
- while( *foundsession != NULL){
-
- *foundchannel = (*foundsession)->channellist->first;
-
- while( *foundchannel != NULL){
-
- if( strcmp( cid, (*foundchannel)->cid) == 0)
- return true;
-
- *foundchannel = (*foundchannel)->next;
- }
- *foundsession = (*foundsession)->next;
- }
-
- fprintf( FCGI_stdout, "Status: 503\r\n");
- fprintf( FCGI_stdout, "Reason: Channel %s not found\r\n", cid);
-
- return false;
-}
-
-void insert_cachemodel_into_session( session_param_t *session, cachemodel_param_t *cachemodel)
-{
- if(!cachemodel)
- return;
-
-#ifndef SERVER
- fprintf( logstream, "local log: insert cachemodel into session\n");
-#endif
- if( session->cachemodellist->first != NULL)
- session->cachemodellist->last->next = cachemodel;
- else
- session->cachemodellist->first = cachemodel;
- session->cachemodellist->last = cachemodel;
-}
-
-bool delete_session( session_param_t **session, sessionlist_param_t *sessionlist)
-{
- session_param_t *ptr;
-
- if( *session == NULL)
- return false;
-
-
- if( *session == sessionlist->first)
- sessionlist->first = (*session)->next;
- else{
- ptr = sessionlist->first;
- while( ptr->next != *session)
- ptr = ptr->next;
- ptr->next = (*session)->next;
-
- if( *session == sessionlist->last)
- sessionlist->last = ptr;
- }
-
- delete_channellist( &((*session)->channellist));
- delete_cachemodellist( &((*session)->cachemodellist));
-
-#ifndef SERVER
- fprintf( logstream, "local log: session: %p deleted!\n", (void *)(*session));
-#endif
- free( *session);
-
- return true;
-}
-
-void delete_sessionlist( sessionlist_param_t **sessionlist)
-{
- session_param_t *sessionPtr, *sessionNext;
-
- sessionPtr = (*sessionlist)->first;
- while( sessionPtr != NULL){
- sessionNext=sessionPtr->next;
-
- delete_channellist( &(sessionPtr->channellist));
- delete_cachemodellist( &(sessionPtr->cachemodellist));
-
-#ifndef SERVER
- fprintf( logstream, "local log: session: %p deleted!\n", (void *)sessionPtr);
-#endif
- free( sessionPtr);
-
- sessionPtr=sessionNext;
- }
-
- (*sessionlist)->first = NULL;
- (*sessionlist)->last = NULL;
-
- free(*sessionlist);
-}
-
-void print_allsession( sessionlist_param_t *sessionlist)
-{
- session_param_t *ptr;
- cachemodel_param_t *cachemodel;
- int i=0;
-
- fprintf( logstream, "SESSIONS info:\n");
-
- ptr = sessionlist->first;
- while( ptr != NULL){
- fprintf( logstream, "session No.%d\n", i++);
- print_allchannel( ptr->channellist);
- cachemodel = ptr->cachemodellist->first;
- while( cachemodel){
- print_target( cachemodel->target);
- cachemodel = cachemodel->next;
- }
- ptr=ptr->next;
- }
-}
+++ /dev/null
-/*
- * $Id: session_manager.h 53 2011-05-09 16:55:39Z kaori $
- *
- * 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.
- */
-
-#ifndef SESSION_MANAGER_H_
-# define SESSION_MANAGER_H_
-
-#include "bool.h"
-#include "channel_manager.h"
-#include "cachemodel_manager.h"
-
-//! Session parameters
-typedef struct session_param{
- channellist_param_t *channellist; //!< channel list pointer
- cachemodellist_param_t *cachemodellist; //!< cache list pointer
- struct session_param *next; //!< pointer to the next session
-} session_param_t;
-
-//! Session list parameters
-typedef struct sessionlist_param{
- session_param_t *first; //!< first session pointer of the list
- session_param_t *last; //!< last session pointer of the list
-} sessionlist_param_t;
-
-
-/**
- * generate a session list
- *
- * @return pointer to the generated session list
- */
-sessionlist_param_t * gene_sessionlist();
-
-
-/**
- * generate a session under the sesion list
- *
- * @param[in] sessionlist session list to insert the new session
- * @return pointer to the generated session
- */
-session_param_t * gene_session( sessionlist_param_t *sessionlist);
-
-/**
- * search a channel and its belonging session by channel ID
- *
- * @param[in] cid channel identifier
- * @param[in] sessionlist session list pointer
- * @param[in,out] foundsession address of the found session pointer
- * @param[in,out] foundchannel address of the found channel pointer
- * @return if the channel is found (true) or not (false)
- */
-bool search_session_and_channel( char cid[],
- sessionlist_param_t *sessionlist,
- session_param_t **foundsession,
- channel_param_t **foundchannel);
-
-/**
- * insert a cache model into a session
- *
- * @param[in] session session pointer
- * @param[in] cachemodel cachemodel pointer
- */
-void insert_cachemodel_into_session( session_param_t *session, cachemodel_param_t *cachemodel);
-
-
-/**
- * delete a session
- *
- * @param[in] session address of the session pointer
- * @param[in] sessionlist session list pointer
- * @return if succeeded (true) or failed (false)
- */
-bool delete_session( session_param_t **session, sessionlist_param_t *sessionlist);
-
-
-/**
- * delete session list
- *
- * @param[in,out] sessionlist address of the session list pointer
- */
-void delete_sessionlist( sessionlist_param_t **sessionlist);
-
-/**
- * print all sessions
- *
- * @param[in] sessionlist session list pointer
- */
-void print_allsession( sessionlist_param_t *sessionlist);
-
-
-#endif /* !SESSION_MANAGER_H_ */
+++ /dev/null
-
-INCLUDE_DIRECTORIES(
- ../libopenjpip
-)
-
-ADD_EXECUTABLE(jpip_to_j2k jpip_to_j2k.c)
-TARGET_LINK_LIBRARIES(jpip_to_j2k openjpip_local)
-IF(UNIX)
- TARGET_LINK_LIBRARIES(jpip_to_j2k m)
-ENDIF(UNIX)
-# Install exe
-INSTALL(TARGETS jpip_to_j2k
- EXPORT OpenJPEGTargets
- DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
-)
-
-ADD_EXECUTABLE(jpip_to_jp2 jpip_to_jp2.c)
-TARGET_LINK_LIBRARIES(jpip_to_jp2 openjpip_local)
-IF(UNIX)
- TARGET_LINK_LIBRARIES(jpip_to_jp2 m)
-ENDIF(UNIX)
-# Install exe
-INSTALL(TARGETS jpip_to_jp2
- EXPORT OpenJPEGTargets
- DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
-)
-
-ADD_EXECUTABLE(test_index test_index.c)
-TARGET_LINK_LIBRARIES(test_index openjpip_local)
-IF(UNIX)
- TARGET_LINK_LIBRARIES(test_index m)
-ENDIF(UNIX)
-# Install exe
-INSTALL(TARGETS test_index
- EXPORT OpenJPEGTargets
- DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
-)
+++ /dev/null
-MAINTAINERCLEANFILES = Makefile.in\r
-\r
-bin_PROGRAMS = jpip_to_jp2 jpip_to_j2k test_index addXMLinJP2\r
-\r
-jpip_to_jp2_CPPFLAGS = \\r
--I. \\r
--I$(top_srcdir)/applications/jpip/libopenjpip \\r
--I$(top_builddir)/applications/jpip/libopenjpip \\r
--I$(top_srcdir)/applications/jpip/libopenjpip/tools \\r
--I$(top_builddir)/applications/jpip/libopenjpip/tools\r
-jpip_to_jp2_CFLAGS = \r
-jpip_to_jp2_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_local.la\r
-jpip_to_jp2_SOURCES = jpip_to_jp2.c\r
-\r
-jpip_to_j2k_CPPFLAGS = \\r
--I. \\r
--I$(top_srcdir)/applications/jpip/libopenjpip \\r
--I$(top_builddir)/applications/jpip/libopenjpip \\r
--I$(top_srcdir)/applications/jpip/libopenjpip/tools \\r
--I$(top_builddir)/applications/jpip/libopenjpip/tools\r
-jpip_to_j2k_CFLAGS = \r
-jpip_to_j2k_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_local.la\r
-jpip_to_j2k_SOURCES = jpip_to_j2k.c\r
-\r
-test_index_CPPFLAGS = \\r
--I. \\r
--I$(top_srcdir)/applications/jpip/libopenjpip \\r
--I$(top_builddir)/applications/jpip/libopenjpip \\r
--I$(top_srcdir)/applications/jpip/libopenjpip/tools \\r
--I$(top_builddir)/applications/jpip/libopenjpip/tools\r
-test_index_CFLAGS = \r
-test_index_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_local.la\r
-test_index_SOURCES = test_index.c\r
-\r
-addXMLinJP2_CPPFLAGS = \\r
--I. \\r
--I$(top_srcdir)/applications/jpip/libopenjpip/tools \\r
--I$(top_builddir)/applications/jpip/libopenjpip/tools\r
-addXMLinJP2_CFLAGS = \r
-addXMLinJP2_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_local.la\r
-addXMLinJP2_SOURCES = addXMLinJP2.c\r
-\r
-install-data-hook:\r
- @echo -e " (B)\t$(bindir)/jpip_to_jp2$(EXEEXT)" >> $(top_builddir)/report.txt\r
- @echo -e " (B)\t$(bindir)/jpip_to_j2k$(EXEEXT)" >> $(top_builddir)/report.txt\r
- @echo -e " (B)\t$(bindir)/test_index$(EXEEXT)" >> $(top_builddir)/report.txt\r
- @echo -e " (B)\t$(bindir)/addXMLinJP2$(EXEEXT)" >> $(top_builddir)/report.txt\r
+++ /dev/null
-LIBDIR = ../libopenjpip
-LIBFNAME = $(LIBDIR)/libopenjpip_local.a
-CFLAGS = -O3 -Wall -I$(LIBDIR)
-LDFLAGS = -L$(LIBDIR) -lm -lopenjpip_local
-
-ALL = jpip_to_jp2 jpip_to_j2k test_index addXMLinJP2
-
-all: $(ALL)
-
-jpip_to_jp2: jpip_to_jp2.o $(LIBFNAME)
- $(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
-
-jpip_to_j2k: jpip_to_j2k.o $(LIBFNAME)
- $(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
-
-test_index: test_index.o $(LIBFNAME)
- $(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
-
-clean:
- rm -f $(ALL) *.o *~
+++ /dev/null
-/*
- * $Id: addXMLinJP2.c 46 2011-02-17 14:50:55Z kaori $
- *
- * 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.
- */
-
-/*! \file
- * \brief addXMLinJP2 is a program to embed metadata into JP2 file
- *
- * \section impinst Implementing instructions
- * This program takes two arguments. \n
- * -# Input/output image file in JP2 format, this JP2 file is being modified
- * -# Input XML file with metadata contents\n
- * % ./addXMLinJP2 image.jp2 metadata.xml\n
- *
- * Currently, this program does not parse XML file, and the XML file contents is directly embedded as a XML Box.\n
- * The following is an example of XML file contents specifying Region Of Interests with target names.\n
- * <xmlbox>\n
- * <roi name="island" x="1890" y="1950" w="770" h="310"/>\n
- * <roi name="ship" x="750" y="330" w="100" h="60"/>\n
- * <roi name="airport" x="650" y="1800" w="650" h="800"/>\n
- * <roi name="harbor" x="4200" y="1650" w="130" h="130"/>\n
- * </xmlbox>
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-/**
- * Open JP2 file with the check of JP2 header
- *
- * @param[in] filename file name string
- * @return file descriptor
- */
-FILE * open_jp2file( char filename[]);
-
-
-/**
- * read xml file without any format check for the moment
- *
- * @param[in] filename file name string
- * @param[out] fsize file byte size
- * @return pointer to the xml file content buffer
- */
-char * read_xmlfile( char filename[], long *fsize);
-
-int main(int argc, char *argv[])
-{
- if( argc<3){
- fprintf( stderr, "USAGE: ./addXMLinJP2 modifing.jp2 adding.xml\n");
- return -1;
- }
-
- FILE *fp;
- char *xmldata, type[]="xml ";
- long fsize, boxsize;
-
- fp = open_jp2file( argv[1]);
- if( !fp)
- return -1;
-
- xmldata = read_xmlfile( argv[2], &fsize);
- boxsize = fsize + 8;
-
- fputc( (boxsize>>24)&0xff, fp);
- fputc( (boxsize>>16)&0xff, fp);
- fputc( (boxsize>>8)&0xff, fp);
- fputc( boxsize&0xff, fp);
- fwrite( type, 4, 1, fp);
- fwrite( xmldata, fsize, 1, fp);
-
- free( xmldata);
- fclose(fp);
-
- return 0;
-}
-
-FILE * open_jp2file( char filename[])
-{
- FILE *fp;
- char *data;
-
- if( !(fp = fopen( filename, "a+b"))){
- fprintf( stderr, "Original JP2 %s not found\n", filename);
- return NULL;
- }
- // Check resource is a JP family file.
- if( fseek( fp, 0, SEEK_SET)==-1){
- fclose(fp);
- fprintf( stderr, "Original JP2 %s broken (fseek error)\n", filename);
- return NULL;
- }
-
- data = (char *)malloc( 12); // size of header
- if( fread( data, 12, 1, fp) != 1){
- free( data);
- fclose(fp);
- fprintf( stderr, "Original JP2 %s broken (read error)\n", filename);
- return NULL;
- }
-
- if( *data || *(data + 1) || *(data + 2) ||
- *(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
- free( data);
- fclose(fp);
- fprintf( stderr, "No JPEG 2000 Signature box in target %s\n", filename);
- return NULL;
- }
- free( data);
- return fp;
-}
-
-char * read_xmlfile( char filename[], long *fsize)
-{
- FILE *fp;
- char *data;
-
- // fprintf( stderr, "open %s\n", filename);
- if(!(fp = fopen( filename, "r"))){
- fprintf( stderr, "XML file %s not found\n", filename);
- return NULL;
- }
-
- if( fseek( fp, 0, SEEK_END) == -1){
- fprintf( stderr, "XML file %s broken (seek error)\n", filename);
- fclose( fp);
- return NULL;
- }
-
- if( (*fsize = ftell( fp)) == -1){
- fprintf( stderr, "XML file %s broken (seek error)\n", filename);
- fclose( fp);
- return NULL;
- }
-
- if( fseek( fp, 0, SEEK_SET) == -1){
- fprintf( stderr, "XML file %s broken (seek error)\n", filename);
- fclose( fp);
- return NULL;
- }
-
- data = (char *)malloc( *fsize);
-
- if( fread( data, *fsize, 1, fp) != 1){
- fprintf( stderr, "XML file %s broken (read error)\n", filename);
- free( data);
- fclose(fp);
- return NULL;
- }
-
- fclose( fp);
-
- return data;
-}
+++ /dev/null
-/*
- * $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.
- */
-
-/*! \file
- * \brief jpip_to_j2k is a program to convert JPT- JPP- stream to J2K file
- *
- * \section impinst Implementing instructions
- * This program takes two arguments. \n
- * -# Input JPT or JPP file
- * -# Output J2K file\n
- * % ./jpip_to_j2k input.jpt output.j2k
- * or
- * % ./jpip_to_j2k input.jpp output.j2k
- */
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include "msgqueue_manager.h"
-#include "jp2k_encoder.h"
-
-int main(int argc,char *argv[])
-{
- msgqueue_param_t *msgqueue;
- int infd, outfd;
- Byte8_t jpiplen, j2klen;
- struct stat sb;
- Byte_t *jpipstream, *j2kstream;
-
- if( argc < 3){
- fprintf( stderr, "Too few arguments:\n");
- fprintf( stderr, " - input jpt or jpp file\n");
- fprintf( stderr, " - output j2k file\n");
- return -1;
- }
-
- if(( infd = open( argv[1], O_RDONLY)) == -1){
- fprintf( stderr, "file %s not exist\n", argv[1]);
- return -1;
- }
-
- if( fstat( infd, &sb) == -1){
- fprintf( stderr, "input file stream is broken\n");
- return -1;
- }
- jpiplen = (Byte8_t)sb.st_size;
-
- jpipstream = (Byte_t *)malloc( jpiplen);
-
- if( read( infd, jpipstream, jpiplen) != jpiplen){
- fprintf( stderr, "file reading error\n");
- free( jpipstream);
- return -1;
- }
- close(infd);
-
- msgqueue = gene_msgqueue( true, NULL);
- parse_JPIPstream( jpipstream, jpiplen, 0, msgqueue);
-
- //print_msgqueue( msgqueue);
-
- // arguments fw, fh need to be set for LRCP, PCRL, CPRL
- j2kstream = recons_j2k( msgqueue, jpipstream, msgqueue->first->csn, 0, 0, &j2klen);
-
- delete_msgqueue( &msgqueue);
- free( jpipstream);
-
-#ifdef _WIN32
- if(( outfd = open( argv[2], O_WRONLY|O_CREAT, _S_IREAD | _S_IWRITE)) == -1){
-#else
- if(( outfd = open( argv[2], O_WRONLY|O_CREAT, S_IRWXU|S_IRWXG)) == -1){
-#endif
- fprintf( stderr, "file %s open error\n", argv[2]);
- return -1;
- }
-
- if( write( outfd, j2kstream, j2klen) != j2klen)
- fprintf( stderr, "j2k file write error\n");
-
- free( j2kstream);
- close(outfd);
-
- return 0;
-}
+++ /dev/null
-/*
- * $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.
- */
-
-/*! \file
- * \brief jpip_to_jp2 is a program to convert JPT- JPP- stream to JP2 file
- *
- * \section impinst Implementing instructions
- * This program takes two arguments. \n
- * -# Input JPT or JPP file
- * -# Output JP2 file\n
- * % ./jpip_to_jp2 input.jpt output.jp2
- * or
- * % ./jpip_to_jp2 input.jpp output.jp2
- */
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include "msgqueue_manager.h"
-#include "byte_manager.h"
-#include "ihdrbox_manager.h"
-#include "metadata_manager.h"
-#include "jp2k_encoder.h"
-
-int main(int argc,char *argv[])
-{
- msgqueue_param_t *msgqueue;
- int infd, outfd;
- Byte8_t jpiplen, jp2len;
- struct stat sb;
- Byte_t *jpipstream, *jp2stream;
- metadatalist_param_t *metadatalist;
- ihdrbox_param_t *ihdrbox;
-
- if( argc < 3){
- fprintf( stderr, "Too few arguments:\n");
- fprintf( stderr, " - input jpt or jpp file\n");
- fprintf( stderr, " - output jp2 file\n");
- return -1;
- }
-
- if(( infd = open( argv[1], O_RDONLY)) == -1){
- fprintf( stderr, "file %s not exist\n", argv[1]);
- return -1;
- }
-
- if( fstat( infd, &sb) == -1){
- fprintf( stderr, "input file stream is broken\n");
- return -1;
- }
- jpiplen = (Byte8_t)sb.st_size;
-
- jpipstream = (Byte_t *)malloc( jpiplen);
-
- if( read( infd, jpipstream, jpiplen) != jpiplen){
- fprintf( stderr, "file reading error\n");
- free( jpipstream);
- return -1;
- }
- close(infd);
-
- metadatalist = gene_metadatalist();
- msgqueue = gene_msgqueue( true, NULL);
- parse_JPIPstream( jpipstream, jpiplen, 0, msgqueue);
- parse_metamsg( msgqueue, jpipstream, jpiplen, metadatalist);
- print_msgqueue( msgqueue);
- //print_allmetadata( metadatalist);
-
- ihdrbox = gene_ihdrbox( metadatalist, jpipstream);
-
- printf("W*H: %d*%d\n", ihdrbox->height, ihdrbox->width);
- printf("NC: %d, bpc: %d\n", ihdrbox->nc, ihdrbox->bpc);
-
- jp2stream = recons_jp2( msgqueue, jpipstream, msgqueue->first->csn, &jp2len);
-
-#ifdef _WIN32
- if(( outfd = open( argv[2], O_WRONLY|O_CREAT, _S_IREAD | _S_IWRITE)) == -1){
-#else
- if(( outfd = open( argv[2], O_WRONLY|O_CREAT, S_IRWXU|S_IRWXG)) == -1){
-#endif
- fprintf( stderr, "file %s open error\n", argv[2]);
- return -1;
- }
-
- if( write( outfd, jp2stream, jp2len) != jp2len)
- fprintf( stderr, "jp2 file write error\n");
-
- //print_msgqueue( msgqueue);
-
- free( ihdrbox);
- free( jp2stream);
- close(outfd);
-
- delete_msgqueue( &msgqueue);
- delete_metadatalist( &metadatalist);
-
- free( jpipstream);
-
- return 0;
-}
+++ /dev/null
-/*
- * $Id: test_index.c 46 2011-02-17 14:50:55Z kaori $
- *
- * 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.
- */
-
-/*! \file
- * \brief test_index is a program to test the index code format of a JP2 file
- *
- * \section impinst Implementing instructions
- * This program takes one argument, and print out text type index information to the terminal. \n
- * -# Input JP2 file\n
- * % ./test_index input.jp2\n
- */
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include "index_manager.h"
-
-
-#ifdef SERVER
-#include "fcgi_stdio.h"
-#define logstream FCGI_stdout
-#else
-#define FCGI_stdout stdout
-#define FCGI_stderr stderr
-#define logstream stderr
-#endif //SERVER
-
-
-/**
- * Open JP2 file with the check of JP2 header
- *
- * @param[in] filename file name string
- * @return file descriptor
- */
-int myopen_jp2file( char filename[]);
-
-
-int
-main(int argc, char *argv[])
-{
- int fd;
- index_param_t *jp2idx;
-
- if((fd = myopen_jp2file( argv[1])) == -1){
- fprintf( stderr, "jp2 file open error\n");
- return -1;
- }
-
- if( !(jp2idx = parse_jp2file( fd))){
- fprintf( FCGI_stdout, "Status: 501\r\n");
- return -1;
- }
-
- print_index( *jp2idx);
-
- delete_index( &jp2idx);
-
- return 0;
-} /* main */
-
-
-
-int myopen_jp2file( char filename[])
-{
- int fd;
- char *data;
-
- if( (fd = open( filename, O_RDONLY)) == -1){
- fprintf( FCGI_stdout, "Reason: Target %s not found\r\n", filename);
- return -1;
- }
- // Check resource is a JP family file.
- if( lseek( fd, 0, SEEK_SET)==-1){
- close(fd);
- fprintf( FCGI_stdout, "Reason: Target %s broken (lseek error)\r\n", filename);
- return -1;
- }
-
- data = (char *)malloc( 12); // size of header
- if( read( fd, data, 12) != 12){
- free( data);
- close(fd);
- fprintf( FCGI_stdout, "Reason: Target %s broken (read error)\r\n", filename);
- return -1;
- }
-
- if( *data || *(data + 1) || *(data + 2) ||
- *(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
- free( data);
- close(fd);
- fprintf( FCGI_stdout, "Reason: No JPEG 2000 Signature box in target %s\r\n", filename);
- return -1;
- }
- free( data);
- return fd;
-}
-
--- /dev/null
+# Headers file are located here:
+INCLUDE_DIRECTORIES(
+ ${OPENJPEG_SOURCE_DIR}/applications/jpip/libopenjpip
+ ${FCGI_INCLUDE_DIRNAME}
+)
+
+SET(OPJ_SERVER_SRCS
+${CMAKE_CURRENT_SOURCE_DIR}/opj_server.c
+)
+
+# Build executable
+ADD_DEFINITIONS(-DSERVER -DQUIT_SIGNAL="quitJPIP")
+#
+ADD_EXECUTABLE(opj_server ${OPJ_SERVER_SRCS})
+TARGET_LINK_LIBRARIES(opj_server openjpip_server ${FCGI_LIBNAME})
+
+# On unix you need to link to the math library:
+IF(UNIX)
+ TARGET_LINK_LIBRARIES(opj_server m)
+ENDIF(UNIX)
+
+# Install exe
+ INSTALL(TARGETS opj_server
+ EXPORT OpenJPEGTargets
+ DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
+ )
+#
+REMOVE_DEFINITIONS(-DSERVER -DQUIT_SIGNAL="quitJPIP")
+#
+FOREACH(exe opj_dec_server jpip_to_jp2 jpip_to_j2k test_index)
+#
+ ADD_EXECUTABLE(${exe} ${exe}.c)
+ TARGET_LINK_LIBRARIES(${exe} openjpip_local)
+ INSTALL(TARGETS ${exe}
+ EXPORT OpenJPEGTargets
+ DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
+ )
+ENDFOREACH(exe)
--- /dev/null
+MAINTAINERCLEANFILES = Makefile.in
+
+bin_PROGRAMS = opj_server opj_dec_server jpip_to_jp2 jpip_to_j2k test_index
+
+opj_server_CPPFLAGS = \
+@FCGI_CFLAGS@ \
+-I. \
+-I$(top_srcdir)/applications/jpip/libopenjpip \
+-I$(top_builddir)/applications/jpip/libopenjpip
+#
+opj_server_CFLAGS = -DServer -DQUIT_SIGNAL=\"quitJPIP\"
+#
+opj_server_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_server.la @FCGI_LIBS@ -lm
+#
+opj_server_SOURCES = \
+opj_server.c
+#-------------
+opj_dec_server_CPPFLAGS = \
+-I. \
+-I$(top_srcdir)/applications/jpip/libopenjpip \
+-I$(top_builddir)/applications/jpip/libopenjpip
+#
+opj_dec_server_CFLAGS =
+opj_dec_server_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_local.la
+opj_dec_server_SOURCES = opj_dec_server.c
+#-------------
+jpip_to_jp2_CPPFLAGS = \
+-I. \
+-I$(top_srcdir)/applications/jpip/libopenjpip \
+-I$(top_builddir)/applications/jpip/libopenjpip
+#
+jpip_to_jp2_CFLAGS =
+jpip_to_jp2_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_local.la
+jpip_to_jp2_SOURCES = jpip_to_jp2.c
+#-------------
+jpip_to_j2k_CPPFLAGS = \
+-I. \
+-I$(top_srcdir)/applications/jpip/libopenjpip \
+-I$(top_builddir)/applications/jpip/libopenjpip
+#
+jpip_to_j2k_CFLAGS =
+jpip_to_j2k_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_local.la
+jpip_to_j2k_SOURCES = jpip_to_j2k.c
+#-------------
+test_index_CPPFLAGS = \
+-I. \
+-I$(top_srcdir)/applications/jpip/libopenjpip \
+-I$(top_builddir)/applications/jpip/libopenjpip
+#
+test_index_CFLAGS =
+test_index_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_local.la
+test_index_SOURCES = test_index.c
+#-------------
+install-data-hook:
+ @echo -e " (B)\t$(bindir)/opj_server$(EXEEXT)" >> $(top_builddir)/report.txt
+ @echo -e " (B)\t$(bindir)/opj_dec_server$(EXEEXT)" >> $(top_builddir)/report.txt
+ @echo -e " (B)\t$(bindir)/jpip_to_jp2$(EXEEXT)" >> $(top_builddir)/report.txt
+ @echo -e " (B)\t$(bindir)/jpip_to_j2k$(EXEEXT)" >> $(top_builddir)/report.txt
+ @echo -e " (B)\t$(bindir)/test_index$(EXEEXT)" >> $(top_builddir)/report.txt
--- /dev/null
+JPIPLIBDIR = ../libopenjpip
+
+SLIBFNAME = $(JPIPLIBDIR)/libopenjpip_server.a
+SCFLAGS = -O3 -Wall -m32 -I$(JPIPLIBDIR) -DSERVER -DQUIT_SIGNAL=\"quitJPIP\"
+SLDFLAGS = -L$(JPIPLIBDIR) -lm -lfcgi -lopenjpip_server
+
+J2KINCDIR = ../../../libopenjpeg
+J2KLIBDIR = $(J2KINCDIR)/.libs
+LIBFNAME = $(JPIPLIBDIR)/libopenjpip_local.a $(J2KLIBDIR)/libopenjpeg.a
+CFLAGS = -O3 -Wall -I$(JPIPLIBDIR)
+LDFLAGS = -L$(JPIPLIBDIR) -L$(J2KLIBDIR) -lm -lopenjpip_local
+
+ALL = opj_server opj_dec_server jpip_to_jp2 jpip_to_j2k test_index addXMLinJP2
+
+all: $(ALL)
+
+opj_server: opj_server.c $(SLIBFNAME)
+ $(CC) $(SCFLAGS) $< $(SLDFLAGS) $(SLIBFNAME) -o $@
+
+opj_dec_server: opj_dec_server.c $(LIBFNAME)
+ $(CC) $(CFLAGS) $< $(LDFLAGS) $(LIBFNAME) -o $@
+
+jpip_to_jp2: jpip_to_jp2.c $(LIBFNAME)
+ $(CC) $(CFLAGS) $< $(LDFLAGS) $(LIBFNAME) -o $@
+
+jpip_to_j2k: jpip_to_j2k.c $(LIBFNAME)
+ $(CC) $(CFLAGS) $< $(LDFLAGS) $(LIBFNAME) -o $@
+
+test_index: test_index.c $(LIBFNAME)
+ $(CC) $(CFLAGS) $< $(LDFLAGS) $(LIBFNAME) -o $@
+
+clean:
+ rm -f $(ALL) *.o *~
--- /dev/null
+/*
+ * $Id: addXMLinJP2.c 46 2011-02-17 14:50:55Z kaori $
+ *
+ * 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.
+ */
+
+/*! \file
+ * \brief addXMLinJP2 is a program to embed metadata into JP2 file
+ *
+ * \section impinst Implementing instructions
+ * This program takes two arguments. \n
+ * -# Input/output image file in JP2 format, this JP2 file is being modified
+ * -# Input XML file with metadata contents\n
+ * % ./addXMLinJP2 image.jp2 metadata.xml\n
+ *
+ * Currently, this program does not parse XML file, and the XML file contents is directly embedded as a XML Box.\n
+ * The following is an example of XML file contents specifying Region Of Interests with target names.\n
+ * <xmlbox>\n
+ * <roi name="island" x="1890" y="1950" w="770" h="310"/>\n
+ * <roi name="ship" x="750" y="330" w="100" h="60"/>\n
+ * <roi name="airport" x="650" y="1800" w="650" h="800"/>\n
+ * <roi name="harbor" x="4200" y="1650" w="130" h="130"/>\n
+ * </xmlbox>
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/**
+ * Open JP2 file with the check of JP2 header
+ *
+ * @param[in] filename file name string
+ * @return file descriptor
+ */
+FILE * open_jp2file( char filename[]);
+
+
+/**
+ * read xml file without any format check for the moment
+ *
+ * @param[in] filename file name string
+ * @param[out] fsize file byte size
+ * @return pointer to the xml file content buffer
+ */
+char * read_xmlfile( char filename[], long *fsize);
+
+int main(int argc, char *argv[])
+{
+ if( argc<3){
+ fprintf( stderr, "USAGE: ./addXMLinJP2 modifing.jp2 adding.xml\n");
+ return -1;
+ }
+
+ FILE *fp;
+ char *xmldata, type[]="xml ";
+ long fsize, boxsize;
+
+ fp = open_jp2file( argv[1]);
+ if( !fp)
+ return -1;
+
+ xmldata = read_xmlfile( argv[2], &fsize);
+ boxsize = fsize + 8;
+
+ fputc( (boxsize>>24)&0xff, fp);
+ fputc( (boxsize>>16)&0xff, fp);
+ fputc( (boxsize>>8)&0xff, fp);
+ fputc( boxsize&0xff, fp);
+ fwrite( type, 4, 1, fp);
+ fwrite( xmldata, fsize, 1, fp);
+
+ free( xmldata);
+ fclose(fp);
+
+ return 0;
+}
+
+FILE * open_jp2file( char filename[])
+{
+ FILE *fp;
+ char *data;
+
+ if( !(fp = fopen( filename, "a+b"))){
+ fprintf( stderr, "Original JP2 %s not found\n", filename);
+ return NULL;
+ }
+ // Check resource is a JP family file.
+ if( fseek( fp, 0, SEEK_SET)==-1){
+ fclose(fp);
+ fprintf( stderr, "Original JP2 %s broken (fseek error)\n", filename);
+ return NULL;
+ }
+
+ data = (char *)malloc( 12); // size of header
+ if( fread( data, 12, 1, fp) != 1){
+ free( data);
+ fclose(fp);
+ fprintf( stderr, "Original JP2 %s broken (read error)\n", filename);
+ return NULL;
+ }
+
+ if( *data || *(data + 1) || *(data + 2) ||
+ *(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
+ free( data);
+ fclose(fp);
+ fprintf( stderr, "No JPEG 2000 Signature box in target %s\n", filename);
+ return NULL;
+ }
+ free( data);
+ return fp;
+}
+
+char * read_xmlfile( char filename[], long *fsize)
+{
+ FILE *fp;
+ char *data;
+
+ // fprintf( stderr, "open %s\n", filename);
+ if(!(fp = fopen( filename, "r"))){
+ fprintf( stderr, "XML file %s not found\n", filename);
+ return NULL;
+ }
+
+ if( fseek( fp, 0, SEEK_END) == -1){
+ fprintf( stderr, "XML file %s broken (seek error)\n", filename);
+ fclose( fp);
+ return NULL;
+ }
+
+ if( (*fsize = ftell( fp)) == -1){
+ fprintf( stderr, "XML file %s broken (seek error)\n", filename);
+ fclose( fp);
+ return NULL;
+ }
+
+ if( fseek( fp, 0, SEEK_SET) == -1){
+ fprintf( stderr, "XML file %s broken (seek error)\n", filename);
+ fclose( fp);
+ return NULL;
+ }
+
+ data = (char *)malloc( *fsize);
+
+ if( fread( data, *fsize, 1, fp) != 1){
+ fprintf( stderr, "XML file %s broken (read error)\n", filename);
+ free( data);
+ fclose(fp);
+ return NULL;
+ }
+
+ fclose( fp);
+
+ return data;
+}
--- /dev/null
+/*
+ * $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.
+ */
+
+/*! \file
+ * \brief jpip_to_j2k is a program to convert JPT- JPP- stream to J2K file
+ *
+ * \section impinst Implementing instructions
+ * This program takes two arguments. \n
+ * -# Input JPT or JPP file
+ * -# Output J2K file\n
+ * % ./jpip_to_j2k input.jpt output.j2k
+ * or
+ * % ./jpip_to_j2k input.jpp output.j2k
+ */
+
+#include <stdio.h>
+#include "openjpip.h"
+
+int main(int argc,char *argv[])
+{
+ jpip_dec_param_t *dec;
+
+ if( argc < 3){
+ fprintf( stderr, "Too few arguments:\n");
+ fprintf( stderr, " - input jpt or jpp file\n");
+ fprintf( stderr, " - output j2k file\n");
+ return -1;
+ }
+
+ dec = init_jpipdecoder( false);
+
+ if(!( fread_jpip( argv[1], dec)))
+ return -1;
+
+ decode_jpip( dec);
+
+ if(!( fwrite_jp2k( argv[2], dec)))
+ return -1;
+
+ output_log( true, false, false, dec);
+
+ destroy_jpipdecoder( &dec);
+
+ return 0;
+}
--- /dev/null
+/*
+ * $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.
+ */
+
+/*! \file
+ * \brief jpip_to_jp2 is a program to convert JPT- JPP- stream to JP2 file
+ *
+ * \section impinst Implementing instructions
+ * This program takes two arguments. \n
+ * -# Input JPT or JPP file
+ * -# Output JP2 file\n
+ * % ./jpip_to_jp2 input.jpt output.jp2
+ * or
+ * % ./jpip_to_jp2 input.jpp output.jp2
+ */
+
+#include <stdio.h>
+#include "openjpip.h"
+
+int main(int argc,char *argv[])
+{
+ jpip_dec_param_t *dec;
+
+ if( argc < 3){
+ fprintf( stderr, "Too few arguments:\n");
+ fprintf( stderr, " - input jpt or jpp file\n");
+ fprintf( stderr, " - output jp2 file\n");
+ return -1;
+ }
+
+ dec = init_jpipdecoder( true);
+
+ if(!( fread_jpip( argv[1], dec)))
+ return -1;
+
+ decode_jpip( dec);
+
+ if(!(fwrite_jp2k( argv[2], dec)))
+ return -1;
+
+ output_log( true, false, true, dec);
+
+ destroy_jpipdecoder( &dec);
+
+ return 0;
+}
--- /dev/null
+/*
+ * $Id: opj_dec_server.c 54 2011-05-10 13:22:47Z kaori $
+ *
+ * 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.
+ */
+
+/*! \file
+ * \brief opj_dec_server is a server to decode JPT-stream and communicate locally with JPIP client, which is coded in java.
+ *
+ * \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
+ * 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
+ * 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 "openjpip.h"
+
+#ifdef _WIN32
+WSADATA initialisation_win32;
+#endif
+
+int main(int argc, char *argv[]){
+
+ dec_server_record_t *server_record;
+ client_t client;
+
+#ifdef _WIN32
+ int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
+ if( erreur!=0)
+ fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
+ else
+ printf( "Initialisation Winsock\n");
+#endif //_WIN32
+
+ server_record = init_dec_server();
+
+ while(( client = accept_connection( server_record)) != -1 )
+ if(!handle_clientreq( client, server_record))
+ break;
+
+ terminate_dec_server( &server_record);
+
+#ifdef _WIN32
+ if( WSACleanup() != 0){
+ printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
+ }else{
+ printf("\nWSACleanup OK\n");
+ }
+#endif
+
+ return 0;
+}
--- /dev/null
+/*
+ * $Id: opj_server.c 53 2011-05-09 16:55:39Z kaori $
+ *
+ * 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
+ * Copyright (c) 2011, Lucian Corlaciu, GSoC
+ * 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.
+ */
+
+/*! \file
+ * \brief opj_server is a JPIP server program, which supports HTTP connection, JPT-stream, session, channels, and cache model managements.
+ *
+ * \section req Requirements
+ * FastCGI development kit (http://www.fastcgi.com).
+ *
+ * \section impinst Implementing instructions
+ * Launch opj_server from the server terminal:\n
+ * % spawn-fcgi -f ./opj_server -p 3000 -n
+ *
+ * Note: JP2 files are stored in the working directory of opj_server\n
+ * Check README for the JP2 Encoding\n
+ *
+ * We tested this software with a virtual server running on the same Linux machine as the clients.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "openjpip.h"
+
+#ifndef QUIT_SIGNAL
+#define QUIT_SIGNAL "quitJPIP"
+#endif
+
+int main(void)
+{
+ server_record_t *server_record;
+
+ server_record = init_JPIPserver();
+
+#ifdef SERVER
+
+ char *query_string;
+ while(FCGI_Accept() >= 0)
+#else
+
+ char query_string[128];
+ while( fgets( query_string, 128, stdin) && query_string[0]!='\n')
+#endif
+ {
+
+#ifdef SERVER
+ query_string = getenv("QUERY_STRING");
+#endif //SERVER
+
+ if( strcmp( query_string, QUIT_SIGNAL) == 0)
+ break;
+
+ QR_t *qr;
+ bool parse_status;
+
+ qr = parse_querystring( query_string);
+
+ if( !(parse_status = process_JPIPrequest( server_record, qr)))
+ fprintf( FCGI_stderr, "Error: JPIP request failed\n");
+
+#ifndef SERVER
+ local_log( true, true, parse_status, false, qr, server_record);
+#endif
+
+ fprintf( FCGI_stdout, "\r\n");
+
+ send_responsedata( qr);
+
+ end_QRprocess( server_record, &qr);
+ }
+
+ fprintf( FCGI_stderr, "JPIP server terminated by a client request\n");
+
+ terminate_JPIPserver( &server_record);
+
+ return 0;
+}
--- /dev/null
+<project name="opj_viewer" default="dist" basedir=".">
+ <description>OpenJPIP client image viewer</description>
+ <property name="src" location="src" />
+ <property name="build" location="build"/>
+ <property name="dist" location="dist" />
+
+ <target name="init">
+ <tstamp/>
+ <mkdir dir="${build}"/>
+ </target>
+ <target name="compile" depends="init">
+ <javac srcdir="${src}" destdir="${build}"/>
+ </target>
+ <target name="dist" depends="compile">
+ <mkdir dir="${dist}"/>
+ <jar jarfile="${dist}/opj_viewer-${DSTAMP}.jar"
+ basedir="${build}" manifest="${dist}/manifest.txt"/>
+ <exec dir="${dist}" executable="ln">
+ <arg line="-sf opj_viewer-${DSTAMP}.jar opj_viewer.jar"/>
+ </exec>
+ </target>
+ <target name="clean">
+ <delete dir="${build}"/>
+ <delete dir="${dist}"/>
+ </target>
+ <target name="test" depends="dist">
+ <exec executable="appletviewer"><arg line="dist.html"/></exec>
+ </target>
+ <target name="build_test" depends="compile">
+ <exec executable="appletviewer"><arg line="compile.html"/></exec>
+ </target>
+ <target name="build_testj" depends="compile">
+ <exec executable="java"><arg line="-classpath build ImageWindow girl"/></exec>
+ </target>
+</project>
--- /dev/null
+Manifest-Version: 1.0
+Ant-Version: Apache Ant 1.7.0
+Created-By: Kaori Hagihara
+Main-Class: ImageWindow
--- /dev/null
+opj_viewer-20111026.jar
\ No newline at end of file
--- /dev/null
+/*
+ * $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
--- /dev/null
+/*
+ * $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.*;
+import java.awt.event.*;
+import javax.swing.*;
+import java.awt.image.*;
+import java.awt.geom.*;
+import java.net.URL;
+import javax.swing.border.*;
+import java.util.*;
+import java.io.*;
+
+public class ImageViewer extends JPanel
+{
+ private ImageManager imgmanager;
+ private int vw, vh;
+ private int iw, ih;
+ private int selected = 0;
+ private Image img;
+
+ private String cmdline = new String();
+ private boolean fullRefresh = false;
+ private Point offset = new Point(0,0);
+ private Rectangle rect = new Rectangle();
+ private Rectangle roirect[] = null;
+ private String roiname[] = null;
+
+ public ImageViewer( String j2kfilename, ImageManager manager, boolean session, boolean jppstream)
+ {
+ String str;
+ MML myMML;
+
+ this.setSize( 170, 170);
+ Dimension asz = this.getSize();
+
+ vw = asz.width;
+ vh = asz.height;
+
+ setBackground(Color.black);
+ myMML = new MML(this);
+
+ imgmanager = manager;
+
+ img = imgmanager.getImage( j2kfilename, vw, vh, session, jppstream, !jppstream);
+
+ addMouseListener(myMML);
+ addMouseMotionListener(myMML);
+ addComponentListener( new ResizeListener(this));
+ }
+
+ public Image getImage()
+ {
+ return img;
+ }
+
+ public void zoomIn()
+ {
+ roirect = null;
+ roiname = null;
+
+ double scalex = (double)vw/(double)rect.width;
+ double scaley = (double)vh/(double)rect.height;
+
+ int fw = (int)(imgmanager.getFw()*scalex);
+ int fh = (int)(imgmanager.getFh()*scaley);
+ int rx = (int)((imgmanager.getRx()+rect.x)*scalex);
+ int ry = (int)((imgmanager.getRy()+rect.y)*scaley);
+
+ img = imgmanager.getImage( fw, fh, rx, ry, vw, vh);
+
+ rect.x = rect.y = rect.width = rect.height = 0;
+
+ selected = 0;
+ fullRefresh = true;
+ repaint();
+ }
+
+ public void enlarge()
+ {
+ roirect = null;
+ roiname = null;
+
+ Dimension asz = this.getSize();
+
+ vw = asz.width;
+ vh = asz.height;
+
+ double scalex = vw/(double)imgmanager.getRw();
+ double scaley = vh/(double)imgmanager.getRh();
+
+ int fw = (int)(imgmanager.getFw()*scalex);
+ int fh = (int)(imgmanager.getFh()*scaley);
+ int rx = (int)(imgmanager.getRx()*scalex);
+ int ry = (int)(imgmanager.getRy()*scaley);
+
+ img = imgmanager.getImage( fw, fh, rx, ry, vw, vh);
+
+ fullRefresh = true;
+ repaint();
+ }
+
+ public void setSelected(int state)
+ {
+ roirect = null;
+ roiname = null;
+
+ if (state != selected) {
+
+ selected = state;
+ repaint();
+ }
+ }
+
+ public boolean isInsideRect(int x, int y)
+ {
+ return rect.contains(x - offset.x, y - offset.y);
+ }
+
+ public void setRGeom(int x1, int y1, int x2, int y2)
+ {
+ rect.x = Math.min(x1,x2) - offset.x;
+ rect.y = Math.min(y1,y2) - offset.y;
+ rect.width = Math.abs(x2-x1);
+ rect.height = Math.abs(y2-y1);
+ }
+
+ // public void annotate( JP2XMLparser.ROIparams roi[])
+ // {
+ // int numofroi = roi.length;
+
+ // roirect = new Rectangle [numofroi];
+ // roiname = new String [numofroi];
+
+ // double scale_x = imgmanager.getFw()/(double)imgmanager.getOrigWidth();
+ // double scale_y = imgmanager.getFh()/(double)imgmanager.getOrigHeight();
+ // int rx = imgmanager.getRx();
+ // int ry = imgmanager.getRy();
+ // int rw = imgmanager.getRw();
+ // int rh = imgmanager.getRh();
+
+ // for( int i=0; i<numofroi ; i++){
+ // int x = (int)(roi[i].x*scale_x) - rx;
+ // int y = (int)(roi[i].y*scale_y) - ry;
+ // int w = (int)(roi[i].w*scale_x);
+ // int h = (int)(roi[i].h*scale_y);
+ // if( 0<=x && 0<=y && x+w<=rw && y+h<=rh){ // can be optimized
+ // roirect[i] = new Rectangle( x, y, w, h);
+ // roiname[i] = new String( roi[i].name);
+ // }
+ // else{
+ // roirect[i] = null;
+ // roiname[i] = null;
+ // }
+ // }
+ // repaint();
+ // }
+
+ public boolean hasAnnotation()
+ {
+ if( roirect == null)
+ return false;
+ else
+ return true;
+ }
+
+ public boolean isInsideROIRect(int x, int y)
+ {
+ for( int i=0; i<roirect.length; i++)
+ if( roirect[i] != null)
+ if( roirect[i].contains(x - offset.x, y - offset.y)){
+ rect = roirect[i];
+ return true;
+ }
+ return false;
+ }
+
+ public void paint(Graphics g)
+ {
+ BufferedImage bi;
+ Graphics2D big;
+ Graphics2D g2 = (Graphics2D) g;
+
+ if (fullRefresh) {
+ g2.clearRect(0, 0, vw, vh);
+ fullRefresh = false;
+ }
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ g2.setRenderingHint(RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_QUALITY);
+
+ offset.x = 0;
+ offset.y = 0;
+
+ iw = img.getWidth(this);
+ ih = img.getHeight(this);
+
+ bi = new BufferedImage( iw, ih, BufferedImage.TYPE_INT_RGB);
+ big = bi.createGraphics();
+
+ big.drawImage(img, 0, 0, this);
+ big.setPaint(Color.red);
+ if ((rect.width > 0) && (rect.height > 0))
+ big.draw(rect);
+
+ if( roirect != null){
+ for( int i=0; i<roirect.length; i++)
+ if( roirect[i] != null){
+ big.draw( roirect[i]);
+ big.drawString( roiname[i], roirect[i].x+3, roirect[i].y+roirect[i].height*2/3);
+ }
+ }
+ if (selected == 1)
+ shadeExt(big, 0, 0, 0, 64);
+ else if (selected == 2) {
+ shadeExt(big, 0, 0, 0, 255);
+ selected = 1;
+ }
+ g2.drawImage(bi, offset.x, offset.y, this);
+ }
+
+ private void shadeRect(Graphics2D g2, int r, int g, int b, int a)
+ {
+ g2.setPaint(new Color(r, g, b, a));
+ g2.fillRect(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1);
+ }
+
+ private void shadeExt(Graphics2D g2, int r, int g, int b, int a)
+ {
+ g2.setPaint(new Color(r, g, b, a));
+ g2.fillRect(0, 0, iw, rect.y); /* _N_ */
+ g2.fillRect(rect.x + rect.width + 1, rect.y,
+ iw - rect.x - rect.width - 1, rect.height + 1); /* E */
+ g2.fillRect(0, rect.y, rect.x, rect.height + 1); /* W */
+ g2.fillRect(0, rect.y + rect.height + 1,
+ iw, ih - rect.y - rect.height - 1); /* _S_ */
+ }
+}
--- /dev/null
+/*
+ * $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 javax.swing.*;
+import java.awt.event.*;
+import java.awt.*;
+
+public class ImageWindow extends JFrame
+{
+ private ImageViewer imgviewer;
+ private ImageManager imgmanager;
+
+ public ImageWindow( String uri, String j2kfilename, boolean session, boolean jppstream)
+ {
+ super( j2kfilename);
+
+ imgmanager = new ImageManager( uri);
+
+ imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream);
+ imgviewer.setOpaque(true); //content panes must be opaque
+
+ JPanel panel = new JPanel();
+ panel.setLayout(new BorderLayout());
+ panel.add( imgviewer, BorderLayout.CENTER);
+
+ setContentPane( panel);
+
+ addWindowListener(new WindowMyAdapter());
+ }
+
+ class WindowMyAdapter extends WindowAdapter
+ {
+ public void windowClosing(WindowEvent arg)
+ {
+ imgmanager.closeChannel();
+ System.exit(0);
+ }
+ }
+
+ public static void main(String s[])
+ {
+ String j2kfilename, uri;
+ boolean session, jppstream;
+
+ if(s.length >= 2){
+ uri = s[0];
+ j2kfilename = s[1];
+ if( s.length > 2)
+ session = !s[2].equalsIgnoreCase( "stateless");
+ else
+ session = true;
+
+ if( s.length > 3)
+ jppstream = !s[3].equalsIgnoreCase( "JPT");
+ else
+ jppstream = true;
+ }
+ else{
+ System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [stateless/session] [JPT/JPP]");
+ return;
+ }
+ ImageWindow frame = new ImageWindow( uri, j2kfilename, session, jppstream);
+
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ //Display the window.
+ frame.pack();
+ frame.setSize(new Dimension(400,200));
+ frame.setLocation( 0, 50);
+ frame.setVisible(true);
+ }
+}
--- /dev/null
+/*
+ * $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.io.*;
+import java.net.*;
+
+public class ImgdecClient{
+
+ public static 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)
+ {
+ send_JPIPstream( jpipstream, j2kfilename, tid, cid);
+ return get_PNMstream( cid, tid, fw, fh);
+ }
+
+ public static void send_JPIPstream( byte[] jpipstream)
+ {
+ try{
+ Socket imgdecSocket = new Socket( "localhost", 5000);
+ DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
+ DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
+
+ System.err.println("Sending " + jpipstream.length + "Data Bytes to decodingServer");
+
+ os.writeBytes("JPIP-stream\n");
+ os.writeBytes("version 1.2\n");
+ os.writeBytes( jpipstream.length + "\n");
+ os.write( jpipstream, 0, jpipstream.length);
+
+ byte signal = is.readByte();
+
+ if( signal == 0)
+ System.err.println(" failed");
+ } catch (UnknownHostException e) {
+ System.err.println("Trying to connect to unknown host: " + e);
+ } catch (IOException e) {
+ System.err.println("IOException: " + e);
+ }
+ }
+
+ public static void send_JPIPstream( byte[] jpipstream, String j2kfilename, String tid, String cid)
+ {
+ try{
+ Socket imgdecSocket = new Socket( "localhost", 5000);
+ DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
+ DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
+ int length = 0;
+
+ if( jpipstream != null)
+ length = jpipstream.length;
+
+ System.err.println("Sending " + length + "Data Bytes to decodingServer");
+
+ os.writeBytes("JPIP-stream\n");
+ os.writeBytes("version 1.2\n");
+ os.writeBytes( j2kfilename + "\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");
+ os.writeBytes( length + "\n");
+ os.write( jpipstream, 0, length);
+
+ byte signal = is.readByte();
+
+ if( signal == 0)
+ System.err.println(" failed");
+ } catch (UnknownHostException e) {
+ System.err.println("Trying to connect to unknown host: " + e);
+ } catch (IOException e) {
+ System.err.println("IOException: " + e);
+ }
+ }
+
+ public static PnmImage get_PNMstream( String cid, String tid, int fw, int fh)
+ {
+ PnmImage pnmstream = null;
+
+ try {
+ Socket imgdecSocket = new Socket( "localhost", 5000);
+ DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
+ DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
+ byte []header = new byte[7];
+
+ os.writeBytes("PNM request\n");
+ if( cid != null)
+ os.writeBytes( cid + "\n");
+ else
+ if( tid != null)
+ os.writeBytes( tid + "\n");
+ else
+ os.writeBytes( "0\n");
+ os.writeBytes( fw + "\n");
+ os.writeBytes( fh + "\n");
+
+ read_stream( is, header, 7);
+
+ if( header[0] == 80){
+ // P5: gray, P6: color
+ byte magicknum = header[1];
+ if( magicknum == 5 || magicknum == 6){
+ int c = magicknum==6 ? 3: 1;
+ int w = (header[2]&0xff)<<8 | (header[3]&0xff);
+ int h = (header[4]&0xff)<<8 | (header[5]&0xff);
+ int maxval = header[6]&0xff;
+ int length = w*h*c;
+
+ if( maxval == 255 && length != 0){
+ pnmstream = new PnmImage( c, w, h);
+ read_stream( is, pnmstream.get_data(), length);
+ }
+ else
+ System.err.println("Error in get_PNMstream(), only 255 is accepted");
+ }
+ else
+ System.err.println("Error in get_PNMstream(), wrong magick number" + header[1]);
+ }
+ else
+ System.err.println("Error in get_PNMstream(), Not starting with P");
+
+ os.close();
+ is.close();
+ imgdecSocket.close();
+ } catch (UnknownHostException e) {
+ System.err.println("Trying to connect to unknown host: " + e);
+ } catch (IOException e) {
+ System.err.println("IOException: " + e);
+ }
+ return pnmstream;
+ }
+
+ public static byte [] get_XMLstream( String cid)
+ {
+ byte []xmldata = null;
+
+ try{
+ Socket imgdecSocket = new Socket( "localhost", 5000);
+ DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
+ DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
+ byte []header = new byte[5];
+
+ os.writeBytes("XML request\n");
+ os.writeBytes( cid + "\n");
+
+ read_stream( is, header, 5);
+
+ if( header[0] == 88 && header[1] == 77 && header[2] == 76){
+ int length = (header[3]&0xff)<<8 | (header[4]&0xff);
+
+ xmldata = new byte[ length];
+ read_stream( is, xmldata, length);
+ }
+ else
+ System.err.println("Error in get_XMLstream(), not starting with XML");
+ } catch (UnknownHostException e) {
+ System.err.println("Trying to connect to unknown host: " + e);
+ } catch (IOException e) {
+ System.err.println("IOException: " + e);
+ }
+ return xmldata;
+ }
+
+ public static String query_cid( String j2kfilename)
+ {
+ int []retmsglabel = new int[3];
+ retmsglabel[0] = 67;
+ retmsglabel[1] = 73;
+ retmsglabel[2] = 68;
+
+ return query_id( "CID request", j2kfilename, retmsglabel);
+ }
+
+ public static String query_tid( String j2kfilename)
+ {
+ int []retmsglabel = new int[3];
+ retmsglabel[0] = 84;
+ retmsglabel[1] = 73;
+ retmsglabel[2] = 68;
+
+ return query_id( "TID request", j2kfilename, retmsglabel);
+ }
+
+ public static String query_id( String reqmsghead, String j2kfilename, int[] retmsglabel)
+ {
+ String id = null;
+
+ try{
+ Socket imgdecSocket = new Socket( "localhost", 5000);
+ DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
+ DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
+ byte []header = new byte[4];
+
+ os.writeBytes( reqmsghead + "\n");
+ os.writeBytes( j2kfilename + "\n");
+
+ read_stream( is, header, 4);
+
+ if( header[0] == retmsglabel[0] && header[1] == retmsglabel[1] && header[2] == retmsglabel[2]){
+ int length = header[3]&0xff;
+
+ if( length > 0){
+
+ byte []iddata = new byte[ length];
+ read_stream( is, iddata, length);
+ id = new String( iddata);
+ }
+ }
+ else
+ System.err.println("Error in query_id("+ reqmsghead + "), 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 id;
+ }
+
+ public static void read_stream( DataInputStream is, byte []stream, int length)
+ {
+ int remlen = length;
+ int off = 0;
+
+ try{
+ while( remlen > 0){
+ int redlen = is.read( stream, off, remlen);
+
+ if( redlen == -1){
+ System.err.println(" failed to read_stream()");
+ break;
+ }
+ off += redlen;
+ remlen -= redlen;
+ }
+ } catch (IOException e) {
+ System.err.println("IOException: " + e);
+ }
+ }
+
+ public static void destroy_cid( String cid)
+ {
+ try{
+ Socket imgdecSocket = new Socket( "localhost", 5000);
+ DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
+ DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
+
+ os.writeBytes("CID destroy\n");
+ os.writeBytes( cid + "\n");
+
+ byte signal = is.readByte();
+
+ if( signal == 0)
+ System.err.println(" failed");
+ } catch (UnknownHostException e) {
+ System.err.println("Trying to connect to unknown host: " + e);
+ } catch (IOException e) {
+ System.err.println("IOException: " + e);
+ }
+ }
+}
--- /dev/null
+/*
+ * $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.net.*;
+import java.io.*;
+import java.util.*;
+
+
+public class JPIPHttpClient
+{
+ private String comURL;
+ protected int fw, fh;
+ protected int rx, ry;
+ protected int rw, rh;
+ protected String cid;
+ protected String tid;
+ private boolean JPTstream;
+ private boolean JPPstream;
+
+ public JPIPHttpClient( String URI)
+ {
+ comURL = URI + "?";
+ fw = fh = -1;
+ rx = ry = -1;
+ rw = rh = -1;
+ cid = null;
+ tid = null;
+ JPTstream = false;
+ JPPstream = false;
+ }
+
+ public int getFw(){ return fw;}
+ public int getFh(){ return fh;}
+ public int getRx(){ return rx;}
+ public int getRy(){ return ry;}
+ public int getRw(){ return rw;}
+ public int getRh(){ return rh;}
+
+ public byte[] requestViewWindow( int reqfw, int reqfh)
+ {
+ if( cid != null)
+ return requestViewWindow( reqfw, reqfh, cid);
+ else
+ return null;
+ }
+
+ public byte[] requestViewWindow( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh)
+ {
+ if( cid != null)
+ return requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh, cid);
+ else
+ if( tid != null)
+ return requestViewWindow( null, tid, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, null, false, false, false);
+ else
+ return null;
+ }
+
+ public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid)
+ {
+ return requestViewWindow( null, null, reqfw, reqfh, -1, -1, -1, -1, reqcid, false, false, false);
+ }
+
+ public byte[] requestViewWindow( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh, String reqcid)
+ {
+ return requestViewWindow( null, null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, false, false, false);
+ }
+
+ public byte[] requestViewWindow( String target, int reqfw, int reqfh)
+ {
+ return requestViewWindow( target, null, reqfw, reqfh, -1, -1, -1, -1, null, false, false, false);
+ }
+
+ public byte[] requestViewWindow( String target, int reqfw, int reqfh, boolean reqcnew, boolean reqJPP, boolean reqJPT)
+ {
+ if( cid == null) // 1 channel allocation only
+ return requestViewWindow( target, null, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew, reqJPP, reqJPT);
+ else
+ return null;
+ }
+
+ public byte[] requestViewWindow( String target, String reqtid, int reqfw, int reqfh, boolean reqcnew, boolean reqJPP, boolean reqJPT)
+ {
+ if( cid == null) // 1 channel allocation only
+ return requestViewWindow( target, reqtid, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew, reqJPP, reqJPT);
+ else
+ return null;
+ }
+
+ public byte[] requestViewWindow( String target, int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh)
+ {
+ return requestViewWindow( target, null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, null, false, false, false);
+ }
+
+
+ public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid, boolean reqcnew, boolean reqJPP, boolean reqJPT)
+ {
+ return requestViewWindow( null, null, reqfw, reqfh, -1, -1, -1, -1, reqcid, reqcnew, reqJPP, reqJPT);
+ }
+
+ public byte[] requestViewWindow( String target,
+ String reqtid,
+ int reqfw, int reqfh,
+ int reqrx, int reqry,
+ int reqrw, int reqrh,
+ String reqcid, boolean reqcnew, boolean reqJPP, boolean reqJPT)
+ {
+ if( reqtid != null)
+ tid = reqtid;
+
+ String urlstring = const_urlstring( target, reqtid, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, reqcnew, reqJPP, reqJPT);
+ return GETrequest( urlstring);
+ }
+
+ public byte[] requestXML()
+ {
+ String urlstring = comURL;
+
+ if( cid == null)
+ return null;
+
+ urlstring = urlstring.concat( "cid=" + cid);
+ urlstring = urlstring.concat( "&metareq=[xml_]");
+
+ return GETrequest( urlstring);
+ }
+
+ private byte[] GETrequest( String urlstring)
+ {
+ int buflen = 0;
+ URL url = null;
+ HttpURLConnection urlconn = null;
+ byte[] jpipstream = null;
+
+ try{
+ url = new URL( urlstring);
+
+ System.err.println("Requesting: " + url);
+
+ urlconn = (HttpURLConnection)url.openConnection();
+ urlconn.setRequestMethod("GET");
+ urlconn.setInstanceFollowRedirects(false);
+ urlconn.connect();
+
+ Map<String,java.util.List<String>> headers = urlconn.getHeaderFields();
+ java.util.List<String> hvaluelist;
+ String hvalueline;
+
+ String status = headers.get(null).get(0);
+
+ System.err.println( status);
+ if( !status.contains("OK"))
+ System.err.println( headers.get("Reason"));
+
+ if(( hvaluelist = headers.get("Content-type")) == null)
+ hvaluelist = headers.get("Content-Type");
+ hvalueline = hvaluelist.get(0);
+ System.err.println( hvalueline);
+
+ if( hvalueline.endsWith("jpt-stream"))
+ JPTstream = true;
+ else if( hvalueline.endsWith("jpp-stream"))
+ JPPstream = true;
+
+ if(( hvaluelist = headers.get("JPIP-fsiz")) != null){
+ hvalueline = hvaluelist.get(0);
+ fw = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue();
+ fh = Integer.valueOf( hvalueline.substring( hvalueline.indexOf(',')+1 )).intValue();
+
+ System.err.println("fw,fh: " + fw + "," + fh);
+ }
+
+ if(( hvaluelist = headers.get("JPIP-roff")) != null){
+ hvalueline = hvaluelist.get(0);
+ rx = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue();
+ ry = Integer.valueOf( hvalueline.substring( hvalueline.indexOf(',')+1 )).intValue();
+ System.err.println("rx,ry: " + rx + "," + ry);
+ }
+
+ if(( hvaluelist = headers.get("JPIP-rsiz")) != null){
+ hvalueline = hvaluelist.get(0);
+ rw = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue();
+ rh = Integer.valueOf( hvalueline.substring( hvalueline.indexOf(',')+1 )).intValue();
+ System.err.println("rw,rh: " + rw + "," + rh);
+ }
+
+ if(( hvaluelist = headers.get("JPIP-cnew")) != null){
+ hvalueline = hvaluelist.get(0);
+ cid = hvalueline.substring( hvalueline.indexOf('=')+1, hvalueline.indexOf(','));
+ System.err.println("cid: " + cid);
+ }
+
+ if(( hvaluelist = headers.get("JPIP-tid")) != null){
+ hvalueline = hvaluelist.get(0);
+ tid = hvalueline.substring( hvalueline.indexOf('=')+1);
+ System.err.println("tid: " + tid);
+ }
+
+ InputStream input = urlconn.getInputStream();
+ buflen = input.available();
+
+ if( buflen > 0){
+ ByteArrayOutputStream tmpstream = new ByteArrayOutputStream();
+ byte[] buf = new byte[ 1024];
+
+ System.err.println("reading jpipstream...");
+
+ int redlen;
+ do{
+ redlen = input.read( buf);
+
+ if( redlen == -1)
+ break;
+ tmpstream.write( buf, 0, redlen);
+ }while( redlen > 0);
+
+ buflen = tmpstream.size();
+
+ jpipstream = tmpstream.toByteArray();
+
+ tmpstream = null;
+
+ System.err.println("jpiplen: " + buflen);
+ System.err.println(" succeeded");
+ }
+ else{
+ System.err.println("No new jpipstream");
+ }
+ input.close();
+ }
+ catch ( MalformedURLException e){
+ e.printStackTrace();
+ }
+ catch ( ProtocolException e){
+ e.printStackTrace();
+ }
+ catch( ClassCastException e){
+ e.printStackTrace();
+ }
+ catch( NullPointerException e){
+ e.printStackTrace();
+ }
+ catch( UnknownServiceException e){
+ e.printStackTrace();
+ }
+ catch ( IOException e){
+ e.printStackTrace();
+ }
+
+ urlconn.disconnect();
+
+ return jpipstream;
+ }
+
+ private String const_urlstring( String target,
+ String reqtid,
+ int reqfw, int reqfh,
+ int reqrx, int reqry,
+ int reqrw, int reqrh,
+ String reqcid, boolean reqcnew, boolean reqJPP, boolean reqJPT)
+ {
+ String urlstring = comURL;
+
+ // C.7.3 Image Return Type
+ // add type=jpp-stream(;ptype=ext) or type=jpt-stream;ttype=ext
+
+ if( target != null){
+ if( !urlstring.endsWith("?"))
+ urlstring = urlstring.concat( "&");
+ urlstring = urlstring.concat( "target=" + target);
+ }
+ if( reqtid != null){
+ if( !urlstring.endsWith("?"))
+ urlstring = urlstring.concat( "&");
+ urlstring = urlstring.concat( "tid=" + reqtid);
+ }
+ if( reqfw != -1 && reqfh != -1){
+ if( !urlstring.endsWith("?"))
+ urlstring = urlstring.concat( "&");
+ urlstring = urlstring.concat( "fsiz=" + reqfw + "," + reqfh);
+ }
+ if( reqrx != -1 && reqry != -1){
+ if( !urlstring.endsWith("?"))
+ urlstring = urlstring.concat( "&");
+ urlstring = urlstring.concat( "roff=" + reqrx + "," + reqry);
+ }
+ if( reqrw != -1 && reqrh != -1){
+ if( !urlstring.endsWith("?"))
+ urlstring = urlstring.concat( "&");
+ urlstring = urlstring.concat( "rsiz=" + reqrw + "," + reqrh);
+ }
+ if( reqcid != null){
+ if( !urlstring.endsWith("?"))
+ urlstring = urlstring.concat( "&");
+ urlstring = urlstring.concat( "cid=" + reqcid);
+ }
+ if( reqcnew){
+ if( !urlstring.endsWith("?"))
+ urlstring = urlstring.concat( "&");
+ urlstring = urlstring.concat( "cnew=http");
+ }
+
+ if( reqJPP && !JPTstream){
+ if( !urlstring.endsWith("?"))
+ urlstring = urlstring.concat( "&");
+ urlstring = urlstring.concat( "type=jpp-stream");
+ }
+ else if( reqJPT && !JPPstream){
+ if( !urlstring.endsWith("?"))
+ urlstring = urlstring.concat( "&");
+ urlstring = urlstring.concat( "type=jpt-stream");
+ }
+ else{ // remove this option later
+ if( !urlstring.endsWith("?"))
+ urlstring = urlstring.concat( "&");
+ if( JPTstream)
+ urlstring = urlstring.concat( "type=jpt-stream");
+ else if( JPPstream)
+ urlstring = urlstring.concat( "type=jpp-stream");
+ }
+
+ return urlstring;
+ }
+
+ public void closeChannel()
+ {
+ if( cid == null)
+ return;
+
+ try{
+ URL url = new URL( comURL + "cclose=" + cid);
+ System.err.println( "closing cid: " + cid);
+
+ HttpURLConnection urlconn = (HttpURLConnection)url.openConnection();
+ urlconn.setRequestMethod("GET");
+ urlconn.setInstanceFollowRedirects(false);
+ urlconn.connect();
+
+ Map headers = urlconn.getHeaderFields();
+
+ urlconn.disconnect();
+ } catch ( MalformedURLException e){
+ e.printStackTrace();
+ } catch ( IOException e){
+ e.printStackTrace();
+ }
+ }
+}
--- /dev/null
+/*
+ * $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.event.*;
+
+class MML implements MouseMotionListener, MouseListener
+{
+ public void mouseExited(MouseEvent e) {}
+ public void mouseEntered(MouseEvent e) {}
+ public void mouseClicked(MouseEvent e) {}
+
+ private ImageViewer iv;
+ private int x1, y1, x2, y2, zf, btn;
+ private boolean zoomrq;
+
+ public MML(ImageViewer imageviewer)
+ {
+ x1 = y1 = -1;
+ iv = imageviewer;
+ zoomrq = false;
+ zf = 0;
+ }
+
+ private boolean isInside(int x, int y)
+ {
+ x -= iv.getX();
+ y -= iv.getY();
+ return (x >= 0) && (x < iv.getWidth())
+ && (y >= 0) && (y < iv.getHeight());
+ }
+
+ public void mousePressed(MouseEvent e)
+ {
+ btn = e.getButton();
+
+ if( iv.hasAnnotation()){
+ if( iv.isInsideROIRect(e.getX(), e.getY())){
+ iv.zoomIn();
+ System.out.println("annotation click");
+ return;
+ }
+ }
+ if (iv.isInsideRect(e.getX(), e.getY())) {
+ iv.setSelected(2);
+ iv.repaint();
+ zoomrq = true;
+ } else {
+ iv.setRGeom(0, 0, 0, 0);
+ iv.setSelected(0);
+ iv.repaint();
+ x1 = y1 = -1;
+ }
+ }
+
+ public void mouseReleased(MouseEvent e)
+ {
+ if(e.getButton() == 1) {
+ if (zoomrq) {
+ iv.zoomIn();
+ zoomrq = false;
+ }
+ }
+ }
+
+ public void mouseMoved(MouseEvent e)
+ {
+ }
+
+ public void mouseDragged(MouseEvent e)
+ {
+ if (btn == 1) {
+ x2 = e.getX();
+ y2 = e.getY();
+
+ iv.setSelected(0);
+ zoomrq = false;
+
+ if (isInside(x2, y2)) {
+ if (x1 == -1) {
+ x1 = x2;
+ y1 = y2;
+ } else {
+ iv.setRGeom(x1, y1, x2, y2);
+ iv.repaint();
+ }
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * $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.*;
+import java.awt.image.*;
+import java.io.*;
+import java.util.regex.*;
+
+public class PnmImage extends Component
+{
+ private byte[] data = null;
+ private int width = 0;
+ private int height = 0;
+ private int channel = 0;
+
+ public PnmImage( int c, int w, int h)
+ {
+ channel = c;
+ width = w;
+ height = h;
+ data = new byte [ w*h*c];
+ }
+
+ public PnmImage( String filename)
+ {
+ String str;
+ Pattern pat;
+ Matcher mat;
+ int bytes;
+ int r, offset = 0;
+
+ try {
+ FileInputStream fis = new FileInputStream( new File(filename));
+ DataInputStream is = new DataInputStream( fis);
+
+ pat = Pattern.compile("^P([56])$");
+ mat = pat.matcher(str = is.readLine());
+ if( !mat.matches()){
+ System.out.println("PNM header format error");
+ return;
+ }
+
+ if( (mat.group(1)).compareTo("5") == 0)
+ channel = 1;
+ else
+ channel = 3;
+
+ pat = Pattern.compile("^(\\d+) (\\d+)$");
+ mat = pat.matcher(str = is.readLine());
+ if( !mat.matches()){
+ System.out.println("PNM header format error");
+ return;
+ }
+ width = Integer.parseInt( mat.group(1));
+ height = Integer.parseInt( mat.group(2));
+
+ str = is.readLine(); // 255
+
+ bytes = width*height*channel;
+ data = new byte[bytes];
+
+ while( bytes > 0){
+ try {
+ r = is.read(data, offset, bytes);
+ if( r == -1){
+ System.err.println(" failed to read()");
+ break;
+ }
+ offset += r;
+ bytes -= r;
+ }
+ catch (IOException e) { e.printStackTrace(); }
+ }
+ fis.close();
+ } catch (IOException e) { e.printStackTrace(); }
+ }
+
+ public byte [] get_data(){ return data;}
+ public int get_width() { return width;}
+ public int get_height(){ return height;}
+
+ public Image createROIImage( int rx, int ry, int rw, int rh)
+ {
+ int []pix = new int[ rw*rh];
+
+ for( int i=0; i<rh; i++)
+ for( int j=0; j<rw; j++){
+ pix[i*rw+j] = 0xFF << 24; // transparency
+ if( channel == 1){
+ Byte lum = data[(ry+i)*width+rx+j];
+ short slum;
+
+ if( lum < 0)
+ slum = (short)(2*128+lum);
+ else
+ slum = (short)lum;
+
+ for( int c=0; c<3; c++){
+ pix[i*rw+j] = pix[i*rw+j] | slum << (8*c);
+ }
+ }
+ else
+ for( int c=0; c<3; c++){
+ Byte lum = data[ ((ry+i)*width+rx+j)*channel+(2-c)];
+ short slum;
+
+ if( lum < 0)
+ slum = (short)(2*128+lum);
+ else
+ slum = (short)lum;
+
+ pix[i*rw+j] = pix[i*rw+j] | slum << (8*c);
+ }
+ }
+
+ return createImage(new MemoryImageSource( rw, rh, pix, 0, rw));
+ }
+
+ public Image createScaleImage( double scale)
+ {
+ Image src = createROIImage( 0, 0, width, height);
+ ImageFilter replicate = new ReplicateScaleFilter( (int)(width*scale), (int)(height*scale));
+ ImageProducer prod = new FilteredImageSource( src.getSource(), replicate);
+
+ return createImage(prod);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * $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 javax.swing.*;
+import java.awt.*;
+import java.awt.image.*;
+import java.awt.geom.AffineTransform;
+
+public class RegimViewer extends JPanel
+{
+ private PnmImage refpnm;
+ private int vw, vh;
+ private Image refimg;
+ private Image jpipImg;
+ private double[] affine_matrix;
+ private AffineTransform affine;
+
+ public RegimViewer( String refname, double[] mat)
+ {
+ refpnm = new PnmImage( refname.replaceFirst("jp2", "pgm")); // decoding not realized
+ affine_matrix = new double[6];
+
+ affine_matrix[0] = mat[0];
+ affine_matrix[1] = mat[3];
+ affine_matrix[2] = mat[1];
+ affine_matrix[3] = mat[4];
+ affine_matrix[4] = mat[2];
+ affine_matrix[5] = mat[5];
+
+ affine = new AffineTransform();
+
+ for( int i=0; i<3; i++){
+ for( int j=0; j<3; j++)
+ System.out.print( mat[i*3+j] + " ");
+ System.out.println();
+ }
+ }
+
+ public void projection( Image jpipimg, double scale)
+ {
+ jpipImg = jpipimg;
+ refimg = refpnm.createScaleImage( scale);
+ vw = refimg.getWidth(this);
+ vh = refimg.getHeight(this);
+ this.setSize( vw, vh);
+
+ affine.setTransform( affine_matrix[0], affine_matrix[1], affine_matrix[2], affine_matrix[3], affine_matrix[4], affine_matrix[5]);
+ repaint();
+ }
+
+ public void paint(Graphics g)
+ {
+ int iw, ih;
+ BufferedImage bi, bi2;
+ Graphics2D big, big2;
+ Graphics2D g2 = (Graphics2D) g;
+
+ g2.clearRect(0, 0, vw, vh);
+
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ g2.setRenderingHint(RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_QUALITY);
+
+ iw = refimg.getWidth(this);
+ ih = refimg.getHeight(this);
+
+ bi = new BufferedImage( iw, ih, BufferedImage.TYPE_INT_RGB);
+ big = bi.createGraphics();
+ big.drawImage(refimg, 0, 0, this);
+
+ g2.drawImage(bi, 0, 0, this);
+
+ bi2 = new BufferedImage( jpipImg.getWidth(this), jpipImg.getHeight(this), BufferedImage.TYPE_INT_RGB);
+ big2 = bi2.createGraphics();
+ big2.drawImage( jpipImg, 0, 0, this);
+
+ g2.setTransform(affine);
+
+ g2.drawImage(bi2, 0, 0, this);
+ }
+
+ public Dimension get_imsize()
+ {
+ return (new Dimension( vw, vh));
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * $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.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+class ResizeListener implements ComponentListener
+{
+ private ImageViewer iv;
+ private Dimension largest;
+
+ public ResizeListener( ImageViewer _iv)
+ {
+ iv = _iv;
+ largest = iv.getSize();
+ }
+
+ public void componentHidden(ComponentEvent e) {}
+
+ public void componentMoved(ComponentEvent e) {}
+
+ public void componentResized(ComponentEvent e) {
+ Dimension cursize = iv.getSize();
+ if( largest.getWidth() < cursize.getWidth() || largest.getHeight() < cursize.getHeight()){
+ update_largest( cursize);
+ iv.enlarge();
+ }
+ }
+
+ private void update_largest( Dimension cursize)
+ {
+ if( largest.getWidth() < cursize.getWidth())
+ largest.setSize( cursize.getWidth(), largest.getHeight());
+ if( largest.getHeight() < cursize.getHeight())
+ largest.setSize( largest.getWidth(), cursize.getHeight());
+ }
+
+ public void componentShown(ComponentEvent e) {}
+}
\ No newline at end of file
--- /dev/null
+<project name="opj_viewer_xerces" default="dist" basedir=".">
+ <description>OpenJPIP client image viewer</description>
+ <property name="src" location="src" />
+ <property name="build" location="build"/>
+ <property name="dist" location="dist" />
+
+ <target name="init">
+ <tstamp/>
+ <mkdir dir="${build}"/>
+ </target>
+ <target name="compile" depends="init">
+ <javac srcdir="${src}" destdir="${build}"/>
+ </target>
+ <target name="dist" depends="compile">
+ <mkdir dir="${dist}"/>
+ <jar jarfile="${dist}/opj_viewer_xerces-${DSTAMP}.jar"
+ basedir="${build}" manifest="${dist}/manifest.txt"/>
+ <exec dir="${dist}" executable="ln">
+ <arg line="-sf opj_viewer_xerces-${DSTAMP}.jar opj_viewer_xerces.jar"/>
+ </exec>
+ </target>
+ <target name="clean">
+ <delete dir="${build}"/>
+ <delete dir="${dist}"/>
+ </target>
+ <target name="test" depends="dist">
+ <exec executable="appletviewer"><arg line="dist.html"/></exec>
+ </target>
+ <target name="build_test" depends="compile">
+ <exec executable="appletviewer"><arg line="compile.html"/></exec>
+ </target>
+ <target name="build_testj" depends="compile">
+ <exec executable="java"><arg line="-classpath build ImageWindow girl"/></exec>
+ </target>
+</project>
--- /dev/null
+Manifest-Version: 1.0
+Ant-Version: Apache Ant 1.7.0
+Created-By: Kaori Hagihara
+Main-Class: ImageWindow
+Class-Path: /usr/share/java/xerces-j2.jar
--- /dev/null
+opj_viewer_xerces-20111026.jar
\ No newline at end of file
--- /dev/null
+../../opj_viewer/src/ImageManager.java
\ No newline at end of file
--- /dev/null
+/*
+ * $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.*;
+import java.awt.event.*;
+import javax.swing.*;
+import java.awt.image.*;
+import java.awt.geom.*;
+import java.net.URL;
+import javax.swing.border.*;
+import java.util.*;
+import java.io.*;
+
+public class ImageViewer extends JPanel
+{
+ private ImageManager imgmanager;
+ private int vw, vh;
+ private int iw, ih;
+ private int selected = 0;
+ private Image img;
+
+ private String cmdline = new String();
+ private boolean fullRefresh = false;
+ private Point offset = new Point(0,0);
+ private Rectangle rect = new Rectangle();
+ private Rectangle roirect[] = null;
+ private String roiname[] = null;
+
+ public ImageViewer( String j2kfilename, ImageManager manager, boolean session, boolean jppstream)
+ {
+ String str;
+ MML myMML;
+
+ this.setSize( 170, 170);
+ Dimension asz = this.getSize();
+
+ vw = asz.width;
+ vh = asz.height;
+
+ setBackground(Color.black);
+ myMML = new MML(this);
+
+ imgmanager = manager;
+
+ img = imgmanager.getImage( j2kfilename, vw, vh, session, jppstream, !jppstream);
+
+ addMouseListener(myMML);
+ addMouseMotionListener(myMML);
+ addComponentListener( new ResizeListener(this));
+ }
+
+ public Image getImage()
+ {
+ return img;
+ }
+
+ public void zoomIn()
+ {
+ roirect = null;
+ roiname = null;
+
+ double scalex = (double)vw/(double)rect.width;
+ double scaley = (double)vh/(double)rect.height;
+
+ int fw = (int)(imgmanager.getFw()*scalex);
+ int fh = (int)(imgmanager.getFh()*scaley);
+ int rx = (int)((imgmanager.getRx()+rect.x)*scalex);
+ int ry = (int)((imgmanager.getRy()+rect.y)*scaley);
+
+ img = imgmanager.getImage( fw, fh, rx, ry, vw, vh);
+
+ rect.x = rect.y = rect.width = rect.height = 0;
+
+ selected = 0;
+ fullRefresh = true;
+ repaint();
+ }
+
+ public void enlarge()
+ {
+ roirect = null;
+ roiname = null;
+
+ Dimension asz = this.getSize();
+
+ vw = asz.width;
+ vh = asz.height;
+
+ double scalex = vw/(double)imgmanager.getRw();
+ double scaley = vh/(double)imgmanager.getRh();
+
+ int fw = (int)(imgmanager.getFw()*scalex);
+ int fh = (int)(imgmanager.getFh()*scaley);
+ int rx = (int)(imgmanager.getRx()*scalex);
+ int ry = (int)(imgmanager.getRy()*scaley);
+
+ img = imgmanager.getImage( fw, fh, rx, ry, vw, vh);
+
+ fullRefresh = true;
+ repaint();
+ }
+
+ public void setSelected(int state)
+ {
+ roirect = null;
+ roiname = null;
+
+ if (state != selected) {
+
+ selected = state;
+ repaint();
+ }
+ }
+
+ public boolean isInsideRect(int x, int y)
+ {
+ return rect.contains(x - offset.x, y - offset.y);
+ }
+
+ public void setRGeom(int x1, int y1, int x2, int y2)
+ {
+ rect.x = Math.min(x1,x2) - offset.x;
+ rect.y = Math.min(y1,y2) - offset.y;
+ rect.width = Math.abs(x2-x1);
+ rect.height = Math.abs(y2-y1);
+ }
+
+ public void annotate( JP2XMLparser.ROIparams roi[])
+ {
+ int numofroi = roi.length;
+
+ roirect = new Rectangle [numofroi];
+ roiname = new String [numofroi];
+
+ double scale_x = imgmanager.getFw()/(double)imgmanager.getOrigWidth();
+ double scale_y = imgmanager.getFh()/(double)imgmanager.getOrigHeight();
+ int rx = imgmanager.getRx();
+ int ry = imgmanager.getRy();
+ int rw = imgmanager.getRw();
+ int rh = imgmanager.getRh();
+
+ for( int i=0; i<numofroi ; i++){
+ int x = (int)(roi[i].x*scale_x) - rx;
+ int y = (int)(roi[i].y*scale_y) - ry;
+ int w = (int)(roi[i].w*scale_x);
+ int h = (int)(roi[i].h*scale_y);
+ if( 0<=x && 0<=y && x+w<=rw && y+h<=rh){ // can be optimized
+ roirect[i] = new Rectangle( x, y, w, h);
+ roiname[i] = new String( roi[i].name);
+ }
+ else{
+ roirect[i] = null;
+ roiname[i] = null;
+ }
+ }
+ repaint();
+ }
+
+ public boolean hasAnnotation()
+ {
+ if( roirect == null)
+ return false;
+ else
+ return true;
+ }
+
+ public boolean isInsideROIRect(int x, int y)
+ {
+ for( int i=0; i<roirect.length; i++)
+ if( roirect[i] != null)
+ if( roirect[i].contains(x - offset.x, y - offset.y)){
+ rect = roirect[i];
+ return true;
+ }
+ return false;
+ }
+
+ public void paint(Graphics g)
+ {
+ BufferedImage bi;
+ Graphics2D big;
+ Graphics2D g2 = (Graphics2D) g;
+
+ if (fullRefresh) {
+ g2.clearRect(0, 0, vw, vh);
+ fullRefresh = false;
+ }
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ g2.setRenderingHint(RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_QUALITY);
+
+ offset.x = 0;
+ offset.y = 0;
+
+ iw = img.getWidth(this);
+ ih = img.getHeight(this);
+
+ bi = new BufferedImage( iw, ih, BufferedImage.TYPE_INT_RGB);
+ big = bi.createGraphics();
+
+ big.drawImage(img, 0, 0, this);
+ big.setPaint(Color.red);
+ if ((rect.width > 0) && (rect.height > 0))
+ big.draw(rect);
+
+ if( roirect != null){
+ for( int i=0; i<roirect.length; i++)
+ if( roirect[i] != null){
+ big.draw( roirect[i]);
+ big.drawString( roiname[i], roirect[i].x+3, roirect[i].y+roirect[i].height*2/3);
+ }
+ }
+ if (selected == 1)
+ shadeExt(big, 0, 0, 0, 64);
+ else if (selected == 2) {
+ shadeExt(big, 0, 0, 0, 255);
+ selected = 1;
+ }
+ g2.drawImage(bi, offset.x, offset.y, this);
+ }
+
+ private void shadeRect(Graphics2D g2, int r, int g, int b, int a)
+ {
+ g2.setPaint(new Color(r, g, b, a));
+ g2.fillRect(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1);
+ }
+
+ private void shadeExt(Graphics2D g2, int r, int g, int b, int a)
+ {
+ g2.setPaint(new Color(r, g, b, a));
+ g2.fillRect(0, 0, iw, rect.y); /* _N_ */
+ g2.fillRect(rect.x + rect.width + 1, rect.y,
+ iw - rect.x - rect.width - 1, rect.height + 1); /* E */
+ g2.fillRect(0, rect.y, rect.x, rect.height + 1); /* W */
+ g2.fillRect(0, rect.y + rect.height + 1,
+ iw, ih - rect.y - rect.height - 1); /* _S_ */
+ }
+}
--- /dev/null
+/*
+ * $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 javax.swing.*;
+import java.awt.event.*;
+import java.awt.*;
+
+public class ImageWindow extends JFrame
+{
+ private ImageViewer imgviewer;
+ private OptionPanel optpanel;
+ private ImageManager imgmanager;
+
+ public ImageWindow( String uri, String j2kfilename, boolean session, boolean jppstream)
+ {
+ super( j2kfilename);
+
+ imgmanager = new ImageManager( uri);
+
+ imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream);
+ imgviewer.setOpaque(true); //content panes must be opaque
+
+ optpanel = new OptionPanel( imgmanager, imgviewer);
+
+ JPanel panel = new JPanel();
+ panel.setLayout(new BorderLayout());
+ panel.add( imgviewer, BorderLayout.CENTER);
+ panel.add( optpanel, BorderLayout.EAST);
+
+ setContentPane( panel);
+
+ addWindowListener(new WindowMyAdapter());
+ }
+
+ class WindowMyAdapter extends WindowAdapter
+ {
+ public void windowClosing(WindowEvent arg)
+ {
+ imgmanager.closeChannel();
+ System.exit(0);
+ }
+ }
+
+ public static void main(String s[])
+ {
+ String j2kfilename, uri;
+ boolean session, jppstream;
+
+ if(s.length >= 2){
+ uri = s[0];
+ j2kfilename = s[1];
+ if( s.length > 2)
+ session = !s[2].equalsIgnoreCase( "stateless");
+ else
+ session = true;
+
+ if( s.length > 3)
+ jppstream = !s[3].equalsIgnoreCase( "JPT");
+ else
+ jppstream = true;
+ }
+ else{
+ System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [stateless/session] [JPT/JPP]");
+ return;
+ }
+ ImageWindow frame = new ImageWindow( uri, j2kfilename, session, jppstream);
+
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ //Display the window.
+ frame.pack();
+ frame.setSize(new Dimension(400,200));
+ frame.setLocation( 0, 50);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file
--- /dev/null
+../../opj_viewer/src/ImgdecClient.java
\ No newline at end of file
--- /dev/null
+/*
+ * $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 org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.ErrorHandler;
+import org.apache.xerces.parsers.DOMParser;
+import org.xml.sax.InputSource;
+import java.io.*;
+import java.lang.Integer;
+
+public class JP2XMLparser
+{
+ Document document;
+
+ public static class ROIparams{
+ public String name = null;
+ public int x = 0;
+ public int y = 0;
+ public int w = 0;
+ public int h = 0;
+ }
+
+ public static class IRTparams{
+ public String refimg = null;
+ public double []mat = { 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
+ }
+
+ public JP2XMLparser( byte[] buf)
+ {
+ try{
+ InputSource source = new InputSource( new ByteArrayInputStream( buf));
+ DOMParser parser = new DOMParser();
+ parser.setErrorHandler(new MyHandler());
+ parser.parse( source);
+ document = parser.getDocument();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public ROIparams [] getROIparams()
+ {
+ ROIparams roi[];
+ NodeList elements = document.getElementsByTagName("roi");
+ int elementCount = elements.getLength();
+
+ roi = new ROIparams [elementCount];
+
+ for( int i = 0; i < elementCount; i++) {
+ Element element = (Element)elements.item(i);
+
+ roi[i] = new ROIparams();
+ roi[i].name = element.getAttribute( "name");
+ roi[i].x = Integer.parseInt( element.getAttribute( "x")) ;
+ roi[i].y = Integer.parseInt( element.getAttribute( "y")) ;
+ roi[i].w = Integer.parseInt( element.getAttribute( "w")) ;
+ roi[i].h = Integer.parseInt( element.getAttribute( "h")) ;
+ }
+ return roi;
+ }
+
+ public IRTparams getIRTparams()
+ {
+ IRTparams irt = new IRTparams();
+ NodeList elements = document.getElementsByTagName("irt");
+ int elementCount = elements.getLength();
+
+ Element element = (Element)elements.item(0);
+ irt.refimg = element.getAttribute( "refimg");
+ for( int i=1; i<=9; i++)
+ irt.mat[i-1] = Double.parseDouble( element.getAttribute("m" + i));
+
+ return irt;
+ }
+}
+
+class MyHandler implements ErrorHandler {
+ public void warning(SAXParseException e) {
+ System.out.println("Warning: line" + e.getLineNumber());
+ System.out.println(e.getMessage());
+ }
+ public void error(SAXParseException e) {
+ System.out.println("Error: line" + e.getLineNumber());
+ System.out.println(e.getMessage());
+ }
+ public void fatalError(SAXParseException e) {
+ System.out.println("Critical error: line" + e.getLineNumber());
+ System.out.println(e.getMessage());
+ }
+}
\ No newline at end of file
--- /dev/null
+../../opj_viewer/src/JPIPHttpClient.java
\ No newline at end of file
--- /dev/null
+../../opj_viewer/src/MML.java
\ No newline at end of file
--- /dev/null
+/*
+ * $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.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class OptionPanel extends JPanel implements ActionListener
+{
+ private JButton roibutton;
+ private JButton imregbutton;
+ private ImageManager imgmanager;
+ private ImageViewer iv;
+ private JP2XMLparser xmlparser;
+ private JFrame regimwindow;
+ private RegimViewer regimgviewer;
+
+ public OptionPanel( ImageManager manager, ImageViewer imgviewer)
+ {
+ this.setLayout(new BoxLayout( this, BoxLayout.Y_AXIS));
+
+ roibutton = new JButton("Region Of Interest");
+ imregbutton = new JButton("Image Registration");
+
+ roibutton.setAlignmentX( Component.CENTER_ALIGNMENT);
+ imregbutton.setAlignmentX( Component.CENTER_ALIGNMENT);
+
+ add( roibutton);
+ add( imregbutton);
+ roibutton.addActionListener(this);
+ imregbutton.addActionListener(this);
+
+ imgmanager = manager;
+ iv = imgviewer;
+ xmlparser = null;
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ if( xmlparser == null){
+ byte []xmldata = imgmanager.getXML();
+ if( xmldata != null)
+ xmlparser = new JP2XMLparser( xmldata);
+ }
+ if( e.getSource() == roibutton){
+ if( xmlparser != null){
+ JP2XMLparser.ROIparams roi[] = xmlparser.getROIparams();
+ iv.annotate( roi);
+ }
+ }
+ if( e.getSource() == imregbutton){
+ if( xmlparser != null){
+ if( regimwindow == null){
+ JP2XMLparser.IRTparams irt = xmlparser.getIRTparams();
+
+ regimgviewer = new RegimViewer( irt.refimg, irt.mat);
+ regimgviewer.setOpaque(false);
+
+ regimwindow = new JFrame("Registered Image");
+ regimwindow.getContentPane().add("Center", regimgviewer);
+ regimwindow.pack();
+ regimwindow.setLocation( 500, 50);
+ regimwindow.setVisible(true);
+ }
+ regimgviewer.projection( iv.getImage(), (double)imgmanager.getRw()/(double)imgmanager.getOrigWidth());
+ regimwindow.setSize( regimgviewer.get_imsize());
+ regimwindow.show();
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+../../opj_viewer/src/PnmImage.java
\ No newline at end of file
--- /dev/null
+../../opj_viewer/src/RegimViewer.java
\ No newline at end of file
--- /dev/null
+../../opj_viewer/src/ResizeListener.java
\ No newline at end of file
--- /dev/null
+/*
+ * $Id: test_index.c 46 2011-02-17 14:50:55Z kaori $
+ *
+ * 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.
+ */
+
+/*! \file
+ * \brief test_index is a program to test the index code format of a JP2 file
+ *
+ * \section impinst Implementing instructions
+ * This program takes one argument, and print out text type index information to the terminal. \n
+ * -# Input JP2 file\n
+ * % ./test_index input.jp2\n
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "openjpip.h"
+
+int
+main(int argc, char *argv[])
+{
+ int fd;
+ index_t *jp2idx;
+
+ if( (fd = open( argv[1], O_RDONLY)) == -1){
+ fprintf( stderr, "Error: Target %s not found\n", argv[1]);
+ return -1;
+ }
+
+ if( !(jp2idx = get_index_from_JP2file( fd))){
+ fprintf( stderr, "JP2 file broken\n");
+ return -1;
+ }
+
+ output_index( jp2idx);
+ destroy_index( &jp2idx);
+ close(fd);
+
+ return 0;
+} /* main */
applications/mj2/Makefile
applications/jpip/Makefile
applications/jpip/libopenjpip/Makefile
-applications/jpip/opj_server/Makefile
-applications/jpip/opj_client/Makefile
-applications/jpip/opj_client/opj_dec_server/Makefile
-applications/jpip/tools/Makefile
+applications/jpip/util/Makefile
doc/Makefile
])
int write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
{
- int len, lenp;
- int size_of_coding; // 4 or 8
- int version;
- int tileno, resno, precno, layno, num_packet=0;
- int i,nmax=0;
+ int len, lenp, tileno, version, i, nmax, size_of_coding; // 4 or 8
opj_tile_info_t *tile_Idx;
opj_packet_info_t packet;
+ int resno, precno, layno, num_packet;
+ int numOfres, numOfprec, numOflayers;
if( j2klen > pow( 2, 32)){
size_of_coding = 8;
cio_skip( cio, 4); /* L [at the end] */
cio_write( cio, JPIP_FAIX, 4); /* FAIX */
cio_write( cio, version,1); /* Version 0 = 4 bytes */
-
+
+ nmax = 0;
for( i=0; i<=cstr_info.numdecompos[compno]; i++)
nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers;
cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */
for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
-
tile_Idx = &cstr_info.tile[ tileno];
- // int correction = EPHused ? 3 : 1;
+
num_packet = 0;
+ numOfres = cstr_info.numdecompos[compno] + 1;
- for( resno=0; resno<=cstr_info.numdecompos[compno]; resno++){
- for( precno=0; precno<tile_Idx->pw[resno]*tile_Idx->ph[resno]; precno++){
- for( layno=0; layno<cstr_info.numlayers; layno++){
- packet = tile_Idx->packet[num_packet * cstr_info.numcomps + compno];
- cio_write( cio, packet.start_pos-coff, size_of_coding); /* start position */
+ for( resno=0; resno<numOfres ; resno++){
+ numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
+ for( precno=0; precno<numOfprec; precno++){
+ numOflayers = cstr_info.numlayers;
+ for( layno=0; layno<numOflayers; layno++){
+
+ switch ( cstr_info.prog){
+ case LRCP:
+ packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
+ break;
+ case RLCP:
+ packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno];
+ break;
+ case RPCL:
+ packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno];
+ break;
+ case PCRL:
+ packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno];
+ break;
+ case CPRL:
+ packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno];
+ break;
+ default:
+ fprintf( stderr, "failed to ppix indexing\n");
+ }
+
+ cio_write( cio, packet.start_pos-coff, size_of_coding); /* start position */
cio_write( cio, packet.end_ph_pos-packet.start_pos+1, size_of_coding); /* length */
num_packet++;
int write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
{
- int len, lenp;
- int tileno, resno, precno, layno, num_packet=0;
- int size_of_coding; // 4 or 8
- int version;
- int i,nmax=0;
+ int len, lenp, tileno, version, i, nmax, size_of_coding; // 4 or 8
opj_tile_info_t *tile_Idx;
opj_packet_info_t packet;
-
+ int resno, precno, layno, num_packet;
+ int numOfres, numOfprec, numOflayers;
+
if( j2klen > pow( 2, 32)){
size_of_coding = 8;
version = 1;
cio_write( cio, JPIP_FAIX, 4); /* FAIX */
cio_write( cio, version, 1); /* Version 0 = 4 bytes */
+ nmax = 0;
for( i=0; i<=cstr_info.numdecompos[compno]; i++)
nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers;
cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */
for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
-
tile_Idx = &cstr_info.tile[ tileno];
- // int correction = EPHused ? 3 : 1;
+
num_packet=0;
-
- for( resno=0; resno<=cstr_info.numdecompos[compno]; resno++){
- for( precno=0; precno<tile_Idx->pw[resno]*tile_Idx->ph[resno]; precno++){
- for( layno=0; layno<cstr_info.numlayers; layno++){
- packet = tile_Idx->packet[num_packet * cstr_info.numcomps + compno];
- cio_write( cio, packet.start_pos-coff, size_of_coding); /* start position */
+ numOfres = cstr_info.numdecompos[compno] + 1;
+
+ for( resno=0; resno<numOfres ; resno++){
+ numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
+ for( precno=0; precno<numOfprec; precno++){
+ numOflayers = cstr_info.numlayers;
+ for( layno=0; layno<numOflayers; layno++){
+
+ switch ( cstr_info.prog){
+ case LRCP:
+ packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
+ break;
+ case RLCP:
+ packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno];
+ break;
+ case RPCL:
+ packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno];
+ break;
+ case PCRL:
+ packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno];
+ break;
+ case CPRL:
+ packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno];
+ break;
+ default:
+ fprintf( stderr, "failed to ppix indexing\n");
+ }
+
+ cio_write( cio, packet.start_pos-coff, size_of_coding); /* start position */
cio_write( cio, packet.end_pos-packet.start_pos+1, size_of_coding); /* length */
num_packet++;
}
}
}
-
- /* PADDING */
- while( num_packet < nmax){
+
+ while( num_packet < nmax){ /* PADDING */
cio_write( cio, 0, size_of_coding); /* start position */
cio_write( cio, 0, size_of_coding); /* length */
num_packet++;
- }
+ }
}
len = cio_tell( cio)-lenp;
cio_seek( cio, lenp+len);
return len;
-
}