美文网首页
yuv420p 转rgb计算

yuv420p 转rgb计算

作者: FM_1ad7 | 来源:发表于2021-11-25 15:48 被阅读0次

andorid 时间 compute shader链接:https://gitee.com/1392492818/compute_shader
YUV420p 格式如下

1637826234(1).png

坐标计算方式:

Y1 Y2
             = =  U1    ==  V1
Y9 Y10

相当于:
U和V的转换:

(h / 2) * (width / 2) + (w / 2)
h: (Y)的纵向坐标
w:  (Y) 的横向坐标
相当于把Y的四个点看成一个点来计算
   int width = 256;
   int height = 256;
   
    unsigned char* data = new unsigned char[width * height * 3 /2];
    unsigned char* rgbData = new unsigned char[width * height * 3];
    unsigned char* ydata = new unsigned char[width * height ];
    unsigned char* udata = new unsigned char[width * height  / 4];
    unsigned char* vdata = new unsigned char[width * height  / 4];

    FILE *fp=fopen("../lena_256x256_yuv420p.yuv","rb+");

    fread(data,1,width*height*3/2,fp);
    memcpy(ydata, data, width * height);

    memcpy(udata,data + width * height, width * height / 4);
    memcpy(vdata, data + width * height * 5 / 4, width * height / 4);
    printf("%d \n",udata[0]);
    int t = 0;

    for(int i = 0; i < width * height;i++)
    {
        int idx = i - i / height * width;
        int idy = i / width;
        int uvId =  (idy /2) * (width/2) + (idx /2);
        unsigned char y = ydata[i];
        unsigned char u = udata[uvId];
        unsigned char v = vdata[uvId];

        rgbData[i * (3) + 2] = y + 1.4075 *(v-128);
        rgbData[i * (3) + 1] = y - 0.3455 *(u -128) - 0.7169 *(v -128);
        rgbData[i * (3) + 0] = y + 1.779 *(u - 128);
    }

相关文章

网友评论

      本文标题:yuv420p 转rgb计算

      本文链接:https://www.haomeiwen.com/subject/iezatrtx.html