1. 程式人生 > >YUV420、YUV422、RGB24轉換

YUV420、YUV422、RGB24轉換

//平面YUV422轉平面RGB24
static void YUV422p_to_RGB24(unsigned char *yuv422[3], unsigned char *rgb24, int width, int height)
{
int R,G,B,Y,U,V;
int x,y;
int nWidth = width>>1; //色度訊號寬度
for (y=0;y<height;y++)
{
for (x=0;x<width;x++)
{
Y = *(yuv422[0] + y*width + x);
U = *(yuv422[1] + y*nWidth + (x>>1));
V = *(yuv422[2] + y*nWidth + (x>>1));
R = Y + 1.402*(V-128);
G = Y - 0.34414*(U-128) - 0.71414*(V-128);
B = Y + 1.772*(U-128);

//防止越界
if (R>255)R=255;
if (R<0)R=0;
if (G>255)G=255;
if (G<0)G=0;
if (B>255)B=255;
if (B<0)B=0;

*(rgb24 + ((height-y-1)*width + x)*3) = B;
*(rgb24 + ((height-y-1)*width + x)*3 + 1) = G;
*(rgb24 + ((height-y-1)*width + x)*3 + 2) = R; 
}
}
}

//平面YUV420轉平面YUV422
static void YUV420p_to_YUV422p(unsigned char *yuv420[3], unsigned char *yuv422, int width, int height)
{
int x, y;
//亮度訊號Y複製
int Ylen = width*height;
memcpy(yuv422, yuv420[0], Ylen);
//色度訊號U複製
unsigned char *pU422 = yuv422 + Ylen; //指向U的位置
int Uwidth = width>>1; //422色度訊號U寬度
int Uheight = height>>1; //422色度訊號U高度 
for (y = 0; y < Uheight; y++) 

memcpy(pU422 + y*width, yuv420[1] + y*Uwidth, Uwidth);
memcpy(pU422 + y*width + Uwidth, yuv420[1] + y*Uwidth, Uwidth);
}
//色度訊號V複製
unsigned char *pV422 = yuv422 + Ylen + (Ylen>>1); //指向V的位置
int Vwidth = Uwidth; //422色度訊號V寬度
int Vheight = Uheight; //422色度訊號U寬度
for (y = 0; y < Vheight; y++) 

memcpy(pV422 + y*width, yuv420[2] + y*Vwidth, Vwidth);
memcpy(pV422 + y*width + Vwidth, yuv420[2] + y*Vwidth, Vwidth);

}

//平面YUV420轉RGB24
static void YUV420p_to_RGB24(unsigned char *yuv420[3], unsigned char *rgb24, int width, int height)
{
// int begin = GetTickCount();
int R,G,B,Y,U,V;
int x,y;
int nWidth = width>>1; //色度訊號寬度
for (y=0;y<height;y++)
{
for (x=0;x<width;x++)
{
Y = *(yuv420[0] + y*width + x);
U = *(yuv420[1] + ((y>>1)*nWidth) + (x>>1));
V = *(yuv420[2] + ((y>>1)*nWidth) + (x>>1));
R = Y + 1.402*(V-128);
G = Y - 0.34414*(U-128) - 0.71414*(V-128);
B = Y + 1.772*(U-128);

//防止越界
if (R>255)R=255;
if (R<0)R=0;
if (G>255)G=255;
if (G<0)G=0;
if (B>255)B=255;
if (B<0)B=0;

*(rgb24 + ((height-y-1)*width + x)*3) = B;
*(rgb24 + ((height-y-1)*width + x)*3 + 1) = G;
*(rgb24 + ((height-y-1)*width + x)*3 + 2) = R;
// *(rgb24 + (y*width + x)*3) = B;
// *(rgb24 + (y*width + x)*3 + 1) = G;
// *(rgb24 + (y*width + x)*3 + 2) = R; 
}
}
}

相關推薦

YUV420YUV422RGB24轉換

//平面YUV422轉平面RGB24static void YUV422p_to_RGB24(unsigned char *yuv422[3], unsigned char *rgb24, int width, int height){int R,G,B,Y,U,V;int x,y;int nWidth

javacpp-FFmpeg系列之2:通用拉流解碼器,支持視頻拉流解碼並轉換為YUVBGR24或RGB24等圖像像素數據

tope sca 封裝 ams 定義 throw tco 如何使用 都是 javacpp-ffmpeg系列: javacpp-FFmpeg系列之1:視頻拉流解碼成YUVJ420P,並保存為jpg圖片 javacpp-FFmpeg系列之2:通用拉流解碼器,支持視頻拉流解碼並

H264編碼器1(MATLAB讀取一張RGB圖片轉成YUV420格式YUV422格式YUV444格式)

來自:https://blog.csdn.net/sinat_39372048/article/details/82287155    1.讀入照片 控制輸出的標誌定義 1 2 3 4 5 6 7 8 9 10 11 clc

自動類型轉換強制類型轉換作用域整型表數範圍

基本類 logs 自動類型轉換 四種 main print 輸出字符串 縮小 stat 一、變量的作用域 測試代碼: public class Test1 { private static int value = 1; // 全局變量 pri

Android pxdpsp之間相互轉換

系統 als 屏幕大小 span ava 不同 text 自動 nal dp(dip): device independent pixels(設備獨立像素). 不同設備有不同的顯示效果,這個和設備硬件有關,一般我們為了支持WVGA、HVGA和QVGA 推薦使用這個,不依

C# Stream 與 byte[]文件的轉換

stream/* - - - - - - - - - - - - - - - - - - - - - - - - * Stream 和 byte[] 之間的轉換 * - - - - - - - - - - - - - - - - - - - - - - - */ /// <summary> ///

office文檔圖片音/視頻格式轉換工具

ria 變量 ora lis window emoji 格式轉換 ffi stand 1、音頻/視屏轉換工具VLC https://wiki.videolan.org/Mp3/#Container_formats http://wenku.baidu.com/vie

cocos2d JS 函數類型相互轉換(字符串整形浮點形布爾值)

賦值 defined 基數 bject 布爾 ring 浮點型 謝謝 val 工作忙好些天了,近段時間抽點空分享一下自己學習JS的一點筆記心得做點記錄,大神勿噴,謝謝! p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0

字典列表字符串轉換關系

單引號 mage http python import nbsp 遍歷 .cn 輸出 python 列表轉為字典的兩個小方法 1、現在有兩個列表,list1 = [‘key1‘,‘key2‘,‘key3‘]和list2 = [‘1‘,‘2‘,‘3‘], 把他們轉為這樣的字典

Python字符串元組列表字典互相轉換的方法

tuple -c 字符 列表 () lis pri int values #-*-coding:utf-8-*- #1、字典dict = {‘name‘: ‘Zara‘, ‘age‘: 7, ‘class‘: ‘First‘}#字典轉為字符串,返回:<type ‘st

centos下 將(jgppng)圖片轉換成webp格式

sys 安裝 學習 isa 幫助 webp格式 system pos ini 由於項目要求需要將jpg、png類型的圖片 轉換成webp格式,最開始使用了php gd類庫裏 imagewebp 方法實現,結果發現轉換成的webp格式文件會偶爾出現空白內容的情況。像

LintCode算法題解——奇偶分割數組二進制中1個數反轉整數加一排序數組轉換為高度最小的二叉搜索樹二進制求和

code style 求和 二進制 題解 二叉 following 算法題 targe Y3訟韭62獻si鏈倥8臣khttp://www.facebolw.com/space/2103837/following 7v6d04Vhpf玖忠http://www.facebol

go語言stringintint64互相轉換

cpp -m pbo boa strong http views tools mod [cpp] view plain copy #string到int int,err:=strconv.Atoi(string) #string到int64 int6

原碼反碼補碼移碼之間的關系和轉換

span 數值 一個 寄存器 如果 有符號數 pan 關系 style 在計算機中參與運算的數有兩大類:無符號數和有符號數。無符號數,即沒有符號的數,在寄存器中的每一位均可用來存放數值;而有符號數,則需要留出位置來存放符號。以機器字長為8位為例,無符號數表示的範圍是0~25

ComboBox在WPF中的綁定示例:綁定項集合轉換,及其源代碼

ati .com med owa panel center generic tle summary 在WPF的Xaml中為ComboBox綁定數據時,由於參數很多,很容易混淆,在ListView中使用更是如此。本文通過對ComboBox在窗口和在ListView中綁定對象的

面向對象第一次練手-------ArrayList集合對象冒泡排序類型轉換

arraylist for 一句話 class new each 註釋 program bsp 思維轉不過彎兒來 怎麽做都是錯 哪怕差一個()就成功的事情,也是千差萬別 忽然想到一句話:差一步就成功的距離 = 差幾萬米就成功的距離 部分的理解和都體現在代

java 中 byte[]FileInputStream 互相轉換

output 轉換 ava available byte數組 leo ear inpu red 1、將File、FileInputStream 轉換為byte數組: File file = new File("test.txt"); InputStream input =

Python 字符串操作(string替換刪除截取復制連接比較查找包含大小寫轉換分割等)

brk 分割 掃描 char 去空格 之前 特殊符號 strip () 去空格及特殊符號 s.strip().lstrip().rstrip(‘,‘) 復制字符串 #strcpy(sStr1,sStr2) sStr1 = ‘strcpy‘ sStr2 = sStr1

將實體類匿名對象轉換為SqlParameter列表

ins 名稱 rem return parameter 實體 mark continue rar /// <summary> /// <remarks> /// <para>將實體類/匿名對象轉換為SqlParameter列表</

Spark算子:RDD基本轉換操作(1)–mapflatMapdistinct

ive 註意 pre spl cti result log bsp blog Spark算子:RDD基本轉換操作(1)–map、flatMap、distinct 關鍵字:Spark算子、Spark RDD基本轉換、map、flatMap、distinct map 將