-void encode_coeff(uint coeff, uint bits, uint sign_bias, inout RansEncoder enc)
+uint RansEncFlush(inout RansEncoder enc)
+{
+ RansPutByte(enc.rans >> 24, enc);
+ RansPutByte(enc.rans >> 16, enc);
+ RansPutByte(enc.rans >> 8, enc);
+ RansPutByte(enc.rans >> 0, enc);
+
+ uint num_bytes_written = (enc.rans_start_offset - enc.rans_offset) * 4 + enc.bytes_in_buffer;
+
+ // Make sure there's nothing left in the buffer.
+ RansPutByte(0, enc);
+ RansPutByte(0, enc);
+ RansPutByte(0, enc);
+
+ return num_bytes_written;
+}
+
+int sign_extend(uint coeff, uint bits)
+{
+ return int(coeff << (32 - bits)) >> (32 - bits);
+}
+
+void encode_coeff(int signed_k, inout RansEncoder enc)