资源简介
RGBA8888转换为YUV NV21格式的几种算法
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include “rgb2yuv420sp.h“
static void rgb2yuv420p_float(char* pYUV char* pRGB int w int h)
{
int frameSize = w * h;
int yIndex = 0;
int uvIndex = frameSize;
int R G B Y U V;
int index = 0;
int ij;
struct RGBQUAD* rbgBuf = (struct RGBQUAD*)pRGB;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
//alpha is not used
R = rbgBuf[index].rgbRed;
G = rbgBuf[index].rgbGreen;
B = rbgBuf[index].rgbBlue;
// printf(“R:%d G:%d B:%d\n “ RGB);
// well known RGB to YUV algorithm
Y = 0.299 * R + 0.587 * G + 0.114 * B;
U = -0.147 * R - 0.289 * G + 0.436 * B;
V = 0.615 * R - 0.515 * G - 0.100 * B;
pYUV[yIndex++] = (char) ((Y < 0) ? 0 : ((Y > 255) ? 255 : Y));
if (j % 2 == 0 && index % 2 == 0) {
pYUV[uvIndex++] = (char)((V<0) ? 0 : ((V > 255) ? 255 : V));
pYUV[uvIndex++] = (char)((U<0) ? 0 : ((U > 255) ? 255 : U));
}
index ++;
}
}
}
static void rgb2yuv420p_int(unsigned char* pYUV char* pRGB int w int h)
{
int frameSize = w * h;
int yIndex = 0;
int uvIndex = frameSize;
int R G B Y U V;
int index = 0;
int ij;
struct RGBQUAD* rbgBuf = (struct RGBQUAD*)pRGB;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
//alpha is not used
R = rbgBuf[index].rgbRed;
G = rbgBuf[index].rgbGreen;
B = rbgBuf[index].rgbBlue;;
//printf(“R:%d G:%d B:%d\n “ RGB);
Y = (1224 * R + 2404 * G + 467 *B) >> 12;
U = (-602 * R - 1184 * G + 1786 * B) >> 12;
V = (2519 * R - 2109 * G - 410 * B ) >> 12;
pYUV[yIndex++] = (unsigned char) ((Y < 0) ? 0 : ((Y > 255) ? 255 : Y));
if (j % 2 == 0 && index % 2 == 0) {
pYUV[uvIndex++] = (unsigned char)((V<0) ? 0 : ((V > 255) ? 255 : V));
pYUV[uvIndex++] = (unsigned char)((U<0) ? 0 : ((U > 255) ? 255 : U));
}
index ++;
}
}
}
static int tlb_RY[256];
static int tlb_GY[256];
static int tlb_BY[256];
static int tlb_RU[256];
static int tlb_GU[256];
static int tlb_BU[256];
static int tlb_RV[256];
static int tlb_GV[256];
static int tlb_BV[256];
static void init_lookup_tables()
{
int i;
for (i = 0; i < 256 ; i++) {
tlb_RY[i] = (i * 1224) >> 12;
tlb_GY[i] = (i * 2404) >> 12;
tlb_BY[i] = (i * 467) >> 12;
tlb_RU[i] = (i * 602)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 290454 2013-10-22 15:41 32.bmp
文件 108900 2013-10-22 15:56 32.yuv
文件 2706 2013-10-22 19:00 rgb2yuv.zip
文件 8126 2013-10-22 16:01 rgb2yuv420sp.c
文件 1433 2013-10-22 15:30 rgb2yuv420sp.h
文件 319488 2013-10-22 13:14 YUVViewer.exe
评论
共有 条评论