twanvl / MagicSetEditor2

Magic Set Editor is a program for designing trading cards
Other
111 stars 41 forks source link

MacOS: Raster Operation wxAND_INVERT not supported #108

Open ciderwolf opened 4 years ago

ciderwolf commented 4 years ago

Mac only supports a limited subset of the usual raster operation modes (see here), which causes MSE to crash when rendering symbols here.

twanvl commented 4 years ago

I can't think of an easy way to fix this. Probably the best solution is to not rely on OS native code for rendering at all, and use cairo everywhere (#62).

ciderwolf commented 4 years ago

This is somewhat sketchy, but it does replicate the AND_INVERT functionality manually.

if(interior) {
  wxImage sourceImg = interior->GetAsBitmap().ConvertToImage();
  wxImage destImg = dc.GetAsBitmap().ConvertToImage();

  Byte* src = sourceImg.GetData();
  Byte* dest = destImg.GetData();
  size_t size = sourceImg.GetWidth() * sourceImg.GetHeight() * 3;
  Byte* combined = (Byte*) malloc(size);
  for(size_t i = 0; i < size; i++) {
    // AND_INVERT == (NOT src) AND dst
    combined[i] = (~src[i]) & dest[i];
  }
  wxImage img = wxImage(sourceImg.GetWidth(), sourceImg.GetHeight());
  img.SetData(combined);

  wxBitmap x = wxBitmap(img);
  dc.DrawBitmap(x, 0, 0);
}