您的位置:程序门 -> linux/unix社区 -> 内核及驱动程序研究区



在linux通过directfb显示bmp图像


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


在linux通过directfb显示bmp图像
发表于:2007-06-20 13:35:08 楼主
在linux通过directfb显示bmp图像
发表于:2007-06-20 13:36:211楼 得分:0
在directfb网站只能查找到png的显示方法,不知道bmp如何通过dirctfb显示.
发表于:2007-06-20 16:24:072楼 得分:0
请大家多多帮助.
以上是通过directfb显示png图像的.
我加入了注解.


#include   <stdio.h>
#include   <unistd.h>
#include   <directfb.h>

static   idirectfb   *dfb   =   null;
static   idirectfbsurface   *primary   =   null;
static   int   screen_width     =   0;
static   int   screen_height   =   0;
#define   dfbcheck(x...)                                                                                   \
    {                                                                                                                         \
        dfbresult   err   =   x;                                                                                   \
                                                                                                                              \
        if   (err   !=   dfb_ok)                                                                                   \
            {                                                                                                                 \
                fprintf(   stderr,   "%s   <%d> :\n\t ",   __file__,   __line__   );   \
                directfberrorfatal(   #x,   err   );                                                   \
            }                                                                                                                 \
    } (globals)
//...the   image   is   to   be   loaded   into   a   surface   that   we   can   blit   from.
static   idirectfbsurface   *logo   =   null;
int   main   (int   argc,   char   **argv)
{
    int   i;
    dfbsurfacedescription   dsc;         //...(locals)
    //...loading   an   image   is   done   with   an   image   provider.
    idirectfbimageprovider   *provider;
    dfbcheck   (directfbinit   (&argc,   &argv));
    dfbcheck   (directfbcreate   (&dfb));
    dfbcheck   (dfb-> setcooperativelevel   (dfb,   dfscl_fullscreen));
    dsc.flags   =   dsdesc_caps;
    dsc.caps     =   dscaps_primary   ¦   dscaps_flipping;
    dfbcheck   (dfb-> createsurface(   dfb,   &dsc,   &primary   ));
    dfbcheck   (primary-> getsize   (primary,   &screen_width,   &screen_height));   //...(initialize)
   
    //...first   we   need   to   create   an   image   provider   by   passing   a   filename.
    //...directfb   will   find   (or   not)   an   image   provider   for   the   file   type.
    dfbcheck   (dfb-> createimageprovider   (dfb,   datadir "/dfblogo.png ",   &provider));

   
    /*get   a   surface   description   from   the   provider.   it   will   contain   the   width,
    height,   bits   per   pixel   and   the   flag   for   an   alphachannel   if   the   image   has
    one.   if   the   image   has   no   alphachannel   the   bits   per   pixel   is   set   to   the
    bits   per   pixel   of   the   primary   layer   to   use   simple   blitting   without   pixel
    format   conversion.*/
    dfbcheck   (provider-> getsurfacedescription   (provider,   &dsc));
   
    //...create   a   surface   based   on   the   description   of   the   provider.
    dfbcheck   (dfb-> createsurface(   dfb,   &dsc,   &logo   ));

    /*let   the   provider   render   to   our   surface.   image   providers   are   supposed   to
    support   every   destination   pixel   format   and   size.   if   the   size   differs   the
    image   will   be   scaled   (bilinear).   the   last   parameter   allows   to   specify
    an   optional   destination   rectangle.   we   use   null   here   so   that   our   image
    covers   the   whole   logo   surface.*/
    dfbcheck   (provider-> renderto   (provider,   logo,   null));
   
    //...release   the   provider,   we   don 't   need   it   anymore.
    provider-> release   (provider);
    for   (i   =   -dsc.width;   i   <   screen_width;   i++)
    {
    //...we   want   to   let   the   logo   slide   in   on   the   left   and   slide   out   on   the   right.
          dfbcheck   (primary-> fillrectangle   (primary,   0,   0,   screen_width,   screen_height));   //...clear   the   screen.
         
    //...blit   the   logo   vertically   centered   with   "i "   as   the   x   coordinate.
          //...null   means   that   we   want   to   blit   the   whole   surface.
          dfbcheck   (primary-> blit   (primary,   logo,   null,   i,   (screen_height   -   dsc.height)   /   2));

            dfbcheck   (primary-> flip   (primary,   null,   dsflip_waitforsync));
        }
    //...flip   the   front   and   back   buffer,   but   wait   for   the   vertical   retrace   to   avoid   tearing.
   
    logo-> release   (logo); //...release   the   image.
    primary-> release   (primary);
    dfb-> release   (dfb); (release)
    return   23;
   
}


快速检索

最新资讯
热门点击