• 图像处理算法大全(基于libyuv或IPP)----RGB32(ARGB)转成yuv420,RGB24,nv12,yuv422集合


    《周星星教你学ffmpeg》技巧

    libyuv源码: 

    1. static void RGB32_2_YUV420(BYTE* pRGBAPtr, BYTE* pYUYVPtr, int width, int height)
    2. {
    3. #ifdef LIBYUV
    4. uint8_t* yplane = pYUYVPtr;
    5. uint8_t* uplane = pYUYVPtr + width * height;
    6. uint8_t* vplane = pYUYVPtr + (width * height*5 / 4);
    7. int n = libyuv::ARGBToI420( pRGBAPtr, width * 4,yplane, width, uplane, width / 2, vplane, width / 2, width, height);
    8. #else
    9. DWORD dwTime = ::GetTickCount();
    10. IppiSize imgSize;
    11. imgSize.width = width;
    12. imgSize.height = height;
    13. Ipp8u* pDes[3] = { pYUYVPtr,pYUYVPtr + height * width * 5 / 4,pYUYVPtr + height * width };
    14. int Des[3] = { width,width * 1 / 2,width * 1 / 2 };//YUV420->1,1/2,1/2
    15. int* pInt = Des;
    16. IppStatus is = ippiBGRToYCrCb420_8u_AC4P3R(pRGBAPtr, width*4, pDes, Des, imgSize);
    17. if (is != ippStsNoErr)
    18. {
    19. return;
    20. }
    21. #endif
    22. }
    23. static void RGB32_2_YUV422(BYTE* pRGBAPtr, BYTE* pYUYVPtr, int width, int height)//yuv422
    24. {
    25. #ifdef LIBYUV
    26. int n = libyuv::ARGBToYUY2(pRGBAPtr, width * 4, pYUYVPtr, width*2, width, height);
    27. #else
    28. DWORD dwTime = ::GetTickCount();
    29. IppiSize imgSize;
    30. imgSize.width = width;
    31. imgSize.height = height;
    32. IppStatus is = ippiBGRToYCbCr422_8u_AC4C2R(pRGBAPtr, width*4, pYUYVPtr, width*2, imgSize);
    33. if (is != ippStsNoErr)
    34. {
    35. return;
    36. }
    37. #endif
    38. }
    1. static void RGB32ToNV12(BYTE* pRGBA, BYTE* pNV12, int width, int height)
    2. {
    3. uint8_t* yplane = pNV12;
    4. uint8_t* uvplane = pNV12 + width * height;
    5. int n = libyuv::ARGBToNV12(pRGBA, width * 4, yplane, width, uvplane, width, width,
    6. }
    7. static void RGB32ToRGB24(BYTE *input_rgba, BYTE *output_rgb24, int width, int height)
    8. {
    9. const int input_stride_rgba = width * 4; // 输入图像的步长,每个像素4字节
    10. const int output_stride_rgb24 = width * 3; // 输出图像的步长,每个像素3字节
    11. libyuv::ARGBToRGB24(input_rgba, input_stride_rgba, output_rgb24, output_stride_rgb24,
    12. width, height);
    13. }

    ok!打完收工!

  • 相关阅读:
    idea技巧--debug使用技巧
    MySQL其他集群类型介绍
    天地不仁,以万物为刍狗!
    Nginx系列教程(六)| 手把手教你搭建 LNMP 架构并部署天空网络电影系统
    关于时间复杂度的一些新认识
    数据结构----线性表之顺序表
    应广PMC131 SOP16 16pin八位单片机
    【Hadoop】使用Metorikku框架读取hive数据统计分析写入mysql
    可变参数函数原理
    代码随想录一一一链表一一一设计链表
  • 原文地址:https://blog.csdn.net/xjb2006/article/details/133019146