[trunk] add libopenjpeg-jpwl.pc.in. fix output when --disable-shared or --disable...
[openjpeg.git] / libopenjpeg / cio.h
1 /*
2  * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
3  * Copyright (c) 2002-2007, Professor Benoit Macq
4  * Copyright (c) 2001-2003, David Janssens
5  * Copyright (c) 2002-2003, Yannick Verschueren
6  * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
7  * Copyright (c) 2005, Herve Drolon, FreeImage Team
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
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.
18  *
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.
30  */
31
32 #ifndef __CIO_H
33 #define __CIO_H
34 /**
35 @file cio.h
36 @brief Implementation of a byte input-output process (CIO)
37
38 The functions in CIO.C have for goal to realize a byte input / output process.
39 */
40
41 /** @defgroup CIO CIO - byte input-output stream */
42 /*@{*/
43
44 #include "opj_config.h"
45
46 /** @name Exported functions (see also openjpeg.h) */
47 /*@{*/
48 /* ----------------------------------------------------------------------- */
49 /**
50 Number of bytes left before the end of the stream
51 @param cio CIO handle
52 @return Returns the number of bytes before the end of the stream
53 */
54 int cio_numbytesleft(opj_cio_t *cio);
55 /**
56 Get pointer to the current position in the stream
57 @param cio CIO handle
58 @return Returns a pointer to the current position
59 */
60 unsigned char *cio_getbp(opj_cio_t *cio);
61 /**
62 Write some bytes
63 @param cio CIO handle
64 @param v Value to write
65 @param n Number of bytes to write
66 @return Returns the number of bytes written or 0 if an error occured
67 */
68 unsigned int cio_write(opj_cio_t *cio, unsigned long long int v, int n);
69 /**
70 Read some bytes
71 @param cio CIO handle
72 @param n Number of bytes to read
73 @return Returns the value of the n bytes read
74 */
75 unsigned int cio_read(opj_cio_t *cio, int n);
76 /**
77 Skip some bytes
78 @param cio CIO handle
79 @param n Number of bytes to skip
80 */
81 void cio_skip(opj_cio_t *cio, int n);
82 /* ----------------------------------------------------------------------- */
83 /*@}*/
84
85 /*@}*/
86
87
88
89 /* ----------------------------------------------------------------------- */
90
91 #if defined(OPJ_BIG_ENDIAN)
92         #define opj_write_bytes         opj_write_bytes_BE
93         #define opj_read_bytes          opj_read_bytes_BE
94         #define opj_write_double        opj_write_double_BE
95         #define opj_read_double         opj_read_double_BE
96         #define opj_write_float         opj_write_float_BE
97         #define opj_read_float          opj_read_float_BE
98 #else
99         #define opj_write_bytes         opj_write_bytes_LE
100         #define opj_read_bytes          opj_read_bytes_LE
101         #define opj_write_double        opj_write_double_LE
102         #define opj_read_double         opj_read_double_LE
103         #define opj_write_float         opj_write_float_LE
104         #define opj_read_float          opj_read_float_LE
105 #endif
106
107
108
109 typedef enum
110 {
111         opj_stream_e_output             = 0x1,
112         opj_stream_e_input              = 0x2,
113         opj_stream_e_end                = 0x4,
114         opj_stream_e_error              = 0x8
115 }
116 opj_stream_flag ;
117
118 /**
119 Byte input-output stream.
120 */
121 typedef struct opj_stream_private
122 {
123         /**
124          * User data, be it files, ... The actual data depends on the type of the stream.
125          */
126         void *                                  m_user_data;
127
128         /**
129          * Pointer to actual read function (NULL at the initialization of the cio.
130          */
131         opj_stream_read_fn              m_read_fn;
132
133         /**
134          * Pointer to actual write function (NULL at the initialization of the cio.
135          */
136         opj_stream_write_fn             m_write_fn;
137
138         /**
139          * Pointer to actual skip function (NULL at the initialization of the cio.
140          * There is no seek function to prevent from back and forth slow procedures.
141          */
142         opj_stream_skip_fn              m_skip_fn;
143
144         /**
145          * Pointer to actual seek function (if available).
146          */
147         opj_stream_seek_fn              m_seek_fn;
148
149
150
151
152         /**
153          * Actual data stored into the stream if readed from. Data is read by chunk of fixed size.
154          * you should never access this data directly.
155          */
156         OPJ_BYTE *                                      m_stored_data;
157
158         /**
159          * Pointer to the current read data.
160          */
161         OPJ_BYTE *                                      m_current_data;
162
163         OPJ_SIZE_T (* m_opj_skip)(struct opj_stream_private * ,OPJ_SIZE_T , struct opj_event_mgr *);
164
165         opj_bool (* m_opj_seek) (struct opj_stream_private * , OPJ_SIZE_T , struct opj_event_mgr *);
166
167         /**
168          * number of bytes containing in the buffer.
169          */
170         OPJ_UINT32                      m_bytes_in_buffer;
171
172         /**
173          * The number of bytes read/written.
174          */
175         OPJ_SIZE_T                      m_byte_offset;
176
177         /**
178          * The size of the buffer.
179          */
180         OPJ_UINT32                      m_buffer_size;
181
182         /**
183          * Flags to tell the status of the stream.
184          */
185         OPJ_UINT32                      m_status;
186
187 }
188 opj_stream_private_t;
189
190
191 /**
192  * Write some bytes to the given data buffer, this function is used in Big Endian cpus.
193  * @param p_buffer              pointer the data buffer to write data to.
194  * @param p_value               the value to write
195  * @param p_nb_bytes    the number of bytes to write
196 */
197 void opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes);
198
199 /**
200  * Reads some bytes from the given data buffer, this function is used in Big Endian cpus.
201  * @param p_buffer              pointer the data buffer to read data from.
202  * @param p_value               pointer to the value that will store the data.
203  * @param p_nb_bytes    the nb bytes to read.
204  * @return                              the number of bytes read or -1 if an error occured.
205  */
206 void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes);
207
208 /**
209  * Write some bytes to the given data buffer, this function is used in Little Endian cpus.
210  * @param p_buffer              pointer the data buffer to write data to.
211  * @param p_value               the value to write
212  * @param p_nb_bytes    the number of bytes to write
213  * @return                              the number of bytes written or -1 if an error occured
214 */
215 void opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes);
216
217 /**
218  * Reads some bytes from the given data buffer, this function is used in Little Endian cpus.
219  * @param p_buffer              pointer the data buffer to read data from.
220  * @param p_value               pointer to the value that will store the data.
221  * @param p_nb_bytes    the nb bytes to read.
222  * @return                              the number of bytes read or -1 if an error occured.
223  */
224 void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes);
225
226
227 /**
228  * Write some bytes to the given data buffer, this function is used in Little Endian cpus.
229  * @param p_buffer              pointer the data buffer to write data to.
230  * @param p_value               the value to write
231  */
232 void opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value);
233
234 /***
235  * Write some bytes to the given data buffer, this function is used in Big Endian cpus.
236  * @param p_buffer              pointer the data buffer to write data to.
237  * @param p_value               the value to write
238  */
239 void opj_write_double_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value);
240
241 /**
242  * Reads some bytes from the given data buffer, this function is used in Little Endian cpus.
243  * @param p_buffer              pointer the data buffer to read data from.
244  * @param p_value               pointer to the value that will store the data.
245  */
246 void opj_read_double_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value);
247
248 /**
249  * Reads some bytes from the given data buffer, this function is used in Big Endian cpus.
250  * @param p_buffer              pointer the data buffer to read data from.
251  * @param p_value               pointer to the value that will store the data.
252  */
253 void opj_read_double_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value);
254
255 /**
256  * Reads some bytes from the given data buffer, this function is used in Little Endian cpus.
257  * @param p_buffer              pointer the data buffer to read data from.
258  * @param p_value               pointer to the value that will store the data.
259  */
260 void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value);
261
262 /**
263  * Reads some bytes from the given data buffer, this function is used in Big Endian cpus.
264  * @param p_buffer              pointer the data buffer to read data from.
265  * @param p_value               pointer to the value that will store the data.
266  */
267 void opj_read_float_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value);
268
269 /**
270  * Write some bytes to the given data buffer, this function is used in Little Endian cpus.
271  * @param p_buffer              pointer the data buffer to write data to.
272  * @param p_value               the value to write
273  */
274 void opj_write_float_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value);
275
276 /***
277  * Write some bytes to the given data buffer, this function is used in Big Endian cpus.
278  * @param p_buffer              pointer the data buffer to write data to.
279  * @param p_value               the value to write
280  */
281 void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value);
282
283 /**
284  * Reads some bytes from the stream.
285  * @param               p_stream        the stream to read data from.
286  * @param               p_buffer        pointer to the data buffer that will receive the data.
287  * @param               p_size          number of bytes to read.
288  * @param               p_event_mgr     the user event manager to be notified of special events.
289  * @return              the number of bytes read, or -1 if an error occured or if the stream is at the end.
290  */
291 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);
292
293 /**
294  * Writes some bytes to the stream.
295  * @param               p_stream        the stream to write data to.
296  * @param               p_buffer        pointer to the data buffer holds the data to be writtent.
297  * @param               p_size          number of bytes to write.
298  * @param               p_event_mgr     the user event manager to be notified of special events.
299  * @return              the number of bytes writtent, or -1 if an error occured.
300  */
301 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);
302
303 /**
304  * Writes the content of the stream buffer to the stream.
305  * @param               p_stream        the stream to write data to.
306  * @param               p_event_mgr     the user event manager to be notified of special events.
307  * @return              true if the data could be flushed, false else.
308  */
309 opj_bool opj_stream_flush (opj_stream_private_t * p_stream, struct opj_event_mgr * p_event_mgr);
310
311 /**
312  * Skips a number of bytes from the stream.
313  * @param               p_stream        the stream to skip data from.
314  * @param               p_size          the number of bytes to skip.
315  * @param               p_event_mgr     the user event manager to be notified of special events.
316  * @return              the number of bytes skipped, or -1 if an error occured.
317  */
318 OPJ_SIZE_T opj_stream_skip (opj_stream_private_t * p_stream,OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
319
320 /**
321  * Tells the byte offset on the stream (similar to ftell).
322  *
323  * @param               p_stream        the stream to get the information from.
324  *
325  * @return              the current position o fthe stream.
326  */
327 OPJ_SIZE_T opj_stream_tell (const opj_stream_private_t * p_stream);
328
329 /**
330  * Skips a number of bytes from the stream.
331  * @param               p_stream        the stream to skip data from.
332  * @param               p_size          the number of bytes to skip.
333  * @param               p_event_mgr     the user event manager to be notified of special events.
334  * @return              the number of bytes skipped, or -1 if an error occured.
335  */
336 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);
337
338 /**
339  * Skips a number of bytes from the stream.
340  * @param               p_stream        the stream to skip data from.
341  * @param               p_size          the number of bytes to skip.
342  * @param               p_event_mgr     the user event manager to be notified of special events.
343  * @return              the number of bytes skipped, or -1 if an error occured.
344  */
345 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);
346
347 /**
348  * Skips a number of bytes from the stream.
349  * @param               p_stream        the stream to skip data from.
350  * @param               p_size          the number of bytes to skip.
351  * @param               p_event_mgr     the user event manager to be notified of special events.
352  * @return              the number of bytes skipped, or -1 if an error occured.
353  */
354 opj_bool opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
355
356 /**
357  * Skips a number of bytes from the stream.
358  * @param               p_stream        the stream to skip data from.
359  * @param               p_size          the number of bytes to skip.
360  * @param               p_event_mgr     the user event manager to be notified of special events.
361  * @return              the number of bytes skipped, or -1 if an error occured.
362  */
363 opj_bool opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
364
365 /**
366  * Seeks a number of bytes from the stream.
367  * @param               p_stream        the stream to skip data from.
368  * @param               p_size          the number of bytes to skip.
369  * @param               p_event_mgr     the user event manager to be notified of special events.
370  * @return              true if the stream is seekable.
371  */
372 opj_bool opj_stream_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
373
374 /**
375  * Tells if the given stream is seekable.
376  */
377 opj_bool opj_stream_has_seek (const opj_stream_private_t * p_stream);
378
379 OPJ_UINT32 opj_stream_default_read (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data);
380 OPJ_UINT32 opj_stream_default_write (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data);
381 OPJ_SIZE_T opj_stream_default_skip (OPJ_SIZE_T p_nb_bytes, void * p_user_data);
382 opj_bool opj_stream_default_seek (OPJ_SIZE_T p_nb_bytes, void * p_user_data);
383
384
385
386 #endif /* __CIO_H */
387