-// Convert wxColour into it's quantized value in lower-precision
-// pixel format (needed for masking by colour).
-static wxColour wxQuantizeColour(const wxColour& clr, const wxBitmap& bmp)
-{
-#if 0
- pixel_format_t *pf = bmp.GetMGLbitmap_t()->pf;
-
- if ( pf->redAdjust == 0 && pf->greenAdjust == 0 && pf->blueAdjust == 0 )
- return clr;
- else
- return wxColour((unsigned char)((clr.Red() >> pf->redAdjust) << pf->redAdjust),
- (unsigned char)((clr.Green() >> pf->greenAdjust) << pf->greenAdjust),
- (unsigned char)((clr.Blue() >> pf->blueAdjust) << pf->blueAdjust));
-#endif
+// NB: Most of this conversion code is needed because of differences between
+// wxImage and wxDFB's wxBitmap representations:
+// (1) wxImage uses RGB order, while DirectFB uses BGR
+// (2) wxImage has alpha channel in a separate plane, while DirectFB puts
+// all components into single BGRA plane
+
+// pitch = stride = # of bytes between the start of N-th line and (N+1)-th line
+// {Src,Dst}PixSize = # of bytes used to represent one pixel
+template<int SrcPixSize, int DstPixSize>
+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 - SrcPixSize * w;
+ unsigned dst_advance = dst_pitch - DstPixSize * w;
+ for ( unsigned y = 0; y < h; y++, src += src_advance, dst += dst_advance )
+ {
+ for ( unsigned x = 0; x < w; x++, src += SrcPixSize, dst += DstPixSize )
+ {
+ // copy with RGB -> BGR translation:
+ dst[0] = src[2];
+ dst[1] = src[1];
+ dst[2] = src[0];
+ }
+ }