开发者

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

开发者 https://www.devze.com 2023-04-09 20:45 出处:网络
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?

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

精彩评论

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

关注公众号