这个DirectFB Blit示例有什么问题?

时间:2013-01-31 16:13:02

标签: blit directfb

我得到了directfb image example,我正试图将图像搞定,正如here所述。所以,这是我的代码:

#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 );                         \
      }                                                        \
  }

/* reflection against y */
static int DFB_FIXED_POINT_ONE = 1;
static const s32 mat_y[9] = {
 -DFB_FIXED_POINT_ONE, 0,                   0,
  0,                   DFB_FIXED_POINT_ONE, 0,
  0,                   0,                   DFB_FIXED_POINT_ONE
};

static IDirectFBSurface *logo = NULL;
int main(int argc, char **argv) {
    int i;

    DFBSurfaceDescription dsc;
    IDirectFBImageProvider *provider;
    DFBCHECK(DirectFBInit (&argc, &argv));
    DFBCHECK(DirectFBCreate (&dfb));
    DFBCHECK(dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
    dsc.flags = DSDESC_CAPS;
    dsc.caps = DFBSurfaceCapabilities(DSCAPS_PRIMARY | DSCAPS_FLIPPING);
    DFBCHECK(dfb->CreateSurface( dfb, &dsc, &primary ));
    DFBCHECK(primary->GetSize (primary, &screen_width, &screen_height));
    DFBCHECK(dfb->CreateImageProvider (dfb, "iconC.png", &provider));
    DFBCHECK(provider->GetSurfaceDescription (provider, &dsc));
    DFBCHECK(dfb->CreateSurface( dfb, &dsc, &logo ));
    DFBCHECK(provider->RenderTo (provider, logo, NULL));
    provider->Release(provider);
    for (i = -dsc.width; i < screen_width; i++) {

        DFBCHECK(primary->SetRenderOptions(primary, DSRO_MATRIX));
        DFBCHECK(primary->SetMatrix(primary, mat_y));

        DFBCHECK(primary->FillRectangle (primary, 0, 0, screen_width, screen_height));
        DFBCHECK(primary->Blit (primary, logo, NULL, i, (screen_height - dsc.height) / 2));
        DFBCHECK(primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC));
        usleep(1000*10); // 10 microseconds
    }
    logo->Release(logo);
    primary->Release(primary);
    dfb->Release(dfb);
    return 23;
}

这个程序的输出很多:

`(!!!)  *** WARNING [rotation not yet implemented] *** [gfxcard.c:2075 in dfb_gfxcard_blit()]`
`(!!!)  *** WARNING [rotation not yet implemented] *** [gfxcard.c:2075 in dfb_gfxcard_blit()]`
`(!!!)  *** WARNING [rotation not yet implemented] *** [gfxcard.c:2075 in dfb_gfxcard_blit()]`

这是我的DFB版本的问题吗?我正在使用DirectFB 1.4.11。

有没有办法让这个例子运行并blit图像?

*(顺便说一句,我不理解DFB_FIXED_POINT_ONE变量,所以我给它任何值来试试)*

1 个答案:

答案 0 :(得分:1)

我想让directfb显示旋转90度的所有内容,这似乎是一个很好的起点。

有两件事需要考虑:

首先,数字是固定点16.16 fmt - 所以上部是整数部分,下部16位是小数部分 - 所以0x10000表示1(即1 <&lt;&lt; 16),0xffff0000表示-1(即-1 <&lt; 16)。

其次,计算似乎是针对实际(而不是标准化的)屏幕坐标进行的,计算结果需要在0 ..屏幕宽度 - 1为X和0 ..屏幕高度 - 1要显示Y.

在您的情况下,正确的矩阵似乎是:

{
    (-1 < 16), 0,         ((screen_width - 1) << 16),
    0,         (1 << 16), 0,
    0,         0,         (1 << 16),
}

注意第一行的最后一个条目,它将X坐标移回X坐标的正确范围。