00001 /* 00002 libit - Library for basic source and channel coding functions 00003 Copyright (C) 2005-2005 Vivien Chappelier, Herve Jegou 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 /* 00021 Arithmetic coder/decoder 00022 Copyright (C) 2005 Vivien Chappelier 00023 */ 00024 00025 /*---------------------------------------------------------------------------*/ 00026 /*! \defgroup entropycoding */ 00027 /* @{ */ 00028 /*---------------------------------------------------------------------------*/ 00029 00030 #ifndef __it_arithmetic_codec_h 00031 #define __it_arithmetic_codec_h 00032 00033 typedef unsigned char arithmetic_codec_bit_t; 00034 typedef unsigned long arithmetic_codec_register_t; 00035 00036 typedef struct _arithmetic_coder_t_ { 00037 int precision; /* # bits of precision */ 00038 arithmetic_codec_register_t lower; /* lower bound of the interval */ 00039 arithmetic_codec_register_t range; /* range of the interval */ 00040 int pending; /* # pending bits to be written */ 00041 bvec buffer; /* buffer for the sequence of bits */ 00042 arithmetic_codec_bit_t *sequence; /* pointer to the current bit */ 00043 } arithmetic_coder_t; 00044 00045 typedef struct _arithmetic_decoder_t_ { 00046 int precision; /* # bits of precision */ 00047 arithmetic_codec_register_t lower; /* lower bound of the interval */ 00048 arithmetic_codec_register_t range; /* range of the interval */ 00049 arithmetic_codec_register_t value; /* encoded value */ 00050 bvec buffer; /* sequence of bits */ 00051 arithmetic_codec_bit_t *sequence; /* pointer to the current bit */ 00052 } arithmetic_decoder_t; 00053 00054 00055 /* encoder constructor/destructor */ 00056 arithmetic_coder_t *arithmetic_coder_new (int precision); 00057 void arithmetic_coder_delete (arithmetic_coder_t * arithmetic_coder); 00058 00059 /* start encoding */ 00060 void arithmetic_coder_start (arithmetic_coder_t * arithmetic_coder, 00061 bvec buffer); 00062 /* stop encoding and return the number of bits written to the buffer */ 00063 int arithmetic_coder_stop (arithmetic_coder_t * arithmetic_coder); 00064 00065 /* encode one bit with probability prob_0 of being 0 */ 00066 void arithmetic_coder_encode_bit (arithmetic_coder_t * arithmetic_coder, 00067 double prob_0, arithmetic_codec_bit_t bit); 00068 /* encode a symbol with the binary arithmetic coder using unary binarization */ 00069 void arithmetic_coder_encode_symbol (arithmetic_coder_t * arithmetic_coder, 00070 vec pdf, int symbol); 00071 00072 /* decoder constructor/destructor */ 00073 arithmetic_decoder_t *arithmetic_decoder_new (int precision); 00074 void arithmetic_decoder_delete (arithmetic_decoder_t * arithmetic_decoder); 00075 00076 /* start decoding */ 00077 void arithmetic_decoder_start (arithmetic_decoder_t * arithmetic_decoder, 00078 bvec buffer); 00079 /* stop decoding and return the number of bits read from the buffer */ 00080 int arithmetic_decoder_stop (arithmetic_decoder_t * arithmetic_decoder); 00081 00082 /* decode one bit with probability prob_zero of being 0 */ 00083 arithmetic_codec_bit_t arithmetic_decoder_decode_bit (arithmetic_decoder_t * 00084 arithmetic_decoder, 00085 double prob_zero); 00086 00087 /* decode a symbol with the binary arithmetic coder using unary binarization */ 00088 int arithmetic_decoder_decode_symbol (arithmetic_decoder_t * 00089 arithmetic_decoder, vec pdf); 00090 00091 /*@}*/ 00092 00093 #endif
|
|