2 * $Id: phix_manager.c 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $
4 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2014, 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"
40 * Write faix box of phix
42 * @param[in] coff offset of j2k codestream
43 * @param[in] compno component number
44 * @param[in] cstr_info codestream information
45 * @param[in] EPHused true if if EPH option used
46 * @param[in] j2klen length of j2k codestream
47 * @param[in] cio file output handle
48 * @return length of faix box
51 int opj_write_phix(int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
52 int j2klen, opj_stream_private_t *cio,
53 opj_event_mgr_t * p_manager)
55 OPJ_BYTE l_data_header [8];
56 OPJ_UINT32 len, compno, i;
60 box = (opj_jp2_box_t *)opj_calloc((size_t)cstr_info.numcomps,
61 sizeof(opj_jp2_box_t));
65 for (i = 0; i < 2; i++) {
67 opj_stream_seek(cio, lenp, p_manager);
70 lenp = opj_stream_tell(cio);
71 opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
72 opj_write_bytes(l_data_header, JPIP_PHIX, 4); /* PHIX */
73 opj_stream_write_data(cio, l_data_header, 4, p_manager);
75 opj_write_manf((int)i, cstr_info.numcomps, box, cio, p_manager);
77 for (compno = 0; compno < (OPJ_UINT32)cstr_info.numcomps; compno++) {
78 box[compno].length = (OPJ_UINT32)opj_write_phixfaix(coff, (int)compno,
79 cstr_info, EPHused, j2klen, cio, p_manager);
80 box[compno].type = JPIP_FAIX;
83 len = (OPJ_UINT32)(opj_stream_tell(cio) - lenp);
84 opj_stream_seek(cio, 4, p_manager);
85 opj_write_bytes(l_data_header, len, 4); /* L */
86 opj_stream_write_data(cio, l_data_header, 4, p_manager);
87 opj_stream_seek(cio, lenp + len, p_manager);
96 int opj_write_phixfaix(int coff, int compno, opj_codestream_info_t cstr_info,
97 OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
98 opj_event_mgr_t * p_manager)
100 OPJ_UINT32 tileno, version, i, nmax, size_of_coding; /* 4 or 8 */
101 opj_tile_info_t *tile_Idx;
102 opj_packet_info_t packet;
103 int resno, precno, layno;
104 OPJ_UINT32 num_packet;
105 int numOfres, numOfprec, numOflayers;
106 OPJ_BYTE l_data_header [8];
110 packet.end_ph_pos = packet.start_pos = -1;
111 (void)EPHused; /* unused ? */
114 if (j2klen > pow(2, 32)) {
122 lenp = opj_stream_tell(cio);
123 opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
124 opj_write_bytes(l_data_header, JPIP_FAIX, 4); /* FAIX */
125 opj_stream_write_data(cio, l_data_header, 4, p_manager);
126 opj_write_bytes(l_data_header, version, 1); /* Version 0 = 4 bytes */
127 opj_stream_write_data(cio, l_data_header, 1, p_manager);
130 for (i = 0; i <= (OPJ_UINT32)cstr_info.numdecompos[compno]; i++) {
131 nmax += (OPJ_UINT32)(cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] *
132 cstr_info.numlayers);
135 opj_write_bytes(l_data_header, nmax, size_of_coding); /* NMAX */
136 opj_stream_write_data(cio, l_data_header, size_of_coding, p_manager);
137 opj_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.tw * cstr_info.th),
138 size_of_coding); /* M */
139 opj_stream_write_data(cio, l_data_header, size_of_coding, p_manager);
141 for (tileno = 0; tileno < (OPJ_UINT32)(cstr_info.tw * cstr_info.th); tileno++) {
142 tile_Idx = &cstr_info.tile[ tileno];
145 numOfres = cstr_info.numdecompos[compno] + 1;
147 for (resno = 0; resno < numOfres ; resno++) {
148 numOfprec = tile_Idx->pw[resno] * tile_Idx->ph[resno];
149 for (precno = 0; precno < numOfprec; precno++) {
150 numOflayers = cstr_info.numlayers;
151 for (layno = 0; layno < numOflayers; layno++) {
153 switch (cstr_info.prog) {
155 packet = tile_Idx->packet[((layno * numOfres + resno) * cstr_info.numcomps +
156 compno) * numOfprec + precno];
159 packet = tile_Idx->packet[((resno * numOflayers + layno) * cstr_info.numcomps +
160 compno) * numOfprec + precno];
163 packet = tile_Idx->packet[((resno * numOfprec + precno) * cstr_info.numcomps +
164 compno) * numOflayers + layno];
167 packet = tile_Idx->packet[((precno * cstr_info.numcomps + compno) * numOfres +
168 resno) * numOflayers + layno];
171 packet = tile_Idx->packet[((compno * numOfprec + precno) * numOfres + resno) *
172 numOflayers + layno];
175 fprintf(stderr, "failed to ppix indexing\n");
178 opj_write_bytes(l_data_header, (OPJ_UINT32)(packet.start_pos - coff),
179 size_of_coding); /* start position */
180 opj_stream_write_data(cio, l_data_header, size_of_coding, p_manager);
181 opj_write_bytes(l_data_header,
182 (OPJ_UINT32)(packet.end_ph_pos - packet.start_pos + 1),
183 size_of_coding); /* length */
184 opj_stream_write_data(cio, l_data_header, size_of_coding, p_manager);
192 while (num_packet < nmax) {
193 opj_write_bytes(l_data_header, 0,
194 size_of_coding); /* start position */
195 opj_stream_write_data(cio, l_data_header, size_of_coding, p_manager);
196 opj_write_bytes(l_data_header, 0,
197 size_of_coding); /* length */
198 opj_stream_write_data(cio, l_data_header, size_of_coding, p_manager);
203 len = (OPJ_UINT32)(opj_stream_tell(cio) - lenp);
204 opj_stream_seek(cio, lenp, p_manager);
205 opj_write_bytes(l_data_header, len, 4); /* L */
206 opj_stream_write_data(cio, l_data_header, 4, p_manager);
207 opj_stream_seek(cio, lenp + len, p_manager);