【转】YUV420SP的格式以及转换为RGB565的代码(Android摄像头的输出一般为YUV420P) .
来源:互联网 发布:软件项目工时估算 编辑:程序博客网 时间:2024/04/28 08:18
static void cvt_420p_to_rgb565(int width,int height,constunsignedchar*src,unsignedshort*dst)
{
int line, col, linewidth;
int y, u, v, yy, vr, ug, vg, ub;
int r, g, b;
const unsigned char *py,*pu,*pv;
linewidth = width >> 1;
py = src;
pu = py + (width * height);
pv = pu + (width * height)/ 4;
y = *py++;
yy = y << 8;
u = *pu - 128;
ug = 88 * u;
ub = 454 * u;
v = *pv - 128;
vg = 183 * v;
vr = 359 * v;
for (line = 0;line< height;line++){
for (col = 0; col < width; col++){
r = (yy + vr) >> 8;
g = (yy - ug - vg)>> 8;
b = (yy + ub ) >> 8;
if (r < 0) r = 0;
if (r > 255) r = 255;
if (g < 0) g = 0;
if (g > 255) g = 255;
if (b < 0) b = 0;
if (b > 255) b = 255;
*dst++ = (((unsignedshort)r>>3)<<11)|(((unsignedshort)g>>2)<<5)|(((unsignedshort)b>>3)<<0);
y = *py++;
yy = y << 8;
if (col & 1) {
pu++;
pv++;
u = *pu - 128;
ug = 88 * u;
ub = 454 * u;
v = *pv - 128;
vg = 183 * v;
vr = 359 * v;
}
}
if ((line & 1)== 0){
pu -= linewidth;
pv -= linewidth;
}
}
}
http://www.elautoctrl.info/wordpress/archives/921
http://blog.csdn.net/dotphoenix/article/details/6431351
extra:
Android手机你应该用little endian:
pSwsContext = sws_getContext(nWidth, nHeight, PIX_FMT_YUV420P, nWidth, nHeight
, PIX_FMT_RGB565LE, SWS_BICUBIC, NULL, NULL, NULL);
刚好手头有一个例子,就顺便给你一个例子吧:
SwsContext *img_convert_ctx = sws_getContext(codecContext->width, codecContext->height,
PIX_FMT_YUV420P,
mReqWidth,mReqHeight,
PIX_FMT_RGB565LE,
SWS_BICUBIC, NULL, NULL, NULL);
LOGD("sws_getContext return =%d",img_convert_ctx);
if(img_convert_ctx){
AVFrame *picture;
avcodec_get_frame_defaults(picture);
picture->data[0] = (uint8_t*)mRGB565Data;
picture->data[1] = 0;
picture->data[2] = 0;
picture->linesize[0] = mReqWidth;
picture->linesize[1] = 0;
picture->linesize[2] = 0;
sws_scale(img_convert_ctx, frame.data, frame.linesize,
0, codecContext->height, picture->data,
picture->linesize);
result = 0;
}
- 【转】YUV420SP的格式以及转换为RGB565的代码(Android摄像头的输出一般为YUV420P) .
- YUV420P的格式以及转换为RGB565的代码(Android摄像头的输出一般为YUV420P)
- YUV420P的格式以及转换为RGB565的代码(Android摄像头的输出一般为YUV420P)
- YUV420P的格式以及转换为RGB565的代码(Android摄像头的输出一般为YUV420P)
- Android 把YUV420P格式的数据转换为RGB565格式
- YUV420sp转换为YUV420p
- YUV420P转换为RGB32格式
- YUV420P转换为RGB32格式
- linux 下将rgb24转化为rgb565的格式
- 搞摄像头的驱动 YCbCr如何转换为RGB格式
- yuv422 转换 为yuv420sp
- 一段ffmpeg视频解码为YUV420P的示例代码
- 24位深的bmp图片转换为16位深RGB565格式的bmp图片源码
- 关于Opencv图像的转换(YUV420sp)
- S3C6410 FramBuffer编程(四) --- RGB565、RGB24简介,以及RGB565转换为RGB24
- S3C6410 FramBuffer编程(四) --- RGB565、RGB24简介,以及RGB565转换为RGB24
- 利用ov511的webeye v2000摄像头实现YUV420P格式转RGB24格式来抓取一张图片
- 利用ov511的webeye v2000摄像头实现YUV420P格式转RGB24格式来抓取一张图片
- 中秋送好礼:天嵌阿里巴巴全场买满1500元返50元
- 谈谈GetSafeHwnd()和GetSafeHandle()的主要区别
- 【学习OpenCV】OpenCV的GPU模块(CUDA)的配置和例程(含OpenCV 3.0的说明)
- 中国安卓智能手机公司小米收集用户数据
- 沃课堂,中国领先的移动教育网络平台
- 【转】YUV420SP的格式以及转换为RGB565的代码(Android摄像头的输出一般为YUV420P) .
- RedHat Linux下安装Oracle_11G_图文全过程介绍
- Win7下使用capDriverConnect()连接失败的解决办法
- iostat -t 200并发 tomcat 16核 压测
- linux下的定时或计时操作(gettimeofday等的用法,秒,微妙,纳秒)
- Eclipse常用的插件在线安装地址或下载地址
- C语言堆栈入门——堆和栈的区别
- SQL Server 中关于EXCEPT和INTERSECT的用法以及 OPENQUERY连接Oracel比较
- Java虚拟机工作原理详解