Exemplo n.º 1
0
int blockIntra(bitstream *bs, mp4_private_t *priv, int block_num, int coded)
{
	int i;
	int dct_dc_size, dct_dc_diff;
	event_t event;
    vop_header_t *h = &priv->vop_header;

	//clearblock(ld->block); // clearblock

	// dc coeff
	setDCscaler(priv, block_num); // calculate DC scaler

	if (block_num < 4) {
		dct_dc_size = getDCsizeLum(bs);
		if (dct_dc_size != 0) 
			dct_dc_diff = getDCdiff(bs, dct_dc_size);
		else 
			dct_dc_diff = 0;
		if (dct_dc_size > 8)
			get_bits(bs, 1); // marker bit
	}
	else {
		dct_dc_size = getDCsizeChr(bs);
		if (dct_dc_size != 0)
			dct_dc_diff = getDCdiff(bs, dct_dc_size);
		else 
			dct_dc_diff = 0;
		if (dct_dc_size > 8)
			get_bits(bs, 1); // marker bit
	}

	//ld->block[0] = (short) dct_dc_diff;

	// dc reconstruction, prediction direction
	//dc_recon(block_num, &ld->block[0]);

	if (coded) 
	{
#if 0        
		unsigned int * zigzag; // zigzag scan dir

		if (h->ac_pred_flag == 1) {

			if (priv->coeff_pred.predict_dir == TOP)
				zigzag = priv->tables.alternate_horizontal_scan;
			else
				zigzag = priv->tables.alternate_vertical_scan;
		}
		else {
			zigzag = priv->tables.zig_zag_scan;
		}
#endif

		i = 1;
		do // event vld
		{
			event = vld_intra_dct(bs, priv);
/***
			if (event.run == -1)
			{
				printf("Error: invalid vld code\n");
				exit(201);
			}
***/			
			i+= event.run;
			//ld->block[zigzag[i]] = (short) event.level;

//			_Print("Vld Event: Run Level Last %d %d %d\n", event.run, event.level, event.last);

			i++;
		} while (! event.last);
	}

#if 0
	// ac reconstruction
	h->intrablock_rescaled = ac_rescaling(block_num, &ld->block[0]);
	if (! h->intrablock_rescaled)
	{
		ac_recon(block_num, &ld->block[0]);
	}
	ac_store(block_num, &ld->block[0]);

	if (h->quant_type == 0)
	{
		iquant(ld->block, 1);
	}
	else 
	{
		iquant_typefirst(ld->block);
	}

	// inverse dct
	idct(ld->block);
#endif

	return 1;
}
Exemplo n.º 2
0
// Purpose: texture decoding of block_num
int block(bitstream *bs, mp4_private_t *priv, int block_num, int coded)
{
	int i;
	int dct_dc_size, dct_dc_diff;
    vop_header_t *h = &priv->vop_header;
    VdpDecoderMpeg4VolHeader *vol = &priv->mpeg4VolHdr;
    
	int intraFlag = ((h->derived_mb_type == INTRA) || 
		(h->derived_mb_type == INTRA_Q)) ? 1 : 0;
	event_t event;

	//clearblock(ld->block); // clearblock

	if (intraFlag)
	{
		setDCscaler(priv, block_num); // calculate DC scaler

		if (block_num < 4) {
			dct_dc_size = getDCsizeLum(bs);
			if (dct_dc_size != 0) 
				dct_dc_diff = getDCdiff(bs, dct_dc_size);
			else 
				dct_dc_diff = 0;
			if (dct_dc_size > 8)
				get_bits(bs, 1); // marker bit
		}
		else {
			dct_dc_size = getDCsizeChr(bs);
			if (dct_dc_size != 0)
				dct_dc_diff = getDCdiff(bs, dct_dc_size);
			else 
				dct_dc_diff = 0;
			if (dct_dc_size > 8)
				get_bits(bs, 1); // marker bit
		}

		//ld->block[0] = (short) dct_dc_diff;
//		_Print("DC diff: %d\n", dct_dc_diff);
	}
	if (intraFlag)
	{
		// dc reconstruction, prediction direction
		//dc_recon(block_num, &ld->block[0]);
	}

	if (coded) 
	{
#if 0    
		unsigned int * zigzag; // zigzag scan dir

		if ((intraFlag) && (h->ac_pred_flag == 1)) {

			if (priv->coeff_pred.predict_dir == TOP)
				zigzag = priv->tables.alternate_horizontal_scan;
			else
				zigzag = priv->tables.alternate_vertical_scan;
		}
		else {
			zigzag = priv->tables.zig_zag_scan;
		}
#endif

		i = intraFlag ? 1 : 0;
		do // event vld
		{
			event = vld_event(bs, priv, intraFlag);
/***
			if (event.run == -1)
			{
				printf("Error: invalid vld code\n");
				exit(201);
			}
***/			
			i+= event.run;
			//ld->block[zigzag[i]] = (short) event.level;

//			_Print("Vld Event: Run Level Last %d %d %d\n", event.run, event.level, event.last);

			i++;
		} while (! event.last);
	}

	if (intraFlag)
	{
		// ac reconstruction
		// ac_rescaling(...)
		//ac_recon(block_num, &ld->block[0]);
	}

#ifdef _DEBUG_B_ACDC
	if (intraFlag)
	{
		int i;
		_Print("After AcDcRecon:\n");
		_Print("   x ");
		for (i = 1; i < 64; i++) {
			if ((i != 0) && ((i % 8) == 0))
				_Print("\n");
			_Print("%4d ", ld->block[i]);
		}
		_Print("\n");
	}
#endif // _DEBUG_ACDC

	if (vol->quant_type == 0)
	{
		// inverse quantization
		//iquant(ld->block, intraFlag);
	}
	else 
	{
		printf("Error: MPEG-2 inverse quantization NOT implemented\n");
		exit(110);
	}

#ifdef _DEBUG_B_QUANT
	{
		int i;
		_Print("After IQuant:\n");
		_Print("   x ");
		for (i = 1; i < 64; i++) {
			if ((i != 0) && ((i % 8) == 0))
				_Print("\n");
			_Print("%4d ", ld->block[i]);
		}
		_Print("\n");
	}
#endif // _DEBUG_B_QUANT

	// inverse dct
	//idct(ld->block);

	return 1;
}
Exemplo n.º 3
0
static void blockIntra( mpeg_decode* dec, int pos )
{
	int j;
	idct_block_t *block;
	const uint16_t *table = vld_mpeg1;
	int qscale;

	dec->Codec.IDCT.Ptr->Process(dec->Codec.IDCT.Ptr,POSX(pos),POSY(pos));

	block = dec->blockptr;
	qscale = dec->qscale;

	for (j=0;j<6;++j)
	{
		int bitpos;
		int len;

		ClearBlock(block);	
		loadbits(dec);

		{
			int dct_dc_size, dct_dc_diff;

			dct_dc_diff = 0;
			dct_dc_size = j<4 ? getDCsizeLum(dec) : getDCsizeChr(dec); //max11bit

			if (dct_dc_size)
				dct_dc_diff = getDCdiff(dct_dc_size,dec);

			dct_dc_size = j<4 ? 0 : j-4+1;
			DEBUG_MSG2(DEBUG_VCODEC2,T("dc=%d diff=%d"), dec->last_dc[dct_dc_size]+dct_dc_diff, dct_dc_diff );
			dct_dc_diff += dec->last_dc[dct_dc_size];
			dec->last_dc[dct_dc_size] = dct_dc_diff;

			*block = (idct_block_t)(dct_dc_diff << 3);
			len = 1;
		}

		bitpos = dec->bitpos;
		
		for (;;) // event vld
		{
			int code,level;

			loadbits_pos(dec,bitpos);
			code = showbits_pos(dec,bitpos,16);	

			vld_code;
			level = code & 63;
			if (level < 62) 
			{
				level *= qscale;
				code >>= 6;
				code &= 63;
				len += code; // run
				if (len >= 64)
					break;

				code = dec->zigzag[len];
				level *= dec->IntraMatrix[len];
				level >>= 3;
				level = (level-1)|1;

				if (getbits1_pos(dec,bitpos)) 
					level = -level;

				block[code] = (idct_block_t)level;
				++len;
			} 
			else 
			{
				if (level==63)
					break;

				// this value is escaped
				loadbits_pos(dec,bitpos);

				len += showbits_pos(dec,bitpos,6); flushbits_pos(dec,bitpos,6);
				if (len >= 64)
					break;

				code = showbits_pos(dec,bitpos,8); flushbits_pos(dec,bitpos,8);
				level = (code << 24) >> 24; //sign extend the lower 8 bits
				code = dec->zigzag[len];

				if (level == -128)
				{
					level = showbits_pos(dec,bitpos,8)-256; flushbits_pos(dec,bitpos,8);
				}
				else 
				if (level == 0)
				{
					level = showbits_pos(dec,bitpos,8); flushbits_pos(dec,bitpos,8);
				}

				if (level<0)
				{
					level= -level;
					level *= qscale * dec->IntraMatrix[len];
					level >>= 3;
					level= (level-1)|1;
					level= -level;

					block[code] = (idct_block_t)level;
					++len;
				}
				else
				{