ARGB32 to YUV12 利用 SDL1.2 SDL_ttf 在视频表面输出文本
提示:ARGB alpha通道的A + 原YUV表面的y0 + 要写进去的y1 = 计算出新的y2.
计算公式为 ( y1 * a + y0 * ( 255 - a ) ) / 255
void rgb2yuv(int r, int g, int b, int *y, int *u, int *v)
{
int y0, u0, v0; y0 = 66*r + 129*g + 25*b;
u0 = -38*r + -74*g + 112*b;
v0 = 112*r + -94*g + -18*b; y0 = (y0+128)>>8;
u0 = (u0+128)>>8;
v0 = (v0+128)>>8; *y = y0 + 16;
*u = u0 + 128;
*v = v0 + 128;
} void yuv2rgb(int y, int u, int v, int *r, int *g, int *b)
{
int r0,g0,b0;
v = v - 128;
u = u - 128;
r0 = y + v + (v>>2) + (v>>3) + (v>>5);
g0 = y - ((u>>2) + (u>>4) + (u>>5)) - ((v>>1) + (v>>3) + (v>>4) + (v>>5));
b0 = y + u + (u>>1) + (u>>2) + (u>>6); *r = r0 > 255 ? 255: r0;
*g = g0 > 255 ? 255: g0;
*b = b0 > 255 ? 255: b0;
} int blitSurface2YUV(SDL_Surface *src, SDL_Overlay *dst, SDL_Rect *dstrect ,int isBlended)
{
Uint8 r, g, b,a;
int y0,u0,v0;
int y1,u1,v1;
int y2,u2,v2;
int y,x;
int height = src->h h ? src->h: dstrect->h;
int width = src->w w ? src->w: dstrect->w;
int uv_off = 0;
Uint32 pixel; printf ("src->format->BitsPerPixel %d src->format %08X\r\n",src->format->BitsPerPixel,src->format); if(dst->format != SDL_YV12_OVERLAY)return 1; for(y = 0; y format->BitsPerPixel)
{
case 8:
pixel = *((Uint8*)src->pixels + y*src->pitch + x);
break;
case 16:
pixel = *((Uint16*)src->pixels + y*src->pitch/2 + x);
break;
case 32:
pixel = *((Uint32*)src->pixels + y*src->pitch/4 + x); break;
default:
return -1;
} //SDL_GetRGB(pixel, src->format, &r, &g, &b);
SDL_GetRGBA(pixel, src->format, &r, &g, &b,&a); rgb2yuv(r, g, b, &y1, &u1, &v1); if(isBlended)
{
y0 = (dst->pixels[0][ (dstrect->y + y) * dst->pitches[0] + (dstrect->x + x)]);
v0 = (dst->pixels[1][ (uv_off + dstrect->y /2) * dst->pitches[1] + (dstrect->x/2 + x/2)]);
u0 = (dst->pixels[2][ (uv_off + dstrect->y /2) * dst->pitches[2] + (dstrect->x/2 + x/2)]); y2 = (Uint8)(( y1 * a + y0 * ( 255 - a ) ) / 255);
u2 = (Uint8)(( u1 * a + u0 * ( 255 - a ) ) / 255);
v2 = (Uint8)(( v1 * a + v0 * ( 255 - a ) ) / 255); y1=y2;
u1=u2;
v1=v2;
} memset(dst->pixels[0] + (dstrect->y + y) * dst->pitches[0] + (dstrect->x + x),
(Uint8)y1 , 1); if((x%2 == 0 ) && (y%2 == 0 ))
{
memset(dst->pixels[1] + (uv_off + dstrect->y /2) * dst->pitches[1] + (dstrect->x/2 + x/2),
(Uint8)v1, 1);
memset(dst->pixels[2] + (uv_off + dstrect->y /2) * dst->pitches[2] + (dstrect->x/2 + x/2),
(Uint8)u1, 1);
}
}
if(y%2 == 0)++uv_off;
}
return 0;
}
ARGB32 to YUV12 利用 SDL1.2 SDL_ttf 在视频表面输出文本的更多相关文章
- 【Linux】利用Xvfb关闭chrome的图形化输出
利用Xvfb关闭chrome的图形化输出 #!/bin/bash . /home/fzuir/.profile # JAVA export JAVA_HOME=/usr/local/jdk1.7.0_ ...
- Java 利用缓冲字节流来实现视频、音频、图片的复制粘贴
InputStream:继承自InputStream的流都是用于向程序中输入数据的,且数据单位都是字节(8位). OutputSteam:继承自OutputStream的流都是程序用于向外输出数据的, ...
- 利用FFmpeg玩转Android视频录制与压缩(二)<转>
转载出处:http://blog.csdn.net/mabeijianxi/article/details/72983362 预热 时光荏苒,光阴如梭,离上一次吹牛逼已经过去了两三个月,身边很多人的女 ...
- 利用java从docx文档中提取文本内容
利用java从docx文档中提取文本内容 使用Apache的第三方jar包,地址为https://poi.apache.org/ docx文档内容如图: 目录结构: 每个文件夹的名称为日期加上来源,例 ...
- 利用开源jPlayer播放.flv视频文件
最近工作中用到视频播放,在网上搜索对比了好几款开源播放插件后,觉得 jPlayer 是比较不错的,故作此记录! 接下来先快速的展示一下 利用jPlayer播放.flv视频的效果: <!DOCTY ...
- java利用过滤器实现编码的转换,内容输出的替换
在页面建个表单 <form action="login.do" method="post"> <input type="text&q ...
- Unity3D基础学习 利用NGUI的Texture播放视频
利用NGUI播放视频,首先你得导入你的视频 你的电脑中必须安装QuickTime软件,没有,去下一个,如果是Windows系统,安装完之后重启. 接下来转换你的视频格式,如果你的视频在QuickTim ...
- 利用jieba,word2vec,LR进行搜狐新闻文本分类
一.简介 1)jieba 中文叫做结巴,是一款中文分词工具,https://github.com/fxsjy/jieba 2)word2vec 单词向量化工具,https://radimrehurek ...
- 利用循环播放dataurl的视频来防止锁屏:NoSleep.js
mark下. 地址:http://www.open-open.com/lib/view/open1430796889882.html
随机推荐
- 【CodeForces 489A】SwapSort
题 Description In this problem your goal is to sort an array consisting of n integers in at most n sw ...
- Excel 计算 tips
1. 对一列数据想看看,distinct的结果 选中数据区域(包含列名),插入pivot table 2. 想检查一个单元格的值在不在某一列中,并返回标志值 =IF (COUNTIF(B:B,A1) ...
- POJ 3278 The merchant
传送门 Time Limit: 3000MS Memory Limit: 65536K Description There are N cities in a country, and there i ...
- TEXT宏,TCHAR类型
TCHAR *ptch = TEXT("This is a const string."); 如果使用UNICODE字符集, 则TEXT("This is a const ...
- Hibernate之多对多
一.项目结构如下图 二.保存学生和课程及其学生选课关系代码如下(测试类中不能再有双向关联,否则会报错,因为,都维护了中间表外键,会有中间表外键冲突,如果非要写双向关联,就需要配置中设置某一方维护主键, ...
- Practical Machine Learning For The Uninitiated
Practical Machine Learning For The Uninitiated Last fall when I took on ShippingEasy's machine learn ...
- 自定义cell的步骤(每个cell的高度不一样,每个cell里面显示的内容也不一样)
1.新建一个继承自UITableViewCell的子类 2. 在initWithStyle:方法中进行子控件的初始化 1> 将有可能显示的所有子控件都添加到contentView中 2> ...
- Shell脚本获得变量值作为新变量一部分的值
最近使用shell写一个发布脚本时,由于shell编程是边学便用的缘故,经验不足,中间遇到一个问题,一个变量的值作为一个新变量的一部分,而我要根据变量获得新变量的值,以前没有遇到过.网络搜索一番,最后 ...
- Linux系统管理远程登录工具PUTTY
PuTTY 简介 PuTTY是一个Telnet.SSH.rlogin.纯TCP以及串行接口连线软件.较早的版本仅支持Windows平台,在最近的版本中开始支持各类Unix平台,并打算移植 ...
- oracle 编译中一个关于clntsh 库的一个 帖子 ,收藏!
oracle 编译中一个关于clntsh 库的一个 帖子 ,收藏! ------------------------------------------------------------------ ...