yuv to rgb 转换失败呀。天呀。谁来帮帮我呀。

为了方便提取YUV数据,扫描一帧图像分1,3,5,7,9...........奇数行

和0,2,4,6,8...偶数行。


转换算法是从  http://www.fourcc.org/fccyvrgb.php 中找到,失败了呀!!!!!

图像一看就不对,唉,搞了好几天了,谁来帮忙试一下呀。



void MainWindow::paintEvent(QPaintEvent *e)

{
    QPainter tPainter(this);
    tPainter.drawText(10,50,"hello");
    QString tYUVFile("/home/shell.albert/project/H.264/football/fb001.yuv");
    QFile tFile(tYUVFile);
    if(!tFile.open(QIODevice::ReadOnly))
    {
            qDebug()<<"open file failed!";
            return;
    }
    QByteArray tYData=tFile.read(84480);
    QByteArray tUData=tFile.read(21120);
    QByteArray tVData=tFile.read(21120);
    QByteArray tRestData=tFile.readAll();
    qDebug()<<"Y:"<<tYData.size();
    qDebug()<<"U:"<<tUData.size();
    qDebug()<<"V:"<<tVData.size();
    qDebug()<<"Rest:"<<tRestData.size();
    QImage tImage(352,240,QImage::Format_RGB32);
    qint32 tYUVWidth=tImage.width();
#if 1
    //1,3,5,7..................
    for(qint32 i=1;i<tImage.height();i+=2)
    {
        for(qint32 j=0;j<tImage.width();j++)
        {
            qint32 x=i-1;
            qint32 y=j;
            qint32 tYOffset=x*tYUVWidth+y;
            qint32 tUOffset=(x/2)*(tYUVWidth/2)+y/2;
            qint32 tVOffset=(x/2)*(tYUVWidth/2)+y/2;
            qDebug("1,3,5,7:(%d,%d):%d,%d,%d",i,j,tYOffset,tUOffset,tVOffset);
            qint32 tYValue=tYData.at(tYOffset);
            qint32 tUValue=tUData.at(tUOffset);
            qint32 tVValue=tVData.at(tVOffset);
            qint32 tRed=tYValue+1.403*tVValue;
            qint32 tGreen=tYValue-0.344*tUValue-0.714*tVValue;
            qint32 tBlue=tYValue+1.770*tUValue;
            tRed=tRed>255?255:tRed<0?0:tRed;
            tGreen=tGreen>255?255:tGreen<0?0:tGreen;
            tBlue=tBlue>255?255:tBlue<0?0:tBlue;
            tImage.setPixel(j,i,qRgb(tRed,tGreen,tBlue));
        }
    }
#endif
#if 0
    //0,2,4,6,8...............
    for(qint32 i=0;i<tImage.height();i+=2)
    {
        for(qint32 j=0;j<tImage.width();j++)
        {
            qint32 x=i;
            qint32 y=j;
            qint32 tYOffset=x*tYUVWidth+y;
            qint32 tUOffset=(x/2)*(tYUVWidth/2)+y/2;
            qint32 tVOffset=(x/2)*(tYUVWidth/2)+y/2;
            qDebug("0,2,4,6:(%d,%d):%d,%d,%d",i,j,tYOffset,tUOffset,tVOffset);
            qint32 tYValue=tYData.at(tYOffset);
            qint32 tUValue=tUData.at(tUOffset);
            qint32 tVValue=tVData.at(tVOffset);
            qint32 tRed=1.164*(tYValue-16)+1.596*(tVValue-128);
            qint32 tGreen=1.164*(tYValue-16)-0.813*(tVValue-128)-0.391*(tUValue-128);
            qint32 tBlue=1.164*(tYValue-16)+2.018*(tUValue-128);
            tRed=tRed>255?255:tRed<0?0:tRed;
            tGreen=tGreen>255?255:tGreen<0?0:tGreen;
            tBlue=tBlue>255?255:tBlue<0?0:tBlue;
            tImage.setPixel(j,i,qRgb(tRed,tGreen,tBlue));
        }
    }
#endif
    tPainter.drawImage(0,0,tImage);
    tYData.resize(0);
    tUData.resize(0);
    tVData.resize(0);
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值