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

Method encode

dlib/entropy_encoder_model/entropy_encoder_model_kernel_2.h:174–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172 typename ccbig
173 >
174 void entropy_encoder_model_kernel_2<alphabet_size,entropy_encoder,cc,ccbig>::
175 encode (
176 unsigned long symbol
177 )
178 {
179 unsigned long low_count = 0, high_count = 0, total_count = 0;
180
181
182 ccbig& context = *order_1[previous_symbol];
183
184 // if we have seen this symbol in the order-1 context
185 if (context.get_range(symbol,low_count,high_count,total_count))
186 {
187 // update the count for this symbol
188 context.increment_count(symbol,2);
189 // encode this symbol
190 coder.encode(low_count,high_count,total_count);
191 previous_symbol = symbol;
192 return;
193 }
194
195 // we didn't find the symbol in the order-1 context so we must escape to a
196 // lower context.
197
198 // escape to the order-0 context
199 context.get_range(alphabet_size,low_count,high_count,total_count);
200 coder.encode(low_count,high_count,total_count);
201
202
203 // increment counts for the escape symbol and the current symbol
204 context.increment_count(alphabet_size);
205 context.increment_count(symbol,2);
206
207 previous_symbol = symbol;
208
209
210
211
212
213 // if we have seen this symbol in the order-0 context
214 if (order_0.get_range(symbol,low_count,high_count,total_count))
215 {
216 // update the count for this symbol
217 order_0.increment_count(symbol,2);
218 // encode this symbol
219 coder.encode(low_count,high_count,total_count);
220 return;
221 }
222
223 // if we are here then the symbol does not appear in the order-0 context
224
225
226 // since we have never seen the current symbol in this context
227 // escape from order-0 context
228 order_0.get_range(alphabet_size,low_count,high_count,total_count);
229 coder.encode(low_count,high_count,total_count);
230 // increment the count for the escape symbol
231 order_0.increment_count(alphabet_size);

Callers

nothing calls this directly

Calls 1

encodeMethod · 0.45

Tested by

no test coverage detected