当前位置:网站首页>Clipping and overlapping of YUV data
Clipping and overlapping of YUV data
2022-06-11 07:49:00 【Hanyang Li】
1. YUV Data clipping
/**
* tailoring YUV data : Both the left and right starting points of width and height are even numbers
* @param src_i420_data Source data
* @param src_width Source width
* @param src_height Source height
* @param dst_i420_data Cropped data
* @param width Cutting width
* @param height Crop height
* @param left Start left starting point
* @param top Start right starting point
*/
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 Parameters
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 Parameters
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) {
// obtain UV component
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 Data overlap
/**
* overlap YUV data : Both the left and right starting points of width and height are even numbers
* @param src_i420_data Overlapping data
* @param src_width Overlap width
* @param src_height Overlap height
* @param dst_i420_data Source data
* @param width Source width
* @param height Source height
* @param left Source start left start
* @param top The source starts at the starting point
*/
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 Parameters
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) {
// obtain UV component
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. Reference crop data
// tailoring YUV 420p data
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 Parameters
int total_clip_w = clip_width;
int total_width = dec_width;
int src_size = dec_width * dec_height;
//uv Parameters
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) {
// obtain UV component
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 language - growth diary-04- preliminary exploration of local variables (local variables)
- 【CodeForces908H】New Year and Boolean Bridges (FWT)
- Image data enhancement (translation, rotation, brightness transformation, flipping, adding Gaussian noise, scaling, cropping)
- Deux diplômés, la Banque a externalisé le travail d'essai pendant plus de quatre mois. Parler de vrais sentiments...
- 【IoT】智能硬件:如何获取硬件产品的wifi信号强度
- C language - Growth Diary -02- function
- [software testing] 90% of the interviewers have been brushed out of such resumes
- Bidirectional linked list simple template (pointer version)
- Tidb cloud launched Google cloud marketplace, empowering global developers with a new stack of real-time HTAP databases
- 零基础自学SQL课程 | OUTER JOIN外连接
猜你喜欢

TiDB Cloud 上線 Google Cloud Marketplace,以全新一棧式實時 HTAP 數據庫賦能全球開發者

Zero foundation self-study SQL course | outer join external connection

放大镜子效果图

C# 微信上传Form-data

Tidb Cloud est en ligne sur le marché Google Cloud pour permettre aux développeurs du monde entier d'utiliser une nouvelle pile de bases de données htap en temps réel

【IoT】智能硬件:如何获取硬件产品的wifi信号强度

2021-11-05 definition of cache

图数据库无缝集成Tushare接口

After 4 years of naked resignation from the test, the test post of 15K interview was rubbed on the ground, and the result made me collapse and cry

【AtCoder1980】Mysterious Light(数学模拟)
随机推荐
Matrix tree theorem
【IoT】项目管理:如何打造更好的跨职能团队?
C language three chess games
模线性方程组(中国剩余定理+通用解法)
Remote office experience sharing | community essay solicitation
[untitled] Weng_ C lesson 1
C language lesson 2
群晖DS918创建m.2 固态硬盘SSD读写缓存
QT custom control library creation
【AtCoder1998】Stamp Rally(整体二分+并查集)
20200730 T3 small B farm [maximum perimeter empty rectangle (monotone stack + line segment tree)] & "ROI 2017 day 2" learning track
黑群晖DSM7.0.1物理机安装教程
Flask页面的分页
【CodeForces908H】New Year and Boolean Bridges (FWT)
[noip2016 d1t3] changing classrooms (expectation dp+floyd) (trap of extreme thinking!)
Classes and objects (medium)
【IoT】智能硬件:如何获取硬件产品的wifi信号强度
String Simulation Implementation
2. Graduated from this course, and the bank has outsourced testing work for more than 4 months. Talk about some real feelings
The solution of "no startup device" after running Bochs