[trunk] Import remaning bits from JPIP/1.5 over to trunk

This commit is contained in:
Mathieu Malaterre 2012-03-02 11:09:16 +00:00
parent d6357bacdd
commit 3d9198592b
59 changed files with 964 additions and 672 deletions

View File

@ -5,16 +5,33 @@ What's New for OpenJPIP
! : changed ! : changed
+ : added + : 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 November 30, 2011
+ [kaori] TCP return (http-tcp) implemented + [kaori] TCP return (http-tcp) implemented
November 16, 2011 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] 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 November 8, 2011
! [kaori] updated main page of doxygen ! [kaori] updated main page of doxygen
! [kaori] enabled OpenJPEG V2 API
November 3, 2011 November 3, 2011
* [kaori] solved memory leak of opj_server * [kaori] solved memory leak of opj_server
@ -43,12 +60,12 @@ October 14, 2011
October 12, 2011 October 12, 2011
+ [kaori] enable layers requests; restricting the number of codesream quality layers + [kaori] enable layers requests; restricting the number of codesream quality layers
October 10, 2011 October 11, 2011
- [antonin] removed obsolete indexer utility + [antonin] enable JPT-stream request from client viewer option (credit to kaori)
+ [kaori] enable JPT-stream request from client viewer option
September 30, 2011 October 10, 2011
+ [kaori] enabled JPP-stream - [antonin] removed obsolete indexer utility (credit to kaori)
+ [antonin] enabled JPP-stream (credit to kaori)
September 16, 2011 September 16, 2011
+ [kaori] enabled stateless requests from the opj_viewers + [kaori] enabled stateless requests from the opj_viewers

View File

@ -92,11 +92,11 @@ Server:
For shutting down JPIP server: For shutting down JPIP server:
%GET http://hostname/myFCGI?quitJPIP %GET http://hostname/myFCGI?quitJPIP
Notice, http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting) 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: Client:
1. Launch image decoding server, and keep it alive as long as image viewers are open 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. You might prefer to implement this program from another directory since cache files are saved in the working directory.
% mkdir cache % mkdir cache
@ -104,10 +104,12 @@ Client:
% ../opj_dec_server % ../opj_dec_server
2. Open image viewers (as many as needed) 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 ( The arguments
- http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting) - 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 - 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 - 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 - 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 - auxiliary return protocol, tcp or udp (udp is not implemented yet), if not given, return data is filled in http chunk
@ -131,7 +133,7 @@ An example to encode a TIF image "copenhague1.tif" at resolution 4780x4050, 8bit
% ./image_to_j2k -i copenhague1.tif -o copenhague1.jp2 -p RPCL -c [64,64] -t 640,480 -jpip -TP R % ./image_to_j2k -i copenhague1.tif -o copenhague1.jp2 -p RPCL -c [64,64] -t 640,480 -jpip -TP R
options 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) -TP R : partition a tile into tile parts of different resolution levels (obligation for JPT-stream)
<Option> <Option>

View File

@ -568,7 +568,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories # directories like "/usr/src/myproject". Separate the files or directories
# with spaces. # 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 # 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 # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is

View File

@ -38,7 +38,6 @@ cachemodel_manager.c \
j2kheader_manager.c \ j2kheader_manager.c \
jp2k_encoder.c \ jp2k_encoder.c \
sock_manager.c \ sock_manager.c \
auxtrans_manager.c \
openjpip.h \ openjpip.h \
bool.h \ bool.h \
boxheader_manager.h \ boxheader_manager.h \
@ -64,8 +63,7 @@ channel_manager.h \
session_manager.h \ session_manager.h \
jpip_parser.h \ jpip_parser.h \
jp2k_decoder.h \ jp2k_decoder.h \
sock_manager.h \ sock_manager.h
auxtrans_manager.h
SERVER_SRC = auxtrans_manager.c \ SERVER_SRC = auxtrans_manager.c \
auxtrans_manager.h auxtrans_manager.h

View File

@ -33,10 +33,10 @@
#include <stdlib.h> #include <stdlib.h>
#include "auxtrans_manager.h" #include "auxtrans_manager.h"
#ifdef __linux__ #ifdef _WIN32
#include <pthread.h>
#else
#include <process.h> #include <process.h>
#else
#include <pthread.h>
#endif #endif
#ifdef SERVER #ifdef SERVER
@ -94,20 +94,21 @@ aux_response_param_t * gene_auxresponse( bool istcp, auxtrans_param_t auxtrans,
void delete_auxresponse( aux_response_param_t **auxresponse); void delete_auxresponse( aux_response_param_t **auxresponse);
#ifdef __linux__
void * aux_streaming( void *arg); #ifdef _WIN32
#else
unsigned __stdcall aux_streaming( void *arg); unsigned __stdcall aux_streaming( void *arg);
#else
void * aux_streaming( void *arg);
#endif #endif
void send_responsedata_on_aux( bool istcp, auxtrans_param_t auxtrans, char cid[], void *data, int datalen, int maxlenPerFrame) void send_responsedata_on_aux( bool istcp, auxtrans_param_t auxtrans, char cid[], void *data, int datalen, int maxlenPerFrame)
{ {
aux_response_param_t *auxresponse; aux_response_param_t *auxresponse;
#ifdef __linux__ #ifdef _WIN32
unsigned int threadId;
#else
pthread_t thread; pthread_t thread;
int status; int status;
#else
unsigned int threadId;
#endif #endif
if( istcp){ if( istcp){
@ -117,15 +118,15 @@ void send_responsedata_on_aux( bool istcp, auxtrans_param_t auxtrans, char cid[]
} }
auxresponse = gene_auxresponse( istcp, auxtrans, cid, data, datalen, maxlenPerFrame); auxresponse = gene_auxresponse( istcp, auxtrans, cid, data, datalen, maxlenPerFrame);
#ifdef __linux__ #ifdef _WIN32
status = pthread_create( &thread, NULL, &aux_streaming, auxresponse);
if( status != 0)
fprintf( FCGI_stderr,"ERROR: pthread_create() %s",strerror(status));
#else
auxresponse->hTh = (HANDLE)_beginthreadex( NULL, 0, &aux_streaming, auxresponse, 0, &threadId); auxresponse->hTh = (HANDLE)_beginthreadex( NULL, 0, &aux_streaming, auxresponse, 0, &threadId);
if( auxresponse->hTh == 0) if( auxresponse->hTh == 0)
fprintf( FCGI_stderr,"ERRO: pthread_create() %s", strerror( (int)auxresponse->hTh)); 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 #endif
} }
else else
@ -166,10 +167,10 @@ bool identify_cid( SOCKET connected_socket, char refcid[], FILE *fp);
bool recv_ack( SOCKET connected_socket, void *data); bool recv_ack( SOCKET connected_socket, void *data);
#ifdef __linux__ #ifdef _WIN32
void * aux_streaming( void *arg)
#else
unsigned __stdcall aux_streaming( void *arg) unsigned __stdcall aux_streaming( void *arg)
#else
void * aux_streaming( void *arg)
#endif #endif
{ {
SOCKET connected_socket; SOCKET connected_socket;
@ -179,10 +180,10 @@ unsigned __stdcall aux_streaming( void *arg)
aux_response_param_t *auxresponse = (aux_response_param_t *)arg; aux_response_param_t *auxresponse = (aux_response_param_t *)arg;
#ifdef __linux__ #ifdef _WIN32
pthread_detach( pthread_self());
#else
CloseHandle( auxresponse->hTh); CloseHandle( auxresponse->hTh);
#else
pthread_detach( pthread_self());
#endif #endif
chunk = (unsigned char *)malloc( auxresponse->maxlenPerFrame); chunk = (unsigned char *)malloc( auxresponse->maxlenPerFrame);
@ -219,10 +220,10 @@ unsigned __stdcall aux_streaming( void *arg)
delete_auxresponse( &auxresponse); delete_auxresponse( &auxresponse);
#ifdef __linux__ #ifdef _WIN32
pthread_exit(0);
#else
_endthreadex(0); _endthreadex(0);
#else
pthread_exit(0);
#endif #endif
return 0; return 0;

View File

@ -33,12 +33,12 @@
#include "sock_manager.h" #include "sock_manager.h"
//! auxiliary transport setting parameters /** auxiliary transport setting parameters*/
typedef struct auxtrans_param{ typedef struct auxtrans_param{
int tcpauxport; //!< tcp port int tcpauxport; /**< tcp port*/
int udpauxport; //!< udp port int udpauxport; /**< udp port*/
SOCKET tcplistensock; //!< listenning socket for aux tcp (-1 if not open) SOCKET tcplistensock; /**< listenning socket for aux tcp (-1 if not open)*/
SOCKET udplistensock; //!< listenning socket for aux udp (-1 if not open) SOCKET udplistensock; /**< listenning socket for aux udp (-1 if not open)*/
} auxtrans_param_t; } auxtrans_param_t;
/** /**

View File

@ -31,9 +31,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <ctype.h> #include <ctype.h>
#include "box_manager.h" #include "box_manager.h"
@ -44,7 +41,7 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
boxlist_param_t * gene_boxlist() boxlist_param_t * gene_boxlist()
{ {
@ -75,7 +72,7 @@ boxlist_param_t * get_boxstructure( int fd, Byte8_t offset, Byte8_t length)
if( !boxlist) if( !boxlist)
boxlist = gene_boxlist(); boxlist = gene_boxlist();
insert_box_into_list( box, boxlist); insert_box_into_list( box, boxlist);
}while( pos < offset+length); }while( pos < (int)(offset+length));
return boxlist; return boxlist;
} }
@ -87,7 +84,7 @@ box_param_t * gene_boxbyOffset( int fd, Byte8_t offset)
char *boxtype; char *boxtype;
box_param_t *box; box_param_t *box;
// read LBox and TBox /* read LBox and TBox*/
if(!(data = fetch_bytes( fd, offset, 8))){ if(!(data = fetch_bytes( fd, offset, 8))){
fprintf( FCGI_stderr, "Error: error in gene_boxbyOffset( %d, %lld)\n", fd, offset); fprintf( FCGI_stderr, "Error: error in gene_boxbyOffset( %d, %lld)\n", fd, offset);
return NULL; return NULL;
@ -97,10 +94,10 @@ box_param_t * gene_boxbyOffset( int fd, Byte8_t offset)
boxlen = (Byte8_t)big4(data); boxlen = (Byte8_t)big4(data);
boxtype = (char *)(data+4); boxtype = (char *)(data+4);
// box type constraint /* box type constraint*/
if( !isalpha(boxtype[0]) || !isalpha(boxtype[1]) || if( !isalpha(boxtype[0]) || !isalpha(boxtype[1]) ||
(!isalnum(boxtype[2])&&!isblank(boxtype[2])) || (!isalnum(boxtype[2])&&!isspace(boxtype[2])) ||
(!isalpha(boxtype[3])&&!isblank(boxtype[3]))){ (!isalpha(boxtype[3])&&!isspace(boxtype[3]))){
free( data); free( data);
return NULL; return NULL;
} }
@ -108,7 +105,7 @@ box_param_t * gene_boxbyOffset( int fd, Byte8_t offset)
if( boxlen == 1){ if( boxlen == 1){
Byte_t *data2; Byte_t *data2;
headlen = 16; headlen = 16;
// read XLBox /* read XLBox*/
if((data2 = fetch_bytes( fd, offset+8, 8))){ if((data2 = fetch_bytes( fd, offset+8, 8))){
boxlen = big8(data2); boxlen = big8(data2);
free(data2); free(data2);
@ -136,21 +133,21 @@ box_param_t * gene_boxbyOffinStream( Byte_t *stream, Byte8_t offset)
char *boxtype; char *boxtype;
box_param_t *box; box_param_t *box;
// read LBox and TBox /* read LBox and TBox*/
headlen = 8; headlen = 8;
boxlen = (Byte8_t)big4( stream); boxlen = (Byte8_t)big4( stream);
boxtype = (char *)( stream+4); boxtype = (char *)( stream+4);
// box type constraint /* box type constraint*/
if( !isalpha(boxtype[0]) || !isalpha(boxtype[1]) || if( !isalpha(boxtype[0]) || !isalpha(boxtype[1]) ||
(!isalnum(boxtype[2])&&!isblank(boxtype[2])) || (!isalnum(boxtype[2])&&!isspace(boxtype[2])) ||
(!isalpha(boxtype[3])&&!isblank(boxtype[3]))){ (!isalpha(boxtype[3])&&!isspace(boxtype[3]))){
return NULL; return NULL;
} }
if( boxlen == 1){ if( boxlen == 1){
headlen = 16; headlen = 16;
boxlen = big8( stream+8); // read XLBox boxlen = big8( stream+8); /* read XLBox*/
} }
box = (box_param_t *)malloc( sizeof( box_param_t)); box = (box_param_t *)malloc( sizeof( box_param_t));
box->fd = -1; box->fd = -1;
@ -164,7 +161,7 @@ box_param_t * gene_boxbyOffinStream( Byte_t *stream, Byte8_t offset)
} }
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; Byte8_t pos;
Byte_t *data; Byte_t *data;
@ -173,19 +170,15 @@ box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[
box_param_t *foundbox; box_param_t *foundbox;
if( length==0){ // set the max length if( length==0){ /* set the max length*/
struct stat sb; if( (length = get_filesize( fd) - offset) <= 0)
if( fstat( fd, &sb) == -1){
fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
return NULL; return NULL;
}
length = (Byte8_t)sb.st_size - offset;
} }
pos = 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))){ if((data = fetch_bytes( fd, pos, 8))){
headlen = 8; headlen = 8;
boxlen = (Byte8_t)big4(data); boxlen = (Byte8_t)big4(data);
@ -194,7 +187,7 @@ box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[
if( boxlen == 1){ if( boxlen == 1){
Byte_t *data2; Byte_t *data2;
headlen = 16; headlen = 16;
// read XLBox /* read XLBox*/
if((data2 = fetch_bytes( fd, pos+8, 8))){ if((data2 = fetch_bytes( fd, pos+8, 8))){
boxlen = big8(data2); boxlen = big8(data2);
free(data2); free(data2);
@ -228,7 +221,7 @@ box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[
return NULL; 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; Byte8_t pos;
Byte_t *data; Byte_t *data;
@ -237,22 +230,22 @@ box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t le
box_param_t *foundbox; 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"); fprintf( FCGI_stderr, "func gene_boxbyTypeinStream(), max length must be more than 0\n");
return NULL; return NULL;
} }
pos = 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*/
data = stream + pos; data = stream + pos;
headlen = 8; headlen = 8;
boxlen = (Byte8_t)big4(data); boxlen = (Byte8_t)big4(data);
boxtype = (char *)(data+4); boxtype = (char *)(data+4);
if( boxlen == 1){ if( boxlen == 1){
// read XLBox /* read XLBox*/
headlen = 16; headlen = 16;
boxlen = big8( data+8); boxlen = big8( data+8);
} }
@ -279,7 +272,7 @@ box_param_t * gene_childboxbyOffset( box_param_t *superbox, Byte8_t offset)
return gene_boxbyOffset( superbox->fd, get_DBoxoff( superbox)+offset); 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 gene_boxbyType( superbox->fd, get_DBoxoff( superbox)+offset, get_DBoxlen( superbox)-offset, TBox);
} }
@ -324,7 +317,7 @@ Byte8_t fetch_DBox8bytebigendian( box_param_t *box, long offset)
return fetch_8bytebigendian( box->fd, get_DBoxoff( box)+offset); 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; box_param_t *foundbox;

View File

@ -33,21 +33,21 @@
#include "byte_manager.h" #include "byte_manager.h"
//! box parameters /** box parameters*/
typedef struct box_param{ typedef struct box_param{
int fd; //!< file descriptor int fd; /**< file descriptor*/
Byte8_t offset; //!< byte position of the whole Box (LBox) in the file Byte8_t offset; /**< byte position of the whole Box (LBox) in the file*/
Byte_t headlen; //!< header length 8 or 16 Byte_t headlen; /**< header length 8 or 16*/
Byte8_t length; //!< length of the whole Box Byte8_t length; /**< length of the whole Box*/
char type[4]; //!< type of information in the DBox char type[4]; /**< type of information in the DBox*/
struct box_param *next; //!< pointer to the next box struct box_param *next; /**< pointer to the next box*/
} box_param_t; } box_param_t;
//! Box list parameters /** Box list parameters*/
typedef struct boxlist_param{ typedef struct boxlist_param{
box_param_t *first; //!< first 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 box_param_t *last; /**< last box pointer of the list*/
} boxlist_param_t; } boxlist_param_t;
@ -97,7 +97,7 @@ box_param_t * gene_boxbyOffinStream( Byte_t *stream, Byte8_t offset);
* @param[in] TBox Box Type * @param[in] TBox Box Type
* @return pointer to the structure of generate/found box parameters * @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 * generate(search) box from code stream
@ -108,7 +108,7 @@ box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[
* @param[in] TBox Box Type * @param[in] TBox Box Type
* @return pointer to the structure of generate/found box parameters * @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 * generate child box from JP2 file at the given offset
@ -127,7 +127,7 @@ box_param_t * gene_childboxbyOffset( box_param_t *superbox, Byte8_t offset);
* @param[in] TBox Box Type * @param[in] TBox Box Type
* @return pointer to the structure of generate/found box parameters * @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 * get DBox offset
@ -210,7 +210,7 @@ Byte8_t fetch_DBox8bytebigendian( box_param_t *box, long offset);
* @param[in] boxlist box list pointer * @param[in] boxlist box list pointer
* @return found box 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 * print box parameters

View File

@ -41,7 +41,7 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
boxheader_param_t * gene_boxheader( int fd, Byte8_t offset) boxheader_param_t * gene_boxheader( int fd, Byte8_t offset)
@ -55,7 +55,7 @@ boxheader_param_t * gene_boxheader( int fd, Byte8_t offset)
boxtype = (char *)fetch_bytes( fd, offset+4, 4); boxtype = (char *)fetch_bytes( fd, offset+4, 4);
headlen = 8; headlen = 8;
if( boxlen == 1){ // read XLBox if( boxlen == 1){ /* read XLBox */
boxlen = fetch_8bytebigendian( fd, offset+8); boxlen = fetch_8bytebigendian( fd, offset+8);
headlen = 16; headlen = 16;
} }

View File

@ -34,12 +34,12 @@
#include "byte_manager.h" #include "byte_manager.h"
#include "box_manager.h" #include "box_manager.h"
//! box header parameters /** box header parameters*/
typedef struct boxheader_param{ typedef struct boxheader_param{
Byte_t headlen; //!< header length 8 or 16 Byte_t headlen; /**< header length 8 or 16*/
Byte8_t length; //!< length of the reference Box Byte8_t length; /**< length of the reference Box*/
char type[4]; //!< type of information in the DBox char type[4]; /**< type of information in the DBox*/
struct boxheader_param *next; //!< pointer to the next header box struct boxheader_param *next; /**< pointer to the next header box*/
} boxheader_param_t; } boxheader_param_t;

View File

@ -29,9 +29,14 @@
*/ */
#include <stdio.h> #include <stdio.h>
#ifdef _WIN32
#include <io.h>
#else
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h>
#include "byte_manager.h" #include "byte_manager.h"
#ifdef SERVER #ifdef SERVER
@ -41,7 +46,7 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
Byte_t * fetch_bytes( int fd, long offset, int size) Byte_t * fetch_bytes( int fd, long offset, int size)
@ -153,3 +158,15 @@ void modify_4Bytecode( Byte4_t code, Byte_t *stream)
*(stream+2) = (Byte_t) ((Byte4_t)(code & 0x0000ff00) >> 8); *(stream+2) = (Byte_t) ((Byte4_t)(code & 0x0000ff00) >> 8);
*(stream+3) = (Byte_t) (code & 0x000000ff); *(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;
}

View File

@ -31,16 +31,16 @@
#ifndef BYTE_MANAGER_H_ #ifndef BYTE_MANAGER_H_
# define BYTE_MANAGER_H_ # define BYTE_MANAGER_H_
//! 1Byte parameter type /** 1Byte parameter type*/
typedef unsigned char Byte_t; typedef unsigned char Byte_t;
//! 2Byte parameter type /** 2Byte parameter type*/
typedef unsigned short int Byte2_t; typedef unsigned short int Byte2_t;
//! 4Byte parameter type /** 4Byte parameter type*/
typedef unsigned int Byte4_t; typedef unsigned int Byte4_t; /* FIXME: Is this portable ? */
//! 8Byte parameter type /** 8Byte parameter type*/
typedef unsigned long long int Byte8_t; typedef unsigned long long int Byte8_t;
@ -124,4 +124,12 @@ Byte8_t big8( Byte_t *buf);
*/ */
void modify_4Bytecode( Byte4_t code, Byte_t *stream); 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_ */ #endif /* !BYTE_MANAGER_H_ */

View File

@ -180,8 +180,8 @@ void add_cachecid( char *cid, cache_param_t *cache)
{ {
if( !cid) if( !cid)
return; 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"); fprintf( stderr, "failed to add new cid to cache table in add_cachecid()\n");
return; return;
} }

View File

@ -34,22 +34,22 @@
#include "metadata_manager.h" #include "metadata_manager.h"
#include "ihdrbox_manager.h" #include "ihdrbox_manager.h"
//! cache parameters /** cache parameters*/
typedef struct cache_param{ typedef struct cache_param{
char *filename; //!< file name char *filename; /**< file name*/
char *tid; //!< taregt identifier char *tid; /**< taregt identifier*/
int csn; //!< codestream number int csn; /**< codestream number*/
char **cid; //!< dynamic array of channel identifiers char **cid; /**< dynamic array of channel identifiers*/
int numOfcid; //!< number of cids int numOfcid; /**< number of cids*/
metadatalist_param_t *metadatalist; //!< metadata-bin list metadatalist_param_t *metadatalist; /**< metadata-bin list*/
ihdrbox_param_t *ihdrbox; //!< ihdrbox ihdrbox_param_t *ihdrbox; /**< ihdrbox*/
struct cache_param *next; //!< pointer to the next cache struct cache_param *next; /**< pointer to the next cache*/
} cache_param_t; } cache_param_t;
//!< cache list parameters /**< cache list parameters*/
typedef struct cachelist_param{ typedef struct cachelist_param{
cache_param_t *first; //!< first 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 cache_param_t *last; /**< last cache pointer of the list*/
} cachelist_param_t; } cachelist_param_t;

View File

@ -40,10 +40,10 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
cachemodellist_param_t * gene_cachemodellist() cachemodellist_param_t * gene_cachemodellist(void)
{ {
cachemodellist_param_t *cachemodellist; cachemodellist_param_t *cachemodellist;
@ -73,7 +73,7 @@ cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, ta
cachemodel->jppstream = true; cachemodel->jppstream = true;
else else
cachemodel->jppstream = false; cachemodel->jppstream = false;
} else{ // reqJPT } else{ /* reqJPT */
if( target->jptstream) if( target->jptstream)
cachemodel->jppstream = false; cachemodel->jppstream = false;
else else
@ -95,9 +95,9 @@ cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, ta
cachemodel->next = NULL; cachemodel->next = NULL;
if( cachemodellist){ if( cachemodellist){
if( cachemodellist->first) // there are one or more entries if( cachemodellist->first) /* there are one or more entries */
cachemodellist->last->next = cachemodel; cachemodellist->last->next = cachemodel;
else // first entry else /* first entry */
cachemodellist->first = cachemodel; cachemodellist->first = cachemodel;
cachemodellist->last = cachemodel; cachemodellist->last = cachemodel;
} }
@ -112,9 +112,10 @@ cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, ta
void print_cachemodel( cachemodel_param_t cachemodel) void print_cachemodel( cachemodel_param_t cachemodel)
{ {
target_param_t *target; target_param_t *target;
Byte8_t TPnum; // num of tile parts in each tile Byte8_t TPnum; /* num of tile parts in each tile */
Byte8_t Pmax; // max num of packets per tile Byte8_t Pmax; /* max num of packets per tile */
int i, j, k, n; Byte8_t i, j, k;
int n; /* FIXME: Is this large enough ? */
target = cachemodel.target; target = cachemodel.target;
@ -135,9 +136,9 @@ void print_cachemodel( cachemodel_param_t cachemodel)
fprintf( logstream, "\t tile header and precinct packet model:\n"); fprintf( logstream, "\t tile header and precinct packet model:\n");
for( i=0; i<target->codeidx->SIZ.XTnum*target->codeidx->SIZ.YTnum; i++){ 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++){ 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]); Pmax = get_nmax( target->codeidx->precpacket[j]);
for( k=0; k<Pmax; k++) for( k=0; k<Pmax; k++)
fprintf( logstream, "%d", cachemodel.pp_model[j][i*Pmax+k]); fprintf( logstream, "%d", cachemodel.pp_model[j][i*Pmax+k]);
@ -197,9 +198,10 @@ void delete_cachemodel( cachemodel_param_t **cachemodel)
bool is_allsent( cachemodel_param_t cachemodel) bool is_allsent( cachemodel_param_t cachemodel)
{ {
target_param_t *target; target_param_t *target;
Byte8_t TPnum; // num of tile parts in each tile Byte8_t TPnum; /* num of tile parts in each tile */
Byte8_t Pmax; // max num of packets per tile Byte8_t Pmax; /* max num of packets per tile */
int i, j, k, n; Byte8_t i, j, k;
int n; /* FIXME: is this large enough ? */
target = cachemodel.target; target = cachemodel.target;

View File

@ -34,21 +34,21 @@
#include "bool.h" #include "bool.h"
#include "target_manager.h" #include "target_manager.h"
//! Cache model parameters /** Cache model parameters*/
typedef struct cachemodel_param{ typedef struct cachemodel_param{
target_param_t *target; //!< reference pointer to the target target_param_t *target; /**< reference pointer to the target*/
bool jppstream; //!< return type, true: JPP-stream, false: JPT-stream bool jppstream; /**< return type, true: JPP-stream, false: JPT-stream*/
bool mhead_model; //!< main header model, if sent, 1, else 0 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 *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 *th_model; /**< dynamic array pointer of tile header model*/
bool **pp_model; //!< dynamic array pointer of precint packet model bool **pp_model; /**< dynamic array pointer of precint packet model*/
struct cachemodel_param *next; //!< pointer to the next cache model struct cachemodel_param *next; /**< pointer to the next cache model*/
} cachemodel_param_t; } cachemodel_param_t;
//! Cache model list parameters /** Cache model list parameters*/
typedef struct cachemodellist_param{ typedef struct cachemodellist_param{
cachemodel_param_t *first; //!< first 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 cachemodel_param_t *last; /**< last cache model pointer of the list*/
} cachemodellist_param_t; } cachemodellist_param_t;
@ -57,7 +57,7 @@ typedef struct cachemodellist_param{
* *
* @return pointer to the generated cache model list * @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 * generate a cache model under a list

View File

@ -36,24 +36,24 @@
#include "cachemodel_manager.h" #include "cachemodel_manager.h"
#include "auxtrans_manager.h" #include "auxtrans_manager.h"
//! maximum length of channel identifier /** maximum length of channel identifier*/
#define MAX_LENOFCID 30 #define MAX_LENOFCID 30
//! Channel parameters /** Channel parameters*/
typedef struct channel_param{ typedef struct channel_param{
cachemodel_param_t *cachemodel; //!< reference pointer to the cache model cachemodel_param_t *cachemodel; /**< reference pointer to the cache model*/
char cid[MAX_LENOFCID]; //!< channel identifier char cid[MAX_LENOFCID]; /**< channel identifier*/
cnew_transport_t aux; //!< auxiliary transport cnew_transport_t aux; /**< auxiliary transport*/
// - a record of the client's capabilities and preferences to the extent that the server queues requests /* - a record of the client's capabilities and preferences to the extent that the server queues requests*/
time_t start_tm; //!< starting time time_t start_tm; /**< starting time*/
struct channel_param *next; //!< pointer to the next channel struct channel_param *next; /**< pointer to the next channel*/
} channel_param_t; } channel_param_t;
//! Channel list parameters /** Channel list parameters*/
typedef struct channellist_param{ typedef struct channellist_param{
channel_param_t *first; //!< first 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 channel_param_t *last; /**< last channel pointer of the list*/
} channellist_param_t; } channellist_param_t;

View File

@ -33,11 +33,11 @@
#include "byte_manager.h" #include "byte_manager.h"
//! codestream parameters /** codestream parameters*/
typedef struct codestream_param{ typedef struct codestream_param{
int fd; //!< file descriptor int fd; /**< file descriptor*/
Byte8_t offset; //!< byte position of DBox (Box Contents) in the file Byte8_t offset; /**< byte position of DBox (Box Contents) in the file*/
Byte8_t length; //!< content length Byte8_t length; /**< content length*/
} codestream_param_t; } codestream_param_t;

View File

@ -31,7 +31,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "dec_clientmsg_handler.h" #include "dec_clientmsg_handler.h"
#include "ihdrbox_manager.h" #include "ihdrbox_manager.h"
#include "jpipstream_manager.h" #include "jpipstream_manager.h"
@ -58,7 +57,7 @@ void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist
metadatalist = gene_metadatalist(); metadatalist = gene_metadatalist();
parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist); parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist);
// cid registration /* cid registration*/
if( target != NULL){ if( target != NULL){
if((cache = search_cache( target, cachelist))){ if((cache = search_cache( target, cachelist))){
if( tid != NULL) if( tid != NULL)
@ -92,7 +91,7 @@ void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_par
char *CIDorTID, tmp[10]; char *CIDorTID, tmp[10];
cache_param_t *cache; cache_param_t *cache;
int fw, fh; int fw, fh;
CIDorTID = receive_string( connected_socket); CIDorTID = receive_string( connected_socket);
if(!(cache = search_cacheBycid( CIDorTID, cachelist))) if(!(cache = search_cacheBycid( CIDorTID, cachelist)))
@ -109,19 +108,21 @@ void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_par
receive_line( connected_socket, tmp); receive_line( connected_socket, tmp);
fh = atoi( tmp); fh = atoi( tmp);
pnmstream = jpipstream_to_pnm( jpipstream, msgqueue, cache->csn, fw, fh, &cache->ihdrbox); ihdrbox = NULL;
ihdrbox = cache->ihdrbox; 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); send_PNMstream( connected_socket, pnmstream, ihdrbox->width, ihdrbox->height, ihdrbox->nc, ihdrbox->bpc > 8 ? 255 : (1 << ihdrbox->bpc) - 1);
if( pnmstream) free( ihdrbox);
free( pnmstream); free( pnmstream);
} }
void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist) void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist)
{ {
char *cid; char *cid;
cache_param_t *cache; cache_param_t *cache;
boxcontents_param_t *boxcontents;
Byte_t *xmlstream;
cid = receive_string( connected_socket); cid = receive_string( connected_socket);
@ -132,8 +133,8 @@ void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_pa
free( cid); free( cid);
boxcontents_param_t *boxcontents = cache->metadatalist->last->boxcontents; boxcontents = cache->metadatalist->last->boxcontents;
Byte_t *xmlstream = (Byte_t *)malloc( boxcontents->length); xmlstream = (Byte_t *)malloc( boxcontents->length);
memcpy( xmlstream, jpipstream+boxcontents->offset, boxcontents->length); memcpy( xmlstream, jpipstream+boxcontents->offset, boxcontents->length);
send_XMLstream( connected_socket, xmlstream, boxcontents->length); send_XMLstream( connected_socket, xmlstream, boxcontents->length);
free( xmlstream); free( xmlstream);
@ -188,6 +189,36 @@ void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
free( cid); 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) void handle_JP2saveMSG( SOCKET connected_socket, cachelist_param_t *cachelist, msgqueue_param_t *msgqueue, Byte_t *jpipstream)
{ {
char *cid; char *cid;

View File

@ -91,6 +91,14 @@ void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
*/ */
void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist); 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 * handle saving JP2 file request message
* *

View File

@ -39,7 +39,7 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
faixbox_param_t * gene_faixbox( box_param_t *box) faixbox_param_t * gene_faixbox( box_param_t *box)
{ {
@ -51,7 +51,7 @@ faixbox_param_t * gene_faixbox( box_param_t *box)
faix->version = fetch_DBox1byte( box, (pos+=1)-1); 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); fprintf( FCGI_stderr, "Error: version %d in faix box is reserved for ISO use.\n", faix->version);
free(faix); free(faix);
return NULL; return NULL;
@ -59,7 +59,7 @@ faixbox_param_t * gene_faixbox( box_param_t *box)
if( faix->version%2){ if( faix->version%2){
subfaixbox8_param_t *subfaixbox; subfaixbox8_param_t *subfaixbox;
int i; size_t i;
faix->subfaixbox.byte8_params = (subfaixbox8_param_t *)malloc( sizeof(subfaixbox8_param_t)); faix->subfaixbox.byte8_params = (subfaixbox8_param_t *)malloc( sizeof(subfaixbox8_param_t));
@ -83,7 +83,7 @@ faixbox_param_t * gene_faixbox( box_param_t *box)
} }
else{ else{
subfaixbox4_param_t *subfaixbox; subfaixbox4_param_t *subfaixbox;
int i; size_t i;
faix->subfaixbox.byte4_params = (subfaixbox4_param_t *)malloc( sizeof(subfaixbox4_param_t)); faix->subfaixbox.byte4_params = (subfaixbox4_param_t *)malloc( sizeof(subfaixbox4_param_t));
@ -182,10 +182,11 @@ Byte8_t get_elemLen( faixbox_param_t *faix, Byte8_t elem_id, Byte8_t row_id)
Byte4_t get_elemAux( faixbox_param_t *faix, Byte8_t elem_id, Byte8_t row_id) Byte4_t get_elemAux( faixbox_param_t *faix, Byte8_t elem_id, Byte8_t row_id)
{ {
Byte8_t nmax;
if( faix->version <2) if( faix->version <2)
return -1; return -1;
Byte8_t nmax = get_nmax( faix); nmax = get_nmax( faix);
if( faix->version%2) if( faix->version%2)
return faix->subfaixbox.byte8_params->aux[ row_id*nmax+elem_id]; return faix->subfaixbox.byte8_params->aux[ row_id*nmax+elem_id];
else else

View File

@ -34,47 +34,47 @@
#include "byte_manager.h" #include "byte_manager.h"
#include "box_manager.h" #include "box_manager.h"
//! 4byte parameters of a faix element /** 4byte parameters of a faix element*/
typedef struct faixelem4_param{ typedef struct faixelem4_param{
Byte4_t off; //!< offset Byte4_t off; /**< offset*/
Byte4_t len; //!< length Byte4_t len; /**< length*/
} faixelem4_param_t; } faixelem4_param_t;
//! 8byte parameters of a faix element /** 8byte parameters of a faix element*/
typedef struct faixelem8_param{ typedef struct faixelem8_param{
Byte8_t off; //!< offset Byte8_t off; /**< offset*/
Byte8_t len; //!< length Byte8_t len; /**< length*/
} faixelem8_param_t; } faixelem8_param_t;
//! 4byte parameters of fragment array index box /** 4byte parameters of fragment array index box*/
typedef struct subfaixbox4_param{ typedef struct subfaixbox4_param{
Byte4_t nmax; //!< maximum number of valid elements in any row of the array Byte4_t nmax; /**< maximum number of valid elements in any row of the array*/
Byte4_t m; //!< number of raws of the array Byte4_t m; /**< number of raws of the array*/
faixelem4_param_t *elem; //!< dynamic array pointer of faix elements faixelem4_param_t *elem; /**< dynamic array pointer of faix elements*/
Byte4_t *aux; //!< dynamic array pointer of auxiliary Byte4_t *aux; /**< dynamic array pointer of auxiliary*/
//!info in each element for version 2 or 3 /**info in each element for version 2 or 3*/
} subfaixbox4_param_t; } subfaixbox4_param_t;
//! 8byte parameters of fragment array index box /** 8byte parameters of fragment array index box*/
typedef struct subfaixbox8_param{ typedef struct subfaixbox8_param{
Byte8_t nmax; //!< maximum number of valid elements in any row of the array Byte8_t nmax; /**< maximum number of valid elements in any row of the array*/
Byte8_t m; //!< number of raws of the array Byte8_t m; /**< number of raws of the array*/
faixelem8_param_t *elem; //!< dynamic array pointer of faix elements faixelem8_param_t *elem; /**< dynamic array pointer of faix elements*/
Byte4_t *aux; //!< dynamic array pointer of auxiliary Byte4_t *aux; /**< dynamic array pointer of auxiliary*/
//!info in each element for version 2 or 3 /**info in each element for version 2 or 3*/
} subfaixbox8_param_t; } subfaixbox8_param_t;
//! variable sized parameters in fragment array index box /** variable sized parameters in fragment array index box*/
typedef union subfaixbox_param{ typedef union subfaixbox_param{
subfaixbox4_param_t *byte4_params; //!< parameters with 4byte codes for version 0 or 2 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 subfaixbox8_param_t *byte8_params; /**< parameters with 8byte codes for version 1 or 3*/
} subfaixbox_param_t; } subfaixbox_param_t;
//! fragment array index box parameters /** fragment array index box parameters*/
//! I.3.2.4.2 Fragment Array Index box /** I.3.2.4.2 Fragment Array Index box*/
typedef struct faixbox_param{ typedef struct faixbox_param{
Byte_t version; //!< Refer to the Table I.3 - Version values Byte_t version; /**< Refer to the Table I.3 - Version values*/
subfaixbox_param_t subfaixbox; //!< rest information in faixbox subfaixbox_param_t subfaixbox; /**< rest information in faixbox*/
} faixbox_param_t; } faixbox_param_t;

View File

@ -35,12 +35,12 @@
#include "box_manager.h" #include "box_manager.h"
#include "metadata_manager.h" #include "metadata_manager.h"
//! I.5.3.1 Image Header box /** I.5.3.1 Image Header box*/
typedef struct ihdrbox_param{ typedef struct ihdrbox_param{
Byte4_t height; Byte4_t height;
Byte4_t width; Byte4_t width;
Byte2_t nc; //!< number of components Byte2_t nc; /**< number of components*/
Byte_t bpc; //!< bits per component Byte_t bpc; /**< bits per component*/
} ihdrbox_param_t; } ihdrbox_param_t;
/** /**

View File

@ -40,7 +40,7 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
imgreg_param_t map_viewin2imgreg( const int fx, const int fy, imgreg_param_t map_viewin2imgreg( const int fx, const int fy,
const int rx, const int ry, const int rx, const int ry,
@ -106,13 +106,13 @@ void find_level( int maxlev, int *lev, int *fx, int *fy, int *xmin, int *ymin, i
int xwidth = *xmax - *xmin; int xwidth = *xmax - *xmin;
int ywidth = *ymax - *ymin; 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)){ if ((*fx < 1 && xwidth != 0) || (*fy < 1 && ywidth != 0)){
fprintf( FCGI_stderr, "Frame size must be strictly positive"); fprintf( FCGI_stderr, "Frame size must be strictly positive");
exit(-1); exit(-1);
} }
else if( *lev < maxlev-1 && ( *fx < xwidth || *fy < ywidth)) { else if( *lev < maxlev-1 && ( *fx < xwidth || *fy < ywidth)) {
// Simulate the ceil function. /* Simulate the ceil function. */
*xmin = ceil((double)*xmin/(double)2.0); *xmin = ceil((double)*xmin/(double)2.0);
*ymin = ceil((double)*ymin/(double)2.0); *ymin = ceil((double)*ymin/(double)2.0);
*xmax = ceil((double)*xmax/(double)2.0); *xmax = ceil((double)*xmax/(double)2.0);
@ -149,5 +149,7 @@ void print_imgreg( imgreg_param_t imgreg)
fprintf( logstream, "\t roff: %d, %d\n", imgreg.ox, imgreg.oy); 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 rsiz: %d, %d\n", imgreg.sx, imgreg.sy);
fprintf( logstream, "\t level: %d\n", imgreg.level); fprintf( logstream, "\t level: %d\n", imgreg.level);
#else
(void)imgreg;
#endif #endif
} }

View File

@ -31,14 +31,14 @@
#ifndef IMGREG_MANAGER_H_ #ifndef IMGREG_MANAGER_H_
# define IMGREG_MANAGER_H_ # define IMGREG_MANAGER_H_
//! image region parameters /** image region parameters */
typedef struct imgreg_param{ typedef struct imgreg_param{
int xosiz, yosiz; //!< offset from the origin of the reference grid int xosiz, yosiz; /** offset from the origin of the reference grid
//!at the decomposition level at the decomposition level */
int fx, fy; //!< frame size (fsiz) int fx, fy; /** frame size (fsiz) */
int ox, oy; //!< offset (roff) int ox, oy; /** offset (roff) */
int sx, sy; //!< region size (rsiz) int sx, sy; /** region size (rsiz) */
int level; //!< decomposition level int level; /** decomposition level */
} imgreg_param_t; } imgreg_param_t;

View File

@ -32,12 +32,17 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "imgsock_manager.h" #include "imgsock_manager.h"
#if _WIN32
#define strncasecmp _strnicmp
#endif
msgtype_t identify_clientmsg( SOCKET connected_socket) msgtype_t identify_clientmsg( SOCKET connected_socket)
{ {
int receive_size; int receive_size;
char buf[BUF_LEN]; 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; int i;
receive_size = receive_line( connected_socket, buf); receive_size = receive_line( connected_socket, buf);
@ -77,7 +82,7 @@ Byte_t * receive_JPIPstream( SOCKET connected_socket, char **target, char **tid,
return NULL; return NULL;
if( strstr( buf, "jp2")){ if( strstr( buf, "jp2")){
// register cid option /* register cid option*/
*target = strdup( buf); *target = strdup( buf);
if((linelen = receive_line( connected_socket, buf)) == 0) if((linelen = receive_line( connected_socket, buf)) == 0)
@ -99,7 +104,7 @@ Byte_t * receive_JPIPstream( SOCKET connected_socket, char **target, char **tid,
jpipstream = receive_stream( connected_socket, datalen); jpipstream = receive_stream( connected_socket, datalen);
// check EOR /* check EOR*/
if( jpipstream[datalen-3] == 0x00 && ( jpipstream[datalen-2] == 0x01 || jpipstream[datalen-2] == 0x02)) if( jpipstream[datalen-3] == 0x00 && ( jpipstream[datalen-2] == 0x01 || jpipstream[datalen-2] == 0x02))
*streamlen = datalen -3; *streamlen = datalen -3;
else else
@ -122,7 +127,7 @@ void send_XMLstream( SOCKET connected_socket, Byte_t *xmlstream, int length)
send_stream( connected_socket, xmlstream, length); 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) void send_CIDstream( SOCKET connected_socket, char *cid, int cidlen)
{ {
@ -134,7 +139,7 @@ void send_TIDstream( SOCKET connected_socket, char *tid, int tidlen)
send_IDstream( connected_socket, tid, tidlen, "TID"); 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]; Byte_t header[4];
@ -166,6 +171,23 @@ void send_PNMstream( SOCKET connected_socket, Byte_t *pnmstream, unsigned int wi
send_stream( connected_socket, pnmstream, pnmlen); 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) void response_signal( SOCKET connected_socket, bool succeed)
{ {
Byte_t code; Byte_t code;

View File

@ -35,8 +35,8 @@
#include "byte_manager.h" #include "byte_manager.h"
#include "sock_manager.h" #include "sock_manager.h"
#define NUM_OF_MSGTYPES 8 #define NUM_OF_MSGTYPES 9
typedef enum eMSGTYPE{ JPIPSTREAM, PNMREQ, XMLREQ, TIDREQ, CIDREQ, CIDDST, JP2SAVE, QUIT, MSGERROR} msgtype_t; typedef enum eMSGTYPE{ JPIPSTREAM, PNMREQ, XMLREQ, TIDREQ, CIDREQ, CIDDST, SIZREQ, JP2SAVE, QUIT, MSGERROR} msgtype_t;
/** /**
* indeitify client message type * indeitify client message type
@ -63,8 +63,8 @@ Byte_t * receive_JPIPstream( SOCKET connected_socket, char **target, char **tid,
* *
* @param [in] connected_socket file descriptor of the connected socket * @param [in] connected_socket file descriptor of the connected socket
* @param [in] pnmstream PGM/PPM image codestream * @param [in] pnmstream PGM/PPM image codestream
* @param [in] width width of the image * @param [in] width width of the PGM/PPM image (different from the original image)
* @param [in] height height of the image * @param [in] height height of the PGM/PPM image
* @param [in] numofcomp number of components of the image * @param [in] numofcomp number of components of the image
* @param [in] maxval maximum value of the image (only 255 supported) * @param [in] maxval maximum value of the image (only 255 supported)
*/ */
@ -97,6 +97,15 @@ void send_TIDstream( SOCKET connected_socket, char *tid, int tidlen);
*/ */
void send_CIDstream( SOCKET connected_socket, char *cid, int cidlen); 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 * send response signal to the client
* *
@ -146,13 +155,19 @@ void response_signal( SOCKET connected_socket, bool succeed);
* client -> server: CID destroy\\n ciddata \n * client -> server: CID destroy\\n ciddata \n
* server -> client: 1 or 0 (of 1Byte response signal) * 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 * Save in JP2 file format
* *
* client -> server: JP2 save\\n ciddata \n * client -> server: JP2 save\\n ciddata \n
* server -> client: 1 or 0 (of 1Byte response signal) * server -> client: 1 or 0 (of 1Byte response signal)
* *
*\section sec8 QUIT *\section sec9 QUIT
* Quit the opj_dec_server program * Quit the opj_dec_server program
* *
* client -> server: quit or QUIT * client -> server: quit or QUIT

View File

@ -31,9 +31,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include "bool.h" #include "bool.h"
@ -53,7 +50,7 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
/** /**
* chekc JP2 box indexing * chekc JP2 box indexing
@ -79,14 +76,12 @@ index_param_t * parse_jp2file( int fd)
box_param_t *cidx; box_param_t *cidx;
metadatalist_param_t *metadatalist; metadatalist_param_t *metadatalist;
boxlist_param_t *toplev_boxlist; boxlist_param_t *toplev_boxlist;
struct stat sb; Byte8_t filesize;
if( fstat( fd, &sb) == -1){
fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
return NULL;
}
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"); fprintf( FCGI_stderr, "Error: Not correctl JP2 format\n");
return NULL; return NULL;
} }
@ -139,7 +134,7 @@ void print_index( index_param_t index)
print_faixbox( index.tilepart); print_faixbox( index.tilepart);
fprintf( logstream, "Tile header information: \n"); 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]); print_mhixbox( index.tileheader[i]);
fprintf( logstream, "Precinct packet information: \n"); fprintf( logstream, "Precinct packet information: \n");
@ -188,12 +183,11 @@ void delete_index( index_param_t **index)
delete_metadatalist( &((*index)->metadatalist)); delete_metadatalist( &((*index)->metadatalist));
free( (*index)->COD.XPsiz); delete_COD( (*index)->COD);
free( (*index)->COD.YPsiz);
delete_faixbox( &((*index)->tilepart)); 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])); delete_mhixbox( &((*index)->tileheader[i]));
free( (*index)->tileheader); free( (*index)->tileheader);
@ -204,10 +198,24 @@ void delete_index( index_param_t **index)
free(*index); 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) bool check_JP2boxidx( boxlist_param_t *toplev_boxlist)
{ {
box_param_t *iptr, *fidx, *prxy; box_param_t *iptr, *fidx, *prxy;
box_param_t *cidx, *jp2c; 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); iptr = search_box( "iptr", toplev_boxlist);
fidx = search_box( "fidx", toplev_boxlist); fidx = search_box( "fidx", toplev_boxlist);
@ -215,40 +223,39 @@ bool check_JP2boxidx( boxlist_param_t *toplev_boxlist)
jp2c = search_box( "jp2c", toplev_boxlist); jp2c = search_box( "jp2c", toplev_boxlist);
prxy = gene_childboxbyType( fidx, 0, "prxy"); prxy = gene_childboxbyType( fidx, 0, "prxy");
Byte8_t off = fetch_DBox8bytebigendian( iptr, 0); off = fetch_DBox8bytebigendian( iptr, 0);
if( off != fidx->offset) if( off != fidx->offset)
fprintf( FCGI_stderr, "Reference File Index box offset in Index Finder box not correct\n"); 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) if( len != fidx->length)
fprintf( FCGI_stderr, "Reference File Index box length in Index Finder box not correct\n"); fprintf( FCGI_stderr, "Reference File Index box length in Index Finder box not correct\n");
pos = 0;
int pos = 0; ooff = fetch_DBox8bytebigendian( prxy, pos);
Byte8_t ooff = fetch_DBox8bytebigendian( prxy, pos);
if( ooff != jp2c->offset) if( ooff != jp2c->offset)
fprintf( FCGI_stderr, "Reference jp2c offset in prxy box not correct\n"); fprintf( FCGI_stderr, "Reference jp2c offset in prxy box not correct\n");
pos += 8; 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) if( obh->length != jp2c->length || strncmp( obh->type, "jp2c",4)!=0)
fprintf( FCGI_stderr, "Reference jp2c header in prxy box not correct\n"); fprintf( FCGI_stderr, "Reference jp2c header in prxy box not correct\n");
pos += obh->headlen; pos += obh->headlen;
free(obh); free(obh);
Byte_t ni = fetch_DBox1byte( prxy, pos); ni = fetch_DBox1byte( prxy, pos);
if( ni != 1){ if( ni != 1){
fprintf( FCGI_stderr, "Multiple indexes not supported\n"); fprintf( FCGI_stderr, "Multiple indexes not supported\n");
return false; return false;
} }
pos += 1; pos += 1;
Byte8_t ioff = fetch_DBox8bytebigendian( prxy, pos); ioff = fetch_DBox8bytebigendian( prxy, pos);
if( ioff != cidx->offset) if( ioff != cidx->offset)
fprintf( FCGI_stderr, "Reference cidx offset in prxy box not correct\n"); fprintf( FCGI_stderr, "Reference cidx offset in prxy box not correct\n");
pos += 8; 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) if( ibh->length != cidx->length || strncmp( ibh->type, "cidx",4)!=0)
fprintf( FCGI_stderr, "Reference cidx header in prxy box not correct\n"); fprintf( FCGI_stderr, "Reference cidx header in prxy box not correct\n");
pos += ibh->headlen; pos += ibh->headlen;
@ -359,23 +366,23 @@ bool set_cidxdata( box_param_t *cidx_box, index_param_t *jp2idx)
bool set_cptrdata( box_param_t *cidx_box, index_param_t *jp2idx) 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; Byte2_t dr, cont;
if( !(box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "cptr"))) if( !(box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "cptr")))
return false; return false;
// DR: Data Reference. /* DR: Data Reference. */
// If 0, the codestream or its Fragment Table box exists in the current file /* If 0, the codestream or its Fragment Table box exists in the current file*/
if(( dr = fetch_DBox2bytebigendian( box, 0))){ if(( dr = fetch_DBox2bytebigendian( box, 0))){
fprintf( FCGI_stderr, "Error: Codestream not present in current file\n"); fprintf( FCGI_stderr, "Error: Codestream not present in current file\n");
free( box); free( box);
return false; return false;
} }
// CONT: Container Type /* CONT: Container Type*/
// If 0, the entire codestream appears as a contiguous range of /* If 0, the entire codestream appears as a contiguous range of*/
// bytes within its file or resource. /* bytes within its file or resource.*/
if(( cont = fetch_DBox2bytebigendian( box, 2))){ if(( cont = fetch_DBox2bytebigendian( box, 2))){
fprintf( FCGI_stderr, "Error: Can't cope with fragmented codestreams yet\n"); fprintf( FCGI_stderr, "Error: Can't cope with fragmented codestreams yet\n");
free( box); free( box);
@ -443,8 +450,8 @@ bool set_mainmhixdata( box_param_t *cidx_box, codestream_param_t codestream, ind
bool set_tpixdata( box_param_t *cidx_box, index_param_t *jp2idx) bool set_tpixdata( box_param_t *cidx_box, index_param_t *jp2idx)
{ {
box_param_t *tpix_box; //!< tpix box box_param_t *tpix_box; /**< tpix box*/
box_param_t *faix_box; //!< faix 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"))){ 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"); fprintf( FCGI_stderr, "Error: tpix box not present in cidx box\n");
@ -518,9 +525,9 @@ bool set_thixdata( box_param_t *cidx_box, index_param_t *jp2idx)
bool set_ppixdata( box_param_t *cidx_box, index_param_t *jp2idx) bool set_ppixdata( box_param_t *cidx_box, index_param_t *jp2idx)
{ {
box_param_t *ppix_box, *faix_box, *manf_box; box_param_t *ppix_box, *faix_box, *manf_box;
manfbox_param_t *manf; //!< manf manfbox_param_t *manf; /**< manf*/
boxheader_param_t *bh; //!< box headers boxheader_param_t *bh; /**< box headers*/
faixbox_param_t *faix; //!< faix faixbox_param_t *faix; /**< faix*/
Byte8_t inbox_offset; Byte8_t inbox_offset;
int comp_idx; int comp_idx;
@ -630,7 +637,7 @@ bool set_CODmkrdata( markeridx_param_t *codmkidx, codestream_param_t codestream,
COD->YPsiz = (Byte4_t *)malloc( (COD->numOfdecomp+1)*sizeof(Byte4_t)); COD->YPsiz = (Byte4_t *)malloc( (COD->numOfdecomp+1)*sizeof(Byte4_t));
for( i=0; i<=COD->numOfdecomp; i++){ for( i=0; i<=COD->numOfdecomp; i++){
//precinct size /*precinct size*/
COD->XPsiz[i] = pow( 2, fetch_marker1byte( codmkr, 12+i) & 0x0F); COD->XPsiz[i] = pow( 2, fetch_marker1byte( codmkr, 12+i) & 0x0F);
COD->YPsiz[i] = pow( 2,(fetch_marker1byte( codmkr, 12+i) & 0xF0) >> 4); COD->YPsiz[i] = pow( 2,(fetch_marker1byte( codmkr, 12+i) & 0xF0) >> 4);
} }
@ -645,6 +652,13 @@ bool set_CODmkrdata( markeridx_param_t *codmkidx, codestream_param_t codestream,
} }
/* 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 max( Byte4_t n1, Byte4_t n2);
Byte4_t min( Byte4_t n1, Byte4_t n2); Byte4_t min( Byte4_t n1, Byte4_t n2);
@ -691,6 +705,7 @@ Byte4_t get_tile_YSiz( SIZmarker_param_t SIZ, Byte4_t tile_id, int level)
return tile_Yrange.maxvalue - tile_Yrange.minvalue; 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) Byte4_t max( Byte4_t n1, Byte4_t n2)
{ {
if( n1 < n2) if( n1 < n2)

View File

@ -37,7 +37,7 @@
#include "mhixbox_manager.h" #include "mhixbox_manager.h"
#include "bool.h" #include "bool.h"
//! progression order /** progression order */
typedef enum porder { typedef enum porder {
PROG_UNKNOWN = -1, /**< place-holder */ PROG_UNKNOWN = -1, /**< place-holder */
LRCP = 0, /**< layer-resolution-component-precinct order */ LRCP = 0, /**< layer-resolution-component-precinct order */
@ -47,48 +47,48 @@ typedef enum porder {
CPRL = 4 /**< component-precinct-resolution-layer order */ CPRL = 4 /**< component-precinct-resolution-layer order */
} porder_t; } porder_t;
//! A.5.1 Image and tile size (SIZ) /** A.5.1 Image and tile size (SIZ)*/
typedef struct SIZmarker_param{ typedef struct SIZmarker_param{
Byte2_t Lsiz; //!< length of marker segment excluding the marker Byte2_t Lsiz; /**< length of marker segment excluding the marker*/
Byte2_t Rsiz; //!< capabilities that a decoder needs Byte2_t Rsiz; /**< capabilities that a decoder needs*/
Byte4_t Xsiz; //!< width of the reference grid Byte4_t Xsiz; /**< width of the reference grid*/
Byte4_t Ysiz; //!< height 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 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 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 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 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 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 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 XTnum; /**< number of tiles in horizontal direction*/
Byte4_t YTnum; //!< number of tiles in vertical direction Byte4_t YTnum; /**< number of tiles in vertical direction*/
Byte2_t Csiz; //!< number of the components in the image 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 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 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 Byte_t YRsiz[3]; /**< vertical separation of a sample of component with respect to the reference grid*/
} SIZmarker_param_t; } SIZmarker_param_t;
//! A.6.1 Coding style default (COD) /** A.6.1 Coding style default (COD)*/
typedef struct CODmarker_param{ typedef struct CODmarker_param{
Byte2_t Lcod; //!< length of marker segment excluding the marker Byte2_t Lcod; /**< length of marker segment excluding the marker*/
Byte_t Scod; //!< Coding style for all components Byte_t Scod; /**< Coding style for all components*/
porder_t prog_order; //!< progression order porder_t prog_order; /**< progression order*/
Byte2_t numOflayers; //!< number of layers Byte2_t numOflayers; /**< number of layers*/
Byte_t numOfdecomp; //!< number of decompositions levels Byte_t numOfdecomp; /**< number of decompositions levels*/
Byte4_t *XPsiz; //!< dynamic array of precinct width at successive resolution level in order 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 Byte4_t *YPsiz; /**< dynamic array of precinct height at successive resolution level in order*/
} CODmarker_param_t; } CODmarker_param_t;
//! index parameters /** index parameters*/
typedef struct index_param{ typedef struct index_param{
metadatalist_param_t *metadatalist; //!< metadata-bin list metadatalist_param_t *metadatalist; /**< metadata-bin list*/
Byte8_t offset; //!< codestream offset Byte8_t offset; /**< codestream offset*/
Byte8_t length; //!< codestream length Byte8_t length; /**< codestream length */
Byte8_t mhead_length; //!< main header length Byte8_t mhead_length; /**< main header length */
SIZmarker_param_t SIZ; // !< SIZ marker information SIZmarker_param_t SIZ; /**< SIZ marker information*/
CODmarker_param_t COD; // !< COD marker information CODmarker_param_t COD; /**< COD marker information*/
faixbox_param_t *tilepart; //!< tile part information from tpix box faixbox_param_t *tilepart; /**< tile part information from tpix box*/
mhixbox_param_t **tileheader; //!< dynamic array of tile header information from thix 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 faixbox_param_t **precpacket; /**< dynamic array of precint packet information from ppix box*/
} index_param_t; } index_param_t;
@ -129,10 +129,18 @@ void print_COD( CODmarker_param_t COD);
*/ */
void delete_index( index_param_t **index); 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{ typedef struct range_param{
Byte4_t minvalue; //!< minimal value Byte4_t minvalue; /**< minimal value*/
Byte4_t maxvalue; //!< maximal value Byte4_t maxvalue; /**< maximal value*/
} range_param_t; } range_param_t;
/** /**

View File

@ -45,7 +45,7 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
/** /**
@ -105,11 +105,11 @@ Byte_t * recons_jp2( msgqueue_param_t *msgqueue, Byte_t *jpipstream, Byte8_t csn
if( ptr->phld){ if( ptr->phld){
if( strncmp( (char *)ptr->phld->OrigBH+4, "jp2c", 4) == 0){ if( strncmp( (char *)ptr->phld->OrigBH+4, "jp2c", 4) == 0){
jp2cDBoxOffset = *jp2len + ptr->phld->OrigBHlen; 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; jp2cDBoxlen = *jp2len - jp2cDBoxOffset;
} }
else 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); jp2stream = add_msgstream( ptr, jpipstream, jp2stream, jp2len);
ptr = ptr->next; ptr = ptr->next;
@ -203,7 +203,7 @@ Byte_t * recons_codestream_from_JPTstream( msgqueue_param_t *msgqueue, Byte_t *j
} }
ptr = msgqueue->first; ptr = msgqueue->first;
while(( ptr = search_message( EXT_TILE_MSG, tileID, csn, ptr))!=NULL){ 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){ if( ptr->bin_offset == binOffset){
found = true; found = true;
j2kstream = add_msgstream( ptr, jpipstream, j2kstream, j2klen); j2kstream = add_msgstream( ptr, jpipstream, j2kstream, j2klen);
@ -278,10 +278,14 @@ Byte_t * recons_codestream_from_JPPstream( msgqueue_param_t *msgqueue, Byte_t *j
} }
if( max_reslev < COD.numOfdecomp) 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; return j2kstream;
}
j2kstream = add_EOC( j2kstream, j2klen); j2kstream = add_EOC( j2kstream, j2klen);
delete_COD( COD);
return j2kstream; return j2kstream;
} }
@ -621,7 +625,7 @@ Byte8_t get_last_tileID( msgqueue_param_t *msgqueue, Byte8_t csn, bool isJPPstre
message_param_t * search_message( Byte8_t class_id, Byte8_t in_class_id, Byte8_t csn, message_param_t *msg) message_param_t * search_message( Byte8_t class_id, Byte8_t in_class_id, Byte8_t csn, message_param_t *msg)
{ {
while( msg != NULL){ while( msg != NULL){
if( in_class_id == -1){ if( in_class_id == (Byte8_t)-1){
if( msg->class_id == class_id && msg->csn == csn) if( msg->class_id == class_id && msg->csn == csn)
return msg; return msg;
} }
@ -785,3 +789,9 @@ Byte_t * gene_emptytilestream( const Byte8_t tileID, Byte8_t *length)
return buf; 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);
}

View File

@ -60,5 +60,15 @@ Byte_t * recons_j2k( msgqueue_param_t *msgqueue, Byte_t *jpipstream, Byte8_t csn
*/ */
Byte_t * recons_jp2( msgqueue_param_t *msgqueue, Byte_t *jpipstream, Byte8_t csn, Byte8_t *jp2len); 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_ */ #endif /* !JP2K_ENCODER_H_ */

View File

@ -43,7 +43,7 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target) bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target)
@ -132,35 +132,35 @@ bool close_channel( query_param_t query_param,
#ifndef SERVER #ifndef SERVER
fprintf( logstream, "local log: close all\n"); fprintf( logstream, "local log: close all\n");
#endif #endif
// all channels associatd with the session will be closed /* all channels associatd with the session will be closed */
if( !delete_session( cursession, sessionlist)) if( !delete_session( cursession, sessionlist))
return false; return false;
} }
else{ 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)){ 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( *cursession == NULL){
if( !search_session_and_channel( cclose, sessionlist, cursession, curchannel)) if( !search_session_and_channel( cclose, sessionlist, cursession, curchannel))
return false; 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))){ if( !(*curchannel=search_channel( cclose, (*cursession)->channellist))){
fprintf( FCGI_stdout, "Reason: Cclose id %s is from another session\r\n", cclose); fprintf( FCGI_stdout, "Reason: Cclose id %s is from another session\r\n", cclose);
return false; return false;
} }
} }
// delete channels /* delete channels */
for( i=0, cclose=query_param.cclose; i<query_param.numOfcclose; i++, cclose += (strlen(cclose)+1)){ for( i=0, cclose=query_param.cclose; i<query_param.numOfcclose; i++, cclose += (strlen(cclose)+1)){
*curchannel = search_channel( cclose, (*cursession)->channellist); *curchannel = search_channel( cclose, (*cursession)->channellist);
delete_channel( curchannel, (*cursession)->channellist); delete_channel( curchannel, (*cursession)->channellist);
} }
if( (*cursession)->channellist->first == NULL || (*cursession)->channellist->last == NULL) if( (*cursession)->channellist->first == NULL || (*cursession)->channellist->last == NULL)
// In case of empty session /* In case of empty session */
delete_session( cursession, sessionlist); delete_session( cursession, sessionlist);
} }
return true; return true;
@ -181,8 +181,9 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue);
* @param[in] query_param structured query * @param[in] query_param structured query
* @param[in] metadatalist pointer to metadata bin list * @param[in] metadatalist pointer to metadata bin list
* @param[in,out] msgqueue message queue pointer * @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, bool gene_JPIPstream( query_param_t query_param,
@ -194,14 +195,14 @@ bool gene_JPIPstream( query_param_t query_param,
index_param_t *codeidx; index_param_t *codeidx;
cachemodel_param_t *cachemodel; cachemodel_param_t *cachemodel;
if( !cursession || !curchannel){ // stateless if( !cursession || !curchannel){ /* stateless */
if( !target) if( !target)
return false; return false;
if( !(cachemodel = gene_cachemodel( NULL, target, query_param.return_type==JPPstream))) if( !(cachemodel = gene_cachemodel( NULL, target, query_param.return_type==JPPstream)))
return false; return false;
*msgqueue = gene_msgqueue( true, cachemodel); *msgqueue = gene_msgqueue( true, cachemodel);
} }
else{ // session else{ /* session */
cachemodel = curchannel->cachemodel; cachemodel = curchannel->cachemodel;
target = cachemodel->target; target = cachemodel->target;
*msgqueue = gene_msgqueue( false, cachemodel); *msgqueue = gene_msgqueue( false, cachemodel);
@ -221,16 +222,22 @@ bool gene_JPIPstream( query_param_t query_param,
} }
} }
//meta /*meta*/
if( query_param.box_type[0][0] != 0 && query_param.len != 0) 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 /* main header */
if( query_param.fx > 0 && query_param.fy > 0){ if( !cachemodel->mhead_model && query_param.len != 0)
if( !cachemodel->mhead_model && query_param.len != 0)
enqueue_mainheader( *msgqueue); enqueue_mainheader( *msgqueue);
/* image codestream */
if( (query_param.fx > 0 && query_param.fy > 0))
enqueue_imagedata( query_param, *msgqueue); enqueue_imagedata( query_param, *msgqueue);
}
return true; return true;
} }
@ -270,13 +277,13 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
index_param_t *codeidx; index_param_t *codeidx;
imgreg_param_t imgreg; imgreg_param_t imgreg;
range_param_t tile_Xrange, tile_Yrange; range_param_t tile_Xrange, tile_Yrange;
int u, v, tile_id; Byte4_t u, v, tile_id;
int xmin, xmax, ymin, ymax; int xmin, xmax, ymin, ymax;
int numOfreslev; int numOfreslev;
codeidx = msgqueue->cachemodel->target->codeidx; 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; numOfreslev = 1;
else else
numOfreslev = codeidx->COD.numOfdecomp+1; numOfreslev = codeidx->COD.numOfdecomp+1;
@ -296,20 +303,20 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
tile_Xrange = get_tile_Xrange( codeidx->SIZ, tile_id, imgreg.level); 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.minvalue < tile_Xrange.maxvalue && tile_Yrange.minvalue < tile_Yrange.maxvalue){
if( tile_Xrange.maxvalue <= imgreg.xosiz + imgreg.ox || if( tile_Xrange.maxvalue <= (Byte4_t)(imgreg.xosiz + imgreg.ox) ||
tile_Xrange.minvalue >= imgreg.xosiz + imgreg.ox + imgreg.sx || tile_Xrange.minvalue >= (Byte4_t)(imgreg.xosiz + imgreg.ox + imgreg.sx) ||
tile_Yrange.maxvalue <= imgreg.yosiz + imgreg.oy || tile_Yrange.maxvalue <= (Byte4_t)(imgreg.yosiz + imgreg.oy) ||
tile_Yrange.minvalue >= imgreg.yosiz + imgreg.oy + imgreg.sy) { tile_Yrange.minvalue >= (Byte4_t)(imgreg.yosiz + imgreg.oy + imgreg.sy)) {
//printf("Tile completely excluded from view-window %d\n", tile_id); /*printf("Tile completely excluded from view-window %d\n", tile_id);*/
// Tile completely excluded from view-window /* Tile completely excluded from view-window */
} }
else if( tile_Xrange.minvalue >= imgreg.xosiz + imgreg.ox && else if( tile_Xrange.minvalue >= (Byte4_t)(imgreg.xosiz + imgreg.ox) &&
tile_Xrange.maxvalue <= imgreg.xosiz + imgreg.ox + imgreg.sx && tile_Xrange.maxvalue <= (Byte4_t)(imgreg.xosiz + imgreg.ox + imgreg.sx) &&
tile_Yrange.minvalue >= imgreg.yosiz + imgreg.oy && tile_Yrange.minvalue >= (Byte4_t)(imgreg.yosiz + imgreg.oy) &&
tile_Yrange.maxvalue <= imgreg.yosiz + imgreg.oy + imgreg.sy) { tile_Yrange.maxvalue <= (Byte4_t)(imgreg.yosiz + imgreg.oy + imgreg.sy)) {
// Tile completely contained within view-window /* Tile completely contained within view-window */
// high priority /* high priority */
//printf("Tile completely contained within view-window %d\n", tile_id); /*printf("Tile completely contained within view-window %d\n", tile_id);*/
if( msgqueue->cachemodel->jppstream){ if( msgqueue->cachemodel->jppstream){
enqueue_tileheader( tile_id, msgqueue); enqueue_tileheader( tile_id, msgqueue);
enqueue_allprecincts( tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue); enqueue_allprecincts( tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue);
@ -318,16 +325,17 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
enqueue_tile( tile_id, imgreg.level, msgqueue); enqueue_tile( tile_id, imgreg.level, msgqueue);
} }
else{ else{
// Tile partially overlaps view-window /* Tile partially overlaps view-window */
// low priority /* low priority */
//printf("Tile partially overlaps view-window %d\n", tile_id); /*printf("Tile partially overlaps view-window %d\n", tile_id);*/
if( msgqueue->cachemodel->jppstream){ if( msgqueue->cachemodel->jppstream){
enqueue_tileheader( tile_id, msgqueue); enqueue_tileheader( tile_id, msgqueue);
xmin = tile_Xrange.minvalue >= imgreg.xosiz + imgreg.ox ? 0 : imgreg.xosiz + imgreg.ox - tile_Xrange.minvalue; /* FIXME: The following code is suspicious it implicitely cast an unsigned int to int, which truncates values */
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; xmin = tile_Xrange.minvalue >= (Byte4_t)(imgreg.xosiz + imgreg.ox) ? 0 : imgreg.xosiz + imgreg.ox - tile_Xrange.minvalue;
ymin = tile_Yrange.minvalue >= imgreg.yosiz + imgreg.oy ? 0 : imgreg.yosiz + imgreg.oy - tile_Yrange.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;
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; 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); enqueue_precincts( xmin, xmax, ymin, ymax, tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue);
} }
else else
@ -339,6 +347,7 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
} }
/* 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) 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; index_param_t *codeidx;
@ -374,16 +383,16 @@ void enqueue_precincts( int xmin, int xmax, int ymin, int ymax, int tile_id, int
xmaxP = XTsiz-1; xmaxP = XTsiz-1;
if( xmaxP < xmin || xminP > xmax || ymaxP < ymin || yminP > ymax){ 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){ else if( xminP >= xmin && xmaxP <= xmax && yminP >= ymin && ymaxP <= ymax){
// Precinct completely contained within view-window /* Precinct completely contained within view-window
// high priority high priority */
enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue); enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue);
} }
else{ else{
// Precinct partially overlaps view-window /* Precinct partially overlaps view-window
// low priority low priority */
enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue); enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue);
} }
} }
@ -419,18 +428,26 @@ void enqueue_allprecincts( int tile_id, int level, int lastcomp, bool *comps, in
} }
} }
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; int i;
for( i=0; query_param.box_type[i][0]!=0 && i<MAX_NUMOFBOX; i++){ for( i=0; query_param.box_type[i][0]!=0 && i<MAX_NUMOFBOX; i++){
if( query_param.box_type[i][0] == '*'){ 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{ else{
int idx = search_metadataidx( query_param.box_type[i], metadatalist); int idx = search_metadataidx( query_param.box_type[i], metadatalist);
if( idx != -1) if( idx != -1)
enqueue_metadata( idx, msgqueue); 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;
} }

View File

@ -35,6 +35,8 @@
#include "jpipstream_manager.h" #include "jpipstream_manager.h"
#include "jp2k_encoder.h" #include "jp2k_encoder.h"
#include "jp2k_decoder.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) Byte_t * update_JPIPstream( Byte_t *newstream, int newstreamlen, Byte_t *cache_stream, int *streamlen)
{ {
@ -50,7 +52,7 @@ Byte_t * update_JPIPstream( Byte_t *newstream, int newstreamlen, Byte_t *cache_s
return stream; 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; time_t timer;
struct tm *t_st; struct tm *t_st;
@ -63,7 +65,8 @@ void save_codestream( Byte_t *codestream, Byte8_t streamlen, char *fmt)
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); 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"); 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); fclose( fp);
} }
@ -71,7 +74,7 @@ void save_codestream( Byte_t *codestream, Byte8_t streamlen, char *fmt)
Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn, int fw, int fh, ihdrbox_param_t **ihdrbox) 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 *pnmstream;
Byte_t *j2kstream; // j2k or jp2 codestream Byte_t *j2kstream; /* j2k or jp2 codestream */
Byte8_t j2klen; Byte8_t j2klen;
FILE *fp; FILE *fp;
char j2kfname[] = "tmp.j2k"; char j2kfname[] = "tmp.j2k";
@ -90,3 +93,28 @@ Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte
return pnmstream; 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;
}

View File

@ -34,6 +34,8 @@
Byte_t * update_JPIPstream( Byte_t *newstream, int newstreamlen, Byte_t *cache_stream, int *streamlen); 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); 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);

View File

@ -96,7 +96,7 @@ void print_manfbox( manfbox_param_t *manf)
} }
} }
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; boxheader_param_t *found;

View File

@ -36,10 +36,10 @@
#include "boxheader_manager.h" #include "boxheader_manager.h"
//! manifest box parameters /** manifest box parameters*/
//! I.3.2.3 Manifest box /** I.3.2.3 Manifest box*/
typedef struct manfbox_param{ 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; } manfbox_param_t;
@ -75,7 +75,7 @@ void print_manfbox( manfbox_param_t *manf);
* @param[in] manf manf box pointer * @param[in] manf manf box pointer
* @return found 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_ */ #endif /* !MANFBOX_MANAGER_H_ */

View File

@ -34,12 +34,12 @@
#include "codestream_manager.h" #include "codestream_manager.h"
//! Marker parameters /** Marker parameters*/
typedef struct marker_param{ typedef struct marker_param{
codestream_param_t cs; //!< corresponding codestream codestream_param_t cs; /**< corresponding codestream*/
Byte2_t code; //!< marker code 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) 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 Byte2_t length; /**< marker segment length*/
} marker_param_t; } marker_param_t;

View File

@ -28,13 +28,10 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "metadata_manager.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include "metadata_manager.h"
#ifdef SERVER #ifdef SERVER
#include "fcgi_stdio.h" #include "fcgi_stdio.h"
@ -43,10 +40,10 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
metadatalist_param_t * gene_metadatalist() metadatalist_param_t * gene_metadatalist(void)
{ {
metadatalist_param_t *list; metadatalist_param_t *list;
@ -67,14 +64,12 @@ metadatalist_param_t * const_metadatalist( int fd)
placeholderlist_param_t *phldlist; placeholderlist_param_t *phldlist;
placeholder_param_t *phld; placeholder_param_t *phld;
int idx; int idx;
struct stat sb; Byte8_t filesize;
if( fstat( fd, &sb) == -1){
fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
return NULL;
}
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"); fprintf( FCGI_stderr, "Error: Not correctl JP2 format\n");
return NULL; return NULL;
} }
@ -82,10 +77,6 @@ metadatalist_param_t * const_metadatalist( int fd)
phldlist = gene_placeholderlist(); phldlist = gene_placeholderlist();
metadatalist = gene_metadatalist(); 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; box = toplev_boxlist->first;
idx = 0; idx = 0;
while( box){ while( box){
@ -149,7 +140,7 @@ void delete_metadata( metadata_param_t **metadata)
if((*metadata)->boxcontents) if((*metadata)->boxcontents)
free((*metadata)->boxcontents); free((*metadata)->boxcontents);
#ifndef SERVER #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 #endif
free( *metadata); free( *metadata);
} }
@ -165,11 +156,12 @@ void insert_metadata_into_list( metadata_param_t *metabin, metadatalist_param_t
void print_metadata( metadata_param_t *metadata) void print_metadata( metadata_param_t *metadata)
{ {
boxcontents_param_t *boxcont;
fprintf( logstream, "metadata-bin %d info:\n", metadata->idx); fprintf( logstream, "metadata-bin %d info:\n", metadata->idx);
print_allbox( metadata->boxlist); print_allbox( metadata->boxlist);
print_allplaceholder( metadata->placeholderlist); print_allplaceholder( metadata->placeholderlist);
boxcontents_param_t *boxcont = metadata->boxcontents; boxcont = metadata->boxcontents;
if( boxcont) if( boxcont)
fprintf( logstream, "box contents:\n" fprintf( logstream, "box contents:\n"
"\t offset: %lld %#llx\n" "\t offset: %lld %#llx\n"

View File

@ -29,29 +29,29 @@
*/ */
#ifndef METADATA_MANAGER_H_ #ifndef METADATA_MANAGER_H_
# define METADATA_MANAGER_H_ #define METADATA_MANAGER_H_
#include "box_manager.h" #include "box_manager.h"
#include "placeholder_manager.h" #include "placeholder_manager.h"
typedef struct boxcontents_param{ typedef struct boxcontents_param{
Byte8_t offset; //!< byte position of the box contents in the file Byte8_t offset; /**< byte position of the box contents in the file*/
Byte8_t length; //!< length of the box contents Byte8_t length; /**< length of the box contents*/
} boxcontents_param_t; } boxcontents_param_t;
//! metadata-bin parameters /** metadata-bin parameters*/
typedef struct metadata_param{ typedef struct metadata_param{
int idx; //!< index number int idx; /**< index number*/
boxlist_param_t *boxlist; //!< box list boxlist_param_t *boxlist; /**< box list*/
placeholderlist_param_t *placeholderlist; //!< placeholder box list placeholderlist_param_t *placeholderlist; /**< placeholder box list*/
boxcontents_param_t *boxcontents; //!< box contens in case of no boxlist and placeholderlist boxcontents_param_t *boxcontents; /**< box contens in case of no boxlist and placeholderlist*/
struct metadata_param *next; //!< pointer to the next metadata-bin struct metadata_param *next; /**< pointer to the next metadata-bin*/
} metadata_param_t; } metadata_param_t;
//! metadata-bin list parameters /** metadata-bin list parameters*/
typedef struct metadatalist_param{ typedef struct metadatalist_param{
metadata_param_t *first; //!< first 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 metadata_param_t *last; /**< last metadata-bin pointer of the list*/
} metadatalist_param_t; } metadatalist_param_t;
@ -60,7 +60,7 @@ typedef struct metadatalist_param{
* *
* @return pointer to the generated metadata list * @return pointer to the generated metadata list
*/ */
metadatalist_param_t * gene_metadatalist(); metadatalist_param_t * gene_metadatalist(void);
/** /**

View File

@ -34,25 +34,25 @@
#include "byte_manager.h" #include "byte_manager.h"
#include "box_manager.h" #include "box_manager.h"
//! Marker index parameters /** Marker index parameters*/
typedef struct markeridx_param{ typedef struct markeridx_param{
Byte2_t code; //!< marker code Byte2_t code; /**< marker code*/
Byte2_t num_remain; //!< remining number of the same marker index segments listed immediately Byte2_t num_remain; /**< remining number of the same marker index segments listed immediately*/
Byte8_t offset; //!< offset relative to the start of the Byte8_t offset; /**< offset relative to the start of the*/
//!codestream ( including the length /**codestream ( including the length*/
//!parameter but not the marker itself) /**parameter but not the marker itself)*/
Byte2_t length; //!< marker segment length Byte2_t length; /**< marker segment length*/
struct markeridx_param *next; //!< pointer to the next markeridx struct markeridx_param *next; /**< pointer to the next markeridx*/
} markeridx_param_t; } markeridx_param_t;
//! header index table box parameters /** header index table box parameters*/
//! I.3.2.4.3 Header Index Table box /** I.3.2.4.3 Header Index Table box*/
typedef struct mhixbox_param{ typedef struct mhixbox_param{
Byte8_t tlen; //!< length ( total length of the main Byte8_t tlen; /**< length ( total length of the main*/
//!header or of the first tile-part header) /**header or of the first tile-part header)*/
markeridx_param_t *first; //!< first marker index pointer of the list markeridx_param_t *first; /**< first marker index pointer of the list*/
} mhixbox_param_t; } mhixbox_param_t;

View File

@ -32,10 +32,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
#include "msgqueue_manager.h" #include "msgqueue_manager.h"
#include "metadata_manager.h" #include "metadata_manager.h"
#include "index_manager.h" #include "index_manager.h"
@ -47,7 +51,7 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
msgqueue_param_t * gene_msgqueue( bool stateless, cachemodel_param_t *cachemodel) msgqueue_param_t * gene_msgqueue( bool stateless, cachemodel_param_t *cachemodel)
{ {
@ -135,7 +139,7 @@ void enqueue_mainheader( msgqueue_param_t *msgqueue)
msg->csn = target->csn; msg->csn = target->csn;
msg->bin_offset = 0; msg->bin_offset = 0;
msg->length = codeidx->mhead_length; msg->length = codeidx->mhead_length;
msg->aux = 0; // non exist msg->aux = 0; /* non exist*/
msg->res_offset = codeidx->offset; msg->res_offset = codeidx->offset;
msg->phld = NULL; msg->phld = NULL;
msg->next = NULL; msg->next = NULL;
@ -163,9 +167,9 @@ void enqueue_tileheader( int tile_id, msgqueue_param_t *msgqueue)
msg->class_id = TILE_HEADER_MSG; msg->class_id = TILE_HEADER_MSG;
msg->csn = target->csn; msg->csn = target->csn;
msg->bin_offset = 0; msg->bin_offset = 0;
msg->length = codeidx->tileheader[tile_id]->tlen-2; // SOT marker segment is removed msg->length = codeidx->tileheader[tile_id]->tlen-2; /* SOT marker segment is removed*/
msg->aux = 0; // non exist msg->aux = 0; /* non exist*/
msg->res_offset = codeidx->offset + get_elemOff( codeidx->tilepart, 0, tile_id) + 2; // skip SOT marker seg msg->res_offset = codeidx->offset + get_elemOff( codeidx->tilepart, 0, tile_id) + 2; /* skip SOT marker seg*/
msg->phld = NULL; msg->phld = NULL;
msg->next = NULL; msg->next = NULL;
@ -179,7 +183,7 @@ void enqueue_tile( int tile_id, int level, msgqueue_param_t *msgqueue)
cachemodel_param_t *cachemodel; cachemodel_param_t *cachemodel;
target_param_t *target; target_param_t *target;
bool *tp_model; bool *tp_model;
Byte8_t numOftparts; // num of tile parts par tile Byte8_t numOftparts; /* num of tile parts par tile*/
Byte8_t numOftiles; Byte8_t numOftiles;
index_param_t *codeidx; index_param_t *codeidx;
faixbox_param_t *tilepart; faixbox_param_t *tilepart;
@ -197,7 +201,7 @@ void enqueue_tile( int tile_id, int level, msgqueue_param_t *msgqueue)
class_id = (numOftparts==1) ? TILE_MSG : EXT_TILE_MSG; 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); fprintf( FCGI_stderr, "Error, Invalid tile-id %d\n", tile_id);
return; return;
} }
@ -205,13 +209,13 @@ void enqueue_tile( int tile_id, int level, msgqueue_param_t *msgqueue)
tp_model = &cachemodel->tp_model[ tile_id*numOftparts]; tp_model = &cachemodel->tp_model[ tile_id*numOftparts];
binOffset=0; binOffset=0;
for( i=0; i<numOftparts-level; i++){ for( i=0; i<(int)numOftparts-level; i++){
binLength = get_elemLen( tilepart, i, tile_id); binLength = get_elemLen( tilepart, i, tile_id);
if( !tp_model[i]){ if( !tp_model[i]){
msg = (message_param_t *)malloc( sizeof(message_param_t)); 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->in_class_id = tile_id;
msg->class_id = class_id; msg->class_id = class_id;
msg->csn = target->csn; msg->csn = target->csn;
@ -365,7 +369,7 @@ message_param_t * gene_metamsg( int meta_id, Byte8_t binOffset, Byte8_t length,
msg->csn = csn; msg->csn = csn;
msg->bin_offset = binOffset; msg->bin_offset = binOffset;
msg->length = length; msg->length = length;
msg->aux = 0; // non exist msg->aux = 0; /* non exist*/
msg->res_offset = res_offset; msg->res_offset = res_offset;
msg->phld = phld; msg->phld = phld;
msg->next = NULL; msg->next = NULL;
@ -427,7 +431,7 @@ void recons_stream_from_msgqueue( msgqueue_param_t *msgqueue, int tmpfd)
add_vbas_stream( msg->bin_offset, tmpfd); add_vbas_stream( msg->bin_offset, tmpfd);
add_vbas_stream (msg->length, 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); add_vbas_stream( msg->aux, tmpfd);
if( msg->phld) if( msg->phld)
@ -447,8 +451,8 @@ void add_bin_id_vbas_stream( Byte_t bb, Byte_t c, Byte8_t in_class_id, int tmpfd
int bytelength; int bytelength;
Byte8_t tmp; Byte8_t tmp;
// A.2.3 In-class identifiers /* A.2.3 In-class identifiers */
// 7k-3bits, where k is the number of bytes in the VBAS /* 7k-3bits, where k is the number of bytes in the VBAS*/
bytelength = 1; bytelength = 1;
tmp = in_class_id >> 4; tmp = in_class_id >> 4;
while( tmp){ while( tmp){
@ -484,7 +488,10 @@ void add_vbas_with_bytelen_stream( Byte8_t code, int bytelength, int tmpfd)
seg = ( code >> (n*7)) & 0x7f; seg = ( code >> (n*7)) & 0x7f;
if( n) if( n)
seg |= 0x80; 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--; n--;
} }
} }
@ -497,13 +504,6 @@ void add_body_stream( message_param_t *msg, int fd, int tmpfd)
fprintf( FCGI_stderr, "Error: fetch_bytes in add_body_stream()\n"); fprintf( FCGI_stderr, "Error: fetch_bytes in add_body_stream()\n");
return; 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){ if( write( tmpfd, data, msg->length) < 1){
free( data); free( data);
@ -539,7 +539,10 @@ void add_bigendian_bytestream( Byte8_t code, int bytelength, int tmpfd)
n = bytelength - 1; n = bytelength - 1;
while( n >= 0) { while( n >= 0) {
seg = ( code >> (n*8)) & 0xff; 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--; n--;
} }
} }
@ -569,15 +572,15 @@ Byte_t * parse_vbas( Byte_t *streamptr, Byte8_t *elem);
void parse_JPIPstream( Byte_t *JPIPstream, Byte8_t streamlen, Byte8_t offset, msgqueue_param_t *msgqueue) 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; message_param_t *msg;
Byte_t bb, c; Byte_t bb, c;
Byte8_t class_id, csn; Byte8_t class_id, csn;
class_id = -1; // dummy class_id = -1; /* dummy*/
csn = -1; csn = -1;
ptr = JPIPstream; ptr = JPIPstream;
while( ptr-JPIPstream < streamlen){ while( (Byte8_t)(ptr-JPIPstream) < streamlen){
msg = (message_param_t *)malloc( sizeof(message_param_t)); msg = (message_param_t *)malloc( sizeof(message_param_t));
ptr = parse_bin_id_vbas( ptr, &bb, &c, &msg->in_class_id); ptr = parse_bin_id_vbas( ptr, &bb, &c, &msg->in_class_id);
@ -596,7 +599,7 @@ void parse_JPIPstream( Byte_t *JPIPstream, Byte8_t streamlen, Byte8_t offset, ms
ptr = parse_vbas( ptr, &msg->bin_offset); ptr = parse_vbas( ptr, &msg->bin_offset);
ptr = parse_vbas( ptr, &msg->length); 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); ptr = parse_vbas( ptr, &msg->aux);
else else
msg->aux = 0; msg->aux = 0;
@ -620,6 +623,7 @@ void parse_metadata( metadata_param_t *metadata, message_param_t *msg, Byte_t *s
void parse_metamsg( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t streamlen, metadatalist_param_t *metadatalist) void parse_metamsg( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t streamlen, metadatalist_param_t *metadatalist)
{ {
message_param_t *msg; message_param_t *msg;
(void)streamlen;
if( metadatalist == NULL) if( metadatalist == NULL)
return; return;
@ -639,6 +643,8 @@ placeholder_param_t * parse_phld( Byte_t *datastream, Byte8_t metalength);
void parse_metadata( metadata_param_t *metadata, message_param_t *msg, Byte_t *datastream) 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); char *boxtype = (char *)(datastream+4);
msg->phld = NULL; msg->phld = NULL;
@ -647,17 +653,17 @@ void parse_metadata( metadata_param_t *metadata, message_param_t *msg, Byte_t *d
if( !metadata->placeholderlist) if( !metadata->placeholderlist)
metadata->placeholderlist = gene_placeholderlist(); metadata->placeholderlist = gene_placeholderlist();
placeholder_param_t *phld = parse_phld( datastream, msg->length); phld = parse_phld( datastream, msg->length);
msg->phld = phld; msg->phld = phld;
insert_placeholder_into_list( phld, metadata->placeholderlist); insert_placeholder_into_list( phld, metadata->placeholderlist);
} }
else if( isalpha(boxtype[0]) && isalpha(boxtype[1]) && else if( isalpha(boxtype[0]) && isalpha(boxtype[1]) &&
(isalnum(boxtype[2])||isblank(boxtype[2])) && (isalnum(boxtype[2])||isspace(boxtype[2])) &&
(isalpha(boxtype[3])||isblank(boxtype[3]))){ (isalpha(boxtype[3])||isspace(boxtype[3]))){
if( !metadata->boxlist) if( !metadata->boxlist)
metadata->boxlist = gene_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); insert_box_into_list( box, metadata->boxlist);
} }
else else

View File

@ -45,26 +45,26 @@
#define MAINHEADER_MSG 6 #define MAINHEADER_MSG 6
#define METADATA_MSG 8 #define METADATA_MSG 8
//! message parameters /** message parameters */
typedef struct message_param{ typedef struct message_param{
bool last_byte; //!< if message contains the last byte of the data-bin 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 in_class_id; /**< in-class identifier A.2.3*/
Byte8_t class_id; //!< class identifiers Byte8_t class_id; /**< class identifiers */
Byte8_t csn; //!< index of the codestream 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 bin_offset; /**< offset of the data in this message from the start of the data-bin*/
Byte8_t length; //!< message byte length Byte8_t length; /**< message byte length*/
Byte8_t aux; //!< Byte8_t aux; /**<*/
Byte8_t res_offset; //!< offset in the resource Byte8_t res_offset; /**< offset in the resource*/
placeholder_param_t *phld; //!< placeholder pointer in index placeholder_param_t *phld; /**< placeholder pointer in index*/
struct message_param *next; //!< pointer to the next message struct message_param *next; /**< pointer to the next message*/
} message_param_t; } message_param_t;
//! message queue parameters /** message queue parameters */
typedef struct msgqueue_param{ typedef struct msgqueue_param{
message_param_t *first; //!< first message pointer of the list message_param_t *first; /**< first message pointer of the list*/
message_param_t *last; //!< last message pointer of the list message_param_t *last; /**< last message pointer of the list*/
bool stateless; //!< if this is a stateless message queue bool stateless; /**< if this is a stateless message queue*/
cachemodel_param_t *cachemodel; //!< reference cachemodel pointer cachemodel_param_t *cachemodel; /**< reference cachemodel pointer*/
} msgqueue_param_t; } msgqueue_param_t;
/** /**

View File

@ -33,7 +33,15 @@
#include "jpip_parser.h" #include "jpip_parser.h"
#include "channel_manager.h" #include "channel_manager.h"
#include "byte_manager.h" #include "byte_manager.h"
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
#ifdef SERVER
#include "auxtrans_manager.h" #include "auxtrans_manager.h"
#endif
#include <stdio.h> #include <stdio.h>
#include "dec_clientmsg_handler.h" #include "dec_clientmsg_handler.h"
@ -43,9 +51,10 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h>
#include "jp2k_encoder.h" #include "jp2k_encoder.h"
#ifdef SERVER
server_record_t * init_JPIPserver( int tcp_auxport, int udp_auxport) server_record_t * init_JPIPserver( int tcp_auxport, int udp_auxport)
{ {
server_record_t *record = (server_record_t *)malloc( sizeof(server_record_t)); server_record_t *record = (server_record_t *)malloc( sizeof(server_record_t));
@ -106,7 +115,7 @@ bool process_JPIPrequest( server_record_t *rec, QR_t *qr)
if( !close_channel( *(qr->query), rec->sessionlist, &cursession, &curchannel)) if( !close_channel( *(qr->query), rec->sessionlist, &cursession, &curchannel))
return false; 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)) if( !gene_JPIPstream( *(qr->query), target, cursession, curchannel, &qr->msgqueue))
return false; return false;
@ -131,24 +140,30 @@ void send_responsedata( server_record_t *rec, QR_t *qr)
recons_stream_from_msgqueue( qr->msgqueue, fd); 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); len_of_jpipstream = get_filesize( fd);
jpipstream = fetch_bytes( fd, 0, len_of_jpipstream); jpipstream = fetch_bytes( fd, 0, len_of_jpipstream);
close( fd); close( fd);
remove( tmpfname); remove( tmpfname);
fprintf( FCGI_stdout, "\r\n"); fprintf( FCGI_stdout, "\r\n");
if( qr->channel) if( len_of_jpipstream){
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 if( qr->channel)
return; 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( fwrite( jpipstream, len_of_jpipstream, 1, FCGI_stdout) != 1)
fprintf( FCGI_stderr, "Error: failed to write jpipstream\n");
}
free( jpipstream); free( jpipstream);
return; return;
} }
@ -160,19 +175,21 @@ void add_EORmsg( int fd, QR_t *qr)
EOR[0] = 0x00; EOR[0] = 0x00;
EOR[1] = is_allsent( *(qr->channel->cachemodel)) ? 0x01 : 0x02; EOR[1] = is_allsent( *(qr->channel->cachemodel)) ? 0x01 : 0x02;
EOR[2] = 0x00; 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) 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_query( &((*qr)->query));
delete_msgqueue( &((*qr)->msgqueue)); delete_msgqueue( &((*qr)->msgqueue));
free( *qr); free( *qr);
} }
void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr, server_record_t *rec) void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr, server_record_t *rec)
{ {
if( query) if( query)
@ -188,6 +205,8 @@ void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr
print_alltarget( rec->targetlist); print_alltarget( rec->targetlist);
} }
#endif /*SERVER*/
#ifndef SERVER #ifndef SERVER
dec_server_record_t * init_dec_server( int port) dec_server_record_t * init_dec_server( int port)
@ -257,6 +276,10 @@ bool handle_clientreq( client_t client, dec_server_record_t *rec)
case CIDDST: case CIDDST:
handle_dstCIDreqMSG( client, rec->cachelist); handle_dstCIDreqMSG( client, rec->cachelist);
break; break;
case SIZREQ:
handle_SIZreqMSG( client, rec->jpipstream, rec->msgqueue, rec->cachelist);
break;
case JP2SAVE: case JP2SAVE:
handle_JP2saveMSG( client, rec->cachelist, rec->msgqueue, rec->jpipstream); handle_JP2saveMSG( client, rec->cachelist, rec->msgqueue, rec->jpipstream);
@ -301,22 +324,18 @@ jpip_dec_param_t * init_jpipdecoder( bool jp2)
bool fread_jpip( char fname[], jpip_dec_param_t *dec) bool fread_jpip( char fname[], jpip_dec_param_t *dec)
{ {
int infd; int infd;
struct stat sb;
if(( infd = open( fname, O_RDONLY)) == -1){ if(( infd = open( fname, O_RDONLY)) == -1){
fprintf( stderr, "file %s not exist\n", fname); fprintf( stderr, "file %s not exist\n", fname);
return false; return false;
} }
if( fstat( infd, &sb) == -1){ if(!(dec->jpiplen = get_filesize(infd)))
fprintf( stderr, "input file stream is broken\n");
return false; return false;
}
dec->jpiplen = (Byte8_t)sb.st_size;
dec->jpipstream = (Byte_t *)malloc( dec->jpiplen); 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"); fprintf( stderr, "file reading error\n");
free( dec->jpipstream); free( dec->jpipstream);
return false; return false;
@ -331,14 +350,14 @@ void decode_jpip( jpip_dec_param_t *dec)
{ {
parse_JPIPstream( dec->jpipstream, dec->jpiplen, 0, dec->msgqueue); 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); parse_metamsg( dec->msgqueue, dec->jpipstream, dec->jpiplen, dec->metadatalist);
dec->ihdrbox = gene_ihdrbox( dec->metadatalist, dec->jpipstream); dec->ihdrbox = gene_ihdrbox( dec->metadatalist, dec->jpipstream);
dec->jp2kstream = recons_jp2( dec->msgqueue, dec->jpipstream, dec->msgqueue->first->csn, &dec->jp2klen); dec->jp2kstream = recons_jp2( dec->msgqueue, dec->jpipstream, dec->msgqueue->first->csn, &dec->jp2klen);
} }
else // J2k encoding else /* J2k encoding */
// Notice: arguments fw, fh need to be set for LRCP, PCRL, CPRL /* 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); dec->jp2kstream = recons_j2k( dec->msgqueue, dec->jpipstream, dec->msgqueue->first->csn, 0, 0, &dec->jp2klen);
} }
@ -355,7 +374,7 @@ bool fwrite_jp2k( char fname[], jpip_dec_param_t *dec)
return false; 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"); fprintf( stderr, "j2k file write error\n");
close(outfd); close(outfd);
@ -394,13 +413,13 @@ index_t * get_index_from_JP2file( int fd)
{ {
char *data; char *data;
// Check resource is a JP family file. /* Check resource is a JP family file.*/
if( lseek( fd, 0, SEEK_SET)==-1){ if( lseek( fd, 0, SEEK_SET)==-1){
fprintf( stderr, "Error: File broken (lseek error)\n"); fprintf( stderr, "Error: File broken (lseek error)\n");
return NULL; return NULL;
} }
data = (char *)malloc( 12); // size of header data = (char *)malloc( 12); /* size of header*/
if( read( fd, data, 12) != 12){ if( read( fd, data, 12) != 12){
free( data); free( data);
fprintf( stderr, "Error: File broken (read error)\n"); fprintf( stderr, "Error: File broken (read error)\n");
@ -428,4 +447,4 @@ void output_index( index_t *index)
print_index( *index); print_index( *index);
} }
#endif //SERVER #endif /*SERVER*/

View File

@ -58,26 +58,28 @@
#include "ihdrbox_manager.h" #include "ihdrbox_manager.h"
#include "index_manager.h" #include "index_manager.h"
#endif //SERVER #endif /*SERVER*/
/* /*
*========================================================== *==========================================================
* JPIP server API * JPIP server API
*========================================================== *==========================================================
*/ */
#ifdef SERVER
//! Server static records /** Server static records*/
typedef struct server_record{ typedef struct server_record{
sessionlist_param_t *sessionlist; //!< list of session records sessionlist_param_t *sessionlist; /**< list of session records*/
targetlist_param_t *targetlist; //!< list of target records targetlist_param_t *targetlist; /**< list of target records*/
auxtrans_param_t auxtrans; auxtrans_param_t auxtrans;
} server_record_t; } server_record_t;
//! Query/response data for each client /** Query/response data for each client*/
typedef struct QR{ typedef struct QR{
query_param_t *query; //!< query parameters query_param_t *query; /**< query parameters*/
msgqueue_param_t *msgqueue; //!< message queue msgqueue_param_t *msgqueue; /**< message queue*/
channel_param_t *channel; //!< channel, (NULL if stateless) channel_param_t *channel; /**< channel, (NULL if stateless)*/
} QR_t; } QR_t;
/** /**
@ -129,8 +131,6 @@ void send_responsedata( server_record_t *rec, QR_t *qr);
*/ */
void end_QRprocess( server_record_t *rec, QR_t **qr); void end_QRprocess( server_record_t *rec, QR_t **qr);
#ifndef SERVER
/** /**
* Option for local tests; print out parameter values to logstream (stderr) * Option for local tests; print out parameter values to logstream (stderr)
* *
@ -143,7 +143,7 @@ void end_QRprocess( server_record_t *rec, QR_t **qr);
*/ */
void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr, server_record_t *rec); void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr, server_record_t *rec);
#endif //SERVER #endif /*SERVER*/
/* /*
*========================================================== *==========================================================
@ -153,17 +153,17 @@ void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr
#ifndef SERVER #ifndef SERVER
//! Decoding server static records /** Decoding server static records*/
typedef struct dec_server_record{ typedef struct dec_server_record{
cachelist_param_t *cachelist; //!< cache list cachelist_param_t *cachelist; /**< cache list*/
Byte_t *jpipstream; //!< JPT/JPP stream Byte_t *jpipstream; /**< JPT/JPP stream*/
int jpipstreamlen; //!< length of jpipstream int jpipstreamlen; /**< length of jpipstream*/
msgqueue_param_t *msgqueue; //!< parsed message queue of jpipstream msgqueue_param_t *msgqueue; /**< parsed message queue of jpipstream*/
SOCKET listening_socket; //!< listenning socket SOCKET listening_socket; /**< listenning socket*/
} dec_server_record_t; } dec_server_record_t;
//! Client socket identifier /** Client socket identifier*/
typedef SOCKET client_t; typedef SOCKET client_t;
/** /**
@ -198,7 +198,7 @@ client_t accept_connection( dec_server_record_t *rec);
*/ */
bool handle_clientreq( client_t client, dec_server_record_t *rec); bool handle_clientreq( client_t client, dec_server_record_t *rec);
#endif //SERVER #endif /*SERVER*/
/* /*
*========================================================== *==========================================================
@ -212,15 +212,15 @@ bool handle_clientreq( client_t client, dec_server_record_t *rec);
* jpip to JP2 or J2K * jpip to JP2 or J2K
*/ */
//! JPIP decoding parameters /** JPIP decoding parameters*/
typedef struct jpip_dec_param{ typedef struct jpip_dec_param{
Byte_t *jpipstream; //!< JPT/JPP-stream Byte_t *jpipstream; /**< JPT/JPP-stream*/
Byte8_t jpiplen; //!< length of jpipstream Byte8_t jpiplen; /**< length of jpipstream*/
msgqueue_param_t *msgqueue; //!< message queue msgqueue_param_t *msgqueue; /**< message queue*/
metadatalist_param_t *metadatalist; //!< metadata list going into JP2 file metadatalist_param_t *metadatalist; /**< metadata list going into JP2 file*/
ihdrbox_param_t *ihdrbox; //!< ihdr box going into JP2 file ihdrbox_param_t *ihdrbox; /**< ihdr box going into JP2 file*/
Byte_t *jp2kstream; //!< J2K codestream or JP2 file codestream Byte_t *jp2kstream; /**< J2K codestream or JP2 file codestream*/
Byte8_t jp2klen; //!< length of j2kstream or JP2 file Byte8_t jp2klen; /**< length of j2kstream or JP2 file*/
} jpip_dec_param_t; } jpip_dec_param_t;
/** /**
@ -277,7 +277,7 @@ void output_log( bool messages, bool metadata, bool ihdrbox, jpip_dec_param_t *d
* test the format of index (cidx) box in JP2 file * test the format of index (cidx) box in JP2 file
*/ */
//! Redefinition of index parameters /** Redefinition of index parameters*/
typedef index_param_t index_t; typedef index_param_t index_t;
/** /**
@ -303,6 +303,6 @@ void destroy_index( index_t **idx);
*/ */
void output_index( index_t *index); void output_index( index_t *index);
#endif //SERVER #endif /*SERVER*/
#endif /* !OPENJPIP_H_ */ #endif /* !OPENJPIP_H_ */

View File

@ -41,11 +41,11 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
placeholderlist_param_t * gene_placeholderlist() placeholderlist_param_t * gene_placeholderlist(void)
{ {
placeholderlist_param_t *list; placeholderlist_param_t *list;
@ -81,7 +81,7 @@ placeholder_param_t * gene_placeholder( box_param_t *box, int origID)
placeholder = (placeholder_param_t *)malloc( sizeof(placeholder_param_t)); placeholder = (placeholder_param_t *)malloc( sizeof(placeholder_param_t));
strncpy( placeholder->TBox, "phld", 4); 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->OrigID = origID;
placeholder->OrigBH = fetch_headbytes( box); placeholder->OrigBH = fetch_headbytes( box);
placeholder->OrigBHlen = box->headlen; placeholder->OrigBHlen = box->headlen;

View File

@ -34,30 +34,30 @@
#include "byte_manager.h" #include "byte_manager.h"
#include "box_manager.h" #include "box_manager.h"
//! A.3.6.3 Placeholder box format /** A.3.6.3 Placeholder box format*/
//! placeholder box parameters /** placeholder box parameters*/
typedef struct placeholder_param{ typedef struct placeholder_param{
Byte4_t LBox; Byte4_t LBox;
char TBox[4]; char TBox[4];
Byte4_t Flags; Byte4_t Flags;
Byte8_t OrigID; Byte8_t OrigID;
Byte_t *OrigBH; //!< dynamic memory pointer Byte_t *OrigBH; /**< dynamic memory pointer*/
Byte_t OrigBHlen; //!< length of OrigBH Byte_t OrigBHlen; /**< length of OrigBH*/
#ifdef AAA #ifdef AAA
Byte8_t EquivID; Byte8_t EquivID;
Byte_t *EquivBH; //!< dynamic memory pointer Byte_t *EquivBH; /**< dynamic memory pointer*/
Byte_t EquivBHlen; //!< length of EquivBH Byte_t EquivBHlen; /**< length of EquivBH*/
Byte8_t CSID; Byte8_t CSID;
Byte4_t NCS; Byte4_t NCS;
#endif //AAA #endif /*AAA*/
struct placeholder_param *next; //!< pointer to the next placeholder struct placeholder_param *next; /**< pointer to the next placeholder*/
} placeholder_param_t; } placeholder_param_t;
//! placeholder box list parameters /** placeholder box list parameters*/
typedef struct placeholderlist_param{ typedef struct placeholderlist_param{
placeholder_param_t *first; //!< first 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 placeholder_param_t *last; /**< last placeholder pointer of the list*/
} placeholderlist_param_t; } placeholderlist_param_t;
@ -66,7 +66,7 @@ typedef struct placeholderlist_param{
* *
* @return pointer to the generated placeholder list * @return pointer to the generated placeholder list
*/ */
placeholderlist_param_t * gene_placeholderlist(); placeholderlist_param_t * gene_placeholderlist(void);
/** /**

View File

@ -33,6 +33,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#define strcasecmp _stricmp #define strcasecmp _stricmp
#define strncasecmp _strnicmp
#else #else
#include <strings.h> #include <strings.h>
#endif #endif
@ -49,7 +50,7 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
/** /**
@ -72,14 +73,14 @@ char * get_fieldparam( char *stringptr, char *fieldname, char *fieldval);
void parse_cclose( char *src, query_param_t *query_param); void parse_cclose( char *src, query_param_t *query_param);
void parse_metareq( char *field, 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); void parse_comps( char *field, query_param_t *query_param);
//! maximum length of field name /** maximum length of field name*/
#define MAX_LENOFFIELDNAME 10 #define MAX_LENOFFIELDNAME 10
//! maximum length of field value /** maximum length of field value*/
#define MAX_LENOFFIELDVAL 128 #define MAX_LENOFFIELDVAL 128
query_param_t * parse_query( char *query_string) query_param_t * parse_query( char *query_string)
@ -140,8 +141,11 @@ query_param_t * parse_query( char *query_string)
query_param->return_type = JPTstream; query_param->return_type = JPTstream;
} }
else if( strcasecmp( fieldname, "len") == 0) else if( strcasecmp( fieldname, "len") == 0){
sscanf( fieldval, "%d", &query_param->len); 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; return query_param;
@ -268,7 +272,7 @@ void print_queryparam( query_param_t query_param)
void parse_cclose( char *src, query_param_t *query_param) void parse_cclose( char *src, query_param_t *query_param)
{ {
int i; size_t i;
size_t len; size_t len;
len = strlen( src); len = strlen( src);
@ -293,7 +297,7 @@ void parse_metareq( char *field, query_param_t *query_param)
memset( req_box_prop, 0, 20); memset( req_box_prop, 0, 20);
// req-box-prop /* req-box-prop*/
ptr = strchr( field, '['); ptr = strchr( field, '[');
ptr++; ptr++;
src = ptr; src = ptr;
@ -329,7 +333,7 @@ void parse_req_box_prop( char *req_box_prop, int idx, query_param_t *query_param
query_param->box_type[idx][0]='*'; query_param->box_type[idx][0]='*';
else else
strncpy( query_param->box_type[idx], req_box_prop, 4); strncpy( query_param->box_type[idx], req_box_prop, 4);
if(( ptr = strchr( req_box_prop, ':'))){ if(( ptr = strchr( req_box_prop, ':'))){
if( *(ptr+1)=='r') if( *(ptr+1)=='r')
query_param->limit[idx] = -1; query_param->limit[idx] = -1;

View File

@ -34,40 +34,40 @@
#include "bool.h" #include "bool.h"
//! maximum number of meta request box /** maximum number of meta request box */
#define MAX_NUMOFBOX 10 #define MAX_NUMOFBOX 10
//! cnew aux transport name /** cnew aux transport name */
typedef enum cnew_transport { non, http, tcp, udp} cnew_transport_t; 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; typedef enum image_return { JPPstream, JPTstream, UNKNOWN=-1} image_return_t;
//! Query parameters /** Query parameters */
typedef struct query_param{ typedef struct query_param{
char *target; //!< target name char *target; /**< target name */
char *tid; //!< target identifier char *tid; /**< target identifier */
int fx, fy; //!< frame size (fx,fy) int fx, fy; /**< frame size (fx,fy) */
int rx, ry, rw, rh; //!< roi region int rx, ry, rw, rh; /**< roi region */
int layers; //!< quality layers int layers; /**< quality layers */
int lastcomp; //!< last component number int lastcomp; /**< last component number */
bool *comps; //!< components (dynamic array) for jpp-stream, null means all components bool *comps; /**< components (dynamic array) for jpp-stream, null means all components */
char *cid; //!< channel identifier char *cid; /**< channel identifier */
cnew_transport_t cnew; //!< transport name if there is new channel request, else non cnew_transport_t cnew; /**< transport name if there is new channel request, else non */
char *cclose; //!< list of closing channel identifiers, separated by '\0' char *cclose; /**< list of closing channel identifiers, separated by '\0' */
int numOfcclose; //!< number of closing channels int numOfcclose; /**< number of closing channels */
char box_type[MAX_NUMOFBOX][4]; //!< interested box-types char box_type[MAX_NUMOFBOX][4]; /**< interested box-types */
int limit[MAX_NUMOFBOX]; //!< limit value, -1: skeleton request "r", 0: entire contents int limit[MAX_NUMOFBOX]; /**< limit value, -1: skeleton request "r", 0: entire contents */
bool w[MAX_NUMOFBOX]; //!< Metadata request qualifier flags bool w[MAX_NUMOFBOX]; /**< Metadata request qualifier flags */
bool s[MAX_NUMOFBOX]; bool s[MAX_NUMOFBOX];
bool g[MAX_NUMOFBOX]; bool g[MAX_NUMOFBOX];
bool a[MAX_NUMOFBOX]; bool a[MAX_NUMOFBOX];
bool priority[MAX_NUMOFBOX]; //!< priority flag bool priority[MAX_NUMOFBOX]; /**< priority flag */
int root_bin; //!< root-bin int root_bin; /**< root-bin */
int max_depth; //!< max-depth int max_depth; /**< max-depth */
bool metadata_only; //!< metadata-only request bool metadata_only; /**< metadata-only request */
image_return_t return_type; //!< image return type image_return_t return_type; /**< image return type */
int len; //!< maximum response length int len; /**< maximum response length */
} query_param_t; } query_param_t;

View File

@ -35,17 +35,17 @@
#include "channel_manager.h" #include "channel_manager.h"
#include "cachemodel_manager.h" #include "cachemodel_manager.h"
//! Session parameters /** Session parameters*/
typedef struct session_param{ typedef struct session_param{
channellist_param_t *channellist; //!< channel list pointer channellist_param_t *channellist; /**< channel list pointer*/
cachemodellist_param_t *cachemodellist; //!< cache list pointer cachemodellist_param_t *cachemodellist; /**< cache list pointer*/
struct session_param *next; //!< pointer to the next session struct session_param *next; /**< pointer to the next session*/
} session_param_t; } session_param_t;
//! Session list parameters /** Session list parameters*/
typedef struct sessionlist_param{ typedef struct sessionlist_param{
session_param_t *first; //!< first 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 session_param_t *last; /**< last session pointer of the list*/
} sessionlist_param_t; } sessionlist_param_t;

View File

@ -34,12 +34,12 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <unistd.h>
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include "sock_manager.h" #include "sock_manager.h"
#ifdef SERVER #ifdef SERVER
@ -49,7 +49,7 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
SOCKET open_listeningsocket( int port) SOCKET open_listeningsocket( int port)
{ {
@ -99,7 +99,7 @@ SOCKET accept_socket( SOCKET listening_socket)
void send_stream( SOCKET connected_socket, void *stream, int length) void send_stream( SOCKET connected_socket, void *stream, int length)
{ {
void *ptr = stream; char *ptr = (char*)stream;
int remlen = length; int remlen = length;
while( remlen > 0){ while( remlen > 0){
@ -115,7 +115,7 @@ void send_stream( SOCKET connected_socket, void *stream, int length)
void * receive_stream( SOCKET connected_socket, int length) void * receive_stream( SOCKET connected_socket, int length)
{ {
void *stream, *ptr; char *stream, *ptr;
int remlen, redlen; int remlen, redlen;
ptr = stream = malloc( length); ptr = stream = malloc( length);

View File

@ -35,10 +35,10 @@
#include "byte_manager.h" #include "byte_manager.h"
#ifdef _WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock.h>
#else #else
typedef int SOCKET; typedef int SOCKET;
#endif //_WIN32 #endif /*_WIN32*/
#define BUF_LEN 256 #define BUF_LEN 256

View File

@ -31,12 +31,16 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#ifdef _WIN32
#define snprintf _snprintf /* Visual Studio */
#include <io.h>
#else
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#endif
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <time.h> #include <time.h>
#include <curl/curl.h>
#include "target_manager.h" #include "target_manager.h"
#ifdef SERVER #ifdef SERVER
@ -47,9 +51,9 @@
#define FCGI_stdout stdout #define FCGI_stdout stdout
#define FCGI_stderr stderr #define FCGI_stderr stderr
#define logstream stderr #define logstream stderr
#endif //SERVER #endif /*SERVER*/
targetlist_param_t * gene_targetlist() targetlist_param_t * gene_targetlist(void)
{ {
targetlist_param_t *targetlist; targetlist_param_t *targetlist;
@ -111,9 +115,9 @@ target_param_t * gene_target( targetlist_param_t *targetlist, char *targetpath)
target->jptstream = isJPTfeasible( *jp2idx); target->jptstream = isJPTfeasible( *jp2idx);
target->next=NULL; 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; targetlist->last->next = target;
else // first entry else /* first entry*/
targetlist->first = target; targetlist->first = target;
targetlist->last = target; targetlist->last = target;
@ -250,7 +254,7 @@ int open_jp2file( char filepath[], char tmpfname[])
int fd; int fd;
char *data; char *data;
// download remote target file to local storage /* download remote target file to local storage*/
if( strncmp( filepath, "http://", 7) == 0){ if( strncmp( filepath, "http://", 7) == 0){
if( (fd = open_remotefile( filepath, tmpfname)) == -1) if( (fd = open_remotefile( filepath, tmpfname)) == -1)
return -1; return -1;
@ -262,14 +266,14 @@ int open_jp2file( char filepath[], char tmpfname[])
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){ if( lseek( fd, 0, SEEK_SET)==-1){
close(fd); close(fd);
fprintf( FCGI_stdout, "Reason: Target %s broken (lseek error)\r\n", filepath); fprintf( FCGI_stdout, "Reason: Target %s broken (lseek error)\r\n", filepath);
return -1; return -1;
} }
data = (char *)malloc( 12); // size of header data = (char *)malloc( 12); /* size of header*/
if( read( fd, data, 12) != 12){ if( read( fd, data, 12) != 12){
free( data); free( data);
@ -298,7 +302,8 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream);
int open_remotefile( char filepath[], char tmpfname[]) int open_remotefile( char filepath[], char tmpfname[])
{ {
#ifndef SERVER #ifndef SERVER
(void)filepath;
(void)tmpfname;
fprintf( FCGI_stderr, "Remote file can not be opened in local mode\n"); fprintf( FCGI_stderr, "Remote file can not be opened in local mode\n");
return -1; return -1;
@ -324,7 +329,7 @@ int open_remotefile( char filepath[], char tmpfname[])
curl_easy_cleanup(curl_handle); curl_easy_cleanup(curl_handle);
return fd; return fd;
#endif //SERVER #endif /*SERVER*/
} }
#ifdef SERVER #ifdef SERVER
@ -335,4 +340,4 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
return written; return written;
} }
#endif //SERVER #endif /*SERVER*/

View File

@ -34,30 +34,30 @@
#include "bool.h" #include "bool.h"
#include "index_manager.h" #include "index_manager.h"
//! maximum length of target identifier /** maximum length of target identifier*/
#define MAX_LENOFTID 30 #define MAX_LENOFTID 30
//! target parameters /** target parameters*/
typedef struct target_param{ typedef struct target_param{
char tid[MAX_LENOFTID]; //!< taregt identifier char tid[MAX_LENOFTID]; /**< target identifier*/
char *targetname; //!< local file path or URL ( URL is suported only with SERVER mode) char *targetname; /**< local file path or URL ( URL is suported only with SERVER mode)*/
int fd; //!< file descriptor int fd; /**< file descriptor*/
#ifdef SERVER #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 #endif
int csn; //!< codestream number int csn; /**< codestream number */
index_param_t *codeidx; //!< index information of codestream index_param_t *codeidx; /**< index information of codestream */
int num_of_use; //!< numbers of sessions refering to this target int num_of_use; /**< numbers of sessions refering to this target */
bool jppstream; //!< if this target can return JPP-stream bool jppstream; /**< if this target can return JPP-stream */
bool jptstream; //!< 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 struct target_param *next; /**< pointer to the next target */
} target_param_t; } target_param_t;
//! Target list parameters /** Target list parameters*/
typedef struct targetlist_param{ typedef struct targetlist_param{
target_param_t *first; //!< first 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 target_param_t *last; /**< last target pointer of the list*/
} targetlist_param_t; } targetlist_param_t;
@ -67,7 +67,7 @@ typedef struct targetlist_param{
* *
* @return pointer to the generated target list * @return pointer to the generated target list
*/ */
targetlist_param_t * gene_targetlist(); targetlist_param_t * gene_targetlist(void);
/** /**

View File

@ -33,11 +33,12 @@
* *
* \section impinst Implementing instructions * \section impinst Implementing instructions
* Launch opj_dec_server from a terminal in the same machine as JPIP client image viewers. \n * 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 * 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 * To quite the opj_dec_server, send a message "quit" through the telnet.\n
* % telnet localhost 5000\n * % telnet localhost 50000\n
* quit\n * quit\n
* Be sure all image viewers are closed.\n * Be sure all image viewers are closed.\n
* Cache file in JPT format is stored in the working directly before it quites. * Cache file in JPT format is stored in the working directly before it quites.
@ -45,6 +46,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "openjpip.h" #include "openjpip.h"
#ifdef _WIN32 #ifdef _WIN32
@ -55,16 +57,22 @@ int main(int argc, char *argv[]){
dec_server_record_t *server_record; dec_server_record_t *server_record;
client_t client; client_t client;
int port = 50000;
int erreur;
(void)erreur;
if( argc > 1)
port = atoi( argv[1]);
#ifdef _WIN32 #ifdef _WIN32
int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32); erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
if( erreur!=0) if( erreur!=0)
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError()); fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else else
printf( "Initialisation Winsock\n"); 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 ) while(( client = accept_connection( server_record)) != -1 )
if(!handle_clientreq( client, server_record)) if(!handle_clientreq( client, server_record))

View File

@ -56,11 +56,14 @@
#ifdef _WIN32 #ifdef _WIN32
WSADATA initialisation_win32; WSADATA initialisation_win32;
#endif //_WIN32 #endif /*_WIN32*/
int main(void) int main(void)
{ {
server_record_t *server_record; server_record_t *server_record;
#ifdef SERVER
char *query_string;
#endif
#ifdef _WIN32 #ifdef _WIN32
int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32); int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
@ -68,13 +71,11 @@ int main(void)
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError()); fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else else
fprintf( stderr, "Initialisation Winsock\n"); fprintf( stderr, "Initialisation Winsock\n");
#endif //_WIN32 #endif /*_WIN32*/
server_record = init_JPIPserver( 60000, 0); server_record = init_JPIPserver( 60000, 0);
#ifdef SERVER #ifdef SERVER
char *query_string;
while(FCGI_Accept() >= 0) while(FCGI_Accept() >= 0)
#else #else
@ -82,17 +83,16 @@ int main(void)
while( fgets( query_string, 128, stdin) && query_string[0]!='\n') while( fgets( query_string, 128, stdin) && query_string[0]!='\n')
#endif #endif
{ {
QR_t *qr;
bool parse_status;
#ifdef SERVER #ifdef SERVER
query_string = getenv("QUERY_STRING"); query_string = getenv("QUERY_STRING");
#endif //SERVER #endif /*SERVER*/
if( strcmp( query_string, QUIT_SIGNAL) == 0) if( strcmp( query_string, QUIT_SIGNAL) == 0)
break; break;
QR_t *qr;
bool parse_status;
qr = parse_querystring( query_string); qr = parse_querystring( query_string);
parse_status = process_JPIPrequest( server_record, qr); parse_status = process_JPIPrequest( server_record, qr);
@ -102,11 +102,11 @@ int main(void)
#endif #endif
if( parse_status) if( parse_status)
send_responsedata( qr); send_responsedata( server_record, qr);
else{ else{
fprintf( FCGI_stderr, "Error: JPIP request failed\n"); fprintf( FCGI_stderr, "Error: JPIP request failed\n");
fprintf( FCGI_stdout, "\r\n"); fprintf( FCGI_stdout, "\r\n");
} }
end_QRprocess( server_record, &qr); end_QRprocess( server_record, &qr);
} }

View File

@ -33,15 +33,34 @@ import java.awt.Image;
public class ImageManager extends JPIPHttpClient public class ImageManager extends JPIPHttpClient
{ {
private PnmImage pnmimage; 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); super( uri);
imgdecoder = new ImgdecClient( host, port);
pnmimage = null; pnmimage = null;
origwidth = 0;
origheight = 0;
} }
public int getOrigWidth(){ return pnmimage.get_width();} public int getOrigWidth(){
public int getOrigHeight(){ return pnmimage.get_height();} 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) public Image getImage( String j2kfilename, int reqfw, int reqfh, boolean reqcnew, int reqaux, boolean reqJPP, boolean reqJPT)
{ {
@ -52,10 +71,10 @@ public class ImageManager extends JPIPHttpClient
// Todo: check if the cid is for the same stream type // Todo: check if the cid is for the same stream type
if( reqcnew) if( reqcnew)
refcid = ImgdecClient.query_cid( j2kfilename); refcid = imgdecoder.query_cid( j2kfilename);
if( refcid == null){ if( refcid == null){
String reftid = ImgdecClient.query_tid( j2kfilename); String reftid = imgdecoder.query_tid( j2kfilename);
if( reftid == null) if( reftid == null)
jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, reqcnew, reqaux, reqJPP, reqJPT); jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, reqcnew, reqaux, reqJPP, reqJPT);
else else
@ -65,7 +84,7 @@ public class ImageManager extends JPIPHttpClient
jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, reqcnew, reqaux, reqJPP, reqJPT); jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, reqcnew, reqaux, reqJPP, reqJPT);
System.err.println( "decoding to PNM image"); 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"); System.err.println( " done");
return pnmimage.createROIImage( rx, ry, rw, rh); return pnmimage.createROIImage( rx, ry, rw, rh);
} }
@ -82,7 +101,7 @@ public class ImageManager extends JPIPHttpClient
byte[] jpipstream = super.requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh); byte[] jpipstream = super.requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh);
System.err.println( "decoding to PNM image"); 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"); System.err.println( " done");
return pnmimage.createROIImage( rx, ry, rw, rh); return pnmimage.createROIImage( rx, ry, rw, rh);
} }
@ -100,17 +119,18 @@ public class ImageManager extends JPIPHttpClient
byte[] jpipstream = super.requestXML(); byte[] jpipstream = super.requestXML();
if( jpipstream != null){ if( jpipstream != null){
ImgdecClient.send_JPIPstream( jpipstream); imgdecoder.send_JPIPstream( jpipstream);
xmldata = ImgdecClient.get_XMLstream( cid); xmldata = imgdecoder.get_XMLstream( cid);
} }
return xmldata; return xmldata;
} }
public void closeChannel() public void closeChannel()
{ {
if( cid != null){ if( cid != null){
ImgdecClient.destroy_cid( cid); imgdecoder.destroy_cid( cid);
super.closeChannel(); super.closeChannel();
} }
} }
} }

View File

@ -37,11 +37,11 @@ public class ImageWindow extends JFrame
private ImageViewer imgviewer; private ImageViewer imgviewer;
private ImageManager imgmanager; 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); super( j2kfilename);
imgmanager = new ImageManager( uri); imgmanager = new ImageManager( uri, host, port);
imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream, aux); imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream, aux);
imgviewer.setOpaque(true); //content panes must be opaque imgviewer.setOpaque(true); //content panes must be opaque
@ -66,25 +66,36 @@ public class ImageWindow extends JFrame
public static void main(String s[]) public static void main(String s[])
{ {
String j2kfilename, uri; String j2kfilename, uri, host;
boolean session, jppstream; boolean session, jppstream;
int aux; // 0: none, 1: tcp, 2: udp int port, aux; // 0: none, 1: tcp, 2: udp
if(s.length >= 2){ if(s.length >= 2){
uri = s[0]; uri = s[0];
j2kfilename = s[1]; j2kfilename = s[1];
if( s.length > 2) if( s.length > 2)
session = !s[2].equalsIgnoreCase( "stateless"); host = s[2];
else
host = "localhost";
if( s.length > 3)
port = Integer.valueOf( s[3]).intValue();
else
port = 50000;
if( s.length > 4)
session = !s[4].equalsIgnoreCase( "stateless");
else else
session = true; session = true;
if( s.length > 3) if( s.length > 5)
jppstream = !s[3].equalsIgnoreCase( "JPT"); jppstream = !s[5].equalsIgnoreCase( "JPT");
else else
jppstream = true; jppstream = true;
if( s.length > 4){ if( s.length > 6){
if( s[4].equalsIgnoreCase("udp")) if( s[6].equalsIgnoreCase("udp"))
aux = 2; aux = 2;
else else
aux = 1; aux = 1;
@ -93,10 +104,10 @@ public class ImageWindow extends JFrame
aux = 0; aux = 0;
} }
else{ 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; 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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

View File

@ -32,24 +32,33 @@ import java.io.*;
import java.net.*; import java.net.*;
public class ImgdecClient{ public class ImgdecClient{
private String hostname;
private int portNo;
public static PnmImage decode_jpipstream( byte[] jpipstream, String tid, String cid, int fw, int fh) public ImgdecClient( String host, int port)
{
hostname = host;
portNo = port;
}
public PnmImage decode_jpipstream( byte[] jpipstream, String tid, String cid, int fw, int fh)
{ {
if( jpipstream != null) if( jpipstream != null)
send_JPIPstream( jpipstream); send_JPIPstream( jpipstream);
return get_PNMstream( cid, tid, fw, fh); 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); send_JPIPstream( jpipstream, j2kfilename, tid, cid);
return get_PNMstream( cid, tid, fw, fh); return get_PNMstream( cid, tid, fw, fh);
} }
public static void send_JPIPstream( byte[] jpipstream) public void send_JPIPstream( byte[] jpipstream)
{ {
try{ try{
Socket imgdecSocket = new Socket( "localhost", 50000); Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
@ -71,10 +80,10 @@ public class ImgdecClient{
} }
} }
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{ try{
Socket imgdecSocket = new Socket( "localhost", 50000); Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
int length = 0; int length = 0;
@ -109,12 +118,12 @@ public class ImgdecClient{
} }
} }
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; PnmImage pnmstream = null;
try { try {
Socket imgdecSocket = new Socket( "localhost", 50000); Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[7]; byte []header = new byte[7];
@ -166,12 +175,12 @@ public class ImgdecClient{
return pnmstream; return pnmstream;
} }
public static byte [] get_XMLstream( String cid) public byte [] get_XMLstream( String cid)
{ {
byte []xmldata = null; byte []xmldata = null;
try{ try{
Socket imgdecSocket = new Socket( "localhost", 50000); Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[5]; byte []header = new byte[5];
@ -197,7 +206,7 @@ public class ImgdecClient{
return xmldata; return xmldata;
} }
public static String query_cid( String j2kfilename) public String query_cid( String j2kfilename)
{ {
int []retmsglabel = new int[3]; int []retmsglabel = new int[3];
retmsglabel[0] = 67; retmsglabel[0] = 67;
@ -207,7 +216,7 @@ public class ImgdecClient{
return query_id( "CID request", j2kfilename, retmsglabel); 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]; int []retmsglabel = new int[3];
retmsglabel[0] = 84; retmsglabel[0] = 84;
@ -217,12 +226,12 @@ public class ImgdecClient{
return query_id( "TID request", j2kfilename, retmsglabel); 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; String id = null;
try{ try{
Socket imgdecSocket = new Socket( "localhost", 50000); Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[4]; byte []header = new byte[4];
@ -254,12 +263,12 @@ public class ImgdecClient{
return id; 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; java.awt.Dimension dim = null;
try{ try{
Socket imgdecSocket = new Socket( "localhost", 50000); Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[3]; byte []header = new byte[3];
@ -297,7 +306,7 @@ public class ImgdecClient{
return dim; 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 remlen = length;
int off = 0; int off = 0;
@ -318,10 +327,10 @@ public class ImgdecClient{
} }
} }
public static void destroy_cid( String cid) public void destroy_cid( String cid)
{ {
try{ try{
Socket imgdecSocket = new Socket( "localhost", 50000); Socket imgdecSocket = new Socket( hostname, portNo);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream()); DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());

View File

@ -38,11 +38,11 @@ public class ImageWindow extends JFrame
private OptionPanel optpanel; private OptionPanel optpanel;
private ImageManager imgmanager; 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); super( j2kfilename);
imgmanager = new ImageManager( uri); imgmanager = new ImageManager( uri, host, port);
imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream, aux); imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream, aux);
imgviewer.setOpaque(true); //content panes must be opaque imgviewer.setOpaque(true); //content panes must be opaque
@ -70,25 +70,36 @@ public class ImageWindow extends JFrame
public static void main(String s[]) public static void main(String s[])
{ {
String j2kfilename, uri; String j2kfilename, uri, host;
boolean session, jppstream; boolean session, jppstream;
int aux; // 0: none, 1: tcp, 2: udp int port, aux; // 0: none, 1: tcp, 2: udp
if(s.length >= 2){ if(s.length >= 2){
uri = s[0]; uri = s[0];
j2kfilename = s[1]; j2kfilename = s[1];
if( s.length > 2) if( s.length > 2)
session = !s[2].equalsIgnoreCase( "stateless"); host = s[2];
else
host = "localhost";
if( s.length > 3)
port = Integer.valueOf( s[3]).intValue();
else
port = 50000;
if( s.length > 4)
session = !s[4].equalsIgnoreCase( "stateless");
else else
session = true; session = true;
if( s.length > 3) if( s.length > 5)
jppstream = !s[3].equalsIgnoreCase( "JPT"); jppstream = !s[5].equalsIgnoreCase( "JPT");
else else
jppstream = true; jppstream = true;
if( s.length > 4){ if( s.length > 6){
if( s[4].equalsIgnoreCase("udp")) if( s[6].equalsIgnoreCase("udp"))
aux = 2; aux = 2;
else else
aux = 1; aux = 1;
@ -97,10 +108,10 @@ public class ImageWindow extends JFrame
aux = 0; aux = 0;
} }
else{ 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; 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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@ -110,4 +121,4 @@ public class ImageWindow extends JFrame
frame.setLocation( 0, 50); frame.setLocation( 0, 50);
frame.setVisible(true); frame.setVisible(true);
} }
} }