zoukankan      html  css  js  c++  java
  • 格式转换至yuv422转 yuv420

    //pYUV为422,yuv为420
    /*ok!
    * brief:pyuv is yuv422sp srcIn, and yuv is yuv420p desOut 
    */
    int YUV422To420(unsigned char *pYUV, unsigned char*yuv, int lWidth, int lHeight)
    {        
    int i,j;
    unsigned char*pY = yuv;
    unsigned char *pU = yuv + lWidth*lHeight;
    unsigned char *pV = pU + (lWidth*lHeight)/4;
     
    unsigned char *pYUVTemp = pYUV;
    unsigned char *pYUVTempNext = pYUV+lWidth*2;
             
     for(i=0; i<lheight; i+=2) <="" div="">
     {
        for(j=0; j<lwidth; j+=2) <="" div="">
         {
           pY[j] = *pYUVTemp++;
           pY[j+lWidth] = *pYUVTempNext++;
                             
           pU[j/2] =(*(pYUVTemp) + *(pYUVTempNext))/2;
           pYUVTemp++;
           pYUVTempNext++;
                             
           pY[j+1] = *pYUVTemp++;
           pY[j+1+lWidth] = *pYUVTempNext++;
                             
           pV[j/2] =(*(pYUVTemp) + *(pYUVTempNext))/2;
           pYUVTemp++;
           pYUVTempNext++;
         }
           pYUVTemp+=lWidth*2;
           pYUVTempNext+=lWidth*2;
           pY+=lWidth*2;
           pU+=lWidth/2;
           pV+=lWidth/2;
       }
             
           return 1;
    }

    大意了,每四行计算时,牵引错误,试试下面的代码吧,不过这种代码很有优化的余地
    书籍可以参考“视频技术手册”,上面有YUV422到YUV420采样转换的讲解

    C/C++ code
     


    int YUV422To420(unsigned char *pYUV, unsigned int *yuv, int lWidth, int lHeight)
    { //sp
    int i,j;
    unsigned int *pY = yuv;
    unsigned int *pU = yuv + lWidth*lHeight;
    unsigned int *pV = pU + (lWidth*lHeight)/4;

    unsigned char *pYUVTemp = pYUV;
    unsigned char *pYUVTempNext = pYUV+lWidth*2;
    unsigned char *pYUV2 = pYUVTempNext + lWidth*2;
    unsigned char *pYUV3 = pYUVTempNext + lWidth*4;

    for(i=0; i<lHeight; i+=4)
    {
    for(j=0; j<lWidth; j+=4)
    {
    // Y0
    pY[j] = pYUVTemp[j];
    pY[j+lWidth] = pYUVTempNext[j];
    pY[j+lWidth*2] = pYUV2[j];
    pY[j+lWidth*3] = pYUV3[j];
    // U
    pU[j/2] = (3*pYUVTemp[j+1] + pYUV2[j+1])/4;
    pU[j/2+lWidth/2] = (pYUVTempNext[j+1] + 3*pYUV3[j+1])/4;
    // Y1
    pY[j+1] = pYUVTemp[j+2];
    pY[j+lWidth+1] = pYUVTempNext[j+2];
    pY[j+lWidth*2+1] = pYUV2[j+2];
    pY[j+lWidth*3+1] = pYUV3[j+2];
    // V
    pV[j/2] = (3*pYUVTemp[j+3] + pYUV2[j+3])/4;
    pV[j/2+lWidth/2] = (pYUVTempNext[j+3] + 3*pYUV3[j+3])/4;

    }
    // 分别加四行
    pYUVTemp+=lWidth*2*4;
    pYUVTempNext+=lWidth*2*4;
    pYUV2+=lWidth*2*4;
    pYUV3+=lWidth*2*4;
    // Y加上四行
    pY+=lWidth*4;
    // UV加两行
    pU+=lWidth;
    pV+=lWidth;
    }

    return 1;
    }


    http://www.xuebuyuan.com/1541892.html

    http://bbs.csdn.net/topics/370045077

    http://blog.csdn.net/searchsun/article/details/2443867  yuv pannle packet

    http://blog.chinaunix.net/uid-29181887-id-3992543.html

    http://www.videolan.org/developers/x264.html x264编码器

    http://www.cnblogs.com/zhengbin/p/5023640.html js 黑客帝国特效

  • 相关阅读:
    《深度剖析CPython解释器》16. Python函数机制的深度解析(第三部分): 闭包的底层实现以及调用
    《深度剖析CPython解释器》15. Python函数机制的深度解析(第二部分): 函数在底层是如何被调用的
    《深度剖析CPython解释器》14. Python函数机制的深度解析(第一部分): 函数在底层的数据结构、以及它的创建方式
    《深度剖析CPython解释器》13. 剖析Python的流程控制语句(if、for、while),以及异常捕获机制
    QT: QObject::connect()剖析
    C++ 点滴 (二)
    飞书有时黑屏的解决办法
    QT:显示器数量检测
    使用WinRar 制作自定义安装包
    QT-Mac:QT的SetText()在有些Mac OS系统上未显示
  • 原文地址:https://www.cnblogs.com/pengkunfan/p/4102632.html
Copyright © 2011-2022 走看看