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

Method flush

dlib/entropy_encoder/entropy_encoder_kernel_1.cpp:175–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173// ----------------------------------------------------------------------------------------
174
175 void entropy_encoder_kernel_1::
176 flush (
177 )
178 {
179 // flush the next 4 or 5 bytes that are buffered
180 // thats whatever is contained in buf and then all of low plus any extra
181 // bits needed to pad that to be an even 4 or 5 bytes
182
183
184 if (buf_used != 8)
185 {
186 buf <<= (8-buf_used);
187 buf |= static_cast<unsigned char>(low>>(24+buf_used));
188 low <<= (8-buf_used);
189 }
190
191 if (streambuf->sputn(reinterpret_cast<char*>(&buf),1) == 0)
192 throw std::ios_base::failure("error occurred in the entropy_encoder object");
193
194
195
196 buf = static_cast<unsigned char>((low >> 24)&0xFF);
197 if (streambuf->sputn(reinterpret_cast<char*>(&buf),1) == 0)
198 throw std::ios_base::failure("error occurred in the entropy_encoder object");
199
200
201
202
203 buf = static_cast<unsigned char>((low >> 16)&0xFF);
204 if (streambuf->sputn(reinterpret_cast<char*>(&buf),1)==0)
205 throw std::ios_base::failure("error occurred in the entropy_encoder object");
206
207
208
209 buf = static_cast<unsigned char>((low >> 8)&0xFF);
210 if (streambuf->sputn(reinterpret_cast<char*>(&buf),1)==0)
211 throw std::ios_base::failure("error occurred in the entropy_encoder object");
212
213
214
215 if (buf_used != 0)
216 {
217 buf = static_cast<unsigned char>((low)&0xFF);
218 if (streambuf->sputn(reinterpret_cast<char*>(&buf),1)==0)
219 throw std::ios_base::failure("error occurred in the entropy_encoder object");
220 }
221
222
223
224 // make sure the stream buffer flushes to its I/O channel
225 streambuf->pubsync();
226
227
228 // reset the encoder state
229 buf_used = 0;
230 buf = 0;
231 low = initial_low;
232 high = initial_high;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected