Hi,

as I wrote in a question in users list I have some problems blitting an image 
using color keys when using SDL as backend.

I have investigated this further by minimizing the code so that I have a 
program only doing this failing blit. This program is attached as "blit.c". 

When compiling the attached program against DirectFB 1.1.1 I have no problems 
using color key for blitting. It works with both DSPF_RGB32 and DSPF_ARGB. 

When compiling against DirectFB 1.2.3 the color key does not work when using 
DSPF_RGB32. It still works when using DSPF_ARGB. 

Any ideas?

Thanks,
Anders Karlsson <[EMAIL PROTECTED]>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <directfb.h>

#define WIDTH 640
#define HEIGHT 480
#define PIXEL_FORMAT DSPF_ARGB

#define DFBCHECK(x...)                                         \
  { DFBResult err = x;                                         \
    if (err != DFB_OK)  {                                      \
        fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
        DirectFBErrorFatal( #x, err ); } }


// Bitmap containing the mouse pointer face.
#define ARROW_WIDTH 12
#define ARROW_HEIGHT 21
static unsigned char arrow_bits[] = {
    0x01, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0f, 0x00, 0x1f, 0x00, 0x3f, 0x00, 0x7f, 0x00, 
    0xff, 0x00, 0xff, 0x01, 0xff, 0x03, 0xff, 0x07, 0xff, 0x0f, 0xff, 0x00, 0xff, 0x00, 
    0xe7, 0x01, 0xe3, 0x01, 0xc1, 0x03, 0xc0, 0x03, 0x80, 0x07, 0x80, 0x07, 0x00, 0x03 };


int main(int argc, char **argv)
{
    IDirectFB *dfb = NULL;
    IDirectFBSurface *surface = NULL;
    DFBSurfaceDescription dsc;
    IDirectFBSurface *arrow = NULL;
    DFBSurfaceDescription arrow_dsc;
    DFBSurfacePixelFormat pixel_format = DSPF_UNKNOWN;
    int bpp = 0;

    DFBCHECK(DirectFBInit(&argc, &argv));
    DFBCHECK(DirectFBCreate(&dfb));
    DFBCHECK(dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));

    // Window surface
    dsc.flags  = (DFBSurfaceDescriptionFlags)(DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
    dsc.caps   = (DFBSurfaceCapabilities)(DSCAPS_PRIMARY | DSCAPS_FLIPPING);
    dsc.height = HEIGHT;
    dsc.width  = WIDTH;
    dsc.pixelformat = PIXEL_FORMAT;
    DFBCHECK(dfb->CreateSurface(dfb, &dsc, &surface));
    DFBCHECK(surface->SetBlittingFlags(surface, DSBLIT_SRC_COLORKEY));
    DFBCHECK(surface->SetColor(surface, 0x80, 0x00, 0xff, 0x00));
    DFBCHECK(surface->FillRectangle(surface, 0, 0, WIDTH, HEIGHT));
    DFBCHECK(surface->GetPixelFormat(surface, &pixel_format));
    bpp = DFB_BITS_PER_PIXEL(pixel_format) / 8;

    // Arrow surface
    arrow_dsc.flags  = (DFBSurfaceDescriptionFlags)(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
    arrow_dsc.height = ARROW_HEIGHT;
    arrow_dsc.width  = ARROW_WIDTH;
    arrow_dsc.pixelformat = PIXEL_FORMAT;
    DFBCHECK(dfb->CreateSurface(dfb, &arrow_dsc, &arrow));

    // Set which color that will be transparent when the pointer surface is blitted onto other surfaces.
    DFBCHECK(arrow->SetSrcColorKey(arrow, 0xff, 0x00, 0x00));
    // Fill the surface with transparent pixels.
    DFBCHECK(arrow->SetColor(arrow, 0xff, 0x00, 0x00, 0xff));
    DFBCHECK(arrow->FillRectangle(arrow, 0, 0, ARROW_WIDTH, ARROW_HEIGHT));

    // Create arrow
    char white_pixel[] = {0xff, 0xff, 0xff, 0xff};
	char *arrow_data = NULL;
	int pitch = 0;
    DFBCHECK(arrow->Lock(arrow, DSLF_WRITE, (void**)&arrow_data, &pitch));
	for (int px = 0; px < arrow_dsc.width; ++px)  {
		for (int py = 0; py < arrow_dsc.height; ++py)  {
			int row_bytes = arrow_dsc.width/8 + ((arrow_dsc.width%8 > 0) ? 1 : 0);
			if ((arrow_bits[py*row_bytes + px/8] >> px%8) & 0x01)     {
                memcpy(arrow_data + py*pitch + px*bpp, &white_pixel, bpp);
            }
        }
    }
    DFBCHECK(arrow->Unlock(arrow));

    // Blit the mouse pointer 
    DFBRectangle pointer_rect = {0, 0, ARROW_WIDTH, ARROW_HEIGHT};
    DFBCHECK(surface->Blit(surface, arrow, &pointer_rect, 100, 100));    
    DFBCHECK(surface->Flip(surface, 0, DSFLIP_BLIT));

    sleep(10);
    
    /* Release the super interface. */
    arrow->Release( arrow );
    surface->Release( surface );
    dfb->Release( dfb );

    return 0;
}

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
directfb-dev mailing list
directfb-dev@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev

Reply via email to