1、下采样(subsample or downsample)
图像下采样原理:原始图像的分辨率为WxH,对其进行n倍下采样得到(W/n)x(H/n)分辨率的图像,其中n应该是M和N的公约数才行。n倍下采样,即每n个像素抽取一个像素。
将YUV视频分为亮度分量(Y)和色度分量(U、V),对视频的每一帧都进行n采样,就可以实现对YUV视频的下采样。
void downsample(int x_sample, int y_sample, int width, int height, unsigned char* pY, unsigned char* pU, unsigned char* pV, unsigned char* pS_Y, unsigned char* pS_U, unsigned char* pS_V) {
//YUV分量的起始位置
unsigned char* src_img_py = pY;
unsigned char* src_img_pu = pU;
unsigned char* src_img_pv = pV;
//YUV分量的目标位置
unsigned char* dst_img_py = pS_Y;
unsigned char* dst_img_pu = pS_U;
unsigned char* dst_img_pv = pS_V;
unsigned char* start_src = src_img_py;
unsigned char* start_src_u = src_img_pu;
unsigned char* start_src_v = src_img_pv;
int cpy_x_end = width / x_sample;
int cpy_y_end = height / y_sample;
int cpy_x_end_c = (cpy_x_end >> 1);
int cpy_y_end_c = (cpy_y_end >> 1);
int i, j = 0;<