[trunk] Update JPIP (FolderReorgProposal task)
This commit does three things: - Use opj_malloc/calloc/free instead of the default C ones. - Update JPIP API to start using cio _v2 API - Create a new opj_jpip_compress which is the replacement for image_to_j2k -jpip Update issue 177
This commit is contained in:
parent
23f5eeec20
commit
9832c911b3
|
@ -2,6 +2,8 @@
|
||||||
include_directories(
|
include_directories(
|
||||||
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
|
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
|
||||||
${OPENJPEG_SOURCE_DIR}/src/lib/openjp2
|
${OPENJPEG_SOURCE_DIR}/src/lib/openjp2
|
||||||
|
${OPENJPEG_SOURCE_DIR}/src/bin/common # opj_getopt.h
|
||||||
|
${OPENJPEG_SOURCE_DIR}/src/bin/jp2 # convert.h
|
||||||
${OPENJPEG_SOURCE_DIR}/src/lib/openjpip
|
${OPENJPEG_SOURCE_DIR}/src/lib/openjpip
|
||||||
${FCGI_INCLUDE_DIRS}
|
${FCGI_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
@ -15,7 +17,6 @@ install(TARGETS opj_jpip_addxml
|
||||||
)
|
)
|
||||||
|
|
||||||
if(BUILD_JPIP_SERVER)
|
if(BUILD_JPIP_SERVER)
|
||||||
|
|
||||||
set(OPJ_SERVER_SRCS
|
set(OPJ_SERVER_SRCS
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/opj_server.c
|
${CMAKE_CURRENT_SOURCE_DIR}/opj_server.c
|
||||||
)
|
)
|
||||||
|
@ -45,9 +46,20 @@ set(EXES
|
||||||
opj_dec_server
|
opj_dec_server
|
||||||
opj_jpip_transcode
|
opj_jpip_transcode
|
||||||
opj_jpip_test
|
opj_jpip_test
|
||||||
|
opj_jpip_compress
|
||||||
)
|
)
|
||||||
foreach(exe ${EXES})
|
foreach(exe ${EXES})
|
||||||
add_executable(${exe} ${exe}.c)
|
if(${exe} STREQUAL "opj_jpip_compress")
|
||||||
|
add_executable(${exe} ${exe}.c
|
||||||
|
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c
|
||||||
|
${OPENJPEG_SOURCE_DIR}/src/bin/jp2/convert.c
|
||||||
|
)
|
||||||
|
target_link_libraries(${exe}
|
||||||
|
${PNG_LIBNAME} ${TIFF_LIBNAME} ${LCMS_LIBNAME}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
add_executable(${exe} ${exe}.c)
|
||||||
|
endif()
|
||||||
target_link_libraries(${exe} openjpip)
|
target_link_libraries(${exe} openjpip)
|
||||||
install(TARGETS ${exe}
|
install(TARGETS ${exe}
|
||||||
EXPORT OpenJPEGTargets
|
EXPORT OpenJPEGTargets
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -205,6 +205,7 @@ typedef struct opj_jp2_v2
|
||||||
OPJ_UINT32 *cl;
|
OPJ_UINT32 *cl;
|
||||||
opj_jp2_comps_t *comps;
|
opj_jp2_comps_t *comps;
|
||||||
OPJ_OFF_T j2k_codestream_offset;
|
OPJ_OFF_T j2k_codestream_offset;
|
||||||
|
OPJ_OFF_T jpip_iptr_offset;
|
||||||
OPJ_UINT32 jp2_state;
|
OPJ_UINT32 jp2_state;
|
||||||
OPJ_UINT32 jp2_img_state;
|
OPJ_UINT32 jp2_img_state;
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ cachemodellist_param_t * gene_cachemodellist(void)
|
||||||
{
|
{
|
||||||
cachemodellist_param_t *cachemodellist;
|
cachemodellist_param_t *cachemodellist;
|
||||||
|
|
||||||
cachemodellist = (cachemodellist_param_t *)malloc( sizeof(cachemodellist_param_t));
|
cachemodellist = (cachemodellist_param_t *)opj_malloc( sizeof(cachemodellist_param_t));
|
||||||
|
|
||||||
cachemodellist->first = NULL;
|
cachemodellist->first = NULL;
|
||||||
cachemodellist->last = NULL;
|
cachemodellist->last = NULL;
|
||||||
|
@ -65,7 +65,7 @@ cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, ta
|
||||||
Byte8_t numOftiles;
|
Byte8_t numOftiles;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
cachemodel = (cachemodel_param_t *)malloc( sizeof(cachemodel_param_t));
|
cachemodel = (cachemodel_param_t *)opj_malloc( sizeof(cachemodel_param_t));
|
||||||
|
|
||||||
refer_target( target, &cachemodel->target);
|
refer_target( target, &cachemodel->target);
|
||||||
|
|
||||||
|
@ -86,12 +86,12 @@ cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, ta
|
||||||
tilepart = target->codeidx->tilepart;
|
tilepart = target->codeidx->tilepart;
|
||||||
numOftiles = get_m( tilepart);
|
numOftiles = get_m( tilepart);
|
||||||
numOfelem = get_nmax( tilepart)*numOftiles;
|
numOfelem = get_nmax( tilepart)*numOftiles;
|
||||||
cachemodel->tp_model = (bool *)calloc( 1, numOfelem*sizeof(bool));
|
cachemodel->tp_model = (bool *)opj_calloc( 1, numOfelem*sizeof(bool));
|
||||||
cachemodel->th_model = (bool *)calloc( 1, numOftiles*sizeof(bool));
|
cachemodel->th_model = (bool *)opj_calloc( 1, numOftiles*sizeof(bool));
|
||||||
cachemodel->pp_model = (bool **)malloc( target->codeidx->SIZ.Csiz*sizeof(bool *));
|
cachemodel->pp_model = (bool **)opj_malloc( target->codeidx->SIZ.Csiz*sizeof(bool *));
|
||||||
for( i=0; i<target->codeidx->SIZ.Csiz; i++){
|
for( i=0; i<target->codeidx->SIZ.Csiz; i++){
|
||||||
precpacket = target->codeidx->precpacket[i];
|
precpacket = target->codeidx->precpacket[i];
|
||||||
cachemodel->pp_model[i] = (bool *)calloc( 1, get_nmax(precpacket)*get_m(precpacket)*sizeof(bool));
|
cachemodel->pp_model[i] = (bool *)opj_calloc( 1, get_nmax(precpacket)*get_m(precpacket)*sizeof(bool));
|
||||||
}
|
}
|
||||||
cachemodel->next = NULL;
|
cachemodel->next = NULL;
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ void delete_cachemodellist( cachemodellist_param_t **cachemodellist)
|
||||||
delete_cachemodel( &cachemodelPtr);
|
delete_cachemodel( &cachemodelPtr);
|
||||||
cachemodelPtr=cachemodelNext;
|
cachemodelPtr=cachemodelNext;
|
||||||
}
|
}
|
||||||
free(*cachemodellist);
|
opj_free(*cachemodellist);
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_cachemodel( cachemodel_param_t **cachemodel)
|
void delete_cachemodel( cachemodel_param_t **cachemodel)
|
||||||
|
@ -183,17 +183,17 @@ void delete_cachemodel( cachemodel_param_t **cachemodel)
|
||||||
|
|
||||||
unrefer_target( (*cachemodel)->target);
|
unrefer_target( (*cachemodel)->target);
|
||||||
|
|
||||||
free( (*cachemodel)->tp_model);
|
opj_free( (*cachemodel)->tp_model);
|
||||||
free( (*cachemodel)->th_model);
|
opj_free( (*cachemodel)->th_model);
|
||||||
|
|
||||||
for( i=0; i<(*cachemodel)->target->codeidx->SIZ.Csiz; i++)
|
for( i=0; i<(*cachemodel)->target->codeidx->SIZ.Csiz; i++)
|
||||||
free( (*cachemodel)->pp_model[i]);
|
opj_free( (*cachemodel)->pp_model[i]);
|
||||||
free( (*cachemodel)->pp_model);
|
opj_free( (*cachemodel)->pp_model);
|
||||||
|
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
fprintf( logstream, "local log: cachemodel deleted\n");
|
fprintf( logstream, "local log: cachemodel deleted\n");
|
||||||
#endif
|
#endif
|
||||||
free( *cachemodel);
|
opj_free( *cachemodel);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_allsent( cachemodel_param_t cachemodel)
|
bool is_allsent( cachemodel_param_t cachemodel)
|
||||||
|
|
|
@ -49,7 +49,7 @@ channellist_param_t * gene_channellist(void)
|
||||||
{
|
{
|
||||||
channellist_param_t *channellist;
|
channellist_param_t *channellist;
|
||||||
|
|
||||||
channellist = (channellist_param_t *)malloc( sizeof(channellist_param_t));
|
channellist = (channellist_param_t *)opj_malloc( sizeof(channellist_param_t));
|
||||||
|
|
||||||
channellist->first = NULL;
|
channellist->first = NULL;
|
||||||
channellist->last = NULL;
|
channellist->last = NULL;
|
||||||
|
@ -68,7 +68,7 @@ channel_param_t * gene_channel( query_param_t query_param, auxtrans_param_t auxt
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
channel = (channel_param_t *)malloc( sizeof(channel_param_t));
|
channel = (channel_param_t *)opj_malloc( sizeof(channel_param_t));
|
||||||
channel->cachemodel = cachemodel;
|
channel->cachemodel = cachemodel;
|
||||||
|
|
||||||
/* set channel ID and get present time */
|
/* set channel ID and get present time */
|
||||||
|
@ -130,7 +130,7 @@ void delete_channel( channel_param_t **channel, channellist_param_t *channellist
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
fprintf( logstream, "local log: channel: %s deleted\n", (*channel)->cid);
|
fprintf( logstream, "local log: channel: %s deleted\n", (*channel)->cid);
|
||||||
#endif
|
#endif
|
||||||
free(*channel);
|
opj_free(*channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_channellist( channellist_param_t **channellist)
|
void delete_channellist( channellist_param_t **channellist)
|
||||||
|
@ -143,10 +143,10 @@ void delete_channellist( channellist_param_t **channellist)
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
fprintf( logstream, "local log: channel %s deleted!\n", channelPtr->cid);
|
fprintf( logstream, "local log: channel %s deleted!\n", channelPtr->cid);
|
||||||
#endif
|
#endif
|
||||||
free(channelPtr);
|
opj_free(channelPtr);
|
||||||
channelPtr=channelNext;
|
channelPtr=channelNext;
|
||||||
}
|
}
|
||||||
free( *channellist);
|
opj_free( *channellist);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_allchannel( channellist_param_t *channellist)
|
void print_allchannel( channellist_param_t *channellist)
|
||||||
|
|
|
@ -41,6 +41,11 @@
|
||||||
*/
|
*/
|
||||||
void write_cptr(int coff, int clen, opj_cio_t *cio);
|
void write_cptr(int coff, int clen, opj_cio_t *cio);
|
||||||
|
|
||||||
|
void write_cptr_v2(int coff, int clen, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager );
|
||||||
|
|
||||||
|
void write_manf_v2(int second, int v, opj_jp2_box_t *box, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write main header index table (box)
|
* Write main header index table (box)
|
||||||
|
@ -123,6 +128,79 @@ int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_i
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int write_cidx_v2( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
int len, i, lenp;
|
||||||
|
opj_jp2_box_t *box;
|
||||||
|
int num_box = 0;
|
||||||
|
opj_bool EPHused;
|
||||||
|
OPJ_BYTE l_data_header [4];
|
||||||
|
|
||||||
|
lenp = -1;
|
||||||
|
box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t));
|
||||||
|
|
||||||
|
for (i=0;i<2;i++){
|
||||||
|
|
||||||
|
if(i)
|
||||||
|
opj_stream_seek(cio,lenp,p_manager);
|
||||||
|
|
||||||
|
|
||||||
|
lenp = opj_stream_tell (cio);
|
||||||
|
|
||||||
|
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, JPIP_CIDX, 4); /* CIDX */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,JPIP_CIDX,4); /* CIDX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
write_cptr_v2( offset, cstr_info.codestream_size, cio,p_manager);
|
||||||
|
|
||||||
|
write_manf_v2( i, num_box, box, cio,p_manager);
|
||||||
|
|
||||||
|
num_box = 0;
|
||||||
|
box[num_box].length = write_mainmhix_v2( offset, cstr_info, cio,p_manager);
|
||||||
|
box[num_box].type = JPIP_MHIX;
|
||||||
|
num_box++;
|
||||||
|
|
||||||
|
box[num_box].length = write_tpix_v2( offset, cstr_info, j2klen, cio);
|
||||||
|
box[num_box].type = JPIP_TPIX;
|
||||||
|
num_box++;
|
||||||
|
|
||||||
|
box[num_box].length = write_thix_v2( offset, cstr_info, cio);
|
||||||
|
box[num_box].type = JPIP_THIX;
|
||||||
|
num_box++;
|
||||||
|
|
||||||
|
EPHused = check_EPHuse_v2( offset, cstr_info.marker, cstr_info.marknum, cio);
|
||||||
|
|
||||||
|
box[num_box].length = write_ppix_v2( offset, cstr_info, EPHused, j2klen, cio);
|
||||||
|
box[num_box].type = JPIP_PPIX;
|
||||||
|
num_box++;
|
||||||
|
|
||||||
|
box[num_box].length = write_phix_v2( offset, cstr_info, EPHused, j2klen, cio);
|
||||||
|
box[num_box].type = JPIP_PHIX;
|
||||||
|
num_box++;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
len = opj_stream_tell(cio)-lenp;
|
||||||
|
opj_stream_seek(cio, lenp,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,len,4);/* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek(cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_free( box);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
void write_cptr(int coff, int clen, opj_cio_t *cio)
|
void write_cptr(int coff, int clen, opj_cio_t *cio)
|
||||||
{
|
{
|
||||||
int len, lenp;
|
int len, lenp;
|
||||||
|
@ -140,6 +218,42 @@ void write_cptr(int coff, int clen, opj_cio_t *cio)
|
||||||
cio_seek( cio, lenp+len);
|
cio_seek( cio, lenp+len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void write_cptr_v2(int coff, int clen, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_BYTE l_data_header [3*8];
|
||||||
|
int len, lenp;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_CPTR, 4); /* T */
|
||||||
|
cio_write( cio, 0, 2); /* DR A PRECISER !! */
|
||||||
|
cio_write( cio, 0, 2); /* CONT */
|
||||||
|
cio_write( cio, coff, 8); /* COFF A PRECISER !! */
|
||||||
|
cio_write( cio, clen, 8); /* CLEN */
|
||||||
|
len = cio_tell( cio) - lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell(cio);
|
||||||
|
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
|
||||||
|
opj_write_bytes( l_data_header, JPIP_CPTR, 4); /* T */
|
||||||
|
opj_write_bytes( l_data_header+4, 0, 2); /* DR A PRECISER !! */
|
||||||
|
opj_write_bytes( l_data_header+6, 0, 2); /* CONT */
|
||||||
|
opj_write_bytes( l_data_header+8, coff, 8); /* COFF A PRECISER !! */
|
||||||
|
opj_write_bytes( l_data_header+16, clen, 8); /* CLEN */
|
||||||
|
opj_stream_write_data(cio,l_data_header,3*8,p_manager);
|
||||||
|
|
||||||
|
len = opj_stream_tell(cio) - lenp;
|
||||||
|
opj_stream_seek(cio,lenp,p_manager);
|
||||||
|
opj_write_bytes(l_data_header, len, 4); /* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek(cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio)
|
void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio)
|
||||||
{
|
{
|
||||||
int len, lenp, i;
|
int len, lenp, i;
|
||||||
|
@ -161,6 +275,51 @@ void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio)
|
||||||
cio_seek( cio, lenp+len);
|
cio_seek( cio, lenp+len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void write_manf_v2(int second, int v, opj_jp2_box_t *box, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_BYTE l_data_header [4];
|
||||||
|
int len, lenp, i;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_MANF,4); /* T */
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell(cio);
|
||||||
|
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
|
||||||
|
opj_write_bytes( l_data_header, JPIP_MANF, 4); /* T */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (second){ /* Write only during the second pass */
|
||||||
|
for( i=0; i<v; i++){
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, box[i].length, 4); /* Box length */
|
||||||
|
cio_write( cio, box[i].type, 4); /* Box type */
|
||||||
|
#else
|
||||||
|
opj_write_bytes( l_data_header, box[i].length, 4); /* Box length */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio) - lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
len = opj_stream_tell(cio) - lenp;
|
||||||
|
opj_stream_seek(cio,lenp,p_manager);
|
||||||
|
opj_write_bytes(l_data_header, len, 4);/* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek(cio,lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio)
|
int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -187,6 +346,64 @@ int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio)
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int write_mainmhix_v2( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_BYTE l_data_header [8];
|
||||||
|
int i;
|
||||||
|
int len, lenp;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_MHIX, 4); /* MHIX */
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell (cio);
|
||||||
|
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
|
||||||
|
opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, cstr_info.main_head_end-cstr_info.main_head_start+1, 8); /* TLEN */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header, cstr_info.main_head_end-cstr_info.main_head_start+1, 8); /* TLEN */
|
||||||
|
opj_stream_write_data(cio,l_data_header,8,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for(i = 1; i < cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, cstr_info.marker[i].type, 2);
|
||||||
|
cio_write( cio, 0, 2);
|
||||||
|
cio_write( cio, cstr_info.marker[i].pos-coff, 8);
|
||||||
|
cio_write( cio, cstr_info.marker[i].len, 2);
|
||||||
|
#else
|
||||||
|
opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
|
||||||
|
opj_write_bytes( l_data_header+2, 0, 2);
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_write_bytes( l_data_header, cstr_info.marker[i].pos-coff, 8);
|
||||||
|
opj_stream_write_data(cio,l_data_header,8,p_manager);
|
||||||
|
opj_write_bytes( l_data_header, cstr_info.marker[i].len, 2);
|
||||||
|
opj_stream_write_data(cio,l_data_header,2,p_manager);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio) - lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
len = opj_stream_tell(cio)-lenp;
|
||||||
|
opj_stream_seek(cio, lenp,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,len,4);/* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek(cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio)
|
opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio)
|
||||||
{
|
{
|
||||||
opj_bool EPHused = OPJ_FALSE;
|
opj_bool EPHused = OPJ_FALSE;
|
||||||
|
@ -201,7 +418,7 @@ opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_ci
|
||||||
|
|
||||||
Scod = cio_read( cio, 1);
|
Scod = cio_read( cio, 1);
|
||||||
if( ((Scod >> 2) & 1))
|
if( ((Scod >> 2) & 1))
|
||||||
EPHused = OPJ_TRUE;
|
EPHused = OPJ_TRUE;
|
||||||
cio_seek( cio, org_pos);
|
cio_seek( cio, org_pos);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -209,3 +426,44 @@ opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_ci
|
||||||
}
|
}
|
||||||
return EPHused;
|
return EPHused;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opj_bool check_EPHuse_v2( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_BYTE l_data_header [4];
|
||||||
|
opj_bool EPHused = OPJ_FALSE;
|
||||||
|
int i=0;
|
||||||
|
int org_pos;
|
||||||
|
unsigned int Scod;
|
||||||
|
|
||||||
|
for(i = 0; i < marknum; i++)
|
||||||
|
{
|
||||||
|
if( markers[i].type == J2K_MS_COD)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
org_pos = cio_tell( cio);
|
||||||
|
cio_seek( cio, coff+markers[i].pos+2);
|
||||||
|
#else
|
||||||
|
org_pos = opj_stream_tell(cio);
|
||||||
|
opj_stream_seek(cio, coff+markers[i].pos+2,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
Scod = cio_read( cio, 1);
|
||||||
|
#else
|
||||||
|
opj_stream_read_data(cio,l_data_header,1,p_manager);
|
||||||
|
opj_read_bytes(l_data_header,&Scod,1);
|
||||||
|
#endif
|
||||||
|
if( ((Scod >> 2) & 1))
|
||||||
|
EPHused = OPJ_TRUE;
|
||||||
|
#if 0
|
||||||
|
cio_seek( cio, org_pos);
|
||||||
|
#else
|
||||||
|
opj_stream_seek( cio, org_pos, p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return EPHused;
|
||||||
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist
|
||||||
parse_JPIPstream( newjpipstream, newstreamlen, (OPJ_OFF_T)*streamlen, msgqueue);
|
parse_JPIPstream( newjpipstream, newstreamlen, (OPJ_OFF_T)*streamlen, msgqueue);
|
||||||
|
|
||||||
*jpipstream = update_JPIPstream( newjpipstream, newstreamlen, *jpipstream, streamlen);
|
*jpipstream = update_JPIPstream( newjpipstream, newstreamlen, *jpipstream, streamlen);
|
||||||
free( newjpipstream);
|
opj_free( newjpipstream);
|
||||||
|
|
||||||
metadatalist = gene_metadatalist();
|
metadatalist = gene_metadatalist();
|
||||||
parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist);
|
parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist);
|
||||||
|
@ -82,9 +82,9 @@ void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist
|
||||||
delete_metadatalist( &cache->metadatalist);
|
delete_metadatalist( &cache->metadatalist);
|
||||||
cache->metadatalist = metadatalist;
|
cache->metadatalist = metadatalist;
|
||||||
|
|
||||||
if( target) free( target);
|
if( target) opj_free( target);
|
||||||
if( tid) free( tid);
|
if( tid) opj_free( tid);
|
||||||
if( cid) free( cid);
|
if( cid) opj_free( cid);
|
||||||
|
|
||||||
response_signal( connected_socket, true);
|
response_signal( connected_socket, true);
|
||||||
}
|
}
|
||||||
|
@ -102,11 +102,11 @@ void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_par
|
||||||
|
|
||||||
if(!(cache = search_cacheBycid( CIDorTID, cachelist)))
|
if(!(cache = search_cacheBycid( CIDorTID, cachelist)))
|
||||||
if(!(cache = search_cacheBytid( CIDorTID, cachelist))){
|
if(!(cache = search_cacheBytid( CIDorTID, cachelist))){
|
||||||
free( CIDorTID);
|
opj_free( CIDorTID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free( CIDorTID);
|
opj_free( CIDorTID);
|
||||||
|
|
||||||
receive_line( connected_socket, tmp);
|
receive_line( connected_socket, tmp);
|
||||||
fw = atoi( tmp);
|
fw = atoi( tmp);
|
||||||
|
@ -121,8 +121,8 @@ void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_par
|
||||||
maxval = ihdrbox->bpc > 8 ? 255 : (1 << ihdrbox->bpc) - 1;
|
maxval = ihdrbox->bpc > 8 ? 255 : (1 << ihdrbox->bpc) - 1;
|
||||||
send_PNMstream( connected_socket, pnmstream, ihdrbox->width, ihdrbox->height, ihdrbox->nc, (Byte_t)maxval );
|
send_PNMstream( connected_socket, pnmstream, ihdrbox->width, ihdrbox->height, ihdrbox->nc, (Byte_t)maxval );
|
||||||
|
|
||||||
free( ihdrbox);
|
opj_free( ihdrbox);
|
||||||
free( pnmstream);
|
opj_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)
|
||||||
|
@ -135,17 +135,17 @@ void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_pa
|
||||||
cid = receive_string( connected_socket);
|
cid = receive_string( connected_socket);
|
||||||
|
|
||||||
if(!(cache = search_cacheBycid( cid, cachelist))){
|
if(!(cache = search_cacheBycid( cid, cachelist))){
|
||||||
free( cid);
|
opj_free( cid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free( cid);
|
opj_free( cid);
|
||||||
|
|
||||||
boxcontents = cache->metadatalist->last->boxcontents;
|
boxcontents = cache->metadatalist->last->boxcontents;
|
||||||
xmlstream = (Byte_t *)malloc( boxcontents->length);
|
xmlstream = (Byte_t *)opj_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);
|
opj_free( xmlstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
|
void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
|
||||||
|
@ -157,7 +157,7 @@ void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
|
||||||
target = receive_string( connected_socket);
|
target = receive_string( connected_socket);
|
||||||
cache = search_cache( target, cachelist);
|
cache = search_cache( target, cachelist);
|
||||||
|
|
||||||
free( target);
|
opj_free( target);
|
||||||
|
|
||||||
if( cache){
|
if( cache){
|
||||||
tid = cache->tid;
|
tid = cache->tid;
|
||||||
|
@ -175,7 +175,7 @@ void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
|
||||||
target = receive_string( connected_socket);
|
target = receive_string( connected_socket);
|
||||||
cache = search_cache( target, cachelist);
|
cache = search_cache( target, cachelist);
|
||||||
|
|
||||||
free( target);
|
opj_free( target);
|
||||||
|
|
||||||
if( cache){
|
if( cache){
|
||||||
if( cache->numOfcid > 0){
|
if( cache->numOfcid > 0){
|
||||||
|
@ -194,7 +194,7 @@ void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
|
||||||
remove_cachecid( cid, cachelist);
|
remove_cachecid( cid, cachelist);
|
||||||
response_signal( connected_socket, true);
|
response_signal( connected_socket, true);
|
||||||
|
|
||||||
free( cid);
|
opj_free( cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_SIZreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_param_t *msgqueue, cachelist_param_t *cachelist)
|
void handle_SIZreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_param_t *msgqueue, cachelist_param_t *cachelist)
|
||||||
|
@ -214,8 +214,8 @@ void handle_SIZreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_par
|
||||||
if( !cache && cid[0] != '0')
|
if( !cache && cid[0] != '0')
|
||||||
cache = search_cacheBycid( cid, cachelist);
|
cache = search_cacheBycid( cid, cachelist);
|
||||||
|
|
||||||
free( tid);
|
opj_free( tid);
|
||||||
free( cid);
|
opj_free( cid);
|
||||||
|
|
||||||
width = height = 0;
|
width = height = 0;
|
||||||
if( cache){
|
if( cache){
|
||||||
|
@ -237,17 +237,17 @@ void handle_JP2saveMSG( SOCKET connected_socket, cachelist_param_t *cachelist, m
|
||||||
|
|
||||||
cid = receive_string( connected_socket);
|
cid = receive_string( connected_socket);
|
||||||
if(!(cache = search_cacheBycid( cid, cachelist))){
|
if(!(cache = search_cacheBycid( cid, cachelist))){
|
||||||
free( cid);
|
opj_free( cid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free( cid);
|
opj_free( cid);
|
||||||
|
|
||||||
assert( cache->csn >= 0);
|
assert( cache->csn >= 0);
|
||||||
jp2stream = recons_jp2( msgqueue, jpipstream, (Byte8_t)cache->csn, &jp2len);
|
jp2stream = recons_jp2( msgqueue, jpipstream, (Byte8_t)cache->csn, &jp2len);
|
||||||
|
|
||||||
if( jp2stream){
|
if( jp2stream){
|
||||||
save_codestream( jp2stream, jp2len, "jp2");
|
save_codestream( jp2stream, jp2len, "jp2");
|
||||||
free( jp2stream);
|
opj_free( jp2stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,11 +99,11 @@ index_param_t * parse_jp2file( int fd)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
jp2idx = (index_param_t *)malloc( sizeof(index_param_t));
|
jp2idx = (index_param_t *)opj_malloc( sizeof(index_param_t));
|
||||||
|
|
||||||
if( !set_cidxdata( cidx, jp2idx)){
|
if( !set_cidxdata( cidx, jp2idx)){
|
||||||
fprintf( FCGI_stderr, "Error: Not correctl format in cidx box\n");
|
fprintf( FCGI_stderr, "Error: Not correctl format in cidx box\n");
|
||||||
free(jp2idx);
|
opj_free(jp2idx);
|
||||||
delete_boxlist( &toplev_boxlist);
|
delete_boxlist( &toplev_boxlist);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -190,19 +190,19 @@ void delete_index( index_param_t **index)
|
||||||
|
|
||||||
for( i=0; i< (int)((*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);
|
opj_free( (*index)->tileheader);
|
||||||
|
|
||||||
for( i=0; i<(*index)->SIZ.Csiz; i++)
|
for( i=0; i<(*index)->SIZ.Csiz; i++)
|
||||||
delete_faixbox( &((*index)->precpacket[i]));
|
delete_faixbox( &((*index)->precpacket[i]));
|
||||||
free( (*index)->precpacket);
|
opj_free( (*index)->precpacket);
|
||||||
|
|
||||||
free(*index);
|
opj_free(*index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_COD( CODmarker_param_t COD)
|
void delete_COD( CODmarker_param_t COD)
|
||||||
{
|
{
|
||||||
if( COD.XPsiz) free( COD.XPsiz);
|
if( COD.XPsiz) opj_free( COD.XPsiz);
|
||||||
if( COD.YPsiz) free( COD.YPsiz);
|
if( COD.YPsiz) opj_free( COD.YPsiz);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_JP2boxidx( boxlist_param_t *toplev_boxlist)
|
bool check_JP2boxidx( boxlist_param_t *toplev_boxlist)
|
||||||
|
@ -242,7 +242,7 @@ bool check_JP2boxidx( boxlist_param_t *toplev_boxlist)
|
||||||
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);
|
opj_free(obh);
|
||||||
|
|
||||||
ni = fetch_DBox1byte( prxy, pos);
|
ni = fetch_DBox1byte( prxy, pos);
|
||||||
if( ni != 1){
|
if( ni != 1){
|
||||||
|
@ -260,9 +260,9 @@ bool check_JP2boxidx( boxlist_param_t *toplev_boxlist)
|
||||||
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;
|
||||||
free(ibh);
|
opj_free(ibh);
|
||||||
|
|
||||||
free(prxy);
|
opj_free(prxy);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -333,34 +333,34 @@ bool set_cidxdata( box_param_t *cidx_box, index_param_t *jp2idx)
|
||||||
|
|
||||||
if( !search_boxheader( "mhix", manf)){
|
if( !search_boxheader( "mhix", manf)){
|
||||||
fprintf( FCGI_stderr, "Error: mhix box not present in manfbox\n");
|
fprintf( FCGI_stderr, "Error: mhix box not present in manfbox\n");
|
||||||
free(jp2idx);
|
opj_free(jp2idx);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
set_mainmhixdata( cidx_box, codestream, jp2idx);
|
set_mainmhixdata( cidx_box, codestream, jp2idx);
|
||||||
|
|
||||||
if( !search_boxheader( "tpix", manf)){
|
if( !search_boxheader( "tpix", manf)){
|
||||||
fprintf( FCGI_stderr, "Error: tpix box not present in manfbox\n");
|
fprintf( FCGI_stderr, "Error: tpix box not present in manfbox\n");
|
||||||
free(jp2idx);
|
opj_free(jp2idx);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
set_tpixdata( cidx_box, jp2idx);
|
set_tpixdata( cidx_box, jp2idx);
|
||||||
|
|
||||||
if( !search_boxheader( "thix", manf)){
|
if( !search_boxheader( "thix", manf)){
|
||||||
fprintf( FCGI_stderr, "Error: thix box not present in manfbox\n");
|
fprintf( FCGI_stderr, "Error: thix box not present in manfbox\n");
|
||||||
free(jp2idx);
|
opj_free(jp2idx);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
set_thixdata( cidx_box, jp2idx);
|
set_thixdata( cidx_box, jp2idx);
|
||||||
|
|
||||||
if( !search_boxheader( "ppix", manf)){
|
if( !search_boxheader( "ppix", manf)){
|
||||||
fprintf( FCGI_stderr, "Error: ppix box not present in manfbox\n");
|
fprintf( FCGI_stderr, "Error: ppix box not present in manfbox\n");
|
||||||
free(jp2idx);
|
opj_free(jp2idx);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
set_ppixdata( cidx_box, jp2idx);
|
set_ppixdata( cidx_box, jp2idx);
|
||||||
|
|
||||||
delete_manfbox( &manf);
|
delete_manfbox( &manf);
|
||||||
free( manf_box);
|
opj_free( manf_box);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ bool set_cptrdata( box_param_t *cidx_box, index_param_t *jp2idx)
|
||||||
/* 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);
|
opj_free( box);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,14 +386,14 @@ bool set_cptrdata( box_param_t *cidx_box, index_param_t *jp2idx)
|
||||||
/* 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);
|
opj_free( box);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
jp2idx->offset = (OPJ_OFF_T)fetch_DBox8bytebigendian( box, 4);
|
jp2idx->offset = (OPJ_OFF_T)fetch_DBox8bytebigendian( box, 4);
|
||||||
jp2idx->length = fetch_DBox8bytebigendian( box, 12);
|
jp2idx->length = fetch_DBox8bytebigendian( box, 12);
|
||||||
|
|
||||||
free( box);
|
opj_free( box);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -436,7 +436,7 @@ bool set_mainmhixdata( box_param_t *cidx_box, codestream_param_t codestream, ind
|
||||||
jp2idx->mhead_length = fetch_DBox8bytebigendian( mhix_box, 0);
|
jp2idx->mhead_length = fetch_DBox8bytebigendian( mhix_box, 0);
|
||||||
|
|
||||||
mhix = gene_mhixbox( mhix_box);
|
mhix = gene_mhixbox( mhix_box);
|
||||||
free( mhix_box);
|
opj_free( mhix_box);
|
||||||
|
|
||||||
sizmkidx = search_markeridx( 0xff51, mhix);
|
sizmkidx = search_markeridx( 0xff51, mhix);
|
||||||
set_SIZmkrdata( sizmkidx, codestream, &(jp2idx->SIZ));
|
set_SIZmkrdata( sizmkidx, codestream, &(jp2idx->SIZ));
|
||||||
|
@ -466,8 +466,8 @@ bool set_tpixdata( box_param_t *cidx_box, index_param_t *jp2idx)
|
||||||
|
|
||||||
jp2idx->tilepart = gene_faixbox( faix_box);
|
jp2idx->tilepart = gene_faixbox( faix_box);
|
||||||
|
|
||||||
free( tpix_box);
|
opj_free( tpix_box);
|
||||||
free( faix_box);
|
opj_free( faix_box);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -489,7 +489,7 @@ bool set_thixdata( box_param_t *cidx_box, index_param_t *jp2idx)
|
||||||
|
|
||||||
if( !(manf_box = gene_boxbyType( thix_box->fd, get_DBoxoff( thix_box), get_DBoxlen( thix_box), "manf"))){
|
if( !(manf_box = gene_boxbyType( thix_box->fd, get_DBoxoff( thix_box), get_DBoxlen( thix_box), "manf"))){
|
||||||
fprintf( FCGI_stderr, "Error: manf box not present in thix box\n");
|
fprintf( FCGI_stderr, "Error: manf box not present in thix box\n");
|
||||||
free( thix_box);
|
opj_free( thix_box);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,14 +498,14 @@ bool set_thixdata( box_param_t *cidx_box, index_param_t *jp2idx)
|
||||||
mhixseqoff = manf_box->offset+(OPJ_OFF_T)manf_box->length;
|
mhixseqoff = manf_box->offset+(OPJ_OFF_T)manf_box->length;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
tile_no = 0;
|
tile_no = 0;
|
||||||
jp2idx->tileheader = (mhixbox_param_t **)malloc( jp2idx->SIZ.XTnum*jp2idx->SIZ.YTnum*sizeof(mhixbox_param_t *));
|
jp2idx->tileheader = (mhixbox_param_t **)opj_malloc( jp2idx->SIZ.XTnum*jp2idx->SIZ.YTnum*sizeof(mhixbox_param_t *));
|
||||||
|
|
||||||
while( ptr){
|
while( ptr){
|
||||||
if( !(mhix_box = gene_boxbyType( thix_box->fd, mhixseqoff+(OPJ_OFF_T)pos, get_DBoxlen( thix_box)-manf_box->length-pos, "mhix"))){
|
if( !(mhix_box = gene_boxbyType( thix_box->fd, mhixseqoff+(OPJ_OFF_T)pos, get_DBoxlen( thix_box)-manf_box->length-pos, "mhix"))){
|
||||||
fprintf( FCGI_stderr, "Error: mhix box not present in thix box\n");
|
fprintf( FCGI_stderr, "Error: mhix box not present in thix box\n");
|
||||||
delete_manfbox( &manf);
|
delete_manfbox( &manf);
|
||||||
free( manf_box);
|
opj_free( manf_box);
|
||||||
free( thix_box);
|
opj_free( thix_box);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mhix = gene_mhixbox( mhix_box);
|
mhix = gene_mhixbox( mhix_box);
|
||||||
|
@ -513,13 +513,13 @@ bool set_thixdata( box_param_t *cidx_box, index_param_t *jp2idx)
|
||||||
pos += mhix_box->length;
|
pos += mhix_box->length;
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
|
|
||||||
free( mhix_box);
|
opj_free( mhix_box);
|
||||||
jp2idx->tileheader[tile_no++] = mhix;
|
jp2idx->tileheader[tile_no++] = mhix;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_manfbox( &manf);
|
delete_manfbox( &manf);
|
||||||
free( manf_box);
|
opj_free( manf_box);
|
||||||
free( thix_box);
|
opj_free( thix_box);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -541,19 +541,19 @@ bool set_ppixdata( box_param_t *cidx_box, index_param_t *jp2idx)
|
||||||
inbox_offset = get_DBoxoff( ppix_box);
|
inbox_offset = get_DBoxoff( ppix_box);
|
||||||
if( !(manf_box = gene_boxbyType( ppix_box->fd, inbox_offset, get_DBoxlen( ppix_box), "manf"))){
|
if( !(manf_box = gene_boxbyType( ppix_box->fd, inbox_offset, get_DBoxlen( ppix_box), "manf"))){
|
||||||
fprintf( FCGI_stderr, "Error: manf box not present in ppix box\n");
|
fprintf( FCGI_stderr, "Error: manf box not present in ppix box\n");
|
||||||
free( ppix_box);
|
opj_free( ppix_box);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
free( ppix_box);
|
opj_free( ppix_box);
|
||||||
|
|
||||||
manf = gene_manfbox( manf_box);
|
manf = gene_manfbox( manf_box);
|
||||||
bh = search_boxheader( "faix", manf);
|
bh = search_boxheader( "faix", manf);
|
||||||
inbox_offset = manf_box->offset + (OPJ_OFF_T)manf_box->length;
|
inbox_offset = manf_box->offset + (OPJ_OFF_T)manf_box->length;
|
||||||
|
|
||||||
free( manf_box);
|
opj_free( manf_box);
|
||||||
|
|
||||||
jp2idx->precpacket = (faixbox_param_t **)malloc( jp2idx->SIZ.Csiz*sizeof(faixbox_param_t *));
|
jp2idx->precpacket = (faixbox_param_t **)opj_malloc( jp2idx->SIZ.Csiz*sizeof(faixbox_param_t *));
|
||||||
|
|
||||||
for( comp_idx=0; bh!=NULL; bh=bh->next, comp_idx++){
|
for( comp_idx=0; bh!=NULL; bh=bh->next, comp_idx++){
|
||||||
if( jp2idx->SIZ.Csiz <= comp_idx ){
|
if( jp2idx->SIZ.Csiz <= comp_idx ){
|
||||||
|
@ -570,7 +570,7 @@ bool set_ppixdata( box_param_t *cidx_box, index_param_t *jp2idx)
|
||||||
jp2idx->precpacket[comp_idx] = faix;
|
jp2idx->precpacket[comp_idx] = faix;
|
||||||
|
|
||||||
inbox_offset = faix_box->offset + (OPJ_OFF_T)faix_box->length;
|
inbox_offset = faix_box->offset + (OPJ_OFF_T)faix_box->length;
|
||||||
free( faix_box);
|
opj_free( faix_box);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_manfbox( &manf);
|
delete_manfbox( &manf);
|
||||||
|
@ -634,8 +634,8 @@ bool set_CODmkrdata( markeridx_param_t *codmkidx, codestream_param_t codestream,
|
||||||
COD->numOfdecomp = fetch_marker1byte( codmkr, 7);
|
COD->numOfdecomp = fetch_marker1byte( codmkr, 7);
|
||||||
|
|
||||||
if(COD->Scod & 0x01){
|
if(COD->Scod & 0x01){
|
||||||
COD->XPsiz = (Byte4_t *)malloc( (OPJ_SIZE_T)(COD->numOfdecomp+1)*sizeof(Byte4_t));
|
COD->XPsiz = (Byte4_t *)opj_malloc( (OPJ_SIZE_T)(COD->numOfdecomp+1)*sizeof(Byte4_t));
|
||||||
COD->YPsiz = (Byte4_t *)malloc( (OPJ_SIZE_T)(COD->numOfdecomp+1)*sizeof(Byte4_t));
|
COD->YPsiz = (Byte4_t *)opj_malloc( (OPJ_SIZE_T)(COD->numOfdecomp+1)*sizeof(Byte4_t));
|
||||||
|
|
||||||
for( i=0; i<=COD->numOfdecomp; i++){
|
for( i=0; i<=COD->numOfdecomp; i++){
|
||||||
/*precinct size*/
|
/*precinct size*/
|
||||||
|
@ -644,8 +644,8 @@ bool set_CODmkrdata( markeridx_param_t *codmkidx, codestream_param_t codestream,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
COD->XPsiz = (Byte4_t *)malloc( sizeof(Byte4_t));
|
COD->XPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t));
|
||||||
COD->YPsiz = (Byte4_t *)malloc( sizeof(Byte4_t));
|
COD->YPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t));
|
||||||
|
|
||||||
COD->XPsiz[0] = COD->YPsiz[0] = pow(2,15);
|
COD->XPsiz[0] = COD->YPsiz[0] = pow(2,15);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
#ifndef INDEX_MANAGER_H_
|
#ifndef INDEX_MANAGER_H_
|
||||||
# define INDEX_MANAGER_H_
|
# define INDEX_MANAGER_H_
|
||||||
|
|
||||||
|
#include "opj_config.h"
|
||||||
|
#include "opj_includes.h"
|
||||||
|
|
||||||
#include "byte_manager.h"
|
#include "byte_manager.h"
|
||||||
#include "faixbox_manager.h"
|
#include "faixbox_manager.h"
|
||||||
#include "metadata_manager.h"
|
#include "metadata_manager.h"
|
||||||
|
@ -38,6 +41,7 @@
|
||||||
#include "bool.h"
|
#include "bool.h"
|
||||||
|
|
||||||
/** progression order */
|
/** progression order */
|
||||||
|
#if 0
|
||||||
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 */
|
||||||
|
@ -46,6 +50,7 @@ typedef enum porder {
|
||||||
PCRL = 3, /**< precinct-component-resolution-layer order */
|
PCRL = 3, /**< precinct-component-resolution-layer order */
|
||||||
CPRL = 4 /**< component-precinct-resolution-layer order */
|
CPRL = 4 /**< component-precinct-resolution-layer order */
|
||||||
} porder_t;
|
} porder_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
/** A.5.1 Image and tile size (SIZ)*/
|
/** A.5.1 Image and tile size (SIZ)*/
|
||||||
typedef struct SIZmarker_param{
|
typedef struct SIZmarker_param{
|
||||||
|
@ -71,7 +76,7 @@ typedef struct SIZmarker_param{
|
||||||
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*/
|
OPJ_PROG_ORDER 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*/
|
||||||
|
|
|
@ -127,8 +127,8 @@ CODmarker_param_t get_CODmkrdata_from_j2kstream( Byte_t *CODstream)
|
||||||
COD.numOfdecomp = *( CODstream+7);
|
COD.numOfdecomp = *( CODstream+7);
|
||||||
|
|
||||||
if(COD.Scod & 0x01){
|
if(COD.Scod & 0x01){
|
||||||
COD.XPsiz = (Byte4_t *)malloc( (OPJ_SIZE_T)(COD.numOfdecomp+1)*sizeof(Byte4_t));
|
COD.XPsiz = (Byte4_t *)opj_malloc( (OPJ_SIZE_T)(COD.numOfdecomp+1)*sizeof(Byte4_t));
|
||||||
COD.YPsiz = (Byte4_t *)malloc( (OPJ_SIZE_T)(COD.numOfdecomp+1)*sizeof(Byte4_t));
|
COD.YPsiz = (Byte4_t *)opj_malloc( (OPJ_SIZE_T)(COD.numOfdecomp+1)*sizeof(Byte4_t));
|
||||||
|
|
||||||
for( i=0; i<=COD.numOfdecomp; i++){
|
for( i=0; i<=COD.numOfdecomp; i++){
|
||||||
/*precinct size */
|
/*precinct size */
|
||||||
|
@ -137,8 +137,8 @@ CODmarker_param_t get_CODmkrdata_from_j2kstream( Byte_t *CODstream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
COD.XPsiz = (Byte4_t *)malloc( sizeof(Byte4_t));
|
COD.XPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t));
|
||||||
COD.YPsiz = (Byte4_t *)malloc( sizeof(Byte4_t));
|
COD.YPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t));
|
||||||
COD.XPsiz[0] = COD.YPsiz[0] = pow(2,15);
|
COD.XPsiz[0] = COD.YPsiz[0] = pow(2,15);
|
||||||
}
|
}
|
||||||
return COD;
|
return COD;
|
||||||
|
|
|
@ -122,7 +122,7 @@ Byte_t * recons_jp2( msgqueue_param_t *msgqueue, Byte_t *jpipstream, Byte8_t csn
|
||||||
if( jp2cDBoxOffset != 0 && codelen <= jp2cDBoxlen)
|
if( jp2cDBoxOffset != 0 && codelen <= jp2cDBoxlen)
|
||||||
memcpy( jp2stream+jp2cDBoxOffset, codestream, codelen);
|
memcpy( jp2stream+jp2cDBoxOffset, codestream, codelen);
|
||||||
|
|
||||||
free( codestream);
|
opj_free( codestream);
|
||||||
|
|
||||||
return jp2stream;
|
return jp2stream;
|
||||||
}
|
}
|
||||||
|
@ -314,14 +314,14 @@ Byte_t * add_SOTmkr( Byte_t *j2kstream, Byte8_t *j2klen)
|
||||||
Byte_t *buf;
|
Byte_t *buf;
|
||||||
const Byte2_t SOT = 0x90ff;
|
const Byte2_t SOT = 0x90ff;
|
||||||
|
|
||||||
buf = (Byte_t *)malloc(( *j2klen)+2);
|
buf = (Byte_t *)opj_malloc(( *j2klen)+2);
|
||||||
|
|
||||||
memcpy( buf, j2kstream, *j2klen);
|
memcpy( buf, j2kstream, *j2klen);
|
||||||
memcpy( buf+(*j2klen), &SOT, 2);
|
memcpy( buf+(*j2klen), &SOT, 2);
|
||||||
|
|
||||||
*j2klen += 2;
|
*j2klen += 2;
|
||||||
|
|
||||||
if(j2kstream) free(j2kstream);
|
if(j2kstream) opj_free(j2kstream);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -660,15 +660,15 @@ Byte_t * add_msgstream( message_param_t *message, Byte_t *origstream, Byte_t *j2
|
||||||
|
|
||||||
newstream = gene_msgstream( message, origstream, &newlen);
|
newstream = gene_msgstream( message, origstream, &newlen);
|
||||||
|
|
||||||
buf = (Byte_t *)malloc(( *j2klen)+newlen);
|
buf = (Byte_t *)opj_malloc(( *j2klen)+newlen);
|
||||||
|
|
||||||
memcpy( buf, j2kstream, *j2klen);
|
memcpy( buf, j2kstream, *j2klen);
|
||||||
memcpy( buf+(*j2klen), newstream, newlen);
|
memcpy( buf+(*j2klen), newstream, newlen);
|
||||||
|
|
||||||
*j2klen += newlen;
|
*j2klen += newlen;
|
||||||
|
|
||||||
free( newstream);
|
opj_free( newstream);
|
||||||
if(j2kstream) free(j2kstream);
|
if(j2kstream) opj_free(j2kstream);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -685,19 +685,19 @@ Byte_t * add_emptyboxstream( placeholder_param_t *phld, Byte_t *jp2stream, Byte8
|
||||||
else
|
else
|
||||||
newlen = big8(phld->OrigBH+8);
|
newlen = big8(phld->OrigBH+8);
|
||||||
|
|
||||||
newstream = (Byte_t *)malloc( newlen);
|
newstream = (Byte_t *)opj_malloc( newlen);
|
||||||
memset( newstream, 0, newlen);
|
memset( newstream, 0, newlen);
|
||||||
memcpy( newstream, phld->OrigBH, phld->OrigBHlen);
|
memcpy( newstream, phld->OrigBH, phld->OrigBHlen);
|
||||||
|
|
||||||
buf = (Byte_t *)malloc(( *jp2len)+newlen);
|
buf = (Byte_t *)opj_malloc(( *jp2len)+newlen);
|
||||||
|
|
||||||
memcpy( buf, jp2stream, *jp2len);
|
memcpy( buf, jp2stream, *jp2len);
|
||||||
memcpy( buf+(*jp2len), newstream, newlen);
|
memcpy( buf+(*jp2len), newstream, newlen);
|
||||||
|
|
||||||
*jp2len += newlen;
|
*jp2len += newlen;
|
||||||
|
|
||||||
free( newstream);
|
opj_free( newstream);
|
||||||
if(jp2stream) free(jp2stream);
|
if(jp2stream) opj_free(jp2stream);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -710,15 +710,15 @@ Byte_t * add_emptytilestream( const Byte8_t tileID, Byte_t *j2kstream, Byte8_t *
|
||||||
|
|
||||||
newstream = gene_emptytilestream( tileID, &newlen);
|
newstream = gene_emptytilestream( tileID, &newlen);
|
||||||
|
|
||||||
buf = (Byte_t *)malloc(( *j2klen)+newlen);
|
buf = (Byte_t *)opj_malloc(( *j2klen)+newlen);
|
||||||
|
|
||||||
memcpy( buf, j2kstream, *j2klen);
|
memcpy( buf, j2kstream, *j2klen);
|
||||||
memcpy( buf+(*j2klen), newstream, newlen);
|
memcpy( buf+(*j2klen), newstream, newlen);
|
||||||
|
|
||||||
*j2klen += newlen;
|
*j2klen += newlen;
|
||||||
|
|
||||||
free( newstream);
|
opj_free( newstream);
|
||||||
if(j2kstream) free(j2kstream);
|
if(j2kstream) opj_free(j2kstream);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -727,14 +727,14 @@ Byte_t * add_padding( Byte8_t padding, Byte_t *j2kstream, Byte8_t *j2klen)
|
||||||
{
|
{
|
||||||
Byte_t *buf;
|
Byte_t *buf;
|
||||||
|
|
||||||
buf = (Byte_t *)malloc(( *j2klen)+padding);
|
buf = (Byte_t *)opj_malloc(( *j2klen)+padding);
|
||||||
|
|
||||||
memcpy( buf, j2kstream, *j2klen);
|
memcpy( buf, j2kstream, *j2klen);
|
||||||
memset( buf+(*j2klen), 0, padding);
|
memset( buf+(*j2klen), 0, padding);
|
||||||
|
|
||||||
*j2klen += padding;
|
*j2klen += padding;
|
||||||
|
|
||||||
if(j2kstream) free(j2kstream);
|
if(j2kstream) opj_free(j2kstream);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -745,14 +745,14 @@ Byte_t * add_EOC( Byte_t *j2kstream, Byte8_t *j2klen)
|
||||||
|
|
||||||
Byte_t *buf;
|
Byte_t *buf;
|
||||||
|
|
||||||
buf = (Byte_t *)malloc(( *j2klen)+2);
|
buf = (Byte_t *)opj_malloc(( *j2klen)+2);
|
||||||
|
|
||||||
memcpy( buf, j2kstream, *j2klen);
|
memcpy( buf, j2kstream, *j2klen);
|
||||||
memcpy( buf+(*j2klen), &EOC, 2);
|
memcpy( buf+(*j2klen), &EOC, 2);
|
||||||
|
|
||||||
*j2klen += 2;
|
*j2klen += 2;
|
||||||
|
|
||||||
if(j2kstream) free(j2kstream);
|
if(j2kstream) opj_free(j2kstream);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -765,7 +765,7 @@ Byte_t * gene_msgstream( message_param_t *message, Byte_t *stream, Byte8_t *leng
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
*length = message->length;
|
*length = message->length;
|
||||||
buf = (Byte_t *)malloc( *length);
|
buf = (Byte_t *)opj_malloc( *length);
|
||||||
memcpy( buf, stream+message->res_offset, *length);
|
memcpy( buf, stream+message->res_offset, *length);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
|
@ -782,7 +782,7 @@ Byte_t * gene_emptytilestream( const Byte8_t tileID, Byte8_t *length)
|
||||||
const Byte2_t SOD = 0x93ff;
|
const Byte2_t SOD = 0x93ff;
|
||||||
|
|
||||||
*length = 14;
|
*length = 14;
|
||||||
buf = (Byte_t *)malloc(*length);
|
buf = (Byte_t *)opj_malloc(*length);
|
||||||
|
|
||||||
Isot = (Byte2_t)((((Byte2_t)tileID) << 8) | ((((Byte2_t)tileID) & 0xf0) >> 8));
|
Isot = (Byte2_t)((((Byte2_t)tileID) << 8) | ((((Byte2_t)tileID) & 0xf0) >> 8));
|
||||||
|
|
||||||
|
|
|
@ -40,14 +40,14 @@
|
||||||
|
|
||||||
Byte_t * update_JPIPstream( Byte_t *newstream, OPJ_SIZE_T newstreamlen, Byte_t *cache_stream, OPJ_SIZE_T *streamlen)
|
Byte_t * update_JPIPstream( Byte_t *newstream, OPJ_SIZE_T newstreamlen, Byte_t *cache_stream, OPJ_SIZE_T *streamlen)
|
||||||
{
|
{
|
||||||
Byte_t *stream = (Byte_t *)malloc( (*streamlen)+newstreamlen);
|
Byte_t *stream = (Byte_t *)opj_malloc( (*streamlen)+newstreamlen);
|
||||||
if( *streamlen > 0)
|
if( *streamlen > 0)
|
||||||
memcpy( stream, cache_stream, *streamlen);
|
memcpy( stream, cache_stream, *streamlen);
|
||||||
memcpy( stream+(*streamlen), newstream, newstreamlen);
|
memcpy( stream+(*streamlen), newstream, newstreamlen);
|
||||||
*streamlen += newstreamlen;
|
*streamlen += newstreamlen;
|
||||||
|
|
||||||
if(cache_stream)
|
if(cache_stream)
|
||||||
free( cache_stream);
|
opj_free( cache_stream);
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte
|
||||||
|
|
||||||
fp = fopen( j2kfname, "w+b");
|
fp = fopen( j2kfname, "w+b");
|
||||||
fwrite( j2kstream, j2klen, 1, fp);
|
fwrite( j2kstream, j2klen, 1, fp);
|
||||||
free( j2kstream);
|
opj_free( j2kstream);
|
||||||
fseek( fp, 0, SEEK_SET);
|
fseek( fp, 0, SEEK_SET);
|
||||||
|
|
||||||
pnmstream = j2k_to_pnm( fp, ihdrbox);
|
pnmstream = j2k_to_pnm( fp, ihdrbox);
|
||||||
|
@ -103,18 +103,18 @@ ihdrbox_param_t * get_SIZ_from_jpipstream( Byte_t *jpipstream, msgqueue_param_t
|
||||||
|
|
||||||
j2kstream = recons_j2kmainhead( msgqueue, jpipstream, csn, &j2klen);
|
j2kstream = recons_j2kmainhead( msgqueue, jpipstream, csn, &j2klen);
|
||||||
if( !get_mainheader_from_j2kstream( j2kstream, &SIZ, NULL)){
|
if( !get_mainheader_from_j2kstream( j2kstream, &SIZ, NULL)){
|
||||||
free( j2kstream);
|
opj_free( j2kstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ihdrbox = (ihdrbox_param_t *)malloc( sizeof(ihdrbox_param_t));
|
ihdrbox = (ihdrbox_param_t *)opj_malloc( sizeof(ihdrbox_param_t));
|
||||||
|
|
||||||
ihdrbox->width = SIZ.Xsiz;
|
ihdrbox->width = SIZ.Xsiz;
|
||||||
ihdrbox->height = SIZ.Ysiz;
|
ihdrbox->height = SIZ.Ysiz;
|
||||||
ihdrbox->nc = SIZ.Csiz;
|
ihdrbox->nc = SIZ.Csiz;
|
||||||
ihdrbox->bpc = SIZ.Ssiz[0];
|
ihdrbox->bpc = SIZ.Ssiz[0];
|
||||||
|
|
||||||
free( j2kstream);
|
opj_free( j2kstream);
|
||||||
|
|
||||||
return ihdrbox;
|
return ihdrbox;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ msgqueue_param_t * gene_msgqueue( bool stateless, cachemodel_param_t *cachemodel
|
||||||
{
|
{
|
||||||
msgqueue_param_t *msgqueue;
|
msgqueue_param_t *msgqueue;
|
||||||
|
|
||||||
msgqueue = (msgqueue_param_t *)malloc( sizeof(msgqueue_param_t));
|
msgqueue = (msgqueue_param_t *)opj_malloc( sizeof(msgqueue_param_t));
|
||||||
|
|
||||||
msgqueue->first = NULL;
|
msgqueue->first = NULL;
|
||||||
msgqueue->last = NULL;
|
msgqueue->last = NULL;
|
||||||
|
@ -82,13 +82,13 @@ void delete_msgqueue( msgqueue_param_t **msgqueue)
|
||||||
|
|
||||||
while( ptr){
|
while( ptr){
|
||||||
next = ptr->next;
|
next = ptr->next;
|
||||||
free( ptr);
|
opj_free( ptr);
|
||||||
ptr = next;
|
ptr = next;
|
||||||
}
|
}
|
||||||
if( (*msgqueue)->stateless && (*msgqueue)->cachemodel)
|
if( (*msgqueue)->stateless && (*msgqueue)->cachemodel)
|
||||||
delete_cachemodel( &((*msgqueue)->cachemodel));
|
delete_cachemodel( &((*msgqueue)->cachemodel));
|
||||||
|
|
||||||
free(*msgqueue);
|
opj_free(*msgqueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_msgqueue( msgqueue_param_t *msgqueue)
|
void print_msgqueue( msgqueue_param_t *msgqueue)
|
||||||
|
@ -135,7 +135,7 @@ void enqueue_mainheader( msgqueue_param_t *msgqueue)
|
||||||
target = cachemodel->target;
|
target = cachemodel->target;
|
||||||
codeidx = target->codeidx;
|
codeidx = target->codeidx;
|
||||||
|
|
||||||
msg = (message_param_t *)malloc( sizeof(message_param_t));
|
msg = (message_param_t *)opj_malloc( sizeof(message_param_t));
|
||||||
|
|
||||||
msg->last_byte = true;
|
msg->last_byte = true;
|
||||||
msg->in_class_id = 0;
|
msg->in_class_id = 0;
|
||||||
|
@ -166,7 +166,7 @@ void enqueue_tileheader( int tile_id, msgqueue_param_t *msgqueue)
|
||||||
codeidx = target->codeidx;
|
codeidx = target->codeidx;
|
||||||
|
|
||||||
if( !cachemodel->th_model[ tile_id]){
|
if( !cachemodel->th_model[ tile_id]){
|
||||||
msg = (message_param_t *)malloc( sizeof(message_param_t));
|
msg = (message_param_t *)opj_malloc( sizeof(message_param_t));
|
||||||
msg->last_byte = true;
|
msg->last_byte = true;
|
||||||
assert( tile_id >= 0 );
|
assert( tile_id >= 0 );
|
||||||
msg->in_class_id = (Byte8_t)tile_id;
|
msg->in_class_id = (Byte8_t)tile_id;
|
||||||
|
@ -220,7 +220,7 @@ void enqueue_tile( Byte4_t tile_id, int level, msgqueue_param_t *msgqueue)
|
||||||
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 *)opj_malloc( sizeof(message_param_t));
|
||||||
|
|
||||||
msg->last_byte = (i==numOftparts-1);
|
msg->last_byte = (i==numOftparts-1);
|
||||||
msg->in_class_id = tile_id;
|
msg->in_class_id = tile_id;
|
||||||
|
@ -269,7 +269,7 @@ void enqueue_precinct( int seq_id, int tile_id, int comp_id, int layers, msgqueu
|
||||||
|
|
||||||
if( !cachemodel->pp_model[comp_id][tile_id*(int)nmax+seq_id*numOflayers+layer_id]){
|
if( !cachemodel->pp_model[comp_id][tile_id*(int)nmax+seq_id*numOflayers+layer_id]){
|
||||||
|
|
||||||
msg = (message_param_t *)malloc( sizeof(message_param_t));
|
msg = (message_param_t *)opj_malloc( sizeof(message_param_t));
|
||||||
msg->last_byte = (layer_id == (numOflayers-1));
|
msg->last_byte = (layer_id == (numOflayers-1));
|
||||||
msg->in_class_id = comp_precinct_id( tile_id, comp_id, seq_id, codeidx->SIZ.Csiz, (int)codeidx->SIZ.XTnum * (int) codeidx->SIZ.YTnum);
|
msg->in_class_id = comp_precinct_id( tile_id, comp_id, seq_id, codeidx->SIZ.Csiz, (int)codeidx->SIZ.XTnum * (int) codeidx->SIZ.YTnum);
|
||||||
msg->class_id = PRECINCT_MSG;
|
msg->class_id = PRECINCT_MSG;
|
||||||
|
@ -376,7 +376,7 @@ message_param_t * gene_metamsg( Byte8_t meta_id, Byte8_t binOffset, Byte8_t leng
|
||||||
{
|
{
|
||||||
message_param_t *msg;
|
message_param_t *msg;
|
||||||
|
|
||||||
msg = (message_param_t *)malloc( sizeof(message_param_t));
|
msg = (message_param_t *)opj_malloc( sizeof(message_param_t));
|
||||||
|
|
||||||
msg->last_byte = false;
|
msg->last_byte = false;
|
||||||
msg->in_class_id = meta_id;
|
msg->in_class_id = meta_id;
|
||||||
|
@ -521,11 +521,11 @@ void add_body_stream( message_param_t *msg, int fd, int tmpfd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if( write( tmpfd, data, msg->length) < 1){
|
if( write( tmpfd, data, msg->length) < 1){
|
||||||
free( data);
|
opj_free( data);
|
||||||
fprintf( FCGI_stderr, "Error: fwrite in add_body_stream()\n");
|
fprintf( FCGI_stderr, "Error: fwrite in add_body_stream()\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
free(data);
|
opj_free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_bigendian_bytestream( Byte8_t code, int bytelength, int tmpfd);
|
void add_bigendian_bytestream( Byte8_t code, int bytelength, int tmpfd);
|
||||||
|
@ -596,7 +596,7 @@ void parse_JPIPstream( Byte_t *JPIPstream, Byte8_t streamlen, OPJ_OFF_T offset,
|
||||||
csn = (Byte8_t)-1;
|
csn = (Byte8_t)-1;
|
||||||
ptr = JPIPstream;
|
ptr = JPIPstream;
|
||||||
while( (Byte8_t)(ptr-JPIPstream) < streamlen){
|
while( (Byte8_t)(ptr-JPIPstream) < streamlen){
|
||||||
msg = (message_param_t *)malloc( sizeof(message_param_t));
|
msg = (message_param_t *)opj_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);
|
||||||
|
|
||||||
|
@ -689,14 +689,14 @@ placeholder_param_t * parse_phld( Byte_t *datastream, Byte8_t metalength)
|
||||||
{
|
{
|
||||||
placeholder_param_t *phld;
|
placeholder_param_t *phld;
|
||||||
|
|
||||||
phld = (placeholder_param_t *)malloc( sizeof(placeholder_param_t));
|
phld = (placeholder_param_t *)opj_malloc( sizeof(placeholder_param_t));
|
||||||
|
|
||||||
phld->LBox = big4( datastream);
|
phld->LBox = big4( datastream);
|
||||||
strcpy( phld->TBox, "phld");
|
strcpy( phld->TBox, "phld");
|
||||||
phld->Flags = big4( datastream+8);
|
phld->Flags = big4( datastream+8);
|
||||||
phld->OrigID = big8( datastream+12);
|
phld->OrigID = big8( datastream+12);
|
||||||
phld->OrigBHlen = (Byte_t)(metalength - 20);
|
phld->OrigBHlen = (Byte_t)(metalength - 20);
|
||||||
phld->OrigBH = (Byte_t *)malloc(phld->OrigBHlen);
|
phld->OrigBH = (Byte_t *)opj_malloc(phld->OrigBHlen);
|
||||||
memcpy( phld->OrigBH, datastream+20, phld->OrigBHlen);
|
memcpy( phld->OrigBH, datastream+20, phld->OrigBHlen);
|
||||||
phld->next = NULL;
|
phld->next = NULL;
|
||||||
|
|
||||||
|
@ -758,5 +758,5 @@ void delete_message_in_msgqueue( message_param_t **msg, msgqueue_param_t *msgque
|
||||||
if( *msg == msgqueue->last)
|
if( *msg == msgqueue->last)
|
||||||
msgqueue->last = ptr;
|
msgqueue->last = ptr;
|
||||||
}
|
}
|
||||||
free( *msg);
|
opj_free( *msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
|
|
||||||
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 *)opj_malloc( sizeof(server_record_t));
|
||||||
|
|
||||||
record->sessionlist = gene_sessionlist();
|
record->sessionlist = gene_sessionlist();
|
||||||
record->targetlist = gene_targetlist();
|
record->targetlist = gene_targetlist();
|
||||||
|
@ -72,14 +72,14 @@ void terminate_JPIPserver( server_record_t **rec)
|
||||||
delete_targetlist( &(*rec)->targetlist);
|
delete_targetlist( &(*rec)->targetlist);
|
||||||
close_aux_transport( (*rec)->auxtrans);
|
close_aux_transport( (*rec)->auxtrans);
|
||||||
|
|
||||||
free( *rec);
|
opj_free( *rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
QR_t * parse_querystring( const char *query_string)
|
QR_t * parse_querystring( const char *query_string)
|
||||||
{
|
{
|
||||||
QR_t *qr;
|
QR_t *qr;
|
||||||
|
|
||||||
qr = (QR_t *)malloc( sizeof(QR_t));
|
qr = (QR_t *)opj_malloc( sizeof(QR_t));
|
||||||
|
|
||||||
qr->query = parse_query( query_string);
|
qr->query = parse_query( query_string);
|
||||||
qr->msgqueue = NULL;
|
qr->msgqueue = NULL;
|
||||||
|
@ -162,7 +162,7 @@ void send_responsedata( server_record_t *rec, QR_t *qr)
|
||||||
fprintf( FCGI_stderr, "Error: failed to write jpipstream\n");
|
fprintf( FCGI_stderr, "Error: failed to write jpipstream\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
free( jpipstream);
|
opj_free( jpipstream);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ void end_QRprocess( server_record_t *rec, QR_t **qr)
|
||||||
(void)rec; /* unused */
|
(void)rec; /* unused */
|
||||||
delete_query( &((*qr)->query));
|
delete_query( &((*qr)->query));
|
||||||
delete_msgqueue( &((*qr)->msgqueue));
|
delete_msgqueue( &((*qr)->msgqueue));
|
||||||
free( *qr);
|
opj_free( *qr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr
|
||||||
|
|
||||||
dec_server_record_t * init_dec_server( int port)
|
dec_server_record_t * init_dec_server( int port)
|
||||||
{
|
{
|
||||||
dec_server_record_t *record = (dec_server_record_t *)malloc( sizeof(dec_server_record_t));
|
dec_server_record_t *record = (dec_server_record_t *)opj_malloc( sizeof(dec_server_record_t));
|
||||||
|
|
||||||
record->cachelist = gene_cachelist();
|
record->cachelist = gene_cachelist();
|
||||||
record->jpipstream = NULL;
|
record->jpipstream = NULL;
|
||||||
|
@ -225,7 +225,7 @@ dec_server_record_t * init_dec_server( int port)
|
||||||
void terminate_dec_server( dec_server_record_t **rec)
|
void terminate_dec_server( dec_server_record_t **rec)
|
||||||
{
|
{
|
||||||
delete_cachelist( &(*rec)->cachelist);
|
delete_cachelist( &(*rec)->cachelist);
|
||||||
free( (*rec)->jpipstream);
|
opj_free( (*rec)->jpipstream);
|
||||||
|
|
||||||
if( (*rec)->msgqueue)
|
if( (*rec)->msgqueue)
|
||||||
delete_msgqueue( &((*rec)->msgqueue));
|
delete_msgqueue( &((*rec)->msgqueue));
|
||||||
|
@ -233,7 +233,7 @@ void terminate_dec_server( dec_server_record_t **rec)
|
||||||
if( close_socket( (*rec)->listening_socket) != 0)
|
if( close_socket( (*rec)->listening_socket) != 0)
|
||||||
perror("close");
|
perror("close");
|
||||||
|
|
||||||
free( *rec);
|
opj_free( *rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
client_t accept_connection( dec_server_record_t *rec)
|
client_t accept_connection( dec_server_record_t *rec)
|
||||||
|
@ -310,7 +310,7 @@ jpip_dec_param_t * init_jpipdecoder( bool jp2)
|
||||||
{
|
{
|
||||||
jpip_dec_param_t *dec;
|
jpip_dec_param_t *dec;
|
||||||
|
|
||||||
dec = (jpip_dec_param_t *)calloc( 1, sizeof(jpip_dec_param_t));
|
dec = (jpip_dec_param_t *)opj_calloc( 1, sizeof(jpip_dec_param_t));
|
||||||
|
|
||||||
dec->msgqueue = gene_msgqueue( true, NULL);
|
dec->msgqueue = gene_msgqueue( true, NULL);
|
||||||
|
|
||||||
|
@ -333,11 +333,11 @@ bool fread_jpip( const char fname[], jpip_dec_param_t *dec)
|
||||||
if(!(dec->jpiplen = (Byte8_t)get_filesize(infd)))
|
if(!(dec->jpiplen = (Byte8_t)get_filesize(infd)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
dec->jpipstream = (Byte_t *)malloc( dec->jpiplen);
|
dec->jpipstream = (Byte_t *)opj_malloc( dec->jpiplen);
|
||||||
|
|
||||||
if( read( infd, dec->jpipstream, dec->jpiplen) != (int)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);
|
opj_free( dec->jpipstream);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,15 +398,15 @@ void output_log( bool messages, bool metadata, bool ihdrbox, jpip_dec_param_t *d
|
||||||
|
|
||||||
void destroy_jpipdecoder( jpip_dec_param_t **dec)
|
void destroy_jpipdecoder( jpip_dec_param_t **dec)
|
||||||
{
|
{
|
||||||
free( (*dec)->jpipstream);
|
opj_free( (*dec)->jpipstream);
|
||||||
delete_msgqueue( &(*dec)->msgqueue);
|
delete_msgqueue( &(*dec)->msgqueue);
|
||||||
if( (*dec)->metadatalist){
|
if( (*dec)->metadatalist){
|
||||||
delete_metadatalist( &(*dec)->metadatalist);
|
delete_metadatalist( &(*dec)->metadatalist);
|
||||||
free( (*dec)->ihdrbox);
|
opj_free( (*dec)->ihdrbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
free( (*dec)->jp2kstream);
|
opj_free( (*dec)->jp2kstream);
|
||||||
free( *dec);
|
opj_free( *dec);
|
||||||
}
|
}
|
||||||
|
|
||||||
index_t * get_index_from_JP2file( int fd)
|
index_t * get_index_from_JP2file( int fd)
|
||||||
|
@ -419,20 +419,20 @@ index_t * get_index_from_JP2file( int fd)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = (char *)malloc( 12); /* size of header*/
|
data = (char *)opj_malloc( 12); /* size of header*/
|
||||||
if( read( fd, data, 12) != 12){
|
if( read( fd, data, 12) != 12){
|
||||||
free( data);
|
opj_free( data);
|
||||||
fprintf( stderr, "Error: File broken (read error)\n");
|
fprintf( stderr, "Error: File broken (read error)\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( *data || *(data + 1) || *(data + 2) ||
|
if( *data || *(data + 1) || *(data + 2) ||
|
||||||
*(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
|
*(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
|
||||||
free( data);
|
opj_free( data);
|
||||||
fprintf( stderr, "Error: No JPEG 2000 Signature box in this file\n");
|
fprintf( stderr, "Error: No JPEG 2000 Signature box in this file\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
free( data);
|
opj_free( data);
|
||||||
|
|
||||||
return parse_jp2file( fd);
|
return parse_jp2file( fd);
|
||||||
}
|
}
|
||||||
|
@ -447,4 +447,731 @@ void output_index( index_t *index)
|
||||||
print_index( *index);
|
print_index( *index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
/* COMPRESSION FUNCTIONS*/
|
||||||
|
typedef struct opj_decompression
|
||||||
|
{
|
||||||
|
/** Main header reading function handler*/
|
||||||
|
opj_bool (*opj_read_header) ( struct opj_stream_private * cio,
|
||||||
|
void * p_codec,
|
||||||
|
opj_image_t **p_image,
|
||||||
|
struct opj_event_mgr * p_manager);
|
||||||
|
/** Decoding function */
|
||||||
|
opj_bool (*opj_decode) ( void * p_codec,
|
||||||
|
struct opj_stream_private *p_cio,
|
||||||
|
opj_image_t *p_image,
|
||||||
|
struct opj_event_mgr * p_manager);
|
||||||
|
/** FIXME DOC */
|
||||||
|
opj_bool (*opj_read_tile_header)( void * p_codec,
|
||||||
|
OPJ_UINT32 * p_tile_index,
|
||||||
|
OPJ_UINT32* p_data_size,
|
||||||
|
OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
|
||||||
|
OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
|
||||||
|
OPJ_UINT32 * p_nb_comps,
|
||||||
|
opj_bool * p_should_go_on,
|
||||||
|
struct opj_stream_private *p_cio,
|
||||||
|
struct opj_event_mgr * p_manager);
|
||||||
|
/** FIXME DOC */
|
||||||
|
opj_bool (*opj_decode_tile_data)( void * p_codec,
|
||||||
|
OPJ_UINT32 p_tile_index,
|
||||||
|
OPJ_BYTE * p_data,
|
||||||
|
OPJ_UINT32 p_data_size,
|
||||||
|
struct opj_stream_private *p_cio,
|
||||||
|
struct opj_event_mgr * p_manager);
|
||||||
|
/** Reading function used after codestream if necessary */
|
||||||
|
opj_bool (* opj_end_decompress) ( void *p_codec,
|
||||||
|
struct opj_stream_private *cio,
|
||||||
|
struct opj_event_mgr * p_manager);
|
||||||
|
/** Codec destroy function handler*/
|
||||||
|
void (*opj_destroy) (void * p_codec);
|
||||||
|
/** Setup decoder function handler */
|
||||||
|
void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param);
|
||||||
|
/** Set decode area function handler */
|
||||||
|
opj_bool (*opj_set_decode_area) ( void * p_codec,
|
||||||
|
opj_image_t* p_image,
|
||||||
|
OPJ_INT32 p_start_x, OPJ_INT32 p_end_x,
|
||||||
|
OPJ_INT32 p_start_y, OPJ_INT32 p_end_y,
|
||||||
|
struct opj_event_mgr * p_manager);
|
||||||
|
|
||||||
|
/** Get tile function */
|
||||||
|
opj_bool (*opj_get_decoded_tile) ( void *p_codec,
|
||||||
|
opj_stream_private_t *p_cio,
|
||||||
|
opj_image_t *p_image,
|
||||||
|
struct opj_event_mgr * p_manager,
|
||||||
|
OPJ_UINT32 tile_index);
|
||||||
|
|
||||||
|
/** Set the decoded resolution factor */
|
||||||
|
opj_bool (*opj_set_decoded_resolution_factor) ( void * p_codec,
|
||||||
|
OPJ_UINT32 res_factor,
|
||||||
|
opj_event_mgr_t * p_manager);
|
||||||
|
|
||||||
|
}opj_decompression_t;
|
||||||
|
|
||||||
|
typedef struct opj_compression
|
||||||
|
{
|
||||||
|
opj_bool (* opj_start_compress) ( void *p_codec,
|
||||||
|
struct opj_stream_private *cio,
|
||||||
|
struct opj_image * p_image,
|
||||||
|
struct opj_event_mgr * p_manager);
|
||||||
|
|
||||||
|
opj_bool (* opj_encode) ( void * p_codec,
|
||||||
|
struct opj_stream_private *p_cio,
|
||||||
|
struct opj_event_mgr * p_manager);
|
||||||
|
|
||||||
|
opj_bool (* opj_write_tile) ( void * p_codec,
|
||||||
|
OPJ_UINT32 p_tile_index,
|
||||||
|
OPJ_BYTE * p_data,
|
||||||
|
OPJ_UINT32 p_data_size,
|
||||||
|
struct opj_stream_private * p_cio,
|
||||||
|
struct opj_event_mgr * p_manager);
|
||||||
|
|
||||||
|
opj_bool (* opj_end_compress) ( void * p_codec,
|
||||||
|
struct opj_stream_private *p_cio,
|
||||||
|
struct opj_event_mgr * p_manager);
|
||||||
|
|
||||||
|
void (* opj_destroy) (void * p_codec);
|
||||||
|
|
||||||
|
void (*opj_setup_encoder) ( void * p_codec,
|
||||||
|
opj_cparameters_t * p_param,
|
||||||
|
struct opj_image * p_image,
|
||||||
|
struct opj_event_mgr * p_manager);
|
||||||
|
|
||||||
|
}opj_compression_t;
|
||||||
|
|
||||||
|
typedef struct opj_codec_private
|
||||||
|
{
|
||||||
|
/** FIXME DOC */
|
||||||
|
union
|
||||||
|
{
|
||||||
|
opj_decompression_t m_decompression;
|
||||||
|
opj_compression_t m_compression;
|
||||||
|
} m_codec_data;
|
||||||
|
/** FIXME DOC*/
|
||||||
|
void * m_codec;
|
||||||
|
/** Event handler */
|
||||||
|
opj_event_mgr_t m_event_mgr;
|
||||||
|
/** Flag to indicate if the codec is used to decode or encode*/
|
||||||
|
opj_bool is_decompressor;
|
||||||
|
void (*opj_dump_codec) (void * p_codec, OPJ_INT32 info_flag, FILE* output_stream);
|
||||||
|
opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec);
|
||||||
|
opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec);
|
||||||
|
}
|
||||||
|
opj_codec_private_t;
|
||||||
|
|
||||||
|
static opj_bool opj_jp2_write_jp( opj_jp2_v2_t *jp2,
|
||||||
|
opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
/* 12 bytes will be read */
|
||||||
|
unsigned char l_signature_data [12];
|
||||||
|
|
||||||
|
/* preconditions */
|
||||||
|
assert(cio != 00);
|
||||||
|
assert(jp2 != 00);
|
||||||
|
assert(p_manager != 00);
|
||||||
|
|
||||||
|
/* write box length */
|
||||||
|
opj_write_bytes(l_signature_data,12,4);
|
||||||
|
/* writes box type */
|
||||||
|
opj_write_bytes(l_signature_data+4,JP2_JP,4);
|
||||||
|
/* writes magic number*/
|
||||||
|
opj_write_bytes(l_signature_data+8,0x0d0a870a,4);
|
||||||
|
|
||||||
|
if (opj_stream_write_data(cio,l_signature_data,12,p_manager) != 12) {
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OPJ_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static opj_bool opj_jp2_write_ftyp(opj_jp2_v2_t *jp2,
|
||||||
|
opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
unsigned int l_ftyp_size = 16 + 4 * jp2->numcl;
|
||||||
|
unsigned char * l_ftyp_data, * l_current_data_ptr;
|
||||||
|
opj_bool l_result;
|
||||||
|
|
||||||
|
/* preconditions */
|
||||||
|
assert(cio != 00);
|
||||||
|
assert(jp2 != 00);
|
||||||
|
assert(p_manager != 00);
|
||||||
|
|
||||||
|
l_ftyp_data = (unsigned char *) opj_malloc(l_ftyp_size);
|
||||||
|
|
||||||
|
if (l_ftyp_data == 00) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to handle ftyp data\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(l_ftyp_data,0,l_ftyp_size);
|
||||||
|
|
||||||
|
l_current_data_ptr = l_ftyp_data;
|
||||||
|
|
||||||
|
opj_write_bytes(l_current_data_ptr, l_ftyp_size,4); /* box size */
|
||||||
|
l_current_data_ptr += 4;
|
||||||
|
|
||||||
|
opj_write_bytes(l_current_data_ptr, JP2_FTYP,4); /* FTYP */
|
||||||
|
l_current_data_ptr += 4;
|
||||||
|
|
||||||
|
opj_write_bytes(l_current_data_ptr, jp2->brand,4); /* BR */
|
||||||
|
l_current_data_ptr += 4;
|
||||||
|
|
||||||
|
opj_write_bytes(l_current_data_ptr, jp2->minversion,4); /* MinV */
|
||||||
|
l_current_data_ptr += 4;
|
||||||
|
|
||||||
|
for (i = 0; i < jp2->numcl; i++) {
|
||||||
|
opj_write_bytes(l_current_data_ptr, jp2->cl[i],4); /* CL */
|
||||||
|
}
|
||||||
|
|
||||||
|
l_result = (opj_stream_write_data(cio,l_ftyp_data,l_ftyp_size,p_manager) == l_ftyp_size);
|
||||||
|
if (! l_result)
|
||||||
|
{
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Error while writing ftyp data to stream\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_free(l_ftyp_data);
|
||||||
|
|
||||||
|
return l_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static opj_bool opj_jp2_default_validation ( opj_jp2_v2_t * jp2,
|
||||||
|
opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager
|
||||||
|
)
|
||||||
|
{
|
||||||
|
opj_bool l_is_valid = OPJ_TRUE;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
/* preconditions */
|
||||||
|
assert(jp2 != 00);
|
||||||
|
assert(cio != 00);
|
||||||
|
assert(p_manager != 00);
|
||||||
|
|
||||||
|
/* JPEG2000 codec validation */
|
||||||
|
/*TODO*/
|
||||||
|
|
||||||
|
/* STATE checking */
|
||||||
|
/* make sure the state is at 0 */
|
||||||
|
l_is_valid &= (jp2->jp2_state == JP2_STATE_NONE);
|
||||||
|
|
||||||
|
/* make sure not reading a jp2h ???? WEIRD */
|
||||||
|
l_is_valid &= (jp2->jp2_img_state == JP2_IMG_STATE_NONE);
|
||||||
|
|
||||||
|
/* POINTER validation */
|
||||||
|
/* make sure a j2k codec is present */
|
||||||
|
l_is_valid &= (jp2->j2k != 00);
|
||||||
|
|
||||||
|
/* make sure a procedure list is present */
|
||||||
|
l_is_valid &= (jp2->m_procedure_list != 00);
|
||||||
|
|
||||||
|
/* make sure a validation list is present */
|
||||||
|
l_is_valid &= (jp2->m_validation_list != 00);
|
||||||
|
|
||||||
|
/* PARAMETER VALIDATION */
|
||||||
|
/* number of components */
|
||||||
|
l_is_valid &= (jp2->numcl > 0);
|
||||||
|
/* width */
|
||||||
|
l_is_valid &= (jp2->h > 0);
|
||||||
|
/* height */
|
||||||
|
l_is_valid &= (jp2->w > 0);
|
||||||
|
/* precision */
|
||||||
|
for (i = 0; i < jp2->numcomps; ++i) {
|
||||||
|
l_is_valid &= (jp2->comps[i].bpcc > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* METH */
|
||||||
|
l_is_valid &= ((jp2->meth > 0) && (jp2->meth < 3));
|
||||||
|
|
||||||
|
/* stream validation */
|
||||||
|
/* back and forth is needed */
|
||||||
|
l_is_valid &= opj_stream_has_seek(cio);
|
||||||
|
|
||||||
|
return l_is_valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void opj_jp2_setup_encoding_validation (opj_jp2_v2_t *jp2)
|
||||||
|
{
|
||||||
|
/* preconditions */
|
||||||
|
assert(jp2 != 00);
|
||||||
|
|
||||||
|
opj_procedure_list_add_procedure(jp2->m_validation_list, (opj_procedure)opj_jp2_default_validation);
|
||||||
|
/* DEVELOPER CORNER, add your custom validation procedure */
|
||||||
|
}
|
||||||
|
|
||||||
|
static opj_bool opj_jp2_skip_jp2c( opj_jp2_v2_t *jp2,
|
||||||
|
opj_stream_private_t *stream,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
/* preconditions */
|
||||||
|
assert(jp2 != 00);
|
||||||
|
assert(stream != 00);
|
||||||
|
assert(p_manager != 00);
|
||||||
|
|
||||||
|
jp2->j2k_codestream_offset = opj_stream_tell(stream);
|
||||||
|
|
||||||
|
if (opj_stream_skip(stream,8,p_manager) != 8) {
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OPJ_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static opj_bool opj_jpip_skip_iptr( opj_jp2_v2_t *jp2,
|
||||||
|
opj_stream_private_t *stream,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
/* preconditions */
|
||||||
|
assert(jp2 != 00);
|
||||||
|
assert(stream != 00);
|
||||||
|
assert(p_manager != 00);
|
||||||
|
|
||||||
|
jp2->jpip_iptr_offset = opj_stream_tell(stream);
|
||||||
|
|
||||||
|
if (opj_stream_skip(stream,24,p_manager) != 24) {
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OPJ_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void opj_jpip_setup_header_writing (opj_jp2_v2_t *jp2)
|
||||||
|
{
|
||||||
|
/* preconditions */
|
||||||
|
assert(jp2 != 00);
|
||||||
|
|
||||||
|
opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_jp );
|
||||||
|
opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_ftyp );
|
||||||
|
opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_jp2h );
|
||||||
|
opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_skip_iptr );
|
||||||
|
opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_skip_jp2c );
|
||||||
|
|
||||||
|
/* DEVELOPER CORNER, insert your custom procedures */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static opj_bool opj_jp2_exec ( opj_jp2_v2_t * jp2,
|
||||||
|
opj_procedure_list_t * p_procedure_list,
|
||||||
|
opj_stream_private_t *stream,
|
||||||
|
opj_event_mgr_t * p_manager
|
||||||
|
)
|
||||||
|
|
||||||
|
{
|
||||||
|
opj_bool (** l_procedure) (opj_jp2_v2_t * jp2, opj_stream_private_t *, opj_event_mgr_t *) = 00;
|
||||||
|
opj_bool l_result = OPJ_TRUE;
|
||||||
|
OPJ_UINT32 l_nb_proc, i;
|
||||||
|
|
||||||
|
/* preconditions */
|
||||||
|
assert(p_procedure_list != 00);
|
||||||
|
assert(jp2 != 00);
|
||||||
|
assert(stream != 00);
|
||||||
|
assert(p_manager != 00);
|
||||||
|
|
||||||
|
l_nb_proc = opj_procedure_list_get_nb_procedures(p_procedure_list);
|
||||||
|
l_procedure = (opj_bool (**) (opj_jp2_v2_t * jp2, opj_stream_private_t *, opj_event_mgr_t *)) opj_procedure_list_get_first_procedure(p_procedure_list);
|
||||||
|
|
||||||
|
for (i=0;i<l_nb_proc;++i) {
|
||||||
|
l_result = l_result && (*l_procedure) (jp2,stream,p_manager);
|
||||||
|
++l_procedure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* and clear the procedure list at the end. */
|
||||||
|
opj_procedure_list_clear(p_procedure_list);
|
||||||
|
return l_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_bool opj_jpip_start_compress(opj_jp2_v2_t *jp2,
|
||||||
|
opj_stream_private_t *stream,
|
||||||
|
opj_image_t * p_image,
|
||||||
|
opj_event_mgr_t * p_manager
|
||||||
|
)
|
||||||
|
{
|
||||||
|
/* preconditions */
|
||||||
|
assert(jp2 != 00);
|
||||||
|
assert(stream != 00);
|
||||||
|
assert(p_manager != 00);
|
||||||
|
|
||||||
|
/* customization of the validation */
|
||||||
|
opj_jp2_setup_encoding_validation (jp2);
|
||||||
|
|
||||||
|
/* validation of the parameters codec */
|
||||||
|
if (! opj_jp2_exec(jp2,jp2->m_validation_list,stream,p_manager)) {
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* customization of the encoding */
|
||||||
|
opj_jpip_setup_header_writing(jp2);
|
||||||
|
|
||||||
|
/* write header */
|
||||||
|
if (! opj_jp2_exec (jp2,jp2->m_procedure_list,stream,p_manager)) {
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return opj_j2k_start_compress(jp2->j2k,stream,p_image,p_manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
static opj_bool opj_jpip_write_iptr(opj_jp2_v2_t *jp2,
|
||||||
|
opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_OFF_T j2k_codestream_exit;
|
||||||
|
OPJ_BYTE l_data_header [24];
|
||||||
|
|
||||||
|
/* preconditions */
|
||||||
|
assert(jp2 != 00);
|
||||||
|
assert(cio != 00);
|
||||||
|
assert(p_manager != 00);
|
||||||
|
assert(opj_stream_has_seek(cio));
|
||||||
|
|
||||||
|
j2k_codestream_exit = opj_stream_tell(cio);
|
||||||
|
opj_write_bytes(l_data_header, 24, 4); /* size of iptr */
|
||||||
|
opj_write_bytes(l_data_header + 4,JPIP_IPTR,4); /* IPTR */
|
||||||
|
#if 0
|
||||||
|
opj_write_bytes(l_data_header + 4 + 4, 0, 8); /* offset */
|
||||||
|
opj_write_bytes(l_data_header + 8 + 8, 0, 8); /* length */
|
||||||
|
#else
|
||||||
|
opj_write_double(l_data_header + 4 + 4, 0); /* offset */
|
||||||
|
opj_write_double(l_data_header + 8 + 8, 0); /* length */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (! opj_stream_seek(cio,jp2->jpip_iptr_offset,p_manager)) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opj_stream_write_data(cio,l_data_header,24,p_manager) != 24) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OPJ_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static opj_bool opj_jpip_write_fidx(opj_jp2_v2_t *jp2,
|
||||||
|
opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_OFF_T j2k_codestream_exit;
|
||||||
|
OPJ_BYTE l_data_header [24];
|
||||||
|
|
||||||
|
/* preconditions */
|
||||||
|
assert(jp2 != 00);
|
||||||
|
assert(cio != 00);
|
||||||
|
assert(p_manager != 00);
|
||||||
|
assert(opj_stream_has_seek(cio));
|
||||||
|
|
||||||
|
opj_write_bytes(l_data_header, 24, 4); /* size of iptr */
|
||||||
|
opj_write_bytes(l_data_header + 4,JPIP_FIDX,4); /* IPTR */
|
||||||
|
opj_write_double(l_data_header + 4 + 4, 0); /* offset */
|
||||||
|
opj_write_double(l_data_header + 8 + 8, 0); /* length */
|
||||||
|
|
||||||
|
if (opj_stream_write_data(cio,l_data_header,24,p_manager) != 24) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
j2k_codestream_exit = opj_stream_tell(cio);
|
||||||
|
if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OPJ_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static opj_bool opj_jpip_write_cidx(opj_jp2_v2_t *jp2,
|
||||||
|
opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_OFF_T j2k_codestream_exit;
|
||||||
|
OPJ_BYTE l_data_header [24];
|
||||||
|
|
||||||
|
/* preconditions */
|
||||||
|
assert(jp2 != 00);
|
||||||
|
assert(cio != 00);
|
||||||
|
assert(p_manager != 00);
|
||||||
|
assert(opj_stream_has_seek(cio));
|
||||||
|
|
||||||
|
j2k_codestream_exit = opj_stream_tell(cio);
|
||||||
|
opj_write_bytes(l_data_header, 24, 4); /* size of iptr */
|
||||||
|
opj_write_bytes(l_data_header + 4,JPIP_CIDX,4); /* IPTR */
|
||||||
|
#if 0
|
||||||
|
opj_write_bytes(l_data_header + 4 + 4, 0, 8); /* offset */
|
||||||
|
opj_write_bytes(l_data_header + 8 + 8, 0, 8); /* length */
|
||||||
|
#else
|
||||||
|
opj_write_double(l_data_header + 4 + 4, 0); /* offset */
|
||||||
|
opj_write_double(l_data_header + 8 + 8, 0); /* length */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opj_stream_write_data(cio,l_data_header,24,p_manager) != 24) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
j2k_codestream_exit = opj_stream_tell(cio);
|
||||||
|
if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OPJ_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void write_prxy_v2( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_BYTE l_data_header [8];
|
||||||
|
int len, lenp;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_PRXY, 4); /* IPTR */
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell(cio);
|
||||||
|
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
|
||||||
|
opj_write_bytes(l_data_header,JPIP_PRXY,4); /* IPTR */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, offset_jp2c, 8); /* OOFF */
|
||||||
|
cio_write( cio, length_jp2c, 4); /* OBH part 1 */
|
||||||
|
cio_write( cio, JP2_JP2C, 4); /* OBH part 2 */
|
||||||
|
#else
|
||||||
|
opj_write_bytes( l_data_header, offset_jp2c, 8); /* OOFF */
|
||||||
|
opj_stream_write_data(cio,l_data_header,8,p_manager);
|
||||||
|
opj_write_bytes( l_data_header, length_jp2c, 4); /* OBH part 1 */
|
||||||
|
opj_write_bytes( l_data_header+4, JP2_JP2C, 4); /* OBH part 2 */
|
||||||
|
opj_stream_write_data(cio,l_data_header,8,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, 1,1); /* NI */
|
||||||
|
#else
|
||||||
|
opj_write_bytes( l_data_header, 1, 1);/* NI */
|
||||||
|
opj_stream_write_data(cio,l_data_header,1,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, offset_idx, 8); /* IOFF */
|
||||||
|
cio_write( cio, length_idx, 4); /* IBH part 1 */
|
||||||
|
cio_write( cio, JPIP_CIDX, 4); /* IBH part 2 */
|
||||||
|
#else
|
||||||
|
opj_write_bytes( l_data_header, offset_idx, 8); /* IOFF */
|
||||||
|
opj_stream_write_data(cio,l_data_header,8,p_manager);
|
||||||
|
opj_write_bytes( l_data_header, length_idx, 4); /* IBH part 1 */
|
||||||
|
opj_write_bytes( l_data_header+4, JPIP_CIDX, 4); /* IBH part 2 */
|
||||||
|
opj_stream_write_data(cio,l_data_header,8,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
len = opj_stream_tell(cio)-lenp;
|
||||||
|
opj_stream_skip(cio, lenp, p_manager);
|
||||||
|
opj_write_bytes(l_data_header,len,4);/* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek(cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int write_fidx_v2( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_BYTE l_data_header [4];
|
||||||
|
int len, lenp;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_FIDX, 4); /* IPTR */
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell(cio);
|
||||||
|
opj_stream_skip(cio, 4, p_manager);
|
||||||
|
opj_write_bytes(l_data_header,JPIP_FIDX,4); /* FIDX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
write_prxy_v2( offset_jp2c, length_jp2c, offset_idx, length_idx, cio,p_manager);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
len = opj_stream_tell(cio)-lenp;
|
||||||
|
opj_stream_skip(cio, lenp, p_manager);
|
||||||
|
opj_write_bytes(l_data_header,len,4);/* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek(cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static opj_bool opj_jpip_write_jp2c(opj_jp2_v2_t *jp2,
|
||||||
|
opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_OFF_T j2k_codestream_exit;
|
||||||
|
OPJ_BYTE l_data_header [8];
|
||||||
|
OPJ_UINT32 len_jp2c;
|
||||||
|
int len_cidx;
|
||||||
|
int len_fidx;
|
||||||
|
int pos_jp2c;
|
||||||
|
int pos_fidx;
|
||||||
|
int pos_cidx;
|
||||||
|
|
||||||
|
/* preconditions */
|
||||||
|
assert(jp2 != 00);
|
||||||
|
assert(cio != 00);
|
||||||
|
assert(p_manager != 00);
|
||||||
|
assert(opj_stream_has_seek(cio));
|
||||||
|
|
||||||
|
j2k_codestream_exit = opj_stream_tell(cio);
|
||||||
|
len_jp2c = j2k_codestream_exit - jp2->j2k_codestream_offset;
|
||||||
|
pos_jp2c = jp2->j2k_codestream_offset;
|
||||||
|
opj_write_bytes(l_data_header, len_jp2c, 4); /* size of codestream */
|
||||||
|
opj_write_bytes(l_data_header + 4,JP2_JP2C,4); /* JP2C */
|
||||||
|
|
||||||
|
if (! opj_stream_seek(cio,jp2->j2k_codestream_offset,p_manager)) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opj_stream_write_data(cio,l_data_header,8,p_manager) != 8) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CIDX */
|
||||||
|
pos_cidx = opj_stream_tell( cio);
|
||||||
|
len_cidx = write_cidx_v2( pos_jp2c+8, cio, jp2_get_cstr_info(jp2), len_jp2c-8);
|
||||||
|
|
||||||
|
/* FIDX */
|
||||||
|
pos_fidx = opj_stream_tell( cio);
|
||||||
|
len_fidx = write_fidx_v2( pos_jp2c, len_jp2c, pos_cidx, len_cidx, cio, p_manager);
|
||||||
|
|
||||||
|
return OPJ_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void opj_jp2_setup_end_header_writing (opj_jp2_v2_t *jp2)
|
||||||
|
{
|
||||||
|
/* preconditions */
|
||||||
|
assert(jp2 != 00);
|
||||||
|
|
||||||
|
opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_iptr );
|
||||||
|
opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_jp2c );
|
||||||
|
#if 0
|
||||||
|
opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_cidx );
|
||||||
|
opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_fidx );
|
||||||
|
#endif
|
||||||
|
/* DEVELOPER CORNER, add your custom procedures */
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_bool opj_jpip_end_compress( opj_jp2_v2_t *jp2,
|
||||||
|
opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager
|
||||||
|
)
|
||||||
|
{
|
||||||
|
/* preconditions */
|
||||||
|
assert(jp2 != 00);
|
||||||
|
assert(cio != 00);
|
||||||
|
assert(p_manager != 00);
|
||||||
|
|
||||||
|
/* customization of the end encoding */
|
||||||
|
opj_jp2_setup_end_header_writing(jp2);
|
||||||
|
|
||||||
|
if (! opj_j2k_end_compress(jp2->j2k,cio,p_manager)) {
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* write header */
|
||||||
|
return opj_jp2_exec(jp2,jp2->m_procedure_list,cio,p_manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
opj_codec_t* OPJ_CALLCONV opj_jpip_create_compress(OPJ_CODEC_FORMAT p_format)
|
||||||
|
{
|
||||||
|
opj_codec_private_t *l_codec = 00;
|
||||||
|
|
||||||
|
l_codec = (opj_codec_private_t*)opj_calloc(1, sizeof(opj_codec_private_t));
|
||||||
|
if (!l_codec) {
|
||||||
|
return 00;
|
||||||
|
}
|
||||||
|
memset(l_codec, 0, sizeof(opj_codec_private_t));
|
||||||
|
|
||||||
|
l_codec->is_decompressor = 0;
|
||||||
|
|
||||||
|
switch(p_format) {
|
||||||
|
case CODEC_JP2:
|
||||||
|
/* get a JP2 decoder handle */
|
||||||
|
l_codec->m_codec_data.m_compression.opj_encode = (opj_bool (*) (void *,
|
||||||
|
struct opj_stream_private *,
|
||||||
|
struct opj_event_mgr * )) opj_jp2_encode;
|
||||||
|
|
||||||
|
l_codec->m_codec_data.m_compression.opj_end_compress = (opj_bool (*) ( void *,
|
||||||
|
struct opj_stream_private *,
|
||||||
|
struct opj_event_mgr *)) opj_jpip_end_compress;
|
||||||
|
|
||||||
|
l_codec->m_codec_data.m_compression.opj_start_compress = (opj_bool (*) (void *,
|
||||||
|
struct opj_stream_private *,
|
||||||
|
struct opj_image * ,
|
||||||
|
struct opj_event_mgr *)) opj_jpip_start_compress;
|
||||||
|
|
||||||
|
l_codec->m_codec_data.m_compression.opj_write_tile = (opj_bool (*) (void *,
|
||||||
|
OPJ_UINT32,
|
||||||
|
OPJ_BYTE*,
|
||||||
|
OPJ_UINT32,
|
||||||
|
struct opj_stream_private *,
|
||||||
|
struct opj_event_mgr *)) opj_jp2_write_tile;
|
||||||
|
|
||||||
|
l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_jp2_destroy;
|
||||||
|
|
||||||
|
l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) ( void *,
|
||||||
|
opj_cparameters_t *,
|
||||||
|
struct opj_image *,
|
||||||
|
struct opj_event_mgr * )) opj_jp2_setup_encoder;
|
||||||
|
|
||||||
|
l_codec->m_codec = opj_jp2_create(OPJ_FALSE);
|
||||||
|
if (! l_codec->m_codec) {
|
||||||
|
opj_free(l_codec);
|
||||||
|
return 00;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CODEC_UNKNOWN:
|
||||||
|
case CODEC_JPT:
|
||||||
|
default:
|
||||||
|
opj_free(l_codec);
|
||||||
|
return 00;
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_set_default_event_handler(&(l_codec->m_event_mgr));
|
||||||
|
return (opj_codec_t*) l_codec;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /*SERVER*/
|
#endif /*SERVER*/
|
||||||
|
|
|
@ -303,6 +303,8 @@ void destroy_index( index_t **idx);
|
||||||
*/
|
*/
|
||||||
void output_index( index_t *index);
|
void output_index( index_t *index);
|
||||||
|
|
||||||
|
OPJ_API opj_codec_t* OPJ_CALLCONV opj_jpip_create_compress(OPJ_CODEC_FORMAT format);
|
||||||
|
|
||||||
#endif /*SERVER*/
|
#endif /*SERVER*/
|
||||||
|
|
||||||
#endif /* !OPENJPIP_H_ */
|
#endif /* !OPENJPIP_H_ */
|
||||||
|
|
|
@ -81,6 +81,60 @@ int write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int write_phix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_BYTE l_data_header [8];
|
||||||
|
int len, lenp=0, compno, i;
|
||||||
|
opj_jp2_box_t *box;
|
||||||
|
|
||||||
|
box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t));
|
||||||
|
|
||||||
|
for( i=0;i<2;i++){
|
||||||
|
if (i)
|
||||||
|
#if 0
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
#else
|
||||||
|
opj_stream_seek( cio, lenp, p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_PHIX, 4); /* PHIX */
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell(cio);
|
||||||
|
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
|
||||||
|
opj_write_bytes(l_data_header,JPIP_PHIX,4); /* PHIX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
write_manf_v2( i, cstr_info.numcomps, box, cio);
|
||||||
|
|
||||||
|
for( compno=0; compno<cstr_info.numcomps; compno++){
|
||||||
|
box[compno].length = write_phixfaix_v2( coff, compno, cstr_info, EPHused, j2klen, cio);
|
||||||
|
box[compno].type = JPIP_FAIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell(cio);
|
||||||
|
opj_stream_seek(cio, 4, p_manager);
|
||||||
|
opj_write_bytes(l_data_header,len,4);/* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek( cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_free(box);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
int write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
|
int write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
|
||||||
{
|
{
|
||||||
int len, lenp, tileno, version, i, nmax, size_of_coding; /* 4 or 8 */
|
int len, lenp, tileno, version, i, nmax, size_of_coding; /* 4 or 8 */
|
||||||
|
@ -167,3 +221,130 @@ int write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_b
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int write_phixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
int len, lenp, tileno, version, i, nmax, size_of_coding; /* 4 or 8 */
|
||||||
|
opj_tile_info_t *tile_Idx;
|
||||||
|
opj_packet_info_t packet;
|
||||||
|
int resno, precno, layno, num_packet;
|
||||||
|
int numOfres, numOfprec, numOflayers;
|
||||||
|
OPJ_BYTE l_data_header [8];
|
||||||
|
packet.end_ph_pos = packet.start_pos = -1;
|
||||||
|
(void)EPHused; /* unused ? */
|
||||||
|
|
||||||
|
if( j2klen > pow( 2, 32)){
|
||||||
|
size_of_coding = 8;
|
||||||
|
version = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
size_of_coding = 4;
|
||||||
|
version = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_FAIX, 4); /* FAIX */
|
||||||
|
cio_write( cio, version,1); /* Version 0 = 4 bytes */
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell(cio);
|
||||||
|
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
|
||||||
|
opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,version,1); /* Version 0 = 4 bytes */
|
||||||
|
opj_stream_write_data(cio,l_data_header,1,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
nmax = 0;
|
||||||
|
for( i=0; i<=cstr_info.numdecompos[compno]; i++)
|
||||||
|
nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, nmax, size_of_coding); /* NMAX */
|
||||||
|
cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,nmax,size_of_coding); /* NMAX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,cstr_info.tw*cstr_info.th,size_of_coding); /* M */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
|
||||||
|
tile_Idx = &cstr_info.tile[ tileno];
|
||||||
|
|
||||||
|
num_packet = 0;
|
||||||
|
numOfres = cstr_info.numdecompos[compno] + 1;
|
||||||
|
|
||||||
|
for( resno=0; resno<numOfres ; resno++){
|
||||||
|
numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
|
||||||
|
for( precno=0; precno<numOfprec; precno++){
|
||||||
|
numOflayers = cstr_info.numlayers;
|
||||||
|
for( layno=0; layno<numOflayers; layno++){
|
||||||
|
|
||||||
|
switch ( cstr_info.prog){
|
||||||
|
case LRCP:
|
||||||
|
packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
|
||||||
|
break;
|
||||||
|
case RLCP:
|
||||||
|
packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno];
|
||||||
|
break;
|
||||||
|
case RPCL:
|
||||||
|
packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno];
|
||||||
|
break;
|
||||||
|
case PCRL:
|
||||||
|
packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno];
|
||||||
|
break;
|
||||||
|
case CPRL:
|
||||||
|
packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf( stderr, "failed to ppix indexing\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, packet.start_pos-coff, size_of_coding); /* start position */
|
||||||
|
cio_write( cio, packet.end_ph_pos-packet.start_pos+1, size_of_coding); /* length */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,packet.start_pos-coff,size_of_coding); /* start position */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,packet.end_ph_pos-packet.start_pos+1,size_of_coding); /* length */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
num_packet++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* PADDING */
|
||||||
|
while( num_packet < nmax){
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, 0, size_of_coding); /* start position */
|
||||||
|
cio_write( cio, 0, size_of_coding); /* length */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,0,size_of_coding);/* start position */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,0,size_of_coding);/* length */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
#endif
|
||||||
|
num_packet++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
len = opj_stream_tell(cio)-lenp;
|
||||||
|
opj_stream_seek(cio, lenp,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,len,4);/* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek(cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
|
@ -83,6 +83,63 @@ int write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int write_ppix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_BYTE l_data_header [4];
|
||||||
|
int len, lenp, compno, i;
|
||||||
|
opj_jp2_box_t *box;
|
||||||
|
|
||||||
|
/* printf("cstr_info.packno %d\n", cstr_info.packno); //NMAX? */
|
||||||
|
|
||||||
|
lenp = -1;
|
||||||
|
box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t));
|
||||||
|
|
||||||
|
for (i=0;i<2;i++){
|
||||||
|
if (i)
|
||||||
|
#if 0
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
#else
|
||||||
|
opj_stream_seek( cio, lenp, p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_PPIX, 4); /* PPIX */
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell(cio);
|
||||||
|
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
|
||||||
|
opj_write_bytes(l_data_header,JPIP_PPIX,4);/* PPIX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
write_manf_v2( i, cstr_info.numcomps, box, cio);
|
||||||
|
|
||||||
|
for (compno=0; compno<cstr_info.numcomps; compno++){
|
||||||
|
box[compno].length = write_ppixfaix_v2( coff, compno, cstr_info, EPHused, j2klen, cio);
|
||||||
|
box[compno].type = JPIP_FAIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
len = opj_stream_tell(cio)-lenp;
|
||||||
|
opj_stream_seek(cio, lenp,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,len,4);/* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek(cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_free(box);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
int write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
|
int write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
|
||||||
{
|
{
|
||||||
int len, lenp, tileno, version, i, nmax, size_of_coding; /* 4 or 8*/
|
int len, lenp, tileno, version, i, nmax, size_of_coding; /* 4 or 8*/
|
||||||
|
@ -168,3 +225,128 @@ int write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_b
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int write_ppixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_BYTE l_data_header [8];
|
||||||
|
int len, lenp, tileno, version, i, nmax, size_of_coding; /* 4 or 8*/
|
||||||
|
opj_tile_info_t *tile_Idx;
|
||||||
|
opj_packet_info_t packet;
|
||||||
|
int resno, precno, layno, num_packet;
|
||||||
|
int numOfres, numOfprec, numOflayers;
|
||||||
|
packet.end_pos = packet.end_ph_pos = packet.start_pos = -1;
|
||||||
|
(void)EPHused; /* unused ? */
|
||||||
|
|
||||||
|
if( j2klen > pow( 2, 32)){
|
||||||
|
size_of_coding = 8;
|
||||||
|
version = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
size_of_coding = 4;
|
||||||
|
version = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_FAIX, 4); /* FAIX */
|
||||||
|
cio_write( cio, version, 1); /* Version 0 = 4 bytes */
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell(cio);
|
||||||
|
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
|
||||||
|
opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
|
||||||
|
opj_write_bytes(l_data_header,version,1);
|
||||||
|
opj_stream_write_data(cio,l_data_header,1,p_manager);/* Version 0 = 4 bytes */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
nmax = 0;
|
||||||
|
for( i=0; i<=cstr_info.numdecompos[compno]; i++)
|
||||||
|
nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, nmax, size_of_coding); /* NMAX */
|
||||||
|
cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,nmax,size_of_coding); /* NMAX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,cstr_info.tw*cstr_info.th,size_of_coding); /* M */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
|
||||||
|
tile_Idx = &cstr_info.tile[ tileno];
|
||||||
|
|
||||||
|
num_packet=0;
|
||||||
|
numOfres = cstr_info.numdecompos[compno] + 1;
|
||||||
|
|
||||||
|
for( resno=0; resno<numOfres ; resno++){
|
||||||
|
numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
|
||||||
|
for( precno=0; precno<numOfprec; precno++){
|
||||||
|
numOflayers = cstr_info.numlayers;
|
||||||
|
for( layno=0; layno<numOflayers; layno++){
|
||||||
|
|
||||||
|
switch ( cstr_info.prog){
|
||||||
|
case LRCP:
|
||||||
|
packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
|
||||||
|
break;
|
||||||
|
case RLCP:
|
||||||
|
packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno];
|
||||||
|
break;
|
||||||
|
case RPCL:
|
||||||
|
packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno];
|
||||||
|
break;
|
||||||
|
case PCRL:
|
||||||
|
packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno];
|
||||||
|
break;
|
||||||
|
case CPRL:
|
||||||
|
packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf( stderr, "failed to ppix indexing\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, packet.start_pos-coff, size_of_coding); /* start position */
|
||||||
|
cio_write( cio, packet.end_pos-packet.start_pos+1, size_of_coding); /* length */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,packet.start_pos-coff,size_of_coding); /* start position */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,packet.end_pos-packet.start_pos+1,size_of_coding); /* length */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
num_packet++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while( num_packet < nmax){ /* PADDING */
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, 0, size_of_coding); /* start position */
|
||||||
|
cio_write( cio, 0, size_of_coding); /* length */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,0,size_of_coding);/* start position */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,0,size_of_coding);/* length */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
#endif
|
||||||
|
num_packet++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
len = opj_stream_tell(cio)-lenp;
|
||||||
|
opj_stream_seek(cio, lenp,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,len,4);/* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek(cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ sessionlist_param_t * gene_sessionlist(void)
|
||||||
{
|
{
|
||||||
sessionlist_param_t *sessionlist;
|
sessionlist_param_t *sessionlist;
|
||||||
|
|
||||||
sessionlist = (sessionlist_param_t *)malloc( sizeof(sessionlist_param_t));
|
sessionlist = (sessionlist_param_t *)opj_malloc( sizeof(sessionlist_param_t));
|
||||||
|
|
||||||
sessionlist->first = NULL;
|
sessionlist->first = NULL;
|
||||||
sessionlist->last = NULL;
|
sessionlist->last = NULL;
|
||||||
|
@ -60,7 +60,7 @@ session_param_t * gene_session( sessionlist_param_t *sessionlist)
|
||||||
{
|
{
|
||||||
session_param_t *session;
|
session_param_t *session;
|
||||||
|
|
||||||
session = (session_param_t *)malloc( sizeof(session_param_t));
|
session = (session_param_t *)opj_malloc( sizeof(session_param_t));
|
||||||
|
|
||||||
session->channellist = gene_channellist();
|
session->channellist = gene_channellist();
|
||||||
session->cachemodellist = gene_cachemodellist();
|
session->cachemodellist = gene_cachemodellist();
|
||||||
|
@ -144,7 +144,7 @@ bool delete_session( session_param_t **session, sessionlist_param_t *sessionlist
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
fprintf( logstream, "local log: session: %p deleted!\n", (void *)(*session));
|
fprintf( logstream, "local log: session: %p deleted!\n", (void *)(*session));
|
||||||
#endif
|
#endif
|
||||||
free( *session);
|
opj_free( *session);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ void delete_sessionlist( sessionlist_param_t **sessionlist)
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
fprintf( logstream, "local log: session: %p deleted!\n", (void *)sessionPtr);
|
fprintf( logstream, "local log: session: %p deleted!\n", (void *)sessionPtr);
|
||||||
#endif
|
#endif
|
||||||
free( sessionPtr);
|
opj_free( sessionPtr);
|
||||||
|
|
||||||
sessionPtr=sessionNext;
|
sessionPtr=sessionNext;
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ void delete_sessionlist( sessionlist_param_t **sessionlist)
|
||||||
(*sessionlist)->first = NULL;
|
(*sessionlist)->first = NULL;
|
||||||
(*sessionlist)->last = NULL;
|
(*sessionlist)->last = NULL;
|
||||||
|
|
||||||
free(*sessionlist);
|
opj_free(*sessionlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_allsession( sessionlist_param_t *sessionlist)
|
void print_allsession( sessionlist_param_t *sessionlist)
|
||||||
|
|
|
@ -58,7 +58,7 @@ targetlist_param_t * gene_targetlist(void)
|
||||||
{
|
{
|
||||||
targetlist_param_t *targetlist;
|
targetlist_param_t *targetlist;
|
||||||
|
|
||||||
targetlist = (targetlist_param_t *)malloc( sizeof(targetlist_param_t));
|
targetlist = (targetlist_param_t *)opj_malloc( sizeof(targetlist_param_t));
|
||||||
|
|
||||||
targetlist->first = NULL;
|
targetlist->first = NULL;
|
||||||
targetlist->last = NULL;
|
targetlist->last = NULL;
|
||||||
|
@ -99,7 +99,7 @@ target_param_t * gene_target( targetlist_param_t *targetlist, char *targetpath)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
target = (target_param_t *)malloc( sizeof(target_param_t));
|
target = (target_param_t *)opj_malloc( sizeof(target_param_t));
|
||||||
snprintf( target->tid, MAX_LENOFTID, "%x-%x", (unsigned int)time(NULL), (unsigned int)rand());
|
snprintf( target->tid, MAX_LENOFTID, "%x-%x", (unsigned int)time(NULL), (unsigned int)rand());
|
||||||
target->targetname = strdup( targetpath);
|
target->targetname = strdup( targetpath);
|
||||||
target->fd = fd;
|
target->fd = fd;
|
||||||
|
@ -158,9 +158,9 @@ void delete_target( target_param_t **target)
|
||||||
fprintf( logstream, "local log: target: %s deleted\n", (*target)->targetname);
|
fprintf( logstream, "local log: target: %s deleted\n", (*target)->targetname);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
free( (*target)->targetname);
|
opj_free( (*target)->targetname);
|
||||||
|
|
||||||
free(*target);
|
opj_free(*target);
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_target_in_list( target_param_t **target, targetlist_param_t *targetlist)
|
void delete_target_in_list( target_param_t **target, targetlist_param_t *targetlist)
|
||||||
|
@ -193,7 +193,7 @@ void delete_targetlist(targetlist_param_t **targetlist)
|
||||||
delete_target( &targetPtr);
|
delete_target( &targetPtr);
|
||||||
targetPtr=targetNext;
|
targetPtr=targetNext;
|
||||||
}
|
}
|
||||||
free( *targetlist);
|
opj_free( *targetlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_target( target_param_t *target)
|
void print_target( target_param_t *target)
|
||||||
|
@ -274,10 +274,10 @@ int open_jp2file( const char filepath[], char tmpfname[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = (char *)malloc( 12); /* size of header*/
|
data = (char *)opj_malloc( 12); /* size of header*/
|
||||||
|
|
||||||
if( read( fd, data, 12) != 12){
|
if( read( fd, data, 12) != 12){
|
||||||
free( data);
|
opj_free( data);
|
||||||
close(fd);
|
close(fd);
|
||||||
fprintf( FCGI_stdout, "Reason: Target %s broken (read error)\r\n", filepath);
|
fprintf( FCGI_stdout, "Reason: Target %s broken (read error)\r\n", filepath);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -285,13 +285,13 @@ int open_jp2file( const char filepath[], char tmpfname[])
|
||||||
|
|
||||||
if( *data || *(data + 1) || *(data + 2) ||
|
if( *data || *(data + 1) || *(data + 2) ||
|
||||||
*(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
|
*(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
|
||||||
free( data);
|
opj_free( data);
|
||||||
close(fd);
|
close(fd);
|
||||||
fprintf( FCGI_stdout, "Reason: No JPEG 2000 Signature box in target %s\r\n", filepath);
|
fprintf( FCGI_stdout, "Reason: No JPEG 2000 Signature box in target %s\r\n", filepath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
free( data);
|
opj_free( data);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,61 @@ int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio)
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int write_thix_v2( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_BYTE l_data_header [4];
|
||||||
|
int len, lenp, i;
|
||||||
|
int tileno;
|
||||||
|
opj_jp2_box_t *box;
|
||||||
|
|
||||||
|
lenp = 0;
|
||||||
|
box = (opj_jp2_box_t *)opj_calloc( cstr_info.tw*cstr_info.th, sizeof(opj_jp2_box_t));
|
||||||
|
|
||||||
|
for ( i = 0; i < 2 ; i++ ){
|
||||||
|
if (i)
|
||||||
|
#if 0
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
#else
|
||||||
|
opj_stream_seek( cio, lenp, p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_THIX, 4); /* THIX */
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell(cio);
|
||||||
|
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
|
||||||
|
opj_write_bytes(l_data_header,JPIP_THIX,4); /* THIX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
write_manf_v2( i, cstr_info.tw*cstr_info.th, box, cio);
|
||||||
|
|
||||||
|
for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++){
|
||||||
|
box[tileno].length = write_tilemhix_v2( coff, cstr_info, tileno, cio);
|
||||||
|
box[tileno].type = JPIP_MHIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
len = opj_stream_tell(cio)-lenp;
|
||||||
|
opj_stream_seek(cio, lenp, p_manager);
|
||||||
|
opj_write_bytes(l_data_header,len,4); /* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek( cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_free(box);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_cio_t *cio)
|
int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_cio_t *cio)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -116,3 +171,72 @@ int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_c
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int write_tilemhix_v2( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_BYTE l_data_header [8];
|
||||||
|
int i;
|
||||||
|
opj_tile_info_t tile;
|
||||||
|
opj_tp_info_t tp;
|
||||||
|
int marknum;
|
||||||
|
int len, lenp;
|
||||||
|
opj_marker_info_t *marker;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_MHIX, 4); /* MHIX */
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell (cio);
|
||||||
|
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
|
||||||
|
opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
tile = cstr_info.tile[tileno];
|
||||||
|
tp = tile.tp[0];
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, tp.tp_end_header-tp.tp_start_pos+1, 8); /* TLEN */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,tp.tp_end_header-tp.tp_start_pos+1, 8); /* TLEN */
|
||||||
|
opj_stream_write_data(cio,l_data_header,8,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
marker = cstr_info.tile[tileno].marker;
|
||||||
|
|
||||||
|
for( i=0; i<cstr_info.tile[tileno].marknum; i++){ /* Marker restricted to 1 apparition */
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, marker[i].type, 2);
|
||||||
|
cio_write( cio, 0, 2);
|
||||||
|
cio_write( cio, marker[i].pos-coff, 8);
|
||||||
|
cio_write( cio, marker[i].len, 2);
|
||||||
|
#else
|
||||||
|
opj_write_bytes( l_data_header, marker[i].type, 2);
|
||||||
|
opj_write_bytes( l_data_header+2, 0, 2);
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_write_bytes( l_data_header, marker[i].pos-coff, 8);
|
||||||
|
opj_stream_write_data(cio,l_data_header,8,p_manager);
|
||||||
|
opj_write_bytes( l_data_header, marker[i].len, 2);
|
||||||
|
opj_stream_write_data(cio,l_data_header,2,p_manager);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free( marker);*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio) - lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
len = opj_stream_tell(cio)-lenp;
|
||||||
|
opj_stream_seek(cio, lenp,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,len,4);/* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek(cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
|
@ -68,6 +68,39 @@ int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int write_tpix_v2( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
OPJ_BYTE l_data_header [4];
|
||||||
|
int len, lenp;
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_TPIX, 4); /* TPIX */
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell(cio);
|
||||||
|
opj_stream_skip(cio, 4, p_manager);
|
||||||
|
opj_write_bytes(l_data_header,JPIP_TPIX,4); /* TPIX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
write_tpixfaix_v2( coff, 0, cstr_info, j2klen, cio,p_manager);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
len = opj_stream_tell(cio)-lenp;
|
||||||
|
opj_stream_skip(cio, lenp, p_manager);
|
||||||
|
opj_write_bytes(l_data_header,len,4);/* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek(cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get number of maximum tile parts per tile
|
* Get number of maximum tile parts per tile
|
||||||
|
@ -111,14 +144,14 @@ int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j
|
||||||
cio_write( cio, tp.tp_start_pos-coff, size_of_coding); /* start position */
|
cio_write( cio, tp.tp_start_pos-coff, size_of_coding); /* start position */
|
||||||
cio_write( cio, tp.tp_end_pos-tp.tp_start_pos+1, size_of_coding); /* length */
|
cio_write( cio, tp.tp_end_pos-tp.tp_start_pos+1, size_of_coding); /* length */
|
||||||
if (version & 0x02){
|
if (version & 0x02){
|
||||||
if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
|
if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
|
||||||
Aux = cstr_info.numdecompos[compno] + 1;
|
Aux = cstr_info.numdecompos[compno] + 1;
|
||||||
else
|
else
|
||||||
Aux = j + 1;
|
Aux = j + 1;
|
||||||
|
|
||||||
cio_write( cio, Aux,4);
|
cio_write( cio, Aux,4);
|
||||||
/*cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4);*/ /* Aux_i,j : Auxiliary value */
|
/*cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4);*/ /* Aux_i,j : Auxiliary value */
|
||||||
/* fprintf(stderr,"AUX value %d\n",Aux);*/
|
/* fprintf(stderr,"AUX value %d\n",Aux);*/
|
||||||
}
|
}
|
||||||
/*cio_write(0,4);*/
|
/*cio_write(0,4);*/
|
||||||
}
|
}
|
||||||
|
@ -127,7 +160,7 @@ int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j
|
||||||
cio_write( cio, 0, size_of_coding); /* start position */
|
cio_write( cio, 0, size_of_coding); /* start position */
|
||||||
cio_write( cio, 0, size_of_coding); /* length */
|
cio_write( cio, 0, size_of_coding); /* length */
|
||||||
if (version & 0x02)
|
if (version & 0x02)
|
||||||
cio_write( cio, 0,4); /* Aux_i,j : Auxiliary value */
|
cio_write( cio, 0,4); /* Aux_i,j : Auxiliary value */
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,6 +174,123 @@ int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int write_tpixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
|
||||||
|
opj_event_mgr_t * p_manager )
|
||||||
|
{
|
||||||
|
int len, lenp;
|
||||||
|
int i, j;
|
||||||
|
int Aux;
|
||||||
|
int num_max_tile_parts;
|
||||||
|
int size_of_coding; /* 4 or 8 */
|
||||||
|
opj_tp_info_t tp;
|
||||||
|
OPJ_BYTE l_data_header [8];
|
||||||
|
int version;
|
||||||
|
|
||||||
|
num_max_tile_parts = get_num_max_tile_parts( cstr_info);
|
||||||
|
|
||||||
|
if( j2klen > pow( 2, 32)){
|
||||||
|
size_of_coding = 8;
|
||||||
|
version = num_max_tile_parts == 1 ? 1:3;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
size_of_coding = 4;
|
||||||
|
version = num_max_tile_parts == 1 ? 0:2;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_FAIX, 4); /* FAIX */
|
||||||
|
cio_write( cio, version, 1); /* Version 0 = 4 bytes */
|
||||||
|
#else
|
||||||
|
lenp = opj_stream_tell(cio);
|
||||||
|
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
|
||||||
|
opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,version,1); /* Version 0 = 4 bytes */
|
||||||
|
opj_stream_write_data(cio,l_data_header,1,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, num_max_tile_parts, size_of_coding); /* NMAX */
|
||||||
|
cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,num_max_tile_parts,size_of_coding); /* NMAX */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,cstr_info.tw*cstr_info.th,size_of_coding); /* M */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
#endif
|
||||||
|
for (i = 0; i < cstr_info.tw*cstr_info.th; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < cstr_info.tile[i].num_tps; j++)
|
||||||
|
{
|
||||||
|
tp = cstr_info.tile[i].tp[j];
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, tp.tp_start_pos-coff, size_of_coding); /* start position */
|
||||||
|
cio_write( cio, tp.tp_end_pos-tp.tp_start_pos+1, size_of_coding); /* length */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,tp.tp_start_pos-coff,size_of_coding); /* start position */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,tp.tp_end_pos-tp.tp_start_pos+1,size_of_coding); /* length */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
#endif
|
||||||
|
if (version & 0x02)
|
||||||
|
{
|
||||||
|
if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
|
||||||
|
Aux = cstr_info.numdecompos[compno] + 1;
|
||||||
|
else
|
||||||
|
Aux = j + 1;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, Aux,4);
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,Aux,4);
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
/*cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4);*/ /* Aux_i,j : Auxiliary value */
|
||||||
|
/* fprintf(stderr,"AUX value %d\n",Aux);*/
|
||||||
|
}
|
||||||
|
/*cio_write(0,4);*/
|
||||||
|
}
|
||||||
|
/* PADDING */
|
||||||
|
while (j < num_max_tile_parts)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, 0, size_of_coding); /* start position */
|
||||||
|
cio_write( cio, 0, size_of_coding); /* length */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,0,size_of_coding);/* start position */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,0,size_of_coding);/* length */
|
||||||
|
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
|
||||||
|
#endif
|
||||||
|
if (version & 0x02)
|
||||||
|
#if 0
|
||||||
|
cio_write( cio, 0,4); /* Aux_i,j : Auxiliary value */
|
||||||
|
#else
|
||||||
|
opj_write_bytes(l_data_header,0,4); /* Aux_i,j : Auxiliary value */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
#endif
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
#else
|
||||||
|
len = opj_stream_tell(cio)-lenp;
|
||||||
|
opj_stream_seek(cio, lenp,p_manager);
|
||||||
|
opj_write_bytes(l_data_header,len,4);/* L */
|
||||||
|
opj_stream_write_data(cio,l_data_header,4,p_manager);
|
||||||
|
opj_stream_seek(cio, lenp+len,p_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
int get_num_max_tile_parts( opj_codestream_info_t cstr_info)
|
int get_num_max_tile_parts( opj_codestream_info_t cstr_info)
|
||||||
{
|
{
|
||||||
int num_max_tp = 0, i;
|
int num_max_tp = 0, i;
|
||||||
|
|
Loading…
Reference in New Issue