+// pitch = stride = # of bytes between the start of N-th line and (N+1)-th line
+static void CopyPixelsAndSwapRGB(unsigned w, unsigned h,
+ const unsigned char *src,
+ unsigned src_pitch,
+ unsigned char *dst,
+ unsigned dst_pitch)
+{
+ unsigned src_advance = src_pitch - 3 * w;
+ unsigned dst_advance = dst_pitch - 3 * w;
+ for ( unsigned y = 0; y < h; y++, src += src_advance, dst += dst_advance )
+ {
+ for ( unsigned x = 0; x < w; x++, src += 3, dst += 3 )
+ {
+ // copy with RGB -> BGR translation:
+ dst[0] = src[2];
+ dst[1] = src[1];
+ dst[2] = src[0];
+ }
+ }
+}
+
+static void CopySurfaceToImage(const wxIDirectFBSurfacePtr& surface,
+ const wxImage& image)
+{
+ wxCHECK_RET( surface->GetPixelFormat() == DSPF_RGB24,
+ _T("unexpected pixel format") );
+
+ wxIDirectFBSurface::Locked locked(surface, DSLF_READ);
+ wxCHECK_RET( locked.ptr, _T("failed to lock surface") );
+
+ CopyPixelsAndSwapRGB(image.GetWidth(), image.GetHeight(),
+ (unsigned char*)locked.ptr, locked.pitch,
+ image.GetData(), image.GetWidth() * 3);
+}
+
+static void CopyImageToSurface(const wxImage& image,
+ const wxIDirectFBSurfacePtr& surface)
+{
+ wxCHECK_RET( surface->GetPixelFormat() == DSPF_RGB24,
+ _T("unexpected pixel format") );
+
+ wxIDirectFBSurface::Locked locked(surface, DSLF_WRITE);
+ wxCHECK_RET( locked.ptr, _T("failed to lock surface") );
+
+ CopyPixelsAndSwapRGB(image.GetWidth(), image.GetHeight(),
+ image.GetData(), image.GetWidth() * 3,
+ (unsigned char*)locked.ptr, locked.pitch);
+}
+