directfb png透明色问题

来源:互联网 发布:zookeeper 集群 端口 编辑:程序博客网 时间:2024/04/29 19:42

directfb是一个做嵌入式的轻型库,对此,我不做太多说明,网上关于基础介绍的内容比较多了!

 

我要讲的是关于directfb插入图片透明色的问题,关于怎么制作成透明色的png,网络上有很多这方面的资料,用ps.....

 

如下图所示:

 

 这是运用常规的方法做的结果。

而我们想要的是以下这种结果:

我们打开directfb,查看API中会发现

DFBResult RenderTo (  IDirectFBImageProvider  * thiz,   IDirectFBSurface  * destination,   const DFBRectangle  * destination_rect );

下面有这样的说明:

If the image file has an alpha channel it is rendered with alpha channel if the destination surface is of the ARGB pixelformat. Otherwise, transparent areas are blended over a black background.

 

我们通过上面的描述,我们可以清楚的知道,我们的PNG图片是有alpha通道的,而我们的surface没有alpha通道时,图片的背景部分会被染黑。

 

解决方案呢:

DFBSurfaceDescription dsc;
    IDirectFBImageProvider *provider;

    dsc.flags       = DSDESC_PIXELFORMAT| DSDESC_WIDTH | DSDESC_HEIGHT ;
  
  dsc.pixelformat = DSPF_ARGB;  //我们在这个地方设置其像素格式
    dsc.width       = size;
    dsc.height      = size;

设置完以后:

   DFBCHECK (dfb->CreateImageProvider (dfb,str, &provider));
    DFBCHECK (provider->RenderTo (provider, logo, NULL));
    provider->Release (provider);
    primary->SetBlittingFlags( primary ,DSBLIT_BLEND_ALPHACHANNEL );

   //在这一行我们需要设置blit格式,然后再对surface进行blit操作

  DFBCHECK (primary->Blit (primary, logo, NULL, posX,posY));

 

总结:这个问题主要是我们对alpha通道没有一个直观清晰的认识,具体我们可以参考晚上的一些资料。关于alpha通道,在directfb源码束中有一个df_porter该例子对alpha进行了一个较好的说明:

其中有著名的Porter/Duff 定理,大家可以做仔细研究。