如何快速将IplImage(OpenCV)转换为ALLEGRO_BITMAP(A5)?

时间:2011-10-02 23:58:05

标签: c++ opencv iplimage allegro5

是否有最快的方法将IplImage类型从OpenCV转换为Allegro 5.0.x的ALLEGRO_BITMAP类型,而不是将每个像素从一个转换为另一个?

像这样的2个循环:

void iplImageToBitmap(IplImage *source, ALLEGRO_BITMAP* dest) {
    if(source!= NULL && dest!= NULL) {
        al_set_target_bitmap(dest);
        int height = source->height;
        int width = source->width;
        int x,y;

        for( y=0; y < height ; y++ ) {
            uchar* ptr = (uchar*) (
                source->imageData + y * source->widthStep
                );
            for( x=0; x < width; x++ ) {
                al_put_pixel(x,y,al_map_rgb(ptr[3*x+2],ptr[3*x+1],ptr[3*x]));
            }
        }
    }
}

1 个答案:

答案 0 :(得分:2)

使用al_lock_bitmap获取ALLEGRO_LOCKED_REGION,然后按照说明设置像素数据。然后使用al_unlock_bitmap解锁。