当前位置:网站首页>YUV数据的裁剪与重叠
YUV数据的裁剪与重叠
2022-06-11 07:45:00 【Hanyang Li】
1. YUV 数据的裁剪
/**
* 裁剪YUV数据 : 宽高左右起点均为偶数
* @param src_i420_data 源数据
* @param src_width 源宽
* @param src_height 源高
* @param dst_i420_data 裁剪的数据
* @param width 裁剪宽
* @param height 裁剪高
* @param left 开始左起点
* @param top 开始右起点
*/
void CropI420p(uint8_t *src_i420_data, int src_width, jint src_height, uint8_t *dst_i420_data,
int clip_width, int clip_height, int left, int top) {
uint8_t *src_yplane = src_i420_data;
uint8_t *src_uplane = src_i420_data + src_width * src_height;
uint8_t *src_vplane = src_uplane + (src_width * src_height / 4);
uint8_t *dst_yplane = dst_i420_data;
uint8_t *dst_uplane = dst_i420_data + clip_width * clip_height;
uint8_t *dst_vplane = dst_uplane + (clip_width * clip_height / 4);
//uv 参数
int uv_total_width = src_width / 2;
int y_clip_width = sizeof(uint8_t) * clip_width;
int uv_clip_width = sizeof(uint8_t) * clip_width / 2;
//uv 参数
int total_clip_width = sizeof(uint8_t) * clip_width / 2;
for (int i = 0; i < clip_height; i++) {
int y_h = top + i;
int src_pos = left + src_width * y_h;
memcpy(dst_yplane + (i * clip_width), src_yplane + src_pos, y_clip_width); //Y
if (i < clip_height / 2) {
//获取 UV分量
int uv_h = top / 2 + i;
int src_pos_u = left / 2 + uv_total_width * uv_h;
int src_pos_v = left / 2 + uv_total_width * uv_h;
int des_pos = total_clip_width * i;
memcpy(dst_uplane + des_pos, src_uplane + src_pos_u, uv_clip_width);//U
memcpy(dst_vplane + des_pos, src_vplane + src_pos_v, uv_clip_width);//V
}
}
}2. YUV 数据的重叠
/**
* 重叠YUV数据 : 宽高左右起点均为偶数
* @param src_i420_data 重叠部分数据
* @param src_width 重叠宽
* @param src_height 重叠高
* @param dst_i420_data 源数据
* @param width 源宽
* @param height 源高
* @param left 源开始左起点
* @param top 源开始上起点
*/
void I420CopyI420(uint8_t *src_i420_data, int src_width, jint src_height, uint8_t *dst_i420_data,
int width, int height, int left, int top) {
uint8_t *src_yplane = src_i420_data;
uint8_t *src_uplane = src_i420_data + src_width * src_height;
uint8_t *src_vplane = src_uplane + (src_width * src_height / 4);
uint8_t *dst_yplane = dst_i420_data;
uint8_t *dst_uplane = dst_i420_data + width * height;
uint8_t *dst_vplane = dst_uplane + (width * height / 4);
//uv 参数
int total_clip_width = src_width / 2;
int uv_total_width = width / 2;
int y_src_width = sizeof(uint8_t) * src_width;
int uv_src_width = sizeof(uint8_t) * src_width / 2;
for (int i = 0; i < src_height; i++) {
int y_h = top + i;
int src_pos = left + width * y_h;
memcpy(dst_yplane + src_pos, src_yplane + (i * src_width), y_src_width); //Y
if (i < src_height / 2) {
//获取 UV分量
int uv_h = top / 2 + i;
int src_pos_u = left / 2 + uv_total_width * uv_h;
int src_pos_v = left / 2 + uv_total_width * uv_h;
int des_pos = total_clip_width * i;
memcpy(dst_uplane + src_pos_u, src_uplane + des_pos, uv_src_width);//U
memcpy(dst_vplane + src_pos_v, src_vplane + des_pos, uv_src_width);//V
}
}
}3.参考裁剪数据
//裁剪 YUV 420p 数据
void DemoCropI420p(uint8_t *src_i420_data, int dec_width, jint dec_height, uint8_t *dst_i420_data,
int clip_width, int clip_height, int x_start, int y_start) {
//y 参数
int total_clip_w = clip_width;
int total_width = dec_width;
int src_size = dec_width * dec_height;
//uv 参数
int total_clip_width = clip_width / 2;
int uv_total_width = dec_width / 2;
for (int x = 0; x < clip_height; x++) {
int y_h = y_start + x;
int src_pos = x_start + total_width * y_h;
memcpy(dst_i420_data + (total_clip_w * x), src_i420_data + src_pos,
sizeof(char) * total_clip_w); //Y
if (x < clip_height / 2) {
//获取 UV分量
int uv_h = y_start / 2 + x;
int src_pos_u = src_size + x_start / 2 + uv_total_width * uv_h;
int src_pos_v = src_size + src_size / 4 + x_start / 2 + uv_total_width * uv_h;
int des_pos = total_clip_width * x;
memcpy(dst_i420_data + des_pos, src_i420_data + src_pos_u,
sizeof(char) * total_clip_width);//U
memcpy(dst_i420_data + des_pos, src_i420_data + src_pos_v,
sizeof(char) * total_clip_width);//V
}
}
}边栏推荐
- C+tinycthread implementation thread
- 测试4年裸辞失业,面试15k的测试岗被按在地上摩擦,结局让我崩溃大哭...
- 2022.6.7 特长生模拟
- 2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]
- pmp到底是什么?
- multi-sig SC
- C language judging big end and small end [consortium or pointer] big end and small end conversion
- [codeforces1019e] raining season
- Zero foundation self-study SQL course | outer join external connection
- 20200730 T3 small B farm [maximum perimeter empty rectangle (monotone stack + line segment tree)] & "ROI 2017 day 2" learning track
猜你喜欢
![[atcoder1980] mystious light (mathematical simulation)](/img/c0/7de31b36e11ff71328d927c1d1c2d3.png)
[atcoder1980] mystious light (mathematical simulation)

A detailed explanation of one of the causes of dead loop caused by array out of bounds in C language

Zero foundation self-study SQL course | outer join external connection
![2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]](/img/4d/a67a63d2c4eb80c98315c3057b01b9.jpg)
2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]

二本毕业,银行外包测试工作 4 个月有余。聊聊一些真实感受 ...

【IoT】项目管理:如何打造更好的跨职能团队?

Qunhui ds918 creates m.2 SSD read / write cache

如何准备PMP新版大纲考试?

C wechat upload form data
![Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]](/img/f0/9d4609a53f398636b8062c625f7d3c.jpg)
Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]
随机推荐
[IOT] intelligent hardware: how to obtain the WiFi signal strength of hardware products
Qstring to hexadecimal qstring
A detailed explanation of one of the causes of dead loop caused by array out of bounds in C language
Database connection pool and bdutils tool
[codeforces1019e] raining season
134. 加油站
Remote office experience | community essay solicitation
wordcloud的使用
VIM common commands
.NET C#基础(6):命名空间 - 有名字的作用域
MFC custom string linked list
【CodeForces908H】New Year and Boolean Bridges (FWT)
2021-10-24
群晖DS918创建m.2 固态硬盘SSD读写缓存
Implementation of queue (C language)
二本毕业,银行外包测试工作 4 个月有余。聊聊一些真实感受 ...
【IoT】智能硬件:如何获取硬件产品的wifi信号强度
远程办公经验分享 | 社区征文
排序——选择排序
[atcoder2307] tree game