initial release of jp3d library and codec
[openjpeg.git] / libjp3dvm / bio.h
1 /*\r
2  * Copyright (c) 2001-2003, David Janssens\r
3  * Copyright (c) 2002-2003, Yannick Verschueren\r
4  * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe\r
5  * Copyright (c) 2005, Herv� Drolon, FreeImage Team\r
6  * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium\r
7  * All rights reserved.\r
8  *\r
9  * Redistribution and use in source and binary forms, with or without\r
10  * modification, are permitted provided that the following conditions\r
11  * are met:\r
12  * 1. Redistributions of source code must retain the above copyright\r
13  *    notice, this list of conditions and the following disclaimer.\r
14  * 2. Redistributions in binary form must reproduce the above copyright\r
15  *    notice, this list of conditions and the following disclaimer in the\r
16  *    documentation and/or other materials provided with the distribution.\r
17  *\r
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'\r
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
28  * POSSIBILITY OF SUCH DAMAGE.\r
29  */\r
30 \r
31 #ifndef __BIO_H\r
32 #define __BIO_H\r
33 /** \r
34 @file bio.h\r
35 @brief Implementation of an individual bit input-output (BIO)\r
36 \r
37 The functions in BIO.C have for goal to realize an individual bit input - output.\r
38 */\r
39 \r
40 /** @defgroup BIO BIO - Individual bit input-output stream */\r
41 /*@{*/\r
42 \r
43 /**\r
44 Individual bit input-output stream (BIO)\r
45 */\r
46 typedef struct opj_bio {\r
47 /** pointer to the start of the buffer */\r
48         unsigned char *start;   \r
49 /** pointer to the end of the buffer */\r
50         unsigned char *end;             \r
51 /** pointer to the present position in the buffer */\r
52         unsigned char *bp;              \r
53 /** temporary place where each byte is read or written */\r
54         unsigned int buf;               \r
55 /** coder : number of bits free to write. decoder : number of bits read */\r
56         int ct;                                 \r
57 } opj_bio_t;\r
58 \r
59 /** @name Funciones generales */\r
60 /*@{*/\r
61 /* ----------------------------------------------------------------------- */\r
62 /**\r
63 Create a new BIO handle \r
64 @return Returns a new BIO handle if successful, returns NULL otherwise\r
65 */\r
66 opj_bio_t* bio_create();\r
67 /**\r
68 Destroy a previously created BIO handle\r
69 @param bio BIO handle to destroy\r
70 */\r
71 void bio_destroy(opj_bio_t *bio);\r
72 /**\r
73 Number of bytes written.\r
74 @param bio BIO handle\r
75 @return Returns the number of bytes written\r
76 */\r
77 int bio_numbytes(opj_bio_t *bio);\r
78 /**\r
79 Init encoder\r
80 @param bio BIO handle\r
81 @param bp Output buffer\r
82 @param len Output buffer length \r
83 */\r
84 void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len);\r
85 /**\r
86 Init decoder\r
87 @param bio BIO handle\r
88 @param bp Input buffer\r
89 @param len Input buffer length \r
90 */\r
91 void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len);\r
92 /**\r
93 Write bits\r
94 @param bio BIO handle\r
95 @param v Value of bits\r
96 @param n Number of bits to write\r
97 */\r
98 void bio_write(opj_bio_t *bio, int v, int n);\r
99 /**\r
100 Read bits\r
101 @param bio BIO handle\r
102 @param n Number of bits to read \r
103 @return Returns the corresponding read number\r
104 */\r
105 int bio_read(opj_bio_t *bio, int n);\r
106 /**\r
107 Flush bits\r
108 @param bio BIO handle\r
109 @return Returns 1 if successful, returns 0 otherwise\r
110 */\r
111 int bio_flush(opj_bio_t *bio);\r
112 /**\r
113 Passes the ending bits (coming from flushing)\r
114 @param bio BIO handle\r
115 @return Returns 1 if successful, returns 0 otherwise\r
116 */\r
117 int bio_inalign(opj_bio_t *bio);\r
118 /**\r
119 Read a bit\r
120 @param bio BIO handle\r
121 @return Returns the read bit\r
122 */\r
123 /* MOD antonin */\r
124 //int bio_getbit(opj_bio_t *bio);\r
125 /* DOM */\r
126 /* ----------------------------------------------------------------------- */\r
127 /*@}*/\r
128 \r
129 /*@}*/\r
130 \r
131 #endif /* __BIO_H */\r
132 \r