いくつかのコードから始めましょう:
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 使用率で画像を反転できることに気付いていないギミックがありますか?