diff --git a/applications/jpip/tools/indexer/Makefile.nix b/applications/jpip/tools/indexer/Makefile.nix index 4ea2b8c6..fe0d6b74 100644 --- a/applications/jpip/tools/indexer/Makefile.nix +++ b/applications/jpip/tools/indexer/Makefile.nix @@ -1,14 +1,15 @@ INCDIR = ../../../../libopenjpeg +INCDIR2 = ext_libopenjpeg LIBDIR = $(INCDIR)/.libs LIBFNAME = $(LIBDIR)/libopenjpeg.a -CFLAGS = -O3 -Wall -I$(INCDIR) +CFLAGS = -O3 -Wall -I$(INCDIR) -I$(INCDIR2) LDFLAGS = -L$(LIBDIR) -lm ALL = j2k_to_idxjp2 all: $(ALL) -j2k_to_idxjp2: j2k_to_idxjp2.o event_mgr_handler.o idxjp2_manager.o j2k_decoder.o cidx_manager.o cio_ext.o tpix_manager.o thix_manager.o ppix_manager.o phix_manager.o $(LIBFNAME) - $(CC) $(CFLAGS) $< event_mgr_handler.o idxjp2_manager.o j2k_decoder.o cidx_manager.o cio_ext.o tpix_manager.o thix_manager.o ppix_manager.o phix_manager.o $(LDFLAGS) $(LIBFNAME) -o $@ +j2k_to_idxjp2: j2k_to_idxjp2.o event_mgr_handler.o idxjp2_manager.o j2k_decoder.o $(INCDIR2)/cidx_manager.o $(INCDIR2)/cio_ext.o $(INCDIR2)/ext_j2k.o $(INCDIR2)/ext_jp2.o $(INCDIR2)/phix_manager.o $(INCDIR2)/ppix_manager.o $(INCDIR2)/thix_manager.o $(INCDIR2)/tpix_manager.o $(LIBFNAME) + $(CC) $(CFLAGS) $< event_mgr_handler.o idxjp2_manager.o j2k_decoder.o $(INCDIR2)/cidx_manager.o $(INCDIR2)/cio_ext.o $(INCDIR2)/ext_j2k.o $(INCDIR2)/ext_jp2.o $(INCDIR2)/phix_manager.o $(INCDIR2)/ppix_manager.o $(INCDIR2)/thix_manager.o $(INCDIR2)/tpix_manager.o $(LDFLAGS) $(LIBFNAME) -o $@ clean: rm -f $(ALL) *.o *~ diff --git a/applications/jpip/tools/indexer/cidx_manager.c b/applications/jpip/tools/indexer/ext_libopenjpeg/cidx_manager.c similarity index 100% rename from applications/jpip/tools/indexer/cidx_manager.c rename to applications/jpip/tools/indexer/ext_libopenjpeg/cidx_manager.c diff --git a/applications/jpip/tools/indexer/cidx_manager.h b/applications/jpip/tools/indexer/ext_libopenjpeg/cidx_manager.h similarity index 100% rename from applications/jpip/tools/indexer/cidx_manager.h rename to applications/jpip/tools/indexer/ext_libopenjpeg/cidx_manager.h diff --git a/applications/jpip/tools/indexer/cio_ext.c b/applications/jpip/tools/indexer/ext_libopenjpeg/cio_ext.c similarity index 96% rename from applications/jpip/tools/indexer/cio_ext.c rename to applications/jpip/tools/indexer/ext_libopenjpeg/cio_ext.c index d507cc9f..29d543e4 100644 --- a/applications/jpip/tools/indexer/cio_ext.c +++ b/applications/jpip/tools/indexer/ext_libopenjpeg/cio_ext.c @@ -38,6 +38,7 @@ /* * Write a byte. + * A copy of cio.c:opj_bool cio_byteout(opj_cio_t *cio, unsigned char v) */ opj_bool cio_ext_byteout(opj_cio_t *cio, unsigned char v); diff --git a/applications/jpip/tools/indexer/cio_ext.h b/applications/jpip/tools/indexer/ext_libopenjpeg/cio_ext.h similarity index 100% rename from applications/jpip/tools/indexer/cio_ext.h rename to applications/jpip/tools/indexer/ext_libopenjpeg/cio_ext.h diff --git a/applications/jpip/tools/indexer/ext_libopenjpeg/ext_j2k.c b/applications/jpip/tools/indexer/ext_libopenjpeg/ext_j2k.c new file mode 100644 index 00000000..c6db306b --- /dev/null +++ b/applications/jpip/tools/indexer/ext_libopenjpeg/ext_j2k.c @@ -0,0 +1,95 @@ +/* + * $Id$ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include "ext_openjpeg.h" +#include "cio.h" +#include "j2k.h" + +/* + * Get main headr marker size + * + * @param[in] type marker type + * @param[in] cstr_info codestream information + * @param[in] cio file input handle + * @return marker size + */ +unsigned short get_mh_markersize( unsigned short type, opj_codestream_info_t cstr_info, opj_cio_t *cio); + +void add_mainheader_marker_info( opj_cio_t *cio, opj_codestream_info_t *cstr_info) +{ + opj_marker_info_t marker; + int pos; + + cstr_info->marker = (opj_marker_info_t *)malloc( 100*sizeof(opj_marker_info_t)); // max 100 + + pos = cstr_info->main_head_start; + cio_seek( cio, pos); + + while( pos <= cstr_info->main_head_end){ + marker.type = cio_read( cio, 2); + marker.pos = cio_tell( cio); + marker.len = get_mh_markersize( marker.type, *cstr_info, cio); + cio_skip( cio, marker.len); + + cstr_info->marker[ cstr_info->marknum] = marker; + + cstr_info->marknum++; + pos = cio_tell( cio); + } +} + +unsigned short get_mh_markersize( unsigned short type, opj_codestream_info_t cstr_info, opj_cio_t *cio) +{ + unsigned short siz; + int pos; + + siz = 0; + + switch( type){ + case J2K_MS_SOC: + siz = 0; + break; + case J2K_MS_SIZ: + siz = 38+3*cstr_info.numcomps; + break; + case J2K_MS_COD: + case J2K_MS_QCD: + case J2K_MS_COM: + pos = cio_tell( cio); + siz = cio_read( cio, 2); + cio_seek( cio, pos); + break; + default: + fprintf( stderr, "marker %x length not defined yet!\n", type); + } + return siz; +} diff --git a/applications/jpip/tools/indexer/ext_libopenjpeg/ext_jp2.c b/applications/jpip/tools/indexer/ext_libopenjpeg/ext_jp2.c new file mode 100644 index 00000000..7f355113 --- /dev/null +++ b/applications/jpip/tools/indexer/ext_libopenjpeg/ext_jp2.c @@ -0,0 +1,226 @@ +/* + * $Id$ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ext_openjpeg.h" +#include "cio.h" +#include "cio_ext.h" +#include "cidx_manager.h" +#include "indexbox_manager.h" + +/* + * Write JP box + * copy from jp2.c + * + * @param[in] cio file output handler + */ +void jp2_write_jp(opj_cio_t *cio); + +/* + * Write FTYP box - File type box + * copy from jp2.c + * + * @param[in] jp2 JP2 handle + * @param[in] cio file output handle + */ +void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio); + +/* + * Write file Index (superbox) + * + * @param[in] offset_jp2c offset of jp2c box + * @param[in] length_jp2c length of jp2c box + * @param[in] offset_idx offset of cidx box + * @param[in] length_idx length of cidx box + * @param[in] cio file output handle + * @return length of fidx box + */ +int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio); + +/* + * Write index Finder box + * + * @param[in] offset offset of fidx box + * @param[in] length length of fidx box + * @param[in] cio file output handle + */ +void write_iptr( int offset, int length, opj_cio_t *cio); + +opj_bool idxjp2_encode( opj_cinfo_t *cinfo, opj_cio_t *cio, unsigned char *j2kstream, int j2klen, opj_codestream_info_t cstr_info, opj_image_t *image) +{ + opj_jp2_t *jp2; + int pos_iptr, pos_cidx, pos_jp2c, end_pos, pos_fidx, len_fidx; + int i; + + jp2 = cinfo->jp2_handle; + + /* JP2 encoding */ + + /* JPEG 2000 Signature box */ + jp2_write_jp(cio); + /* File Type box */ + jp2_write_ftyp(jp2, cio); + /* JP2 Header box */ + jp2_write_jp2h(jp2, cio); + + pos_iptr = cio_tell( cio); + cio_skip( cio, 24); /* IPTR further ! */ + + pos_jp2c = cio_tell( cio); + + cio_write( cio, j2klen+8, 4); // L NOTICE: modify for the extended box + cio_write( cio, JP2_JP2C, 4); // JP2C + + for( i=0; ibrand, 4); /* BR */ + cio_write(cio, jp2->minversion, 4); /* MinV */ + + for (i = 0; i < jp2->numcl; i++) { + cio_write(cio, jp2->cl[i], 4); /* CL */ + } + + box.length = cio_tell(cio) - box.init_pos; + cio_seek(cio, box.init_pos); + cio_write(cio, box.length, 4); /* L */ + cio_seek(cio, box.init_pos + box.length); +} + + +/* + * Write proxy box + * + * @param[in] offset_jp2c offset of jp2c box + * @param[in] length_jp2c length of jp2c box + * @param[in] offset_idx offset of cidx box + * @param[in] length_idx length of cidx box + * @param[in] cio file output handle + */ +void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio); + +int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio) +{ + int len, lenp; + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_FIDX, 4); /* IPTR */ + + write_prxy( offset_jp2c, length_jp2c, offset_idx, offset_jp2c, cio); + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + + return len; +} + +void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio) +{ + int len, lenp; + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_PRXY, 4); /* IPTR */ + + cio_ext_write( cio, offset_jp2c, 8); /* OOFF */ + cio_write( cio, length_jp2c, 4); /* OBH part 1 */ + cio_write( cio, JP2_JP2C, 4); /* OBH part 2 */ + + cio_write( cio, 1,1); /* NI */ + + cio_ext_write( cio, offset_idx, 8); /* IOFF */ + cio_write( cio, length_idx, 4); /* IBH part 1 */ + cio_write( cio, JPIP_CIDX, 4); /* IBH part 2 */ + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); +} + +void write_iptr( int offset, int length, opj_cio_t *cio) +{ + int len, lenp; + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_IPTR, 4); /* IPTR */ + + cio_ext_write( cio, offset, 8); + cio_ext_write( cio, length, 8); + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); +} diff --git a/applications/jpip/tools/indexer/ext_libopenjpeg/ext_openjpeg.h b/applications/jpip/tools/indexer/ext_libopenjpeg/ext_openjpeg.h new file mode 100644 index 00000000..5b90c273 --- /dev/null +++ b/applications/jpip/tools/indexer/ext_libopenjpeg/ext_openjpeg.h @@ -0,0 +1,57 @@ +/* + * $Id$ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EXT_OPENJPEG_H_ +# define EXT_OPENJPEG_H_ + +#include "openjpeg.h" + +/* + * Decode and Add main header marker information + * + * @param[in] cio file input handle + * @param[in,out] cstr_info codestream information + */ +void add_mainheader_marker_info( opj_cio_t *cio, opj_codestream_info_t *cstr_info); + +/* + * Encode JP2 stream with index box + * + * @param[in] cinfo codestream information + * @param[in] cio file output handle + * @param[in] j2kstream j2k codestream + * @param[in] j2klen length of j2k codestream + * @param[in] cstr_info codestream information + * @param[in] image image data + * @return true if succeed + */ +opj_bool idxjp2_encode( opj_cinfo_t *cinfo, opj_cio_t *cio, unsigned char *j2kstream, int j2klen, opj_codestream_info_t cstr_info, opj_image_t *image); + +#endif /* !EXT_OPENJPEGS_H_ */ diff --git a/applications/jpip/tools/indexer/indexbox_manager.h b/applications/jpip/tools/indexer/ext_libopenjpeg/indexbox_manager.h similarity index 100% rename from applications/jpip/tools/indexer/indexbox_manager.h rename to applications/jpip/tools/indexer/ext_libopenjpeg/indexbox_manager.h diff --git a/applications/jpip/tools/indexer/phix_manager.c b/applications/jpip/tools/indexer/ext_libopenjpeg/phix_manager.c similarity index 100% rename from applications/jpip/tools/indexer/phix_manager.c rename to applications/jpip/tools/indexer/ext_libopenjpeg/phix_manager.c diff --git a/applications/jpip/tools/indexer/ppix_manager.c b/applications/jpip/tools/indexer/ext_libopenjpeg/ppix_manager.c similarity index 100% rename from applications/jpip/tools/indexer/ppix_manager.c rename to applications/jpip/tools/indexer/ext_libopenjpeg/ppix_manager.c diff --git a/applications/jpip/tools/indexer/thix_manager.c b/applications/jpip/tools/indexer/ext_libopenjpeg/thix_manager.c similarity index 100% rename from applications/jpip/tools/indexer/thix_manager.c rename to applications/jpip/tools/indexer/ext_libopenjpeg/thix_manager.c diff --git a/applications/jpip/tools/indexer/tpix_manager.c b/applications/jpip/tools/indexer/ext_libopenjpeg/tpix_manager.c similarity index 100% rename from applications/jpip/tools/indexer/tpix_manager.c rename to applications/jpip/tools/indexer/ext_libopenjpeg/tpix_manager.c diff --git a/applications/jpip/tools/indexer/idxjp2_manager.c b/applications/jpip/tools/indexer/idxjp2_manager.c index 08c9217b..6146d800 100644 --- a/applications/jpip/tools/indexer/idxjp2_manager.c +++ b/applications/jpip/tools/indexer/idxjp2_manager.c @@ -38,27 +38,9 @@ */ #include -#include -#include -#include "event_mgr_handler.h" -#include "cio.h" -#include "cio_ext.h" +#include "ext_openjpeg.h" #include "j2k_to_idxjp2.h" -#include "cidx_manager.h" -#include "indexbox_manager.h" - -/* - * Encode JP2 stream with index box - * - * @param[in] jp2 jp2 handle - * @param[in] cio file output handle - * @param[in] j2kstream j2k codestream - * @param[in] j2klen length of j2k codestream - * @param[in] cstr_info codestream information - * @param[in] image image data - * @return true if succeed - */ -opj_bool idxjp2_encode( opj_jp2_t *jp2, opj_cio_t *cio, unsigned char *j2kstream, int j2klen, opj_codestream_info_t cstr_info, opj_image_t *image); +#include "event_mgr_handler.h" void fwrite_idxjp2( char filename[], unsigned char *j2kstream, int j2klen, opj_image_t *image, opj_codestream_info_t cstr_info) @@ -89,7 +71,7 @@ void fwrite_idxjp2( char filename[], unsigned char *j2kstream, int j2klen, opj_i /* allocate memory for all tiles */ cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0); - encSuccess = idxjp2_encode( (opj_jp2_t*)cinfo->jp2_handle, cio, j2kstream, j2klen, cstr_info, image); + encSuccess = idxjp2_encode( cinfo, cio, j2kstream, j2klen, cstr_info, image); if (!encSuccess){ opj_cio_close(cio); @@ -116,191 +98,3 @@ void fwrite_idxjp2( char filename[], unsigned char *j2kstream, int j2klen, opj_i opj_destroy_cstr_info(&cstr_info); } - -/* - * Write JP box - * copy from jp2.c - * - * @param[in] cio file output handler - */ -void jp2_write_jp(opj_cio_t *cio); - -/* - * Write FTYP box - File type box - * copy from jp2.c - * - * @param[in] jp2 JP2 handle - * @param[in] cio file output handle - */ -void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio); - -/* - * Write file Index (superbox) - * - * @param[in] offset_jp2c offset of jp2c box - * @param[in] length_jp2c length of jp2c box - * @param[in] offset_idx offset of cidx box - * @param[in] length_idx length of cidx box - * @param[in] cio file output handle - * @return length of fidx box - */ -int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio); - -/* - * Write index Finder box - * - * @param[in] offset offset of fidx box - * @param[in] length length of fidx box - * @param[in] cio file output handle - */ -void write_iptr( int offset, int length, opj_cio_t *cio); - -opj_bool idxjp2_encode( opj_jp2_t *jp2, opj_cio_t *cio, unsigned char *j2kstream, int j2klen, opj_codestream_info_t cstr_info, opj_image_t *image) -{ - int pos_iptr, pos_cidx, pos_jp2c, end_pos, pos_fidx, len_fidx; - int i; - - /* JP2 encoding */ - - /* JPEG 2000 Signature box */ - jp2_write_jp(cio); - /* File Type box */ - jp2_write_ftyp(jp2, cio); - /* JP2 Header box */ - jp2_write_jp2h(jp2, cio); - - pos_iptr = cio_tell( cio); - cio_skip( cio, 24); /* IPTR further ! */ - - pos_jp2c = cio_tell( cio); - - cio_write( cio, j2klen+8, 4); // L NOTICE: modify for the extended box - cio_write( cio, JP2_JP2C, 4); // JP2C - - for( i=0; ibrand, 4); /* BR */ - cio_write(cio, jp2->minversion, 4); /* MinV */ - - for (i = 0; i < jp2->numcl; i++) { - cio_write(cio, jp2->cl[i], 4); /* CL */ - } - - box.length = cio_tell(cio) - box.init_pos; - cio_seek(cio, box.init_pos); - cio_write(cio, box.length, 4); /* L */ - cio_seek(cio, box.init_pos + box.length); -} - - -/* - * Write proxy box - * - * @param[in] offset_jp2c offset of jp2c box - * @param[in] length_jp2c length of jp2c box - * @param[in] offset_idx offset of cidx box - * @param[in] length_idx length of cidx box - * @param[in] cio file output handle - */ -void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio); - -int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio) -{ - int len, lenp; - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_FIDX, 4); /* IPTR */ - - write_prxy( offset_jp2c, length_jp2c, offset_idx, offset_jp2c, cio); - - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); - - return len; -} - -void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio) -{ - int len, lenp; - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_PRXY, 4); /* IPTR */ - - cio_ext_write( cio, offset_jp2c, 8); /* OOFF */ - cio_write( cio, length_jp2c, 4); /* OBH part 1 */ - cio_write( cio, JP2_JP2C, 4); /* OBH part 2 */ - - cio_write( cio, 1,1); /* NI */ - - cio_ext_write( cio, offset_idx, 8); /* IOFF */ - cio_write( cio, length_idx, 4); /* IBH part 1 */ - cio_write( cio, JPIP_CIDX, 4); /* IBH part 2 */ - - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); -} - -void write_iptr( int offset, int length, opj_cio_t *cio) -{ - int len, lenp; - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_IPTR, 4); /* IPTR */ - - cio_ext_write( cio, offset, 8); - cio_ext_write( cio, length, 8); - - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); -} diff --git a/applications/jpip/tools/indexer/j2k_decoder.c b/applications/jpip/tools/indexer/j2k_decoder.c index 6e625035..111e0001 100644 --- a/applications/jpip/tools/indexer/j2k_decoder.c +++ b/applications/jpip/tools/indexer/j2k_decoder.c @@ -29,19 +29,9 @@ */ #include -#include +#include "ext_openjpeg.h" #include "j2k_to_idxjp2.h" #include "event_mgr_handler.h" -#include "cio.h" -#include "j2k.h" - -/* - * Decode and Add main header marker information - * - * @param[in] cio file input handle - * @param[in,out] cstr_info codestream information - */ -void add_mainheader_marker_info( opj_cio_t *cio, opj_codestream_info_t *cstr_info); opj_image_t * decode_j2k( unsigned char *j2kstream, int j2klen, opj_codestream_info_t *cstr_info) { @@ -83,7 +73,7 @@ opj_image_t * decode_j2k( unsigned char *j2kstream, int j2klen, opj_codestream_i if( cstr_info->marknum == 0) add_mainheader_marker_info( cio, cstr_info); - + /* close the byte stream */ opj_cio_close(cio); @@ -94,64 +84,3 @@ opj_image_t * decode_j2k( unsigned char *j2kstream, int j2klen, opj_codestream_i return image; } - - -/* - * Get main headr marker size - * - * @param[in] type marker type - * @param[in] cstr_info codestream information - * @param[in] cio file input handle - * @return marker size - */ -unsigned short get_mh_markersize( unsigned short type, opj_codestream_info_t cstr_info, opj_cio_t *cio); - -void add_mainheader_marker_info( opj_cio_t *cio, opj_codestream_info_t *cstr_info) -{ - opj_marker_info_t marker; - int pos; - - cstr_info->marker = (opj_marker_info_t *)malloc( 100*sizeof(opj_marker_info_t)); // max 100 - - pos = cstr_info->main_head_start; - cio_seek( cio, pos); - - while( pos <= cstr_info->main_head_end){ - marker.type = cio_read( cio, 2); - marker.pos = cio_tell( cio); - marker.len = get_mh_markersize( marker.type, *cstr_info, cio); - cio_skip( cio, marker.len); - - cstr_info->marker[ cstr_info->marknum] = marker; - - cstr_info->marknum++; - pos = cio_tell( cio); - } -} - -unsigned short get_mh_markersize( unsigned short type, opj_codestream_info_t cstr_info, opj_cio_t *cio) -{ - unsigned short siz; - int pos; - - siz = 0; - - switch( type){ - case J2K_MS_SOC: - siz = 0; - break; - case J2K_MS_SIZ: - siz = 38+3*cstr_info.numcomps; - break; - case J2K_MS_COD: - case J2K_MS_QCD: - case J2K_MS_COM: - pos = cio_tell( cio); - siz = cio_read( cio, 2); - cio_seek( cio, pos); - break; - default: - fprintf( stderr, "marker %x length not defined yet!\n", type); - } - return siz; -}