diff options
| author | Mathieu Malaterre <mathieu.malaterre@gmail.com> | 2012-10-25 07:39:59 +0000 |
|---|---|---|
| committer | Mathieu Malaterre <mathieu.malaterre@gmail.com> | 2012-10-25 07:39:59 +0000 |
| commit | f3d7d2f7b1b0cf41c10c48eaecdab6707780e7f1 (patch) | |
| tree | 8549b6bde309d055f69ae05f79903159d8196a96 /src/lib/openjp2 | |
| parent | 0358983ee649c8ff8cdf690ec6724559bb8f2b00 (diff) | |
[trunk] Rework r2077
r2077 did expose too much of the detail implementation of OpenJPEG. Rework dependencies in between JPIP file level details and JPIP client/server arch.
Move JPIP file level functionalities back into OpenJP2 as was the case in openjpeg 1.5.x. Use new cio func.
Diffstat (limited to 'src/lib/openjp2')
| -rw-r--r-- | src/lib/openjp2/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | src/lib/openjp2/cidx_manager.c | 469 | ||||
| -rw-r--r-- | src/lib/openjp2/cidx_manager.h | 60 | ||||
| -rw-r--r-- | src/lib/openjp2/cio.c | 50 | ||||
| -rw-r--r-- | src/lib/openjp2/cio.h | 28 | ||||
| -rw-r--r-- | src/lib/openjp2/event.c | 4 | ||||
| -rw-r--r-- | src/lib/openjp2/event.h | 4 | ||||
| -rw-r--r-- | src/lib/openjp2/function_list.c | 8 | ||||
| -rw-r--r-- | src/lib/openjp2/function_list.h | 10 | ||||
| -rw-r--r-- | src/lib/openjp2/indexbox_manager.h | 139 | ||||
| -rw-r--r-- | src/lib/openjp2/j2k.c | 4 | ||||
| -rw-r--r-- | src/lib/openjp2/j2k.h | 4 | ||||
| -rw-r--r-- | src/lib/openjp2/jp2.c | 14 | ||||
| -rw-r--r-- | src/lib/openjp2/jp2.h | 14 | ||||
| -rw-r--r-- | src/lib/openjp2/openjpeg.h | 8 | ||||
| -rw-r--r-- | src/lib/openjp2/phix_manager.c | 350 | ||||
| -rw-r--r-- | src/lib/openjp2/ppix_manager.c | 352 | ||||
| -rw-r--r-- | src/lib/openjp2/thix_manager.c | 242 | ||||
| -rw-r--r-- | src/lib/openjp2/tpix_manager.c | 302 |
19 files changed, 1999 insertions, 75 deletions
diff --git a/src/lib/openjp2/CMakeLists.txt b/src/lib/openjp2/CMakeLists.txt index ed8f681c..d1e08cf6 100644 --- a/src/lib/openjp2/CMakeLists.txt +++ b/src/lib/openjp2/CMakeLists.txt @@ -7,7 +7,6 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/opj_config.h include_directories( ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h ) - # Defines the source code for the library set(OPENJPEG_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/bio.c @@ -31,6 +30,17 @@ set(OPENJPEG_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tgt.c ${CMAKE_CURRENT_SOURCE_DIR}/function_list.c ) +if(BUILD_JPIP) + add_definitions(-DUSE_JPIP) + set(OPENJPEG_SRCS + ${OPENJPEG_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/cidx_manager.c + ${CMAKE_CURRENT_SOURCE_DIR}/phix_manager.c + ${CMAKE_CURRENT_SOURCE_DIR}/ppix_manager.c + ${CMAKE_CURRENT_SOURCE_DIR}/thix_manager.c + ${CMAKE_CURRENT_SOURCE_DIR}/tpix_manager.c + ) +endif() # Build the library if(WIN32) diff --git a/src/lib/openjp2/cidx_manager.c b/src/lib/openjp2/cidx_manager.c new file mode 100644 index 00000000..0c6c669e --- /dev/null +++ b/src/lib/openjp2/cidx_manager.c @@ -0,0 +1,469 @@ +/* + * $Id: cidx_manager.c 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2003-2004, Yannick Verschueren + * 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 "opj_includes.h" + + +/* + * Write CPTR Codestream finder box + * + * @param[in] coff offset of j2k codestream + * @param[in] clen length of j2k codestream + * @param[in] cio file output handle + */ +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) + * + * @param[in] coff offset of j2k codestream + * @param[in] cstr_info codestream information + * @param[in] cio file output handle + * @return length of mainmhix box + */ +int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio); + + +/* + * Check if EPH option is used + * + * @param[in] coff offset of j2k codestream + * @param[in] markers marker information + * @param[in] marknum number of markers + * @param[in] cio file output handle + * @return true if EPH is used + */ +opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio); + + +int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen) +{ + int len, i, lenp; + opj_jp2_box_t *box; + int num_box = 0; + opj_bool EPHused; + (void)image; /* unused ? */ + + lenp = -1; + box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t)); + + for (i=0;i<2;i++){ + + if(i) + cio_seek( cio, lenp); + + lenp = cio_tell( cio); + + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_CIDX, 4); /* CIDX */ + write_cptr( offset, cstr_info.codestream_size, cio); + + write_manf( i, num_box, box, cio); + + num_box = 0; + box[num_box].length = write_mainmhix( offset, cstr_info, cio); + box[num_box].type = JPIP_MHIX; + num_box++; + + box[num_box].length = write_tpix( offset, cstr_info, j2klen, cio); + box[num_box].type = JPIP_TPIX; + num_box++; + + box[num_box].length = write_thix( offset, cstr_info, cio); + box[num_box].type = JPIP_THIX; + num_box++; + + EPHused = check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio); + + box[num_box].length = write_ppix( offset, cstr_info, EPHused, j2klen, cio); + box[num_box].type = JPIP_PPIX; + num_box++; + + box[num_box].length = write_phix( offset, cstr_info, EPHused, j2klen, cio); + box[num_box].type = JPIP_PHIX; + num_box++; + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + } + + opj_free( box); + + 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,p_manager); + box[num_box].type = JPIP_TPIX; + num_box++; + + box[num_box].length = write_thix_v2( offset, cstr_info, cio, p_manager); + box[num_box].type = JPIP_THIX; + num_box++; + + EPHused = check_EPHuse_v2( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager); + + box[num_box].length = write_ppix_v2( offset, cstr_info, EPHused, j2klen, cio,p_manager); + box[num_box].type = JPIP_PPIX; + num_box++; + + box[num_box].length = write_phix_v2( offset, cstr_info, EPHused, j2klen, cio,p_manager); + 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) +{ + int len, lenp; + + 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); +} + +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) +{ + int len, lenp, i; + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_MANF,4); /* T */ + + if (second){ /* Write only during the second pass */ + for( i=0; i<v; i++){ + cio_write( cio, box[i].length, 4); /* Box length */ + cio_write( cio, box[i].type, 4); /* Box type */ + } + } + + len = cio_tell( cio) - lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + 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 i; + int len, lenp; + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_MHIX, 4); /* MHIX */ + + cio_write( cio, cstr_info.main_head_end-cstr_info.main_head_start+1, 8); /* TLEN */ + + for(i = 1; i < cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */ + 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); + } + + len = cio_tell( cio) - lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+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 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){ + org_pos = cio_tell( cio); + cio_seek( cio, coff+markers[i].pos+2); + + Scod = cio_read( cio, 1); + if( ((Scod >> 2) & 1)) + EPHused = OPJ_TRUE; + cio_seek( cio, org_pos); + + break; + } + } + 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; +} diff --git a/src/lib/openjp2/cidx_manager.h b/src/lib/openjp2/cidx_manager.h new file mode 100644 index 00000000..17925505 --- /dev/null +++ b/src/lib/openjp2/cidx_manager.h @@ -0,0 +1,60 @@ +/* + * $Id: cidx_manager.h 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2003-2004, Yannick Verschueren + * 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. + */ + +/*! \file + * \brief Modification of jpip.h from 2KAN indexer + */ + + +#ifndef CIDX_MANAGER_H_ +# define CIDX_MANAGER_H_ + +#include "openjpeg.h" + + +/* + * Write Codestream index box (superbox) + * + * @param[in] offset offset of j2k codestream + * @param[in] cio file output handle + * @param[in] image image data + * @param[in] cstr_info codestream information + * @param[in] j2klen length of j2k codestream + * @return length of cidx box + */ +int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen); +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 ); + +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 ); + +#endif /* !CIDX_MANAGER_H_ */ diff --git a/src/lib/openjp2/cio.c b/src/lib/openjp2/cio.c index 5b2edd49..553809cc 100644 --- a/src/lib/openjp2/cio.c +++ b/src/lib/openjp2/cio.c @@ -33,7 +33,7 @@ /* ----------------------------------------------------------------------- */ -opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) { +opj_cio_t* opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) { opj_cp_t *cp = NULL; opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t)); if(!cio) return NULL; @@ -80,7 +80,7 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer return cio; } -void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) { +void opj_cio_close(opj_cio_t *cio) { if(cio) { if(cio->openmode == OPJ_STREAM_WRITE) { /* destroy the allocated buffer */ @@ -96,7 +96,7 @@ void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) { /* * Get position in byte stream. */ -OPJ_OFF_T OPJ_CALLCONV cio_tell(opj_cio_t *cio) { +OPJ_OFF_T cio_tell(opj_cio_t *cio) { return cio->bp - cio->start; } @@ -105,7 +105,7 @@ OPJ_OFF_T OPJ_CALLCONV cio_tell(opj_cio_t *cio) { * * pos : position, in number of bytes, from the beginning of the stream */ -void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) { +void cio_seek(opj_cio_t *cio, int pos) { cio->bp = cio->start + pos; } @@ -154,7 +154,7 @@ unsigned char cio_bytein(opj_cio_t *cio) { * v : value to write * n : number of bytes to write */ -unsigned int OPJ_CALLCONV cio_write(opj_cio_t *cio, unsigned long long int v, int n) { +unsigned int cio_write(opj_cio_t *cio, unsigned long long int v, int n) { int i; for (i = n - 1; i >= 0; i--) { if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) ) @@ -171,7 +171,7 @@ unsigned int OPJ_CALLCONV cio_write(opj_cio_t *cio, unsigned long long int v, in * * return : value of the n bytes read */ -unsigned int OPJ_CALLCONV cio_read(opj_cio_t *cio, int n) { +unsigned int cio_read(opj_cio_t *cio, int n) { int i; unsigned int v = 0; for (i = n - 1; i >= 0; i--) { @@ -186,13 +186,13 @@ unsigned int OPJ_CALLCONV cio_read(opj_cio_t *cio, int n) { * * n : number of bytes to skip */ -void OPJ_CALLCONV cio_skip(opj_cio_t *cio, int n) { +void cio_skip(opj_cio_t *cio, int n) { cio->bp += n; } /* ----------------------------------------------------------------------- */ -void OPJ_CALLCONV opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes) +void opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes) { const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + p_nb_bytes; @@ -201,7 +201,7 @@ void OPJ_CALLCONV opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, O memcpy(p_buffer,l_data_ptr,p_nb_bytes); } -void OPJ_CALLCONV opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes) +void opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes) { const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + p_nb_bytes - 1; OPJ_UINT32 i; @@ -213,7 +213,7 @@ void OPJ_CALLCONV opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, O } } -void OPJ_CALLCONV opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes) +void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes) { OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value); @@ -223,7 +223,7 @@ void OPJ_CALLCONV opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_va memcpy(l_data_ptr+4-p_nb_bytes,p_buffer,p_nb_bytes); } -void OPJ_CALLCONV opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes) +void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes) { OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + p_nb_bytes-1; OPJ_UINT32 i; @@ -242,7 +242,7 @@ void opj_write_double_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value) memcpy(p_buffer,l_data_ptr,sizeof(OPJ_FLOAT64)); } -void OPJ_CALLCONV opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value) +void opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value) { const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof(OPJ_FLOAT64) - 1; OPJ_UINT32 i; @@ -338,7 +338,7 @@ opj_stream_t* OPJ_CALLCONV opj_stream_default_create(opj_bool l_is_input) return opj_stream_create(J2K_STREAM_CHUNK_SIZE,l_is_input); } -OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream) +void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream) { opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; @@ -349,7 +349,7 @@ OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream) } } -OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function) +void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function) { opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; @@ -360,7 +360,7 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, o l_stream->m_read_fn = p_function; } -OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function) +void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function) { opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; @@ -370,7 +370,7 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, o l_stream->m_seek_fn = p_function; } -OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function) +void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function) { opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; @@ -381,7 +381,7 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, l_stream->m_write_fn = p_function; } -OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function) +void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function) { opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; @@ -392,19 +392,19 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, o l_stream->m_skip_fn = p_function; } -OPJ_API void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data) +void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data) { opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; l_stream->m_user_data = p_data; } -OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length) +void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length) { opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; l_stream->m_user_data_length = data_length; } -OPJ_SIZE_T OPJ_CALLCONV opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, opj_event_mgr_t * p_event_mgr) +OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, opj_event_mgr_t * p_event_mgr) { OPJ_SIZE_T l_read_nb_bytes = 0; if (p_stream->m_bytes_in_buffer >= p_size) { @@ -511,7 +511,7 @@ OPJ_SIZE_T OPJ_CALLCONV opj_stream_read_data (opj_stream_private_t * p_stream,OP } } -OPJ_SIZE_T OPJ_CALLCONV opj_stream_write_data (opj_stream_private_t * p_stream, +OPJ_SIZE_T opj_stream_write_data (opj_stream_private_t * p_stream, const OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, opj_event_mgr_t * p_event_mgr) @@ -683,7 +683,7 @@ OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_si return l_skip_nb_bytes; } -OPJ_OFF_T OPJ_CALLCONV opj_stream_tell (const opj_stream_private_t * p_stream) +OPJ_OFF_T opj_stream_tell (const opj_stream_private_t * p_stream) { return p_stream->m_byte_offset; } @@ -697,7 +697,7 @@ OPJ_OFF_T opj_stream_get_number_byte_left (const opj_stream_private_t * p_stream 0; } -OPJ_OFF_T OPJ_CALLCONV opj_stream_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr) +OPJ_OFF_T opj_stream_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr) { assert(p_size >= 0); return p_stream->m_opj_skip(p_stream,p_size,p_event_mgr); @@ -744,13 +744,13 @@ opj_bool opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz return OPJ_TRUE; } -opj_bool OPJ_CALLCONV opj_stream_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr) +opj_bool opj_stream_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr) { assert(p_size >= 0); return p_stream->m_opj_seek(p_stream,p_size,p_event_mgr); } -opj_bool OPJ_CALLCONV opj_stream_has_seek (const opj_stream_private_t * p_stream) +opj_bool opj_stream_has_seek (const opj_stream_private_t * p_stream) { return p_stream->m_seek_fn != opj_stream_default_seek; } diff --git a/src/lib/openjp2/cio.h b/src/lib/openjp2/cio.h index 08063d1d..f5c4a862 100644 --- a/src/lib/openjp2/cio.h +++ b/src/lib/openjp2/cio.h @@ -71,20 +71,20 @@ Write some bytes @param n Number of bytes to write @return Returns the number of bytes written or 0 if an error occured */ -OPJ_API unsigned int OPJ_CALLCONV cio_write(opj_cio_t *cio, unsigned long long int v, int n); +unsigned int cio_write(opj_cio_t *cio, unsigned long long int v, int n); /** Read some bytes @param cio CIO handle @param n Number of bytes to read @return Returns the value of the n bytes read */ -OPJ_API unsigned int OPJ_CALLCONV cio_read(opj_cio_t *cio, int n); +unsigned int cio_read(opj_cio_t *cio, int n); /** Skip some bytes @param cio CIO handle @param n Number of bytes to skip */ -OPJ_API void OPJ_CALLCONV cio_skip(opj_cio_t *cio, int n); +void cio_skip(opj_cio_t *cio, int n); /* ----------------------------------------------------------------------- */ /*@}*/ @@ -206,7 +206,7 @@ opj_stream_private_t; * @param p_value the value to write * @param p_nb_bytes the number of bytes to write */ -OPJ_API void OPJ_CALLCONV opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes); +void opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes); /** * Reads some bytes from the given data buffer, this function is used in Big Endian cpus. @@ -215,7 +215,7 @@ OPJ_API void OPJ_CALLCONV opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_ * @param p_nb_bytes the nb bytes to read. * @return the number of bytes read or -1 if an error occured. */ -OPJ_API void OPJ_CALLCONV opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes); +void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes); /** * Write some bytes to the given data buffer, this function is used in Little Endian cpus. @@ -224,7 +224,7 @@ OPJ_API void OPJ_CALLCONV opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT3 * @param p_nb_bytes the number of bytes to write * @return the number of bytes written or -1 if an error occured */ -OPJ_API void OPJ_CALLCONV opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes); +void opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes); /** * Reads some bytes from the given data buffer, this function is used in Little Endian cpus. @@ -233,7 +233,7 @@ OPJ_API void OPJ_CALLCONV opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_ * @param p_nb_bytes the nb bytes to read. * @return the number of bytes read or -1 if an error occured. */ -OPJ_API void OPJ_CALLCONV opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes); +void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes); /** @@ -241,7 +241,7 @@ OPJ_API void OPJ_CALLCONV opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT3 * @param p_buffer pointer the data buffer to write data to. * @param p_value the value to write */ -OPJ_API void OPJ_CALLCONV opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value); +void opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value); /*** * Write some bytes to the given data buffer, this function is used in Big Endian cpus. @@ -300,7 +300,7 @@ void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value); * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes read, or -1 if an error occured or if the stream is at the end. */ -OPJ_API OPJ_SIZE_T OPJ_CALLCONV opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr); +OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr); /** * Writes some bytes to the stream. @@ -310,7 +310,7 @@ OPJ_API OPJ_SIZE_T OPJ_CALLCONV opj_stream_read_data (opj_stream_private_t * p_s * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes writtent, or -1 if an error occured. */ -OPJ_API OPJ_SIZE_T OPJ_CALLCONV opj_stream_write_data (opj_stream_private_t * p_stream,const OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr); +OPJ_SIZE_T opj_stream_write_data (opj_stream_private_t * p_stream,const OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr); /** * Writes the content of the stream buffer to the stream. @@ -327,7 +327,7 @@ opj_bool opj_stream_flush (opj_stream_private_t * p_stream, struct opj_event_mgr * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes skipped, or -1 if an error occured. */ -OPJ_API OPJ_OFF_T OPJ_CALLCONV opj_stream_skip (opj_stream_private_t * p_stream,OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); +OPJ_OFF_T opj_stream_skip (opj_stream_private_t * p_stream,OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); /** * Tells the byte offset on the stream (similar to ftell). @@ -336,7 +336,7 @@ OPJ_API OPJ_OFF_T OPJ_CALLCONV opj_stream_skip (opj_stream_private_t * p_stream, * * @return the current position o fthe stream. */ -OPJ_API OPJ_OFF_T OPJ_CALLCONV opj_stream_tell (const opj_stream_private_t * p_stream); +OPJ_OFF_T opj_stream_tell (const opj_stream_private_t * p_stream); /** @@ -391,12 +391,12 @@ opj_bool opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz * @param p_event_mgr the user event manager to be notified of special events. * @return true if the stream is seekable. */ -OPJ_API opj_bool OPJ_CALLCONV opj_stream_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); +opj_bool opj_stream_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); /** * Tells if the given stream is seekable. */ -OPJ_API opj_bool OPJ_CALLCONV opj_stream_has_seek (const opj_stream_private_t * p_stream); +opj_bool opj_stream_has_seek (const opj_stream_private_t * p_stream); OPJ_SIZE_T opj_stream_default_read (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data); OPJ_SIZE_T opj_stream_default_write (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data); diff --git a/src/lib/openjp2/event.c b/src/lib/openjp2/event.c index cfc68c19..fa505619 100644 --- a/src/lib/openjp2/event.c +++ b/src/lib/openjp2/event.c @@ -117,7 +117,7 @@ opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, .. } /* ----------------------------------------------------------------------- */ -opj_bool OPJ_CALLCONV opj_event_msg_v2(opj_event_mgr_t* p_event_mgr, int event_type, const char *fmt, ...) { +opj_bool opj_event_msg_v2(opj_event_mgr_t* p_event_mgr, int event_type, const char *fmt, ...) { #define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ opj_msg_callback msg_handler = 00; void * l_data = 00; @@ -167,7 +167,7 @@ opj_bool OPJ_CALLCONV opj_event_msg_v2(opj_event_mgr_t* p_event_mgr, int event_t return OPJ_TRUE; } -void OPJ_CALLCONV opj_set_default_event_handler(opj_event_mgr_t * p_manager) +void opj_set_default_event_handler(opj_event_mgr_t * p_manager) { p_manager->m_error_data = 00; p_manager->m_warning_data = 00; diff --git a/src/lib/openjp2/event.h b/src/lib/openjp2/event.h index 98543b5d..111cea9f 100644 --- a/src/lib/openjp2/event.h +++ b/src/lib/openjp2/event.h @@ -89,13 +89,13 @@ opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, .. * * @return Returns true if successful, returns false otherwise */ -OPJ_API opj_bool OPJ_CALLCONV opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char *fmt, ...); +opj_bool opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char *fmt, ...); /* ----------------------------------------------------------------------- */ /** * Set the event manager with the default callback function for the 3 levels. */ -OPJ_API void OPJ_CALLCONV opj_set_default_event_handler(opj_event_mgr_t * p_manager); +void opj_set_default_event_handler(opj_event_mgr_t * p_manager); /*@}*/ diff --git a/src/lib/openjp2/function_list.c b/src/lib/openjp2/function_list.c index 4b4b0a83..183525af 100644 --- a/src/lib/openjp2/function_list.c +++ b/src/lib/openjp2/function_list.c @@ -67,7 +67,7 @@ void opj_procedure_list_destroy(opj_procedure_list_t * p_list) opj_free(p_list); } -opj_bool OPJ_CALLCONV opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure) +opj_bool opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure) { if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures) { @@ -98,17 +98,17 @@ opj_bool OPJ_CALLCONV opj_procedure_list_add_procedure (opj_procedure_list_t * p return OPJ_TRUE; } -OPJ_UINT32 OPJ_CALLCONV opj_procedure_list_get_nb_procedures (opj_procedure_list_t * p_validation_list) +OPJ_UINT32 opj_procedure_list_get_nb_procedures (opj_procedure_list_t * p_validation_list) { return p_validation_list->m_nb_procedures; } -opj_procedure* OPJ_CALLCONV opj_procedure_list_get_first_procedure (opj_procedure_list_t * p_validation_list) +opj_procedure* opj_procedure_list_get_first_procedure (opj_procedure_list_t * p_validation_list) { return p_validation_list->m_procedures; } -void OPJ_CALLCONV opj_procedure_list_clear (opj_procedure_list_t * p_validation_list) +void opj_procedure_list_clear (opj_procedure_list_t * p_validation_list) { p_validation_list->m_nb_procedures = 0; } diff --git a/src/lib/openjp2/function_list.h b/src/lib/openjp2/function_list.h index 17a50051..1c0553d6 100644 --- a/src/lib/openjp2/function_list.h +++ b/src/lib/openjp2/function_list.h @@ -88,9 +88,9 @@ void opj_procedure_list_destroy(opj_procedure_list_t * p_list); * @param p_validation_list the list of procedure to modify. * @param p_procedure the procedure to add. * - * @return OPJ_FALSE if the procedure could ne added. + * @return OPJ_TRUE if the procedure could be added. */ -OPJ_API opj_bool OPJ_CALLCONV opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure); +opj_bool opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure); /** * Gets the number of validation procedures. @@ -99,7 +99,7 @@ OPJ_API opj_bool OPJ_CALLCONV opj_procedure_list_add_procedure (opj_procedure_li * * @return the number of validation procedures. */ -OPJ_API OPJ_UINT32 OPJ_CALLCONV opj_procedure_list_get_nb_procedures (opj_procedure_list_t * p_validation_list); +OPJ_UINT32 opj_procedure_list_get_nb_procedures (opj_procedure_list_t * p_validation_list); /** * Gets the pointer on the first validation procedure. This function is similar to the C++ @@ -110,7 +110,7 @@ OPJ_API OPJ_UINT32 OPJ_CALLCONV opj_procedure_list_get_nb_procedures (opj_proced * * @return a pointer to the first procedure. */ -OPJ_API opj_procedure* OPJ_CALLCONV opj_procedure_list_get_first_procedure (opj_procedure_list_t * p_validation_list); +opj_procedure* opj_procedure_list_get_first_procedure (opj_procedure_list_t * p_validation_list); /** @@ -119,7 +119,7 @@ OPJ_API opj_procedure* OPJ_CALLCONV opj_procedure_list_get_first_procedure (opj_ * @param p_validation_list the list of procedure to clear. * */ -OPJ_API void OPJ_CALLCONV opj_procedure_list_clear (opj_procedure_list_t * p_validation_list); +void opj_procedure_list_clear (opj_procedure_list_t * p_validation_list); /*@}*/ #endif /* __FUNCTION_LIST_H */ diff --git a/src/lib/openjp2/indexbox_manager.h b/src/lib/openjp2/indexbox_manager.h new file mode 100644 index 00000000..d468e72f --- /dev/null +++ b/src/lib/openjp2/indexbox_manager.h @@ -0,0 +1,139 @@ +/* + * $Id: indexbox_manager.h 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2003-2004, Yannick Verschueren + * 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. + */ + +/*! \file + * \brief Modification of jpip.c from 2KAN indexer + */ + +#ifndef INDEXBOX_MANAGER_H_ +# define INDEXBOX_MANAGER_H_ + +#include "openjpeg.h" +#include "j2k.h" /* needed to use jp2.h */ +#include "jp2.h" + +#define JPIP_CIDX 0x63696478 /* Codestream index */ +#define JPIP_CPTR 0x63707472 /* Codestream Finder Box */ +#define JPIP_MANF 0x6d616e66 /* Manifest Box */ +#define JPIP_FAIX 0x66616978 /* Fragment array Index box */ +#define JPIP_MHIX 0x6d686978 /* Main Header Index Table */ +#define JPIP_TPIX 0x74706978 /* Tile-part Index Table box */ +#define JPIP_THIX 0x74686978 /* Tile header Index Table box */ +#define JPIP_PPIX 0x70706978 /* Precinct Packet Index Table box */ +#define JPIP_PHIX 0x70686978 /* Packet Header index Table */ +#define JPIP_FIDX 0x66696478 /* File Index */ +#define JPIP_FPTR 0x66707472 /* File Finder */ +#define JPIP_PRXY 0x70727879 /* Proxy boxes */ +#define JPIP_IPTR 0x69707472 /* Index finder box */ +#define JPIP_PHLD 0x70686c64 /* Place holder */ + + +/* + * Write tile-part Index table box (superbox) + * + * @param[in] coff offset of j2k codestream + * @param[in] cstr_info codestream information + * @param[in] j2klen length of j2k codestream + * @param[in] cio file output handle + * @return length of tpix box + */ +int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio); +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 ); + + +/* + * Write tile header index table box (superbox) + * + * @param[in] coff offset of j2k codestream + * @param[in] cstr_info codestream information pointer + * @param[in] cio file output handle + * @return length of thix box + */ +int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio); +int write_thix_v2( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ); + + +/* + * Write precinct packet index table box (superbox) + * + * @param[in] coff offset of j2k codestream + * @param[in] cstr_info codestream information + * @param[in] EPHused true if EPH option used + * @param[in] j2klen length of j2k codestream + * @param[in] cio file output handle + * @return length of ppix box + */ +int write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio); +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 ); + + +/* + * Write packet header index table box (superbox) + * + * @param[in] coff offset of j2k codestream + * @param[in] cstr_info codestream information + * @param[in] EPHused true if EPH option used + * @param[in] j2klen length of j2k codestream + * @param[in] cio file output handle + * @return length of ppix box + */ +int write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio); +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 ); + +/* + * Wriet manifest box (box) + * + * @param[in] second number to be visited + * @param[in] v number of boxes + * @param[in] box box to be manifested + * @param[in] cio file output handle + */ +void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio); + +int write_mainmhix_v2( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, + opj_event_mgr_t * p_manager ); + +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 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 ); + +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 ); + +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 ); + +#endif /* !INDEXBOX_MANAGER_H_ */ diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 82bc0627..5d4cd2e8 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -9056,7 +9056,7 @@ opj_bool opj_j2k_encode_v2( opj_j2k_v2_t * p_j2k, return OPJ_TRUE; } -opj_bool OPJ_CALLCONV opj_j2k_end_compress( opj_j2k_v2_t *p_j2k, +opj_bool opj_j2k_end_compress( opj_j2k_v2_t *p_j2k, opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager) { @@ -9071,7 +9071,7 @@ opj_bool OPJ_CALLCONV opj_j2k_end_compress( opj_j2k_v2_t *p_j2k, return OPJ_TRUE; } -OPJ_API opj_bool OPJ_CALLCONV opj_j2k_start_compress(opj_j2k_v2_t *p_j2k, +opj_bool opj_j2k_start_compress(opj_j2k_v2_t *p_j2k, opj_stream_private_t *p_stream, opj_image_t * p_image, opj_event_mgr_t * p_manager) diff --git a/src/lib/openjp2/j2k.h b/src/lib/openjp2/j2k.h index 7353071c..2782a096 100644 --- a/src/lib/openjp2/j2k.h +++ b/src/lib/openjp2/j2k.h @@ -1024,7 +1024,7 @@ opj_bool opj_j2k_encode_v2( opj_j2k_v2_t * p_j2k, * * @return true if the codec is valid. */ -OPJ_API opj_bool OPJ_CALLCONV opj_j2k_start_compress(opj_j2k_v2_t *p_j2k, +opj_bool opj_j2k_start_compress(opj_j2k_v2_t *p_j2k, opj_stream_private_t *p_stream, opj_image_t * p_image, opj_event_mgr_t * p_manager); @@ -1033,7 +1033,7 @@ OPJ_API opj_bool OPJ_CALLCONV opj_j2k_start_compress(opj_j2k_v2_t *p_j2k, * Ends the compression procedures and possibiliy add data to be read after the * codestream. */ -OPJ_API opj_bool OPJ_CALLCONV opj_j2k_end_compress( opj_j2k_v2_t *p_j2k, +opj_bool opj_j2k_end_compress( opj_j2k_v2_t *p_j2k, opj_stream_private_t *cio, opj_event_mgr_t * p_manager); diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index be66c295..0f31d383 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -1103,7 +1103,7 @@ opj_bool opj_jp2_decode(opj_jp2_v2_t *jp2, return OPJ_TRUE; } -opj_bool OPJ_CALLCONV opj_jp2_write_jp2h(opj_jp2_v2_t *jp2, +opj_bool opj_jp2_write_jp2h(opj_jp2_v2_t *jp2, opj_stream_private_t *stream, opj_event_mgr_t * p_manager ) @@ -1334,7 +1334,7 @@ void opj_jp2_setup_decoder(opj_jp2_v2_t *jp2, opj_dparameters_t *parameters) /* JP2 encoder interface */ /* ----------------------------------------------------------------------- */ -void OPJ_CALLCONV opj_jp2_setup_encoder( opj_jp2_v2_t *jp2, +void opj_jp2_setup_encoder( opj_jp2_v2_t *jp2, opj_cparameters_t *parameters, opj_image_t *image, opj_event_mgr_t * p_manager) @@ -1412,7 +1412,7 @@ void OPJ_CALLCONV opj_jp2_setup_encoder( opj_jp2_v2_t *jp2, jp2->approx = 0; /* APPROX */ } -opj_bool OPJ_CALLCONV opj_jp2_encode(opj_jp2_v2_t *jp2, +opj_bool opj_jp2_encode(opj_jp2_v2_t *jp2, opj_stream_private_t *stream, opj_event_mgr_t * p_manager) { @@ -2087,7 +2087,7 @@ opj_bool opj_jp2_read_tile_header ( opj_jp2_v2_t * p_jp2, p_manager); } -opj_bool OPJ_CALLCONV opj_jp2_write_tile ( opj_jp2_v2_t *p_jp2, +opj_bool opj_jp2_write_tile ( opj_jp2_v2_t *p_jp2, OPJ_UINT32 p_tile_index, OPJ_BYTE * p_data, OPJ_UINT32 p_data_size, @@ -2110,7 +2110,7 @@ opj_bool opj_jp2_decode_tile ( opj_jp2_v2_t * p_jp2, return opj_j2k_decode_tile (p_jp2->j2k,p_tile_index,p_data,p_data_size,p_stream,p_manager); } -void OPJ_CALLCONV opj_jp2_destroy(opj_jp2_v2_t *jp2) +void opj_jp2_destroy(opj_jp2_v2_t *jp2) { if (jp2) { /* destroy the J2K codec */ @@ -2241,7 +2241,7 @@ opj_bool opj_jp2_get_tile( opj_jp2_v2_t *p_jp2, /* JP2 encoder interface */ /* ----------------------------------------------------------------------- */ -opj_jp2_v2_t* OPJ_CALLCONV opj_jp2_create(opj_bool p_is_decoder) +opj_jp2_v2_t* opj_jp2_create(opj_bool p_is_decoder) { opj_jp2_v2_t *jp2 = (opj_jp2_v2_t*)opj_malloc(sizeof(opj_jp2_v2_t)); if (jp2) { @@ -2300,7 +2300,7 @@ opj_codestream_index_t* jp2_get_cstr_index(opj_jp2_v2_t* p_jp2) return j2k_get_cstr_index(p_jp2->j2k); } -opj_codestream_info_v2_t* OPJ_CALLCONV jp2_get_cstr_info(opj_jp2_v2_t* p_jp2) +opj_codestream_info_v2_t* jp2_get_cstr_info(opj_jp2_v2_t* p_jp2) { return j2k_get_cstr_info(p_jp2->j2k); } diff --git a/src/lib/openjp2/jp2.h b/src/lib/openjp2/jp2.h index 24670173..006c4e6d 100644 --- a/src/lib/openjp2/jp2.h +++ b/src/lib/openjp2/jp2.h @@ -265,7 +265,7 @@ opj_jp2_img_header_writer_handler_t; * * @return true if writing was successful. */ -OPJ_API opj_bool OPJ_CALLCONV opj_jp2_write_jp2h(opj_jp2_v2_t *jp2, +opj_bool opj_jp2_write_jp2h(opj_jp2_v2_t *jp2, opj_stream_private_t *stream, opj_event_mgr_t * p_manager ); @@ -300,7 +300,7 @@ opj_bool opj_jp2_decode(opj_jp2_v2_t *jp2, * @param image input filled image * @param p_manager FIXME DOC */ -OPJ_API void OPJ_CALLCONV opj_jp2_setup_encoder( opj_jp2_v2_t *jp2, +void opj_jp2_setup_encoder( opj_jp2_v2_t *jp2, opj_cparameters_t *parameters, opj_image_t *image, opj_event_mgr_t * p_manager); @@ -312,7 +312,7 @@ Encode an image into a JPEG-2000 file stream @param p_manager event manager @return Returns true if successful, returns false otherwise */ -OPJ_API opj_bool OPJ_CALLCONV opj_jp2_encode( opj_jp2_v2_t *jp2, +opj_bool opj_jp2_encode( opj_jp2_v2_t *jp2, opj_stream_private_t *stream, opj_event_mgr_t * p_manager); @@ -402,7 +402,7 @@ opj_bool opj_jp2_read_tile_header ( opj_jp2_v2_t * p_jp2, * @param p_stream the stream to write data to. * @param p_manager the user event manager. */ -OPJ_API opj_bool OPJ_CALLCONV opj_jp2_write_tile ( opj_jp2_v2_t *p_jp2, +opj_bool opj_jp2_write_tile ( opj_jp2_v2_t *p_jp2, OPJ_UINT32 p_tile_index, OPJ_BYTE * p_data, OPJ_UINT32 p_data_size, @@ -432,13 +432,13 @@ opj_bool opj_jp2_decode_tile ( opj_jp2_v2_t * p_jp2, * * @return an empty jpeg2000 file codec. */ -OPJ_API opj_jp2_v2_t* OPJ_CALLCONV opj_jp2_create (opj_bool p_is_decoder); +opj_jp2_v2_t* opj_jp2_create (opj_bool p_is_decoder); /** Destroy a JP2 decompressor handle @param jp2 JP2 decompressor handle to destroy */ -OPJ_API void OPJ_CALLCONV opj_jp2_destroy(opj_jp2_v2_t *jp2); +void opj_jp2_destroy(opj_jp2_v2_t *jp2); /** @@ -496,7 +496,7 @@ void jp2_dump (opj_jp2_v2_t* p_jp2, OPJ_INT32 flag, FILE* out_stream); * *@return the codestream information extract from the jpg2000 codec */ -OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV jp2_get_cstr_info(opj_jp2_v2_t* p_jp2); +opj_codestream_info_v2_t* jp2_get_cstr_info(opj_jp2_v2_t* p_jp2); /** * Get the codestream index from a JPEG2000 codec. diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index c9788204..581f4bfc 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -1082,26 +1082,26 @@ to contain encoded data. @param length Reading: buffer length. Writing: 0 @return Returns a CIO handle if successful, returns NULL otherwise */ -OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length); +opj_cio_t* opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length); /** Close and free a CIO handle @param cio CIO handle to free */ -OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio); +void opj_cio_close(opj_cio_t *cio); /** Get position in byte stream @param cio CIO handle @return Returns the position in bytes */ -OPJ_API OPJ_OFF_T OPJ_CALLCONV cio_tell(opj_cio_t *cio); +OPJ_OFF_T cio_tell(opj_cio_t *cio); /** Set position in byte stream @param cio CIO handle @param pos Position, in number of bytes, from the beginning of the stream */ -OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos); +void cio_seek(opj_cio_t *cio, int pos); /* <----------- */ /* V2 framework */ diff --git a/src/lib/openjp2/phix_manager.c b/src/lib/openjp2/phix_manager.c new file mode 100644 index 00000000..bb15ed37 --- /dev/null +++ b/src/lib/openjp2/phix_manager.c @@ -0,0 +1,350 @@ +/* + * $Id: phix_manager.c 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2003-2004, Yannick Verschueren + * 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. + */ + +/*! \file + * \brief Modification of jpip.c from 2KAN indexer + */ + +#include "opj_includes.h" + + +/* + * Write faix box of phix + * + * @param[in] coff offset of j2k codestream + * @param[in] compno component number + * @param[in] cstr_info codestream information + * @param[in] EPHused true if if EPH option used + * @param[in] j2klen length of j2k codestream + * @param[in] cio file output handle + * @return length of faix box + */ +int write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio); + +int write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio) +{ + 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) cio_seek( cio, lenp); + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_PHIX, 4); /* PHIX */ + + write_manf( i, cstr_info.numcomps, box, cio); + + for( compno=0; compno<cstr_info.numcomps; compno++){ + box[compno].length = write_phixfaix( coff, compno, cstr_info, EPHused, j2klen, cio); + box[compno].type = JPIP_FAIX; + } + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + } + + opj_free(box); + + 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,p_manager); + 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 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_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; + } + + 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 */ + + 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; + + cio_write( cio, nmax, size_of_coding); /* NMAX */ + cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */ + + 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"); + } + + 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 */ + + num_packet++; + } + } + } + + /* PADDING */ + while( num_packet < nmax){ + cio_write( cio, 0, size_of_coding); /* start position */ + cio_write( cio, 0, size_of_coding); /* length */ + num_packet++; + } + } + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+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; +} diff --git a/src/lib/openjp2/ppix_manager.c b/src/lib/openjp2/ppix_manager.c new file mode 100644 index 00000000..ad1d934b --- /dev/null +++ b/src/lib/openjp2/ppix_manager.c @@ -0,0 +1,352 @@ +/* + * $Id: ppix_manager.c 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2003-2004, Yannick Verschueren + * 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. + */ + +/*! \file + * \brief Modification of jpip.c from 2KAN indexer + */ + +#include "opj_includes.h" + +/* + * Write faix box of ppix + * + * @param[in] coff offset of j2k codestream + * @param[in] compno component number + * @param[in] cstr_info codestream information + * @param[in] EPHused true if if EPH option used + * @param[in] j2klen length of j2k codestream + * @param[in] cio file output handle + * @return length of faix box + */ +int write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio); + +int write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio) +{ + 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) cio_seek( cio, lenp); + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_PPIX, 4); /* PPIX */ + + write_manf( i, cstr_info.numcomps, box, cio); + + for (compno=0; compno<cstr_info.numcomps; compno++){ + box[compno].length = write_ppixfaix( coff, compno, cstr_info, EPHused, j2klen, cio); + box[compno].type = JPIP_FAIX; + } + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + } + + opj_free(box); + + 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,p_manager); + 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 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; + } + + 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 */ + + 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; + + cio_write( cio, nmax, size_of_coding); /* NMAX */ + cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */ + + 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"); + } + + 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 */ + + num_packet++; + } + } + } + + while( num_packet < nmax){ /* PADDING */ + cio_write( cio, 0, size_of_coding); /* start position */ + cio_write( cio, 0, size_of_coding); /* length */ + num_packet++; + } + } + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+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; +} diff --git a/src/lib/openjp2/thix_manager.c b/src/lib/openjp2/thix_manager.c new file mode 100644 index 00000000..fe584cbc --- /dev/null +++ b/src/lib/openjp2/thix_manager.c @@ -0,0 +1,242 @@ +/* + * $Id: thix_manager.c 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2003-2004, Yannick Verschueren + * 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. + */ + +/*! \file + * \brief Modification of jpip.c from 2KAN indexer + */ + +#include "opj_includes.h" + +/* + * Write tile-part headers mhix box + * + * @param[in] coff offset of j2k codestream + * @param[in] cstr_info codestream information + * @param[in] tileno tile number + * @param[in] cio file output handle + * @return length of mhix box + */ +int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_cio_t *cio); + +int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio) +{ + 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) + cio_seek( cio, lenp); + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_THIX, 4); /* THIX */ + write_manf( 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( coff, cstr_info, tileno, cio); + box[tileno].type = JPIP_MHIX; + } + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + } + + opj_free(box); + + 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,p_manager); + 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 i; + opj_tile_info_t tile; + opj_tp_info_t tp; + int marknum; + int len, lenp; + opj_marker_info_t *marker; + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_MHIX, 4); /* MHIX */ + + tile = cstr_info.tile[tileno]; + tp = tile.tp[0]; + + cio_write( cio, tp.tp_end_header-tp.tp_start_pos+1, 8); /* TLEN */ + + marker = cstr_info.tile[tileno].marker; + + for( i=0; i<cstr_info.tile[tileno].marknum; i++){ /* Marker restricted to 1 apparition */ + 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); + } + + /* free( marker);*/ + + len = cio_tell( cio) - lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+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; +} diff --git a/src/lib/openjp2/tpix_manager.c b/src/lib/openjp2/tpix_manager.c new file mode 100644 index 00000000..0c58a329 --- /dev/null +++ b/src/lib/openjp2/tpix_manager.c @@ -0,0 +1,302 @@ +/* + * $Id: tpix_manager.c 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2003-2004, Yannick Verschueren + * 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. + */ + +/*! \file + * \brief Modification of jpip.c from 2KAN indexer + */ + +#include "opj_includes.h" + +#define MAX(a,b) ((a)>(b)?(a):(b)) + + +/* + * Write faix box of tpix + * + * @param[in] coff offset of j2k codestream + * @param[in] compno component number + * @param[in] cstr_info codestream information + * @param[in] j2klen length of j2k codestream + * @param[in] cio file output handle + * @return length of faix box + */ +int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio); + + +int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio) +{ + int len, lenp; + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_TPIX, 4); /* TPIX */ + + write_tpixfaix( coff, 0, cstr_info, j2klen, cio); + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+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 + * + * @param[in] cstr_info codestream information + * @return number of maximum tile parts per tile + */ +int get_num_max_tile_parts( opj_codestream_info_t cstr_info); + +int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio) +{ + 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; + 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; + } + + 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 */ + + cio_write( cio, num_max_tile_parts, size_of_coding); /* NMAX */ + cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */ + 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]; + 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 */ + 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; + + cio_write( cio, Aux,4); + /*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){ + cio_write( cio, 0, size_of_coding); /* start position */ + cio_write( cio, 0, size_of_coding); /* length */ + if (version & 0x02) + cio_write( cio, 0,4); /* Aux_i,j : Auxiliary value */ + j++; + } + } + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + + return len; + +} + +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 num_max_tp = 0, i; + + for( i=0; i<cstr_info.tw*cstr_info.th; i++) + num_max_tp = MAX( cstr_info.tile[i].num_tps, num_max_tp); + + return num_max_tp; +} |
