📄 bitstr.h
字号:
/****************************************************************************//* * bitstr.h -- C Definition of BitStream files handling * * Author : St閜hane TAVENARD * * (C) Copyright 1997-1998 St閜hane TAVENARD * All Rights Reserved * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//****************************************************************************/#ifndef BITSTR_H#define BITSTR_H/****************************************************************************//* * Endianess optimizations. */#ifndef LITTLE_ENDIAN#define BSTR_MSBF#endif#ifdef BSTR_MSBF// This target is MSB first, so faster#define BSTR_BUFF unsigned int#else#define BSTR_BUFF unsigned char#endif/* * File stream access: * * open: open the bitstream, should return the file handle or NULL * if failed * close: close the bitstream * read: read bytes from bitstream, return # of bytes read or <=0 if EOF * seek: seek to an absolute byte position inside the bitstream, * return 0 if Ok */typedef struct { long (*open)(char *stream_name, long buffer_size, long *stream_size); void (*close)(long handle); long (*read)(long handle, void *buffer, long num_bytes); int (*seek)(long handle, long abs_byte_seek_pos);} BITSTREAM_ACCESS;typedef struct { BITSTREAM_ACCESS baccess; long file_handle; long buffer_size; BSTR_BUFF *buffer; BSTR_BUFF *buffer_ptr; long remain_bytes; long bitstream_size; int end_of_stream; unsigned int bit_cache; int cache_size; unsigned int bits; long buffer_len; long buffer_pos;} BITSTREAM;#define BSTR_MAX_BITS 32extern BITSTREAM *BSTR_open(BITSTREAM_ACCESS *bs_access, char *filename, long buffer_size);extern unsigned long BSTR_read_byte(BITSTREAM *b);extern unsigned int BSTR_read_bytes(BITSTREAM *b, unsigned int count, char *buffer);extern unsigned long BSTR_read_bit_cache(BITSTREAM *bitstream);extern unsigned long BSTR_read_bits_cache(BITSTREAM *bitstream, unsigned int bit_count);extern void BSTR_close(BITSTREAM *bitstream);extern int BSTR_seek( BITSTREAM *bitstream, long seek_byte_pos );extern long BSTR_pos( BITSTREAM *bitstream );#define BSTR_end(b) b->end_of_stream#define BSTR_read_bit(b) \ ((b->cache_size-- > 0) ? \ (b->bits = (b->bit_cache & 0x80000000) ? 1 : 0, \ b->bit_cache <<= 1, b->bits) : \ BSTR_read_bit_cache(b))#define BSTR_read_bits(b,c) \ ((b->cache_size >= (c)) ? \ (b->cache_size -= c, b->bits = b->bit_cache >> (32-(c)), \ b->bit_cache <<= c, b->bits) : \ BSTR_read_bits_cache(b,c))/****************************************************************************/#endif /* BITSTR_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -