void test_bitstream(void) { unsigned int b; RFX_BITSTREAM * bs; bs = rfx_bitstream_new(); rfx_bitstream_put_bytes(bs, y_data, sizeof(y_data)); while (!rfx_bitstream_eos(bs)) { b = rfx_bitstream_get_bits(bs, 3); //printf("%u ", b); } rfx_bitstream_free(bs); //printf("\n"); }
void test_bitstream(void) { uint16 b; RFX_BITSTREAM * bs; bs = rfx_bitstream_new(); rfx_bitstream_put_buffer(bs, (uint8 *) y_data, sizeof(y_data)); while (!rfx_bitstream_eos(bs)) { b = rfx_bitstream_get_bits(bs, 3); //printf("%u ", b); } rfx_bitstream_free(bs); //printf("\n"); }
void test_bitstream_enc(void) { uint8 buffer[10]; RFX_BITSTREAM * bs; int i; bs = rfx_bitstream_new(); memset(buffer, 0, sizeof(buffer)); rfx_bitstream_put_buffer(bs, buffer, sizeof(buffer)); for (i = 0; i < 16; i++) { rfx_bitstream_put_bits(bs, i, 5); } /*for (i = 0; i < sizeof(buffer); i++) { printf("%X ", buffer[i]); }*/ rfx_bitstream_free(bs); //printf("\n"); }
int rfx_rlgr_decode(RLGR_MODE mode, const uint8 * data, int data_size, uint32 * buffer, int buffer_size) { int k; int kp; int kr; int krp; uint32 * dst; RFX_BITSTREAM * bs; bs = rfx_bitstream_new(); rfx_bitstream_put_buffer(bs, (uint8 *) data, data_size); dst = buffer; /* initialize the parameters */ k = 1; kp = k << LSGR; kr = 1; krp = kr << LSGR; while (!rfx_bitstream_eos(bs) && buffer_size > 0) { int run; if (k) { int mag; uint32 sign; /* RL MODE */ while (!rfx_bitstream_eos(bs) && GetBits(1) == 0) { /* we have an RL escape "0", which translates to a run (1<<k) of zeros */ WriteZeroes(1 << k); UpdateParam(kp, UP_GR, k); /* raise k and kp up because of zero run */ } /* next k bits will contain remaining run or zeros */ run = GetBits(k); WriteZeroes(run); /* get nonzero value, starting with sign bit and then GRCode for magnitude -1 */ sign = GetBits(1); /* magnitude - 1 was coded (because it was nonzero) */ mag = (int) GetGRCode(&krp, &kr) + 1; WriteValue(sign ? -mag : mag); UpdateParam(kp, -DN_GR, k); /* lower k and kp because of nonzero term */ } else { uint32 mag; uint32 nIdx; uint32 val1; uint32 val2; /* GR (GOLOMB-RICE) MODE */ mag = GetGRCode(&krp, &kr); /* values coded are 2 * magnitude - sign */ if (mode == RLGR1) { if (!mag) { WriteValue(0); UpdateParam(kp, UQ_GR, k); /* raise k and kp due to zero */ } else { WriteValue(GetIntFrom2MagSign(mag)); UpdateParam(kp, -DQ_GR, k); /* lower k and kp due to nonzero */ } } else /* mode == RLGR3 */ { /* * In GR mode FOR RLGR3, we have encoded the * sum of two (2 * mag - sign) values */ /* maximum possible bits for first term */ GetMinBits(mag, nIdx); /* decode val1 is first term's (2 * mag - sign) value */ val1 = GetBits(nIdx); /* val2 is second term's (2 * mag - sign) value */ val2 = mag - val1; if (val1 && val2) { /* raise k and kp if both terms nonzero */ UpdateParam(kp, -2 * DQ_GR, k); } else if (!val1 && !val2) { /* lower k and kp if both terms zero */ UpdateParam(kp, 2 * UQ_GR, k); } WriteValue(GetIntFrom2MagSign(val1)); WriteValue(GetIntFrom2MagSign(val2)); } } } rfx_bitstream_free(bs); return (dst - buffer); }