[1.5][JPIP] fixed Region of Interest option, and memory leak of opj_dec_server

This commit is contained in:
Kaori Hagihara 2011-11-16 15:43:01 +00:00
parent 735b40989d
commit 544e8c9de0
22 changed files with 225 additions and 24 deletions

View File

@ -5,6 +5,9 @@ What's New for OpenJPIP
! : changed ! : changed
+ : added + : added
November 16, 2011
* [kaori] fixed Region of Interest option, and memory leak of opj_dec_server
November 8, 2011 November 8, 2011
! [kaori] updated main page of doxygen ! [kaori] updated main page of doxygen

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

@ -90,7 +90,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)))
@ -107,11 +107,12 @@ 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);
free( ihdrbox);
free( pnmstream); free( pnmstream);
} }
@ -185,6 +186,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

@ -85,7 +85,7 @@ SOCKET open_listeningsocket()
close_socket(listening_socket); close_socket(listening_socket);
exit(1); exit(1);
} }
printf("port %d is listened\n", port); fprintf( stderr, "port %d is listened\n", port);
return listening_socket; return listening_socket;
} }
@ -102,7 +102,7 @@ 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"}; 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);
@ -114,7 +114,7 @@ msgtype_t identify_clientmsg( SOCKET connected_socket)
for( i=0; i<NUM_OF_MSGTYPES; i++){ for( i=0; i<NUM_OF_MSGTYPES; i++){
if( strncasecmp( magicid[i], buf, strlen(magicid[i])) == 0){ if( strncasecmp( magicid[i], buf, strlen(magicid[i])) == 0){
printf("%s\n", magicid[i]); fprintf( stderr, "%s\n", magicid[i]);
return i; return i;
} }
} }
@ -238,6 +238,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 send_stream( SOCKET connected_socket, void *stream, int length) void send_stream( SOCKET connected_socket, void *stream, int length)
{ {
void *ptr = stream; void *ptr = stream;

View File

@ -56,8 +56,8 @@ SOCKET open_listeningsocket();
SOCKET accept_socket( SOCKET listening_socket); SOCKET accept_socket( SOCKET listening_socket);
#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
@ -84,8 +84,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)
*/ */
@ -118,6 +118,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
* *
@ -192,13 +201,19 @@ int close_socket( SOCKET sock);
* 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

@ -188,8 +188,7 @@ 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));
@ -204,6 +203,12 @@ 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;

View File

@ -129,6 +129,14 @@ void print_COD( CODmarker_param_t COD);
*/ */
void delete_index( index_param_t **index); void delete_index( index_param_t **index);
/**
* delete dynamic arrays in COD marker
*
* @param[in] COD COD marker information
*/
void delete_COD( CODmarker_param_t COD);
//! 1-dimensional range parameters //! 1-dimensional range parameters
typedef struct range_param{ typedef struct range_param{
Byte4_t minvalue; //!< minimal value Byte4_t minvalue; //!< minimal value

View File

@ -74,11 +74,11 @@ Byte_t * j2k_to_pnm( Byte_t *j2kstream, Byte8_t j2klen, ihdrbox_param_t **ihdrbo
/* open a byte stream */ /* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, j2kstream, j2klen); cio = opj_cio_open((opj_common_ptr)dinfo, j2kstream, j2klen);
fprintf( stderr, "opj_decode dinfo:%p cio:%p\n", dinfo, cio);
/* decode the stream and fill the image structure */ /* decode the stream and fill the image structure */
image = opj_decode(dinfo, cio); image = opj_decode(dinfo, cio);
fprintf( stderr, "done\n"); fprintf(stderr, "image is decoded!\n");
if(!image) { if(!image) {
fprintf(stderr, "ERROR -> jp2_to_image: failed to decode image!\n"); fprintf(stderr, "ERROR -> jp2_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo); opj_destroy_decompress(dinfo);

View File

@ -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;
} }
@ -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

@ -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)
{ {
@ -81,3 +83,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

@ -37,3 +37,5 @@ Byte_t * update_JPIPstream( Byte_t *newstream, int newstreamlen, Byte_t *cache_s
void save_codestream( Byte_t *codestream, Byte8_t streamlen, char *fmt); 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);
ihdrbox_param_t * get_SIZ_from_jpipstream( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn);

View File

@ -205,6 +205,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);
@ -218,7 +222,7 @@ bool handle_clientreq( client_t client, dec_server_record_t *rec)
break; break;
} }
printf("\t end of the connection\n\n"); fprintf( stderr, "\t end of the connection\n\n");
if( close_socket(client) != 0){ if( close_socket(client) != 0){
perror("close"); perror("close");
return false; return false;

View File

@ -1 +1 @@
opj_viewer-20111026.jar opj_viewer-20111116.jar

View File

@ -33,15 +33,32 @@ 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;
public ImageManager( String uri) public ImageManager( String uri)
{ {
super( uri); super( uri);
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 = ImgdecClient.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, boolean reqJPP, boolean reqJPT) public Image getImage( String j2kfilename, int reqfw, int reqfh, boolean reqcnew, boolean reqJPP, boolean reqJPT)
{ {
@ -106,6 +123,7 @@ public class ImageManager extends JPIPHttpClient
} }
return xmldata; return xmldata;
} }
public void closeChannel() public void closeChannel()
{ {
if( cid != null){ if( cid != null){

View File

@ -253,6 +253,49 @@ public class ImgdecClient{
return id; return id;
} }
public static java.awt.Dimension query_imagesize( String cid, String tid)
{
java.awt.Dimension dim = null;
try{
Socket imgdecSocket = new Socket( "localhost", 5000);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[3];
os.writeBytes( "SIZ request\n");
if( tid == null)
os.writeBytes( "0\n");
else
os.writeBytes( tid + "\n");
if( cid == null)
os.writeBytes( "0\n");
else
os.writeBytes( cid + "\n");
read_stream( is, header, 3);
if( header[0] == 83 && header[1] == 73 && header[2] == 90){
byte []data = new byte[ 3];
read_stream( is, data, 3);
int w = (data[0]&0xff)<<16 | (data[1]&0xff)<<8 | (data[2]&0xff);
read_stream( is, data, 3);
int h = (data[0]&0xff)<<16 | (data[1]&0xff)<<8 | (data[2]&0xff);
dim = new java.awt.Dimension( w, h);
}
else
System.err.println("Error in query_imagesize("+ cid + ", " + tid + "), wrong to start with " + header);
}
catch (UnknownHostException e) {
System.err.println("Trying to connect to unknown host: " + e);
} catch (IOException e) {
System.err.println("IOException: " + e);
}
return dim;
}
public static void read_stream( DataInputStream is, byte []stream, int length) public static void read_stream( DataInputStream is, byte []stream, int length)
{ {

View File

@ -1 +1 @@
opj_viewer_xerces-20111026.jar opj_viewer_xerces-20111116.jar