MCPcopy Create free account
hub / github.com/davisking/dlib / decode

Method decode

dlib/entropy_decoder/entropy_decoder_kernel_1.cpp:119–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117// ----------------------------------------------------------------------------------------
118
119 void entropy_decoder_kernel_1::
120 decode (
121 uint32 low_count,
122 uint32 high_count
123 )
124 {
125 // note that we must subtract 1 to preserve the convention that
126 // high == the real upper range - 1
127 high = low + r*high_count - 1;
128 low = low + r*low_count;
129 r = 0;
130
131
132
133 while (true)
134 {
135
136 // if the highest order bit in high and low is the same
137 if ( low >= 0x80000000 || high < 0x80000000)
138 {
139 // make sure buf isn't empty
140 if (buf_used == 0)
141 {
142 buf_used = 8;
143 if (streambuf->sgetn(reinterpret_cast<char*>(&buf),1)==0)
144 {
145 // if there isn't anything else in the streambuffer then just
146 // make buf zero.
147 buf = 0;
148 }
149 }
150
151 // we will be taking one bit from buf to replace the one we threw away
152 --buf_used;
153
154 // roll off the bit in target
155 target <<= 1;
156
157 // roll off the bit
158 high <<= 1;
159 low <<= 1;
160 high |= 1; // note that it is ok to add one to high here because
161 // of the convention that high == real upper range - 1.
162 // so that means that if we want to shift the upper range
163 // left by one then we must shift a one into high also
164 // since real upper range == high + 0.999999999...
165
166 // make sure low is never zero
167 if (low == 0)
168 low = 1;
169
170 // take a bit from buf to fill in the one we threw away
171 target += (buf>>buf_used)&0x01;
172 }
173 // if the distance between high and low is small and there aren't
174 // any bits we can roll off then round low up or high down.
175 else if (high-low < 0x10000)
176 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected