开发者

How to convert IplImage(OpenCV) to ALLEGRO_BITMAP (A5) fast?

Is there a fastest way to convert a IplImage type from OpenCV to ALLEGRO_BITMAP type from Allegro 5.0.x than just putting every pixel from one to another?

Like 2 for loops like this:

void iplImageToBitmap(IplImage *source, ALLEGRO_BITMAP* dest) {
    if(source!= NULL && d开发者_如何学运维est!= 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]));
            }
        }
    }
}


Use al_lock_bitmap to get an ALLEGRO_LOCKED_REGION, then set the pixel data as described. Then unlock it with al_unlock_bitmap.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜