+ wxCHECK_RET( locked.ptr, "failed to lock surface" );
+
+ const unsigned width = image.GetWidth();
+ const unsigned height = image.GetHeight();
+ const DFBSurfacePixelFormat format = surface->GetPixelFormat();
+
+ // copy RGB data to the surface:
+ switch ( format )
+ {
+ case DSPF_RGB24:
+ CopyPixelsAndSwapRGB<3,3>
+ (
+ width, height,
+ image.GetData(), width * 3,
+ (unsigned char*)locked.ptr, locked.pitch
+ );
+ break;
+
+ case DSPF_RGB32:
+ case DSPF_ARGB:
+ CopyPixelsAndSwapRGB<3,4>
+ (
+ width, height,
+ image.GetData(), width * 3,
+ (unsigned char*)locked.ptr, locked.pitch
+ );
+ break;
+
+ default:
+ wxFAIL_MSG( "unexpected pixel format" );
+ return;
+ }
+
+ // if the image has alpha channel, merge it in:
+ if ( format == DSPF_ARGB )
+ {
+ wxCHECK_RET( image.HasAlpha(), "logic error - ARGB, but no alpha" );
+
+ const unsigned advance = locked.pitch - 4 * width;
+ const unsigned char *alpha = image.GetAlpha();
+ // NB: "+3" is to get pointer to alpha component
+ unsigned char *dest = ((unsigned char*)locked.ptr) + 3;
+
+ for ( unsigned y = 0; y < height; y++, dest += advance )
+ for ( unsigned x = 0; x < width; x++, dest += 4 )
+ *dest = *(alpha++);
+ }
+}
+
+static wxIDirectFBSurfacePtr
+CreateSurfaceWithFormat(int w, int h, DFBSurfacePixelFormat format)
+{
+ DFBSurfaceDescription desc;
+ desc.flags = (DFBSurfaceDescriptionFlags)
+ (DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT);
+ desc.caps = DSCAPS_NONE;
+ desc.width = w;
+ desc.height = h;
+
+ if ( format != DSPF_UNKNOWN )
+ {
+ desc.flags = (DFBSurfaceDescriptionFlags)(
+ desc.flags | DSDESC_PIXELFORMAT);
+ desc.pixelformat = format;
+ }