2 * $Id: tpix_manager.c 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $
4 * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2011, Professor Benoit Macq
6 * Copyright (c) 2003-2004, Yannick Verschueren
7 * Copyright (c) 2010-2011, Kaori Hagihara
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * \brief Modification of jpip.c from 2KAN indexer
36 #include "opj_includes.h"
38 #define MAX(a,b) ((a)>(b)?(a):(b))
41 * Get number of maximum tile parts per tile
43 * @param[in] cstr_info codestream information
44 * @return number of maximum tile parts per tile
46 int get_num_max_tile_parts( opj_codestream_info_t cstr_info);
50 * Write faix box of tpix
52 * @param[in] coff offset of j2k codestream
53 * @param[in] compno component number
54 * @param[in] cstr_info codestream information
55 * @param[in] j2klen length of j2k codestream
56 * @param[in] cio file output handle
57 * @return length of faix box
60 int opj_write_tpix( int coff,
61 opj_codestream_info_t cstr_info,
62 int j2klen, opj_stream_private_t *cio,
63 opj_event_mgr_t * p_manager )
65 OPJ_BYTE l_data_header [4];
69 lenp = opj_stream_tell(cio);
70 opj_stream_skip(cio, 4, p_manager);
71 opj_write_bytes(l_data_header,JPIP_TPIX,4); /* TPIX */
72 opj_stream_write_data(cio,l_data_header,4,p_manager);
74 opj_write_tpixfaix( coff, 0, cstr_info, j2klen, cio,p_manager);
76 len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
78 opj_stream_skip(cio, lenp, p_manager);
79 opj_write_bytes(l_data_header,len,4);/* L */
80 opj_stream_write_data(cio,l_data_header,4,p_manager);
81 opj_stream_seek(cio, lenp+len,p_manager);
86 int opj_write_tpixfaix( int coff,
88 opj_codestream_info_t cstr_info,
90 opj_stream_private_t *cio,
91 opj_event_mgr_t * p_manager )
97 OPJ_UINT32 num_max_tile_parts;
98 OPJ_UINT32 size_of_coding; /* 4 or 8 */
100 OPJ_BYTE l_data_header [8];
103 num_max_tile_parts = (OPJ_UINT32)get_num_max_tile_parts( cstr_info);
105 if( j2klen > pow( 2, 32)){
107 version = num_max_tile_parts == 1 ? 1:3;
111 version = num_max_tile_parts == 1 ? 0:2;
114 lenp = opj_stream_tell(cio);
115 opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
116 opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
117 opj_stream_write_data(cio,l_data_header,4,p_manager);
118 opj_write_bytes(l_data_header,version,1); /* Version 0 = 4 bytes */
119 opj_stream_write_data(cio,l_data_header,1,p_manager);
121 opj_write_bytes(l_data_header,num_max_tile_parts,size_of_coding); /* NMAX */
122 opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
123 opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
124 opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
126 for (i = 0; i < (OPJ_UINT32)(cstr_info.tw*cstr_info.th); i++)
128 for (j = 0; j < (OPJ_UINT32)cstr_info.tile[i].num_tps; j++)
130 tp = cstr_info.tile[i].tp[j];
132 opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_start_pos-coff),size_of_coding); /* start position */
133 opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
134 opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_pos-tp.tp_start_pos+1),size_of_coding); /* length */
135 opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
139 if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
140 Aux = (OPJ_UINT32)(cstr_info.numdecompos[compno] + 1);
144 opj_write_bytes(l_data_header,Aux,4);
145 opj_stream_write_data(cio,l_data_header,4,p_manager);
147 /*cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4);*/ /* Aux_i,j : Auxiliary value */
148 /* fprintf(stderr,"AUX value %d\n",Aux);*/
153 while (j < num_max_tile_parts)
156 opj_write_bytes(l_data_header,0,size_of_coding);/* start position */
157 opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
158 opj_write_bytes(l_data_header,0,size_of_coding);/* length */
159 opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
162 opj_write_bytes(l_data_header,0,4); /* Aux_i,j : Auxiliary value */
163 opj_stream_write_data(cio,l_data_header,4,p_manager);
168 len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
169 opj_stream_seek(cio, lenp,p_manager);
170 opj_write_bytes(l_data_header,len,4);/* L */
171 opj_stream_write_data(cio,l_data_header,4,p_manager);
172 opj_stream_seek(cio, lenp+len,p_manager);
177 int get_num_max_tile_parts( opj_codestream_info_t cstr_info)
179 int num_max_tp = 0, i;
181 for( i=0; i<cstr_info.tw*cstr_info.th; i++)
182 num_max_tp = MAX( cstr_info.tile[i].num_tps, num_max_tp);