![]() | DirectFB Tutorials |
Image loading and displaying |
#include <stdio.h> | |
#include <directfb.h> | |
static IDirectFB *dfb = NULL; |
(Globals) |
static IDirectFBSurface *logo = NULL; |
The image is to be loaded into a surface that we can blit from. |
int main (int argc, char **argv) | |
DFBSurfaceDescription dsc; |
(Locals) |
IDirectFBImageProvider *provider; |
Loading an image is done with an Image Provider. |
DFBCHECK (DirectFBInit (&argc, &argv)); |
(Initialize) |
DFBCHECK (dfb->CreateImageProvider (dfb, DATADIR"/dfblogo.png", &provider)); |
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 (provider->GetSurfaceDescription (provider, &dsc)); |
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 (dfb->CreateSurface( dfb, &dsc, &logo )); |
Create a surface based on the description of the provider. |
DFBCHECK (provider->RenderTo (provider, logo, NULL)); |
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. |
provider->Release (provider); |
Release the provider, we don't need it anymore. |
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. |
DFBCHECK (primary->Blit (primary, logo, NULL, i, (screen_height - dsc.height) / 2)); |
Blit the logo vertically centered with "i" as the X coordinate. NULL means that we want to blit the whole surface. |
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); |
(Release) |
return 23; |
(C) Copyright by convergence GmbH |
![]() |