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

📄 mc.c

📁 由bmp生成mpeg2 的I_frame 数据
💻 C
📖 第 1 页 / 共 3 页
字号:
			w = in[x] + in[x+1] + in[x+in_step] + in[x+in_step+1] + 2;
			w >>= 2;
			w += out[x] + 1;
			out[x] = (w >> 1);
		}
		in += in_step;
		out += out_step;
	}
}

static void prediction_w16_fh_1st(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int w;
	int x, y;

	for(y=0;y<height;y++){
		for(x=0;x<16;x++){
			w = in[x] + in[x+in_step] + 1;
			out[x] = (w >> 1);
		}
		in += in_step;
		out += out_step;
	}
}
	
static void prediction_w16_fh_2nd(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int w;
	int x, y;

	for(y=0;y<height;y++){
		for(x=0;x<16;x++){
			w = in[x] + in[x+in_step] + 1;
			w >>= 1;
			w += out[x] + 1;
			out[x] = (w >> 1);
		}
		in += in_step;
		out += out_step;
	}
}

static void prediction_w16_hf_1st(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int w;
	int x, y;

	for(y=0;y<height;y++){
		for(x=0;x<16;x++){
			w = in[x] + in[x+1] + 1;
			out[x] = (w >> 1);
		}
		in += in_step;
		out += out_step;
	}
}

static void prediction_w16_hf_2nd(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int w;
	int x, y;

	for(y=0;y<height;y++){
		for(x=0;x<16;x++){
			w = in[x] + in[x+1] + 1;
			w >>= 1;
			w += out[x] + 1;
			out[x] = (w >> 1);
		}
		in += in_step;
		out += out_step;
	}
}

static void prediction_w16_ff_1st(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int y;

	for(y=0;y<height;y++){
		memcpy(out, in, 16);
		in += in_step;
		out += out_step;
	}
}

static void prediction_w16_ff_2nd(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int w;
	int x, y;

	for(y=0;y<height;y++){
		for(x=0;x<16;x++){
			w = in[x] + out[x] + 1;
			out[x] = w >> 1;
		}
		in += in_step;
		out += out_step;
	}
}

static void prediction_w8_hh_1st(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int w;
	int x, y;

	for(y=0;y<height;y++){
		for(x=0;x<8;x++){
			w = in[x] + in[x+1] + in[x+in_step] + in[x+in_step+1] + 2;
			out[x] = (w >> 2);
		}
		in += in_step;
		out += out_step;
	}
}

static void prediction_w8_hh_2nd(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int w;
	int x, y;

	for(y=0;y<height;y++){
		for(x=0;x<8;x++){
			w = in[x] + in[x+1] + in[x+in_step] + in[x+in_step+1] + 2;
			w >>= 2;
			w += out[x] + 1;
			out[x] = (w >> 1);
		}
		in += in_step;
		out += out_step;
	}
}

static void prediction_w8_fh_1st(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int w;
	int x, y;

	for(y=0;y<height;y++){
		for(x=0;x<8;x++){
			w = in[x] + in[x+in_step] + 1;
			out[x] = (w >> 1);
		}
		in += in_step;
		out += out_step;
	}
}
	
static void prediction_w8_fh_2nd(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int w;
	int x, y;

	for(y=0;y<height;y++){
		for(x=0;x<8;x++){
			w = in[x] + in[x+in_step] + 1;
			w >>= 1;
			w += out[x] + 1;
			out[x] = (w >> 1);
		}
		in += in_step;
		out += out_step;
	}
}

static void prediction_w8_hf_1st(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int w;
	int x, y;

	for(y=0;y<height;y++){
		for(x=0;x<8;x++){
			w = in[x] + in[x+1] + 1;
			out[x] = (w >> 1);
		}
		in += in_step;
		out += out_step;
	}
}

static void prediction_w8_hf_2nd(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int w;
	int x, y;

	for(y=0;y<height;y++){
		for(x=0;x<8;x++){
			w = in[x] + in[x+1] + 1;
			w >>= 1;
			w += out[x] + 1;
			out[x] = (w >> 1);
		}
		in += in_step;
		out += out_step;
	}
}

static void prediction_w8_ff_1st(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int y;

	for(y=0;y<height;y++){
		memcpy(out, in, 8);
		in += in_step;
		out += out_step;
	}
}

static void prediction_w8_ff_2nd(unsigned char *in, unsigned char *out, int in_step, int out_step, int height)
{
	int w;
	int x, y;

	for(y=0;y<height;y++){
		for(x=0;x<8;x++){
			w = in[x] + out[x] + 1;
			out[x] = w >> 1;
		}
		in += in_step;
		out += out_step;
	}
}

typedef void (* STD_MC_CORE)(unsigned char *, unsigned char *, int, int, int); 

void prediction(FRAME *in, FRAME *out, int type, int xv, int yv, int x, int y, int first, int chroma_format)
{
	int r_offset, p_offset;
	int r_step, p_step;
	int width, height;
	int xh, yh;
	int xiv, yiv;
	unsigned char *r, *p;

	static STD_MC_CORE table[2][2][2][2] = {
		{/* width - 8 */
			{ /* horizontal full */
				{ /* vertical full */
					prediction_w8_ff_2nd,
					prediction_w8_ff_1st,
				},
				{ /* vertical half */
					prediction_w8_fh_2nd,
					prediction_w8_fh_1st,
				},
			},
			{ /* horizontal half */
				{ /* vertical full */
					prediction_w8_hf_2nd,
					prediction_w8_hf_1st,
				},
				{ /* vertical half */
					prediction_w8_hh_2nd,
					prediction_w8_hh_1st,
				},
			},
		},
		{/* width - 16 */
			{ /* horizontal full */
				{ /* vertical full */
					prediction_w16_ff_2nd,
					prediction_w16_ff_1st,
				},
				{ /* vertical half */
					prediction_w16_fh_2nd,
					prediction_w16_fh_1st,
				},
			},
			{ /* horizontal half */
				{ /* vertical full */
					prediction_w16_hf_2nd,
					prediction_w16_hf_1st,
				},
				{ /* vertical half */
					prediction_w16_hh_2nd,
					prediction_w16_hh_1st,
				},
			},
		},
	};

	switch(type){
	case PREDICTION_FRAME_TO_FRAME:
		r_offset = in->width * y + x;
		p_offset = in->width * y + x;
		r_step = in->width;
		p_step = in->width;
		width = 16;
		height = 16;
		break;
	case PREDICTION_FRAME_TO_TOP:
		r_offset = in->width * y + x;
		p_offset = in->width * y + x;
		r_step = in->width;
		p_step = in->width * 2;
		width = 16;
		height = 8;
		break;
	case PREDICTION_FRAME_TO_BOTOM:
		r_offset = in->width * (y+1) + x;
		p_offset = in->width * (y+1) + x;
		r_step = in->width;
		p_step = in->width * 2;
		width = 16;
		height = 8;
		break;
	case PREDICTION_TOP_TO_TOP:
		r_offset = in->width * y + x;
		p_offset = in->width * y + x;
		r_step = in->width * 2;
		p_step = in->width * 2;
		width = 16;
		height = 8;
		break;
	case PREDICTION_TOP_TO_BOTOM:
		r_offset = in->width * y + x;
		p_offset = in->width * (y+1) + x;
		r_step = in->width * 2;
		p_step = in->width * 2;
		width = 16;
		height = 8;
		break;
	case PREDICTION_BOTOM_TO_TOP:
		r_offset = in->width * (y+1) + x;
		p_offset = in->width * y + x;
		r_step = in->width * 2;
		p_step = in->width * 2;
		width = 16;
		height = 8;
		break;
	case PREDICTION_BOTOM_TO_BOTOM:
		r_offset = in->width * (y+1) + x;
		p_offset = in->width * (y+1) + x;
		r_step = in->width * 2;
		p_step = in->width * 2;
		width = 16;
		height = 8;
		break;
	default:
		return;
	}

	r = in->y + r_offset;
	p = out->y + p_offset;

	xh = xv & 1;
	yh = yv & 1;
	xiv = xv >> 1;
	yiv = yv >> 1;

	r += yiv * r_step + xiv;

	table[width>>4][xh][yh][first](r, p, r_step, p_step, height);

	if(chroma_format != 3){
		width >>= 1;
		xv /= 2;
		x /= 2;
		r_offset -= x;
		p_offset -= x;
	}
	if(chroma_format == 1){
		height >>= 1;
		yv /= 2;
		y /= 2;
		r_offset -= in->width * y;
		p_offset -= in->width * y;
	}

	r = in->u + r_offset;
	p = out->u + p_offset;

	xh = xv & 1;
	yh = yv & 1;
	xiv = xv >> 1;
	yiv = yv >> 1;

	r += yiv * r_step + xiv;

	table[width>>4][xh][yh][first](r, p, r_step, p_step, height);

	r = in->v + r_offset;
	p = out->v + p_offset;

	r += yiv * r_step + xiv;

	table[width>>4][xh][yh][first](r, p, r_step, p_step, height);
}

⌨️ 快捷键说明

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