⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 block.c

📁 由bmp生成mpeg2 的I_frame 数据
💻 C
📖 第 1 页 / 共 2 页
字号:
int read_block_mpeg1_intra_cr(VIDEO_STREAM *in, short *out, READ_BLOCK_OPTION *opt)
{
	int i,n;

	int run;
	int level;

	short *qw;
	
	qw = opt->qw[0];
	
	/* initialize output block */
	memset(out, 0, sizeof(short)*64);

	opt->dc_dct_predictor[2] += get_dct_dc_diff_chrominance(in);
	out[0] = limit_dct_coefficient(opt->dc_dct_predictor[2] << 3);

	n = 1;
	while(read_dct_ac_coefficient_mpeg1(in, &run, &level) > 0){
		n += run;
		if(n >= 64){
			return 0;
		}
		i = scan_table[0][n];

		out[i] = limit_dct_coefficient( (((level * qw[i]) / 16)-1) | 1);
		n += 1;
	}

	return 1;
}

int read_block_mpeg1_nonintra(VIDEO_STREAM *in, short *out, READ_BLOCK_OPTION *opt)
{
	int i,n;

	int run;
	int level;

	short *qw;
	
	qw = opt->qw[1];
	
	/* initialize output block */
	memset(out, 0, sizeof(short)*64);

	/* read first coefficient */
	read_dct_dc_coefficient_mpeg1(in, &run, &level);
	n = run;
	i = scan_table[0][n];
	out[i] = limit_dct_coefficient( ((( ((level * 2) + ( (level > 0) ? 1 : -1)) * qw[i] ) / 32)-1)|1 );
	n += 1;

	while(read_dct_ac_coefficient_mpeg1(in, &run, &level) > 0){
		n += run;
		if(n >= 64){
			return 0;
		}
		i = scan_table[0][n];
		out[i] = limit_dct_coefficient( ((( ((level * 2) + ( (level > 0) ? 1 : -1)) * qw[i] ) / 32)-1)|1 );
		n += 1;
	}

	return 1;
}

int reset_dc_dct_predictor(READ_BLOCK_OPTION *p)
{
	int w;

	w = 1 << (7 + p->intra_dc_precision);
	p->dc_dct_predictor[0] = w;
	p->dc_dct_predictor[1] = w;
	p->dc_dct_predictor[2] = w;

	return 1;
}

static int get_dct_dc_size_luminance(VIDEO_STREAM *in)
{
	int code;

	static const BASIC_VLC_ELEMENT table[] = {
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 

		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 

		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 

		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}, 

		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},

		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},

		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},

		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},

		{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},
		{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},
		{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},
		{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},

		{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},
		{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},
		{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},
		{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},{0,3},

		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},

		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},

		{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},
		{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},
		{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},
		{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},

		{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},
		{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},
		{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},
		{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},

		{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},
		{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},
		{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},
		{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},

		{6,5},{6,5},{6,5},{6,5},{6,5},{6,5},{6,5},{6,5},
		{6,5},{6,5},{6,5},{6,5},{6,5},{6,5},{6,5},{6,5},
		{7,6},{7,6},{7,6},{7,6},{7,6},{7,6},{7,6},{7,6},
		{8,7},{8,7},{8,7},{8,7},{9,8},{9,8},{10,9},{11,9},
	};

	code = vs_read_bits(in, 9);

	vs_erase_bits(in, table[code].length);
	
	return table[code].value;
}

static int get_dct_dc_size_chrominance(VIDEO_STREAM *in)
{
	int code;

	static const BASIC_VLC_ELEMENT table[] = {
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},

		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},

		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},

		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},

		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},

		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},

		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},

		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
		{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},

		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
		
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},

		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},

		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},

		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},

		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},

		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},

		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},

		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
		{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},

		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},

		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},

		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},

		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
		{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},

		{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},
		{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},
		{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},
		{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},

		{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},
		{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},
		{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},
		{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},

		{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},
		{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},
		{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},
		{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},

		{6,6},{6,6},{6,6},{6,6},{6,6},{6,6},{6,6},{6,6},
		{6,6},{6,6},{6,6},{6,6},{6,6},{6,6},{6,6},{6,6},
		{7,7},{7,7},{7,7},{7,7},{7,7},{7,7},{7,7},{7,7},
		{8,8},{8,8},{8,8},{8,8},{9,9},{9,9},{10,10},{11,10},
	};

	code = vs_read_bits(in, 10);

	vs_erase_bits(in, table[code].length);

	return table[code].value;
}

void __stdcall setup_qw_nosimd(unsigned short *qw, unsigned short *qm, int q)
{
	int i;
	
	for(i=0;i<256;i++){
		qw[i] = qm[i] * q;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -