4 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2014, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 #ifndef BOX_MANAGER_H_
32 # define BOX_MANAGER_H_
34 #include "byte_manager.h"
37 typedef struct box_param {
38 int fd; /**< file descriptor*/
39 OPJ_OFF_T offset; /**< byte position of the whole Box (LBox) in the file*/
40 Byte_t headlen; /**< header length 8 or 16*/
41 Byte8_t length; /**< length of the whole Box*/
42 char type[4]; /**< type of information in the DBox*/
43 struct box_param *next; /**< pointer to the next box*/
47 /** Box list parameters*/
48 typedef struct boxlist_param {
49 box_param_t *first; /**< first box pointer of the list*/
50 box_param_t *last; /**< last box pointer of the list*/
57 * @return pointer to the generated box list
59 boxlist_param_t * gene_boxlist(void);
62 * get box structure of JP2 file
64 * @param[in] fd file descriptor
65 * @param[in] offset offset of the decomposing region
66 * @param[in] length length of the decomposing region
67 * @return pointer to the generated boxlist
69 boxlist_param_t * get_boxstructure(int fd, OPJ_OFF_T offset, OPJ_SIZE_T length);
73 * generate box from JP2 file at the given offset
75 * @param[in] fd file discriptor of the JP2 file
76 * @param[in] offset Box offset
77 * @return pointer to the structure of generate box parameters
79 box_param_t * gene_boxbyOffset(int fd, OPJ_OFF_T offset);
83 * generate box from code stream (JPP or JPT stream) at the given offset
85 * @param[in] stream code stream of a box
86 * @param[in] offset Box offset of the whole stream
87 * @return pointer to the structure of generate box parameters
89 box_param_t * gene_boxbyOffinStream(Byte_t *stream, OPJ_OFF_T offset);
92 * generate(search) box from JP2 file
94 * @param[in] fd file discriptor of the JP2 file
95 * @param[in] offset start Byte position of the search
96 * @param[in] length Byte length of the search, if 0, size to the end of file
97 * @param[in] TBox Box Type
98 * @return pointer to the structure of generate/found box parameters
100 box_param_t * gene_boxbyType(int fd, OPJ_OFF_T offset, OPJ_SIZE_T length,
104 * generate(search) box from code stream
106 * @param[in] stream code stream ( from the first byte)
107 * @param[in] offset start Byte position of the search
108 * @param[in] length Byte length of the search, if 0, size to the end of file
109 * @param[in] TBox Box Type
110 * @return pointer to the structure of generate/found box parameters
112 box_param_t * gene_boxbyTypeinStream(Byte_t *stream, OPJ_OFF_T offset,
113 OPJ_SIZE_T length, const char TBox[]);
116 * generate child box from JP2 file at the given offset
118 * @param[in] superbox super box pointer
119 * @param[in] offset offset from DBox first byte of superbox
120 * @return pointer to the structure of generate box parameters
122 box_param_t * gene_childboxbyOffset(box_param_t *superbox, OPJ_OFF_T offset);
125 * generate(search) box from JP2 file
127 * @param[in] superbox super box pointer
128 * @param[in] offset offset from DBox first byte of superbox
129 * @param[in] TBox Box Type
130 * @return pointer to the structure of generate/found box parameters
132 box_param_t * gene_childboxbyType(box_param_t *superbox, OPJ_OFF_T offset,
138 * @param[in] box box pointer
139 * @return DBox offset (byte position) in the file
141 OPJ_OFF_T get_DBoxoff(box_param_t *box);
147 * @param[in] box box pointer
148 * @return DBox length ( content length)
150 OPJ_SIZE_T get_DBoxlen(box_param_t *box);
154 * fetch header bytes in file stream
156 * @param[in] box box pointer
157 * @return pointer to the fetched bytes
159 Byte_t * fetch_headbytes(box_param_t *box);
163 * fetch DBox (Box Contents) bytes of data in file stream
165 * @param[in] box box pointer
166 * @param[in] offset start Byte position in DBox
167 * @param[in] size Byte length
168 * @return pointer to the fetched data
170 Byte_t * fetch_DBoxbytes(box_param_t *box, OPJ_OFF_T offset, OPJ_SIZE_T size);
173 * fetch DBox (Box Contents) 1-byte Byte codes in file stream
175 * @param[in] box box pointer
176 * @param[in] offset start Byte position in DBox
177 * @return fetched code
179 Byte_t fetch_DBox1byte(box_param_t *box, OPJ_OFF_T offset);
182 * fetch DBox (Box Contents) 2-byte big endian Byte codes in file stream
184 * @param[in] box box pointer
185 * @param[in] offset start Byte position in DBox
186 * @return fetched code
188 Byte2_t fetch_DBox2bytebigendian(box_param_t *box, OPJ_OFF_T offset);
191 * fetch DBox (Box Contents) 4-byte big endian Byte codes in file stream
193 * @param[in] box box pointer
194 * @param[in] offset start Byte position in DBox
195 * @return fetched code
197 Byte4_t fetch_DBox4bytebigendian(box_param_t *box, OPJ_OFF_T offset);
200 * fetch DBox (Box Contents) 8-byte big endian Byte codes in file stream
202 * @param[in] box box pointer
203 * @param[in] offset start Byte position in DBox
204 * @return fetched code
206 Byte8_t fetch_DBox8bytebigendian(box_param_t *box, OPJ_OFF_T offset);
210 * search a box by box type
212 * @param[in] type box type
213 * @param[in] boxlist box list pointer
214 * @return found box pointer
216 box_param_t * search_box(const char type[], boxlist_param_t *boxlist);
219 * print box parameters
221 * @param[in] box box pointer
223 void print_box(box_param_t *box);
227 * print all box parameters
229 * @param[in] boxlist box list pointer
231 void print_allbox(boxlist_param_t *boxlist);
234 * delete a box in list
236 * @param[in,out] box address of the deleting box pointer
237 * @param[in] boxlist box list pointer
239 void delete_box_in_list(box_param_t **box, boxlist_param_t *boxlist);
243 * delete a box in list by Type
245 * @param[in,out] type box type
246 * @param[in] boxlist box list pointer
248 void delete_box_in_list_by_type(const char type[], boxlist_param_t *boxlist);
254 * @param[in,out] boxlist address of the box list pointer
256 void delete_boxlist(boxlist_param_t **boxlist);
260 * insert a box into list
262 * @param[in] box box pointer
263 * @param[in] boxlist box list pointer
265 void insert_box_into_list(box_param_t *box, boxlist_param_t *boxlist);
267 #endif /* !BOX_MANAGER_H_ */