开发者

Show RGB888 content

开发者 https://www.devze.com 2022-12-22 22:17 出处:网络
I have to show RGB888 content using the ShowRGBContent function. The below function is a ShowRGBContent function for yv12->rgb565 & UYVY->RGB565

I have to show RGB888 content using the ShowRGBContent function.

The below function is a ShowRGBContent function for yv12->rgb565 & UYVY->RGB565

static void ShowRGBContent(UINT8 * pImageBuf, INT32 width, INT32 height) 
{
LogEntry(L"%d : In %s Function \r\n",++abhineet,__WFUNCTION__);
UINT16 * temp;
BYTE rValue, gValue, bValue;

// this is to refresh the background desktop
ShowWindow(GetDesktopWindow(),SW_HIDE);
ShowWindow(GetDesktopWindow(),SW_SHOW); 

for(int i=0; i<height; i++)
{
 for (int j=0; j< width; j++)        
 {
  temp = (UINT16 *) (pImageBuf+ i*width*PP_TEST_FR开发者_如何学GoAME_BPP+j*PP_TEST_FRAME_BPP);
  bValue = (BYTE) ((*temp & RGB_COMPONET0_MASK) >> RGB_COMPONET0_OFFSET) << (8 -RGB_COMPONET0_WIDTH);
  gValue = (BYTE) ((*temp & RGB_COMPONET1_MASK) >> RGB_COMPONET1_OFFSET) << (8 -RGB_COMPONET1_WIDTH);
  rValue = (BYTE) ((*temp & RGB_COMPONET2_MASK) >> RGB_COMPONET2_OFFSET) << (8 -RGB_COMPONET2_WIDTH);            
  SetPixel(g_hDisplay, SCREEN_OFFSET_X + j, SCREEN_OFFSET_Y+i, RGB(rValue, gValue, bValue));
 }
}

Sleep(2000); //sleep here to review the result

LogEntry(L"%d :Out %s Function \r\n",++abhineet,__WFUNCTION__);
}

I have to modify this for RGB888

Here in the above function:

************************
RGB_COMPONET0_WIDTH = 5
RGB_COMPONET1_WIDTH = 6
RGB_COMPONET2_WIDTH = 5
************************

************************
RGB_COMPONET0_MASK = 0x001F //31 in decimal
RGB_COMPONET1_MASK = 0x07E0 //2016 in decimal
RGB_COMPONET2_MASK = 0xF800 //63488 in decimal
************************

************************
RGB_COMPONET0_OFFSET = 0
RGB_COMPONET1_OFFSET = 5
RGB_COMPONET2_OFFSET = 11
************************

************************
SCREEN_OFFSET_X = 100
SCREEN_OFFSET_Y = 0
************************

Here 
Also PP_TEST_FRAME_BPP = 2 for yv12 -> RGB565 & UYVY -> RGB565

iOutputBytesPerFrame = iOutputStride * iOutputHeight; 
// where iOutputStride = (iOutputWidth * PP_TEST_FRAME_BPP) i.e (112 * 2)  
// & iOutputHeight = 160 
// These are in case of RGB565

pOutputFrameVirtAddr = (UINT32 *) AllocPhysMem( iOutputBytesPerFrame, 
                                                PAGE_EXECUTE_READWRITE, 
                                                0,
                                                0,
                                                (ULONG *) &pOutputFramePhysAddr); 

// PAGE_EXECUTE_READWRITE = 0x40 mentioned in winnt.h

// Width =112 & Height = 160 in all the formats for i/p & o/p

Now my task is for RGB888. Please guide me what shall i do in this. **Thanks in advance.


Conversion from yuv444 to rgb888 is pretty simple since all of the components fall on byte boundaries so no bit masking should even be needed. According to the wikipedia article nobugz referred to in the comments section, the conversion can be done in fixed point by the following

UINT8* pimg = pImageBuf;
for(int i=0; i<height; i++)
{
    for (int j=0; j< width; j++)        
    {
        INT16 Y = pimg[0];
        INT16 Cb = (INT16)pimg[1] - 128;
        INT16 Cr = (INT16)pimg[2] - 128;
        rValue = Y + Cr + Cr >> 2 + Cr >> 3 + Cr >> 5
        gValue = Y - (Cb >> 2 + Cb >> 4 + Cb >> 5) -
                 (Cr >> 1 + Cr >> 3 + Cr >> 4 + Cr >> 5);
        bValue = Y + Cb + Cb >> 1 + Cb >> 2 + Cb >> 6;
        SetPixel(g_hDisplay, SCREEN_OFFSET_X + j, SCREEN_OFFSET_Y+i, RGB(rValue,
                 gValue, bValue));
        pimg+=3;
    }
}

This assumes that your yuv444 is 8 bits per sample (24 bits per pixel). The conversion can also be done in floating point but this should be quicker if it works since your source and destinations are both fixed point. I'm also not sure the conversion to int16 is necessary, but I did it to be safe.

Note that the 444 in yuv444 is not referring to the same thing as the 888 in rgb888. The 444 refers to the subsampling that often occurs when using the TUV colorspace. For instance in YUV420, Cb and Cr are decimated by two in both directions. yuv444 just means that all three components are sampled the same (no subsampling). The 888 in rgb888 is referring to the bits per sample (8 bits for each of the three color components).

I have not actually tested this code, but it should at least give you an idea where to start.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号