2003-11-27 11:10:17 +01:00
|
|
|
/*
|
2017-05-15 12:21:30 +02:00
|
|
|
* 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
|
2014-04-03 17:30:57 +02:00
|
|
|
* 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
|
2005-12-02 14:34:15 +01:00
|
|
|
* Copyright (c) 2001-2003, David Janssens
|
|
|
|
* Copyright (c) 2002-2003, Yannick Verschueren
|
2017-05-15 12:21:30 +02:00
|
|
|
* Copyright (c) 2003-2007, Francois-Olivier Devaux
|
2014-04-03 17:30:57 +02:00
|
|
|
* Copyright (c) 2003-2014, Antonin Descampe
|
2007-01-15 10:55:40 +01:00
|
|
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
2003-11-27 11:10:17 +01:00
|
|
|
* 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 __BIO_H
|
|
|
|
#define __BIO_H
|
2012-03-26 10:51:12 +02:00
|
|
|
|
|
|
|
#include <stddef.h> /* ptrdiff_t */
|
|
|
|
|
2017-05-15 12:21:30 +02:00
|
|
|
/**
|
2005-12-02 14:34:15 +01:00
|
|
|
@file bio.h
|
|
|
|
@brief Implementation of an individual bit input-output (BIO)
|
2003-11-27 11:10:17 +01:00
|
|
|
|
2005-12-02 14:34:15 +01:00
|
|
|
The functions in BIO.C have for goal to realize an individual bit input - output.
|
|
|
|
*/
|
2004-02-13 10:47:40 +01:00
|
|
|
|
2005-12-02 14:34:15 +01:00
|
|
|
/** @defgroup BIO BIO - Individual bit input-output stream */
|
|
|
|
/*@{*/
|
2004-02-13 10:47:40 +01:00
|
|
|
|
2005-12-02 14:34:15 +01:00
|
|
|
/**
|
|
|
|
Individual bit input-output stream (BIO)
|
|
|
|
*/
|
|
|
|
typedef struct opj_bio {
|
2017-05-15 12:21:30 +02:00
|
|
|
/** pointer to the start of the buffer */
|
|
|
|
OPJ_BYTE *start;
|
|
|
|
/** pointer to the end of the buffer */
|
|
|
|
OPJ_BYTE *end;
|
|
|
|
/** pointer to the present position in the buffer */
|
|
|
|
OPJ_BYTE *bp;
|
|
|
|
/** temporary place where each byte is read or written */
|
|
|
|
OPJ_UINT32 buf;
|
|
|
|
/** coder : number of bits free to write. decoder : number of bits read */
|
|
|
|
OPJ_UINT32 ct;
|
2005-12-02 14:34:15 +01:00
|
|
|
} opj_bio_t;
|
2004-02-13 10:47:40 +01:00
|
|
|
|
2005-12-02 14:34:15 +01:00
|
|
|
/** @name Exported functions */
|
|
|
|
/*@{*/
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/**
|
2017-05-15 12:21:30 +02:00
|
|
|
Create a new BIO handle
|
2005-12-02 14:34:15 +01:00
|
|
|
@return Returns a new BIO handle if successful, returns NULL otherwise
|
|
|
|
*/
|
2012-09-27 16:42:08 +02:00
|
|
|
opj_bio_t* opj_bio_create(void);
|
2005-12-02 14:34:15 +01:00
|
|
|
/**
|
|
|
|
Destroy a previously created BIO handle
|
|
|
|
@param bio BIO handle to destroy
|
|
|
|
*/
|
2012-09-27 16:42:08 +02:00
|
|
|
void opj_bio_destroy(opj_bio_t *bio);
|
2005-12-02 14:34:15 +01:00
|
|
|
/**
|
|
|
|
Number of bytes written.
|
|
|
|
@param bio BIO handle
|
|
|
|
@return Returns the number of bytes written
|
|
|
|
*/
|
2012-10-03 11:04:44 +02:00
|
|
|
ptrdiff_t opj_bio_numbytes(opj_bio_t *bio);
|
2005-12-02 14:34:15 +01:00
|
|
|
/**
|
|
|
|
Init encoder
|
|
|
|
@param bio BIO handle
|
|
|
|
@param bp Output buffer
|
2017-05-15 12:21:30 +02:00
|
|
|
@param len Output buffer length
|
2005-12-02 14:34:15 +01:00
|
|
|
*/
|
2012-10-03 11:04:44 +02:00
|
|
|
void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len);
|
2005-12-02 14:34:15 +01:00
|
|
|
/**
|
|
|
|
Init decoder
|
|
|
|
@param bio BIO handle
|
|
|
|
@param bp Input buffer
|
2017-05-15 12:21:30 +02:00
|
|
|
@param len Input buffer length
|
2005-12-02 14:34:15 +01:00
|
|
|
*/
|
2012-10-03 11:04:44 +02:00
|
|
|
void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len);
|
2005-12-02 14:34:15 +01:00
|
|
|
/**
|
|
|
|
Write bits
|
|
|
|
@param bio BIO handle
|
|
|
|
@param v Value of bits
|
|
|
|
@param n Number of bits to write
|
|
|
|
*/
|
2012-10-03 11:04:44 +02:00
|
|
|
void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n);
|
2005-12-02 14:34:15 +01:00
|
|
|
/**
|
|
|
|
Read bits
|
|
|
|
@param bio BIO handle
|
2017-05-15 12:21:30 +02:00
|
|
|
@param n Number of bits to read
|
2005-12-02 14:34:15 +01:00
|
|
|
@return Returns the corresponding read number
|
|
|
|
*/
|
2012-10-03 11:04:44 +02:00
|
|
|
OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n);
|
2005-12-02 14:34:15 +01:00
|
|
|
/**
|
|
|
|
Flush bits
|
|
|
|
@param bio BIO handle
|
2012-10-03 11:04:44 +02:00
|
|
|
@return Returns OPJ_TRUE if successful, returns OPJ_FALSE otherwise
|
2005-12-02 14:34:15 +01:00
|
|
|
*/
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL opj_bio_flush(opj_bio_t *bio);
|
2005-12-02 14:34:15 +01:00
|
|
|
/**
|
|
|
|
Passes the ending bits (coming from flushing)
|
|
|
|
@param bio BIO handle
|
2012-10-03 11:04:44 +02:00
|
|
|
@return Returns OPJ_TRUE if successful, returns OPJ_FALSE otherwise
|
2005-12-02 14:34:15 +01:00
|
|
|
*/
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL opj_bio_inalign(opj_bio_t *bio);
|
2005-12-02 14:34:15 +01:00
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/*@}*/
|
2004-02-13 10:47:40 +01:00
|
|
|
|
2005-12-02 14:34:15 +01:00
|
|
|
/*@}*/
|
2004-02-13 10:47:40 +01:00
|
|
|
|
2005-12-02 14:34:15 +01:00
|
|
|
#endif /* __BIO_H */
|
2003-11-27 11:10:17 +01:00
|
|
|
|