2016-08-15:从YUV420P中提取指定大小区域
typedef struct
{
int width;
int height;
}SizeInfo; typedef struct
{
int x;
int y;
int width;
int height;
}ImageRect; /*************************************************
// Method : ExtraceSpecifiedSizeYuv
// Author : zhoulee
// Date : 2016/08/15 16:14
// Description: 从YUV420P中获取指定大小的YUV420P图像
// Returns : bool: true 获取成功; false 获取失败
// Parameter :
// image: 原始YUV420P数据指针
// imgSize: 原始图像尺寸, 图像宽高必须为偶数
// rect: 指定的区域信息, 区域左上角坐标以及宽高必须为偶数
// partionImg: 指定区域的YUV420P数据
*************************************************/
bool ExtraceSpecifiedSizeYuv(const unsigned char* image, const SizeInfo& imgSize,
const ImageRect& rect, unsigned char* partionImg); bool ExtraceSpecifiedSizeYuv(const unsigned char* image, const SizeInfo& imgSize,
const ImageRect& rect, unsigned char* partionImg)
{
if(imgSize.width%2 != 0 || imgSize.height%2 != 0
|| rect.x%2 != 0 || rect.y%2 != 0
|| rect.width%2 != 0 || rect.height%2 != 0
|| rect.x + rect.width > imgSize.width
|| rect.y + rect.height > imgSize.height)
{
return false;
} int yBegPos = 0;
int uBegPos = imgSize.width * imgSize.height;
int vBegPos = uBegPos + (imgSize.width * imgSize.height) / 4; int offset = 0;
//y component
for(int row = rect.y; row < rect.y + rect.height; ++row)
{
int yOffset = yBegPos + row * imgSize.width + rect.x;
memcpy(partionImg + offset, image + yOffset, rect.width);
offset += rect.width;
} //u component
for (int row = rect.y; row < rect.y + rect.height; row+=2)
{
//for (int col = rect.x; col < rect.x + rect.width; col+=2)
//{
// int uOffset = row * imgSize.width / 4 + col / 2;
// partionImg[offset] = image[uBegPos + uOffset];
// ++offset;
//}
int uOffset = uBegPos + row * imgSize.width / 4 + rect.x / 2;
memcpy(partionImg + offset, image + uOffset, rect.width / 2);
offset += rect.width / 2;
} //v component
for (int row = rect.y; row < rect.y + rect.height; row+=2)
{
//for (int col = rect.x; col < rect.x + rect.width; col+=2)
//{
// int vOffset = row * imgSize.width / 4 + col / 2;
// partionImg[offset] = image[vBegPos + vOffset];
// ++offset;
//}
int vOffset = vBegPos + row * imgSize.width / 4 + rect.x / 2;
memcpy(partionImg + offset, image + vOffset, rect.width / 2);
offset += rect.width / 2;
} return true;
}
2016-08-15:从YUV420P中提取指定大小区域的更多相关文章
- 2016.8.15上午纪中初中部NOIP普及组比赛
2016.8.15上午纪中初中部NOIP普及组比赛 链接:https://jzoj.net/junior/#contest/home/1333 这次比赛不怎么好,因为这套题目我并不是很擅长. 可同学们 ...
- Delphi中建立指定大小字体和读取该字体点阵信息的函数(转)
源:Delphi中建立指定大小字体和读取该字体点阵信息的函数 Delphi中建立指定大小字体和读取该字体点阵信息的函数 作者:Thermometer Email: webmaster@daheng- ...
- 截取UIImage指定大小区域
截取UIImage指定大小区域 最近遇到这样的需求:从服务器获取到一张照片,只需要显示他的左半部分,或者中间部分等等.也就是截取UIImage指定大小区域. UIImage扩展 我的解决方案是对UII ...
- C# 从字符串中提取指定字符类型的内容
从一段字符串中,提取中文.英文.数字 中文字符30Margin中文字符40HorizontalAlignment 正则表达式: /// <summary> /// 英文字母与数字 /// ...
- 答疑记录:jmeter从返回的html中提取指定内容
返回的html(截取部分),要求从中提取:2022-02-22 13:46:15 <!-- 前面省略557行 --> <td>2022-02-22</td> < ...
- python从字符串中提取指定的内容
有如下字符串: text=cssPath:"http://imgcache.qq.com/ptlogin/v4/style/32",sig:"OvL7F1OQEojtPk ...
- 从.o文件中提取指定开头依赖于外部接口的脚本
nm -g audio_la-audio.o | grep " U " | awk '{ print $2}' | grep "^gst_"
- linux脚本学习之路-在suse10环境中生存指定大小指定文件名的压缩文件
#!/bin/bash#-------------------------------------------------------------------------------# Name: ...
- python 提取字符串中的指定字符 正则表达式
例1: 字符串: '湖南省长沙市岳麓区麓山南路麓山门' 提取:湖南,长沙 在不用正则表达式的情况下: address = '湖南省长沙市岳麓区麓山南路麓山门' address1 = address.s ...
随机推荐
- CSS3-Media Query 基础
一.常见的属性: device-width , device-height 屏幕宽高 width , height 渲染窗口宽高 orientation 设备方向 resolution 设备分辨率 二 ...
- fopen和fopen_s用法的比较 【zz】
在定义FILE * fp 之后,fopen的用法是: fp = fopen(filename,"w").而对于fopen_s来说,还得定义另外一个变量errno_t err,然后e ...
- plist文件真机写入方法
http://blog.csdn.net/mydo/article/details/50290219 转 但是这对真机不管用,因为在真机环境下,App在Xcode中的Resources文件夹都是不可 ...
- 在 C++ 代码中使用 UE4 插件---Using a plugin in C++ code
例如使用 CustomMeshComponent 插件 在Build.cs 文件 中 添加以下两行代码 如图可配置路径,可解决#include "CustomMeshComponent&qu ...
- E1_1 用邻接矩阵存储有向图,并输出各顶点的出度和入度
参考书:图论算法理论.实现及应用(北京大学出版社) 输入数据:(test.txt) 程序: /* 邻接矩阵存储有向图 */ #include <cstring> #include < ...
- Startup key combinations for Intel-based Macs
Learn about the startup key combinations you can use with Intel-based Macs. You can use the followin ...
- PAT (Basic Level) Practise:1031. 查验身份证
[题目链接] 一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9, ...
- applicationContext.xml和web.xml的一些配置
applicationContext.xml <!-- test环境 --> <beans profile="test"> <context:prop ...
- codeforces194a
link:http://codeforces.com/contest/334/problem/A 很有意思的一道构造题.发现CF上经常出这种不难但是很不错的构造题. #include <iost ...
- javaScript DOM JQuery AJAX
http://www.cnblogs.com/wupeiqi/articles/5369773.html 一 JavaScript JavaScript是一门编程语言,浏览器内置了JavaScript ...