[英]How to convert 8 bits Grayscale image to NV12 (limited range) color space using IPP
[英]How to convert RGB to NV12 color space using IPP
我發現IPP功能存在:
很難找到,因為功能名稱或描述沒有提到NV12。
該功能使用BT.601標准。
以下是在BT.601標准中將RGB轉換為NV12的代碼示例:
void Rgb2NV12(const unsigned char I[], int image_width, int image_height, unsigned char J[])
{
IppStatus ipp_status;
int srcStep = image_width*3;
int dstYStep = image_width;
int dstCbCrStep = image_width;
IppiSize roiSize = {image_width, image_height};
const Ipp8u* pSrc = (Ipp8u*)I;
Ipp8u *pDstY = (Ipp8u*)J; //Y color plane is the first image_width*image_height pixels of J.
Ipp8u *pDstCbCr = (Ipp8u*)&J[image_width*image_height]; //In NV12 format, UV plane starts below Y.
ipp_status = ippiRGBToYCbCr420_8u_C3P2R(pSrc, srcStep, pDstY, dstYStep, pDstCbCr, dstCbCrStep, roiSize);
//if (ipp_status != ippStsNoErr), Handle errors...
}
使用BT.709標准將RGB轉換為NV12:
至於2019年,BT.709(HDTV)標准可能比BT.601(SDTV)更具相關性。
IPP缺乏在BT.709標准中從RGB直接轉換為NV12的功能。
有一個功能可以將BGR轉換為NV12 。
該解決方案包括兩個階段:
ippiSwapChannels_8u_C3R
進行RGB到BGR轉換。 ippiBGRToYCbCr420_709CSC_8u_C3P2R
進行BGR到NV12的轉換。 樣本函數需要一些額外的存儲空間來存儲中間BGR圖像。
指向草圖存儲器的指針被傳遞給函數(存儲器應該在函數外部分配)。
以下是在BT.709標准中將RGB轉換為NV12的代碼示例:
//sketch_buff - Temporary buffer for storing image in BGR format.
// Size of sketch_buff must be at least image_width*image_height*3 bytes.
void Rgb2NV12_709(const unsigned char I[],
const int image_width,
const int image_height,
unsigned char sketch_buff[],
unsigned char J[])
{
IppStatus ipp_status;
int srcStep = image_width*3;
int dstBgrStep = image_width*3;
int dstYStep = image_width;
int dstCbCrStep = image_width;
IppiSize roiSize = {image_width, image_height};
const Ipp8u* pRGB = (Ipp8u*)I;
Ipp8u* pBGR = (Ipp8u*)sketch_buff; //BGR image is stored in sketch_buff
Ipp8u *pDstY = (Ipp8u*)J; //Y color plane is the first image_width*image_height pixels of J.
Ipp8u *pDstCbCr = (Ipp8u*)&J[image_width*image_height]; //In NV12 format, UV plane starts below Y.
const int bgrOrder[3] = {2, 1, 0};
//Swap Red and Blue color channels - convert from RGB to BGR
//Store the result into sketch_buff (sketch buffer is allocated outside the function)
ipp_status = ippiSwapChannels_8u_C3R(pRGB, srcStep, pBGR, dstBgrStep, roiSize, bgrOrder);
//if (ipp_status != ippStsNoErr), Handle errors...
//Convert BGR to NV12 in BT.709 standard
ipp_status = ippiBGRToYCbCr420_709CSC_8u_C3P2R(pBGR, srcStep, pDstY, dstYStep, pDstCbCr, dstCbCrStep, roiSize);
//if (ipp_status != ippStsNoErr), Handle errors...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.