~ubuntu-branches/ubuntu/utopic/p7zip/utopic-updates

« back to all changes in this revision

Viewing changes to 7zip/Compress/RangeCoder/RangeCoder.h

  • Committer: Bazaar Package Importer
  • Author(s): Mohammed Adnène Trojette
  • Date: 2006-02-10 20:54:59 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060210205459-qbpkkabtqdd97zo7
Tags: 4.33.dfsg-1
* New upstream release
* Move p7zip from /usr/share to /usr/bin
   - modify debian/install
   - write debian/p7zip.1
* debian/README.Debian: document directory exclusion
* patches/01_add_help_switch: 7z --help works now (Closes: #353235)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
class CEncoder
16
16
{
17
 
  UInt32 _ffNum;
 
17
  UInt32 _cacheSize;
18
18
  Byte _cache;
19
19
public:
20
20
  UInt64 Low;
28
28
    Stream.Init();
29
29
    Low = 0;
30
30
    Range = 0xFFFFFFFF;
31
 
    _ffNum = 0;
 
31
    _cacheSize = 1;
32
32
    _cache = 0;
33
33
  }
34
34
 
54
54
    }
55
55
  }
56
56
 
57
 
  /*
58
 
  void EncodeDirectBitsDiv(UInt32 value, UInt32 numTotalBits)
59
 
  {
60
 
    Low += value * (Range >>= numTotalBits);
61
 
    Normalize();
62
 
  }
63
 
  
64
 
  void EncodeDirectBitsDiv2(UInt32 value, UInt32 numTotalBits)
65
 
  {
66
 
    if (numTotalBits <= kNumBottomBits)
67
 
      EncodeDirectBitsDiv(value, numTotalBits);
68
 
    else
69
 
    {
70
 
      EncodeDirectBitsDiv(value >> kNumBottomBits, (numTotalBits - kNumBottomBits));
71
 
      EncodeDirectBitsDiv(value & ((1 << kBottomValueBits) - 1), kNumBottomBits);
72
 
    }
73
 
  }
74
 
  */
75
57
  void ShiftLow()
76
58
  {
77
 
    if (Low < (UInt32)0xFF000000 || UInt32(Low >> 32) == 1) 
 
59
    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0) 
78
60
    {
79
 
      Stream.WriteByte(Byte(_cache + Byte(Low >> 32)));            
80
 
      for (;_ffNum != 0; _ffNum--) 
81
 
        Stream.WriteByte(Byte(0xFF + Byte(Low >> 32)));
82
 
      _cache = Byte(UInt32(Low) >> 24);                      
 
61
      Byte temp = _cache;
 
62
      do
 
63
      {
 
64
        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));
 
65
        temp = 0xFF;
 
66
      }
 
67
      while(--_cacheSize != 0);
 
68
      _cache = (Byte)((UInt32)Low >> 24);                      
83
69
    } 
84
 
    else 
85
 
      _ffNum++;                               
86
 
    Low = UInt32(Low) << 8;                           
 
70
    _cacheSize++;                               
 
71
    Low = (UInt32)Low << 8;                           
87
72
  }
88
73
  
89
74
  void EncodeDirectBits(UInt32 value, int numTotalBits)
118
103
    }
119
104
  }
120
105
 
121
 
  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _ffNum; }
 
106
  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }
122
107
};
123
108
 
124
109
class CDecoder
162
147
    Normalize();
163
148
  }
164
149
 
165
 
  /*
166
 
  UInt32 DecodeDirectBitsDiv(UInt32 numTotalBits)
167
 
  {
168
 
    Range >>= numTotalBits;
169
 
    UInt32 threshold = Code / Range;
170
 
    Code -= threshold * Range;
171
 
    
172
 
    Normalize();
173
 
    return threshold;
174
 
  }
175
 
 
176
 
  UInt32 DecodeDirectBitsDiv2(UInt32 numTotalBits)
177
 
  {
178
 
    if (numTotalBits <= kNumBottomBits)
179
 
      return DecodeDirectBitsDiv(numTotalBits);
180
 
    UInt32 result = DecodeDirectBitsDiv(numTotalBits - kNumBottomBits) << kNumBottomBits;
181
 
    return (result | DecodeDirectBitsDiv(kNumBottomBits));
182
 
  }
183
 
  */
184
 
 
185
150
  UInt32 DecodeDirectBits(int numTotalBits)
186
151
  {
187
152
    UInt32 range = Range;