【问题标题】:Custom array sort ( YUYV -> YUV422P)自定义数组排序( YUYV -> YUV422P)
【发布时间】:2012-06-15 19:02:30
【问题描述】:

我正在尝试从 YUYV 格式排序和排列为 YUV422p 格式。该数组目前看起来像:

[y1][cb1][y2][cr1][y3][cb2][y4][cr2][y5][cb3][y6][cr3][y7][cb4][y8][cr4 ] ...[yn][cbn+1/2][yn+1][crn+1/2]

我需要将其排序为:

[y1][y2][y3][y4][y5][y6][y7][y8][yn][yn+1]..[cb1][cb2][cb3][cb4][ cbn+1/2]..[cr1][cr2][cr3][cr4][crn+1/2]

所有的 y 都需要在一起,所有的 cb 的在一起,所有的 cr 的在一起。

我正在努力使这部分尽可能高效并花费最少的时间。

这是我到目前为止所做的:

    inline const void YUYV_to_YUV422P_1280x960( char* yuyv, char* yuv422p)
    {
         const unsigned int height = 960;
         const unsigned int width  = 1280;
         int loopCount1 = height*width/2;
         int loopCount2 = height*width;
         char* yComponent   = yuv422p;
         char* cbComponent  = yuv422p + loopCount2;
         char* crComponent  = yuv422p + loopCount1 + loopCount2; 

         int i;
         for( i = (loopCount1 - 1); i != 0; --i )
         {
           cbComponent[ i ] = yuyv[ i*4 + 1 ];
           crComponent[ i ] = yuyv[ i*4 + 3 ];
         }

         for( i = (loopCount2 -1); i != 0; --i )
         {
           yComponent[ i ] = yuyv[ i*2 ];
         }
    }

关于如何提高效率和速度的任何想法,请告诉我。

【问题讨论】:

    标签: arrays algorithm optimization image-processing sorting


    【解决方案1】:

    建议一如既往地衡量它,然后决定它是否足够快。如果您在 3GHz 的 PC 上执行此操作,是否会节省几微秒?

    通常在此类任务中,您的内存 I/O 受限,因此为获得最佳缓存性能而编写它很重要。根据图像的大小和硬件,最好一次处理一行图像,以便在缓存中输入和输出图像行

    如果您拥有现代 CPU,您可以使用 SSE2 加速它,并同时对多个像素执行大量此类操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-23
      • 1970-01-01
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-25
      • 1970-01-01
      相关资源
      最近更新 更多