/* * The copyright in this software is being made available under the 2-clauses * BSD License, included below. This software may be subject to other third * party and contributor rights, including patent rights, and no such rights * are granted under this license. * * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2001-2003, David Janssens * Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2012, CS Systemes d'Information, France * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef OPJ_CIO_H #define OPJ_CIO_H /** @file cio.h @brief Implementation of a byte input-output process (CIO) The functions in CIO.C have for goal to realize a byte input / output process. */ /** @defgroup CIO CIO - byte input-output stream */ /*@{*/ #include "opj_config_private.h" /* ----------------------------------------------------------------------- */ #if defined(OPJ_BIG_ENDIAN) #define opj_write_bytes … #define opj_read_bytes … #define opj_write_double … #define opj_read_double … #define opj_write_float … #define opj_read_float … #else #define opj_write_bytes … #define opj_read_bytes … #define opj_write_double … #define opj_read_double … #define opj_write_float … #define opj_read_float … #endif #define OPJ_STREAM_STATUS_OUTPUT … #define OPJ_STREAM_STATUS_INPUT … #define OPJ_STREAM_STATUS_END … #define OPJ_STREAM_STATUS_ERROR … /** Byte input-output stream. */ opj_stream_private_t; /** @name Exported functions (see also openjpeg.h) */ /*@{*/ /* ----------------------------------------------------------------------- */ /** * Write some bytes to the given data buffer, this function is used in Big Endian cpus. * @param p_buffer pointer the data buffer to write data to. * @param p_value the value to write * @param p_nb_bytes the number of bytes to write */ void opj_write_bytes_BE(OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes); /** * Reads some bytes from the given data buffer, this function is used in Big Endian cpus. * @param p_buffer pointer the data buffer to read data from. * @param p_value pointer to the value that will store the data. * @param p_nb_bytes the nb bytes to read. * @return the number of bytes read or -1 if an error occurred. */ void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes); /** * Write some bytes to the given data buffer, this function is used in Little Endian cpus. * @param p_buffer pointer the data buffer to write data to. * @param p_value the value to write * @param p_nb_bytes the number of bytes to write * @return the number of bytes written or -1 if an error occurred */ void opj_write_bytes_LE(OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes); /** * Reads some bytes from the given data buffer, this function is used in Little Endian cpus. * @param p_buffer pointer the data buffer to read data from. * @param p_value pointer to the value that will store the data. * @param p_nb_bytes the nb bytes to read. * @return the number of bytes read or -1 if an error occurred. */ void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes); /** * Write some bytes to the given data buffer, this function is used in Little Endian cpus. * @param p_buffer pointer the data buffer to write data to. * @param p_value the value to write */ void opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value); /*** * Write some bytes to the given data buffer, this function is used in Big Endian cpus. * @param p_buffer pointer the data buffer to write data to. * @param p_value the value to write */ void opj_write_double_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value); /** * Reads some bytes from the given data buffer, this function is used in Little Endian cpus. * @param p_buffer pointer the data buffer to read data from. * @param p_value pointer to the value that will store the data. */ void opj_read_double_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value); /** * Reads some bytes from the given data buffer, this function is used in Big Endian cpus. * @param p_buffer pointer the data buffer to read data from. * @param p_value pointer to the value that will store the data. */ void opj_read_double_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value); /** * Reads some bytes from the given data buffer, this function is used in Little Endian cpus. * @param p_buffer pointer the data buffer to read data from. * @param p_value pointer to the value that will store the data. */ void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value); /** * Reads some bytes from the given data buffer, this function is used in Big Endian cpus. * @param p_buffer pointer the data buffer to read data from. * @param p_value pointer to the value that will store the data. */ void opj_read_float_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value); /** * Write some bytes to the given data buffer, this function is used in Little Endian cpus. * @param p_buffer pointer the data buffer to write data to. * @param p_value the value to write */ void opj_write_float_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value); /*** * Write some bytes to the given data buffer, this function is used in Big Endian cpus. * @param p_buffer pointer the data buffer to write data to. * @param p_value the value to write */ void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value); /** * Reads some bytes from the stream. * @param p_stream the stream to read data from. * @param p_buffer pointer to the data buffer that will receive the data. * @param p_size number of bytes to read. * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes read, or -1 if an error occurred or if the stream is at the end. */ OPJ_SIZE_T opj_stream_read_data(opj_stream_private_t * p_stream, OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr); /** * Writes some bytes to the stream. * @param p_stream the stream to write data to. * @param p_buffer pointer to the data buffer holds the data to be writtent. * @param p_size number of bytes to write. * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes writtent, or -1 if an error occurred. */ OPJ_SIZE_T opj_stream_write_data(opj_stream_private_t * p_stream, const OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr); /** * Writes the content of the stream buffer to the stream. * @param p_stream the stream to write data to. * @param p_event_mgr the user event manager to be notified of special events. * @return true if the data could be flushed, false else. */ OPJ_BOOL opj_stream_flush(opj_stream_private_t * p_stream, struct opj_event_mgr * p_event_mgr); /** * Skips a number of bytes from the stream. * @param p_stream the stream to skip data from. * @param p_size the number of bytes to skip. * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes skipped, or -1 if an error occurred. */ OPJ_OFF_T opj_stream_skip(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); /** * Tells the byte offset on the stream (similar to ftell). * * @param p_stream the stream to get the information from. * * @return the current position o fthe stream. */ OPJ_OFF_T opj_stream_tell(const opj_stream_private_t * p_stream); /** * Get the number of bytes left before the end of the stream (similar to cio_numbytesleft). * * @param p_stream the stream to get the information from. * * @return Number of bytes left before the end of the stream. */ OPJ_OFF_T opj_stream_get_number_byte_left(const opj_stream_private_t * p_stream); /** * Skips a number of bytes from the stream. * @param p_stream the stream to skip data from. * @param p_size the number of bytes to skip. * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes skipped, or -1 if an error occurred. */ OPJ_OFF_T opj_stream_write_skip(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); /** * Skips a number of bytes from the stream. * @param p_stream the stream to skip data from. * @param p_size the number of bytes to skip. * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes skipped, or -1 if an error occurred. */ OPJ_OFF_T opj_stream_read_skip(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); /** * Skips a number of bytes from the stream. * @param p_stream the stream to skip data from. * @param p_size the number of bytes to skip. * @param p_event_mgr the user event manager to be notified of special events. * @return OPJ_TRUE if success, or OPJ_FALSE if an error occurred. */ OPJ_BOOL opj_stream_read_seek(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); /** * Skips a number of bytes from the stream. * @param p_stream the stream to skip data from. * @param p_size the number of bytes to skip. * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes skipped, or -1 if an error occurred. */ OPJ_BOOL opj_stream_write_seek(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); /** * Seeks a number of bytes from the stream. * @param p_stream the stream to skip data from. * @param p_size the number of bytes to skip. * @param p_event_mgr the user event manager to be notified of special events. * @return true if the stream is seekable. */ OPJ_BOOL opj_stream_seek(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); /** * Tells if the given stream is seekable. */ OPJ_BOOL opj_stream_has_seek(const opj_stream_private_t * p_stream); /** * FIXME DOC. */ OPJ_SIZE_T opj_stream_default_read(void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data); /** * FIXME DOC. */ OPJ_SIZE_T opj_stream_default_write(void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data); /** * FIXME DOC. */ OPJ_OFF_T opj_stream_default_skip(OPJ_OFF_T p_nb_bytes, void * p_user_data); /** * FIXME DOC. */ OPJ_BOOL opj_stream_default_seek(OPJ_OFF_T p_nb_bytes, void * p_user_data); /* ----------------------------------------------------------------------- */ /*@}*/ /*@}*/ #endif /* OPJ_CIO_H */