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
11 * Redistribution and use in source and binary forms, with or without
\r
12 * modification, are permitted provided that the following conditions
\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
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
37 @brief Implementation of a byte input-output process (CIO)
\r
39 The functions in CIO.C have for goal to realize a byte input / output process.
\r
42 /** @defgroup CIO CIO - byte input-output stream */
\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
50 /* ----------------------------------------------------------------------- */
\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
61 #error "Either BIG_ENDIAN or LITTLE_ENDIAN must be #defined, but not both."
\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
72 #error "Either BIG_ENDIAN or LITTLE_ENDIAN must be #defined, but not none."
\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
88 Byte input-output stream.
\r
90 typedef struct opj_stream_private
\r
93 * User data, be it files, ... The actual data depends on the type of the stream.
\r
98 * Pointer to actual read function (NULL at the initialization of the cio.
\r
100 opj_stream_read_fn m_read_fn;
\r
103 * Pointer to actual write function (NULL at the initialization of the cio.
\r
105 opj_stream_write_fn m_write_fn;
\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
111 opj_stream_skip_fn m_skip_fn;
\r
114 * Pointer to actual seek function (if available).
\r
116 opj_stream_seek_fn m_seek_fn;
\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
125 OPJ_BYTE * m_stored_data;
\r
128 * Pointer to the current read data.
\r
130 OPJ_BYTE * m_current_data;
\r
132 OPJ_SIZE_T (* m_opj_skip)(struct opj_stream_private * ,OPJ_SIZE_T , struct opj_event_mgr *);
\r
134 bool (* m_opj_seek) (struct opj_stream_private * , OPJ_SIZE_T , struct opj_event_mgr *);
\r
137 * number of bytes containing in the buffer.
\r
139 OPJ_UINT32 m_bytes_in_buffer;
\r
142 * The number of bytes read/written.
\r
144 OPJ_SIZE_T m_byte_offset;
\r
147 * The size of the buffer.
\r
149 OPJ_UINT32 m_buffer_size;
\r
152 * Flags to tell the status of the stream.
\r
154 OPJ_UINT32 m_status;
\r
157 opj_stream_private_t;
\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
166 void opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes);
\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
175 void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes);
\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
184 void opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes);
\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
193 void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes);
\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
201 void opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value);
\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
208 void opj_write_double_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value);
\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
215 void opj_read_double_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value);
\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
222 void opj_read_double_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value);
\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
229 void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value);
\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
236 void opj_read_float_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value);
\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
243 void opj_write_float_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value);
\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
250 void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value);
\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
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
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
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
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
278 bool opj_stream_flush (opj_stream_private_t * p_stream, struct opj_event_mgr * p_event_mgr);
\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
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
290 * Tells the byte offset on the stream (similar to ftell).
\r
292 * @param p_stream the stream to get the information from.
\r
294 * @return the current position o fthe stream.
\r
296 OPJ_SIZE_T opj_stream_tell (const opj_stream_private_t * p_stream);
\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
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
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
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
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
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
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
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
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
341 bool opj_stream_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
\r
344 * Tells if the given stream is seekable.
\r
346 bool opj_stream_has_seek (const opj_stream_private_t * p_stream);
\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
353 /* ----------------------------------------------------------------------- */
\r
358 #endif /* __CIO_H */
\r