2 * $Id: GolombBuffer.cpp 3526 2011-08-01 15:46:29Z XhmikosR $
4 * (C) 2006-2010 see AUTHORS
6 * This file is part of mplayerc.
8 * Mplayerc is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * Mplayerc is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "GolombBuffer.h"
27 CGolombBuffer::CGolombBuffer(BYTE
* pBuffer
, int nSize
)
35 UINT64
CGolombBuffer::BitRead(int nBits
, bool fPeek
)
37 // ASSERT(nBits >= 0 && nBits <= 64);
39 while(m_bitlen
< nBits
) {
42 if (m_nBitPos
>= m_nSize
) {
46 *(BYTE
*)&m_bitbuff
= m_pBuffer
[m_nBitPos
++];
50 int bitlen
= m_bitlen
- nBits
;
52 UINT64 ret
= (m_bitbuff
>> bitlen
) & ((1ui
64 << nBits
) - 1);
55 m_bitbuff
&= ((1ui
64 << bitlen
) - 1);
62 UINT64
CGolombBuffer::UExpGolombRead()
65 for(BYTE b
= 0; !b
; n
++) {
68 return (1ui
64 << n
) - 1 + BitRead(n
);
71 INT64
CGolombBuffer::SExpGolombRead()
73 UINT64 k
= UExpGolombRead();
74 return ((k
&1) ? 1 : -1) * ((k
+ 1) >> 1);
77 void CGolombBuffer::BitByteAlign()
82 __int64
CGolombBuffer::GetPos()
84 return m_nBitPos
- (m_bitlen
>>3);
87 void CGolombBuffer::ReadBuffer(BYTE
* pDest
, int nSize
)
89 ASSERT (m_nBitPos
+ nSize
<= m_nSize
);
90 ASSERT (m_bitlen
== 0);
91 nSize
= min (nSize
, m_nSize
- m_nBitPos
);
93 memcpy (pDest
, m_pBuffer
+m_nBitPos
, nSize
);
97 void CGolombBuffer::Reset()
104 void CGolombBuffer::Reset(BYTE
* pNewBuffer
, int nNewSize
)
106 m_pBuffer
= pNewBuffer
;
112 void CGolombBuffer::SkipBytes(int nCount
)