Added the default lossless parameter to opj_set_default_encoder_parameters in openjpeg.c
[openjpeg.git] / v2 / libopenjpeg / cio.h
1 /*\r
2  * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium\r
3  * Copyright (c) 2002-2007, Professor Benoit Macq\r
4  * Copyright (c) 2001-2003, David Janssens\r
5  * Copyright (c) 2002-2003, Yannick Verschueren\r
6  * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe\r
7  * Copyright (c) 2005, Herve Drolon, FreeImage Team\r
8  * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>\r
9  * All rights reserved.\r
10  *\r
11  * Redistribution and use in source and binary forms, with or without\r
12  * modification, are permitted provided that the following conditions\r
13  * are met:\r
14  * 1. Redistributions of source code must retain the above copyright\r
15  *    notice, this list of conditions and the following disclaimer.\r
16  * 2. Redistributions in binary form must reproduce the above copyright\r
17  *    notice, this list of conditions and the following disclaimer in the\r
18  *    documentation and/or other materials provided with the distribution.\r
19  *\r
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'\r
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
30  * POSSIBILITY OF SUCH DAMAGE.\r
31  */\r
32 \r
33 #ifndef __CIO_H\r
34 #define __CIO_H\r
35 /**\r
36 @file cio.h\r
37 @brief Implementation of a byte input-output process (CIO)\r
38 \r
39 The functions in CIO.C have for goal to realize a byte input / output process.\r
40 */\r
41 \r
42 /** @defgroup CIO CIO - byte input-output stream */\r
43 /*@{*/\r
44 \r
45 #include "openjpeg.h"\r
46 #include "opj_configure.h"\r
47 struct opj_event_mgr;\r
48 /** @name Exported functions (see also openjpeg.h) */\r
49 /*@{*/\r
50 /* ----------------------------------------------------------------------- */\r
51 \r
52 #if defined(OPJ_BIG_ENDIAN) \r
53         #if !defined(OPJ_LITTLE_ENDIAN)\r
54                         #define opj_write_bytes         opj_write_bytes_BE\r
55                         #define opj_read_bytes          opj_read_bytes_BE\r
56                         #define opj_write_double        opj_write_double_BE\r
57                         #define opj_read_double         opj_read_double_BE\r
58                         #define opj_write_float         opj_write_float_BE\r
59                         #define opj_read_float          opj_read_float_BE\r
60         #else\r
61                         #error "Either BIG_ENDIAN or LITTLE_ENDIAN must be #defined, but not both."\r
62         #endif\r
63 #else\r
64         #if defined(OPJ_LITTLE_ENDIAN)\r
65                         #define opj_write_bytes         opj_write_bytes_LE\r
66                         #define opj_read_bytes          opj_read_bytes_LE\r
67                         #define opj_write_double        opj_write_double_LE\r
68                         #define opj_read_double         opj_read_double_LE\r
69                         #define opj_write_float         opj_write_float_LE\r
70                         #define opj_read_float          opj_read_float_LE\r
71         #else\r
72                 #error "Either BIG_ENDIAN or LITTLE_ENDIAN must be #defined, but not none."\r
73         #endif\r
74 #endif\r
75 \r
76 \r
77 \r
78 typedef enum  \r
79 {\r
80         opj_stream_e_output             = 0x1,\r
81         opj_stream_e_input              = 0x2,\r
82         opj_stream_e_end                = 0x4,\r
83         opj_stream_e_error              = 0x8\r
84 }\r
85 opj_stream_flag ;\r
86 \r
87 /**\r
88 Byte input-output stream.\r
89 */\r
90 typedef struct opj_stream_private\r
91 {\r
92         /**\r
93          * User data, be it files, ... The actual data depends on the type of the stream.\r
94          */\r
95         void *                                  m_user_data;\r
96         \r
97         /**\r
98          * Pointer to actual read function (NULL at the initialization of the cio.\r
99          */\r
100         opj_stream_read_fn              m_read_fn;\r
101         \r
102         /**\r
103          * Pointer to actual write function (NULL at the initialization of the cio.\r
104          */\r
105         opj_stream_write_fn             m_write_fn;\r
106         \r
107         /**\r
108          * Pointer to actual skip function (NULL at the initialization of the cio.\r
109          * There is no seek function to prevent from back and forth slow procedures.\r
110          */\r
111         opj_stream_skip_fn              m_skip_fn;\r
112         \r
113         /**\r
114          * Pointer to actual seek function (if available).\r
115          */\r
116         opj_stream_seek_fn              m_seek_fn;\r
117 \r
118 \r
119 \r
120 \r
121         /**\r
122          * Actual data stored into the stream if readed from. Data is read by chunk of fixed size.\r
123          * you should never access this data directly.\r
124          */\r
125         OPJ_BYTE *                                      m_stored_data;\r
126 \r
127         /**\r
128          * Pointer to the current read data.\r
129          */\r
130         OPJ_BYTE *                                      m_current_data;\r
131 \r
132         OPJ_SIZE_T (* m_opj_skip)(struct opj_stream_private * ,OPJ_SIZE_T , struct opj_event_mgr *);\r
133         \r
134         bool (* m_opj_seek) (struct opj_stream_private * , OPJ_SIZE_T , struct opj_event_mgr *);\r
135         \r
136         /**\r
137          * number of bytes containing in the buffer.\r
138          */\r
139         OPJ_UINT32                      m_bytes_in_buffer;\r
140         \r
141         /**\r
142          * The number of bytes read/written.\r
143          */\r
144         OPJ_SIZE_T                      m_byte_offset;\r
145         \r
146         /**\r
147          * The size of the buffer.\r
148          */\r
149         OPJ_UINT32                      m_buffer_size;\r
150 \r
151         /**\r
152          * Flags to tell the status of the stream.\r
153          */\r
154         OPJ_UINT32                      m_status;\r
155         \r
156\r
157 opj_stream_private_t;\r
158 \r
159 \r
160 /**\r
161  * Write some bytes to the given data buffer, this function is used in Big Endian cpus.\r
162  * @param p_buffer              pointer the data buffer to write data to.\r
163  * @param p_value               the value to write\r
164  * @param p_nb_bytes    the number of bytes to write\r
165 */\r
166 void opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes);\r
167 \r
168 /**\r
169  * Reads some bytes from the given data buffer, this function is used in Big Endian cpus.\r
170  * @param p_buffer              pointer the data buffer to read data from.\r
171  * @param p_value               pointer to the value that will store the data.\r
172  * @param p_nb_bytes    the nb bytes to read.\r
173  * @return                              the number of bytes read or -1 if an error occured.\r
174  */\r
175 void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes);\r
176 \r
177 /**\r
178  * Write some bytes to the given data buffer, this function is used in Little Endian cpus.\r
179  * @param p_buffer              pointer the data buffer to write data to.\r
180  * @param p_value               the value to write\r
181  * @param p_nb_bytes    the number of bytes to write\r
182  * @return                              the number of bytes written or -1 if an error occured\r
183 */\r
184 void opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes);\r
185 \r
186 /**\r
187  * Reads some bytes from the given data buffer, this function is used in Little Endian cpus.\r
188  * @param p_buffer              pointer the data buffer to read data from.\r
189  * @param p_value               pointer to the value that will store the data.\r
190  * @param p_nb_bytes    the nb bytes to read.\r
191  * @return                              the number of bytes read or -1 if an error occured.\r
192  */\r
193 void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes);\r
194 \r
195 \r
196 /**\r
197  * Write some bytes to the given data buffer, this function is used in Little Endian cpus.\r
198  * @param p_buffer              pointer the data buffer to write data to.\r
199  * @param p_value               the value to write\r
200  */\r
201 void opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value);\r
202 \r
203 /***\r
204  * Write some bytes to the given data buffer, this function is used in Big Endian cpus.\r
205  * @param p_buffer              pointer the data buffer to write data to.\r
206  * @param p_value               the value to write\r
207  */\r
208 void opj_write_double_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value);\r
209 \r
210 /**\r
211  * Reads some bytes from the given data buffer, this function is used in Little Endian cpus.\r
212  * @param p_buffer              pointer the data buffer to read data from.\r
213  * @param p_value               pointer to the value that will store the data.\r
214  */\r
215 void opj_read_double_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value);\r
216 \r
217 /**\r
218  * Reads some bytes from the given data buffer, this function is used in Big Endian cpus.\r
219  * @param p_buffer              pointer the data buffer to read data from.\r
220  * @param p_value               pointer to the value that will store the data.\r
221  */\r
222 void opj_read_double_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value);\r
223 \r
224 /**\r
225  * Reads some bytes from the given data buffer, this function is used in Little Endian cpus.\r
226  * @param p_buffer              pointer the data buffer to read data from.\r
227  * @param p_value               pointer to the value that will store the data.\r
228  */\r
229 void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value);\r
230 \r
231 /**\r
232  * Reads some bytes from the given data buffer, this function is used in Big Endian cpus.\r
233  * @param p_buffer              pointer the data buffer to read data from.\r
234  * @param p_value               pointer to the value that will store the data.\r
235  */\r
236 void opj_read_float_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value);\r
237 \r
238 /**\r
239  * Write some bytes to the given data buffer, this function is used in Little Endian cpus.\r
240  * @param p_buffer              pointer the data buffer to write data to.\r
241  * @param p_value               the value to write\r
242  */\r
243 void opj_write_float_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value);\r
244 \r
245 /***\r
246  * Write some bytes to the given data buffer, this function is used in Big Endian cpus.\r
247  * @param p_buffer              pointer the data buffer to write data to.\r
248  * @param p_value               the value to write\r
249  */\r
250 void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value);\r
251 \r
252 /**\r
253  * Reads some bytes from the stream.\r
254  * @param               p_stream        the stream to read data from.\r
255  * @param               p_buffer        pointer to the data buffer that will receive the data.\r
256  * @param               p_size          number of bytes to read.\r
257  * @param               p_event_mgr     the user event manager to be notified of special events.\r
258  * @return              the number of bytes read, or -1 if an error occured or if the stream is at the end.\r
259  */\r
260 OPJ_UINT32 opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_buffer, OPJ_UINT32 p_size, struct opj_event_mgr * p_event_mgr);\r
261 \r
262 /**\r
263  * Writes some bytes to the stream.\r
264  * @param               p_stream        the stream to write data to.\r
265  * @param               p_buffer        pointer to the data buffer holds the data to be writtent.\r
266  * @param               p_size          number of bytes to write.\r
267  * @param               p_event_mgr     the user event manager to be notified of special events.\r
268  * @return              the number of bytes writtent, or -1 if an error occured.\r
269  */\r
270 OPJ_UINT32 opj_stream_write_data (opj_stream_private_t * p_stream,const OPJ_BYTE * p_buffer, OPJ_UINT32 p_size, struct opj_event_mgr * p_event_mgr);\r
271 \r
272 /**\r
273  * Writes the content of the stream buffer to the stream.\r
274  * @param               p_stream        the stream to write data to.\r
275  * @param               p_event_mgr     the user event manager to be notified of special events.\r
276  * @return              true if the data could be flushed, false else.\r
277  */\r
278 bool opj_stream_flush (opj_stream_private_t * p_stream, struct opj_event_mgr * p_event_mgr);\r
279 \r
280 /**\r
281  * Skips a number of bytes from the stream.\r
282  * @param               p_stream        the stream to skip data from.\r
283  * @param               p_size          the number of bytes to skip.\r
284  * @param               p_event_mgr     the user event manager to be notified of special events.\r
285  * @return              the number of bytes skipped, or -1 if an error occured.\r
286  */\r
287 OPJ_SIZE_T opj_stream_skip (opj_stream_private_t * p_stream,OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);\r
288 \r
289 /**\r
290  * Tells the byte offset on the stream (similar to ftell).\r
291  * \r
292  * @param               p_stream        the stream to get the information from.\r
293  * \r
294  * @return              the current position o fthe stream.\r
295  */\r
296 OPJ_SIZE_T opj_stream_tell (const opj_stream_private_t * p_stream);\r
297 \r
298 /**\r
299  * Skips a number of bytes from the stream.\r
300  * @param               p_stream        the stream to skip data from.\r
301  * @param               p_size          the number of bytes to skip.\r
302  * @param               p_event_mgr     the user event manager to be notified of special events.\r
303  * @return              the number of bytes skipped, or -1 if an error occured.\r
304  */\r
305 OPJ_SIZE_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);\r
306 \r
307 /**\r
308  * Skips a number of bytes from the stream.\r
309  * @param               p_stream        the stream to skip data from.\r
310  * @param               p_size          the number of bytes to skip.\r
311  * @param               p_event_mgr     the user event manager to be notified of special events.\r
312  * @return              the number of bytes skipped, or -1 if an error occured.\r
313  */\r
314 OPJ_SIZE_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);\r
315 \r
316 /**\r
317  * Skips a number of bytes from the stream.\r
318  * @param               p_stream        the stream to skip data from.\r
319  * @param               p_size          the number of bytes to skip.\r
320  * @param               p_event_mgr     the user event manager to be notified of special events.\r
321  * @return              the number of bytes skipped, or -1 if an error occured.\r
322  */\r
323 bool opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);\r
324 \r
325 /**\r
326  * Skips a number of bytes from the stream.\r
327  * @param               p_stream        the stream to skip data from.\r
328  * @param               p_size          the number of bytes to skip.\r
329  * @param               p_event_mgr     the user event manager to be notified of special events.\r
330  * @return              the number of bytes skipped, or -1 if an error occured.\r
331  */\r
332 bool opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);\r
333 \r
334 /**\r
335  * Seeks a number of bytes from the stream.\r
336  * @param               p_stream        the stream to skip data from.\r
337  * @param               p_size          the number of bytes to skip.\r
338  * @param               p_event_mgr     the user event manager to be notified of special events.\r
339  * @return              true if the stream is seekable.\r
340  */\r
341 bool opj_stream_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);\r
342 \r
343 /**\r
344  * Tells if the given stream is seekable.\r
345  */\r
346 bool opj_stream_has_seek (const opj_stream_private_t * p_stream);\r
347 \r
348 OPJ_UINT32 opj_stream_default_read (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data);\r
349 OPJ_UINT32 opj_stream_default_write (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data);\r
350 OPJ_SIZE_T opj_stream_default_skip (OPJ_SIZE_T p_nb_bytes, void * p_user_data);\r
351 bool opj_stream_default_seek (OPJ_SIZE_T p_nb_bytes, void * p_user_data);\r
352 \r
353 /* ----------------------------------------------------------------------- */\r
354 /*@}*/\r
355 \r
356 /*@}*/\r
357 \r
358 #endif /* __CIO_H */\r
359 \r