2

いくつかのコードから始めましょう:

QByteArray OpenGLWidget::modifyImage(QByteArray imageArray, const int width, const int height){
    if (vertFlip){
        /* Each pixel constist of four unisgned chars: Red Green Blue Alpha.
         * The field is normally 640*480, this means that the whole picture is in fact 640*4 uChars wide.
         * The whole ByteArray is onedimensional, this means that 640*4 is the red of the first pixel of the second row
         * This function is EXTREMELY SLOW
         */
        QByteArray tempArray = imageArray;
        for (int h = 0; h < height; ++h){
            for (int w = 0; w < width/2; ++w){
                for (int i = 0; i < 4; ++i){
                    imageArray.data()[h*width*4 + 4*w + i] = tempArray.data()[h*width*4 + (4*width - 4*w) + i ];
                    imageArray.data()[h*width*4 + (4*width - 4*w) + i] = tempArray.data()[h*width*4 + 4*w + i];
                }
            }
        }
    }
    return imageArray;
}

これは、640*480 の画像を垂直方向に反転するために現在使用しているコードです (画像は実際には 640*480 であるとは限りませんが、ほとんどは保証されています)。カラー エンコーディングは RGBA です。これは、配列の合計サイズが 640*480*4 であることを意味します。30 FPS で画像を取得し、同じ FPS で画面に表示したいと考えています。

古い CPU (Athlon x2) では、このコードは多すぎます: CPU は 30 FPS に追いつくために競争しています。

私は OpenGL も使用していますが、比較的低い CPU/GPU 使用率で画像を反転できることに気付いていないギミックがありますか?

4

3 に答える 3

2

この質問によると、OpenGL で画像を でスケーリングすることにより、画像を反転できます(1,-1,1)この質問では、変換とスケーリングを行う方法について説明します。

于 2013-07-29T13:54:28.537 に答える
1

キャッシュ アーキテクチャを利用して、ブロックごとに実行することで、少なくとも改善できます。あなたの例では、アクセスの1つ(読み取りまたは書き込みのいずれか)がオフキャッシュになります。

于 2013-07-29T13:52:39.833 に答える