! : changed
+ : added
+Feburary 28, 2012
++ [kaori] enabled the opj_server to reply the first query consisting with len request from kakadu client
+
+February 9, 2012
+* [kaori] fixed Doxygen configuration file to document the utilities
++ [kaori] added execution argument to set port number for opj_dec_server, opj_viewer*
+
+January 26, 2012
+! [kaori] unapplied auxtrans_manager to the local mode
+
+December 24, 2011
+* [kaori] additional modification for the warning
+
+December 22, 2011
+* [kaori] fixed auxtrans_manager to enable MAC
+* [kaori] warnings due to disregarding return value are removed
+
November 30, 2011
+ [kaori] TCP return (http-tcp) implemented
November 16, 2011
-* [kaori] fixed opj_server execusion error (instant terminating) with autotool, cmake still need to be fixed
+* [kaori] fixed Region of Interest option, and memory leak of opj_dec_server
+ [kaori] new feature to target JP2 files from www (libcurl required)
+* [kaori] fixed opj_server execusion error (instant terminating) with autotool, cmake still need to be fixed
November 8, 2011
! [kaori] updated main page of doxygen
-! [kaori] enabled OpenJPEG V2 API
November 3, 2011
* [kaori] solved memory leak of opj_server
October 12, 2011
+ [kaori] enable layers requests; restricting the number of codesream quality layers
-October 10, 2011
-- [antonin] removed obsolete indexer utility
-+ [kaori] enable JPT-stream request from client viewer option
+October 11, 2011
++ [antonin] enable JPT-stream request from client viewer option (credit to kaori)
-September 30, 2011
-+ [kaori] enabled JPP-stream
+October 10, 2011
+- [antonin] removed obsolete indexer utility (credit to kaori)
++ [antonin] enabled JPP-stream (credit to kaori)
September 16, 2011
+ [kaori] enabled stateless requests from the opj_viewers
For shutting down JPIP server:
%GET http://hostname/myFCGI?quitJPIP
Notice, http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting)
- Request message "quitJPIP" can be changed in Makefile, modify -DQUIT_SIGNAL=\"quitJPIP\"
+ Requst message "quitJPIP" can be changed in Makfile, modify -DQUIT_SIGNAL=\"quitJPIP\"
Client:
1. Launch image decoding server, and keep it alive as long as image viewers are open
- % ./opj_dec_server
+ % ./opj_dec_server [portnumber (50000 by default)]
You might prefer to implement this program from another directory since cache files are saved in the working directory.
% mkdir cache
% ../opj_dec_server
2. Open image viewers (as many as needed)
- % java -jar opj_viewer.jar http://hostname/myFCGI path/filename.jp2 [stateless/session] [jptstream/jppstream] [tcp/udp]
+ % java -jar opj_viewer.jar http://hostname/myFCGI path/filename.jp2 [hostname] [portnumber] [stateless/session] [jptstream/jppstream] [tcp/udp]
( The arguments
- http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting)
- path/filename.jp2 is the server local path or URL of a JP2 file
+ - host name of opj_dec_server, localhost by default
+ - portnumber of opj_dec_server, 50000 by default
- request type stateless for no caching, session (default) for caching
- return media type, JPT-stream tile based stream, or JPP-stream (default) precinct based stream
- auxiliary return protocol, tcp or udp (udp is not implemented yet), if not given, return data is filled in http chunk
% ./image_to_j2k -i copenhague1.tif -o copenhague1.jp2 -p RPCL -c [64,64] -t 640,480 -jpip -TP R
options
- -jpip : embed index table box into the output JP2 file (obligation for JPIP)
+ -jpip : embed index table 'cidx' box into the output JP2 file (obligation for JPIP)
-TP R : partition a tile into tile parts of different resolution levels (obligation for JPT-stream)
<Option>
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-INPUT = .. ../libopenjpip ../opj_server ../opj_client/opj_dec_server ../tools ../tools/indexer
+INPUT = .. ../libopenjpip ../util
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
j2kheader_manager.c \
jp2k_encoder.c \
sock_manager.c \
-auxtrans_manager.c \
openjpip.h \
bool.h \
boxheader_manager.h \
session_manager.h \
jpip_parser.h \
jp2k_decoder.h \
-sock_manager.h \
-auxtrans_manager.h
+sock_manager.h
SERVER_SRC = auxtrans_manager.c \
auxtrans_manager.h
#include <stdlib.h>
#include "auxtrans_manager.h"
-#ifdef __linux__
-#include <pthread.h>
-#else
+#ifdef _WIN32
#include <process.h>
+#else
+#include <pthread.h>
#endif
#ifdef SERVER
void delete_auxresponse( aux_response_param_t **auxresponse);
-#ifdef __linux__
-void * aux_streaming( void *arg);
-#else
+
+#ifdef _WIN32
unsigned __stdcall aux_streaming( void *arg);
+#else
+void * aux_streaming( void *arg);
#endif
void send_responsedata_on_aux( bool istcp, auxtrans_param_t auxtrans, char cid[], void *data, int datalen, int maxlenPerFrame)
{
aux_response_param_t *auxresponse;
-#ifdef __linux__
+#ifdef _WIN32
+ unsigned int threadId;
+#else
pthread_t thread;
int status;
-#else
- unsigned int threadId;
#endif
if( istcp){
}
auxresponse = gene_auxresponse( istcp, auxtrans, cid, data, datalen, maxlenPerFrame);
-
-#ifdef __linux__
- status = pthread_create( &thread, NULL, &aux_streaming, auxresponse);
- if( status != 0)
- fprintf( FCGI_stderr,"ERROR: pthread_create() %s",strerror(status));
-#else
+
+#ifdef _WIN32
auxresponse->hTh = (HANDLE)_beginthreadex( NULL, 0, &aux_streaming, auxresponse, 0, &threadId);
if( auxresponse->hTh == 0)
fprintf( FCGI_stderr,"ERRO: pthread_create() %s", strerror( (int)auxresponse->hTh));
+#else
+ status = pthread_create( &thread, NULL, &aux_streaming, auxresponse);
+ if( status != 0)
+ fprintf( FCGI_stderr,"ERROR: pthread_create() %s",strerror(status));
#endif
}
else
bool recv_ack( SOCKET connected_socket, void *data);
-#ifdef __linux__
-void * aux_streaming( void *arg)
-#else
+#ifdef _WIN32
unsigned __stdcall aux_streaming( void *arg)
+#else
+void * aux_streaming( void *arg)
#endif
{
SOCKET connected_socket;
aux_response_param_t *auxresponse = (aux_response_param_t *)arg;
-#ifdef __linux__
- pthread_detach( pthread_self());
-#else
+#ifdef _WIN32
CloseHandle( auxresponse->hTh);
+#else
+ pthread_detach( pthread_self());
#endif
chunk = (unsigned char *)malloc( auxresponse->maxlenPerFrame);
delete_auxresponse( &auxresponse);
-#ifdef __linux__
- pthread_exit(0);
-#else
+#ifdef _WIN32
_endthreadex(0);
+#else
+ pthread_exit(0);
#endif
return 0;
#include "sock_manager.h"
-//! auxiliary transport setting parameters
+/** auxiliary transport setting parameters*/
typedef struct auxtrans_param{
- int tcpauxport; //!< tcp port
- int udpauxport; //!< udp port
- SOCKET tcplistensock; //!< listenning socket for aux tcp (-1 if not open)
- SOCKET udplistensock; //!< listenning socket for aux udp (-1 if not open)
+ int tcpauxport; /**< tcp port*/
+ int udpauxport; /**< udp port*/
+ SOCKET tcplistensock; /**< listenning socket for aux tcp (-1 if not open)*/
+ SOCKET udplistensock; /**< listenning socket for aux udp (-1 if not open)*/
} auxtrans_param_t;
/**
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
#include <ctype.h>
#include "box_manager.h"
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
boxlist_param_t * gene_boxlist()
{
if( !boxlist)
boxlist = gene_boxlist();
insert_box_into_list( box, boxlist);
- }while( pos < offset+length);
+ }while( pos < (int)(offset+length));
return boxlist;
}
char *boxtype;
box_param_t *box;
- // read LBox and TBox
+ /* read LBox and TBox*/
if(!(data = fetch_bytes( fd, offset, 8))){
fprintf( FCGI_stderr, "Error: error in gene_boxbyOffset( %d, %lld)\n", fd, offset);
return NULL;
boxlen = (Byte8_t)big4(data);
boxtype = (char *)(data+4);
- // box type constraint
+ /* box type constraint*/
if( !isalpha(boxtype[0]) || !isalpha(boxtype[1]) ||
- (!isalnum(boxtype[2])&&!isblank(boxtype[2])) ||
- (!isalpha(boxtype[3])&&!isblank(boxtype[3]))){
+ (!isalnum(boxtype[2])&&!isspace(boxtype[2])) ||
+ (!isalpha(boxtype[3])&&!isspace(boxtype[3]))){
free( data);
return NULL;
}
if( boxlen == 1){
Byte_t *data2;
headlen = 16;
- // read XLBox
+ /* read XLBox*/
if((data2 = fetch_bytes( fd, offset+8, 8))){
boxlen = big8(data2);
free(data2);
char *boxtype;
box_param_t *box;
- // read LBox and TBox
+ /* read LBox and TBox*/
headlen = 8;
boxlen = (Byte8_t)big4( stream);
boxtype = (char *)( stream+4);
- // box type constraint
+ /* box type constraint*/
if( !isalpha(boxtype[0]) || !isalpha(boxtype[1]) ||
- (!isalnum(boxtype[2])&&!isblank(boxtype[2])) ||
- (!isalpha(boxtype[3])&&!isblank(boxtype[3]))){
+ (!isalnum(boxtype[2])&&!isspace(boxtype[2])) ||
+ (!isalpha(boxtype[3])&&!isspace(boxtype[3]))){
return NULL;
}
if( boxlen == 1){
headlen = 16;
- boxlen = big8( stream+8); // read XLBox
+ boxlen = big8( stream+8); /* read XLBox*/
}
box = (box_param_t *)malloc( sizeof( box_param_t));
box->fd = -1;
}
-box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[])
+box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, const char TBox[])
{
Byte8_t pos;
Byte_t *data;
box_param_t *foundbox;
- if( length==0){ // set the max length
- struct stat sb;
- if( fstat( fd, &sb) == -1){
- fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
+ if( length==0){ /* set the max length*/
+ if( (length = get_filesize( fd) - offset) <= 0)
return NULL;
- }
- length = (Byte8_t)sb.st_size - offset;
}
pos = offset;
- while( pos < offset+length-7){ // LBox+TBox-1=7
+ while( pos < offset+length-7){ /* LBox+TBox-1=7*/
- // read LBox and TBox
+ /* read LBox and TBox*/
if((data = fetch_bytes( fd, pos, 8))){
headlen = 8;
boxlen = (Byte8_t)big4(data);
if( boxlen == 1){
Byte_t *data2;
headlen = 16;
- // read XLBox
+ /* read XLBox*/
if((data2 = fetch_bytes( fd, pos+8, 8))){
boxlen = big8(data2);
free(data2);
return NULL;
}
-box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t length, char TBox[])
+box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t length, const char TBox[])
{
Byte8_t pos;
Byte_t *data;
box_param_t *foundbox;
- if( length<=0){ // set the max length
+ if( length<=0){ /* set the max length*/
fprintf( FCGI_stderr, "func gene_boxbyTypeinStream(), max length must be more than 0\n");
return NULL;
}
pos = offset;
- while( pos < offset+length-7){ // LBox+TBox-1=7
+ while( pos < offset+length-7){ /* LBox+TBox-1=7*/
- // read LBox and TBox
+ /* read LBox and TBox*/
data = stream + pos;
headlen = 8;
boxlen = (Byte8_t)big4(data);
boxtype = (char *)(data+4);
if( boxlen == 1){
- // read XLBox
+ /* read XLBox*/
headlen = 16;
boxlen = big8( data+8);
}
return gene_boxbyOffset( superbox->fd, get_DBoxoff( superbox)+offset);
}
-box_param_t * gene_childboxbyType( box_param_t *superbox, Byte8_t offset, char TBox[])
+box_param_t * gene_childboxbyType( box_param_t *superbox, Byte8_t offset, const char TBox[])
{
return gene_boxbyType( superbox->fd, get_DBoxoff( superbox)+offset, get_DBoxlen( superbox)-offset, TBox);
}
return fetch_8bytebigendian( box->fd, get_DBoxoff( box)+offset);
}
-box_param_t * search_box( char type[], boxlist_param_t *boxlist)
+box_param_t * search_box( const char type[], boxlist_param_t *boxlist)
{
box_param_t *foundbox;
#include "byte_manager.h"
-//! box parameters
+/** box parameters*/
typedef struct box_param{
- int fd; //!< file descriptor
- Byte8_t offset; //!< byte position of the whole Box (LBox) in the file
- Byte_t headlen; //!< header length 8 or 16
- Byte8_t length; //!< length of the whole Box
- char type[4]; //!< type of information in the DBox
- struct box_param *next; //!< pointer to the next box
+ int fd; /**< file descriptor*/
+ Byte8_t offset; /**< byte position of the whole Box (LBox) in the file*/
+ Byte_t headlen; /**< header length 8 or 16*/
+ Byte8_t length; /**< length of the whole Box*/
+ char type[4]; /**< type of information in the DBox*/
+ struct box_param *next; /**< pointer to the next box*/
} box_param_t;
-//! Box list parameters
+/** Box list parameters*/
typedef struct boxlist_param{
- box_param_t *first; //!< first box pointer of the list
- box_param_t *last; //!< last box pointer of the list
+ box_param_t *first; /**< first box pointer of the list*/
+ box_param_t *last; /**< last box pointer of the list*/
} boxlist_param_t;
* @param[in] TBox Box Type
* @return pointer to the structure of generate/found box parameters
*/
-box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[]);
+box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, const char TBox[]);
/**
* generate(search) box from code stream
* @param[in] TBox Box Type
* @return pointer to the structure of generate/found box parameters
*/
-box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t length, char TBox[]);
+box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t length, const char TBox[]);
/**
* generate child box from JP2 file at the given offset
* @param[in] TBox Box Type
* @return pointer to the structure of generate/found box parameters
*/
-box_param_t * gene_childboxbyType( box_param_t *superbox, Byte8_t offset, char TBox[]);
+box_param_t * gene_childboxbyType( box_param_t *superbox, Byte8_t offset, const char TBox[]);
/**
* get DBox offset
* @param[in] boxlist box list pointer
* @return found box pointer
*/
-box_param_t * search_box( char type[], boxlist_param_t *boxlist);
+box_param_t * search_box( const char type[], boxlist_param_t *boxlist);
/**
* print box parameters
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
boxheader_param_t * gene_boxheader( int fd, Byte8_t offset)
boxtype = (char *)fetch_bytes( fd, offset+4, 4);
headlen = 8;
- if( boxlen == 1){ // read XLBox
+ if( boxlen == 1){ /* read XLBox */
boxlen = fetch_8bytebigendian( fd, offset+8);
headlen = 16;
}
#include "byte_manager.h"
#include "box_manager.h"
-//! box header parameters
+/** box header parameters*/
typedef struct boxheader_param{
- Byte_t headlen; //!< header length 8 or 16
- Byte8_t length; //!< length of the reference Box
- char type[4]; //!< type of information in the DBox
- struct boxheader_param *next; //!< pointer to the next header box
+ Byte_t headlen; /**< header length 8 or 16*/
+ Byte8_t length; /**< length of the reference Box*/
+ char type[4]; /**< type of information in the DBox*/
+ struct boxheader_param *next; /**< pointer to the next header box*/
} boxheader_param_t;
*/
#include <stdio.h>
+#ifdef _WIN32
+#include <io.h>
+#else
#include <sys/types.h>
#include <unistd.h>
+#endif
#include <stdlib.h>
+#include <sys/stat.h>
#include "byte_manager.h"
#ifdef SERVER
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
Byte_t * fetch_bytes( int fd, long offset, int size)
*(stream+2) = (Byte_t) ((Byte4_t)(code & 0x0000ff00) >> 8);
*(stream+3) = (Byte_t) (code & 0x000000ff);
}
+
+Byte8_t get_filesize( int fd)
+{
+ struct stat sb;
+
+ if( fstat( fd, &sb) == -1){
+ fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
+ fprintf( FCGI_stderr, "Error: error in get_filesize( %d)\n", fd);
+ return 0;
+ }
+ return (Byte8_t)sb.st_size;
+}
#ifndef BYTE_MANAGER_H_
# define BYTE_MANAGER_H_
-//! 1Byte parameter type
+/** 1Byte parameter type*/
typedef unsigned char Byte_t;
-//! 2Byte parameter type
+/** 2Byte parameter type*/
typedef unsigned short int Byte2_t;
-//! 4Byte parameter type
-typedef unsigned int Byte4_t;
+/** 4Byte parameter type*/
+typedef unsigned int Byte4_t; /* FIXME: Is this portable ? */
-//! 8Byte parameter type
+/** 8Byte parameter type*/
typedef unsigned long long int Byte8_t;
*/
void modify_4Bytecode( Byte4_t code, Byte_t *stream);
+/**
+ * Get file size
+ *
+ * @param[in] fd file discriptor
+ * @return file size
+ */
+Byte8_t get_filesize( int fd);
+
#endif /* !BYTE_MANAGER_H_ */
{
if( !cid)
return;
-
- if( realloc( cache->cid, (cache->numOfcid+1)*sizeof(char *)) == NULL){
+
+ if( (cache->cid = realloc( cache->cid, (cache->numOfcid+1)*sizeof(char *))) == NULL){
fprintf( stderr, "failed to add new cid to cache table in add_cachecid()\n");
return;
}
#include "metadata_manager.h"
#include "ihdrbox_manager.h"
-//! cache parameters
+/** cache parameters*/
typedef struct cache_param{
- char *filename; //!< file name
- char *tid; //!< 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
+ char *filename; /**< file name*/
+ char *tid; /**< 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
+/**< 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
+ cache_param_t *first; /**< first cache pointer of the list*/
+ cache_param_t *last; /**< last cache pointer of the list*/
} cachelist_param_t;
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
-cachemodellist_param_t * gene_cachemodellist()
+cachemodellist_param_t * gene_cachemodellist(void)
{
cachemodellist_param_t *cachemodellist;
cachemodel->jppstream = true;
else
cachemodel->jppstream = false;
- } else{ // reqJPT
+ } else{ /* reqJPT */
if( target->jptstream)
cachemodel->jppstream = false;
else
cachemodel->next = NULL;
if( cachemodellist){
- if( cachemodellist->first) // there are one or more entries
+ if( cachemodellist->first) /* there are one or more entries */
cachemodellist->last->next = cachemodel;
- else // first entry
+ else /* first entry */
cachemodellist->first = cachemodel;
cachemodellist->last = cachemodel;
}
void print_cachemodel( cachemodel_param_t cachemodel)
{
target_param_t *target;
- Byte8_t TPnum; // num of tile parts in each tile
- Byte8_t Pmax; // max num of packets per tile
- int i, j, k, n;
+ Byte8_t TPnum; /* num of tile parts in each tile */
+ Byte8_t Pmax; /* max num of packets per tile */
+ Byte8_t i, j, k;
+ int n; /* FIXME: Is this large enough ? */
target = cachemodel.target;
fprintf( logstream, "\t tile header and precinct packet model:\n");
for( i=0; i<target->codeidx->SIZ.XTnum*target->codeidx->SIZ.YTnum; i++){
- fprintf( logstream, "\t tile.%d %d\n", i, cachemodel.th_model[i]);
+ fprintf( logstream, "\t tile.%llud %d\n", i, cachemodel.th_model[i]);
for( j=0; j<target->codeidx->SIZ.Csiz; j++){
- fprintf( logstream, "\t compo.%d: ", j);
+ fprintf( logstream, "\t compo.%llud: ", j);
Pmax = get_nmax( target->codeidx->precpacket[j]);
for( k=0; k<Pmax; k++)
fprintf( logstream, "%d", cachemodel.pp_model[j][i*Pmax+k]);
bool is_allsent( cachemodel_param_t cachemodel)
{
target_param_t *target;
- Byte8_t TPnum; // num of tile parts in each tile
- Byte8_t Pmax; // max num of packets per tile
- int i, j, k, n;
+ Byte8_t TPnum; /* num of tile parts in each tile */
+ Byte8_t Pmax; /* max num of packets per tile */
+ Byte8_t i, j, k;
+ int n; /* FIXME: is this large enough ? */
target = cachemodel.target;
#include "bool.h"
#include "target_manager.h"
-//! Cache model parameters
+/** Cache model parameters*/
typedef struct cachemodel_param{
- target_param_t *target; //!< reference pointer to the target
- bool jppstream; //!< return type, true: JPP-stream, false: JPT-stream
- bool mhead_model; //!< main header model, if sent, 1, else 0
- bool *tp_model; //!< dynamic array pointer of tile part model, if sent, 1, else 0
- bool *th_model; //!< dynamic array pointer of tile header model
- bool **pp_model; //!< dynamic array pointer of precint packet model
- struct cachemodel_param *next; //!< pointer to the next cache model
+ target_param_t *target; /**< reference pointer to the target*/
+ bool jppstream; /**< return type, true: JPP-stream, false: JPT-stream*/
+ bool mhead_model; /**< main header model, if sent, 1, else 0*/
+ bool *tp_model; /**< dynamic array pointer of tile part model, if sent, 1, else 0*/
+ bool *th_model; /**< dynamic array pointer of tile header model*/
+ bool **pp_model; /**< dynamic array pointer of precint packet model*/
+ struct cachemodel_param *next; /**< pointer to the next cache model*/
} cachemodel_param_t;
-//! Cache model list parameters
+/** Cache model list parameters*/
typedef struct cachemodellist_param{
- cachemodel_param_t *first; //!< first cache model pointer of the list
- cachemodel_param_t *last; //!< last cache model pointer of the list
+ cachemodel_param_t *first; /**< first cache model pointer of the list*/
+ cachemodel_param_t *last; /**< last cache model pointer of the list*/
} cachemodellist_param_t;
*
* @return pointer to the generated cache model list
*/
-cachemodellist_param_t * gene_cachemodellist();
+cachemodellist_param_t * gene_cachemodellist(void);
/**
* generate a cache model under a list
#include "cachemodel_manager.h"
#include "auxtrans_manager.h"
-//! maximum length of channel identifier
+/** maximum length of channel identifier*/
#define MAX_LENOFCID 30
-//! Channel parameters
+/** Channel parameters*/
typedef struct channel_param{
- cachemodel_param_t *cachemodel; //!< reference pointer to the cache model
- char cid[MAX_LENOFCID]; //!< channel identifier
- cnew_transport_t aux; //!< auxiliary transport
- // - 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
+ cachemodel_param_t *cachemodel; /**< reference pointer to the cache model*/
+ char cid[MAX_LENOFCID]; /**< channel identifier*/
+ cnew_transport_t aux; /**< auxiliary transport*/
+ /* - 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
+/** 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
+ channel_param_t *first; /**< first channel pointer of the list*/
+ channel_param_t *last; /**< last channel pointer of the list*/
} channellist_param_t;
#include "byte_manager.h"
-//! codestream parameters
+/** codestream parameters*/
typedef struct codestream_param{
- int fd; //!< file descriptor
- Byte8_t offset; //!< byte position of DBox (Box Contents) in the file
- Byte8_t length; //!< content length
+ int fd; /**< file descriptor*/
+ Byte8_t offset; /**< byte position of DBox (Box Contents) in the file*/
+ Byte8_t length; /**< content length*/
} codestream_param_t;
#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"
metadatalist = gene_metadatalist();
parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist);
- // cid registration
+ /* cid registration*/
if( target != NULL){
if((cache = search_cache( target, cachelist))){
if( tid != NULL)
char *CIDorTID, tmp[10];
cache_param_t *cache;
int fw, fh;
-
+
CIDorTID = receive_string( connected_socket);
if(!(cache = search_cacheBycid( CIDorTID, cachelist)))
receive_line( connected_socket, tmp);
fh = atoi( tmp);
- pnmstream = jpipstream_to_pnm( jpipstream, msgqueue, cache->csn, fw, fh, &cache->ihdrbox);
- ihdrbox = cache->ihdrbox;
+ ihdrbox = NULL;
+ pnmstream = jpipstream_to_pnm( jpipstream, msgqueue, cache->csn, fw, fh, &ihdrbox);
send_PNMstream( connected_socket, pnmstream, ihdrbox->width, ihdrbox->height, ihdrbox->nc, ihdrbox->bpc > 8 ? 255 : (1 << ihdrbox->bpc) - 1);
- if( pnmstream)
- free( pnmstream);
+ free( ihdrbox);
+ free( pnmstream);
}
void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist)
{
char *cid;
cache_param_t *cache;
+ boxcontents_param_t *boxcontents;
+ Byte_t *xmlstream;
cid = receive_string( connected_socket);
free( cid);
- boxcontents_param_t *boxcontents = cache->metadatalist->last->boxcontents;
- Byte_t *xmlstream = (Byte_t *)malloc( boxcontents->length);
+ boxcontents = cache->metadatalist->last->boxcontents;
+ xmlstream = (Byte_t *)malloc( boxcontents->length);
memcpy( xmlstream, jpipstream+boxcontents->offset, boxcontents->length);
send_XMLstream( connected_socket, xmlstream, boxcontents->length);
free( xmlstream);
free( cid);
}
+void handle_SIZreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_param_t *msgqueue, cachelist_param_t *cachelist)
+{
+ char *tid, *cid;
+ cache_param_t *cache;
+ Byte4_t width, height;
+
+ tid = receive_string( connected_socket);
+ cid = receive_string( connected_socket);
+
+ cache = NULL;
+
+ if( tid[0] != '0')
+ cache = search_cacheBytid( tid, cachelist);
+
+ if( !cache && cid[0] != '0')
+ cache = search_cacheBycid( cid, cachelist);
+
+ free( tid);
+ free( cid);
+
+ width = height = 0;
+ if( cache){
+ if( !cache->ihdrbox)
+ cache->ihdrbox = get_SIZ_from_jpipstream( jpipstream, msgqueue, cache->csn);
+ width = cache->ihdrbox->width;
+ height = cache->ihdrbox->height;
+ }
+ send_SIZstream( connected_socket, width, height);
+}
+
void handle_JP2saveMSG( SOCKET connected_socket, cachelist_param_t *cachelist, msgqueue_param_t *msgqueue, Byte_t *jpipstream)
{
char *cid;
*/
void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
+/**
+ * handle SIZ request message
+ *
+ * @param[in] connected_socket socket descriptor
+ * @param[in,out] cachelist cache list pointer
+ */
+void handle_SIZreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_param_t *msgqueue, cachelist_param_t *cachelist);
+
/**
* handle saving JP2 file request message
*
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
faixbox_param_t * gene_faixbox( box_param_t *box)
{
faix->version = fetch_DBox1byte( box, (pos+=1)-1);
- if( faix->version < 0 || 3< faix->version){
+ if( 3< faix->version){
fprintf( FCGI_stderr, "Error: version %d in faix box is reserved for ISO use.\n", faix->version);
free(faix);
return NULL;
if( faix->version%2){
subfaixbox8_param_t *subfaixbox;
- int i;
+ size_t i;
faix->subfaixbox.byte8_params = (subfaixbox8_param_t *)malloc( sizeof(subfaixbox8_param_t));
}
else{
subfaixbox4_param_t *subfaixbox;
- int i;
+ size_t i;
faix->subfaixbox.byte4_params = (subfaixbox4_param_t *)malloc( sizeof(subfaixbox4_param_t));
Byte4_t get_elemAux( faixbox_param_t *faix, Byte8_t elem_id, Byte8_t row_id)
{
+ Byte8_t nmax;
if( faix->version <2)
return -1;
- Byte8_t nmax = get_nmax( faix);
+ nmax = get_nmax( faix);
if( faix->version%2)
return faix->subfaixbox.byte8_params->aux[ row_id*nmax+elem_id];
else
#include "byte_manager.h"
#include "box_manager.h"
-//! 4byte parameters of a faix element
+/** 4byte parameters of a faix element*/
typedef struct faixelem4_param{
- Byte4_t off; //!< offset
- Byte4_t len; //!< length
+ Byte4_t off; /**< offset*/
+ Byte4_t len; /**< length*/
} faixelem4_param_t;
-//! 8byte parameters of a faix element
+/** 8byte parameters of a faix element*/
typedef struct faixelem8_param{
- Byte8_t off; //!< offset
- Byte8_t len; //!< length
+ Byte8_t off; /**< offset*/
+ Byte8_t len; /**< length*/
} faixelem8_param_t;
-//! 4byte parameters of fragment array index box
+/** 4byte parameters of fragment array index box*/
typedef struct subfaixbox4_param{
- Byte4_t nmax; //!< maximum number of valid elements in any row of the array
- Byte4_t m; //!< number of raws of the array
- faixelem4_param_t *elem; //!< dynamic array pointer of faix elements
- Byte4_t *aux; //!< dynamic array pointer of auxiliary
- //!info in each element for version 2 or 3
+ Byte4_t nmax; /**< maximum number of valid elements in any row of the array*/
+ Byte4_t m; /**< number of raws of the array*/
+ faixelem4_param_t *elem; /**< dynamic array pointer of faix elements*/
+ Byte4_t *aux; /**< dynamic array pointer of auxiliary*/
+ /**info in each element for version 2 or 3*/
} subfaixbox4_param_t;
-//! 8byte parameters of fragment array index box
+/** 8byte parameters of fragment array index box*/
typedef struct subfaixbox8_param{
- Byte8_t nmax; //!< maximum number of valid elements in any row of the array
- Byte8_t m; //!< number of raws of the array
- faixelem8_param_t *elem; //!< dynamic array pointer of faix elements
- Byte4_t *aux; //!< dynamic array pointer of auxiliary
- //!info in each element for version 2 or 3
+ Byte8_t nmax; /**< maximum number of valid elements in any row of the array*/
+ Byte8_t m; /**< number of raws of the array*/
+ faixelem8_param_t *elem; /**< dynamic array pointer of faix elements*/
+ Byte4_t *aux; /**< dynamic array pointer of auxiliary*/
+ /**info in each element for version 2 or 3*/
} subfaixbox8_param_t;
-//! variable sized parameters in fragment array index box
+/** variable sized parameters in fragment array index box*/
typedef union subfaixbox_param{
- subfaixbox4_param_t *byte4_params; //!< parameters with 4byte codes for version 0 or 2
- subfaixbox8_param_t *byte8_params; //!< parameters with 8byte codes for version 1 or 3
+ subfaixbox4_param_t *byte4_params; /**< parameters with 4byte codes for version 0 or 2*/
+ subfaixbox8_param_t *byte8_params; /**< parameters with 8byte codes for version 1 or 3*/
} subfaixbox_param_t;
-//! fragment array index box parameters
-//! I.3.2.4.2 Fragment Array Index box
+/** fragment array index box parameters*/
+/** I.3.2.4.2 Fragment Array Index box*/
typedef struct faixbox_param{
- Byte_t version; //!< Refer to the Table I.3 - Version values
- subfaixbox_param_t subfaixbox; //!< rest information in faixbox
+ Byte_t version; /**< Refer to the Table I.3 - Version values*/
+ subfaixbox_param_t subfaixbox; /**< rest information in faixbox*/
} faixbox_param_t;
#include "box_manager.h"
#include "metadata_manager.h"
-//! I.5.3.1 Image Header box
+/** I.5.3.1 Image Header box*/
typedef struct ihdrbox_param{
Byte4_t height;
Byte4_t width;
- Byte2_t nc; //!< number of components
- Byte_t bpc; //!< bits per component
+ Byte2_t nc; /**< number of components*/
+ Byte_t bpc; /**< bits per component*/
} ihdrbox_param_t;
/**
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
imgreg_param_t map_viewin2imgreg( const int fx, const int fy,
const int rx, const int ry,
int xwidth = *xmax - *xmin;
int ywidth = *ymax - *ymin;
- /// Find smaller frame size for now (i.e. assume "round-down").
+ /* Find smaller frame size for now (i.e. assume "round-down"). */
if ((*fx < 1 && xwidth != 0) || (*fy < 1 && ywidth != 0)){
fprintf( FCGI_stderr, "Frame size must be strictly positive");
exit(-1);
}
else if( *lev < maxlev-1 && ( *fx < xwidth || *fy < ywidth)) {
- // Simulate the ceil function.
+ /* Simulate the ceil function. */
*xmin = ceil((double)*xmin/(double)2.0);
*ymin = ceil((double)*ymin/(double)2.0);
*xmax = ceil((double)*xmax/(double)2.0);
fprintf( logstream, "\t roff: %d, %d\n", imgreg.ox, imgreg.oy);
fprintf( logstream, "\t rsiz: %d, %d\n", imgreg.sx, imgreg.sy);
fprintf( logstream, "\t level: %d\n", imgreg.level);
+#else
+ (void)imgreg;
#endif
}
#ifndef IMGREG_MANAGER_H_
# define IMGREG_MANAGER_H_
-//! image region parameters
+/** image region parameters */
typedef struct imgreg_param{
- int xosiz, yosiz; //!< offset from the origin of the reference grid
- //!at the decomposition level
- int fx, fy; //!< frame size (fsiz)
- int ox, oy; //!< offset (roff)
- int sx, sy; //!< region size (rsiz)
- int level; //!< decomposition level
+ int xosiz, yosiz; /** offset from the origin of the reference grid
+ at the decomposition level */
+ int fx, fy; /** frame size (fsiz) */
+ int ox, oy; /** offset (roff) */
+ int sx, sy; /** region size (rsiz) */
+ int level; /** decomposition level */
} imgreg_param_t;
#include <string.h>
#include <stdlib.h>
#include "imgsock_manager.h"
+#if _WIN32
+#define strncasecmp _strnicmp
+#endif
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"};
+ static const char *magicid[] = { "JPIP-stream", "PNM request", "XML request",
+ "TID request", "CID request", "CID destroy", "SIZ request", "JP2 save",
+ "QUIT"};
int i;
receive_size = receive_line( connected_socket, buf);
return NULL;
if( strstr( buf, "jp2")){
- // register cid option
+ /* register cid option*/
*target = strdup( buf);
if((linelen = receive_line( connected_socket, buf)) == 0)
jpipstream = receive_stream( connected_socket, datalen);
- // check EOR
+ /* check EOR*/
if( jpipstream[datalen-3] == 0x00 && ( jpipstream[datalen-2] == 0x01 || jpipstream[datalen-2] == 0x02))
*streamlen = datalen -3;
else
send_stream( connected_socket, xmlstream, length);
}
-void send_IDstream( SOCKET connected_socket, char *id, int idlen, char *label);
+void send_IDstream( SOCKET connected_socket, char *id, int idlen, const char *label);
void send_CIDstream( SOCKET connected_socket, char *cid, int cidlen)
{
send_IDstream( connected_socket, tid, tidlen, "TID");
}
-void send_IDstream( SOCKET connected_socket, char *id, int idlen, char *label)
+void send_IDstream( SOCKET connected_socket, char *id, int idlen, const char *label)
{
Byte_t header[4];
send_stream( connected_socket, pnmstream, pnmlen);
}
+void send_SIZstream( SOCKET connected_socket, unsigned int width, unsigned int height)
+{
+ Byte_t responce[9];
+
+ responce[0] = 'S';
+ responce[1] = 'I';
+ responce[2] = 'Z';
+ responce[3] = (width >> 16) & 0xff;
+ responce[4] = (width >> 8) & 0xff;
+ responce[5] = width & 0xff;
+ responce[6] = (height >> 16) & 0xff;
+ responce[7] = (height >> 8) & 0xff;
+ responce[8] = height & 0xff;
+
+ send_stream( connected_socket, responce, 9);
+}
+
void response_signal( SOCKET connected_socket, bool succeed)
{
Byte_t code;
#include "byte_manager.h"
#include "sock_manager.h"
-#define NUM_OF_MSGTYPES 8
-typedef enum eMSGTYPE{ JPIPSTREAM, PNMREQ, XMLREQ, TIDREQ, CIDREQ, CIDDST, JP2SAVE, QUIT, MSGERROR} msgtype_t;
+#define NUM_OF_MSGTYPES 9
+typedef enum eMSGTYPE{ JPIPSTREAM, PNMREQ, XMLREQ, TIDREQ, CIDREQ, CIDDST, SIZREQ, JP2SAVE, QUIT, MSGERROR} msgtype_t;
/**
* indeitify client message type
*
* @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] width width of the PGM/PPM image (different from the original image)
+ * @param [in] height height of the PGM/PPM image
* @param [in] numofcomp number of components of the image
* @param [in] maxval maximum value of the image (only 255 supported)
*/
*/
void send_CIDstream( SOCKET connected_socket, char *cid, int cidlen);
+/**
+ * send SIZ data stream to the client
+ *
+ * @param [in] connected_socket file descriptor of the connected socket
+ * @param [in] width original width of the image
+ * @param [in] height original height of the image
+ */
+void send_SIZstream( SOCKET connected_socket, unsigned int width, unsigned int height);
+
/**
* send response signal to the client
*
* client -> server: CID destroy\\n ciddata \n
* server -> client: 1 or 0 (of 1Byte response signal)
*
- *\section sec7 JP2 save
+ *\section sec7 SIZ request
+ * Get original size of image
+ *
+ * client -> server: SIZ request\\n tidstring\\n cidstring\\n \n
+ * server -> client: SIZ (3Byte) width (3Byte Big endian) height (3Byte Big endian)
+ *
+ *\section sec8 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
+ *\section sec9 QUIT
* Quit the opj_dec_server program
*
* client -> server: quit or QUIT
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
#include <string.h>
#include "bool.h"
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
/**
* chekc JP2 box indexing
box_param_t *cidx;
metadatalist_param_t *metadatalist;
boxlist_param_t *toplev_boxlist;
- struct stat sb;
-
- if( fstat( fd, &sb) == -1){
- fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
- return NULL;
- }
+ Byte8_t filesize;
- if( !(toplev_boxlist = get_boxstructure( fd, 0, sb.st_size))){
+ if( !(filesize = get_filesize( fd)))
+ return NULL;
+
+ if( !(toplev_boxlist = get_boxstructure( fd, 0, filesize))){
fprintf( FCGI_stderr, "Error: Not correctl JP2 format\n");
return NULL;
}
print_faixbox( index.tilepart);
fprintf( logstream, "Tile header information: \n");
- for( i=0; i<index.SIZ.XTnum*index.SIZ.YTnum ;i++)
+ for( i=0; i<(int)(index.SIZ.XTnum*index.SIZ.YTnum);i++)
print_mhixbox( index.tileheader[i]);
fprintf( logstream, "Precinct packet information: \n");
delete_metadatalist( &((*index)->metadatalist));
- free( (*index)->COD.XPsiz);
- free( (*index)->COD.YPsiz);
+ delete_COD( (*index)->COD);
delete_faixbox( &((*index)->tilepart));
- for( i=0; i< (*index)->SIZ.XTnum*(*index)->SIZ.YTnum ;i++)
+ for( i=0; i< (int)((*index)->SIZ.XTnum*(*index)->SIZ.YTnum);i++)
delete_mhixbox( &((*index)->tileheader[i]));
free( (*index)->tileheader);
free(*index);
}
+void delete_COD( CODmarker_param_t COD)
+{
+ if( COD.XPsiz) free( COD.XPsiz);
+ if( COD.YPsiz) free( COD.YPsiz);
+}
+
bool check_JP2boxidx( boxlist_param_t *toplev_boxlist)
{
box_param_t *iptr, *fidx, *prxy;
box_param_t *cidx, *jp2c;
+ Byte8_t off;
+ Byte8_t len;
+ int pos;
+ Byte8_t ooff;
+ boxheader_param_t *obh;
+ Byte_t ni;
+ Byte8_t ioff;
+ boxheader_param_t *ibh;
iptr = search_box( "iptr", toplev_boxlist);
fidx = search_box( "fidx", toplev_boxlist);
jp2c = search_box( "jp2c", toplev_boxlist);
prxy = gene_childboxbyType( fidx, 0, "prxy");
- Byte8_t off = fetch_DBox8bytebigendian( iptr, 0);
+ off = fetch_DBox8bytebigendian( iptr, 0);
if( off != fidx->offset)
fprintf( FCGI_stderr, "Reference File Index box offset in Index Finder box not correct\n");
- Byte8_t len = fetch_DBox8bytebigendian( iptr, 8);
+ len = fetch_DBox8bytebigendian( iptr, 8);
if( len != fidx->length)
fprintf( FCGI_stderr, "Reference File Index box length in Index Finder box not correct\n");
-
- int pos = 0;
- Byte8_t ooff = fetch_DBox8bytebigendian( prxy, pos);
+ pos = 0;
+ ooff = fetch_DBox8bytebigendian( prxy, pos);
if( ooff != jp2c->offset)
fprintf( FCGI_stderr, "Reference jp2c offset in prxy box not correct\n");
pos += 8;
- boxheader_param_t *obh = gene_childboxheader( prxy, pos);
+ obh = gene_childboxheader( prxy, pos);
if( obh->length != jp2c->length || strncmp( obh->type, "jp2c",4)!=0)
fprintf( FCGI_stderr, "Reference jp2c header in prxy box not correct\n");
pos += obh->headlen;
free(obh);
- Byte_t ni = fetch_DBox1byte( prxy, pos);
+ ni = fetch_DBox1byte( prxy, pos);
if( ni != 1){
fprintf( FCGI_stderr, "Multiple indexes not supported\n");
return false;
}
pos += 1;
- Byte8_t ioff = fetch_DBox8bytebigendian( prxy, pos);
+ ioff = fetch_DBox8bytebigendian( prxy, pos);
if( ioff != cidx->offset)
fprintf( FCGI_stderr, "Reference cidx offset in prxy box not correct\n");
pos += 8;
- boxheader_param_t *ibh = gene_childboxheader( prxy, pos);
+ ibh = gene_childboxheader( prxy, pos);
if( ibh->length != cidx->length || strncmp( ibh->type, "cidx",4)!=0)
fprintf( FCGI_stderr, "Reference cidx header in prxy box not correct\n");
pos += ibh->headlen;
bool set_cptrdata( box_param_t *cidx_box, index_param_t *jp2idx)
{
- box_param_t *box; //!< cptr box
+ box_param_t *box; /**< cptr box*/
Byte2_t dr, cont;
if( !(box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "cptr")))
return false;
- // DR: Data Reference.
- // If 0, the codestream or its Fragment Table box exists in the current file
+ /* DR: Data Reference. */
+ /* If 0, the codestream or its Fragment Table box exists in the current file*/
if(( dr = fetch_DBox2bytebigendian( box, 0))){
fprintf( FCGI_stderr, "Error: Codestream not present in current file\n");
free( box);
return false;
}
- // CONT: Container Type
- // If 0, the entire codestream appears as a contiguous range of
- // bytes within its file or resource.
+ /* CONT: Container Type*/
+ /* If 0, the entire codestream appears as a contiguous range of*/
+ /* bytes within its file or resource.*/
if(( cont = fetch_DBox2bytebigendian( box, 2))){
fprintf( FCGI_stderr, "Error: Can't cope with fragmented codestreams yet\n");
free( box);
bool set_tpixdata( box_param_t *cidx_box, index_param_t *jp2idx)
{
- box_param_t *tpix_box; //!< tpix box
- box_param_t *faix_box; //!< faix box
+ box_param_t *tpix_box; /**< tpix box*/
+ box_param_t *faix_box; /**< faix box*/
if( !(tpix_box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "tpix"))){
fprintf( FCGI_stderr, "Error: tpix box not present in cidx box\n");
bool set_ppixdata( box_param_t *cidx_box, index_param_t *jp2idx)
{
box_param_t *ppix_box, *faix_box, *manf_box;
- manfbox_param_t *manf; //!< manf
- boxheader_param_t *bh; //!< box headers
- faixbox_param_t *faix; //!< faix
+ manfbox_param_t *manf; /**< manf*/
+ boxheader_param_t *bh; /**< box headers*/
+ faixbox_param_t *faix; /**< faix*/
Byte8_t inbox_offset;
int comp_idx;
COD->YPsiz = (Byte4_t *)malloc( (COD->numOfdecomp+1)*sizeof(Byte4_t));
for( i=0; i<=COD->numOfdecomp; i++){
- //precinct size
+ /*precinct size*/
COD->XPsiz[i] = pow( 2, fetch_marker1byte( codmkr, 12+i) & 0x0F);
COD->YPsiz[i] = pow( 2,(fetch_marker1byte( codmkr, 12+i) & 0xF0) >> 4);
}
}
+/* very very generic name see NOMINMAX */
+#ifdef min
+#undef min
+#endif
+#ifdef max
+#undef max
+#endif
Byte4_t max( Byte4_t n1, Byte4_t n2);
Byte4_t min( Byte4_t n1, Byte4_t n2);
return tile_Yrange.maxvalue - tile_Yrange.minvalue;
}
+/* TODO: what is this code doing ? will all compiler be able to optimize the following ? */
Byte4_t max( Byte4_t n1, Byte4_t n2)
{
if( n1 < n2)
#include "mhixbox_manager.h"
#include "bool.h"
-//! progression order
+/** progression order */
typedef enum porder {
PROG_UNKNOWN = -1, /**< place-holder */
LRCP = 0, /**< layer-resolution-component-precinct order */
CPRL = 4 /**< component-precinct-resolution-layer order */
} porder_t;
-//! A.5.1 Image and tile size (SIZ)
+/** A.5.1 Image and tile size (SIZ)*/
typedef struct SIZmarker_param{
- Byte2_t Lsiz; //!< length of marker segment excluding the marker
- Byte2_t Rsiz; //!< capabilities that a decoder needs
- Byte4_t Xsiz; //!< width of the reference grid
- Byte4_t Ysiz; //!< height of the reference grid
- Byte4_t XOsiz; //!< horizontal offset from the origin of the reference grid to the left side of the image area
- Byte4_t YOsiz; //!< vertical offset from the origin of the reference grid to the top side of the image area
- Byte4_t XTsiz; //!< width of one reference tile with respect to the reference grid
- Byte4_t YTsiz; //!< height of one reference tile with respect to the reference grid
- Byte4_t XTOsiz; //!< horizontal offset from the origin of the reference grid to the left side of the first tile
- Byte4_t YTOsiz; //!< vertical offset from the origin of the reference grid to the top side of the first tile
- Byte4_t XTnum; //!< number of tiles in horizontal direction
- Byte4_t YTnum; //!< number of tiles in vertical direction
- Byte2_t Csiz; //!< number of the components in the image
- Byte_t Ssiz[3]; //!< precision (depth) in bits and sign of the component samples
- Byte_t XRsiz[3]; //!< horizontal separation of a sample of component with respect to the reference grid
- Byte_t YRsiz[3]; //!< vertical separation of a sample of component with respect to the reference grid
+ Byte2_t Lsiz; /**< length of marker segment excluding the marker*/
+ Byte2_t Rsiz; /**< capabilities that a decoder needs*/
+ Byte4_t Xsiz; /**< width of the reference grid*/
+ Byte4_t Ysiz; /**< height of the reference grid*/
+ Byte4_t XOsiz; /**< horizontal offset from the origin of the reference grid to the left side of the image area*/
+ Byte4_t YOsiz; /**< vertical offset from the origin of the reference grid to the top side of the image area*/
+ Byte4_t XTsiz; /**< width of one reference tile with respect to the reference grid*/
+ Byte4_t YTsiz; /**< height of one reference tile with respect to the reference grid*/
+ Byte4_t XTOsiz; /**< horizontal offset from the origin of the reference grid to the left side of the first tile*/
+ Byte4_t YTOsiz; /**< vertical offset from the origin of the reference grid to the top side of the first tile*/
+ Byte4_t XTnum; /**< number of tiles in horizontal direction*/
+ Byte4_t YTnum; /**< number of tiles in vertical direction*/
+ Byte2_t Csiz; /**< number of the components in the image*/
+ Byte_t Ssiz[3]; /**< precision (depth) in bits and sign of the component samples*/
+ Byte_t XRsiz[3]; /**< horizontal separation of a sample of component with respect to the reference grid*/
+ Byte_t YRsiz[3]; /**< vertical separation of a sample of component with respect to the reference grid*/
} SIZmarker_param_t;
-//! A.6.1 Coding style default (COD)
+/** A.6.1 Coding style default (COD)*/
typedef struct CODmarker_param{
- Byte2_t Lcod; //!< length of marker segment excluding the marker
- Byte_t Scod; //!< Coding style for all components
- porder_t prog_order; //!< progression order
- Byte2_t numOflayers; //!< number of layers
- Byte_t numOfdecomp; //!< number of decompositions levels
- Byte4_t *XPsiz; //!< dynamic array of precinct width at successive resolution level in order
- Byte4_t *YPsiz; //!< dynamic array of precinct height at successive resolution level in order
+ Byte2_t Lcod; /**< length of marker segment excluding the marker*/
+ Byte_t Scod; /**< Coding style for all components*/
+ porder_t prog_order; /**< progression order*/
+ Byte2_t numOflayers; /**< number of layers*/
+ Byte_t numOfdecomp; /**< number of decompositions levels*/
+ Byte4_t *XPsiz; /**< dynamic array of precinct width at successive resolution level in order*/
+ Byte4_t *YPsiz; /**< dynamic array of precinct height at successive resolution level in order*/
} CODmarker_param_t;
-//! index parameters
+/** index parameters*/
typedef struct index_param{
- metadatalist_param_t *metadatalist; //!< metadata-bin list
- Byte8_t offset; //!< codestream offset
- Byte8_t length; //!< codestream length
- Byte8_t mhead_length; //!< main header length
- SIZmarker_param_t SIZ; // !< SIZ marker information
- CODmarker_param_t COD; // !< COD marker information
- faixbox_param_t *tilepart; //!< tile part information from tpix box
- mhixbox_param_t **tileheader; //!< dynamic array of tile header information from thix box
- faixbox_param_t **precpacket; //!< dynamic array of precint packet information from ppix box
+ metadatalist_param_t *metadatalist; /**< metadata-bin list*/
+ Byte8_t offset; /**< codestream offset*/
+ Byte8_t length; /**< codestream length */
+ Byte8_t mhead_length; /**< main header length */
+ SIZmarker_param_t SIZ; /**< SIZ marker information*/
+ CODmarker_param_t COD; /**< COD marker information*/
+ faixbox_param_t *tilepart; /**< tile part information from tpix box*/
+ mhixbox_param_t **tileheader; /**< dynamic array of tile header information from thix box*/
+ faixbox_param_t **precpacket; /**< dynamic array of precint packet information from ppix box*/
} index_param_t;
*/
void delete_index( index_param_t **index);
-//! 1-dimensional range parameters
+/**
+ * delete dynamic arrays in COD marker
+ *
+ * @param[in] COD COD marker information
+ */
+void delete_COD( CODmarker_param_t COD);
+
+
+/** 1-dimensional range parameters*/
typedef struct range_param{
- Byte4_t minvalue; //!< minimal value
- Byte4_t maxvalue; //!< maximal value
+ Byte4_t minvalue; /**< minimal value*/
+ Byte4_t maxvalue; /**< maximal value*/
} range_param_t;
/**
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
/**
if( ptr->phld){
if( strncmp( (char *)ptr->phld->OrigBH+4, "jp2c", 4) == 0){
jp2cDBoxOffset = *jp2len + ptr->phld->OrigBHlen;
- jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); // header only
+ jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); /* header only */
jp2cDBoxlen = *jp2len - jp2cDBoxOffset;
}
else
- jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); // header only
+ jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); /* header only */
}
jp2stream = add_msgstream( ptr, jpipstream, jp2stream, jp2len);
ptr = ptr->next;
}
ptr = msgqueue->first;
while(( ptr = search_message( EXT_TILE_MSG, tileID, csn, ptr))!=NULL){
- if( ptr->aux > mindeclev){
+ if( ptr->aux > mindeclev){ /* FIXME: pointer comparison ? */
if( ptr->bin_offset == binOffset){
found = true;
j2kstream = add_msgstream( ptr, jpipstream, j2kstream, j2klen);
}
if( max_reslev < COD.numOfdecomp)
- if( !modify_mainheader( j2kstream, max_reslev, SIZ, COD, j2klen))
+ if( !modify_mainheader( j2kstream, max_reslev, SIZ, COD, j2klen)){
+ delete_COD( COD);
return j2kstream;
+ }
j2kstream = add_EOC( j2kstream, j2klen);
+ delete_COD( COD);
+
return j2kstream;
}
message_param_t * search_message( Byte8_t class_id, Byte8_t in_class_id, Byte8_t csn, message_param_t *msg)
{
while( msg != NULL){
- if( in_class_id == -1){
+ if( in_class_id == (Byte8_t)-1){
if( msg->class_id == class_id && msg->csn == csn)
return msg;
}
return buf;
}
+
+Byte_t * recons_j2kmainhead( msgqueue_param_t *msgqueue, Byte_t *jpipstream, Byte8_t csn, Byte8_t *j2klen)
+{
+ *j2klen = 0;
+ return add_mainhead_msgstream( msgqueue, jpipstream, NULL, csn, j2klen);
+}
*/
Byte_t * recons_jp2( msgqueue_param_t *msgqueue, Byte_t *jpipstream, Byte8_t csn, Byte8_t *jp2len);
+/**
+ * reconstruct j2k codestream of mainheader from message queue
+ *
+ * @param[in] msgqueue message queue pointer
+ * @param[in] jpipstream original jpt- jpp- stream
+ * @param[in] csn codestream number
+ * @param[out] j2klen pointer to the j2k codestream length
+ * @return generated reconstructed j2k codestream
+ */
+Byte_t * recons_j2kmainhead( msgqueue_param_t *msgqueue, Byte_t *jpipstream, Byte8_t csn, Byte8_t *j2klen);
#endif /* !JP2K_ENCODER_H_ */
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target)
#ifndef SERVER
fprintf( logstream, "local log: close all\n");
#endif
- // all channels associatd with the session will be closed
+ /* 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
+ /* check if all entry belonging to the same session */
for( i=0, cclose=query_param.cclose; i<query_param.numOfcclose; i++, cclose += (strlen(cclose)+1)){
- // In case of the first entry of close cid
+ /* In case of the first entry of close cid */
if( *cursession == NULL){
if( !search_session_and_channel( cclose, sessionlist, cursession, curchannel))
return false;
}
- else // second or more entry of close cid
+ else /* second or more entry of close cid */
if( !(*curchannel=search_channel( cclose, (*cursession)->channellist))){
fprintf( FCGI_stdout, "Reason: Cclose id %s is from another session\r\n", cclose);
return false;
}
}
- // delete channels
+ /* delete channels */
for( i=0, cclose=query_param.cclose; i<query_param.numOfcclose; i++, cclose += (strlen(cclose)+1)){
*curchannel = search_channel( cclose, (*cursession)->channellist);
delete_channel( curchannel, (*cursession)->channellist);
}
if( (*cursession)->channellist->first == NULL || (*cursession)->channellist->last == NULL)
- // In case of empty session
+ /* In case of empty session */
delete_session( cursession, sessionlist);
}
return true;
* @param[in] query_param structured query
* @param[in] metadatalist pointer to metadata bin list
* @param[in,out] msgqueue message queue pointer
+ * @return if succeeded (true) or failed (false)
*/
-void enqueue_metabins( query_param_t query_param, metadatalist_param_t *metadatalist, msgqueue_param_t *msgqueue);
+bool enqueue_metabins( query_param_t query_param, metadatalist_param_t *metadatalist, msgqueue_param_t *msgqueue);
bool gene_JPIPstream( query_param_t query_param,
index_param_t *codeidx;
cachemodel_param_t *cachemodel;
- if( !cursession || !curchannel){ // stateless
+ 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
+ else{ /* session */
cachemodel = curchannel->cachemodel;
target = cachemodel->target;
*msgqueue = gene_msgqueue( false, cachemodel);
}
}
- //meta
+ /*meta*/
if( query_param.box_type[0][0] != 0 && query_param.len != 0)
- enqueue_metabins( query_param, codeidx->metadatalist, *msgqueue);
+ if( !enqueue_metabins( query_param, codeidx->metadatalist, *msgqueue))
+ return false;
+
+ if( query_param.metadata_only)
+ return true;
- // image codestream
- if( query_param.fx > 0 && query_param.fy > 0){
- if( !cachemodel->mhead_model && query_param.len != 0)
+ /* main header */
+ if( !cachemodel->mhead_model && query_param.len != 0)
enqueue_mainheader( *msgqueue);
+
+ /* image codestream */
+ if( (query_param.fx > 0 && query_param.fy > 0))
enqueue_imagedata( query_param, *msgqueue);
- }
+
return true;
}
index_param_t *codeidx;
imgreg_param_t imgreg;
range_param_t tile_Xrange, tile_Yrange;
- int u, v, tile_id;
+ Byte4_t 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
+ if( !(msgqueue->cachemodel->jppstream) && get_nmax( codeidx->tilepart) == 1) /* normally not the case */
numOfreslev = 1;
else
numOfreslev = codeidx->COD.numOfdecomp+1;
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
+ if( tile_Xrange.maxvalue <= (Byte4_t)(imgreg.xosiz + imgreg.ox) ||
+ tile_Xrange.minvalue >= (Byte4_t)(imgreg.xosiz + imgreg.ox + imgreg.sx) ||
+ tile_Yrange.maxvalue <= (Byte4_t)(imgreg.yosiz + imgreg.oy) ||
+ tile_Yrange.minvalue >= (Byte4_t)(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);
+ else if( tile_Xrange.minvalue >= (Byte4_t)(imgreg.xosiz + imgreg.ox) &&
+ tile_Xrange.maxvalue <= (Byte4_t)(imgreg.xosiz + imgreg.ox + imgreg.sx) &&
+ tile_Yrange.minvalue >= (Byte4_t)(imgreg.yosiz + imgreg.oy) &&
+ tile_Yrange.maxvalue <= (Byte4_t)(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);
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);
+ /* 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;
+ /* FIXME: The following code is suspicious it implicitely cast an unsigned int to int, which truncates values */
+ xmin = tile_Xrange.minvalue >= (Byte4_t)(imgreg.xosiz + imgreg.ox) ? 0 : imgreg.xosiz + imgreg.ox - tile_Xrange.minvalue;
+ xmax = tile_Xrange.maxvalue <= (Byte4_t)(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 >= (Byte4_t)(imgreg.yosiz + imgreg.oy) ? 0 : imgreg.yosiz + imgreg.oy - tile_Yrange.minvalue;
+ ymax = tile_Yrange.maxvalue <= (Byte4_t)(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
}
+/* MM: shouldnt xmin/xmax be Byte4_t instead ? */
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;
xmaxP = XTsiz-1;
if( xmaxP < xmin || xminP > xmax || ymaxP < ymin || yminP > ymax){
- // Precinct completely excluded from view-window
+ /* Precinct completely excluded from view-window */
}
else if( xminP >= xmin && xmaxP <= xmax && yminP >= ymin && ymaxP <= ymax){
- // Precinct completely contained within view-window
- // high priority
+ /* 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
+ /* Precinct partially overlaps view-window
+ low priority */
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)
+bool 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
+ fprintf( FCGI_stdout, "Status: 501\r\n");
+ fprintf( FCGI_stdout, "Reason: metareq with all box-property * not implemented\r\n");
+ return false;
}
else{
int idx = search_metadataidx( query_param.box_type[i], metadatalist);
if( idx != -1)
enqueue_metadata( idx, msgqueue);
+ else{
+ fprintf( FCGI_stdout, "Status: 400\r\n");
+ fprintf( FCGI_stdout, "Reason: box-type %.4s not found\r\n", query_param.box_type[i]);
+ return false;
+ }
}
}
+ return true;
}
#include "jpipstream_manager.h"
#include "jp2k_encoder.h"
#include "jp2k_decoder.h"
+#include "ihdrbox_manager.h"
+#include "j2kheader_manager.h"
Byte_t * update_JPIPstream( Byte_t *newstream, int newstreamlen, Byte_t *cache_stream, int *streamlen)
{
return stream;
}
-void save_codestream( Byte_t *codestream, Byte8_t streamlen, char *fmt)
+void save_codestream( Byte_t *codestream, Byte8_t streamlen, const char *fmt)
{
time_t timer;
struct tm *t_st;
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);
+ if( fwrite( codestream, streamlen, 1, fp) != 1)
+ fprintf( stderr, "Error: failed to write codestream to file %s\n", filename);
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
+ Byte_t *j2kstream; /* j2k or jp2 codestream */
Byte8_t j2klen;
FILE *fp;
char j2kfname[] = "tmp.j2k";
return pnmstream;
}
+
+ihdrbox_param_t * get_SIZ_from_jpipstream( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn)
+{
+ ihdrbox_param_t *ihdrbox;
+ Byte_t *j2kstream;
+ Byte8_t j2klen;
+ SIZmarker_param_t SIZ;
+
+ j2kstream = recons_j2kmainhead( msgqueue, jpipstream, csn, &j2klen);
+ if( !get_mainheader_from_j2kstream( j2kstream, &SIZ, NULL)){
+ free( j2kstream);
+ return NULL;
+ }
+
+ ihdrbox = (ihdrbox_param_t *)malloc( sizeof(ihdrbox_param_t));
+
+ ihdrbox->width = SIZ.Xsiz;
+ ihdrbox->height = SIZ.Ysiz;
+ ihdrbox->nc = SIZ.Csiz;
+ ihdrbox->bpc = SIZ.Ssiz[0];
+
+ free( j2kstream);
+
+ return ihdrbox;
+}
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);
+void save_codestream( Byte_t *codestream, Byte8_t streamlen, const 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);
+
+ihdrbox_param_t * get_SIZ_from_jpipstream( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn);
}
}
-boxheader_param_t * search_boxheader( char type[], manfbox_param_t *manf)
+boxheader_param_t * search_boxheader( const char type[], manfbox_param_t *manf)
{
boxheader_param_t *found;
#include "boxheader_manager.h"
-//! manifest box parameters
-//! I.3.2.3 Manifest box
+/** manifest box parameters*/
+/** I.3.2.3 Manifest box*/
typedef struct manfbox_param{
- boxheader_param_t *first; //!< top of the box header list
+ boxheader_param_t *first; /**< top of the box header list*/
} manfbox_param_t;
* @param[in] manf manf box pointer
* @return found box pointer
*/
-boxheader_param_t * search_boxheader( char type[], manfbox_param_t *manf);
+boxheader_param_t * search_boxheader( const char type[], manfbox_param_t *manf);
#endif /* !MANFBOX_MANAGER_H_ */
#include "codestream_manager.h"
-//! Marker parameters
+/** Marker parameters*/
typedef struct marker_param{
- codestream_param_t cs; //!< corresponding codestream
- Byte2_t code; //!< marker code
- Byte8_t offset; //!< offset relative to the start of the codestream ( including the length parameter but not the marker itself)
- Byte2_t length; //!< marker segment length
+ codestream_param_t cs; /**< corresponding codestream*/
+ Byte2_t code; /**< marker code*/
+ Byte8_t offset; /**< offset relative to the start of the codestream ( including the length parameter but not the marker itself)*/
+ Byte2_t length; /**< marker segment length*/
} marker_param_t;
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "metadata_manager.h"
#include <stdio.h>
#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
#include <string.h>
-#include "metadata_manager.h"
#ifdef SERVER
#include "fcgi_stdio.h"
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
-metadatalist_param_t * gene_metadatalist()
+metadatalist_param_t * gene_metadatalist(void)
{
metadatalist_param_t *list;
placeholderlist_param_t *phldlist;
placeholder_param_t *phld;
int idx;
- struct stat sb;
-
- if( fstat( fd, &sb) == -1){
- fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
- return NULL;
- }
+ Byte8_t filesize;
- if( !(toplev_boxlist = get_boxstructure( fd, 0, sb.st_size))){
+ if(!(filesize = get_filesize( fd)))
+ return NULL;
+
+ if( !(toplev_boxlist = get_boxstructure( fd, 0, filesize))){
fprintf( FCGI_stderr, "Error: Not correctl JP2 format\n");
return NULL;
}
phldlist = gene_placeholderlist();
metadatalist = gene_metadatalist();
- delete_box_in_list_by_type( "iptr", toplev_boxlist);
- delete_box_in_list_by_type( "cidx", toplev_boxlist);
- delete_box_in_list_by_type( "fidx", toplev_boxlist);
-
box = toplev_boxlist->first;
idx = 0;
while( box){
if((*metadata)->boxcontents)
free((*metadata)->boxcontents);
#ifndef SERVER
- // fprintf( logstream, "local log: Metadata-bin: %d deleted\n", (*metadata)->idx);
+ /* fprintf( logstream, "local log: Metadata-bin: %d deleted\n", (*metadata)->idx);*/
#endif
free( *metadata);
}
void print_metadata( metadata_param_t *metadata)
{
+ boxcontents_param_t *boxcont;
fprintf( logstream, "metadata-bin %d info:\n", metadata->idx);
print_allbox( metadata->boxlist);
print_allplaceholder( metadata->placeholderlist);
- boxcontents_param_t *boxcont = metadata->boxcontents;
+ boxcont = metadata->boxcontents;
if( boxcont)
fprintf( logstream, "box contents:\n"
"\t offset: %lld %#llx\n"
*/
#ifndef METADATA_MANAGER_H_
-# define METADATA_MANAGER_H_
+#define METADATA_MANAGER_H_
#include "box_manager.h"
#include "placeholder_manager.h"
typedef struct boxcontents_param{
- Byte8_t offset; //!< byte position of the box contents in the file
- Byte8_t length; //!< length of the box contents
+ Byte8_t offset; /**< byte position of the box contents in the file*/
+ Byte8_t length; /**< length of the box contents*/
} boxcontents_param_t;
-//! metadata-bin parameters
+/** metadata-bin parameters*/
typedef struct metadata_param{
- int idx; //!< index number
- boxlist_param_t *boxlist; //!< box list
- placeholderlist_param_t *placeholderlist; //!< placeholder box list
- boxcontents_param_t *boxcontents; //!< box contens in case of no boxlist and placeholderlist
- struct metadata_param *next; //!< pointer to the next metadata-bin
+ int idx; /**< index number*/
+ boxlist_param_t *boxlist; /**< box list*/
+ placeholderlist_param_t *placeholderlist; /**< placeholder box list*/
+ boxcontents_param_t *boxcontents; /**< box contens in case of no boxlist and placeholderlist*/
+ struct metadata_param *next; /**< pointer to the next metadata-bin*/
} metadata_param_t;
-//! metadata-bin list parameters
+/** metadata-bin list parameters*/
typedef struct metadatalist_param{
- metadata_param_t *first; //!< first metadata-bin pointer of the list
- metadata_param_t *last; //!< last metadata-bin pointer of the list
+ metadata_param_t *first; /**< first metadata-bin pointer of the list*/
+ metadata_param_t *last; /**< last metadata-bin pointer of the list*/
} metadatalist_param_t;
*
* @return pointer to the generated metadata list
*/
-metadatalist_param_t * gene_metadatalist();
+metadatalist_param_t * gene_metadatalist(void);
/**
#include "byte_manager.h"
#include "box_manager.h"
-//! Marker index parameters
+/** Marker index parameters*/
typedef struct markeridx_param{
- Byte2_t code; //!< marker code
- Byte2_t num_remain; //!< remining number of the same marker index segments listed immediately
- Byte8_t offset; //!< offset relative to the start of the
- //!codestream ( including the length
- //!parameter but not the marker itself)
- Byte2_t length; //!< marker segment length
- struct markeridx_param *next; //!< pointer to the next markeridx
+ Byte2_t code; /**< marker code*/
+ Byte2_t num_remain; /**< remining number of the same marker index segments listed immediately*/
+ Byte8_t offset; /**< offset relative to the start of the*/
+ /**codestream ( including the length*/
+ /**parameter but not the marker itself)*/
+ Byte2_t length; /**< marker segment length*/
+ struct markeridx_param *next; /**< pointer to the next markeridx*/
} markeridx_param_t;
-//! header index table box parameters
-//! I.3.2.4.3 Header Index Table box
+/** header index table box parameters*/
+/** I.3.2.4.3 Header Index Table box*/
typedef struct mhixbox_param{
- Byte8_t tlen; //!< length ( total length of the main
- //!header or of the first tile-part header)
- markeridx_param_t *first; //!< first marker index pointer of the list
+ Byte8_t tlen; /**< length ( total length of the main*/
+ /**header or of the first tile-part header)*/
+ markeridx_param_t *first; /**< first marker index pointer of the list*/
} mhixbox_param_t;
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
-#include <unistd.h>
#include <sys/stat.h>
#include <string.h>
#include <ctype.h>
+#ifdef _WIN32
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
#include "msgqueue_manager.h"
#include "metadata_manager.h"
#include "index_manager.h"
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
msgqueue_param_t * gene_msgqueue( bool stateless, cachemodel_param_t *cachemodel)
{
msg->csn = target->csn;
msg->bin_offset = 0;
msg->length = codeidx->mhead_length;
- msg->aux = 0; // non exist
+ msg->aux = 0; /* non exist*/
msg->res_offset = codeidx->offset;
msg->phld = NULL;
msg->next = NULL;
msg->class_id = TILE_HEADER_MSG;
msg->csn = target->csn;
msg->bin_offset = 0;
- msg->length = codeidx->tileheader[tile_id]->tlen-2; // SOT marker segment is removed
- msg->aux = 0; // non exist
- msg->res_offset = codeidx->offset + get_elemOff( codeidx->tilepart, 0, tile_id) + 2; // skip SOT marker seg
+ msg->length = codeidx->tileheader[tile_id]->tlen-2; /* SOT marker segment is removed*/
+ msg->aux = 0; /* non exist*/
+ msg->res_offset = codeidx->offset + get_elemOff( codeidx->tilepart, 0, tile_id) + 2; /* skip SOT marker seg*/
msg->phld = NULL;
msg->next = NULL;
cachemodel_param_t *cachemodel;
target_param_t *target;
bool *tp_model;
- Byte8_t numOftparts; // num of tile parts par tile
+ Byte8_t numOftparts; /* num of tile parts par tile*/
Byte8_t numOftiles;
index_param_t *codeidx;
faixbox_param_t *tilepart;
class_id = (numOftparts==1) ? TILE_MSG : EXT_TILE_MSG;
- if( tile_id < 0 || numOftiles <= tile_id){
+ if( tile_id < 0 || (int)numOftiles <= tile_id){
fprintf( FCGI_stderr, "Error, Invalid tile-id %d\n", tile_id);
return;
}
tp_model = &cachemodel->tp_model[ tile_id*numOftparts];
binOffset=0;
- for( i=0; i<numOftparts-level; i++){
+ for( i=0; i<(int)numOftparts-level; i++){
binLength = get_elemLen( tilepart, i, tile_id);
if( !tp_model[i]){
msg = (message_param_t *)malloc( sizeof(message_param_t));
- msg->last_byte = (i==numOftparts-1);
+ msg->last_byte = (i==(int)numOftparts-1);
msg->in_class_id = tile_id;
msg->class_id = class_id;
msg->csn = target->csn;
msg->csn = csn;
msg->bin_offset = binOffset;
msg->length = length;
- msg->aux = 0; // non exist
+ msg->aux = 0; /* non exist*/
msg->res_offset = res_offset;
msg->phld = phld;
msg->next = NULL;
add_vbas_stream( msg->bin_offset, tmpfd);
add_vbas_stream (msg->length, tmpfd);
- if( msg->class_id%2) // Aux is present only if the id is odd
+ if( msg->class_id%2) /* Aux is present only if the id is odd*/
add_vbas_stream( msg->aux, tmpfd);
if( msg->phld)
int bytelength;
Byte8_t tmp;
- // A.2.3 In-class identifiers
- // 7k-3bits, where k is the number of bytes in the VBAS
+ /* A.2.3 In-class identifiers */
+ /* 7k-3bits, where k is the number of bytes in the VBAS*/
bytelength = 1;
tmp = in_class_id >> 4;
while( tmp){
seg = ( code >> (n*7)) & 0x7f;
if( n)
seg |= 0x80;
- write( tmpfd, ( Byte4_t *)&seg, 1);
+ if( write( tmpfd, ( Byte4_t *)&seg, 1) != 1){
+ fprintf( FCGI_stderr, "Error: failed to write vbas\n");
+ return;
+ }
n--;
}
}
fprintf( FCGI_stderr, "Error: fetch_bytes in add_body_stream()\n");
return;
}
-
- data = (Byte_t *)malloc( msg->length);
- if( read( fd, data, msg->length) != msg->length){
- free( data);
- fprintf( FCGI_stderr, "Error: fread in emit_body()\n");
- return;
- }
if( write( tmpfd, data, msg->length) < 1){
free( data);
n = bytelength - 1;
while( n >= 0) {
seg = ( code >> (n*8)) & 0xff;
- write( tmpfd, ( Byte4_t *)&seg, 1);
+ if( write( tmpfd, ( Byte4_t *)&seg, 1) != 1){
+ fprintf( FCGI_stderr, "ERROR: failed to write bigendian_bytestream\n");
+ return;
+ }
n--;
}
}
void parse_JPIPstream( Byte_t *JPIPstream, Byte8_t streamlen, Byte8_t offset, msgqueue_param_t *msgqueue)
{
- Byte_t *ptr; // stream pointer
+ Byte_t *ptr; /* stream pointer*/
message_param_t *msg;
Byte_t bb, c;
Byte8_t class_id, csn;
- class_id = -1; // dummy
+ class_id = -1; /* dummy*/
csn = -1;
ptr = JPIPstream;
- while( ptr-JPIPstream < streamlen){
+ while( (Byte8_t)(ptr-JPIPstream) < streamlen){
msg = (message_param_t *)malloc( sizeof(message_param_t));
ptr = parse_bin_id_vbas( ptr, &bb, &c, &msg->in_class_id);
ptr = parse_vbas( ptr, &msg->bin_offset);
ptr = parse_vbas( ptr, &msg->length);
- if( msg->class_id%2) // Aux is present only if the id is odd
+ if( msg->class_id%2) /* Aux is present only if the id is odd*/
ptr = parse_vbas( ptr, &msg->aux);
else
msg->aux = 0;
void parse_metamsg( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t streamlen, metadatalist_param_t *metadatalist)
{
message_param_t *msg;
+ (void)streamlen;
if( metadatalist == NULL)
return;
void parse_metadata( metadata_param_t *metadata, message_param_t *msg, Byte_t *datastream)
{
+ box_param_t *box;
+ placeholder_param_t *phld;
char *boxtype = (char *)(datastream+4);
msg->phld = NULL;
if( !metadata->placeholderlist)
metadata->placeholderlist = gene_placeholderlist();
- placeholder_param_t *phld = parse_phld( datastream, msg->length);
+ phld = parse_phld( datastream, msg->length);
msg->phld = phld;
insert_placeholder_into_list( phld, metadata->placeholderlist);
}
else if( isalpha(boxtype[0]) && isalpha(boxtype[1]) &&
- (isalnum(boxtype[2])||isblank(boxtype[2])) &&
- (isalpha(boxtype[3])||isblank(boxtype[3]))){
+ (isalnum(boxtype[2])||isspace(boxtype[2])) &&
+ (isalpha(boxtype[3])||isspace(boxtype[3]))){
if( !metadata->boxlist)
metadata->boxlist = gene_boxlist();
- box_param_t *box = gene_boxbyOffinStream( datastream, msg->res_offset);
+ box = gene_boxbyOffinStream( datastream, msg->res_offset);
insert_box_into_list( box, metadata->boxlist);
}
else
#define MAINHEADER_MSG 6
#define METADATA_MSG 8
-//! message parameters
+/** message parameters */
typedef struct message_param{
- bool last_byte; //!< if message contains the last byte of the data-bin
- Byte8_t in_class_id; //!< in-class identifier A.2.3
- Byte8_t class_id; //!< class identifiers
- Byte8_t csn; //!< index of the codestream
- Byte8_t bin_offset; //!< offset of the data in this message from the start of the data-bin
- Byte8_t length; //!< message byte length
- Byte8_t aux; //!<
- Byte8_t res_offset; //!< offset in the resource
- placeholder_param_t *phld; //!< placeholder pointer in index
- struct message_param *next; //!< pointer to the next message
+ bool last_byte; /**< if message contains the last byte of the data-bin*/
+ Byte8_t in_class_id; /**< in-class identifier A.2.3*/
+ Byte8_t class_id; /**< class identifiers */
+ Byte8_t csn; /**< index of the codestream*/
+ Byte8_t bin_offset; /**< offset of the data in this message from the start of the data-bin*/
+ Byte8_t length; /**< message byte length*/
+ Byte8_t aux; /**<*/
+ Byte8_t res_offset; /**< offset in the resource*/
+ placeholder_param_t *phld; /**< placeholder pointer in index*/
+ struct message_param *next; /**< pointer to the next message*/
} message_param_t;
-//! message queue parameters
+/** message queue parameters */
typedef struct msgqueue_param{
- message_param_t *first; //!< first message pointer of the list
- message_param_t *last; //!< last message pointer of the list
- bool stateless; //!< if this is a stateless message queue
- cachemodel_param_t *cachemodel; //!< reference cachemodel pointer
+ message_param_t *first; /**< first message pointer of the list*/
+ message_param_t *last; /**< last message pointer of the list*/
+ bool stateless; /**< if this is a stateless message queue*/
+ cachemodel_param_t *cachemodel; /**< reference cachemodel pointer*/
} msgqueue_param_t;
/**
#include "jpip_parser.h"
#include "channel_manager.h"
#include "byte_manager.h"
+#ifdef _WIN32
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#ifdef SERVER
#include "auxtrans_manager.h"
+#endif
#include <stdio.h>
#include "dec_clientmsg_handler.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <unistd.h>
#include "jp2k_encoder.h"
+#ifdef SERVER
+
server_record_t * init_JPIPserver( int tcp_auxport, int udp_auxport)
{
server_record_t *record = (server_record_t *)malloc( sizeof(server_record_t));
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( (qr->query->fx > 0 && qr->query->fy > 0) || qr->query->box_type[0][0] != 0 || qr->query->len > 0)
if( !gene_JPIPstream( *(qr->query), target, cursession, curchannel, &qr->msgqueue))
return false;
recons_stream_from_msgqueue( qr->msgqueue, fd);
- add_EORmsg( fd, qr); // needed at least for tcp and udp
-
+ add_EORmsg( fd, qr); /* needed at least for tcp and udp */
+
len_of_jpipstream = get_filesize( fd);
jpipstream = fetch_bytes( fd, 0, len_of_jpipstream);
-
+
close( fd);
remove( tmpfname);
fprintf( FCGI_stdout, "\r\n");
- if( qr->channel)
- if( qr->channel->aux == tcp || qr->channel->aux == udp){
- send_responsedata_on_aux( qr->channel->aux==tcp, rec->auxtrans, qr->channel->cid, jpipstream, len_of_jpipstream, 1000); // 1KB per frame
- return;
- }
-
- fwrite( jpipstream, len_of_jpipstream, 1, FCGI_stdout);
+ if( len_of_jpipstream){
+
+ if( qr->channel)
+ if( qr->channel->aux == tcp || qr->channel->aux == udp){
+ send_responsedata_on_aux( qr->channel->aux==tcp, rec->auxtrans, qr->channel->cid, jpipstream, len_of_jpipstream, 1000); /* 1KB per frame*/
+ return;
+ }
+
+ if( fwrite( jpipstream, len_of_jpipstream, 1, FCGI_stdout) != 1)
+ fprintf( FCGI_stderr, "Error: failed to write jpipstream\n");
+ }
+
free( jpipstream);
+
return;
}
EOR[0] = 0x00;
EOR[1] = is_allsent( *(qr->channel->cachemodel)) ? 0x01 : 0x02;
EOR[2] = 0x00;
- write( fd, EOR, 3);
+ if( write( fd, EOR, 3) != 3)
+ fprintf( FCGI_stderr, "Error: failed to write EOR message\n");
}
}
void end_QRprocess( server_record_t *rec, QR_t **qr)
{
- // TODO: record client preferences if necessary
-
+ /* TODO: record client preferences if necessary*/
+ (void)rec; /* unused */
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_alltarget( rec->targetlist);
}
+#endif /*SERVER*/
+
#ifndef SERVER
dec_server_record_t * init_dec_server( int port)
case CIDDST:
handle_dstCIDreqMSG( client, rec->cachelist);
break;
+
+ case SIZREQ:
+ handle_SIZreqMSG( client, rec->jpipstream, rec->msgqueue, rec->cachelist);
+ break;
case JP2SAVE:
handle_JP2saveMSG( client, rec->cachelist, rec->msgqueue, rec->jpipstream);
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");
+ if(!(dec->jpiplen = get_filesize(infd)))
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){
+ if( read( infd, dec->jpipstream, dec->jpiplen) != (int)dec->jpiplen){
fprintf( stderr, "file reading error\n");
free( dec->jpipstream);
return false;
{
parse_JPIPstream( dec->jpipstream, dec->jpiplen, 0, dec->msgqueue);
- if( dec->metadatalist){ // JP2 encoding
+ 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
+ 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);
}
return false;
}
- if( write( outfd, dec->jp2kstream, dec->jp2klen) != dec->jp2klen)
+ if( write( outfd, dec->jp2kstream, dec->jp2klen) != (int)dec->jp2klen)
fprintf( stderr, "j2k file write error\n");
close(outfd);
{
char *data;
- // Check resource is a JP family file.
+ /* 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
+ data = (char *)malloc( 12); /* size of header*/
if( read( fd, data, 12) != 12){
free( data);
fprintf( stderr, "Error: File broken (read error)\n");
print_index( *index);
}
-#endif //SERVER
+#endif /*SERVER*/
#include "ihdrbox_manager.h"
#include "index_manager.h"
-#endif //SERVER
+#endif /*SERVER*/
/*
*==========================================================
* JPIP server API
*==========================================================
*/
+
+ #ifdef SERVER
-//! Server static records
+/** Server static records*/
typedef struct server_record{
- sessionlist_param_t *sessionlist; //!< list of session records
- targetlist_param_t *targetlist; //!< list of target records
+ sessionlist_param_t *sessionlist; /**< list of session records*/
+ targetlist_param_t *targetlist; /**< list of target records*/
auxtrans_param_t auxtrans;
} server_record_t;
-//! Query/response data for each client
+/** Query/response data for each client*/
typedef struct QR{
- query_param_t *query; //!< query parameters
- msgqueue_param_t *msgqueue; //!< message queue
- channel_param_t *channel; //!< channel, (NULL if stateless)
+ query_param_t *query; /**< query parameters*/
+ msgqueue_param_t *msgqueue; /**< message queue*/
+ channel_param_t *channel; /**< channel, (NULL if stateless)*/
} QR_t;
/**
*/
void end_QRprocess( server_record_t *rec, QR_t **qr);
-#ifndef SERVER
-
/**
* Option for local tests; print out parameter values to logstream (stderr)
*
*/
void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr, server_record_t *rec);
-#endif //SERVER
+#endif /*SERVER*/
/*
*==========================================================
#ifndef SERVER
-//! Decoding server static records
+/** 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
+ 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
+/** Client socket identifier*/
typedef SOCKET client_t;
/**
*/
bool handle_clientreq( client_t client, dec_server_record_t *rec);
- #endif //SERVER
+#endif /*SERVER*/
/*
*==========================================================
* jpip to JP2 or J2K
*/
-//! JPIP decoding parameters
+/** 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
+ 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;
/**
* test the format of index (cidx) box in JP2 file
*/
-//! Redefinition of index parameters
+/** Redefinition of index parameters*/
typedef index_param_t index_t;
/**
*/
void output_index( index_t *index);
-#endif //SERVER
+#endif /*SERVER*/
#endif /* !OPENJPIP_H_ */
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
-placeholderlist_param_t * gene_placeholderlist()
+placeholderlist_param_t * gene_placeholderlist(void)
{
placeholderlist_param_t *list;
placeholder = (placeholder_param_t *)malloc( sizeof(placeholder_param_t));
strncpy( placeholder->TBox, "phld", 4);
- placeholder->Flags = 1; // only the access to the original contents of this box, for now
+ placeholder->Flags = 1; /* only the access to the original contents of this box, for now */
placeholder->OrigID = origID;
placeholder->OrigBH = fetch_headbytes( box);
placeholder->OrigBHlen = box->headlen;
#include "byte_manager.h"
#include "box_manager.h"
-//! A.3.6.3 Placeholder box format
-//! placeholder box parameters
+/** A.3.6.3 Placeholder box format*/
+/** placeholder box parameters*/
typedef struct placeholder_param{
Byte4_t LBox;
char TBox[4];
Byte4_t Flags;
Byte8_t OrigID;
- Byte_t *OrigBH; //!< dynamic memory pointer
- Byte_t OrigBHlen; //!< length of OrigBH
+ Byte_t *OrigBH; /**< dynamic memory pointer*/
+ Byte_t OrigBHlen; /**< length of OrigBH*/
#ifdef AAA
Byte8_t EquivID;
- Byte_t *EquivBH; //!< dynamic memory pointer
- Byte_t EquivBHlen; //!< length of EquivBH
+ Byte_t *EquivBH; /**< dynamic memory pointer*/
+ Byte_t EquivBHlen; /**< length of EquivBH*/
Byte8_t CSID;
Byte4_t NCS;
-#endif //AAA
- struct placeholder_param *next; //!< pointer to the next placeholder
+#endif /*AAA*/
+ struct placeholder_param *next; /**< pointer to the next placeholder*/
} placeholder_param_t;
-//! placeholder box list parameters
+/** placeholder box list parameters*/
typedef struct placeholderlist_param{
- placeholder_param_t *first; //!< first placeholder pointer of the list
- placeholder_param_t *last; //!< last placeholder pointer of the list
+ placeholder_param_t *first; /**< first placeholder pointer of the list*/
+ placeholder_param_t *last; /**< last placeholder pointer of the list*/
} placeholderlist_param_t;
*
* @return pointer to the generated placeholder list
*/
-placeholderlist_param_t * gene_placeholderlist();
+placeholderlist_param_t * gene_placeholderlist(void);
/**
#ifdef _WIN32
#include <windows.h>
#define strcasecmp _stricmp
+#define strncasecmp _strnicmp
#else
#include <strings.h>
#endif
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
/**
void parse_cclose( char *src, query_param_t *query_param);
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)
+/* 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
+/** maximum length of field name*/
#define MAX_LENOFFIELDNAME 10
-//! maximum length of field value
+/** maximum length of field value*/
#define MAX_LENOFFIELDVAL 128
query_param_t * parse_query( char *query_string)
query_param->return_type = JPTstream;
}
- else if( strcasecmp( fieldname, "len") == 0)
+ else if( strcasecmp( fieldname, "len") == 0){
sscanf( fieldval, "%d", &query_param->len);
+ if( query_param->len = 2000) /* for kakadu client*/
+ strncpy( query_param->box_type[0], "ftyp", 4);
+ }
}
}
return query_param;
void parse_cclose( char *src, query_param_t *query_param)
{
- int i;
+ size_t i;
size_t len;
len = strlen( src);
memset( req_box_prop, 0, 20);
- // req-box-prop
+ /* req-box-prop*/
ptr = strchr( field, '[');
ptr++;
src = ptr;
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;
#include "bool.h"
-//! maximum number of meta request box
+/** maximum number of meta request box */
#define MAX_NUMOFBOX 10
-//! cnew aux transport name
+/** cnew aux transport name */
typedef enum cnew_transport { non, http, tcp, udp} cnew_transport_t;
-//! image return type
+/** image return type */
typedef enum image_return { JPPstream, JPTstream, UNKNOWN=-1} image_return_t;
-//! Query parameters
+/** Query parameters */
typedef struct query_param{
- char *target; //!< target name
- char *tid; //!< 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; //!< channel identifier
- cnew_transport_t cnew; //!< transport name if there is new channel request, else non
- char *cclose; //!< list of closing channel identifiers, separated by '\0'
- int numOfcclose; //!< number of closing channels
- 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
+ char *target; /**< target name */
+ char *tid; /**< 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; /**< channel identifier */
+ cnew_transport_t cnew; /**< transport name if there is new channel request, else non */
+ char *cclose; /**< list of closing channel identifiers, separated by '\0' */
+ int numOfcclose; /**< number of closing channels */
+ 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
+ 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;
#include "channel_manager.h"
#include "cachemodel_manager.h"
-//! Session parameters
+/** 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
+ 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
+/** 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
+ session_param_t *first; /**< first session pointer of the list*/
+ session_param_t *last; /**< last session pointer of the list*/
} sessionlist_param_t;
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
+#include <unistd.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <unistd.h>
#include "sock_manager.h"
#ifdef SERVER
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
SOCKET open_listeningsocket( int port)
{
void send_stream( SOCKET connected_socket, void *stream, int length)
{
- void *ptr = stream;
+ char *ptr = (char*)stream;
int remlen = length;
while( remlen > 0){
void * receive_stream( SOCKET connected_socket, int length)
{
- void *stream, *ptr;
+ char *stream, *ptr;
int remlen, redlen;
ptr = stream = malloc( length);
#include "byte_manager.h"
#ifdef _WIN32
-#include <winsock2.h>
+#include <winsock.h>
#else
typedef int SOCKET;
-#endif //_WIN32
+#endif /*_WIN32*/
#define BUF_LEN 256
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#ifdef _WIN32
+#define snprintf _snprintf /* Visual Studio */
+#include <io.h>
+#else
#include <sys/types.h>
-#include <sys/stat.h>
#include <unistd.h>
+#endif
+#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
-#include <curl/curl.h>
#include "target_manager.h"
#ifdef SERVER
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
-#endif //SERVER
+#endif /*SERVER*/
-targetlist_param_t * gene_targetlist()
+targetlist_param_t * gene_targetlist(void)
{
targetlist_param_t *targetlist;
target->jptstream = isJPTfeasible( *jp2idx);
target->next=NULL;
- if( targetlist->first) // there are one or more entries
+ if( targetlist->first) /* there are one or more entries*/
targetlist->last->next = target;
- else // first entry
+ else /* first entry*/
targetlist->first = target;
targetlist->last = target;
int fd;
char *data;
- // download remote target file to local storage
+ /* download remote target file to local storage*/
if( strncmp( filepath, "http://", 7) == 0){
if( (fd = open_remotefile( filepath, tmpfname)) == -1)
return -1;
return -1;
}
}
- // Check resource is a JP family file.
+ /* 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", filepath);
return -1;
}
- data = (char *)malloc( 12); // size of header
+ data = (char *)malloc( 12); /* size of header*/
if( read( fd, data, 12) != 12){
free( data);
int open_remotefile( char filepath[], char tmpfname[])
{
#ifndef SERVER
-
+ (void)filepath;
+ (void)tmpfname;
fprintf( FCGI_stderr, "Remote file can not be opened in local mode\n");
return -1;
curl_easy_cleanup(curl_handle);
return fd;
-#endif //SERVER
+#endif /*SERVER*/
}
#ifdef SERVER
return written;
}
-#endif //SERVER
+#endif /*SERVER*/
#include "bool.h"
#include "index_manager.h"
-//! maximum length of target identifier
+/** maximum length of target identifier*/
#define MAX_LENOFTID 30
-//! target parameters
+/** target parameters*/
typedef struct target_param{
- char tid[MAX_LENOFTID]; //!< taregt identifier
- char *targetname; //!< local file path or URL ( URL is suported only with SERVER mode)
- int fd; //!< file descriptor
+ char tid[MAX_LENOFTID]; /**< target identifier*/
+ char *targetname; /**< local file path or URL ( URL is suported only with SERVER mode)*/
+ int fd; /**< file descriptor*/
#ifdef SERVER
- char *tmpfname; //!< temporal file name to download a remote target file
+ char *tmpfname; /**< temporal file name to download a remote target file*/
#endif
- int csn; //!< codestream number
- index_param_t *codeidx; //!< index information of codestream
- int num_of_use; //!< numbers of sessions refering to this target
- bool jppstream; //!< if this target can return JPP-stream
- bool jptstream; //!< if this target can return JPP-stream
- struct target_param *next; //!< pointer to the next target
+ int csn; /**< codestream number */
+ index_param_t *codeidx; /**< index information of codestream */
+ int num_of_use; /**< numbers of sessions refering to this target */
+ bool jppstream; /**< if this target can return JPP-stream */
+ bool jptstream; /**< if this target can return JPP-stream */
+ struct target_param *next; /**< pointer to the next target */
} target_param_t;
-//! Target list parameters
+/** Target list parameters*/
typedef struct targetlist_param{
- target_param_t *first; //!< first target pointer of the list
- target_param_t *last; //!< last target pointer of the list
+ target_param_t *first; /**< first target pointer of the list*/
+ target_param_t *last; /**< last target pointer of the list*/
} targetlist_param_t;
*
* @return pointer to the generated target list
*/
-targetlist_param_t * gene_targetlist();
+targetlist_param_t * gene_targetlist(void);
/**
*
* \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
+ * % ./opj_dec_server [portnumber]\n
+ * ( portnumber=50000 by default)\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
+ * % telnet localhost 50000\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 "openjpip.h"
#ifdef _WIN32
dec_server_record_t *server_record;
client_t client;
+ int port = 50000;
+ int erreur;
+ (void)erreur;
+
+ if( argc > 1)
+ port = atoi( argv[1]);
#ifdef _WIN32
- int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
+ 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
+#endif /*_WIN32*/
- server_record = init_dec_server( 50000);
+ server_record = init_dec_server( port);
while(( client = accept_connection( server_record)) != -1 )
if(!handle_clientreq( client, server_record))
#ifdef _WIN32
WSADATA initialisation_win32;
-#endif //_WIN32
+#endif /*_WIN32*/
int main(void)
{
server_record_t *server_record;
+#ifdef SERVER
+ char *query_string;
+#endif
#ifdef _WIN32
int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else
fprintf( stderr, "Initialisation Winsock\n");
-#endif //_WIN32
+#endif /*_WIN32*/
server_record = init_JPIPserver( 60000, 0);
#ifdef SERVER
-
- char *query_string;
while(FCGI_Accept() >= 0)
#else
while( fgets( query_string, 128, stdin) && query_string[0]!='\n')
#endif
{
+ QR_t *qr;
+ bool parse_status;
#ifdef SERVER
query_string = getenv("QUERY_STRING");
-#endif //SERVER
+#endif /*SERVER*/
if( strcmp( query_string, QUIT_SIGNAL) == 0)
break;
- QR_t *qr;
- bool parse_status;
-
qr = parse_querystring( query_string);
parse_status = process_JPIPrequest( server_record, qr);
#endif
if( parse_status)
- send_responsedata( qr);
+ send_responsedata( server_record, qr);
else{
fprintf( FCGI_stderr, "Error: JPIP request failed\n");
- fprintf( FCGI_stdout, "\r\n");
- }
+ fprintf( FCGI_stdout, "\r\n");
+ }
end_QRprocess( server_record, &qr);
}
public class ImageManager extends JPIPHttpClient
{
private PnmImage pnmimage;
+ private int origwidth;
+ private int origheight;
+ private ImgdecClient imgdecoder;
- public ImageManager( String uri)
+ public ImageManager( String uri, String host, int port)
{
super( uri);
+ imgdecoder = new ImgdecClient( host, port);
pnmimage = null;
+ origwidth = 0;
+ origheight = 0;
}
- public int getOrigWidth(){ return pnmimage.get_width();}
- public int getOrigHeight(){ return pnmimage.get_height();}
+ public int getOrigWidth(){
+ if( origwidth == 0){
+ if( cid != null || tid != null){
+ java.awt.Dimension dim = imgdecoder.query_imagesize( cid, tid);
+ if( dim != null){
+ origwidth = dim.width;
+ origheight = dim.height;
+ }
+ }
+ else
+ System.err.println("Neither cid or tid obtained before to get Original Image Dimension");
+ }
+ return origwidth;
+ }
+ public int getOrigHeight(){ return origheight;}
public Image getImage( String j2kfilename, int reqfw, int reqfh, boolean reqcnew, int reqaux, boolean reqJPP, boolean reqJPT)
{
// Todo: check if the cid is for the same stream type
if( reqcnew)
- refcid = ImgdecClient.query_cid( j2kfilename);
+ refcid = imgdecoder.query_cid( j2kfilename);
if( refcid == null){
- String reftid = ImgdecClient.query_tid( j2kfilename);
+ String reftid = imgdecoder.query_tid( j2kfilename);
if( reftid == null)
jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, reqcnew, reqaux, reqJPP, reqJPT);
else
jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, reqcnew, reqaux, reqJPP, reqJPT);
System.err.println( "decoding to PNM image");
- if((pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh))!=null){
+ if((pnmimage = imgdecoder.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh))!=null){
System.err.println( " done");
return pnmimage.createROIImage( rx, ry, rw, rh);
}
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){
+ if((pnmimage = imgdecoder.decode_jpipstream( jpipstream, tid, cid, fw, fh)) != null){
System.err.println( " done");
return pnmimage.createROIImage( rx, ry, rw, rh);
}
byte[] jpipstream = super.requestXML();
if( jpipstream != null){
- ImgdecClient.send_JPIPstream( jpipstream);
+ imgdecoder.send_JPIPstream( jpipstream);
- xmldata = ImgdecClient.get_XMLstream( cid);
+ xmldata = imgdecoder.get_XMLstream( cid);
}
return xmldata;
}
+
public void closeChannel()
{
if( cid != null){
- ImgdecClient.destroy_cid( cid);
+ imgdecoder.destroy_cid( cid);
super.closeChannel();
}
}
-}
\ No newline at end of file
+}
private ImageViewer imgviewer;
private ImageManager imgmanager;
- public ImageWindow( String uri, String j2kfilename, boolean session, boolean jppstream, int aux)
+ public ImageWindow( String uri, String j2kfilename, String host, int port, boolean session, boolean jppstream, int aux)
{
super( j2kfilename);
- imgmanager = new ImageManager( uri);
+ imgmanager = new ImageManager( uri, host, port);
imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream, aux);
imgviewer.setOpaque(true); //content panes must be opaque
public static void main(String s[])
{
- String j2kfilename, uri;
+ String j2kfilename, uri, host;
boolean session, jppstream;
- int aux; // 0: none, 1: tcp, 2: udp
-
+ int port, aux; // 0: none, 1: tcp, 2: udp
+
if(s.length >= 2){
uri = s[0];
j2kfilename = s[1];
+
if( s.length > 2)
- session = !s[2].equalsIgnoreCase( "stateless");
+ host = s[2];
else
- session = true;
-
+ host = "localhost";
+
if( s.length > 3)
- jppstream = !s[3].equalsIgnoreCase( "JPT");
+ port = Integer.valueOf( s[3]).intValue();
+ else
+ port = 50000;
+
+ if( s.length > 4)
+ session = !s[4].equalsIgnoreCase( "stateless");
+ else
+ session = true;
+
+ if( s.length > 5)
+ jppstream = !s[5].equalsIgnoreCase( "JPT");
else
jppstream = true;
-
- if( s.length > 4){
- if( s[4].equalsIgnoreCase("udp"))
+
+ if( s.length > 6){
+ if( s[6].equalsIgnoreCase("udp"))
aux = 2;
else
aux = 1;
aux = 0;
}
else{
- System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [stateless/session] [JPT/JPP] [tcp/udp]");
+ System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [hostname] [portnumber] [stateless/session] [JPT/JPP] [tcp/udp]");
return;
}
- ImageWindow frame = new ImageWindow( uri, j2kfilename, session, jppstream, aux);
+ ImageWindow frame = new ImageWindow( uri, j2kfilename, host, port, session, jppstream, aux);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
import java.net.*;
public class ImgdecClient{
+
+ private String hostname;
+ private int portNo;
+
+ public ImgdecClient( String host, int port)
+ {
+ hostname = host;
+ portNo = port;
+ }
- public static PnmImage decode_jpipstream( byte[] jpipstream, String tid, String cid, int fw, int fh)
+ public 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)
+ public 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)
+ public void send_JPIPstream( byte[] jpipstream)
{
try{
- Socket imgdecSocket = new Socket( "localhost", 50000);
+ Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
}
}
- public static void send_JPIPstream( byte[] jpipstream, String j2kfilename, String tid, String cid)
+ public void send_JPIPstream( byte[] jpipstream, String j2kfilename, String tid, String cid)
{
try{
- Socket imgdecSocket = new Socket( "localhost", 50000);
+ Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
int length = 0;
}
}
- public static PnmImage get_PNMstream( String cid, String tid, int fw, int fh)
+ public PnmImage get_PNMstream( String cid, String tid, int fw, int fh)
{
PnmImage pnmstream = null;
try {
- Socket imgdecSocket = new Socket( "localhost", 50000);
+ Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[7];
return pnmstream;
}
- public static byte [] get_XMLstream( String cid)
+ public byte [] get_XMLstream( String cid)
{
byte []xmldata = null;
try{
- Socket imgdecSocket = new Socket( "localhost", 50000);
+ Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[5];
return xmldata;
}
- public static String query_cid( String j2kfilename)
+ public String query_cid( String j2kfilename)
{
int []retmsglabel = new int[3];
retmsglabel[0] = 67;
return query_id( "CID request", j2kfilename, retmsglabel);
}
- public static String query_tid( String j2kfilename)
+ public String query_tid( String j2kfilename)
{
int []retmsglabel = new int[3];
retmsglabel[0] = 84;
return query_id( "TID request", j2kfilename, retmsglabel);
}
- public static String query_id( String reqmsghead, String j2kfilename, int[] retmsglabel)
+ public String query_id( String reqmsghead, String j2kfilename, int[] retmsglabel)
{
String id = null;
try{
- Socket imgdecSocket = new Socket( "localhost", 50000);
+ Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[4];
return id;
}
- public static java.awt.Dimension query_imagesize( String cid, String tid)
+ public java.awt.Dimension query_imagesize( String cid, String tid)
{
java.awt.Dimension dim = null;
try{
- Socket imgdecSocket = new Socket( "localhost", 50000);
+ Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[3];
return dim;
}
- public static void read_stream( DataInputStream is, byte []stream, int length)
+ private static void read_stream( DataInputStream is, byte []stream, int length)
{
int remlen = length;
int off = 0;
}
}
- public static void destroy_cid( String cid)
+ public void destroy_cid( String cid)
{
try{
- Socket imgdecSocket = new Socket( "localhost", 50000);
+ Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
private OptionPanel optpanel;
private ImageManager imgmanager;
- public ImageWindow( String uri, String j2kfilename, boolean session, boolean jppstream, int aux)
+ public ImageWindow( String uri, String j2kfilename, String host, int port, boolean session, boolean jppstream, int aux)
{
super( j2kfilename);
- imgmanager = new ImageManager( uri);
+ imgmanager = new ImageManager( uri, host, port);
imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream, aux);
imgviewer.setOpaque(true); //content panes must be opaque
public static void main(String s[])
{
- String j2kfilename, uri;
+ String j2kfilename, uri, host;
boolean session, jppstream;
- int aux; // 0: none, 1: tcp, 2: udp
-
+ int port, aux; // 0: none, 1: tcp, 2: udp
+
if(s.length >= 2){
uri = s[0];
j2kfilename = s[1];
+
if( s.length > 2)
- session = !s[2].equalsIgnoreCase( "stateless");
+ host = s[2];
else
- session = true;
-
+ host = "localhost";
+
if( s.length > 3)
- jppstream = !s[3].equalsIgnoreCase( "JPT");
+ port = Integer.valueOf( s[3]).intValue();
+ else
+ port = 50000;
+
+ if( s.length > 4)
+ session = !s[4].equalsIgnoreCase( "stateless");
+ else
+ session = true;
+
+ if( s.length > 5)
+ jppstream = !s[5].equalsIgnoreCase( "JPT");
else
jppstream = true;
- if( s.length > 4){
- if( s[4].equalsIgnoreCase("udp"))
+ if( s.length > 6){
+ if( s[6].equalsIgnoreCase("udp"))
aux = 2;
else
aux = 1;
aux = 0;
}
else{
- System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [stateless/session] [JPT/JPP] [tcp/udp]");
+ System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [hostname] [portnumber] [stateless/session] [JPT/JPP] [tcp/udp]");
return;
}
- ImageWindow frame = new ImageWindow( uri, j2kfilename, session, jppstream, aux);
+ ImageWindow frame = new ImageWindow( uri, j2kfilename, host, port, session, jppstream, aux);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation( 0, 50);
frame.setVisible(true);
}
-}
\ No newline at end of file
+}