How to convert yuy2 to a BITMAP in C++

前端 未结 4 1931
醉梦人生
醉梦人生 2021-01-05 07:58

I\'m using a security camera DLL to retreive the image from the camera. The DLL call a function of my program passing the image buffer as a parameter, but the image is in yu

4条回答
  •  被撕碎了的回忆
    2021-01-05 08:52

    This formula worked:

    int C = luma - 16;
    int D = cr - 128;
    int E = cb - 128;
    r = (298*C+409*E+128)/256;
    g = (298*C-100*D-208*E+128)/256;
    b = (298*C+516*D+128)/256;
    

    I got this from a matlab example.

    The gotcha is: in memory, Windows bitmaps aren't RGB, they are BGR. If you are writing to a memory buffer, you need to do something like this:

    rgbbuffer[rgbindex] = (char)b;
    rgbbuffer[rgbindex + 1] = (char)g;
    rgbbuffer[rgbindex + 2] = (char)r;
    

提交回复
热议问题