1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
49 #pragma warning( disable: 4711 4324 )
52 #define RBS_THROW_EOS -123 /* <end of stream> exception code */
53 #define RBS_THROW_FORB -124 /* <forrbidden huffman code> exception code */
54 #define RBS_HUFF_FORB 2047 /* forrbidden huffman code "value" */
56 typedef unsigned char uchar;
57 typedef unsigned long ulong;
59 // class RBaseStream - base class for other reading streams.
65 virtual ~RBaseStream();
67 virtual bool Open( const char* filename );
69 void SetBlockSize( int block_size, int unGetsize = 4 );
71 void SetPos( int pos );
73 void Skip( int bytes );
89 virtual void ReadBlock();
90 virtual void Release();
91 virtual void Allocate();
95 // class RLByteStream - uchar-oriented stream.
96 // l in prefix means that the least significant uchar of a multi-uchar value goes first
97 class RLByteStream : public RBaseStream
100 virtual ~RLByteStream();
103 void GetBytes( void* buffer, int count, int* readed = 0 );
108 // class RMBitStream - uchar-oriented stream.
109 // m in prefix means that the most significant uchar of a multi-uchar value go first
110 class RMByteStream : public RLByteStream
113 virtual ~RMByteStream();
119 // class RLBitStream - bit-oriented stream.
120 // l in prefix means that the least significant bit of a multi-bit value goes first
121 class RLBitStream : public RBaseStream
124 virtual ~RLBitStream();
126 void SetPos( int pos );
129 int Show( int bits );
130 int GetHuff( const short* table );
131 void Move( int shift );
132 void Skip( int bytes );
136 virtual void ReadBlock();
139 // class RMBitStream - bit-oriented stream.
140 // m in prefix means that the most significant bit of a multi-bit value goes first
141 class RMBitStream : public RLBitStream
144 virtual ~RMBitStream();
146 void SetPos( int pos );
149 int Show( int bits );
150 int GetHuff( const short* table );
151 void Move( int shift );
152 void Skip( int bytes );
155 virtual void ReadBlock();
159 // WBaseStream - base class for output streams
165 virtual ~WBaseStream();
167 virtual bool Open( const char* filename );
168 virtual void Close();
169 void SetBlockSize( int block_size );
183 virtual void WriteBlock();
184 virtual void Release();
185 virtual void Allocate();
189 // class WLByteStream - uchar-oriented stream.
190 // l in prefix means that the least significant uchar of a multi-byte value goes first
191 class WLByteStream : public WBaseStream
194 virtual ~WLByteStream();
196 void PutByte( int val );
197 void PutBytes( const void* buffer, int count );
198 void PutWord( int val );
199 void PutDWord( int val );
203 // class WLByteStream - uchar-oriented stream.
204 // m in prefix means that the least significant uchar of a multi-byte value goes last
205 class WMByteStream : public WLByteStream
208 virtual ~WMByteStream();
210 void PutWord( int val );
211 void PutDWord( int val );
215 // class WLBitStream - bit-oriented stream.
216 // l in prefix means that the least significant bit of a multi-bit value goes first
217 class WLBitStream : public WBaseStream
220 virtual ~WLBitStream();
223 void Put( int val, int bits );
224 void PutHuff( int val, const int* table );
229 virtual void WriteBlock();
233 // class WMBitStream - bit-oriented stream.
234 // l in prefix means that the least significant bit of a multi-bit value goes first
235 class WMBitStream : public WBaseStream
239 virtual ~WMBitStream();
241 bool Open( const char* filename );
243 virtual void Flush();
246 void Put( int val, int bits );
247 void PutHuff( int val, const ulong* table );
253 virtual void WriteBlock();
259 #define BSWAP(v) (((v)<<24)|(((v)&0xff00)<<8)| \
260 (((v)>>8)&0xff00)|((unsigned)(v)>>24))
262 int* bsCreateSourceHuffmanTable( const uchar* src, int* dst,
263 int max_bits, int first_bits );
264 bool bsCreateDecodeHuffmanTable( const int* src, short* dst, int max_size );
265 bool bsCreateEncodeHuffmanTable( const int* src, ulong* dst, int max_size );
267 void bsBSwapBlock( uchar *start, uchar *end );
268 bool bsIsBigEndian( void );
270 extern const ulong bs_bit_mask[];
272 #endif/*_BITSTRM_H_*/