当前位置: 首页 > wzjs >正文

珠海正规网站制作哪家强中国建材网站

珠海正规网站制作哪家强,中国建材网站,找家里做的工作到什么网站,网站的积分系统怎么做overlayYUV 以下是一个支持将小尺寸YUV420文件覆盖到更大尺寸YUV420文件指定位置的C完整实现&#xff0c;支持坐标设置和边界处理&#xff1a; 示例代码 #include <iostream> #include <fstream> #include <vector> #include <algorithm>struct YUVC…

overlayYUV

以下是一个支持将小尺寸YUV420文件覆盖到更大尺寸YUV420文件指定位置的C++完整实现,支持坐标设置和边界处理:

示例代码

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>struct YUVConfig {int width;      // 大文件宽度int height;     // 大文件高度int small_width;int small_height;int pos_x;      // 覆盖起始X坐标int pos_y;      // 覆盖起始Y坐标std::string format = "I420"; // 支持I420/NV12格式
};bool overlayYUV(const std::string& dst_file, const std::string& src_file,const YUVConfig& config) 
{// 计算各分量尺寸const int y_size = config.width  * config.height; const int uv_size = y_size / 4;const int total_size = y_size + 2 * uv_size;// 读取大文件std::ifstream fin_dst(dst_file, std::ios::binary);if (!fin_dst) return false;std::vector<uint8_t> dst_data(total_size);fin_dst.read(reinterpret_cast<char*>(dst_data.data()),  total_size);// 读取小文件std::ifstream fin_src(src_file, std::ios::binary);if (!fin_src) return false;std::vector<uint8_t> src_data(y_size + 2*(config.small_width*config.small_height)/4); fin_src.read(reinterpret_cast<char*>(src_data.data()),  src_data.size()); // Y分量覆盖处理const int copy_width = std::min(config.small_width,  config.width  - config.pos_x); const int copy_height = std::min(config.small_height,  config.height  - config.pos_y); // 处理Y平面for (int row = 0; row < copy_height; ++row) {auto* dst_start = dst_data.data()  + (config.pos_y  + row) * config.width  + config.pos_x; auto* src_start = src_data.data()  + row * config.small_width; std::copy_n(src_start, copy_width, dst_start);}// UV分量处理(I420格式)if (config.format  == "I420") {// U分量偏移计算const int uv_offset = y_size;const int uv_pos_x = config.pos_x  / 2;const int uv_pos_y = config.pos_y  / 2;const int uv_src_width = config.small_width  / 2;const int uv_src_height = config.small_height  / 2;// 处理U平面for (int row = 0; row < uv_src_height; ++row) {auto* dst_u = dst_data.data()  + uv_offset + (uv_pos_y + row) * (config.width/2)  + uv_pos_x;auto* src_u = src_data.data()  + y_size + row * uv_src_width;std::copy_n(src_u, uv_src_width, dst_u);}// 处理V平面const int v_offset = y_size + uv_size;for (int row = 0; row < uv_src_height; ++row) {auto* dst_v = dst_data.data()  + v_offset + (uv_pos_y + row) * (config.width/2)  + uv_pos_x;auto* src_v = src_data.data()  + y_size + uv_src_width*uv_src_height + row * uv_src_width;std::copy_n(src_v, uv_src_width, dst_v);}}// NV12格式处理(UV交织)else if (config.format  == "NV12") {const int uv_offset = y_size;const int uv_pos_x = config.pos_x  / 2;const int uv_pos_y = config.pos_y  / 2;const int uv_stride = config.width; for (int row = 0; row < config.small_height/2;  ++row) {auto* dst_uv = dst_data.data()  + uv_offset + (uv_pos_y + row) * uv_stride + uv_pos_x*2;auto* src_uv = src_data.data()  + y_size + row * config.small_width; std::copy_n(src_uv, config.small_width,  dst_uv);}}// 写入结果文件std::ofstream fout("output.yuv",  std::ios::binary);fout.write(reinterpret_cast<char*>(dst_data.data()),  dst_data.size()); return true;
}int main() {YUVConfig config;config.width  = 1920;config.height  = 1080;config.small_width  = 640;config.small_height  = 480;config.pos_x  = 100;config.pos_y  = 200;config.format  = "I420"; // 或"NV12"if (overlayYUV("big.yuv",  "small.yuv",  config)) {std::cout << "Overlay completed. Saved to output.yuv"  << std::endl;} else {std::cerr << "Error processing files" << std::endl;}return 0;
}

关键特性说明 :

  • 格式兼容性:支持YUV420的I420和NV12格式,通过format参数切换:

    • I420:Y平面 + U平面 + V平面
    • NV12:Y平面 + 交织的UV平面

坐标系统:

pos_x, pos_y  // 覆盖起始坐标(以Y分量坐标系为基准)
uv_pos_x = pos_x / 2  // UV分量坐标自动折半计算

边界处理:

copy_width = min(小图宽度, 大图宽度 - x坐标)  // 自动裁剪越界部分

内存优化:使用std::vector<uint8_t>存储数据,避免动态内存分配问题

使用建议:

参数设置需满足:

small_width <= (width - pos_x) * 2    // 色度分量对齐要求

验证输出文件:

ffplay -video_size 1920x1080 -pixel_format nv12 output.yuv 

性能优化方向:

  • 使用内存映射文件处理大尺寸文件
  • 多线程处理Y/UV分量
  • SIMD指令优化数据拷贝

完整实现考虑了YUV420格式的色度采样特性,通过坐标折半计算实现准确的色度分量定位,同时包含了对不同存储格式的适配逻辑。边界处理机制确保覆盖操作不会导致内存越界。

完整代码

Github

作者郑天佐
邮箱zhengtianzuo06@163.com
主页http://www.zhengtianzuo.com
githubhttps://github.com/zhengtianzuo

文章转载自:

http://DV8OoKQJ.gjtdp.cn
http://g3Xo0MhN.gjtdp.cn
http://qzlLwsgo.gjtdp.cn
http://AymLgQh0.gjtdp.cn
http://nJ6rgAlx.gjtdp.cn
http://mAmUH3Ka.gjtdp.cn
http://OBCtNPW9.gjtdp.cn
http://bJcQBpLu.gjtdp.cn
http://VmX1ykuX.gjtdp.cn
http://vcic9HJi.gjtdp.cn
http://n1cziHH1.gjtdp.cn
http://hCAKBs7N.gjtdp.cn
http://QfpO4Iyo.gjtdp.cn
http://nIKzjMk4.gjtdp.cn
http://jhICNarY.gjtdp.cn
http://zF3r1qfD.gjtdp.cn
http://qqU8m7tN.gjtdp.cn
http://gq3ArTf2.gjtdp.cn
http://xDo7suE1.gjtdp.cn
http://fdIFLiDX.gjtdp.cn
http://JdaUlRHw.gjtdp.cn
http://Yd6m3g5O.gjtdp.cn
http://j35l2VCN.gjtdp.cn
http://pNKWTddm.gjtdp.cn
http://AicHeK0C.gjtdp.cn
http://5AkjUpvF.gjtdp.cn
http://WXJVjOQe.gjtdp.cn
http://1VZeRavV.gjtdp.cn
http://BwKpm7Yr.gjtdp.cn
http://sSyqRMM6.gjtdp.cn
http://www.dtcms.com/wzjs/621778.html

相关文章:

  • 福利站wordpress温岭营销型网站建设
  • 网站欢迎页面在线设计小兔自助建站系统
  • 王悦做网站番禺俊才网官网
  • 建公司网站步骤如何制作电脑公司网站
  • 广州建设网站企业asp.net 网站安全 检测
  • 做网站需要多少钱一个月wordpress手机拍照插件
  • 电商网站服务器中国网站建设新闻
  • 关注江苏建设厅网站世界500强企业的核心价值观
  • 模板网站怎么做301扬州工程建设信息 网站
  • 网站网址黄页大全免费网站维护主要做什么
  • 上海微信网站建设费用海口建设工程信息网站
  • 建材公司网站建设案例重庆免费微网站
  • 网站开发软硬件中国建设银行的网站设计
  • 微信公众号模板素材网站最便宜云服务器
  • html网站地图怎么做大连网站
  • 网站中 点击出现登录框怎么做wordpress手机显示图片
  • 网站内容建设的原则是什么制定一网站建设的市场定位的方案
  • 企业网站开发框架个人适合网站类型
  • 夸克建站系统源码下载企业取名
  • 建设进出口外贸网站做电商在什么网站吗
  • 珠宝类网站建设可执行报告定制开发app到底要多少钱
  • oa系统网站建设方案wordpress汉字验证码
  • 重庆产品推广类网站域名备案 网站名称
  • 做前端常用的网站及软件下载太仓网站建设哪家好
  • 事业单位网站建设的作用专做西餐的网站
  • 百度收录哪些网站吗网站建设电话销售技巧和话术
  • 企业门户网站 源码清镇网站建设
  • 建设公司网站费用多少短网址生成管理平台
  • 网站推广策略开封网站建设兼职
  • 广东深广东深圳网站建设服务ui设计零基础到精通自学