YUV格式图像补黑边
原理:https://blog.csdn.net/andrew57/article/details/79644442
1、直接使用libyuv库 libyuv::I420Scale
注意:要提前给原始YUV图像分配补边后内存,否则可能崩溃
2、自己实现,原始YUV保持原本的大小就可以
代码:
1 int offset_in = 0; 2 int offset_out = 0; 3 for (int i = 0; i < inHeight; ++i) 4 { 5 // Y 6 memcpy(YUV_out + offset_out, YUV_in + offset_in, inWidth); 7 offset_out += outWidth; 8 offset_in += inWidth; 9 } 10 offset_out += (outHeight - inHeight) * outWidth; 11 for (int i = 0; i < inHeight / 2; ++i) 12 { 13 // U 14 memcpy(YUV_out + offset_out, YUV_in + offset_in, inWidth / 2); 15 offset_out += outWidth / 2; 16 offset_in += inWidth / 2; 17 } 18 offset_out += (outHeight - inHeight) * outWidth / 4; 19 for (int i = 0; i < inHeight / 2; ++i) 20 { 21 // V 22 memcpy(YUV_out + offset_out, YUV_in + offset_in, inWidth / 2); 23 offset_out += outWidth / 2; 24 offset_in += inWidth / 2; 25 }