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中提取指定大小区域的更多相关文章

  1. 2016.8.15上午纪中初中部NOIP普及组比赛

    2016.8.15上午纪中初中部NOIP普及组比赛 链接:https://jzoj.net/junior/#contest/home/1333 这次比赛不怎么好,因为这套题目我并不是很擅长. 可同学们 ...

  2. Delphi中建立指定大小字体和读取该字体点阵信息的函数(转)

    源:Delphi中建立指定大小字体和读取该字体点阵信息的函数 Delphi中建立指定大小字体和读取该字体点阵信息的函数 作者:Thermometer Email:  webmaster@daheng- ...

  3. 截取UIImage指定大小区域

    截取UIImage指定大小区域 最近遇到这样的需求:从服务器获取到一张照片,只需要显示他的左半部分,或者中间部分等等.也就是截取UIImage指定大小区域. UIImage扩展 我的解决方案是对UII ...

  4. C# 从字符串中提取指定字符类型的内容

    从一段字符串中,提取中文.英文.数字 中文字符30Margin中文字符40HorizontalAlignment 正则表达式: /// <summary> /// 英文字母与数字 /// ...

  5. 答疑记录:jmeter从返回的html中提取指定内容

    返回的html(截取部分),要求从中提取:2022-02-22 13:46:15 <!-- 前面省略557行 --> <td>2022-02-22</td> < ...

  6. python从字符串中提取指定的内容

    有如下字符串: text=cssPath:"http://imgcache.qq.com/ptlogin/v4/style/32",sig:"OvL7F1OQEojtPk ...

  7. 从.o文件中提取指定开头依赖于外部接口的脚本

    nm -g audio_la-audio.o | grep " U " | awk '{ print $2}' | grep "^gst_"

  8. linux脚本学习之路-在suse10环境中生存指定大小指定文件名的压缩文件

    #!/bin/bash#-------------------------------------------------------------------------------# Name:   ...

  9. python 提取字符串中的指定字符 正则表达式

    例1: 字符串: '湖南省长沙市岳麓区麓山南路麓山门' 提取:湖南,长沙 在不用正则表达式的情况下: address = '湖南省长沙市岳麓区麓山南路麓山门' address1 = address.s ...

随机推荐

  1. 持续集成-sourcetree的安装、使用记录

    1.参考 http://blog.sina.com.cn/s/blog_672143a30102vold.html 2.问题-安装sourcetree后,打开时提示下载但是连接不上相应链接 自行下载g ...

  2. Hibernate原生SQL查询多表关联,SQL语句要注意的问题

    Hibernate原生SQL查询多表关联,SQL语句要注意的问题 @for&ever 2009-9-4 系统环境: MySQL5.1 Hibernate3.3 有如下的假定: 实体类 Ques ...

  3. C#—WebService

    一.qq是否在线 1.添加Web引用    qqOnlineWebService cn.com.webxml.www.qqOnlineWebService shelly1 = new NIIT1109 ...

  4. php get_magic_quotes_gpc()函数用法介绍

    magic_quotes_gpc函数在php中的作用是判断解析用户提交的数据,如包括有:post.get.cookie过来的数据增加转义字符“\”,以确保这些数据不会引起程序,特别是数据库语句因为特殊 ...

  5. Call to undefined function curl_init()

    运行PHP不支持curl_init()的解决方法: 1.修改php.ini,将;extension=php_curl.dll前面的分号去掉(同时检查扩展的引用路径是否正确)2.拷贝libeay32.d ...

  6. 查看oracle当前session

      怎样查看oracle当前的连接数呢?只需要用下面的SQL语句查询一下就可以了. #查看当前不为空的连接select * from v$session where username is not n ...

  7. Linux线程-pthread_kill

    该函数可以用于向指定的线程发送信号: int pthread_kill(pthread_t threadId,int signal); 如果线程内不对信号进行处理,则调用默认的处理程式,如SIGQUI ...

  8. /proc/uptime详解

    From:http://smilejay.com/2012/05/proc_uptime/ 在Linux中,我们常常会使用到uptime命令去看看系统的运行时间,它与一个文件有关,就是/proc/up ...

  9. Java-->Tomcat(免费的Java Web服务器)

    --> 要在浏览器访问一个Java Web项目,首先需要将这个项目放到服务器中. --> Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器. --> ...

  10. LintCode Validate Binary Search Tree

    Validate Binary Search Tree Given a binary tree, determine if it is a valid binary search tree (BST) ...