+#if defined(__WXMSW__) || defined(__WXMAC__)
+#define wxPy_premultiply(p, a) ((p) * (a) / 0xff)
+#else
+#define wxPy_premultiply(p, a) (p)
+#endif
+
+void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize,
+ ColourDesired fill, int alphaFill,
+ ColourDesired outline, int alphaOutline,
+ int /*flags*/) {
+#if wxUSE_GRAPHICS_CONTEXT
+ wxGCDC dc(*(wxMemoryDC*)hdc);
+ wxColour penColour(wxColourFromCDandAlpha(outline, alphaOutline));
+ wxColour brushColour(wxColourFromCDandAlpha(fill, alphaFill));
+ dc.SetPen(wxPen(penColour));
+ dc.SetBrush(wxBrush(brushColour));
+ dc.DrawRoundedRectangle(wxRectFromPRectangle(rc), cornerSize);
+ return;
+#else
+
+#ifdef wxHAS_RAW_BITMAP
+
+ // TODO: do something with cornerSize
+ wxUnusedVar(cornerSize);
+
+ int x, y;
+ wxRect r = wxRectFromPRectangle(rc);
+ wxBitmap bmp(r.width, r.height, 32);
+ wxAlphaPixelData pixData(bmp);
+
+ // Set the fill pixels
+ ColourDesired cdf(fill.AsLong());
+ int red = cdf.GetRed();
+ int green = cdf.GetGreen();
+ int blue = cdf.GetBlue();
+
+ wxAlphaPixelData::Iterator p(pixData);
+ for (y=0; y<r.height; y++) {
+ p.MoveTo(pixData, 0, y);
+ for (x=0; x<r.width; x++) {
+ p.Red() = wxPy_premultiply(red, alphaFill);
+ p.Green() = wxPy_premultiply(green, alphaFill);
+ p.Blue() = wxPy_premultiply(blue, alphaFill);
+ p.Alpha() = alphaFill;
+ ++p;
+ }
+ }
+
+ // Set the outline pixels
+ ColourDesired cdo(outline.AsLong());
+ red = cdo.GetRed();
+ green = cdo.GetGreen();
+ blue = cdo.GetBlue();
+ for (x=0; x<r.width; x++) {
+ p.MoveTo(pixData, x, 0);
+ p.Red() = wxPy_premultiply(red, alphaOutline);
+ p.Green() = wxPy_premultiply(green, alphaOutline);
+ p.Blue() = wxPy_premultiply(blue, alphaOutline);
+ p.Alpha() = alphaOutline;
+ p.MoveTo(pixData, x, r.height-1);
+ p.Red() = wxPy_premultiply(red, alphaOutline);
+ p.Green() = wxPy_premultiply(green, alphaOutline);
+ p.Blue() = wxPy_premultiply(blue, alphaOutline);
+ p.Alpha() = alphaOutline;
+ }
+
+ for (y=0; y<r.height; y++) {
+ p.MoveTo(pixData, 0, y);
+ p.Red() = wxPy_premultiply(red, alphaOutline);
+ p.Green() = wxPy_premultiply(green, alphaOutline);
+ p.Blue() = wxPy_premultiply(blue, alphaOutline);
+ p.Alpha() = alphaOutline;
+ p.MoveTo(pixData, r.width-1, y);
+ p.Red() = wxPy_premultiply(red, alphaOutline);
+ p.Green() = wxPy_premultiply(green, alphaOutline);
+ p.Blue() = wxPy_premultiply(blue, alphaOutline);
+ p.Alpha() = alphaOutline;
+ }
+
+ // Draw the bitmap
+ hdc->DrawBitmap(bmp, r.x, r.y, true);
+
+#else
+ wxUnusedVar(cornerSize);
+ wxUnusedVar(alphaFill);
+ wxUnusedVar(alphaOutline);
+ RectangleDraw(rc, outline, fill);
+#endif
+#endif
+}
+
+#ifdef wxHAS_RAW_BITMAP
+wxBitmap BitmapFromRGBAImage(int width, int height, const unsigned char *pixelsImage)
+{
+ int x, y;
+ wxBitmap bmp(width, height, 32);
+ wxAlphaPixelData pixData(bmp);
+
+ wxAlphaPixelData::Iterator p(pixData);
+ for (y=0; y<height; y++) {
+ p.MoveTo(pixData, 0, y);
+ for (x=0; x<width; x++) {
+ unsigned char red = *pixelsImage++;
+ unsigned char green = *pixelsImage++;
+ unsigned char blue = *pixelsImage++;
+ unsigned char alpha = *pixelsImage++;
+
+ p.Red() = wxPy_premultiply(red, alpha);
+ p.Green() = wxPy_premultiply(green, alpha);
+ p.Blue() = wxPy_premultiply(blue, alpha);
+ p.Alpha() = alpha;
+ ++p;
+ }
+ }
+ return bmp;
+}
+#endif
+
+
+void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height,
+ const unsigned char *pixelsImage)
+{
+#ifdef wxHAS_RAW_BITMAP
+ wxRect r = wxRectFromPRectangle(rc);
+ wxBitmap bmp = BitmapFromRGBAImage(width, height, pixelsImage);
+ hdc->DrawBitmap(bmp, r.x, r.y, true);
+#endif
+}
+
+
+void SurfaceImpl::Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back) {