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 ...
随机推荐
- Android 计算器UI-TableLayout
表格布局(TableLayout) <?xml version="1.0" encoding="utf-8"?> <TableLayout x ...
- Day3 summary
今天主要学习了K-means算法,又过了遍Andrew教授的coursera视频,弄明白了Action书上的算法.困难出现在实例练习,申请Yahoo place finder API获得了appid, ...
- Jquery和Javascript 实际项目中写法基础 (1)
一.JS 是什么,jquery 是什么 就不说明了,直接说一般使用是怎么样的 <!DOCTYPE html> <html> <head> <meta cha ...
- Java数据结构和算法之递归
四.递归 递归是函数调用自身的一种特殊的编程技术,其应用主要在以下几个方面: 阶乘 在java当中的基本形式是: Public void mothed(int n){//当满足某条件时: Mo ...
- 最短路径问题——dijkstra算法
仅谈谈个人对dijkstra的理解,dijkstra算法是基于邻接表实现的,用于处理单源最短路径问题(顺便再提一下,处理单源最短路径问题的还有bellman算法).开辟一个结构体,其变量为边的终点和边 ...
- github 如何合并不同分支
From: http://stackoverflow.com/questions/1123344/merging-between-forks-in-github 1. 添加remote origina ...
- Streaming replication slots in PostgreSQL 9.4
Streaming replication slots are a pending feature in PostgreSQL 9.4, as part of the logical changese ...
- Maven学习5-聚合与继承
一.聚合 如果我们想一次构建多个项目模块,那我们就需要对多个项目模块进行聚合 1.1.聚合配置代码 1 <modules> 2 <module>模块一</module&g ...
- Linux下安装php加速器xcache
一.环境说明 php安装目录:/usr/local/php php.ini配置文件路径:/usr/local/php/etc/php.ini Nginx安装目录:/usr/local/nginx Ng ...
- mongoose学习文档
名词解释 Schema : 一种以文件形式存储的数据库模型骨架,不具备数据库的操作能力 Model : 由Schema发布生成的模型,具有抽象属性和行为的数据库操作对 来自cnode社区 1.创建一个 ...