提示: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 在视频表面输出文本的更多相关文章

  1. 【Linux】利用Xvfb关闭chrome的图形化输出

    利用Xvfb关闭chrome的图形化输出 #!/bin/bash . /home/fzuir/.profile # JAVA export JAVA_HOME=/usr/local/jdk1.7.0_ ...

  2. Java 利用缓冲字节流来实现视频、音频、图片的复制粘贴

    InputStream:继承自InputStream的流都是用于向程序中输入数据的,且数据单位都是字节(8位). OutputSteam:继承自OutputStream的流都是程序用于向外输出数据的, ...

  3. 利用FFmpeg玩转Android视频录制与压缩(二)<转>

    转载出处:http://blog.csdn.net/mabeijianxi/article/details/72983362 预热 时光荏苒,光阴如梭,离上一次吹牛逼已经过去了两三个月,身边很多人的女 ...

  4. 利用java从docx文档中提取文本内容

    利用java从docx文档中提取文本内容 使用Apache的第三方jar包,地址为https://poi.apache.org/ docx文档内容如图: 目录结构: 每个文件夹的名称为日期加上来源,例 ...

  5. 利用开源jPlayer播放.flv视频文件

    最近工作中用到视频播放,在网上搜索对比了好几款开源播放插件后,觉得 jPlayer 是比较不错的,故作此记录! 接下来先快速的展示一下 利用jPlayer播放.flv视频的效果: <!DOCTY ...

  6. java利用过滤器实现编码的转换,内容输出的替换

    在页面建个表单 <form action="login.do" method="post"> <input type="text&q ...

  7. Unity3D基础学习 利用NGUI的Texture播放视频

    利用NGUI播放视频,首先你得导入你的视频 你的电脑中必须安装QuickTime软件,没有,去下一个,如果是Windows系统,安装完之后重启. 接下来转换你的视频格式,如果你的视频在QuickTim ...

  8. 利用jieba,word2vec,LR进行搜狐新闻文本分类

    一.简介 1)jieba 中文叫做结巴,是一款中文分词工具,https://github.com/fxsjy/jieba 2)word2vec 单词向量化工具,https://radimrehurek ...

  9. 利用循环播放dataurl的视频来防止锁屏:NoSleep.js

    mark下. 地址:http://www.open-open.com/lib/view/open1430796889882.html

随机推荐

  1. 解决Oracle忘记密码问题

    在使用ORACLE的过程中,会出现各种各样的问题,各种各样的错误,其中ORA-12899就是前段时间我在将数据导入到我本地机器上的时候一直出现的问题.不过还好已经解决了这个问题,现在分享一下,解决方案 ...

  2. BZOJ-3282 Tree Link-Cut-Tree(似乎树链剖分亦可)

    蛋蛋用链剖A的,我写的LCT 3282: Tree Time Limit: 30 Sec Memory Limit: 512 MB Submit: 1241 Solved: 542 [Submit][ ...

  3. BZOJ-2326 数学作业 矩阵乘法快速幂+快速乘

    2326: [HNOI2011]数学作业 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1564 Solved: 910 [Submit][Statu ...

  4. 学习笔记 BIT(树状数组)

    痛定思痛,打算切割数据结构,于是乎直接一发BIT 树状数组能做的题目,线段树都可以解决 反之则不能,不过树状数组优势在于编码简单和速度更快 首先了解下树状数组: 树状数组是一种操作和修改时间复杂度都是 ...

  5. Python input()和raw_input()的区别

    当输入为数字的时候,input()获得的是数字,而后者获得的是str,可以用int(raw_input())来转换. i = input() print i+1 j = raw_input() pri ...

  6. windows ubuntu双系统启动

    开始安装系统 1.安装系统 首先安装windows8和ubuntu12.04,安装先后顺序可以不用管,只是安装到ubuntu的分区时需要注意device for boot loader install ...

  7. Selenium2+python自动化13-Alert

    不是所有的弹出框都叫alert,在使用alert方法前,先要识别出它到底是不是alert.先认清楚alert长什么样子,下次碰到了,就可以用对应方法解决.alert\confirm\prompt弹出框 ...

  8. 中国天气网-天气预报接口api

    中国天气网地址:http://www.weather.com.cn 请求服务 : 查询实时天气信息 http://www.weather.com.cn/data/sk/101110101.html 在 ...

  9. Linux 安装Rsync和配置

    1.检查rsync 是否已经安装 [root@test home]# rpm -qa|grep rsync 若已经安装,则使用rpm -e 命令卸载. [root@test home]#rpm -e ...

  10. dedecms升级后报错

    DedeCMS Error: (PHP 5.3 and above) Please set 'request_order' ini value to include C,G and P (recomm ...