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     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM