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

Method decode

dlib/entropy_decoder/entropy_decoder_kernel_2.cpp:112–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110// ----------------------------------------------------------------------------------------
111
112 void entropy_decoder_kernel_2::
113 decode (
114 uint32 low_count,
115 uint32 high_count
116 )
117 {
118 // note that we must subtract 1 to preserve the convention that
119 // high == the real upper range - 1
120 high = low + r*high_count - 1;
121 low = low + r*low_count;
122 r = 0;
123
124
125 while (true )
126 {
127
128 // if high and low don't have the same 8 high order bits
129 if ((high&0xFF000000) != (low&0xFF000000))
130 {
131 // if the distance between high and low is small and there aren't
132 // any bits we can roll off then force high and low to have common high
133 // order bits.
134 if ((high-low < 0x10000))
135 {
136 if (high-low > 0x1000)
137 {
138 high>>=1;
139 low>>=1;
140 high = low = high+low;
141 high += 0xFF;
142 low -= 0xFF;
143 }
144 else /**/
145 {
146 high>>=1;
147 low>>=1;
148 high = low = high+low;
149 }
150 }
151 else
152 {
153 // there are no bits to roll off and high and low are not
154 // too close so just quit the loop
155 break;
156 }
157
158 }
159 // else if there are 8 bits we can roll off
160 else
161 {
162 unsigned char buf;
163 if (streambuf->sgetn(reinterpret_cast<char*>(&buf),1)==0)
164 {
165 // if there isn't anything else in the streambuffer then just
166 // make buf zero.
167 buf = 0;
168 }
169

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected