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/openjpip | |
| 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/openjpip')
| -rw-r--r-- | src/lib/openjpip/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | src/lib/openjpip/cidx_manager.c | 469 | ||||
| -rw-r--r-- | src/lib/openjpip/cidx_manager.h | 60 | ||||
| -rw-r--r-- | src/lib/openjpip/indexbox_manager.h | 139 | ||||
| -rw-r--r-- | src/lib/openjpip/openjpip.c | 756 | ||||
| -rw-r--r-- | src/lib/openjpip/openjpip.h | 28 | ||||
| -rw-r--r-- | src/lib/openjpip/phix_manager.c | 350 | ||||
| -rw-r--r-- | src/lib/openjpip/ppix_manager.c | 352 | ||||
| -rw-r--r-- | src/lib/openjpip/thix_manager.c | 242 | ||||
| -rw-r--r-- | src/lib/openjpip/tpix_manager.c | 302 |
10 files changed, 26 insertions, 2677 deletions
diff --git a/src/lib/openjpip/CMakeLists.txt b/src/lib/openjpip/CMakeLists.txt index 814d2931..c149ef3f 100644 --- a/src/lib/openjpip/CMakeLists.txt +++ b/src/lib/openjpip/CMakeLists.txt @@ -36,11 +36,6 @@ set(OPENJPIP_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/session_manager.c ${CMAKE_CURRENT_SOURCE_DIR}/jpip_parser.c ${CMAKE_CURRENT_SOURCE_DIR}/sock_manager.c - ${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 ) set(SERVER_SRCS diff --git a/src/lib/openjpip/cidx_manager.c b/src/lib/openjpip/cidx_manager.c deleted file mode 100644 index 0c6c669e..00000000 --- a/src/lib/openjpip/cidx_manager.c +++ /dev/null @@ -1,469 +0,0 @@ -/* - * $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/openjpip/cidx_manager.h b/src/lib/openjpip/cidx_manager.h deleted file mode 100644 index 17925505..00000000 --- a/src/lib/openjpip/cidx_manager.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * $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/openjpip/indexbox_manager.h b/src/lib/openjpip/indexbox_manager.h deleted file mode 100644 index d468e72f..00000000 --- a/src/lib/openjpip/indexbox_manager.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * $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/openjpip/openjpip.c b/src/lib/openjpip/openjpip.c index 7682de1a..8308f3e3 100644 --- a/src/lib/openjpip/openjpip.c +++ b/src/lib/openjpip/openjpip.c @@ -209,7 +209,7 @@ void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr #ifndef SERVER -dec_server_record_t * OPJ_CALLCONV init_dec_server( int port) +dec_server_record_t * init_dec_server( int port) { dec_server_record_t *record = (dec_server_record_t *)opj_malloc( sizeof(dec_server_record_t)); @@ -222,7 +222,7 @@ dec_server_record_t * OPJ_CALLCONV init_dec_server( int port) return record; } -void OPJ_CALLCONV terminate_dec_server( dec_server_record_t **rec) +void terminate_dec_server( dec_server_record_t **rec) { delete_cachelist( &(*rec)->cachelist); opj_free( (*rec)->jpipstream); @@ -236,7 +236,7 @@ void OPJ_CALLCONV terminate_dec_server( dec_server_record_t **rec) opj_free( *rec); } -client_t OPJ_CALLCONV accept_connection( dec_server_record_t *rec) +client_t accept_connection( dec_server_record_t *rec) { client_t client; @@ -247,7 +247,7 @@ client_t OPJ_CALLCONV accept_connection( dec_server_record_t *rec) return client; } -bool OPJ_CALLCONV handle_clientreq( client_t client, dec_server_record_t *rec) +bool handle_clientreq( client_t client, dec_server_record_t *rec) { bool quit = false; msgtype_t msgtype = identify_clientmsg( client); @@ -306,7 +306,7 @@ bool OPJ_CALLCONV handle_clientreq( client_t client, dec_server_record_t *rec) } -jpip_dec_param_t * OPJ_CALLCONV init_jpipdecoder( bool jp2) +jpip_dec_param_t * init_jpipdecoder( bool jp2) { jpip_dec_param_t *dec; @@ -321,7 +321,7 @@ jpip_dec_param_t * OPJ_CALLCONV init_jpipdecoder( bool jp2) } -bool OPJ_CALLCONV fread_jpip( const char fname[], jpip_dec_param_t *dec) +bool fread_jpip( const char fname[], jpip_dec_param_t *dec) { int infd; @@ -346,7 +346,7 @@ bool OPJ_CALLCONV fread_jpip( const char fname[], jpip_dec_param_t *dec) return true; } -void OPJ_CALLCONV decode_jpip( jpip_dec_param_t *dec) +void decode_jpip( jpip_dec_param_t *dec) { parse_JPIPstream( dec->jpipstream, dec->jpiplen, 0, dec->msgqueue); @@ -361,7 +361,7 @@ void OPJ_CALLCONV decode_jpip( jpip_dec_param_t *dec) dec->jp2kstream = recons_j2k( dec->msgqueue, dec->jpipstream, dec->msgqueue->first->csn, 0, 0, &dec->jp2klen); } -bool OPJ_CALLCONV fwrite_jp2k( const char fname[], jpip_dec_param_t *dec) +bool fwrite_jp2k( const char fname[], jpip_dec_param_t *dec) { int outfd; @@ -382,7 +382,7 @@ bool OPJ_CALLCONV fwrite_jp2k( const char fname[], jpip_dec_param_t *dec) return true; } -void OPJ_CALLCONV output_log( bool messages, bool metadata, bool ihdrbox, jpip_dec_param_t *dec) +void output_log( bool messages, bool metadata, bool ihdrbox, jpip_dec_param_t *dec) { if( messages) print_msgqueue( dec->msgqueue); @@ -396,7 +396,7 @@ void OPJ_CALLCONV output_log( bool messages, bool metadata, bool ihdrbox, jpip_d } } -void OPJ_CALLCONV destroy_jpipdecoder( jpip_dec_param_t **dec) +void destroy_jpipdecoder( jpip_dec_param_t **dec) { opj_free( (*dec)->jpipstream); delete_msgqueue( &(*dec)->msgqueue); @@ -409,7 +409,7 @@ void OPJ_CALLCONV destroy_jpipdecoder( jpip_dec_param_t **dec) opj_free( *dec); } -index_t * OPJ_CALLCONV get_index_from_JP2file( int fd) +index_t * get_index_from_JP2file( int fd) { char *data; @@ -437,744 +437,14 @@ index_t * OPJ_CALLCONV get_index_from_JP2file( int fd) return parse_jp2file( fd); } -void OPJ_CALLCONV destroy_index( index_t **idx) +void destroy_index( index_t **idx) { delete_index( idx); } -void OPJ_CALLCONV output_index( index_t *index) +void output_index( index_t *index) { print_index( *index); } -/* ---------------------------------------------------------------------- */ -/* COMPRESSION FUNCTIONS*/ -typedef struct opj_decompression -{ - /** Main header reading function handler*/ - opj_bool (*opj_read_header) ( struct opj_stream_private * cio, - void * p_codec, - opj_image_t **p_image, - struct opj_event_mgr * p_manager); - /** Decoding function */ - opj_bool (*opj_decode) ( void * p_codec, - struct opj_stream_private *p_cio, - opj_image_t *p_image, - struct opj_event_mgr * p_manager); - /** FIXME DOC */ - opj_bool (*opj_read_tile_header)( void * p_codec, - OPJ_UINT32 * p_tile_index, - OPJ_UINT32* p_data_size, - OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0, - OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1, - OPJ_UINT32 * p_nb_comps, - opj_bool * p_should_go_on, - struct opj_stream_private *p_cio, - struct opj_event_mgr * p_manager); - /** FIXME DOC */ - opj_bool (*opj_decode_tile_data)( void * p_codec, - OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, - OPJ_UINT32 p_data_size, - struct opj_stream_private *p_cio, - struct opj_event_mgr * p_manager); - /** Reading function used after codestream if necessary */ - opj_bool (* opj_end_decompress) ( void *p_codec, - struct opj_stream_private *cio, - struct opj_event_mgr * p_manager); - /** Codec destroy function handler*/ - void (*opj_destroy) (void * p_codec); - /** Setup decoder function handler */ - void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param); - /** Set decode area function handler */ - opj_bool (*opj_set_decode_area) ( void * p_codec, - opj_image_t* p_image, - OPJ_INT32 p_start_x, OPJ_INT32 p_end_x, - OPJ_INT32 p_start_y, OPJ_INT32 p_end_y, - struct opj_event_mgr * p_manager); - - /** Get tile function */ - opj_bool (*opj_get_decoded_tile) ( void *p_codec, - opj_stream_private_t *p_cio, - opj_image_t *p_image, - struct opj_event_mgr * p_manager, - OPJ_UINT32 tile_index); - - /** Set the decoded resolution factor */ - opj_bool (*opj_set_decoded_resolution_factor) ( void * p_codec, - OPJ_UINT32 res_factor, - opj_event_mgr_t * p_manager); - -}opj_decompression_t; - -typedef struct opj_compression -{ - opj_bool (* opj_start_compress) ( void *p_codec, - struct opj_stream_private *cio, - struct opj_image * p_image, - struct opj_event_mgr * p_manager); - - opj_bool (* opj_encode) ( void * p_codec, - struct opj_stream_private *p_cio, - struct opj_event_mgr * p_manager); - - opj_bool (* opj_write_tile) ( void * p_codec, - OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, - OPJ_UINT32 p_data_size, - struct opj_stream_private * p_cio, - struct opj_event_mgr * p_manager); - - opj_bool (* opj_end_compress) ( void * p_codec, - struct opj_stream_private *p_cio, - struct opj_event_mgr * p_manager); - - void (* opj_destroy) (void * p_codec); - - void (*opj_setup_encoder) ( void * p_codec, - opj_cparameters_t * p_param, - struct opj_image * p_image, - struct opj_event_mgr * p_manager); - -}opj_compression_t; - -typedef struct opj_codec_private -{ - /** FIXME DOC */ - union - { - opj_decompression_t m_decompression; - opj_compression_t m_compression; - } m_codec_data; - /** FIXME DOC*/ - void * m_codec; - /** Event handler */ - opj_event_mgr_t m_event_mgr; - /** Flag to indicate if the codec is used to decode or encode*/ - opj_bool is_decompressor; - void (*opj_dump_codec) (void * p_codec, OPJ_INT32 info_flag, FILE* output_stream); - opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec); - opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec); -} -opj_codec_private_t; - -static opj_bool opj_jp2_write_jp( opj_jp2_v2_t *jp2, - opj_stream_private_t *cio, - opj_event_mgr_t * p_manager ) -{ - /* 12 bytes will be read */ - unsigned char l_signature_data [12]; - - /* preconditions */ - assert(cio != 00); - assert(jp2 != 00); - assert(p_manager != 00); - - /* write box length */ - opj_write_bytes(l_signature_data,12,4); - /* writes box type */ - opj_write_bytes(l_signature_data+4,JP2_JP,4); - /* writes magic number*/ - opj_write_bytes(l_signature_data+8,0x0d0a870a,4); - - if (opj_stream_write_data(cio,l_signature_data,12,p_manager) != 12) { - return OPJ_FALSE; - } - - return OPJ_TRUE; -} - -static opj_bool opj_jp2_write_ftyp(opj_jp2_v2_t *jp2, - opj_stream_private_t *cio, - opj_event_mgr_t * p_manager ) -{ - unsigned int i; - unsigned int l_ftyp_size = 16 + 4 * jp2->numcl; - unsigned char * l_ftyp_data, * l_current_data_ptr; - opj_bool l_result; - - /* preconditions */ - assert(cio != 00); - assert(jp2 != 00); - assert(p_manager != 00); - - l_ftyp_data = (unsigned char *) opj_malloc(l_ftyp_size); - - if (l_ftyp_data == 00) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to handle ftyp data\n"); - return OPJ_FALSE; - } - - memset(l_ftyp_data,0,l_ftyp_size); - - l_current_data_ptr = l_ftyp_data; - - opj_write_bytes(l_current_data_ptr, l_ftyp_size,4); /* box size */ - l_current_data_ptr += 4; - - opj_write_bytes(l_current_data_ptr, JP2_FTYP,4); /* FTYP */ - l_current_data_ptr += 4; - - opj_write_bytes(l_current_data_ptr, jp2->brand,4); /* BR */ - l_current_data_ptr += 4; - - opj_write_bytes(l_current_data_ptr, jp2->minversion,4); /* MinV */ - l_current_data_ptr += 4; - - for (i = 0; i < jp2->numcl; i++) { - opj_write_bytes(l_current_data_ptr, jp2->cl[i],4); /* CL */ - } - - l_result = (opj_stream_write_data(cio,l_ftyp_data,l_ftyp_size,p_manager) == l_ftyp_size); - if (! l_result) - { - opj_event_msg_v2(p_manager, EVT_ERROR, "Error while writing ftyp data to stream\n"); - } - - opj_free(l_ftyp_data); - - return l_result; -} - -static opj_bool opj_jp2_default_validation ( opj_jp2_v2_t * jp2, - opj_stream_private_t *cio, - opj_event_mgr_t * p_manager - ) -{ - opj_bool l_is_valid = OPJ_TRUE; - unsigned int i; - - /* preconditions */ - assert(jp2 != 00); - assert(cio != 00); - assert(p_manager != 00); - - /* JPEG2000 codec validation */ - /*TODO*/ - - /* STATE checking */ - /* make sure the state is at 0 */ - l_is_valid &= (jp2->jp2_state == JP2_STATE_NONE); - - /* make sure not reading a jp2h ???? WEIRD */ - l_is_valid &= (jp2->jp2_img_state == JP2_IMG_STATE_NONE); - - /* POINTER validation */ - /* make sure a j2k codec is present */ - l_is_valid &= (jp2->j2k != 00); - - /* make sure a procedure list is present */ - l_is_valid &= (jp2->m_procedure_list != 00); - - /* make sure a validation list is present */ - l_is_valid &= (jp2->m_validation_list != 00); - - /* PARAMETER VALIDATION */ - /* number of components */ - l_is_valid &= (jp2->numcl > 0); - /* width */ - l_is_valid &= (jp2->h > 0); - /* height */ - l_is_valid &= (jp2->w > 0); - /* precision */ - for (i = 0; i < jp2->numcomps; ++i) { - l_is_valid &= (jp2->comps[i].bpcc > 0); - } - - /* METH */ - l_is_valid &= ((jp2->meth > 0) && (jp2->meth < 3)); - - /* stream validation */ - /* back and forth is needed */ - l_is_valid &= opj_stream_has_seek(cio); - - return l_is_valid; -} - -static void opj_jp2_setup_encoding_validation (opj_jp2_v2_t *jp2) -{ - /* preconditions */ - assert(jp2 != 00); - - opj_procedure_list_add_procedure(jp2->m_validation_list, (opj_procedure)opj_jp2_default_validation); - /* DEVELOPER CORNER, add your custom validation procedure */ -} - -static opj_bool opj_jp2_skip_jp2c( opj_jp2_v2_t *jp2, - opj_stream_private_t *stream, - opj_event_mgr_t * p_manager ) -{ - /* preconditions */ - assert(jp2 != 00); - assert(stream != 00); - assert(p_manager != 00); - - jp2->j2k_codestream_offset = opj_stream_tell(stream); - - if (opj_stream_skip(stream,8,p_manager) != 8) { - return OPJ_FALSE; - } - - return OPJ_TRUE; -} - -static opj_bool opj_jpip_skip_iptr( opj_jp2_v2_t *jp2, - opj_stream_private_t *stream, - opj_event_mgr_t * p_manager ) -{ - /* preconditions */ - assert(jp2 != 00); - assert(stream != 00); - assert(p_manager != 00); - - jp2->jpip_iptr_offset = opj_stream_tell(stream); - - if (opj_stream_skip(stream,24,p_manager) != 24) { - return OPJ_FALSE; - } - - return OPJ_TRUE; -} - -static void opj_jpip_setup_header_writing (opj_jp2_v2_t *jp2) -{ - /* preconditions */ - assert(jp2 != 00); - - opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_jp ); - opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_ftyp ); - opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_jp2h ); - opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_skip_iptr ); - opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_skip_jp2c ); - - /* DEVELOPER CORNER, insert your custom procedures */ - -} - -static opj_bool opj_jp2_exec ( opj_jp2_v2_t * jp2, - opj_procedure_list_t * p_procedure_list, - opj_stream_private_t *stream, - opj_event_mgr_t * p_manager - ) - -{ - opj_bool (** l_procedure) (opj_jp2_v2_t * jp2, opj_stream_private_t *, opj_event_mgr_t *) = 00; - opj_bool l_result = OPJ_TRUE; - OPJ_UINT32 l_nb_proc, i; - - /* preconditions */ - assert(p_procedure_list != 00); - assert(jp2 != 00); - assert(stream != 00); - assert(p_manager != 00); - - l_nb_proc = opj_procedure_list_get_nb_procedures(p_procedure_list); - l_procedure = (opj_bool (**) (opj_jp2_v2_t * jp2, opj_stream_private_t *, opj_event_mgr_t *)) opj_procedure_list_get_first_procedure(p_procedure_list); - - for (i=0;i<l_nb_proc;++i) { - l_result = l_result && (*l_procedure) (jp2,stream,p_manager); - ++l_procedure; - } - - /* and clear the procedure list at the end. */ - opj_procedure_list_clear(p_procedure_list); - return l_result; -} - -static opj_bool opj_jpip_start_compress(opj_jp2_v2_t *jp2, - opj_stream_private_t *stream, - opj_image_t * p_image, - opj_event_mgr_t * p_manager - ) -{ - /* preconditions */ - assert(jp2 != 00); - assert(stream != 00); - assert(p_manager != 00); - - /* customization of the validation */ - opj_jp2_setup_encoding_validation (jp2); - - /* validation of the parameters codec */ - if (! opj_jp2_exec(jp2,jp2->m_validation_list,stream,p_manager)) { - return OPJ_FALSE; - } - - /* customization of the encoding */ - opj_jpip_setup_header_writing(jp2); - - /* write header */ - if (! opj_jp2_exec (jp2,jp2->m_procedure_list,stream,p_manager)) { - return OPJ_FALSE; - } - - return opj_j2k_start_compress(jp2->j2k,stream,p_image,p_manager); -} - -static opj_bool opj_jpip_write_iptr(opj_jp2_v2_t *jp2, - opj_stream_private_t *cio, - opj_event_mgr_t * p_manager ) -{ - OPJ_OFF_T j2k_codestream_exit; - OPJ_BYTE l_data_header [24]; - - /* preconditions */ - assert(jp2 != 00); - assert(cio != 00); - assert(p_manager != 00); - assert(opj_stream_has_seek(cio)); - - j2k_codestream_exit = opj_stream_tell(cio); - opj_write_bytes(l_data_header, 24, 4); /* size of iptr */ - opj_write_bytes(l_data_header + 4,JPIP_IPTR,4); /* IPTR */ -#if 0 - opj_write_bytes(l_data_header + 4 + 4, 0, 8); /* offset */ - opj_write_bytes(l_data_header + 8 + 8, 0, 8); /* length */ -#else - opj_write_double(l_data_header + 4 + 4, 0); /* offset */ - opj_write_double(l_data_header + 8 + 8, 0); /* length */ -#endif - - if (! opj_stream_seek(cio,jp2->jpip_iptr_offset,p_manager)) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); - return OPJ_FALSE; - } - - if (opj_stream_write_data(cio,l_data_header,24,p_manager) != 24) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); - return OPJ_FALSE; - } - - if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); - return OPJ_FALSE; - } - - return OPJ_TRUE; -} - -static opj_bool opj_jpip_write_fidx(opj_jp2_v2_t *jp2, - opj_stream_private_t *cio, - opj_event_mgr_t * p_manager ) -{ - OPJ_OFF_T j2k_codestream_exit; - OPJ_BYTE l_data_header [24]; - - /* preconditions */ - assert(jp2 != 00); - assert(cio != 00); - assert(p_manager != 00); - assert(opj_stream_has_seek(cio)); - - opj_write_bytes(l_data_header, 24, 4); /* size of iptr */ - opj_write_bytes(l_data_header + 4,JPIP_FIDX,4); /* IPTR */ - opj_write_double(l_data_header + 4 + 4, 0); /* offset */ - opj_write_double(l_data_header + 8 + 8, 0); /* length */ - - if (opj_stream_write_data(cio,l_data_header,24,p_manager) != 24) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); - return OPJ_FALSE; - } - - j2k_codestream_exit = opj_stream_tell(cio); - if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); - return OPJ_FALSE; - } - - return OPJ_TRUE; -} - -static opj_bool opj_jpip_write_cidx(opj_jp2_v2_t *jp2, - opj_stream_private_t *cio, - opj_event_mgr_t * p_manager ) -{ - OPJ_OFF_T j2k_codestream_exit; - OPJ_BYTE l_data_header [24]; - - /* preconditions */ - assert(jp2 != 00); - assert(cio != 00); - assert(p_manager != 00); - assert(opj_stream_has_seek(cio)); - - j2k_codestream_exit = opj_stream_tell(cio); - opj_write_bytes(l_data_header, 24, 4); /* size of iptr */ - opj_write_bytes(l_data_header + 4,JPIP_CIDX,4); /* IPTR */ -#if 0 - opj_write_bytes(l_data_header + 4 + 4, 0, 8); /* offset */ - opj_write_bytes(l_data_header + 8 + 8, 0, 8); /* length */ -#else - opj_write_double(l_data_header + 4 + 4, 0); /* offset */ - opj_write_double(l_data_header + 8 + 8, 0); /* length */ -#endif - - if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); - return OPJ_FALSE; - } - - if (opj_stream_write_data(cio,l_data_header,24,p_manager) != 24) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); - return OPJ_FALSE; - } - - j2k_codestream_exit = opj_stream_tell(cio); - if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); - return OPJ_FALSE; - } - - return OPJ_TRUE; -} - -static void write_prxy_v2( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager ) -{ - OPJ_BYTE l_data_header [8]; - int len, lenp; - -#if 0 - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_PRXY, 4); /* IPTR */ -#else - lenp = opj_stream_tell(cio); - opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ - opj_write_bytes(l_data_header,JPIP_PRXY,4); /* IPTR */ - opj_stream_write_data(cio,l_data_header,4,p_manager); -#endif - -#if 0 - cio_write( cio, offset_jp2c, 8); /* OOFF */ - cio_write( cio, length_jp2c, 4); /* OBH part 1 */ - cio_write( cio, JP2_JP2C, 4); /* OBH part 2 */ -#else - opj_write_bytes( l_data_header, offset_jp2c, 8); /* OOFF */ - opj_stream_write_data(cio,l_data_header,8,p_manager); - opj_write_bytes( l_data_header, length_jp2c, 4); /* OBH part 1 */ - opj_write_bytes( l_data_header+4, JP2_JP2C, 4); /* OBH part 2 */ - opj_stream_write_data(cio,l_data_header,8,p_manager); -#endif - -#if 0 - cio_write( cio, 1,1); /* NI */ -#else - opj_write_bytes( l_data_header, 1, 1);/* NI */ - opj_stream_write_data(cio,l_data_header,1,p_manager); -#endif - -#if 0 - cio_write( cio, offset_idx, 8); /* IOFF */ - cio_write( cio, length_idx, 4); /* IBH part 1 */ - cio_write( cio, JPIP_CIDX, 4); /* IBH part 2 */ -#else - opj_write_bytes( l_data_header, offset_idx, 8); /* IOFF */ - opj_stream_write_data(cio,l_data_header,8,p_manager); - opj_write_bytes( l_data_header, length_idx, 4); /* IBH part 1 */ - opj_write_bytes( l_data_header+4, JPIP_CIDX, 4); /* IBH part 2 */ - opj_stream_write_data(cio,l_data_header,8,p_manager); -#endif - -#if 0 - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); -#else - len = opj_stream_tell(cio)-lenp; - opj_stream_skip(cio, lenp, p_manager); - opj_write_bytes(l_data_header,len,4);/* L */ - opj_stream_write_data(cio,l_data_header,4,p_manager); - opj_stream_seek(cio, lenp+len,p_manager); -#endif -} - - -static int write_fidx_v2( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager ) -{ - OPJ_BYTE l_data_header [4]; - int len, lenp; - -#if 0 - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_FIDX, 4); /* IPTR */ -#else - lenp = opj_stream_tell(cio); - opj_stream_skip(cio, 4, p_manager); - opj_write_bytes(l_data_header,JPIP_FIDX,4); /* FIDX */ - opj_stream_write_data(cio,l_data_header,4,p_manager); -#endif - - write_prxy_v2( offset_jp2c, length_jp2c, offset_idx, length_idx, cio,p_manager); - -#if 0 - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); -#else - len = opj_stream_tell(cio)-lenp; - opj_stream_skip(cio, lenp, p_manager); - opj_write_bytes(l_data_header,len,4);/* L */ - opj_stream_write_data(cio,l_data_header,4,p_manager); - opj_stream_seek(cio, lenp+len,p_manager); -#endif - - return len; -} - -static opj_bool opj_jpip_write_jp2c(opj_jp2_v2_t *jp2, - opj_stream_private_t *cio, - opj_event_mgr_t * p_manager ) -{ - OPJ_OFF_T j2k_codestream_exit; - opj_codestream_info_t cstr_info; - OPJ_BYTE l_data_header [8]; - OPJ_UINT32 len_jp2c; - int len_cidx; - int len_fidx; - int pos_jp2c; - int pos_fidx; - int pos_cidx; - - /* preconditions */ - assert(jp2 != 00); - assert(cio != 00); - assert(p_manager != 00); - assert(opj_stream_has_seek(cio)); - - j2k_codestream_exit = opj_stream_tell(cio); - len_jp2c = j2k_codestream_exit - jp2->j2k_codestream_offset; - pos_jp2c = jp2->j2k_codestream_offset; - opj_write_bytes(l_data_header, len_jp2c, 4); /* size of codestream */ - opj_write_bytes(l_data_header + 4,JP2_JP2C,4); /* JP2C */ - - if (! opj_stream_seek(cio,jp2->j2k_codestream_offset,p_manager)) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); - return OPJ_FALSE; - } - - if (opj_stream_write_data(cio,l_data_header,8,p_manager) != 8) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); - return OPJ_FALSE; - } - - if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); - return OPJ_FALSE; - } - - /* CIDX */ - pos_cidx = opj_stream_tell( cio); - /*cinfo = jp2_get_cstr_info(jp2);*/ - assert( 0 ); /* MM: FIXME */ - len_cidx = write_cidx_v2( pos_jp2c+8, cio, cstr_info, len_jp2c-8,p_manager); - - /* FIDX */ - pos_fidx = opj_stream_tell( cio); - len_fidx = write_fidx_v2( pos_jp2c, len_jp2c, pos_cidx, len_cidx, cio, p_manager); - - return OPJ_TRUE; -} - -static void opj_jp2_setup_end_header_writing (opj_jp2_v2_t *jp2) -{ - /* preconditions */ - assert(jp2 != 00); - - opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_iptr ); - opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_jp2c ); -#if 0 - opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_cidx ); - opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_fidx ); -#endif - /* DEVELOPER CORNER, add your custom procedures */ -} - -static opj_bool opj_jpip_end_compress( opj_jp2_v2_t *jp2, - opj_stream_private_t *cio, - opj_event_mgr_t * p_manager - ) -{ - /* preconditions */ - assert(jp2 != 00); - assert(cio != 00); - assert(p_manager != 00); - - /* customization of the end encoding */ - opj_jp2_setup_end_header_writing(jp2); - - if (! opj_j2k_end_compress(jp2->j2k,cio,p_manager)) { - return OPJ_FALSE; - } - - /* write header */ - return opj_jp2_exec(jp2,jp2->m_procedure_list,cio,p_manager); -} - - -opj_codec_t* OPJ_CALLCONV opj_jpip_create_compress(OPJ_CODEC_FORMAT p_format) -{ - opj_codec_private_t *l_codec = 00; - - l_codec = (opj_codec_private_t*)opj_calloc(1, sizeof(opj_codec_private_t)); - if (!l_codec) { - return 00; - } - memset(l_codec, 0, sizeof(opj_codec_private_t)); - - l_codec->is_decompressor = 0; - - switch(p_format) { - case CODEC_JP2: - /* get a JP2 decoder handle */ - l_codec->m_codec_data.m_compression.opj_encode = (opj_bool (*) (void *, - struct opj_stream_private *, - struct opj_event_mgr * )) opj_jp2_encode; - - l_codec->m_codec_data.m_compression.opj_end_compress = (opj_bool (*) ( void *, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_jpip_end_compress; - - l_codec->m_codec_data.m_compression.opj_start_compress = (opj_bool (*) (void *, - struct opj_stream_private *, - struct opj_image * , - struct opj_event_mgr *)) opj_jpip_start_compress; - - l_codec->m_codec_data.m_compression.opj_write_tile = (opj_bool (*) (void *, - OPJ_UINT32, - OPJ_BYTE*, - OPJ_UINT32, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_jp2_write_tile; - - l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_jp2_destroy; - - l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) ( void *, - opj_cparameters_t *, - struct opj_image *, - struct opj_event_mgr * )) opj_jp2_setup_encoder; - - l_codec->m_codec = opj_jp2_create(OPJ_FALSE); - if (! l_codec->m_codec) { - opj_free(l_codec); - return 00; - } - - break; - - case CODEC_UNKNOWN: - case CODEC_JPT: - default: - opj_free(l_codec); - return 00; - } - - opj_set_default_event_handler(&(l_codec->m_event_mgr)); - return (opj_codec_t*) l_codec; -} - #endif /*SERVER*/ diff --git a/src/lib/openjpip/openjpip.h b/src/lib/openjpip/openjpip.h index 584a69b3..c08c3d86 100644 --- a/src/lib/openjpip/openjpip.h +++ b/src/lib/openjpip/openjpip.h @@ -172,14 +172,14 @@ typedef SOCKET client_t; * @param[in] port opening tcp port (valid No. 49152-65535) * @return intialized decoding server record pointer */ -OPJ_API dec_server_record_t * OPJ_CALLCONV init_dec_server( int port); +dec_server_record_t * init_dec_server( int port); /** * Terminate the image decoding server * * @param[in] rec address of deleting decoding server static record pointer */ -OPJ_API void OPJ_CALLCONV terminate_dec_server( dec_server_record_t **rec); +void terminate_dec_server( dec_server_record_t **rec); /** * Accept client connection @@ -187,7 +187,7 @@ OPJ_API void OPJ_CALLCONV terminate_dec_server( dec_server_record_t **rec); * @param[in] rec decoding server static record pointer * @return client socket ID, -1 if failed */ -OPJ_API client_t OPJ_CALLCONV accept_connection( dec_server_record_t *rec); +client_t accept_connection( dec_server_record_t *rec); /** * Handle client request @@ -196,7 +196,7 @@ OPJ_API client_t OPJ_CALLCONV accept_connection( dec_server_record_t *rec); * @param[in] rec decoding server static record pointer * @return true if succeed */ -OPJ_API bool OPJ_CALLCONV handle_clientreq( client_t client, dec_server_record_t *rec); +bool handle_clientreq( client_t client, dec_server_record_t *rec); #endif /*SERVER*/ @@ -229,14 +229,14 @@ typedef struct jpip_dec_param{ * @param[in] jp2 true in case of jp2 file encoding, else j2k file encoding * @return JPIP decoding parameters pointer */ -OPJ_API jpip_dec_param_t * OPJ_CALLCONV init_jpipdecoder( bool jp2); +jpip_dec_param_t * init_jpipdecoder( bool jp2); /** * Destroy jpip decoding parameters * * @param[in] dec address of JPIP decoding parameters pointer */ -OPJ_API void OPJ_CALLCONV destroy_jpipdecoder( jpip_dec_param_t **dec); +void destroy_jpipdecoder( jpip_dec_param_t **dec); /** * Read jpip codestream from a file @@ -245,14 +245,14 @@ OPJ_API void OPJ_CALLCONV destroy_jpipdecoder( jpip_dec_param_t **dec); * @param[in] dec JPIP decoding parameters pointer * @return true if succeed */ -OPJ_API bool OPJ_CALLCONV fread_jpip( const char fname[], jpip_dec_param_t *dec); +bool fread_jpip( const char fname[], jpip_dec_param_t *dec); /** * Decode jpip codestream * * @param[in] dec JPIP decoding parameters pointer */ -OPJ_API void OPJ_CALLCONV decode_jpip( jpip_dec_param_t *dec); +void decode_jpip( jpip_dec_param_t *dec); /** * Write J2K/JP2 codestream to a file @@ -261,7 +261,7 @@ OPJ_API void OPJ_CALLCONV decode_jpip( jpip_dec_param_t *dec); * @param[in] dec JPIP decoding parameters pointer * @return true if succeed */ -OPJ_API bool OPJ_CALLCONV fwrite_jp2k( const char fname[], jpip_dec_param_t *dec); +bool fwrite_jp2k( const char fname[], jpip_dec_param_t *dec); /** * Option; print out parameter values to stderr @@ -271,7 +271,7 @@ OPJ_API bool OPJ_CALLCONV fwrite_jp2k( const char fname[], jpip_dec_param_t *dec * @param[in] ihdrbox true if image header data is to be printed out * @param[in] dec JPIP decoding parameters pointer */ -OPJ_API void OPJ_CALLCONV output_log( bool messages, bool metadata, bool ihdrbox, jpip_dec_param_t *dec); +void output_log( bool messages, bool metadata, bool ihdrbox, jpip_dec_param_t *dec); /* * test the format of index (cidx) box in JP2 file @@ -286,14 +286,14 @@ typedef index_param_t index_t; * @param[in] fd file descriptor of the JP2 file * @return pointer to the generated structure of index parameters */ -OPJ_API index_t * OPJ_CALLCONV get_index_from_JP2file( int fd); +index_t * get_index_from_JP2file( int fd); /** * Destroy index parameters * * @param[in,out] idx addressof the index pointer */ -OPJ_API void OPJ_CALLCONV destroy_index( index_t **idx); +void destroy_index( index_t **idx); /** @@ -301,9 +301,7 @@ OPJ_API void OPJ_CALLCONV destroy_index( index_t **idx); * * @param[in] index index parameters */ -OPJ_API void OPJ_CALLCONV output_index( index_t *index); - -OPJ_API opj_codec_t* OPJ_CALLCONV opj_jpip_create_compress(OPJ_CODEC_FORMAT format); +void output_index( index_t *index); #endif /*SERVER*/ diff --git a/src/lib/openjpip/phix_manager.c b/src/lib/openjpip/phix_manager.c deleted file mode 100644 index bb15ed37..00000000 --- a/src/lib/openjpip/phix_manager.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - * $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/openjpip/ppix_manager.c b/src/lib/openjpip/ppix_manager.c deleted file mode 100644 index ad1d934b..00000000 --- a/src/lib/openjpip/ppix_manager.c +++ /dev/null @@ -1,352 +0,0 @@ -/* - * $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/openjpip/thix_manager.c b/src/lib/openjpip/thix_manager.c deleted file mode 100644 index fe584cbc..00000000 --- a/src/lib/openjpip/thix_manager.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - * $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/openjpip/tpix_manager.c b/src/lib/openjpip/tpix_manager.c deleted file mode 100644 index 0c58a329..00000000 --- a/src/lib/openjpip/tpix_manager.c +++ /dev/null @@ -1,302 +0,0 @@ -/* - * $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; -} |
