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

Method encode

dlib/entropy_encoder/entropy_encoder_kernel_2.cpp:98–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96// ----------------------------------------------------------------------------------------
97
98 void entropy_encoder_kernel_2::
99 encode (
100 uint32 low_count,
101 uint32 high_count,
102 uint32 total
103 )
104 {
105 // note that we must add one because of the convention that
106 // high == the real upper range minus 1
107 uint32 r = (high-low+1)/total;
108
109 // note that we must subtract 1 to preserve the convention that
110 // high == the real upper range - 1
111 high = low + r*high_count-1;
112 low = low + r*low_count;
113
114
115
116 while (true )
117 {
118
119 // if high and low don't have the same 8 high order bits
120 if ((high&0xFF000000) != (low&0xFF000000))
121 {
122 // if the distance between high and low is small and there aren't
123 // any bits we can roll off then force high and low to have common high
124 // order bits.
125 if ((high-low < 0x10000))
126 {
127 if (high-low > 0x1000)
128 {
129 high>>=1;
130 low>>=1;
131 high = low = high+low;
132 high += 0xFF;
133 low -= 0xFF;
134 }
135 else /**/
136 {
137 high>>=1;
138 low>>=1;
139 high = low = high+low;
140 }
141 }
142 else
143 {
144 // there are no bits to roll off and high and low are not
145 // too close so just quit the loop
146 break;
147 }
148
149 }
150 // else if there are 8 bits we can roll off
151 else
152 {
153 // write the 8 high order bits from low into buf
154 unsigned char buf = static_cast<unsigned char>(low>>24);
155

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected