~ubuntu-branches/ubuntu/trusty/advancecomp/trusty

« back to all changes in this revision

Viewing changes to 7z/LSBFEncoder.cc

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ozarowski
  • Date: 2006-05-13 21:15:49 UTC
  • Revision ID: james.westby@ubuntu.com-20060513211549-2vu7peis643ojcm5
Tags: upstream-1.15
ImportĀ upstreamĀ versionĀ 1.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "Portable.h"
 
2
#include "LSBFEncoder.h"
 
3
 
 
4
namespace NStream {
 
5
namespace NLSBF {
 
6
 
 
7
void CEncoder::WriteBits(UINT32 aValue, UINT32 aNumBits)
 
8
{
 
9
  while(aNumBits > 0)
 
10
  {
 
11
    UINT32 aNumNewBits = MyMin(aNumBits, m_BitPos);
 
12
    aNumBits -= aNumNewBits;
 
13
 
 
14
    UINT32 aMask = (1 << aNumNewBits) - 1;
 
15
    m_CurByte |= (aValue & aMask) << (8 - m_BitPos);
 
16
    aValue >>= aNumNewBits;
 
17
 
 
18
    m_BitPos -= aNumNewBits;
 
19
 
 
20
    if (m_BitPos == 0)
 
21
    {
 
22
      m_Stream.WriteByte(m_CurByte);
 
23
      m_BitPos = 8;
 
24
      m_CurByte = 0;
 
25
    }
 
26
  }
 
27
}
 
28
 
 
29
 
 
30
void CReverseEncoder::WriteBits(UINT32 aValue, UINT32 aNumBits)
 
31
{
 
32
  UINT32 aReverseValue = 0;
 
33
  for(UINT32 i = 0; i < aNumBits; i++) 
 
34
  {
 
35
    aReverseValue <<= 1;
 
36
    aReverseValue |= aValue & 1;
 
37
    aValue >>= 1;
 
38
  } 
 
39
  m_Encoder->WriteBits(aReverseValue, aNumBits);
 
40
}
 
41
 
 
42
}}