[trunk][JPIP] enabled OpenJPEG V2 API

This commit is contained in:
Kaori Hagihara 2011-11-08 15:22:02 +00:00
parent bd8bca87b2
commit 815e2f3d03
7 changed files with 65 additions and 28 deletions

View File

@ -7,6 +7,7 @@ What's New for OpenJPIP
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

View File

@ -112,7 +112,8 @@ void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_par
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( pnmstream); if( 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)

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

View File

@ -41,14 +41,14 @@ void info_callback(const char *msg, void *client_data);
Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox); Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox);
Byte_t * j2k_to_pnm( Byte_t *j2kstream, Byte8_t j2klen, ihdrbox_param_t **ihdrbox) Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox)
{ {
Byte_t *pnmstream = NULL; Byte_t *pnmstream = NULL;
opj_dparameters_t parameters; /* decompression parameters */ opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
opj_image_t *image = NULL; opj_image_t *image = NULL;
opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */ opj_codec_t *dinfo = NULL; /* handle to a decompressor */
opj_cio_t *cio = NULL; opj_stream_t *cio = NULL;
/* configure the event callbacks (not required) */ /* configure the event callbacks (not required) */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
@ -59,35 +59,61 @@ Byte_t * j2k_to_pnm( Byte_t *j2kstream, Byte8_t j2klen, ihdrbox_param_t **ihdrbo
/* set decoding parameters to default values */ /* set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters); opj_set_default_decoder_parameters(&parameters);
/* Set default event mgr */
opj_initialize_default_event_handler(&event_mgr, 1);
/* set a byte stream */
cio = opj_stream_create_default_file_stream( fp, 1);
if (!cio){
fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
return NULL;
}
/* decode the code-stream */ /* decode the code-stream */
/* ---------------------- */ /* ---------------------- */
/* JPEG-2000 codestream */ /* JPEG-2000 codestream */
/* get a decoder handle */ /* get a decoder handle */
dinfo = opj_create_decompress( CODEC_J2K); dinfo = opj_create_decompress_v2(CODEC_J2K);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */ /* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, &parameters); if ( !opj_setup_decoder_v2(dinfo, &parameters, &event_mgr) ){
/* open a byte stream */ fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
cio = opj_cio_open((opj_common_ptr)dinfo, j2kstream, j2klen);
fprintf( stderr, "opj_decode dinfo:%p cio:%p\n", dinfo, cio);
/* decode the stream and fill the image structure */
image = opj_decode(dinfo, cio);
fprintf( stderr, "done\n");
if(!image) {
fprintf(stderr, "ERROR -> jp2_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
return NULL; return NULL;
} }
/* Read the main header of the codestream and if necessary the JP2 boxes*/
if(! opj_read_header( cio, dinfo, &image)){
fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n");
opj_stream_destroy(cio);
opj_destroy_codec(dinfo);
opj_image_destroy(image);
return NULL;
}
#ifdef TODO //decode area could be set from j2k_to_pnm call, modify the protocol between JPIP viewer and opj_dec_server
if (! opj_set_decode_area( dinfo, image, parameters.DA_x0, parameters.DA_y0, parameters.DA_x1, parameters.DA_y1)){
fprintf(stderr, "ERROR -> j2k_to_image: failed to set the decoded area\n");
opj_stream_destroy(cio);
opj_destroy_codec(dinfo);
opj_image_destroy(image);
return NULL;
}
#endif //TODO
/* Get the decoded image */
if ( !( opj_decode_v2(dinfo, cio, image) && opj_end_decompress(dinfo,cio) ) ) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_stream_destroy(cio);
opj_destroy_codec(dinfo);
opj_image_destroy(image);
return NULL;
}
fprintf(stderr, "image is decoded!\n");
/* close the byte stream */ /* close the byte stream */
opj_cio_close(cio); opj_stream_destroy(cio);
/* create output image */ /* create output image */
/* ------------------- */ /* ------------------- */
@ -96,7 +122,7 @@ Byte_t * j2k_to_pnm( Byte_t *j2kstream, Byte8_t j2klen, ihdrbox_param_t **ihdrbo
/* free remaining structures */ /* free remaining structures */
if(dinfo) { if(dinfo) {
opj_destroy_decompress(dinfo); opj_destroy_codec(dinfo);
} }
/* free image data structure */ /* free image data structure */

View File

@ -34,6 +34,6 @@
#include "byte_manager.h" #include "byte_manager.h"
#include "ihdrbox_manager.h" #include "ihdrbox_manager.h"
Byte_t * j2k_to_pnm( Byte_t *j2kstream, Byte8_t j2klen, ihdrbox_param_t **ihdrbox); Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox);
#endif /* !JP2K_DECODER_H_ */ #endif /* !JP2K_DECODER_H_ */

View File

@ -73,11 +73,20 @@ Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte
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;
char j2kfname[] = "tmp.j2k";
j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen); j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen);
pnmstream = j2k_to_pnm( j2kstream, j2klen, ihdrbox);
fp = fopen( j2kfname, "w+b");
fwrite( j2kstream, j2klen, 1, fp);
free( j2kstream); free( j2kstream);
fseek( fp, 0, SEEK_SET);
pnmstream = j2k_to_pnm( fp, ihdrbox);
fclose( fp);
remove( j2kfname);
return pnmstream; return pnmstream;
} }

View File

@ -218,7 +218,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;