1

I got the directfb image example, and I'm trying to blit an image, as stated here. So, this is my code:

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

The output of this program is a lot of:

`(!!!)  *** 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()]`

Is this a problem of my DFB version? I'm using DirectFB 1.4.11.

Is there a way to make this example run and blit the image?

*(by the way, I didn't understand the DFB_FIXED_POINT_ONE variable, so I give any value to it to try)*

The Student
  • 27,520
  • 68
  • 161
  • 264
  • Out of curiosity, how did you compile DirectFB at all? I have tried multiple times and failed (the header files didn't install properly). I would love to help out, but I can't even get the thing to *compile*! – fouric Feb 13 '13 at 03:04
  • As far as I remember, it compiled with no problem, in Ubuntu 10.10, using DirectFB 1.4.11. – The Student Feb 14 '13 at 10:59
  • Could you repeat the exact steps that you took to download and compile DirectFB, and then the steps that you used to compile the above program? By the way, is there a particular reason that you are using the older 1.4.x line as opposed to the newer 1.6.x series? – fouric Feb 14 '13 at 19:31
  • For the program I use `g++ test.cpp -I /usr/local/include/directfb/ -L /usr/local/lib/directfb-1.4-5/ -ldirectfb`, for the DirectFB I would have to do it again to remember, if it's really necessary. We're using this version of DFB because it's an old project, and we can't update (and fix all the dependencies and new API) now. – The Student Feb 15 '13 at 11:47
  • Hm. Got it compiled (saw stdio instead of iostream, assumed that it was C, your example cleared that up), and I am now getting an error, but it is different from yours. Have you tried building/running the program on a host with different hardware and seeing if you get the same error message? – fouric Feb 16 '13 at 05:24
  • Yes, I was trying this simpler one (to begin understanding) in a newer system, but with no success: http://stackoverflow.com/questions/14752993/how-to-run-this-dfb-image-example-on-ubuntu-12-04-64-bit-with-directfb-1-6-3 – The Student Feb 19 '13 at 12:16
  • Does the simple image example on the dfb site work? The problem is only the rotation matrix? – John Carter Mar 06 '13 at 03:22
  • @JohnCarter Yes, the example works, the problem is only the rotation. – The Student Mar 21 '13 at 15:25

1 Answers1

1

I wanted to get directfb to display everything rotated 90 degrees, and this seemed like a good starting point.

There are two things to consider:

First the numbers are fixed point 16.16 fmt - so the upper part is the integer part and the lower 16 bits is the fractional part - so 0x10000 would represent 1 (ie. 1 << 16), and 0xffff0000 would represent -1 (ie -1 << 16).

Second the calculations appear to be done against the actual (rather than normalized) screen coordinates, and the result of the calculation needs to be in the range 0 .. screen width - 1 for X and 0 .. screen height - 1 for Y to be displayed.

In your case the correct matrix would seem to be:

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

Note the final entry on the first row that shifts the X coordinate back to the correct range for a X coordinate.

  • After using the above matrix instead of 90 degrees, it rotated 180 degrees. Can you please update the matrix for 90 degree – md.jamal Jun 11 '18 at 11:31