示例#1
0
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");
}
示例#2
0
void test_bitstream(void)
{
	UINT16 b;
	RFX_BITSTREAM* bs;

	bs = xnew(RFX_BITSTREAM);
	rfx_bitstream_attach(bs, (BYTE*) y_data, sizeof(y_data));
	while (!rfx_bitstream_eos(bs))
	{
		rfx_bitstream_get_bits(bs, 3, b);
		(void) b;
		//printf("%u ", b);
	}
	free(bs);

	//printf("\n");
}
示例#3
0
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");
}
示例#4
0
int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* data, int data_size, INT16* buffer, int buffer_size)
{
	int k;
	int kp;
	int kr;
	int krp;
	UINT16 r;
	INT16* dst;
	RFX_BITSTREAM* bs;

	int vk;
	UINT16 mag16;

	bs = (RFX_BITSTREAM*) malloc(sizeof(RFX_BITSTREAM));
	ZeroMemory(bs, sizeof(RFX_BITSTREAM));

	rfx_bitstream_attach(bs, 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, r);
				if (r)
					break;
				/* 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 */
			GetBits(k, run);
			WriteZeroes(run);

			/* get nonzero value, starting with sign bit and then GRCode for magnitude -1 */
			GetBits(1, sign);

			/* magnitude - 1 was coded (because it was nonzero) */
			GetGRCode(&krp, &kr, vk, mag16)
			mag = (int) (mag16 + 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 */
			GetGRCode(&krp, &kr, vk, mag16) /* values coded are 2 * magnitude - sign */
			mag = (UINT32) mag16;

			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 */
				GetBits(nIdx, val1);

				/* 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));
			}
		}
	}

	free(bs);

	return (dst - buffer);
}